]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
Cleanups
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index 8718a72afb74b14051b9e2b1df0ed71a223cd4f3..52413ca084608d2b64a7eb1bb4f8d6f7b047c579 100644 (file)
--- a/main.c
+++ b/main.c
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
+#include <stdlib.h>
+#include <string.h>
+#include <limits.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) {
-       if (argc <= 1) {
-               printf("Usage: %s infile.qc outfile\n", *argv);
-               return -1;
+       const char *ofile = NULL;
+       const char *ifile = NULL;
+       int i;
+       if (argc <= 2) {
+               return usage(*argv);
+       }
+               
+       for (i=0; i < argc; i++) {
+               if (argc != i + 1) {
+                       switch(argv[i][0]) {
+                               case '-':
+                                       switch(argv[i][1]) {
+                                               case 'f': ifile = argv[i+1]; break;
+                                               case 'o': ofile = argv[i+1]; break;
+                                       }
+                                       break;
+                       }
+               }
        }
        
-       struct lex_file *lex = lex_open(argv[1]);
-       lex_debug(lex);
-       parse    (lex);
-       lex_close(lex);
+       if (!ofile || !ifile) {
+               return usage(*argv);
+       }
        
+       printf("ifile: %s\n", ifile);
+       printf("ofile: %s\n", ofile);
+       
+       
+       /* 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_tree(lex); /* generate parse tree */
+               lex_close (lex); /* cleanup  lexer      */
+       }
        return 0;
 }