/* Event handler for tool 'addimports' */ ATerm addimports_handler(int conn, ATerm term) { ATerm in, out; /* We need some temporary variables during matching */ char *s0; ATerm t0; if(ATmatch(term, "rec-eval(add-imports(<str>,<term>))", &s0, &t0)) { return add_imports(conn, s0, t0); } if(ATmatch(term, "rec-terminate(<term>)", &t0)) { rec_terminate(conn, t0); return NULL; } if(ATmatch(term, "rec-do(signature(<term>,<term>))", &in, &out)) { ATerm result = addimports_checker(conn, in); if(!ATmatch(result, "[]")) ATfprintf(stderr, "warning: not in input signature:\n\t%\n\tl\n", result); return NULL; } ATerror("tool addimports cannot handle term %t", term); return NULL; /* Silence the compiler */ }
int main (int argc, char **argv) { int width=640, height=480; /* default stage size */ int i; int swfcompression = DEFSWFCOMPRESSION; float framerate = 12.0; /* * Allow network access from locally-loaded movies. * * 0 = file access * 1 = network access * -1 = unspecified (omit the tag if SWF < 8, file access otherwise) * * By default is unspecified. */ int networkAccess = -1; int usedfiles = 0; struct stat statbuf; int debug_parser = 0; #ifdef HAVE_GETOPT_LONG struct option opts[] = { {"dont-preprocess", 0, 0, 'p'}, {"frame-rate", 1, 0, 'r'}, {"swfversion", 1, 0, 'v'}, {"bgcolor", 1, 0, 'b'}, {"compression", 1, 0, 'c'}, {"includepath", 1, 0, 'I'}, {"define", 1, 0, 'D'}, {"size", 1, 0, 's'}, {"network-access", 1, 0, 'n'}, {"output", 1, 0, 'o'}, {"import", 1, 0, 'i'}, {"version", 0, 0, 'V'}, {"help", 0, 0, 'h'}, {"debug", 0, 0, 'd'}, {"init-action", 1, 0, 'a'}, {0, 0, 0, 0} }; int opts_idx; #endif int c; char *me; cppargs = malloc(cppargsize); sprintf(cppargs, "%s", DEFAULT_FLAGS); //cppargs[0] = '\0'; me = argv[0]; while (1) { #define BUFSIZE 1024 char buf [BUFSIZE]; const char *optstring = "Vhpds:r:D:I:v:c:b:i:o:a:n:"; #ifdef HAVE_GETOPT_LONG c = getopt_long (argc, argv, optstring, opts, &opts_idx); #else c = getopt (argc, argv, optstring); #endif if (c == -1) break; switch (c) { case 'p': makeswf_set_dopreprocess(0); break; case 's': if ( sscanf(optarg, "%dx%d", &width, &height) != 2 ) { usage(argv[0], EXIT_FAILURE); } break; case 'n': { if ( ! strcasecmp(optarg, "network") ) { networkAccess = 1; } else if ( ! strcasecmp(optarg, "file") ) { networkAccess = 0; } else { fprintf(stderr, "Network access must be 'network' or 'file'\n"); exit(1); } break; } case 'v': if ( sscanf(optarg, "%d", &swfversion) != 1 ) { usage(argv[0], EXIT_FAILURE); } makeswf_set_swfversion(swfversion); break; case 'b': if ( sscanf(optarg, "%lx", &bgcolor) != 1 ) { usage(argv[0], EXIT_FAILURE); } useBgColor=1; break; case 'c': if ( sscanf(optarg, "%d", &swfcompression) != 1 ) { usage(argv[0], EXIT_FAILURE); } if ( swfcompression < -1 || swfcompression > 9 ) { fprintf(stderr, "Compression level must be in the range -1..9\n"); exit(1); } break; case 'r': if ( sscanf(optarg, "%f", &framerate) != 1 ) { usage(argv[0], EXIT_FAILURE); } break; case 'I': snprintf(buf, BUFSIZE-1, " -I%s", optarg); buf[BUFSIZE-1]='\0'; makeswf_append_cpparg(buf); break; case 'i': add_import_spec(optarg); break; case 'o': outputfile = optarg; break; case 'D': // yes, you can smash the stack ... snprintf(buf, BUFSIZE-1, " -D%s", optarg); buf[BUFSIZE-1]='\0'; makeswf_append_cpparg(buf); break; case 'd': debug_parser = 1; break; case 'a': add_init_action_spec(optarg); break; case 'V': printf("%s\n", RCSID); printf("Copyright (C) 2001-2006 \"Sandro Santilli\" <*****@*****.**>.\n"); printf("Released under the GNU General Public License.\n"); exit(EXIT_SUCCESS); case 'h': usage(argv[0], EXIT_SUCCESS); default: usage(argv[0], EXIT_FAILURE); break; } } argv+=optind; argc-=optind; if ( argc < 1 ) usage(me, EXIT_FAILURE); if ( stat(outputfile, &statbuf) ) { // should warn about overriding (-f ?) } if ( Ming_init() ) { fprintf(stderr, "Ming initialization error\n"); exit(EXIT_FAILURE); } Ming_setWarnFunction(warningHandler); //Ming_setErrorFunction(compileError); Ming_useSWFVersion(swfversion); Ming_setSWFCompression(swfcompression); mo = newSWFMovie(); if ( networkAccess >= 0 ) SWFMovie_setNetworkAccess(mo, networkAccess); SWFMovie_setDimension(mo, (float)width, (float)height); SWFMovie_setRate(mo, framerate); if ( useBgColor ) { SWFMovie_setBackground(mo, bgcolor >> 16, (bgcolor&0x00FF00) >> 8, (bgcolor&0x0000FF)); } printf("Output file name: %s\n", outputfile); printf("Output compression level: %d\n", swfcompression); printf("Output SWF version: %d\n", swfversion); /* * Add imports */ if ( numimport_specs ) add_imports(); for ( i=0; i<argc; i++ ) { SWFAction ac; char *filename = argv[i]; char ppfile[PATH_MAX]; FileType type = getFileType(filename); compile_init_actions(i, debug_parser); if ( type == SWF ) { printf("Adding prebuilt clip %s to frame %d... ", filename, i); embed_swf(mo, filename); } else if ( type == BITMAP ) { printf("Adding bitmap %s to frame %d... ", filename, i); embed_image(mo, filename); } else { sprintf(ppfile, "%s.frame%d.pp", outputfile, i); ac = makeswf_compile_source(filename, ppfile, debug_parser); printf("Adding %s to frame %d... ", filename, i); SWFMovie_add(mo, (SWFBlock)ac); } printf("done.\n"); usedfiles++; SWFMovie_nextFrame(mo); } if ( i <= max_init_action_frame ) { fprintf(stderr, "WARNING: following init actions for frames > %d have been discarded:\n", i-1); for (;i<=max_init_action_frame; ++i) { print_init_actions(i, stderr); } } if ( ! usedfiles ) { printf("No valid input files\n"); return 1; } printf("Saving output to %s... ", outputfile); fflush(stdout); SWFMovie_save(mo, outputfile); printf("done.\n"); return 0; }