From 65dec90461cf9ceb574ba89189a65980960a3f56 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Sun, 8 Mar 2009 16:21:28 +0100 Subject: [PATCH] integrated as3 compiler into swfc --- lib/as3/compiler.c | 6 +++--- lib/as3/compiler.h | 2 +- lib/as3/import.c | 3 ++- lib/as3/import.h | 5 ++--- lib/rfxswf.h | 1 + src/as3compile.c | 17 +++++++++++++++++ src/as3compile.doc | 4 ++++ src/parser.lex | 10 +++++----- src/parser.yy.c | 10 +++++----- src/swfc.c | 40 +++++++++++++++++++++++++++++----------- 10 files changed, 69 insertions(+), 29 deletions(-) diff --git a/lib/as3/compiler.c b/lib/as3/compiler.c index 89b746e..0272650 100644 --- a/lib/as3/compiler.c +++ b/lib/as3/compiler.c @@ -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); diff --git a/lib/as3/compiler.h b/lib/as3/compiler.h index 7786e7a..fdf0310 100644 --- a/lib/as3/compiler.h +++ b/lib/as3/compiler.h @@ -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); diff --git a/lib/as3/import.c b/lib/as3/import.c index c38f02e..dd42cfb 100644 --- a/lib/as3/import.c +++ b/lib/as3/import.c @@ -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;tclasses->num;t++) { abc_class_t*cls = array_getvalue(abc->classes, t); diff --git a/lib/as3/import.h b/lib/as3/import.h index b963b4d..2bfaaa1 100644 --- a/lib/as3/import.h +++ b/lib/as3/import.h @@ -22,10 +22,9 @@ #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 diff --git a/lib/rfxswf.h b/lib/rfxswf.h index 2f6c429..d4b0424 100644 --- a/lib/rfxswf.h +++ b/lib/rfxswf.h @@ -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 diff --git a/src/as3compile.c b/src/as3compile.c index 4f0193e..89252f5 100644 --- a/src/as3compile.c +++ b/src/as3compile.c @@ -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); diff --git a/src/as3compile.doc b/src/as3compile.doc index a24543c..b370903 100644 --- a/src/as3compile.doc +++ b/src/as3compile.doc @@ -24,6 +24,10 @@ Compiles a file written in ActionScript to a SWF file. Include library file -I, --include Add include dir +-N, --local-with-network + Make output file "local with networking" +-L, --local-with-filesystem + Make output file "local with filesystem" -T, --flashversion Set target SWF flash version to . must be >= 9. diff --git a/src/parser.lex b/src/parser.lex index 138e740..a4338e8 100644 --- a/src/parser.lex +++ b/src/parser.lex @@ -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')) { diff --git a/src/parser.yy.c b/src/parser.yy.c index 3ee201e..175d72d 100644 --- a/src/parser.yy.c +++ b/src/parser.yy.c @@ -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')) { diff --git a/src/swfc.c b/src/swfc.c index 2cc9887..646ec80 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -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) -- 1.7.10.4