Changed to execvp and output cleanup
authorRobert Pengelly <robertapengelly@hotmail.com>
Mon, 15 Sep 2025 00:55:51 +0000 (01:55 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Mon, 15 Sep 2025 00:55:51 +0000 (01:55 +0100)
32 files changed:
Makefile.pdw
Makefile.unix
Makefile.w32
Makefile.wat
command.h [new file with mode: 0644]
cstr.c
cstr.h [new file with mode: 0644]
dep.h [new file with mode: 0644]
hashtab.c
hashtab.h [new file with mode: 0644]
include/xmake/command.h [deleted file]
include/xmake/cstr.h [deleted file]
include/xmake/dep.h [deleted file]
include/xmake/hashtab.h [deleted file]
include/xmake/lib.h [deleted file]
include/xmake/read.h [deleted file]
include/xmake/report.h [deleted file]
include/xmake/rule.h [deleted file]
include/xmake/variable.h [deleted file]
include/xmake/xmake.h [deleted file]
lib.c
lib.h [new file with mode: 0644]
read.c
read.h [new file with mode: 0644]
report.c
report.h [new file with mode: 0644]
rule.c
rule.h [new file with mode: 0644]
variable.c
variable.h [new file with mode: 0644]
xmake.c
xmake.h [new file with mode: 0644]

index a6256dfcb56aaaa5d62ef56f4b360fb0ef2bdbb7..b269b7f1ed3261847de29668ce2c8478109261cb 100644 (file)
@@ -5,7 +5,7 @@ AS=aswin
 CC=gccwin
 LD=ldwin
 
-COPTS=-S -O2 -fno-common -ansi -I. -I./include -I../pdos/pdpclib -I../pdos/src -D__WIN32__ -D__NOBIVA__ -D__PDOS__
+COPTS=-S -O2 -fno-common -ansi -I. -I../pdos/pdpclib -I../pdos/src -D__WIN32__ -D__NOBIVA__ -D__PDOS__
 COBJ=cstr.o hashtab.o lib.o report.o read.o rule.o variable.o xmake.o
 
 all: clean xmake.exe
index 9c4310bb50ad1b9c4cab2010da9dee770c3e4f27..18faf043576bd12b8261f3201d49c346ded364e8 100644 (file)
@@ -5,7 +5,7 @@ SRCDIR              ?=  $(CURDIR)
 VPATH               :=  $(SRCDIR)
 
 CC                  :=  gcc
-CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -I$(SRCDIR)/include -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90
+CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90
 
 CSRC                :=  cstr.c hashtab.c lib.c read.c report.c rule.c variable.c xmake.c
 
index 7d64d9ec93a7b50358b5fe4e21dd153720789177..29e873e75a3b80ae86d0c91cfae71c532b6a87c3 100644 (file)
@@ -5,7 +5,7 @@ SRCDIR              ?=  $(CURDIR)
 VPATH               :=  $(SRCDIR)
 
 CC                  :=  gcc
-CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -I$(SRCDIR)/include -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90
+CFLAGS              :=  -D_FILE_OFFSET_BITS=64 -O2 -Wall -Werror -Wextra -ansi -pedantic -std=c90
 
 CSRC                :=  cstr.c hashtab.c lib.c read.c report.c rule.c variable.c xmake.c
 
index 29f7ade42689ec04b413531eb7712de16219a2e2..42bddbd50b3a20bda17b0a9d0459e6ca96cdf0ce 100644 (file)
@@ -10,7 +10,7 @@ all: xmake.exe
 
 xmake.exe: $(SRC)
 
-       wcl -I.\\include -fe=$@ $^
+       wcl -fe=$@ $^
 
 clean:
 
diff --git a/command.h b/command.h
new file mode 100644 (file)
index 0000000..c3ce4e1
--- /dev/null
+++ b/command.h
@@ -0,0 +1,14 @@
+/******************************************************************************
+ * @file            command.h
+ *****************************************************************************/
+#ifndef     _COMMAND_H
+#define     _COMMAND_H
+
+struct commands {
+
+    char *text;
+    unsigned long len;
+
+};
+
+#endif      /* _COMMAND_H */
diff --git a/cstr.c b/cstr.c
index 803ee72960f336b34baf320c3dae1c5735ddd14b..a4a219d343c10f793531b7efac52bedc22e648dd 100644 (file)
--- a/cstr.c
+++ b/cstr.c
@@ -4,8 +4,7 @@
 #include    <stdlib.h>
 #include    <string.h>
 
-#include    <xmake/cstr.h>
-
+#include    "cstr.h"
 extern void *xrealloc (void *__ptr, unsigned long __size);
 
 static void cstr_realloc (CString *cstr, long new_size) {
diff --git a/cstr.h b/cstr.h
new file mode 100644 (file)
index 0000000..6202270
--- /dev/null
+++ b/cstr.h
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * @file            cstr.h
+ *****************************************************************************/
+#ifndef     _CSTR_H
+#define     _CSTR_H
+
+typedef struct CString {
+
+    long size;
+    void *data;
+    
+    long size_allocated;
+
+} CString;
+
+void cstr_ccat (CString *cstr, int ch);
+void cstr_cat (CString *cstr, const char *str, long len);
+
+void cstr_new (CString *cstr);
+void cstr_free (CString *cstr);
+
+#endif      /* _CSTR_H */
diff --git a/dep.h b/dep.h
new file mode 100644 (file)
index 0000000..b683f81
--- /dev/null
+++ b/dep.h
@@ -0,0 +1,14 @@
+/******************************************************************************
+ * @file            dep.h
+ *****************************************************************************/
+#ifndef     _DEP_H
+#define     _DEP_H
+
+struct dep {
+
+    char *name;
+    struct dep *next;
+
+};
+
+#endif      /* _DEP_H */
index 32f3c401ed850578e1431af57a03d90f0aa36c0b..abd6ad69a1b3f020a1808b72897407d74c2361af 100644 (file)
--- a/hashtab.c
+++ b/hashtab.c
@@ -5,7 +5,7 @@
 #include    <stdlib.h>
 #include    <string.h>
 
-#include    <xmake/hashtab.h>
+#include    "hashtab.h"
 static struct hashtab_entry *find_entry (struct hashtab_entry *entries, unsigned long capacity, struct hashtab_name *key);
 
 static int adjust_capacity (struct hashtab *table, unsigned long new_capacity) {
diff --git a/hashtab.h b/hashtab.h
new file mode 100644 (file)
index 0000000..24e6b0d
--- /dev/null
+++ b/hashtab.h
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * @file            hashtab.h
+ *****************************************************************************/
+#ifndef     _HASHTAB_H
+#define     _HASHTAB_H
+
+#include    <stddef.h>
+
+#define hashtab_get haget
+#define hashtab_put haput
+#define hashtab_remove haremove
+
+
+struct hashtab_name {
+
+    const char *chars;
+    unsigned int bytes, hash;
+
+};
+
+struct hashtab_entry {
+
+    struct hashtab_name *key;
+    void *value;
+
+};
+
+struct hashtab {
+
+    struct hashtab_entry *entries;
+    unsigned long capacity, count, used;
+
+};
+
+struct hashtab_name *hashtab_alloc_name (const char *str);
+struct hashtab_name *hashtab_get_key (struct hashtab *table, const char *name);
+
+int hashtab_put (struct hashtab *table, struct hashtab_name *key, void *value);
+
+void *hashtab_get (struct hashtab *table, struct hashtab_name *key);
+void hashtab_remove (struct hashtab *table, struct hashtab_name *key);
+
+#endif      /* _HASHTAB_H */
diff --git a/include/xmake/command.h b/include/xmake/command.h
deleted file mode 100644 (file)
index c3ce4e1..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/******************************************************************************
- * @file            command.h
- *****************************************************************************/
-#ifndef     _COMMAND_H
-#define     _COMMAND_H
-
-struct commands {
-
-    char *text;
-    unsigned long len;
-
-};
-
-#endif      /* _COMMAND_H */
diff --git a/include/xmake/cstr.h b/include/xmake/cstr.h
deleted file mode 100644 (file)
index 6202270..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/******************************************************************************
- * @file            cstr.h
- *****************************************************************************/
-#ifndef     _CSTR_H
-#define     _CSTR_H
-
-typedef struct CString {
-
-    long size;
-    void *data;
-    
-    long size_allocated;
-
-} CString;
-
-void cstr_ccat (CString *cstr, int ch);
-void cstr_cat (CString *cstr, const char *str, long len);
-
-void cstr_new (CString *cstr);
-void cstr_free (CString *cstr);
-
-#endif      /* _CSTR_H */
diff --git a/include/xmake/dep.h b/include/xmake/dep.h
deleted file mode 100644 (file)
index b683f81..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/******************************************************************************
- * @file            dep.h
- *****************************************************************************/
-#ifndef     _DEP_H
-#define     _DEP_H
-
-struct dep {
-
-    char *name;
-    struct dep *next;
-
-};
-
-#endif      /* _DEP_H */
diff --git a/include/xmake/hashtab.h b/include/xmake/hashtab.h
deleted file mode 100644 (file)
index 24e6b0d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/******************************************************************************
- * @file            hashtab.h
- *****************************************************************************/
-#ifndef     _HASHTAB_H
-#define     _HASHTAB_H
-
-#include    <stddef.h>
-
-#define hashtab_get haget
-#define hashtab_put haput
-#define hashtab_remove haremove
-
-
-struct hashtab_name {
-
-    const char *chars;
-    unsigned int bytes, hash;
-
-};
-
-struct hashtab_entry {
-
-    struct hashtab_name *key;
-    void *value;
-
-};
-
-struct hashtab {
-
-    struct hashtab_entry *entries;
-    unsigned long capacity, count, used;
-
-};
-
-struct hashtab_name *hashtab_alloc_name (const char *str);
-struct hashtab_name *hashtab_get_key (struct hashtab *table, const char *name);
-
-int hashtab_put (struct hashtab *table, struct hashtab_name *key, void *value);
-
-void *hashtab_get (struct hashtab *table, struct hashtab_name *key);
-void hashtab_remove (struct hashtab *table, struct hashtab_name *key);
-
-#endif      /* _HASHTAB_H */
diff --git a/include/xmake/lib.h b/include/xmake/lib.h
deleted file mode 100644 (file)
index d0afe68..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/******************************************************************************
- * @file            lib.h
- *****************************************************************************/
-#ifndef     _LIB_H
-#define     _LIB_H
-
-#if     defined (_WIN32)
-# define    PATHSEP                     ";"
-#else
-# define    PATHSEP                     ":"
-#endif
-
-struct option {
-
-    const char *rule;
-    int (*callback) (const char *);
-
-};
-
-char *skip_whitespace (char *p);
-
-char *xstrdup (const char *__s);
-char *xstrndup (const char *__s, unsigned long __len);
-
-int parse_args (char **__args, int __cnt);
-void dynarray_add (void *__ptab, unsigned long *__nb_ptr, void *__data);
-
-void *xmalloc (unsigned long __sz);
-void *xrealloc (void *__ptr, unsigned long __sz);
-
-
-char *get_current_directory (void);
-
-int change_directory (const char *__path);
-int directory_exists (const char *__path);
-
-#endif      /* _LIB_H */
diff --git a/include/xmake/read.h b/include/xmake/read.h
deleted file mode 100644 (file)
index a880c0e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/******************************************************************************
- * @file            read.h
- *****************************************************************************/
-#ifndef     _READ_H
-#define     _READ_H
-
-void read_memory_makefile (const char *filename, unsigned long line_no, char *memory);
-int read_makefile (const char *filename);
-
-struct nameseq {
-
-    char *name;
-    struct nameseq *next;
-
-};
-
-void record_files (const char *filename, unsigned long line_no, struct nameseq *filenames, char *cmds, size_t cmds_idx, char *depstr);
-void *parse_nameseq (char *line, size_t size);
-
-#endif      /* _READ_H */
diff --git a/include/xmake/report.h b/include/xmake/report.h
deleted file mode 100644 (file)
index 4e507f4..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/******************************************************************************
- * @file            report.h
- *****************************************************************************/
-#ifndef     _REPORT_H
-#define     _REPORT_H
-
-enum report_type {
-
-    REPORT_WARNING,
-    REPORT_ERROR,
-    REPORT_FATAL_ERROR,
-    REPORT_INTERNAL_ERROR
-
-};
-
-#if     defined (_WIN32)
-# define    COLOR_ERROR                 12
-# define    COLOR_WARNING               13
-# define    COLOR_INTERNAL_ERROR        19
-#else
-# define    COLOR_ERROR                 91
-# define    COLOR_INTERNAL_ERROR        94
-# define    COLOR_WARNING               95
-#endif
-
-unsigned long get_error_count (void);
-void report_at (const char *filename, unsigned long lineno, enum report_type type, const char *fmt, ...);
-
-#endif      /* _REPORT_H */
diff --git a/include/xmake/rule.h b/include/xmake/rule.h
deleted file mode 100644 (file)
index 9e01c7b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/******************************************************************************
- * @file            rule.h
- *****************************************************************************/
-#ifndef     _RULE_H
-#define     _RULE_H
-
-#include    <xmake/command.h>
-#include    <xmake/dep.h>
-
-struct rule {
-
-    char *name;
-    
-    struct dep *deps;
-    struct commands *cmds;
-    
-    const char *filename;
-    unsigned long line_no;
-
-};
-
-struct suffix_rule {
-
-    char *first, *second;
-    struct commands *cmds;
-    
-    const char *filename;
-    unsigned long line_no;
-    
-    struct suffix_rule *next;
-
-};
-
-extern struct suffix_rule *suffix_rules;
-struct rule *rule_find (const char *name);
-
-void rule_add (const char *filename, unsigned long line_no, char *name, struct dep *deps, struct commands *cmds);
-void rule_add_suffix (const char *filename, unsigned long line_no, char *name, struct commands *cmds);
-void rules_init (void);
-
-#endif      /* _RULE_H */
diff --git a/include/xmake/variable.h b/include/xmake/variable.h
deleted file mode 100644 (file)
index 95573cb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/******************************************************************************
- * @file            variable.h
- *****************************************************************************/
-#ifndef     _VARIABLE_H
-#define     _VARIABLE_H
-
-enum variable_flavor {
-
-    VAR_FLAVOR_RECURSIVELY_EXPANDED,
-    VAR_FLAVOR_SIMPLY_EXPANDED,
-    VAR_FLAVOR_IMMEDIATELY_EXPANDED
-
-};
-
-enum variable_origin {
-
-    VAR_ORIGIN_AUTOMATIC,
-    VAR_ORIGIN_COMMAND_LINE,
-    VAR_ORIGIN_FILE
-
-};
-
-struct variable {
-
-    char *name, *value;
-    
-    enum variable_flavor flavor;
-    enum variable_origin origin;
-
-};
-
-struct variable *variable_add (char *name, char *value, enum variable_origin origin);
-struct variable *variable_change (char *name, char *value, enum variable_origin origin);
-struct variable *variable_find (char *name);
-
-void parse_var_line (const char *filename, unsigned long line_no, char *line, enum variable_origin origin);
-char *variable_expand_line (const char *filename, unsigned long line_no, char *line);
-
-void variables_init (void);
-
-#endif      /* _VARIABLE_H */
diff --git a/include/xmake/xmake.h b/include/xmake/xmake.h
deleted file mode 100644 (file)
index c277782..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/******************************************************************************
- * @file            xmake.h
- *****************************************************************************/
-#ifndef     _XMAKE_H
-#define     _XMAKE_H
-
-struct xmake_state {
-
-    char **makefiles;
-    unsigned long nb_makefiles;
-    
-    char **goals;
-    unsigned long nb_goals;
-    
-    char **include_paths;
-    unsigned long nb_include_paths;
-    
-    char **directories;
-    unsigned long nb_directories;
-    
-    char *path;
-    int quiet, no_print;
-    
-    int dry_run, env_override, keep_going;
-    int ignore_errors;
-
-};
-
-#if     defined (__PDOS386__)
-# ifndef        __PDOS__
-#  define   __PDOS__
-# endif
-#endif
-
-extern struct xmake_state *state;
-extern const char *program_name;
-
-int rule_search_and_build (char *name);
-
-#endif      /* _XMAKE_H */
diff --git a/lib.c b/lib.c
index 01bf0b30cde0250f1b716960a56fb08c9b807ef8..94c69a5cb1dccf22d555dcf6300c06345b27a1fc 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -7,11 +7,11 @@
 #include    <stdlib.h>
 #include    <string.h>
 
-#include    <xmake/cstr.h>
-#include    <xmake/lib.h>
-#include    <xmake/report.h>
-#include    <xmake/variable.h>
-#include    <xmake/xmake.h>
+#include    "cstr.h"
+#include    "lib.h"
+#include    "report.h"
+#include    "variable.h"
+#include    "xmake.h"
 
 size_t len = 0;
 
diff --git a/lib.h b/lib.h
new file mode 100644 (file)
index 0000000..d0afe68
--- /dev/null
+++ b/lib.h
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * @file            lib.h
+ *****************************************************************************/
+#ifndef     _LIB_H
+#define     _LIB_H
+
+#if     defined (_WIN32)
+# define    PATHSEP                     ";"
+#else
+# define    PATHSEP                     ":"
+#endif
+
+struct option {
+
+    const char *rule;
+    int (*callback) (const char *);
+
+};
+
+char *skip_whitespace (char *p);
+
+char *xstrdup (const char *__s);
+char *xstrndup (const char *__s, unsigned long __len);
+
+int parse_args (char **__args, int __cnt);
+void dynarray_add (void *__ptab, unsigned long *__nb_ptr, void *__data);
+
+void *xmalloc (unsigned long __sz);
+void *xrealloc (void *__ptr, unsigned long __sz);
+
+
+char *get_current_directory (void);
+
+int change_directory (const char *__path);
+int directory_exists (const char *__path);
+
+#endif      /* _LIB_H */
diff --git a/read.c b/read.c
index 5e0eab821c4938a442546e78720252b16be0e2f3..b19c453184668664a4f26f2038e5002e28bdd821 100644 (file)
--- a/read.c
+++ b/read.c
@@ -6,13 +6,13 @@
 #include    <stdlib.h>
 #include    <string.h>
 
-#include    <xmake/command.h>
-#include    <xmake/dep.h>
-#include    <xmake/lib.h>
-#include    <xmake/read.h>
-#include    <xmake/rule.h>
-#include    <xmake/variable.h>
-#include    <xmake/xmake.h>
+#include    "command.h"
+#include    "dep.h"
+#include    "lib.h"
+#include    "read.h"
+#include    "rule.h"
+#include    "variable.h"
+#include    "xmake.h"
 
 extern struct variable *default_goal_var;
 
diff --git a/read.h b/read.h
new file mode 100644 (file)
index 0000000..a880c0e
--- /dev/null
+++ b/read.h
@@ -0,0 +1,20 @@
+/******************************************************************************
+ * @file            read.h
+ *****************************************************************************/
+#ifndef     _READ_H
+#define     _READ_H
+
+void read_memory_makefile (const char *filename, unsigned long line_no, char *memory);
+int read_makefile (const char *filename);
+
+struct nameseq {
+
+    char *name;
+    struct nameseq *next;
+
+};
+
+void record_files (const char *filename, unsigned long line_no, struct nameseq *filenames, char *cmds, size_t cmds_idx, char *depstr);
+void *parse_nameseq (char *line, size_t size);
+
+#endif      /* _READ_H */
index d36483b6d449496e9dc812cb6b5388fd61351a73..db2c9b1551ebec05631699b1993b76a793332c19 100644 (file)
--- a/report.c
+++ b/report.c
@@ -5,8 +5,7 @@
 #include    <stdio.h>
 #include    <string.h>
 
-#include    <xmake/report.h>
-
+#include    "report.h"
 unsigned long errors = 0;
 
 #ifndef     __PDOS__
diff --git a/report.h b/report.h
new file mode 100644 (file)
index 0000000..4e507f4
--- /dev/null
+++ b/report.h
@@ -0,0 +1,29 @@
+/******************************************************************************
+ * @file            report.h
+ *****************************************************************************/
+#ifndef     _REPORT_H
+#define     _REPORT_H
+
+enum report_type {
+
+    REPORT_WARNING,
+    REPORT_ERROR,
+    REPORT_FATAL_ERROR,
+    REPORT_INTERNAL_ERROR
+
+};
+
+#if     defined (_WIN32)
+# define    COLOR_ERROR                 12
+# define    COLOR_WARNING               13
+# define    COLOR_INTERNAL_ERROR        19
+#else
+# define    COLOR_ERROR                 91
+# define    COLOR_INTERNAL_ERROR        94
+# define    COLOR_WARNING               95
+#endif
+
+unsigned long get_error_count (void);
+void report_at (const char *filename, unsigned long lineno, enum report_type type, const char *fmt, ...);
+
+#endif      /* _REPORT_H */
diff --git a/rule.c b/rule.c
index 19c7484f26c6ed5cc568533f4614a2c8957ba126..58470f35ffb19482e93ebbac4cac907921816eeb 100644 (file)
--- a/rule.c
+++ b/rule.c
@@ -3,11 +3,11 @@
  *****************************************************************************/
 #include    <string.h>
 
-#include    <xmake/command.h>
-#include    <xmake/dep.h>
-#include    <xmake/hashtab.h>
-#include    <xmake/lib.h>
-#include    <xmake/rule.h>
+#include    "command.h"
+#include    "dep.h"
+#include    "hashtab.h"
+#include    "lib.h"
+#include    "rule.h"
 
 static struct hashtab hashtab_rules = { 0 };
 struct suffix_rule *suffix_rules = 0;
diff --git a/rule.h b/rule.h
new file mode 100644 (file)
index 0000000..862bd4d
--- /dev/null
+++ b/rule.h
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * @file            rule.h
+ *****************************************************************************/
+#ifndef     _RULE_H
+#define     _RULE_H
+
+#include    "command.h"
+#include    "dep.h"
+
+struct rule {
+
+    char *name;
+    
+    struct dep *deps;
+    struct commands *cmds;
+    
+    const char *filename;
+    unsigned long line_no;
+
+};
+
+struct suffix_rule {
+
+    char *first, *second;
+    struct commands *cmds;
+    
+    const char *filename;
+    unsigned long line_no;
+    
+    struct suffix_rule *next;
+
+};
+
+extern struct suffix_rule *suffix_rules;
+struct rule *rule_find (const char *name);
+
+void rule_add (const char *filename, unsigned long line_no, char *name, struct dep *deps, struct commands *cmds);
+void rule_add_suffix (const char *filename, unsigned long line_no, char *name, struct commands *cmds);
+void rules_init (void);
+
+#endif      /* _RULE_H */
index e6cd868e675f693aa6f486db9dea2813b050ba2d..ef98a445a9094a8cba3dd9d8231a677d7a60f9fa 100644 (file)
 
 #include    <stdio.h>
 
-#include    <xmake/hashtab.h>
-#include    <xmake/lib.h>
-#include    <xmake/read.h>
-#include    <xmake/report.h>
-#include    <xmake/variable.h>
-#include    <xmake/xmake.h>
+#include    "hashtab.h"
+#include    "lib.h"
+#include    "read.h"
+#include    "report.h"
+#include    "variable.h"
+#include    "xmake.h"
 
 struct linebuf {
 
diff --git a/variable.h b/variable.h
new file mode 100644 (file)
index 0000000..95573cb
--- /dev/null
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * @file            variable.h
+ *****************************************************************************/
+#ifndef     _VARIABLE_H
+#define     _VARIABLE_H
+
+enum variable_flavor {
+
+    VAR_FLAVOR_RECURSIVELY_EXPANDED,
+    VAR_FLAVOR_SIMPLY_EXPANDED,
+    VAR_FLAVOR_IMMEDIATELY_EXPANDED
+
+};
+
+enum variable_origin {
+
+    VAR_ORIGIN_AUTOMATIC,
+    VAR_ORIGIN_COMMAND_LINE,
+    VAR_ORIGIN_FILE
+
+};
+
+struct variable {
+
+    char *name, *value;
+    
+    enum variable_flavor flavor;
+    enum variable_origin origin;
+
+};
+
+struct variable *variable_add (char *name, char *value, enum variable_origin origin);
+struct variable *variable_change (char *name, char *value, enum variable_origin origin);
+struct variable *variable_find (char *name);
+
+void parse_var_line (const char *filename, unsigned long line_no, char *line, enum variable_origin origin);
+char *variable_expand_line (const char *filename, unsigned long line_no, char *line);
+
+void variables_init (void);
+
+#endif      /* _VARIABLE_H */
diff --git a/xmake.c b/xmake.c
index 4878820bd6d11e845c7e024f8b4877f668e0a83d..4b1d5af5d93da910b78ca1d1449319413dff7c65 100644 (file)
--- a/xmake.c
+++ b/xmake.c
 
 #include    <stdio.h>
 
-#include    <xmake/cstr.h>
-#include    <xmake/lib.h>
-#include    <xmake/read.h>
-#include    <xmake/rule.h>
-#include    <xmake/variable.h>
-#include    <xmake/xmake.h>
+#include    "cstr.h"
+#include    "lib.h"
+#include    "read.h"
+#include    "rule.h"
+#include    "variable.h"
+#include    "xmake.h"
 
 struct variable *default_goal_var = 0;
 
@@ -302,8 +302,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu
                 p = xstrndup (p, space - p);
             }
             
-            fprintf (stderr, "%s", lbuf.start);
-            fprintf (stderr, "%s: *** [%s:%lu: %s] Error %ld\n", program_name, filename, line_no, name, dwExitCode);
+            fprintf (stderr, "%s%s: *** [%s:%lu: %s] Error %ld\n", lbuf.start, program_name, filename, line_no, name, dwExitCode);
             
             if (state->keep_going) {
                 return dwExitCode;
@@ -349,18 +348,112 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu
     
     if (pid == 0) {
     
-        char *prog = input, *space = 0, *slash;
+        char **argv;
+        int argc = 1;
+        
+        char *prog = input, *space = 0, *ptr;
+        int offset = 0, quote, i;
         
         if ((space = strchr (prog, ' '))) {
+        
+            ptr = space + 1;
+            
+            for (i = 0; ptr[i]; i++) {
+            
+                if (isspace ((int) ptr[i])) {
+                    argc++;
+                }
+            
+            }
+            
             prog = xstrndup (prog, space - prog);
+            argv = xmalloc (sizeof (*argv) * (argc + 1));
+            
+            for (i = 0; ; i++) {
+            
+                if (!isspace ((int) ptr[i])) {
+                    break;
+                }
+            
+            }
+            
+            argv[1] = ptr + i;
+            argc = 1;
+            quote = 0;
+            
+            while (ptr[i]) {
+            
+                ptr[i - offset] = ptr[i];
+                
+                if (quote) {
+                
+                    if (ptr[i] == '\\' && (ptr[i + 1] == quote || ptr[i + 1] == '\\')) {
+                    
+                        offset++;
+                        i++;
+                        
+                        ptr[i - offset] = ptr[i];
+                    
+                    } else if (ptr[i] == quote) {
+                    
+                        quote = 0;
+                        offset++;
+                    
+                    }
+                    
+                    i++;
+                
+                } else if (ptr[i] == '\'' || ptr[i] == '"') {
+                
+                    if (argv[argc] == ptr + i - offset) {
+                        argv[argc]++;
+                    }
+                    
+                    quote = ptr[i];
+                    i++;
+                
+                } else if (isspace ((int) ptr[i])) {
+                
+                    ptr[i - offset] = '\0';
+                    argc++;
+                    
+                    for (i = i + 1; ; i++) {
+                    
+                        if (!isspace ((int) ptr[i])) {
+                            break;
+                        }
+                    
+                    }
+                    
+                    argv[argc] = ptr + i - offset;
+                
+                } else {
+                    i++;
+                }
+            
+            }
+            
+            if (argv[argc] != ptr + i - offset) {
+            
+                ptr[i - offset] = '\0';
+                argc++;
+            
+            }
+        
+        } else {
+            argv = xmalloc (sizeof (*argv) * (argc + 1));
         }
         
+        argv[0] = prog;
+        argv[argc] = 0;
+        
         dup2 (pipefd[1], STDOUT_FILENO);
         
         close (pipefd[0]);
         close (pipefd[1]);
         
-        execlp (prog, (slash = strrchr (prog, '/')) ? (slash + 1) : prog, space ? skip_whitespace (space) : NULL, NULL);
+        execvp (prog, argv);
+        free (argv);
         
         printf ("%s: %s: %s\n", program_name, prog, strerror (errno));
         exit (EXIT_FAILURE);
@@ -411,7 +504,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu
     
     }
     
-    {
+    /*{
     
         char *p = lbuf.start, ch;
         
@@ -438,14 +531,13 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu
             *(p - 1) = '\0';
         }
     
-    }
+    }*/
     
     if (status) {
     
         if (!is_ignoring_errors) {
         
-            fprintf (stderr, "%s\n", lbuf.start);
-            fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status);
+            fprintf (stderr, "%s%s: *** [%s:%lu: %s] Error %d\n", lbuf.start, program_name, filename, line_no, name, status);
             
             if (state->keep_going) {
                 return status;
@@ -456,7 +548,7 @@ static int pipe_command (const char *filename, unsigned long line_no, char *inpu
         }
     
     } else {
-        printf ("%s\n", lbuf.start);
+        printf ("%s", lbuf.start);
     }
     
     return 0;
diff --git a/xmake.h b/xmake.h
new file mode 100644 (file)
index 0000000..c277782
--- /dev/null
+++ b/xmake.h
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * @file            xmake.h
+ *****************************************************************************/
+#ifndef     _XMAKE_H
+#define     _XMAKE_H
+
+struct xmake_state {
+
+    char **makefiles;
+    unsigned long nb_makefiles;
+    
+    char **goals;
+    unsigned long nb_goals;
+    
+    char **include_paths;
+    unsigned long nb_include_paths;
+    
+    char **directories;
+    unsigned long nb_directories;
+    
+    char *path;
+    int quiet, no_print;
+    
+    int dry_run, env_override, keep_going;
+    int ignore_errors;
+
+};
+
+#if     defined (__PDOS386__)
+# ifndef        __PDOS__
+#  define   __PDOS__
+# endif
+#endif
+
+extern struct xmake_state *state;
+extern const char *program_name;
+
+int rule_search_and_build (char *name);
+
+#endif      /* _XMAKE_H */