Correct off-by-whatever errors of the source position in parse_select_expression().
[cparser] / main.c
diff --git a/main.c b/main.c
index 1ca12b1..1c63e0b 100644 (file)
--- 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 */
@@ -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                 :
@@ -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(EXIT_SUCCESS);
+                               return EXIT_SUCCESS;
                        }
 
                        if (mode == CompileExportIR) {
                                fclose(out);
                                ir_export(outname);
-                               exit(EXIT_SUCCESS);
+                               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(EXIT_FAILURE);
+                       return EXIT_FAILURE;
                }
        }