X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfc.c;h=e46efa545bd4ebbfc50bcb11c07061703f293289;hb=9a8ddef2f3d19eaebdc8f3f7e9fb7116f1604b15;hp=bc6d711f2e42ded1d29f6ebe4a07dd6d8c6b5f03;hpb=5aef26eca4bd74018284f97e5f9212dea1cf3e5d;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index bc6d711..e46efa5 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -44,6 +44,7 @@ static char * outputname = "output.swf"; static int verbose = 2; static int optimize = 0; static int override_outputname = 0; +static int do_cgi = 0; static struct options_t options[] = { {"h", "help"}, @@ -68,6 +69,10 @@ int args_callback_option(char*name,char*val) optimize = 1; return 0; } + else if(!strcmp(name, "C")) { + do_cgi = 1; + return 0; + } else if(!strcmp(name, "v")) { verbose ++; return 0; @@ -119,7 +124,7 @@ static void syntaxerror(char*format, ...) va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - printf("\"%s\", line %d column %d: error- %s\n", filename, line, column, buf); + fprintf(stderr, "\"%s\", line %d column %d: error- %s\n", filename, line, column, buf); exit(1); } @@ -130,7 +135,7 @@ static void warning(char*format, ...) va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - printf("\"%s\", line %d column %d: warning- %s\n", filename, line, column, buf); + fprintf(stderr, "\"%s\", line %d column %d: warning- %s\n", filename, line, column, buf); } static void readToken() @@ -673,11 +678,16 @@ static void s_endSWF() warning("Empty bounding box for movie"); } - fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); + if(do_cgi) + fi = fileno(stdout); + else + fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); if(fi<0) { syntaxerror("couldn't create output file %s", filename); } - if(swf->compressed) + if(do_cgi) + {if(swf_WriteCGI(swf)<0) syntaxerror("WriteCGI() failed.\n");} + else if(swf->compressed) {if(swf_WriteSWC(fi, swf)<0) syntaxerror("WriteSWC() failed.\n");} else {if(swf_WriteSWF(fi, swf)<0) syntaxerror("WriteSWF() failed.\n");} @@ -715,7 +725,7 @@ int s_getframe() return currentframe+1; } -void s_frame(int nr, int cut, char*name) +void s_frame(int nr, int cut, char*name, char anchor) { int t; TAG*now = tag; @@ -729,13 +739,15 @@ void s_frame(int nr, int cut, char*name) if(t==nr-1 && name && *name) { tag = swf_InsertTag(tag, ST_FRAMELABEL); swf_SetString(tag, name); - swf_SetU8(tag, 1); //make this an anchor + if(anchor) + swf_SetU8(tag, 1); //make this an anchor } } - if(nr == 0 && currentframe == 0 && name) { + if(nr == 0 && currentframe == 0 && name && *name) { tag = swf_InsertTag(tag, ST_FRAMELABEL); swf_SetString(tag, name); - swf_SetU8(tag, 1); //make this an anchor + if(anchor) + swf_SetU8(tag, 1); //make this an anchor } if(cut) { @@ -1025,7 +1037,7 @@ void s_image(char*name, char*type, char*filename, int quality) int imageID = id; int width, height; if(!strcmp(type,"jpeg")) { -#ifndef HAVE_LIBJPEG +#ifndef HAVE_JPEGLIB warning("no jpeg support compiled in"); s_box(name, 0, 0, black, 20, 0); return; @@ -1264,7 +1276,15 @@ void s_sound(char*name, char*filename) { swf_SetSoundDefine(tag, samples, numsamples); } - + + tag = swf_InsertTag(tag, ST_NAMECHARACTER); + swf_SetU16(tag, id); + swf_SetString(tag, name); + tag = swf_InsertTag(tag, ST_EXPORTASSETS); + swf_SetU16(tag, 1); + swf_SetU16(tag, id); + swf_SetString(tag, name); + sound = (sound_t*)malloc(sizeof(sound_t)); /* mem leak */ sound->tag = tag; sound->id = id; @@ -1500,13 +1520,17 @@ void s_includeswf(char*name, char*filename) level--; if(!level) break; - /* We simply dump all tags right after the sprite - header, relying on the fact that swf_OptimizeTagOrder() will - sort things out for us later. - We also rely on the fact that the imported SWF is well-formed. - */ - tag = swf_InsertTag(tag, ftag->id); - swf_SetBlock(tag, ftag->data, ftag->len); + + if(ftag->id != ST_SETBACKGROUNDCOLOR) { + /* We simply dump all tags right after the sprite + header, relying on the fact that swf_OptimizeTagOrder() will + sort things out for us later. + We also rely on the fact that the imported SWF is well-formed. + */ + tag = swf_InsertTag(tag, ftag->id); + swf_SetBlock(tag, ftag->data, ftag->len); + } + ftag = ftag->next; } if(!ftag) @@ -1731,7 +1755,7 @@ typedef int command_func_t(map_t*args); SRECT parseBox(char*str) { - SRECT r; + SRECT r = {0,0,0,0}; float xmin, xmax, ymin, ymax; char*x = strchr(str, 'x'); char*d1=0,*d2=0; @@ -1801,8 +1825,10 @@ int parseTwip(char*str) int t; return sign*parseInt(str)*20; } else { - int l=strlen(++dot); + char* old = strdup(str); + int l=strlen(dot+1); char*s; + *dot++ = 0; for(s=str;s'9') syntaxerror("Not a coordinate: \"%s\"", str); @@ -1811,10 +1837,12 @@ int parseTwip(char*str) syntaxerror("Not a coordinate: \"%s\"", str); } if(l>2 || (l==2 && (dot[1]!='0' && dot[1]!='5'))) { - warning("precision loss: %s converted to twip: %s", str, dot); + dot[1] = ((dot[1]-0x30)/5)*5 + 0x30; dot[2] = 0; l=2; + warning("precision loss: %s converted to twip: %s.%s", old, str, dot); } + free(old); if(l==0) return sign*atoi(str)*20; if(l==1) @@ -2490,7 +2518,14 @@ static int c_frame(map_t*args) { char*framestr = lu(args, "n"); char*cutstr = lu(args, "cut"); + char*name = lu(args, "name"); + char*anchor = lu(args, "anchor"); + char buf[40]; + + if(!strcmp(anchor, "anchor") && !*name) + name = framestr; + int frame; int cut = 0; if(strcmp(cutstr, "no")) @@ -2507,7 +2542,7 @@ static int c_frame(map_t*args) && !(frame==1 && s_getframe()==frame)) // equality is o.k. for frame 0 syntaxerror("frame expression must be >%d (is:%s)", s_getframe(), framestr); } - s_frame(frame, cut, name); + s_frame(frame, cut, name, !strcmp(anchor, "anchor")); return 0; } static int c_primitive(map_t*args) @@ -2872,7 +2907,7 @@ static struct { char*arguments; } arguments[] = {{"flash", c_flash, "bbox=autocrop background=black version=6 fps=50 name= filename= @compress=default"}, - {"frame", c_frame, "n=1 name= @cut=no"}, + {"frame", c_frame, "n=1 name= @cut=no @anchor=no"}, // "import" type stuff {"swf", c_swf, "name filename"}, {"shape", c_swf, "name filename"}, @@ -3171,7 +3206,7 @@ int main (int argc,char ** argv) file = generateTokens(filename); if(!file) { - printf("parser returned error.\n"); + fprintf(stderr, "parser returned error.\n"); return 1; } pos=0;