integrated as3 compiler into swfc
authorMatthias Kramm <kramm@quiss.org>
Sun, 8 Mar 2009 15:21:28 +0000 (16:21 +0100)
committerMatthias Kramm <kramm@quiss.org>
Sun, 8 Mar 2009 15:21:28 +0000 (16:21 +0100)
lib/as3/compiler.c
lib/as3/compiler.h
lib/as3/import.c
lib/as3/import.h
lib/rfxswf.h
src/as3compile.c
src/as3compile.doc
src/parser.lex
src/parser.yy.c
src/swfc.c

index 89b746e..0272650 100644 (file)
@@ -85,7 +85,7 @@ int a3_lex()
 #endif
 }
 
-static void as3_parse_file_or_array(int pass, const char*name, const char*filename, void*mem, int length)
+static void as3_parse_file_or_array(int pass, const char*name, const char*filename, const void*mem, int length)
 {
     if(!registry_initialized) {
         registry_initialized = 1;
@@ -108,7 +108,7 @@ static void as3_parse_file_or_array(int pass, const char*name, const char*filena
     } else {
         DEBUG printf("[pass %d] parse bytearray %s (%d bytes)\n", pass, name, length);
         enter_file(name, name, 0);
-        as3_buffer_input(mem, length);
+        as3_buffer_input((void*)mem, length);
     }
 
     as3_tokencount=0;
@@ -173,7 +173,7 @@ void as3_schedule_file(const char*name, const char*filename)
     scheduled = f;
 }
 
-void as3_parse_bytearray(const char*name, void*mem, int length)
+void as3_parse_bytearray(const char*name, const void*mem, int length)
 {
     as3_parse_file_or_array(1, name, 0, mem, length);
     as3_parse_scheduled(1);
index 7786e7a..fdf0310 100644 (file)
@@ -5,7 +5,7 @@ void as3_setverbosity(int level);
 void as3_add_include_dir(char*dir);
 
 void as3_parse_file(const char*filename);
-void as3_parse_bytearray(const char*name, void*mem, int length);
+void as3_parse_bytearray(const char*name, const void*mem, int length);
 void as3_parse_directory(const char*dir);
 
 char as3_schedule_directory(const char*dir);
index c38f02e..dd42cfb 100644 (file)
@@ -108,8 +108,9 @@ static classinfo_t*resolve_class(char*what, multiname_t*n)
     return c;
 }
 
-void as3_import_code(abc_file_t*abc)
+void as3_import_code(void*_abc)
 {
+    abc_file_t*abc = _abc;
     int t;
     for(t=0;t<abc->classes->num;t++) {
         abc_class_t*cls = array_getvalue(abc->classes, t);
index b963b4d..2bfaaa1 100644 (file)
 #ifndef __as3_import_h__
 #define __as3_import_h__
 
-#include "abc.h"
-
 void as3_import_file(char*filename);
 void as3_import_swf(char*filename);
 void as3_import_abc(char*filename);
-void as3_import_code(abc_file_t*f);
+void as3_import_code(void*f);
+
 #endif
index 2f6c429..d4b0424 100644 (file)
@@ -753,6 +753,7 @@ void swf_FreeABC(void*code);
 void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events);
 TAG*swf_AddAS3FontDefine(TAG*tag, U16 id, char*fontname);
 #include "as3/compiler.h"
+#include "as3/import.h"
 
 // swfaction.c
 
index 4f0193e..89252f5 100644 (file)
@@ -38,6 +38,8 @@ 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 struct options_t options[] = {
 {"h", "help"},
@@ -102,6 +104,16 @@ int args_callback_option(char*name,char*val)
         as3_add_include_dir(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);
@@ -218,6 +230,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);
index a24543c..b370903 100644 (file)
@@ -24,6 +24,10 @@ Compiles a file written in ActionScript to a SWF file.
     Include library file <file>
 -I, --include <dir>
     Add include dir <dir>
+-N, --local-with-network
+    Make output file "local with networking"
+-L, --local-with-filesystem
+    Make output file "local with filesystem"
 -T, --flashversion <num>
     Set target SWF flash version to <num>.
     <num> must be >= 9.
index 138e740..a4338e8 100644 (file)
@@ -157,12 +157,12 @@ static void store(enum type_t type, int line, int column, char*text, int length)
 }
 
 #define MAX_INCLUDE_DEPTH 16
-YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
-int line_stack[MAX_INCLUDE_DEPTH];
-int column_stack[MAX_INCLUDE_DEPTH];
-int include_stack_ptr = 0;
+static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+static int line_stack[MAX_INCLUDE_DEPTH];
+static int column_stack[MAX_INCLUDE_DEPTH];
+static int include_stack_ptr = 0;
 
-void handleInclude(char*text, int len)
+static void handleInclude(char*text, int len)
 {
     text+=9;len-=9;
     while(len >=1 && (text[0] == ' ' || text[0] == '\t')) {
index 3ee201e..175d72d 100644 (file)
@@ -734,12 +734,12 @@ static void store(enum type_t type, int line, int column, char*text, int length)
 }
 
 #define MAX_INCLUDE_DEPTH 16
-YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
-int line_stack[MAX_INCLUDE_DEPTH];
-int column_stack[MAX_INCLUDE_DEPTH];
-int include_stack_ptr = 0;
+static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+static int line_stack[MAX_INCLUDE_DEPTH];
+static int column_stack[MAX_INCLUDE_DEPTH];
+static int include_stack_ptr = 0;
 
-void handleInclude(char*text, int len)
+static void handleInclude(char*text, int len)
 {
     text+=9;len-=9;
     while(len >=1 && (text[0] == ' ' || text[0] == '\t')) {
index 2cc9887..646ec80 100644 (file)
@@ -177,6 +177,7 @@ static struct level
    /* for swf (0): */
    SWF*swf;
    char*filename;
+   char as3;
 
    /* for sprites (1): */
    TAG*tag;
@@ -1029,6 +1030,22 @@ static void s_endSWF()
     //    tag = swf_InsertTag(tag, ST_SHOWFRAME);
     tag = swf_InsertTag(tag, ST_SHOWFRAME);
 
+    if(stack[0].as3) {
+        TAG*tag = swf->firstTag;
+        tag = swf_InsertTag(tag, ST_DOABC);
+        void*code = as3_getcode();
+        swf_WriteABC(tag, code);
+        if(as3_getglobalclass()) {
+            tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
+            swf_SetU16(tag, 1);
+            swf_SetU16(tag, 0);
+            swf_SetString(tag, as3_getglobalclass());
+        } else {
+            warning("no global public MovieClip subclass");
+        }
+        as3_destroy();
+    }
+
     tag = swf_InsertTag(tag, ST_END);
 
     swf_OptimizeTagOrder(swf);
@@ -1864,19 +1881,20 @@ void s_blur(const char*name, double blurx, double blury, int passes)
 
 void s_action(const char*text)
 {
-    ActionTAG* a = 0;
-    a = swf_ActionCompile(text, stack[0].swf->fileVersion);
-    if(!a)
-    {
+    if(stack[0].swf->fileVersion < 9) {
+        ActionTAG* a = 0;
+        a = swf_ActionCompile(text, stack[0].swf->fileVersion);
+        if(!a) {
+            swf_ActionFree(a);
+            syntaxerror("Couldn't compile ActionScript");
+        }
+        tag = swf_InsertTag(tag, ST_DOACTION);
+        swf_ActionSet(tag, a);
         swf_ActionFree(a);
-        syntaxerror("Couldn't compile ActionScript");
+    } else {
+        as3_parse_bytearray(stack[0].filename, text, strlen(text));
+        stack[0].as3 = 1;
     }
-
-    tag = swf_InsertTag(tag, ST_DOACTION);
-
-    swf_ActionSet(tag, a);
-
-    swf_ActionFree(a);
 }
 
 void s_initaction(const char*character, const char*text)