X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=ec09657045ece963871d1127e4a25de79dd3bfeb;hb=c4004b40b7e11ae7ff32c26b330e5f33a7abe2d3;hp=5e2c7bc9a2f3fa6b48172ad9e4d5e3cc8e4a661a;hpb=5fa879eb4cc6e5187e1e673e154b11f5a6f813ce;p=cparser diff --git a/main.c b/main.c index 5e2c7bc..ec09657 100644 --- a/main.c +++ b/main.c @@ -345,7 +345,7 @@ static FILE *preprocess(const char *fname, filetype_t filetype) FILE *f = popen(buf, "r"); if (f == NULL) { fprintf(stderr, "invoking preprocessor failed\n"); - exit(1); + exit(EXIT_FAILURE); } /* we don't really need that anymore */ @@ -381,7 +381,7 @@ static void assemble(const char *out, const char *in) int err = system(buf); if (err != 0) { fprintf(stderr, "assembler reported an error\n"); - exit(1); + exit(EXIT_FAILURE); } obstack_free(&asflags_obst, NULL); @@ -415,7 +415,7 @@ static void print_file_name(const char *file) int err = system(commandline); if (err != EXIT_SUCCESS) { fprintf(stderr, "linker reported an error\n"); - exit(1); + exit(EXIT_FAILURE); } } @@ -483,12 +483,12 @@ static FILE *make_temp_file(char *buffer, size_t buflen, const char *prefix) if (fd == -1) { fprintf(stderr, "couldn't create temporary file: %s\n", strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } FILE *out = fdopen(fd, "w"); if (out == NULL) { fprintf(stderr, "couldn't create temporary file FILE*\n"); - exit(1); + exit(EXIT_FAILURE); } file_list_entry_t *entry = xmalloc(sizeof(*entry)); @@ -636,7 +636,7 @@ static FILE *open_file(const char *filename) if (in == NULL) { fprintf(stderr, "Couldn't open '%s': %s\n", filename, strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } return in; @@ -934,6 +934,13 @@ int main(int argc, char **argv) GET_ARG_AFTER(opt, "-isystem"); add_flag(&cppflags_obst, "-isystem"); add_flag(&cppflags_obst, "%s", opt); +#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__CYGWIN__) + } else if (streq(option, "pthread")) { + /* set flags for the preprocessor */ + add_flag(&cppflags_obst, "-D_REENTRANT"); + /* set flags for the linker */ + add_flag(&ldflags_obst, "-lpthread"); +#endif } else if (streq(option, "nostdinc") || streq(option, "trigraphs")) { /* pass these through to the preprocessor */ @@ -1025,7 +1032,7 @@ int main(int argc, char **argv) } } else if (option[0] == 'W') { if (option[1] == '\0') { - /* ignore -W, out defaults are already quiet verbose */ + /* ignore -W, our defaults are already quite verbose */ } else if (strstart(option + 1, "p,")) { // pass options directly to the preprocessor const char *opt; @@ -1191,11 +1198,29 @@ int main(int argc, char **argv) mode = PrintCaml; } else if (streq(option, "print-jna")) { mode = PrintJna; + } else if (streq(option, "jna-limit")) { + ++i; + if (i >= argc) { + fprintf(stderr, "error: " + "expected argument after '--jna-limit'\n"); + argument_errors = true; + break; + } + jna_limit_output(argv[i]); + } else if (streq(option, "jna-libname")) { + ++i; + if (i >= argc) { + fprintf(stderr, "error: " + "expected argument after '--jna-libname'\n"); + argument_errors = true; + break; + } + jna_set_libname(argv[i]); } else if (streq(option, "time")) { do_timing = true; } else if (streq(option, "version")) { print_cparser_version(); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } else if (streq(option, "help")) { print_help(argv[0]); help_displayed = true; @@ -1234,9 +1259,14 @@ int main(int argc, char **argv) streq(suffix, "S") ? FILETYPE_ASSEMBLER : streq(suffix, "a") ? FILETYPE_OBJECT : streq(suffix, "c") ? FILETYPE_C : + streq(suffix, "C") ? FILETYPE_CXX : streq(suffix, "cc") ? FILETYPE_CXX : + streq(suffix, "cp") ? FILETYPE_CXX : streq(suffix, "cpp") ? FILETYPE_CXX : + streq(suffix, "CPP") ? FILETYPE_CXX : streq(suffix, "cxx") ? FILETYPE_CXX : + streq(suffix, "c++") ? FILETYPE_CXX : + streq(suffix, "ii") ? FILETYPE_CXX : streq(suffix, "h") ? FILETYPE_C : streq(suffix, "ir") ? FILETYPE_IR : streq(suffix, "o") ? FILETYPE_OBJECT : @@ -1268,7 +1298,7 @@ int main(int argc, char **argv) if (print_file_name_file != NULL) { print_file_name(print_file_name_file); - return 0; + return EXIT_SUCCESS; } if (files == NULL) { fprintf(stderr, "error: no input files specified\n"); @@ -1277,7 +1307,7 @@ int main(int argc, char **argv) if (argument_errors) { usage(argv[0]); - return 1; + return EXIT_FAILURE; } /* we do the lowering in ast2firm */ @@ -1364,7 +1394,7 @@ int main(int argc, char **argv) if (out == NULL) { fprintf(stderr, "Couldn't open '%s' for writing: %s\n", outname, strerror(errno)); - return 1; + return EXIT_FAILURE; } } @@ -1384,7 +1414,7 @@ int main(int argc, char **argv) in = open_file(filename); lextest(in, filename); fclose(in); - exit(EXIT_SUCCESS); + return EXIT_SUCCESS; } FILE *preprocessed_in = NULL; @@ -1511,7 +1541,7 @@ do_parsing: /* remove output file */ if (out != stdout) unlink(outname); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } } @@ -1561,18 +1591,18 @@ graph_built: if (irg == NULL) { fprintf(stderr, "No graph for function '%s' found\n", dumpfunction); - exit(1); + return EXIT_FAILURE; } dump_ir_graph_file(out, irg); fclose(out); - exit(0); + return EXIT_SUCCESS; } if (mode == CompileExportIR) { fclose(out); ir_export(outname); - exit(0); + return EXIT_SUCCESS; } gen_firm_finish(asm_out, filename, have_const_functions); @@ -1673,7 +1703,7 @@ graph_built: int err = system(commandline); if (err != EXIT_SUCCESS) { fprintf(stderr, "linker reported an error\n"); - exit(1); + return EXIT_FAILURE; } } @@ -1693,5 +1723,5 @@ graph_built: exit_types(); exit_tokens(); exit_symbol_table(); - return 0; + return EXIT_SUCCESS; }