int opts_standard = COMPILER_GMQCC;
bool opts_debug = false;
bool opts_memchk = false;
+bool opts_dump = false;
+
+static bool opts_output_wasset = false;
typedef struct { char *filename; int type; } argitem;
VECTOR_MAKE(argitem, items);
opts_debug = true;
continue;
}
+ if (!strcmp(argv[0]+1, "dump")) {
+ opts_dump = true;
+ continue;
+ }
if (!strcmp(argv[0]+1, "memchk")) {
opts_memchk = true;
continue;
return false;
}
opts_output = argarg;
+ opts_output_wasset = true;
break;
case 'a':
}
else {
/* All long options with arguments */
- if (options_long_witharg("output", &argc, &argv, &argarg))
+ if (options_long_witharg("output", &argc, &argv, &argarg)) {
opts_output = argarg;
- else
- {
+ opts_output_wasset = true;
+ } else {
printf("Unknown parameter: %s\n", argv[0]);
return false;
}
#endif
}
-bool parser_init();
-bool parser_compile(const char *filename);
-bool parser_finish(const char *output);
-void parser_cleanup();
+/* returns the line number, or -1 on error */
+static bool progs_nextline(char **out, FILE *src)
+{
+ size_t alen;
+ int len;
+ char *line;
+ char *start;
+ char *end;
+
+ line = *out;
+ len = util_getline(&line, &alen, src);
+ if (len == -1)
+ return false;
+
+ /* start at first non-blank */
+ for (start = line; isspace(*start); ++start) {}
+ /* end at the first non-blank */
+ for (end = start; *end && !isspace(*end); ++end) {}
+
+ *out = line;
+ /* move the actual filename to the beginning */
+ while (start != end) {
+ *line++ = *start++;
+ }
+ *line = 0;
+ return true;
+}
int main(int argc, char **argv) {
size_t itr;
+ int retval = 0;
+ bool opts_output_free = false;
+
app_name = argv[0];
/* default options / warn flags */
options_set(opts_warn, WARN_UNKNOWN_CONTROL_SEQUENCE, true);
+ options_set(opts_warn, WARN_EXTENSIONS, true);
+ options_set(opts_warn, WARN_FIELD_REDECLARED, true);
if (!options_parse(argc, argv)) {
return usage();
}
- for (itr = 0; itr < COUNT_FLAGS; ++itr) {
- printf("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
- }
- for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
- printf("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
+ if (opts_dump) {
+ for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+ printf("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
+ }
+ for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+ printf("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
+ }
+ printf("output = %s\n", opts_output);
+ printf("optimization level = %i\n", (int)opts_O);
+ printf("standard = %i\n", opts_standard);
}
- printf("output = %s\n", opts_output);
- printf("optimization level = %i\n", (int)opts_O);
- printf("standard = %i\n", opts_standard);
if (!parser_init()) {
printf("failed to initialize parser\n");
+ retval = 1;
goto cleanup;
}
(items_data[itr].type == TYPE_SRC ? "progs.src" :
("unknown"))))));
- if (!parser_compile(items_data[itr].filename))
+ if (!parser_compile(items_data[itr].filename)) {
+ retval = 1;
goto cleanup;
+ }
}
parser_finish(opts_output);
} else {
- printf("Mode: progs.src - not implemented\n");
+ FILE *src;
+ char *line;
+
+ printf("Mode: progs.src\n");
+ src = util_fopen("progs.src", "rb");
+ if (!src) {
+ printf("failed to open `progs.src` for reading\n");
+ retval = 1;
+ goto cleanup;
+ }
+
+ line = NULL;
+ if (!progs_nextline(&line, src) || !line[0]) {
+ printf("illformatted progs.src file: expected output filename in first line\n");
+ retval = 1;
+ goto srcdone;
+ }
+
+ if (!opts_output_wasset) {
+ opts_output = util_strdup(line);
+ opts_output_free = true;
+ }
+
+ while (progs_nextline(&line, src)) {
+ if (!line[0] || (line[0] == '/' && line[1] == '/'))
+ continue;
+ printf(" src: %s\n", line);
+ if (!parser_compile(line)) {
+ retval = 1;
+ goto srcdone;
+ }
+ }
+
+ parser_finish(opts_output);
+
+srcdone:
+ fclose(src);
+ mem_d(line);
}
/* stuff */
util_debug("COM", "cleaning ...\n");
parser_cleanup();
+ if (opts_output_free)
+ mem_d((char*)opts_output);
util_meminfo();
- return 0;
+ return retval;
}