added stdin support ("swfc -")
authorkramm <kramm>
Sun, 21 Jan 2007 21:20:22 +0000 (21:20 +0000)
committerkramm <kramm>
Sun, 21 Jan 2007 21:20:22 +0000 (21:20 +0000)
src/parser.lex

index b22d95c..fb0fa62 100644 (file)
@@ -326,10 +326,19 @@ void freeTokens(struct token_t*file)
 
 struct token_t* generateTokens(char*filename)
 {
-    FILE*fi = fopen(filename, "rb");
+    FILE*fi;
     int t;
     struct token_t*result;
     int num;
+
+    if(!filename)
+       return 0;
+
+    if(!strcmp(filename,"-"))
+       fi = stdin;
+    else
+       fi = fopen(filename, "rb");
+
     if(!fi) {
        printf("Couldn't find file %s\n", filename);
        return 0;
@@ -359,7 +368,8 @@ struct token_t* generateTokens(char*filename)
            result[t].text += (int)strings.buffer;
     }
 
-    fclose(fi);
+    if(fi!=stdin)
+       fclose(fi);
     return result;
 }