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
, int 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
)
68 g_print ("usage: %s FILE ...\n\n", argv
[0]);
73 Ming_setSWFCompression (-1);
75 g_print ("/* This file is autogenerated, do not edit! */\n\n");
76 for (i
= 1; i
< argc
; i
++) {
77 if (!g_file_get_contents (argv
[1], &contents
, NULL
, &error
)) {
78 g_printerr ("Error: %s\n", error
->message
);
83 action
= newSWFAction (contents
);
84 if (SWFAction_compile (action
, 6, &len
) != 0) {
85 g_printerr ("Error: Couldn't compile\n");
88 data
= SWFAction_getByteCode (action
, &ignored
);
89 contents
= get_name (argv
[i
]);
90 g_print ("/* compiled from %s */\n", argv
[i
]);
91 g_print ("static const unsigned char %s[] = {\n", contents
);
93 write_data (data
, len
);