2 Compiles ActionScript 3.0 (.as) files into .swf files.
4 Part of the swftools package.
6 Copyright (c) 2008/2009 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
27 #include "../lib/rfxswf.h"
28 #include "../lib/args.h"
30 #include "../lib/os.h"
32 static char * filename = 0;
33 static char * outputname = 0;
34 static int override_outputname = 0;
35 static int do_cgi = 0;
36 static double framerate = 25.0;
37 static double width = 400;
38 static double height = 300;
39 static int flashversion = 9;
40 static int verbose = 1;
41 static char local_with_networking = 0;
42 static char local_with_filesystem = 0;
44 static struct options_t options[] = {
56 {"T", "flashversion"},
62 int args_callback_option(char*name,char*val)
64 if(!strcmp(name, "V")) {
65 printf("swfc - part of %s %s\n", PACKAGE, VERSION);
68 else if(!strcmp(name, "o")) {
70 override_outputname = 1;
73 else if(!strcmp(name, "r")) {
74 framerate = atof(val);
77 else if(!strcmp(name, "v")) {
81 else if(!strcmp(name, "q")) {
85 else if(!strcmp(name, "X")) {
89 else if(!strcmp(name, "Y")) {
93 else if(!strcmp(name, "T")) {
94 flashversion = atoi(val);
97 else if(!strcmp(name, "C")) {
101 else if(!strcmp(name, "l")) {
102 as3_import_file(val);
105 else if(!strcmp(name, "I")) {
106 as3_add_include_dir(val);
109 else if(!strcmp(name, "R")) {
110 as3_set_option("recurse","1");
113 else if(!strcmp(name, "D")) {
117 else if (!strcmp(name, "N"))
119 local_with_networking = 1;
122 else if (!strcmp(name, "L"))
124 local_with_filesystem = 1;
128 printf("Unknown option: -%s\n", name);
133 int args_callback_longoption(char*name,char*val)
135 return args_long2shortoption(options, name, val);
137 void args_callback_usage(char *name)
140 printf("Usage: %s file.as [-o file.swf] \n", name);
142 printf("-h , --help Print short help message and exit\n");
143 printf("-V , --version Print version info and exit\n");
144 printf("-v , --verbose Increase verbosity\n");
145 printf("-q , --quiet Decrease verbosity\n");
146 printf("-C , --cgi Output to stdout (for use in CGI environments)\n");
147 printf("-X , --width Set target SWF width\n");
148 printf("-Y , --height Set target SWF width\n");
149 printf("-r , --rate Set target SWF framerate\n");
150 printf("-l , --library <file> Include library file <file>\n");
151 printf("-I , --include <dir> Add include dir <dir>\n");
152 printf("-T , --flashversion <num> Set target SWF flash version to <num>.\n");
153 printf("-o , --output <filename> Set output file to <filename>.\n");
156 int args_callback_command(char*name,char*val)
159 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
166 void writeSWF(SWF*swf)
169 if(do_cgi || !strcmp(filename, "-"))
172 fi = open(outputname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
174 fprintf(stderr, "couldn't create output file %s\n", filename);
178 if(swf_WriteCGI(swf)<0) {
179 fprintf(stderr, "WriteCGI failed.\n");
183 if(swf_WriteSWF(fi, swf)<0) {
184 fprintf(stderr, "WriteSWF() failed.\n");
190 int main (int argc,char ** argv)
193 char*currentdir = getcwd(buf, 512);
195 as3_warning("Could not determine the current directory");
197 as3_add_include_dir(currentdir);
202 processargs(argc, argv);
203 as3_setverbosity(verbose);
206 args_callback_usage(argv[0]);
210 outputname = stripFilename(filename, ".swf");
211 //as3_warning("output name not given, writing to %s", outputname);
214 as3_parse_file(filename);
215 void*code = as3_getcode();
218 memset(&swf, 0, sizeof(swf));
219 swf.fileVersion = flashversion;
220 swf.frameRate = framerate*0x100;
221 swf.movieSize.xmin = 0;
222 swf.movieSize.ymin = 0;
223 swf.movieSize.xmax = width*20;
224 swf.movieSize.ymax = height*20;
225 TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC);
226 swf_WriteABC(tag, code);
228 if(as3_getglobalclass()) {
229 tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
232 swf_SetString(tag, as3_getglobalclass());
234 as3_warning("no global public MovieClip subclass");
239 tag = swf_InsertTag(tag, ST_SHOWFRAME);
240 tag = swf_InsertTag(tag, ST_END);
244 if(local_with_filesystem)
245 swf.fileAttributes &= ~FILEATTRIBUTE_USENETWORK;
246 if(local_with_networking)
247 swf.fileAttributes |= FILEATTRIBUTE_USENETWORK;