uses compiler.h now instead of doing everything itself
[swftools.git] / lib / as3 / main.c
1 /* main.c
2
3    Flash ActionScript 3.0 compiler
4
5    Part of the swftools package.
6
7    Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
8  
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <memory.h>
27 #include "../rfxswf.h"
28 #include "../os.h"
29 #include "files.h"
30 #include "tokenizer.h"
31 #include "parser.tab.h"
32 #include "parser.h"
33 #include "compiler.h"
34
35 void test_lexer(char*filename)
36 {
37     char*fullfilename = enter_file(filename, 0);
38     FILE*fi = fopen(fullfilename, "rb");
39     avm2_set_in(fi);
40     while(1) {
41         int token = avm2_lex();
42         if(token==T_EOF)
43             break;
44         if(token>=32 && token<256) {
45             printf("'%c'\n", token);
46         } else {
47             printf("%s\n", token2string(token, avm2_lval));
48         }
49     }
50 }
51
52 int main(int argn, char*argv[])
53 {
54     char*filename = 0;
55     char buf[512];
56     
57     if(argn<=1) {
58         fprintf(stderr, "please supply a filename\n");
59         exit(1);
60     }
61     filename=argv[1];
62     
63     if(argn>2 && !strcmp(argv[2], "-lex")) {
64         test_lexer(filename);
65         return 0;
66     }
67     
68     as3_add_include_dir(getcwd(buf, 512));
69     as3_parse_file(filename);
70     void*code = as3_getcode();
71
72     SWF swf;
73     memset(&swf, 0, sizeof(swf));
74     swf.fileVersion = 9;
75     swf.frameRate = 0x2500;
76     swf.movieSize.xmin = swf.movieSize.ymin = 0;
77     swf.movieSize.xmax = 20*20;
78     swf.movieSize.ymax = 10*20;
79     TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC);
80     swf_WriteABC(tag, code);
81
82     if(as3_getglobalclass()) {
83         tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
84         swf_SetU16(tag, 1);
85         swf_SetU16(tag, 0);
86         swf_SetString(tag, as3_getglobalclass());
87     } else {
88         printf("Warning: no global public MovieClip subclass\n");
89     }
90
91     tag = swf_InsertTag(tag, ST_SHOWFRAME);
92     tag = swf_InsertTag(tag, ST_END);
93
94     swf_FreeABC(code);
95
96     int f = open("abc.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
97     swf_WriteSWF(f,&swf);
98     close(f);
99
100     swf_FreeTags(&swf);
101
102     return 0;
103 }