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;
42 static struct options_t options[] = {
51 {"T", "flashversion"},
56 int args_callback_option(char*name,char*val)
58 if(!strcmp(name, "V")) {
59 printf("swfc - part of %s %s\n", PACKAGE, VERSION);
62 else if(!strcmp(name, "o")) {
64 override_outputname = 1;
67 else if(!strcmp(name, "r")) {
68 framerate = atof(val);
71 else if(!strcmp(name, "v")) {
75 else if(!strcmp(name, "q")) {
79 else if(!strcmp(name, "X")) {
83 else if(!strcmp(name, "Y")) {
87 else if(!strcmp(name, "T")) {
88 flashversion = atoi(val);
91 else if(!strcmp(name, "C")) {
96 printf("Unknown option: -%s\n", name);
101 int args_callback_longoption(char*name,char*val)
103 return args_long2shortoption(options, name, val);
105 void args_callback_usage(char *name)
108 printf("Usage: %s file.as [-o file.swf] \n", name);
110 printf("-h , --help Print short help message and exit\n");
111 printf("-V , --version Print version info and exit\n");
112 printf("-v , --verbose Increase verbosity\n");
113 printf("-q , --quiet Decrease verbosity\n");
114 printf("-C , --cgi Output to stdout (for use in CGI environments)\n");
115 printf("-X , --width Set target SWF width\n");
116 printf("-Y , --height Set target SWF width\n");
117 printf("-r , --rate Set target SWF framerate\n");
118 printf("-T , --flashversion <num> Set target SWF flash version to <num>.\n");
119 printf("-o , --output <filename> Set output file to <filename>.\n");
122 int args_callback_command(char*name,char*val)
125 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
132 void writeSWF(SWF*swf)
135 if(do_cgi || !strcmp(filename, "-"))
138 fi = open(outputname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
140 fprintf(stderr, "couldn't create output file %s\n", filename);
144 if(swf_WriteCGI(swf)<0) {
145 fprintf(stderr, "WriteCGI failed.\n");
149 if(swf_WriteSWF(fi, swf)<0) {
150 fprintf(stderr, "WriteSWF() failed.\n");
156 int main (int argc,char ** argv)
159 processargs(argc, argv);
162 args_callback_usage(argv[0]);
166 outputname = stripFilename(filename, ".swf");
167 //as3_warning("output name not given, writing to %s", outputname);
170 as3_setverbosity(verbose);
173 char*currentdir = getcwd(buf, 512);
175 as3_warning("Could not determine the current directory");
177 as3_add_include_dir(currentdir);
180 as3_parse_file(filename);
181 void*code = as3_getcode();
184 memset(&swf, 0, sizeof(swf));
185 swf.fileVersion = flashversion;
186 swf.frameRate = framerate*0x100;
187 swf.movieSize.xmin = 0;
188 swf.movieSize.ymin = 0;
189 swf.movieSize.xmax = width*20;
190 swf.movieSize.ymax = height*20;
191 TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC);
192 swf_WriteABC(tag, code);
194 if(as3_getglobalclass()) {
195 tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
198 swf_SetString(tag, as3_getglobalclass());
200 as3_warning("no global public MovieClip subclass");
206 tag = swf_InsertTag(tag, ST_SHOWFRAME);
207 tag = swf_InsertTag(tag, ST_END);