From e531f5204757feafa7e09630e4c6b66dd6be6147 Mon Sep 17 00:00:00 2001 From: kramm Date: Tue, 6 Jan 2009 21:32:47 +0000 Subject: [PATCH] added simple interface to the parser --- lib/as3/compiler.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/as3/compiler.h | 12 +++++++ 2 files changed, 108 insertions(+) create mode 100644 lib/as3/compiler.c create mode 100644 lib/as3/compiler.h diff --git a/lib/as3/compiler.c b/lib/as3/compiler.c new file mode 100644 index 0000000..af418cb --- /dev/null +++ b/lib/as3/compiler.c @@ -0,0 +1,96 @@ +/* compiler.h + + Compiler for parsing Flash2 AVM2 ABC Actionscript + + Extension module for the rfxswf library. + Part of the swftools package. + + Copyright (c) 2008/2009 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include "tokenizer.h" +#include "files.h" +#include "parser.h" +#include "parser.tab.h" +#include "compiler.h" +#include + +/* flex/bison definitions */ +extern void avm2_set_in (FILE * in_str ); +extern int avm2_parse(); +extern int avm2_lex_destroy(); + +void as3_setverbosity(int level) +{ + as3_verbosity=level; +} +void as3_add_include_dir(char*dir) +{ + add_include_dir(dir); +} + +static char registry_initialized = 0; +static char parser_initialized = 0; + +void as3_parse_file(char*filename) +{ + if(!registry_initialized) { + registry_initialized = 1; + registry_init(); + } + if(!parser_initialized) { + parser_initialized = 1; + initialize_parser(); + } + + char*fullfilename = enter_file(filename, 0); + FILE*fi = fopen(fullfilename, "rb"); + if(!fi) { + syntaxerror("Couldn't find file %s: %s", fullfilename, strerror(errno)); + } + avm2_set_in(fi); + initialize_file(filename); + avm2_parse(); + avm2_lex_destroy(); + fclose(fi); + finish_file(); +} + +static void*as3code = 0; +void* as3_getcode() +{ + if(parser_initialized) { + parser_initialized = 0; + as3code = finish_parser(); + } + return as3code; +} +char* as3_getglobalclass() +{ + return as3_globalclass; +} + +void as3_destroy() +{ + if(parser_initialized) { + parser_initialized = 0; + swf_FreeABC(finish_parser()); + } + if(as3_globalclass) { + free(as3_globalclass);as3_globalclass=0; + } +} + diff --git a/lib/as3/compiler.h b/lib/as3/compiler.h new file mode 100644 index 0000000..1a6681a --- /dev/null +++ b/lib/as3/compiler.h @@ -0,0 +1,12 @@ +#ifndef __as3_compiler_h__ +#define __as3_compiler_h__ + +void as3_setverbosity(int level); +void as3_add_include_dir(char*dir); +void as3_parse_file(char*filename); +void as3_warning(const char*format, ...); +char* as3_getglobalclass(); +void* as3_getcode(); +void as3_destroy(); + +#endif //__as3_compiler_h__ -- 1.7.10.4