fixed bug in jpeg2000 decoding
[swftools.git] / src / as3compile.c
index 4f0193e..9ee4569 100644 (file)
@@ -38,6 +38,9 @@ static double width = 400;
 static double height = 300;
 static int flashversion = 9;
 static int verbose = 1;
+static char local_with_networking = 0;
+static char local_with_filesystem = 0;
+static char*mainclass = 0;
 
 static struct options_t options[] = {
 {"h", "help"},
@@ -45,11 +48,16 @@ static struct options_t options[] = {
 {"v", "verbose"},
 {"q", "quiet"},
 {"C", "cgi"},
+{"R", "resolve"},
+{"D", "define"},
 {"X", "width"},
 {"Y", "height"},
 {"r", "rate"},
+{"M", "mainclass"},
 {"l", "library"},
 {"I", "include"},
+{"N", "local-with-network"},
+{"L", "local-with-filesystem"},
 {"T", "flashversion"},
 {"o", "output"},
 {0,0}
@@ -70,6 +78,10 @@ int args_callback_option(char*name,char*val)
        framerate = atof(val);
         return 1;
     }
+    else if(!strcmp(name, "M")) {
+        mainclass = val;
+        return 1;
+    }
     else if(!strcmp(name, "v")) {
        verbose++;
         return 0;
@@ -94,14 +106,36 @@ int args_callback_option(char*name,char*val)
        do_cgi = 1;
        return 0;
     }
-    else if(!strcmp(name, "-l")) {
+    else if(!strcmp(name, "l")) {
         as3_import_file(val);
        return 1;
     }
-    else if(!strcmp(name, "-I")) {
+    else if(!strcmp(name, "I")) {
         as3_add_include_dir(val);
        return 1;
     }
+    else if(!strcmp(name, "R")) {
+        as3_set_option("recurse","1");
+       return 0;
+    }
+    else if(!strcmp(name, "D")) {
+        if(!strstr(val, "::")) {
+            fprintf(stderr, "Error: compile definition must contain \"::\"\n");
+            exit(1);
+        }
+        as3_set_define(val);
+       return 1;
+    }
+    else if (!strcmp(name, "N"))
+    {
+       local_with_networking = 1;
+       return 0;
+    }
+    else if (!strcmp(name, "L"))
+    {
+       local_with_filesystem = 1;
+       return 0;
+    }
     else {
         printf("Unknown option: -%s\n", name);
        exit(1);
@@ -122,11 +156,16 @@ void args_callback_usage(char *name)
     printf("-v , --verbose                 Increase verbosity\n");
     printf("-q , --quiet                   Decrease verbosity\n");
     printf("-C , --cgi                     Output to stdout (for use in CGI environments)\n");
+    printf("-R , --resolve                 Try to resolve undefined classes automatically.\n");
+    printf("-D , --define <namespace::variable>    Set a compile time variable (for doing conditional compilation)\n");
     printf("-X , --width                   Set target SWF width\n");
     printf("-Y , --height                  Set target SWF width\n");
     printf("-r , --rate                    Set target SWF framerate\n");
-    printf("-l , --library <file>          Include library file <file>\n");
-    printf("-I , --include <dir>           Add include dir <dir>\n");
+    printf("-M , --mainclass               Set the name of the main class (extending flash.display.MovieClip or .Sprite)\n");
+    printf("-l , --library <file>          Include library file <file>. <file> can be an .abc or .swf file.\n");
+    printf("-I , --include <dir>           Add additional include dir <dir>.\n");
+    printf("-N , --local-with-network      Make output file \"local with networking\"\n");
+    printf("-L , --local-with-filesystem     Make output file \"local with filesystem\"\n");
     printf("-T , --flashversion <num>      Set target SWF flash version to <num>.\n");
     printf("-o , --output <filename>       Set output file to <filename>.\n");
     printf("\n");
@@ -174,7 +213,6 @@ int main (int argc,char ** argv)
     } else {
         as3_add_include_dir(currentdir);
     }
-    registry_init();
 
     int t;
     processargs(argc, argv);
@@ -189,7 +227,12 @@ int main (int argc,char ** argv)
         //as3_warning("output name not given, writing to %s", outputname);
     }
 
-    as3_parse_file(filename);
+    if(!strcmp(filename, ".")) {
+        as3_parse_directory(".");
+    } else {
+        as3_parse_file(filename);
+    }
+
     void*code = as3_getcode();
 
     SWF swf;
@@ -203,11 +246,13 @@ int main (int argc,char ** argv)
     TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC);
     swf_WriteABC(tag, code);
 
-    if(as3_getglobalclass()) {
+    if(!mainclass)
+        mainclass = as3_getglobalclass();
+    if(mainclass) {
         tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
         swf_SetU16(tag, 1);
         swf_SetU16(tag, 0);
-        swf_SetString(tag, as3_getglobalclass());
+        swf_SetString(tag, mainclass);
     } else {
         as3_warning("no global public MovieClip subclass");
     }
@@ -218,6 +263,11 @@ int main (int argc,char ** argv)
     tag = swf_InsertTag(tag, ST_END);
 
     swf_FreeABC(code);
+    
+    if(local_with_filesystem)
+        swf.fileAttributes &= ~FILEATTRIBUTE_USENETWORK;
+    if(local_with_networking)
+        swf.fileAttributes |= FILEATTRIBUTE_USENETWORK;
 
     writeSWF(&swf);
     swf_FreeTags(&swf);