update warning flags for gcc 4.4
[swfdec.git] / test / compiler.c
blobf4e0fcbedc89f426d200e9436921ffb1238afd57
1 //gcc -Wall -Werror `pkg-config --libs --cflags libming glib-2.0` compiler.c -o compiler
3 #include <glib.h>
4 #include <ming.h>
5 #include <string.h>
7 /* This is what is used to compile the Actionscript parts of the source to
8 * Swfdec test scripts 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 in Ming, only on internal ones.
15 /* header to put in front of script */
16 #define HEADER "Swfdec Test Script\0\1"
18 int
19 main (int argc, char **argv)
21 SWFAction action;
22 char *contents;
23 GError *error = NULL;
24 int len;
25 byte *data;
27 if (argc != 3) {
28 g_print ("usage: %s INFILE OUTFILE\n\n", argv[0]);
29 return 1;
32 Ming_init ();
34 if (!g_file_get_contents (argv[1], &contents, NULL, &error)) {
35 g_printerr ("%s\n", error->message);
36 g_error_free (error);
37 error = NULL;
38 return 1;
40 action = newSWFAction (contents);
41 if (SWFAction_compile (action, 8, &len) != 0) {
42 g_printerr ("compilation failed\n");
43 return 1;
45 data = SWFAction_getByteCode (action, NULL);
46 contents = g_malloc (len + sizeof (HEADER));
47 memcpy (contents, HEADER, sizeof (HEADER));
48 memcpy (contents + sizeof (HEADER), data, len);
49 if (!g_file_set_contents (argv[2], contents, len + sizeof (HEADER), &error)) {
50 g_printerr ("%s\n", error->message);
51 g_error_free (error);
52 error = NULL;
53 return 1;
55 g_free (contents);
56 return 0;