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
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
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
xmake.exe: $(SRC)
- wcl -I.\\include -fe=$@ $^
+ wcl -fe=$@ $^
clean:
--- /dev/null
+/******************************************************************************
+ * @file command.h
+ *****************************************************************************/
+#ifndef _COMMAND_H
+#define _COMMAND_H
+
+struct commands {
+
+ char *text;
+ unsigned long len;
+
+};
+
+#endif /* _COMMAND_H */
#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) {
--- /dev/null
+/******************************************************************************
+ * @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 */
--- /dev/null
+/******************************************************************************
+ * @file dep.h
+ *****************************************************************************/
+#ifndef _DEP_H
+#define _DEP_H
+
+struct dep {
+
+ char *name;
+ struct dep *next;
+
+};
+
+#endif /* _DEP_H */
#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) {
--- /dev/null
+/******************************************************************************
+ * @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 */
+++ /dev/null
-/******************************************************************************
- * @file command.h
- *****************************************************************************/
-#ifndef _COMMAND_H
-#define _COMMAND_H
-
-struct commands {
-
- char *text;
- unsigned long len;
-
-};
-
-#endif /* _COMMAND_H */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @file dep.h
- *****************************************************************************/
-#ifndef _DEP_H
-#define _DEP_H
-
-struct dep {
-
- char *name;
- struct dep *next;
-
-};
-
-#endif /* _DEP_H */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
+++ /dev/null
-/******************************************************************************
- * @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 */
#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;
--- /dev/null
+/******************************************************************************
+ * @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 */
#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;
--- /dev/null
+/******************************************************************************
+ * @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 */
#include <stdio.h>
#include <string.h>
-#include <xmake/report.h>
-
+#include "report.h"
unsigned long errors = 0;
#ifndef __PDOS__
--- /dev/null
+/******************************************************************************
+ * @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 */
*****************************************************************************/
#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;
--- /dev/null
+/******************************************************************************
+ * @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 */
#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 {
--- /dev/null
+/******************************************************************************
+ * @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 */
#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;
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;
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);
}
- {
+ /*{
char *p = lbuf.start, ch;
*(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;
}
} else {
- printf ("%s\n", lbuf.start);
+ printf ("%s", lbuf.start);
}
return 0;
--- /dev/null
+/******************************************************************************
+ * @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 */