1 //gcc -Wall -Werror `pkg-config --libs --cflags libming glib-2.0` compiler.c -o compiler
7 /* This is what is used to compile the Actionscript parts of the source to
8 * includable C data that can later be executed.
9 * Note that this is pretty much a hack until someone writes a proper
10 * Actionscript compiler for Swfdec.
11 * Also note that the creation of the include-scripts should probably not be
12 * autorun, as we don't want to depend on external bugs, only on internal ones.
15 write_data (guint8
*data
, gsize len
)
19 for (i
= 0; i
< len
; i
++) {
23 g_print (" 0x%02X", data
[i
]);
25 g_print (",\n 0x%02X", data
[i
]);
30 g_print (", 0x%02X", data
[i
]);
33 g_print (", 0x%02X", data
[i
]);
42 get_name (const char *filename
)
46 end
= strrchr (filename
, '/');
49 end
= strchr (filename
, '.');
51 return g_strndup (filename
, end
- filename
);
53 return g_strdup (filename
);
57 main (int argc
, char **argv
)
67 g_print ("usage: %s FILE ...\n\n", argv
[0]);
72 Ming_setSWFCompression (-1);
74 g_print ("/* This file is autogenerated, do not edit! */\n\n");
75 for (i
= 1; i
< argc
; i
++) {
76 if (!g_file_get_contents (argv
[1], &contents
, NULL
, &error
)) {
77 g_printerr ("%s\n", error
->message
);
82 action
= newSWFAction (contents
);
83 data
= SWFAction_getByteCode (action
, &len
);
84 contents
= get_name (argv
[i
]);
85 g_print ("/* compiled from %s */\n", argv
[i
]);
86 g_print ("const unsigned char %s[] = {\n", contents
);
88 write_data (data
, len
);