]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
More parse tree stuff
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index 22662dbe04a5f4868dd6c7321d45549fca656ef8..c796d7c6525898885dba1e340d105eb10fce2b1e 100644 (file)
--- a/main.c
+++ b/main.c
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
-#include <sys/stat.h>
 #include "gmqcc.h"
 
 int usage(const char *name) {
        printf("Usage: %s -f infile -o outfile\n", name);
        return 0;
 }
-
 int main(int argc, char **argv) {
-       struct      stat chk;
        const char *ofile = NULL;
        const char *ifile = NULL;
        int i;
-       if (argc <= 2)
+       if (argc <= 2) {
                return usage(*argv);
+       }
                
-       for (i=0; i<argc; i++) {
+       for (i=0; i < argc; i++) {
                if (argc != i + 1) {
                        switch(argv[i][0]) {
                                case '-':
@@ -52,20 +50,23 @@ int main(int argc, char **argv) {
                }
        }
        
-       if (!ofile || !ifile)
+       if (!ofile || !ifile) {
                return usage(*argv);
+       }
        
        printf("ifile: %s\n", ifile);
        printf("ofile: %s\n", ofile);
        
-       /* we check here for file existance, not in the lexer */
-       if (stat(ifile, &chk) != 0)
-               return error(ERROR_COMPILER, "source file `%s` not found\n", ifile);
-       
-       struct lex_file *lex = lex_open(ifile);
-       lex_debug(lex);
-       parse    (lex);
-       lex_close(lex);
        
+       /* Open file */
+       FILE *fp = fopen(ifile, "r");
+       if  (!fp) {
+               fclose(fp);
+               return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
+       } else {
+               struct lex_file *lex = lex_open(fp);
+               parse    (lex);
+               lex_close(lex);
+       }
        return 0;
 }