as3: improved protected handling, xml support. added 'arguments' keyword
[swftools.git] / lib / as3 / main.c
index a5a4b62..df7aed3 100644 (file)
 #include "../rfxswf.h"
 #include "../os.h"
 #include "files.h"
+#include "common.h"
 #include "tokenizer.h"
 #include "parser.tab.h"
 #include "parser.h"
 #include "compiler.h"
+#include "import.h"
 
 void test_lexer(char*filename)
 {
-    char*fullfilename = enter_file(filename, 0);
+    char*fullfilename = find_file(filename, 1);
+    enter_file(filename, fullfilename, 0);
     FILE*fi = fopen(fullfilename, "rb");
-    avm2_set_in(fi);
+    as3_file_input(fi);
     while(1) {
-        int token = avm2_lex();
+        int token = as3_lex();
         if(token==T_EOF)
             break;
         if(token>=32 && token<256) {
             printf("'%c'\n", token);
         } else {
-            printf("%s\n", token2string(token, avm2_lval));
+            printf("%s\n", token2string(token, a3_lval));
         }
     }
 }
 
+extern int a3_debug;
 int main(int argn, char*argv[])
 {
     char*filename = 0;
@@ -58,18 +62,55 @@ int main(int argn, char*argv[])
         fprintf(stderr, "please supply a filename\n");
         exit(1);
     }
-    filename=argv[1];
-    
-    if(argn>2 && !strcmp(argv[2], "-lex")) {
-        test_lexer(filename);
-        return 0;
+    filename=argv[argn-1];
+
+    //a3_debug = 1; //if bison was called with -t
+   
+    as3_add_include_dir(getcwd(buf, 512));
+
+    registry_init();
+
+    int t=0;
+    for(t=1;t<argn-1;t++) {
+        if(!strcmp(argv[t], "-lex")) {
+            test_lexer(filename);
+            return 0;
+        }
+        if(!strcmp(argv[t], "-v")) {
+            as3_verbosity++;
+        }
+        if(!strcmp(argv[t], "-q")) {
+            as3_verbosity--;
+        }
+        if(!strcmp(argv[t], "-D")) {
+            char*c = argv[t+1];
+            if(!strstr(c, "::"))
+                printf("Error: compile definition must contain \"::\"\n");
+            as3_set_define(c);
+        }
+        if(!strcmp(argv[t], "-R")) {
+            as3_set_option("recurse","1");
+        }
+        if(!strcmp(argv[t], "-I")) {
+            as3_add_include_dir(argv[++t]);
+        }
+        if(!strcmp(argv[t], "-l")) {
+            as3_import_file(argv[++t]);
+        }
     }
 
     //extern int avm2_debug;
     //avm2_debug = 1;
-    
-    as3_add_include_dir(getcwd(buf, 512));
-    as3_parse_file(filename);
+
+    //memfile_t*m = memfile_open(filename);
+    //as3_parse_bytearray(filename, m->data, m->len);
+    //memfile_close(m);
+    if(!strcmp(filename, ".")) {
+        as3_parse_directory(".");
+    } else {
+        as3_parse_file(filename);
+    }
+
     void*code = as3_getcode();
 
     SWF swf;