fix input from stdin
authorMatthias Braun <matze@braunis.de>
Fri, 11 Jul 2008 08:24:14 +0000 (08:24 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 11 Jul 2008 08:24:14 +0000 (08:24 +0000)
[r20422]

Makefile
main.c

index 60dcb5f..1f8c7b1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -109,7 +109,7 @@ $(DIRS):
 
 build/cpb/%.o: %.c build/cparser
        @echo '===> CPARSER $<'
-       $(Q)./build/cparser $(CPPFLAGS) -Wall -g -c $< -o $@
+       $(Q)./build/cparser $(CPPFLAGS) -Wall -g3 -c $< -o $@
 
 build/cpb2/%.o: %.c cparser.bootstrap
        @echo '===> CPARSER.BOOTSTRAP $<'
diff --git a/main.c b/main.c
index 7b4d0c1..5e66ff1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -463,7 +463,7 @@ int main(int argc, char **argv)
        bool argument_errors = false;
        for(int i = 1; i < argc; ++i) {
                const char *arg = argv[i];
-               if(arg[0] == '-') {
+               if(arg[0] == '-' && arg[1] != 0) {
                        /* an option */
                        const char *option = &arg[1];
                        if(option[0] == 'o') {
@@ -692,15 +692,22 @@ int main(int argc, char **argv)
                        }
                } else {
 
+                       file_list_entry_t *entry
+                               = obstack_alloc(&file_obst, sizeof(entry[0]));
+                       entry->filename = arg;
+
                        size_t len = strlen(arg);
                        if (len < 2) {
+                               if (arg[0] == '-') {
+                                       /* exception: '-' as name reads C from stdin */
+                                       entry->next = c_files;
+                                       c_files     = entry;
+                                       continue;
+                               }
                                fprintf(stderr, "'%s': file format not recognized\n", input);
                                continue;
                        }
 
-                       file_list_entry_t *entry
-                               = obstack_alloc(&file_obst, sizeof(entry[0]));
-                       entry->filename = arg;
                        if (strcmp(arg+len-2, ".c") == 0) {
                                entry->next = c_files;
                                c_files     = entry;
@@ -721,7 +728,11 @@ int main(int argc, char **argv)
        } else if (c_files != NULL && c_files->next == NULL) {
                input = c_files->filename;
        } else {
-               fprintf(stderr, "error: multiple input files specified\n");
+               if (c_files == NULL) {
+                       fprintf(stderr, "error: no input files specified\n");
+               } else {
+                       fprintf(stderr, "error: multiple input files specified\n");
+               }
                argument_errors = true;
        }