[Swfdec-commits] 15 commits - test/custom vivified/code

Pekka Lampila medar at kemper.freedesktop.org
Wed May 7 12:21:27 PDT 2008


 test/custom/key-isdown-mouse.swf.trace                  |   13 
 vivified/code/compiler.c                                |  250 ++++++++++------
 vivified/code/test/compiler/Makefile.am                 |   17 -
 vivified/code/test/compiler/builtin_statement.as        |    7 
 vivified/code/test/compiler/builtin_statement.as.expect |   10 
 vivified/code/test/compiler/comment.as                  |    3 
 vivified/code/test/compiler/comment.as.expect           |    3 
 vivified/code/test/compiler/empty.as                    |    3 
 vivified/code/test/compiler/empty_statement.as          |    1 
 vivified/code/test/compiler/empty_statement.as.expect   |    3 
 vivified/code/test/compiler/trace.as                    |    1 
 vivified/code/test/compiler/trace.as.expect             |    6 
 vivified/code/vivi_code_asm_push.c                      |   70 +++-
 vivified/code/vivi_code_asm_push.h                      |   21 -
 vivified/code/vivi_code_assembler.c                     |  123 +++++++
 vivified/code/vivi_code_assembler.h                     |    2 
 vivified/code/vivi_parser.c                             |    4 
 17 files changed, 425 insertions(+), 112 deletions(-)

New commits:
commit b2a557c13672552c65f677a573ac3626685bcf2a
Merge: 16734f4... 6438586...
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 18:38:58 2008 +0300

    Merge branch 'master' of ssh://medar@git.freedesktop.org/git/swfdec/swfdec

commit 16734f421d7e430de537376844cc0fcab0d9d991
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 17:22:55 2008 +0300

    Add tests for vivi-compile: comment, empty file, empty statement

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index 91b7c2f..fd2c3cf 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -16,5 +16,11 @@ check-local: $(top_builddir)/vivified/code/vivi-compile
 EXTRA_DIST = \
 	builtin_statement.as \
 	builtin_statement.as.expect \
+	comment.as \
+	comment.as.expect \
+	empty.as \
+	empty.as.expect \
+	empty_statement.as \
+	empty_statement.as.expect \
 	trace.as \
 	trace.as.expect
diff --git a/vivified/code/test/compiler/comment.as b/vivified/code/test/compiler/comment.as
new file mode 100644
index 0000000..ded6e31
--- /dev/null
+++ b/vivified/code/test/compiler/comment.as
@@ -0,0 +1,3 @@
+// Single line
+/* Multi
+line */
diff --git a/vivified/code/test/compiler/comment.as.expect b/vivified/code/test/compiler/comment.as.expect
new file mode 100644
index 0000000..08304fb
--- /dev/null
+++ b/vivified/code/test/compiler/comment.as.expect
@@ -0,0 +1,3 @@
+asm {
+  end
+}
diff --git a/vivified/code/test/compiler/empty.as b/vivified/code/test/compiler/empty.as
new file mode 100644
index 0000000..e69de29
diff --git a/vivified/code/test/compiler/empty.as.expect b/vivified/code/test/compiler/empty.as.expect
new file mode 100644
index 0000000..08304fb
--- /dev/null
+++ b/vivified/code/test/compiler/empty.as.expect
@@ -0,0 +1,3 @@
+asm {
+  end
+}
diff --git a/vivified/code/test/compiler/empty_statement.as b/vivified/code/test/compiler/empty_statement.as
new file mode 100644
index 0000000..092bc2b
--- /dev/null
+++ b/vivified/code/test/compiler/empty_statement.as
@@ -0,0 +1 @@
+;
diff --git a/vivified/code/test/compiler/empty_statement.as.expect b/vivified/code/test/compiler/empty_statement.as.expect
new file mode 100644
index 0000000..08304fb
--- /dev/null
+++ b/vivified/code/test/compiler/empty_statement.as.expect
@@ -0,0 +1,3 @@
+asm {
+  end
+}
commit 87a338676bb6f20ddca29988452d6cdc8d6dfef4
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 17:19:49 2008 +0300

    Don't give an error when parsing an empty file

diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 77daecb..722c7f9 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -3079,6 +3079,10 @@ parse_program (ParseData *data)
 {
   ViviCodeStatement *statement;
 
+  // empty file
+  if (peek_token (data, TOKEN_NONE))
+    return vivi_code_block_new ();
+
   g_assert (data->level == NULL);
   vivi_parser_start_level (data);
 
commit 13df5f7d1f7667f48f8a6c9ecafcbef1dac02dad
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 17:03:28 2008 +0300

    Add a built in statement test for vivi-compile

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index 9adfea2..91b7c2f 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -14,5 +14,7 @@ check-local: $(top_builddir)/vivified/code/vivi-compile
 	fi
 
 EXTRA_DIST = \
+	builtin_statement.as \
+	builtin_statement.as.expect \
 	trace.as \
 	trace.as.expect
diff --git a/vivified/code/test/compiler/builtin_statement.as b/vivified/code/test/compiler/builtin_statement.as
new file mode 100644
index 0000000..61ee791
--- /dev/null
+++ b/vivified/code/test/compiler/builtin_statement.as
@@ -0,0 +1,7 @@
+nextFrame ();
+play ();
+prevFrame ();
+stop ();
+stopDrag ();
+stopSounds ();
+toggleQuality ();
diff --git a/vivified/code/test/compiler/builtin_statement.as.expect b/vivified/code/test/compiler/builtin_statement.as.expect
new file mode 100644
index 0000000..ee17fbf
--- /dev/null
+++ b/vivified/code/test/compiler/builtin_statement.as.expect
@@ -0,0 +1,10 @@
+asm {
+  next_frame
+  play
+  previous_frame
+  stop
+  end_drag
+  stop_sounds
+  toggle_quality
+  end
+}
commit 1e3d942a3e1b0c92d00b711a9cff4d9affa0044e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 17:01:34 2008 +0300

    Fix an assert when pooling and no strings are found

diff --git a/vivified/code/vivi_code_assembler.c b/vivified/code/vivi_code_assembler.c
index 7116964..fff4087 100644
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@ -208,6 +208,12 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
     }
   }
 
+  if (num == 0) {
+    g_slist_foreach (list, (GFunc)g_free, NULL);
+    g_slist_free (list);
+    return TRUE;
+  }
+
   // so we have first encountered strings first
   list = g_slist_reverse (list);
 
commit de3774389de285be0428b65bc3e71405103d4da2
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 17:01:09 2008 +0300

    Make assembler include the end action. Fix the test case

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index c107aa8..8ebd650 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -29,6 +29,7 @@
 #include "vivi_parser.h"
 #include "vivi_code_text_printer.h"
 #include "vivi_code_assembler.h"
+#include "vivi_code_asm_code_default.h"
 
 static SwfdecBuffer *
 create_file (SwfdecBuffer *actions, guint version, guint rate, SwfdecRect rect)
@@ -77,7 +78,9 @@ int
 main (int argc, char *argv[])
 {
   SwfdecBuffer *source, *output;
-  ViviCodeStatement *statement, *assembler;
+  ViviCodeStatement *statement;
+  ViviCodeAssembler *assembler;
+  ViviCodeAsm *code;
   int version = 8;
   int rate = 15;
   char *size_string = NULL;
@@ -177,10 +180,15 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  assembler = vivi_code_assembler_new ();
-  vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
+  assembler = VIVI_CODE_ASSEMBLER (vivi_code_assembler_new ());
+  vivi_code_statement_compile (statement, assembler);
   g_object_unref (statement);
-  vivi_code_assembler_pool (VIVI_CODE_ASSEMBLER (assembler));
+
+  code = vivi_code_asm_end_new ();
+  vivi_code_assembler_add_code (assembler, code);
+  g_object_unref (code);
+
+  vivi_code_assembler_pool (assembler);
 
   if (use_asm) {
     ViviCodePrinter *printer = vivi_code_text_printer_new ();
@@ -188,8 +196,8 @@ main (int argc, char *argv[])
     g_object_unref (printer);
     g_object_unref (assembler);
   } else {
-    SwfdecScript *script = vivi_code_assembler_assemble_script (
-	VIVI_CODE_ASSEMBLER (assembler), version, NULL);
+    SwfdecScript *script =
+      vivi_code_assembler_assemble_script (assembler, version, NULL);
     g_object_unref (assembler);
 
     if (script == NULL) {
diff --git a/vivified/code/test/compiler/trace.as.expect b/vivified/code/test/compiler/trace.as.expect
index f0fe913..1da2bf9 100644
--- a/vivified/code/test/compiler/trace.as.expect
+++ b/vivified/code/test/compiler/trace.as.expect
@@ -2,4 +2,5 @@ asm {
   pool "Hello, world!"
   push pool 0
   trace
+  end
 }
commit 213b8cc3685efa64faf550b10a9af6a0f4067e6d
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:50:43 2008 +0300

    Store values to the pool in the order they appear, not reversed

diff --git a/vivified/code/vivi_code_assembler.c b/vivified/code/vivi_code_assembler.c
index d53acdb..7116964 100644
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@ -186,7 +186,7 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
 	ViviCodeConstantType type =
 	  vivi_code_asm_push_get_value_type (push, j);
 
-	// if there already is something that triest to access a pool,
+	// if there already is something that tries to access a pool,
 	// don't touch anything
 	if (type == VIVI_CODE_CONSTANT_CONSTANT_POOL ||
 	    type == VIVI_CODE_CONSTANT_CONSTANT_POOL_BIG) {
@@ -208,6 +208,9 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
     }
   }
 
+  // so we have first encountered strings first
+  list = g_slist_reverse (list);
+
   // create the pool action
   bots = swfdec_bots_open ();
   swfdec_bots_put_u16 (bots, num);
commit 397e8b4494e788a6cddd07b829d6b3e60b105a01
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:43:51 2008 +0300

    Add the first test for vivi-compile, tracing hello world

diff --git a/vivified/code/test/compiler/Makefile.am b/vivified/code/test/compiler/Makefile.am
index 7f7036f..9adfea2 100644
--- a/vivified/code/test/compiler/Makefile.am
+++ b/vivified/code/test/compiler/Makefile.am
@@ -1,7 +1,7 @@
 check-local: $(top_builddir)/vivified/code/vivi-compile
 	RESULT=""; \
-	for file in $(srcdir)/*.swf; do \
-	  echo "$$file ..." && $(top_builddir)/vivified/code/vivi-compile $$file | diff -u $$file.expect - || RESULT="$$RESULT $$file"; \
+	for file in $(srcdir)/*.as; do \
+	  echo "$$file ..." && $(top_builddir)/vivified/code/vivi-compile -a $$file | diff -u $$file.expect - || RESULT="$$RESULT $$file"; \
 	done; \
 	if test "x$$RESULT" == "x"; then \
 	  echo "OK"; \
@@ -13,5 +13,6 @@ check-local: $(top_builddir)/vivified/code/vivi-compile
 	  exit 1; \
 	fi
 
-EXTRA_DIST =
-
+EXTRA_DIST = \
+	trace.as \
+	trace.as.expect
diff --git a/vivified/code/test/compiler/trace.as b/vivified/code/test/compiler/trace.as
new file mode 100644
index 0000000..7918421
--- /dev/null
+++ b/vivified/code/test/compiler/trace.as
@@ -0,0 +1 @@
+trace ("Hello, world!");
diff --git a/vivified/code/test/compiler/trace.as.expect b/vivified/code/test/compiler/trace.as.expect
new file mode 100644
index 0000000..f0fe913
--- /dev/null
+++ b/vivified/code/test/compiler/trace.as.expect
@@ -0,0 +1,5 @@
+asm {
+  pool "Hello, world!"
+  push pool 0
+  trace
+}
commit d1b4024879e9d51a99579ea99118d13a271fcfc8
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:42:58 2008 +0300

    Add key-isdown-mouse.swf.trace that was forgotten earlier

diff --git a/test/custom/key-isdown-mouse.swf.trace b/test/custom/key-isdown-mouse.swf.trace
new file mode 100644
index 0000000..fa5e071
--- /dev/null
+++ b/test/custom/key-isdown-mouse.swf.trace
@@ -0,0 +1,13 @@
+Check if mouse presses show up as in Key.isDown and Key.getCode
+1: false
+2: false
+code: 0
+1: true
+2: false
+code: 0
+1: false
+2: false
+code: 0
+1: false
+2: false
+code: 0
commit c5afadb0f728e0001d65de51721a47194819c45f
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:39:01 2008 +0300

    Add -a/--asm option for vivi-compile to output asm as text

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index e07e8c6..c107aa8 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -78,12 +78,12 @@ main (int argc, char *argv[])
 {
   SwfdecBuffer *source, *output;
   ViviCodeStatement *statement, *assembler;
-  SwfdecScript *script;
   int version = 8;
   int rate = 15;
   char *size_string = NULL;
   SwfdecRect size_rect = { 0, 0, 2000, 3000 };
-  const char *output_filename = "out.swf";
+  const char *output_filename = NULL;
+  gboolean use_asm;
   GError *error = NULL;
 
   GOptionEntry options[] = {
@@ -91,6 +91,7 @@ main (int argc, char *argv[])
     { "rate", 'r', 0, G_OPTION_ARG_INT, &rate, "the frame rate of the resulting Flash file", NULL },
     { "size", 's', 0, G_OPTION_ARG_STRING, &size_string, "the size give as WxH of the resulting Flash file", NULL },
     { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_filename, "output filename", NULL },
+    { "asm", 'a', 0, G_OPTION_ARG_NONE, &use_asm, "output assembler instead of a Flash file", NULL },
     { NULL }
   };
   GOptionContext *ctx;
@@ -149,6 +150,16 @@ main (int argc, char *argv[])
     size_rect.y1 = 20 * height;
   }
 
+  if (use_asm) {
+    if (output_filename != NULL) {
+      g_printerr ("Can't use output file when using -a\n");
+      return 1;
+    }
+  } else {
+    if (output_filename == NULL)
+      output_filename = "out.swf";
+  }
+
   swfdec_init ();
 
   source = swfdec_buffer_new_from_file (argv[1], &error);
@@ -168,25 +179,33 @@ main (int argc, char *argv[])
 
   assembler = vivi_code_assembler_new ();
   vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
-  vivi_code_assembler_pool (VIVI_CODE_ASSEMBLER (assembler));
-  script = vivi_code_assembler_assemble_script (
-      VIVI_CODE_ASSEMBLER (assembler), version, NULL);
-  g_object_unref (assembler);
   g_object_unref (statement);
+  vivi_code_assembler_pool (VIVI_CODE_ASSEMBLER (assembler));
 
-  if (script == NULL) {
-    g_printerr ("Script assembling failed\n");
-    return 1;
-  }
+  if (use_asm) {
+    ViviCodePrinter *printer = vivi_code_text_printer_new ();
+    vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (assembler));
+    g_object_unref (printer);
+    g_object_unref (assembler);
+  } else {
+    SwfdecScript *script = vivi_code_assembler_assemble_script (
+	VIVI_CODE_ASSEMBLER (assembler), version, NULL);
+    g_object_unref (assembler);
+
+    if (script == NULL) {
+      g_printerr ("Script assembling failed\n");
+      return 1;
+    }
 
-  output = create_file (script->buffer, version, rate, size_rect);
-  swfdec_script_unref (script);
+    output = create_file (script->buffer, version, rate, size_rect);
+    swfdec_script_unref (script);
 
-  if (!g_file_set_contents (output_filename, (char *) output->data,
-	output->length, &error)) {
-    swfdec_buffer_unref (output);
-    g_printerr ("Error saving: %s\n", error->message);
-    return 1;
+    if (!g_file_set_contents (output_filename, (char *) output->data,
+	  output->length, &error)) {
+      swfdec_buffer_unref (output);
+      g_printerr ("Error saving: %s\n", error->message);
+      return 1;
+    }
   }
 
   return 0;
commit 3c067aa5c9b387bf069d47b98fd7bf3f803ee7af
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:38:39 2008 +0300

    Minor clean ups to vivi_code_assembler_pool

diff --git a/vivified/code/vivi_code_assembler.c b/vivified/code/vivi_code_assembler.c
index daf63af..d53acdb 100644
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@ -167,7 +167,7 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
   SwfdecConstantPool *pool;
   ViviCodeAsm *code;
 
-  // create the pool
+  // collect the strings
   list = NULL;
   length = 0;
   num = 0;
@@ -208,6 +208,7 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
     }
   }
 
+  // create the pool action
   bots = swfdec_bots_open ();
   swfdec_bots_put_u16 (bots, num);
   for (iter = list; iter != NULL; iter = iter->next) {
@@ -237,7 +238,7 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
 	if (vivi_code_asm_push_get_value_type (old, j) ==
 	    VIVI_CODE_CONSTANT_STRING) {
 	  const char *str = vivi_code_asm_push_get_string (old, j);
-	  int k = 0;
+	  guint k = 0;
 
 	  for (iter = list; iter != NULL; iter = iter->next) {
 	    if (strcmp (iter->data, str) == 0)
@@ -260,6 +261,7 @@ vivi_code_assembler_pool (ViviCodeAssembler *assembler)
     }
   }
 
+  // done
   g_slist_foreach (list, (GFunc)g_free, NULL);
   g_slist_free (list);
 
commit 3fb637e8edd3e9eee0024f74004acd279aadd47e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 16:24:45 2008 +0300

    Implement vivi_code_assembler_pool to transform stack strings to pool strings

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index dba4cd6..e07e8c6 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -168,6 +168,7 @@ main (int argc, char *argv[])
 
   assembler = vivi_code_assembler_new ();
   vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
+  vivi_code_assembler_pool (VIVI_CODE_ASSEMBLER (assembler));
   script = vivi_code_assembler_assemble_script (
       VIVI_CODE_ASSEMBLER (assembler), version, NULL);
   g_object_unref (assembler);
diff --git a/vivified/code/vivi_code_asm_push.c b/vivified/code/vivi_code_asm_push.c
index e21f9f1..f5509fd 100644
--- a/vivified/code/vivi_code_asm_push.c
+++ b/vivified/code/vivi_code_asm_push.c
@@ -182,7 +182,7 @@ vivi_code_asm_push_new (void)
 }
 
 guint
-vivi_code_asm_push_get_n_values (ViviCodeAsmPush *push)
+vivi_code_asm_push_get_n_values (const ViviCodeAsmPush *push)
 {
   g_return_val_if_fail (VIVI_IS_CODE_ASM_PUSH (push), 0);
   
@@ -190,7 +190,7 @@ vivi_code_asm_push_get_n_values (ViviCodeAsmPush *push)
 }
 
 ViviCodeConstantType
-vivi_code_asm_push_get_value_type (ViviCodeAsmPush *push, guint i)
+vivi_code_asm_push_get_value_type (const ViviCodeAsmPush *push, guint i)
 {
   g_return_val_if_fail (VIVI_IS_CODE_ASM_PUSH (push), 0);
   g_return_val_if_fail (i < push->offsets->len, 0);
@@ -301,8 +301,60 @@ vivi_code_asm_push_add_pool_big (ViviCodeAsmPush *push, guint id)
   swfdec_bots_put_u16 (push->contents, id);
 }
 
+void
+vivi_code_asm_push_copy_value (ViviCodeAsmPush *push,
+    const ViviCodeAsmPush *other, guint id)
+{
+  g_return_if_fail (VIVI_IS_CODE_ASM_PUSH (push));
+  g_return_if_fail (VIVI_IS_CODE_ASM_PUSH (other));
+  g_return_if_fail (id <= G_MAXUINT16);
+
+  switch (vivi_code_asm_push_get_value_type (other, id)) {
+    case VIVI_CODE_CONSTANT_STRING:
+      vivi_code_asm_push_add_string (push,
+	  vivi_code_asm_push_get_string (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_FLOAT:
+      vivi_code_asm_push_add_float (push,
+	  vivi_code_asm_push_get_float (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_NULL:
+      vivi_code_asm_push_add_null (push);
+      break;
+    case VIVI_CODE_CONSTANT_UNDEFINED:
+      vivi_code_asm_push_add_undefined (push);
+      break;
+    case VIVI_CODE_CONSTANT_REGISTER:
+      vivi_code_asm_push_add_register (push,
+	  vivi_code_asm_push_get_register (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_BOOLEAN:
+      vivi_code_asm_push_add_boolean (push,
+	  vivi_code_asm_push_get_boolean (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_DOUBLE:
+      vivi_code_asm_push_add_double (push,
+	  vivi_code_asm_push_get_double (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_INTEGER:
+      vivi_code_asm_push_add_integer (push,
+	  vivi_code_asm_push_get_integer (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_CONSTANT_POOL:
+      vivi_code_asm_push_add_pool (push,
+	  vivi_code_asm_push_get_pool (other, id));
+      break;
+    case VIVI_CODE_CONSTANT_CONSTANT_POOL_BIG:
+      vivi_code_asm_push_add_pool_big (push,
+	  vivi_code_asm_push_get_pool (other, id));
+      break;
+    default:
+      g_assert_not_reached ();
+  }
+}
+
 const char *
-vivi_code_asm_push_get_string (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_string (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -317,7 +369,7 @@ vivi_code_asm_push_get_string (ViviCodeAsmPush *push, guint id)
 }
 
 float
-vivi_code_asm_push_get_float (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_float (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -332,7 +384,7 @@ vivi_code_asm_push_get_float (ViviCodeAsmPush *push, guint id)
 }
 
 guint
-vivi_code_asm_push_get_register (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_register (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -347,7 +399,7 @@ vivi_code_asm_push_get_register (ViviCodeAsmPush *push, guint id)
 }
 
 double
-vivi_code_asm_push_get_double (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_double (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -362,7 +414,7 @@ vivi_code_asm_push_get_double (ViviCodeAsmPush *push, guint id)
 }
 
 int
-vivi_code_asm_push_get_integer (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_integer (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -377,7 +429,7 @@ vivi_code_asm_push_get_integer (ViviCodeAsmPush *push, guint id)
 }
 
 gboolean
-vivi_code_asm_push_get_boolean (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_boolean (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
 
@@ -392,7 +444,7 @@ vivi_code_asm_push_get_boolean (ViviCodeAsmPush *push, guint id)
 }
 
 guint
-vivi_code_asm_push_get_pool (ViviCodeAsmPush *push, guint id)
+vivi_code_asm_push_get_pool (const ViviCodeAsmPush *push, guint id)
 {
   SwfdecBits bits;
   guint type;
diff --git a/vivified/code/vivi_code_asm_push.h b/vivified/code/vivi_code_asm_push.h
index b93f845..e0f36e3 100644
--- a/vivified/code/vivi_code_asm_push.h
+++ b/vivified/code/vivi_code_asm_push.h
@@ -66,22 +66,22 @@ GType			vivi_code_asm_push_get_type	  	(void);
 
 ViviCodeAsm *		vivi_code_asm_push_new			(void);
 
-guint			vivi_code_asm_push_get_n_values		(ViviCodeAsmPush *	push);
-ViviCodeConstantType	vivi_code_asm_push_get_value_type     	(ViviCodeAsmPush *	push,
+guint			vivi_code_asm_push_get_n_values		(const ViviCodeAsmPush *	push);
+ViviCodeConstantType	vivi_code_asm_push_get_value_type	(const ViviCodeAsmPush *	push,
 								 guint			i);
-const char *		vivi_code_asm_push_get_string		(ViviCodeAsmPush *	push,
+const char *		vivi_code_asm_push_get_string		(const ViviCodeAsmPush *	push,
 								 guint			id);
-float			vivi_code_asm_push_get_float		(ViviCodeAsmPush *	push,
+float			vivi_code_asm_push_get_float		(const ViviCodeAsmPush *	push,
 								 guint			id);
-guint			vivi_code_asm_push_get_register		(ViviCodeAsmPush *	push,
+guint			vivi_code_asm_push_get_register		(const ViviCodeAsmPush *	push,
 								 guint			id);
-double			vivi_code_asm_push_get_double		(ViviCodeAsmPush *	push,
+double			vivi_code_asm_push_get_double		(const ViviCodeAsmPush *	push,
 								 guint			id);
-int			vivi_code_asm_push_get_integer		(ViviCodeAsmPush *	push,
+int			vivi_code_asm_push_get_integer		(const ViviCodeAsmPush *	push,
 								 guint			id);
-gboolean		vivi_code_asm_push_get_boolean		(ViviCodeAsmPush *	push,
+gboolean		vivi_code_asm_push_get_boolean		(const ViviCodeAsmPush *	push,
 								 guint			id);
-guint			vivi_code_asm_push_get_pool		(ViviCodeAsmPush *	push,
+guint			vivi_code_asm_push_get_pool		(const ViviCodeAsmPush *	push,
 								 guint			id);
 
 void			vivi_code_asm_push_add_string		(ViviCodeAsmPush *	push,
@@ -102,6 +102,9 @@ void			vivi_code_asm_push_add_pool		(ViviCodeAsmPush *	push,
 								 guint			id);
 void			vivi_code_asm_push_add_pool_big		(ViviCodeAsmPush *	push,
 								 guint			id);
+void			vivi_code_asm_push_copy_value		(ViviCodeAsmPush *	push,
+								 const ViviCodeAsmPush *other,
+								 guint id);
 
 
 G_END_DECLS
diff --git a/vivified/code/vivi_code_assembler.c b/vivified/code/vivi_code_assembler.c
index 428801a..daf63af 100644
--- a/vivified/code/vivi_code_assembler.c
+++ b/vivified/code/vivi_code_assembler.c
@@ -29,6 +29,8 @@
 #include "vivi_code_emitter.h"
 #include "vivi_code_label.h"
 #include "vivi_code_printer.h"
+#include "vivi_code_asm_pool.h"
+#include "vivi_code_asm_push.h"
 
 G_DEFINE_TYPE (ViviCodeAssembler, vivi_code_assembler, VIVI_TYPE_CODE_STATEMENT)
 
@@ -154,6 +156,116 @@ vivi_code_assembler_remove_code (ViviCodeAssembler *assembler, ViviCodeAsm *code
     g_return_if_reached ();
 }
 
+gboolean
+vivi_code_assembler_pool (ViviCodeAssembler *assembler)
+{
+  guint i, j, num;
+  gsize length;
+  GSList *list, *iter;
+  SwfdecBots *bots;
+  SwfdecBuffer *buffer;
+  SwfdecConstantPool *pool;
+  ViviCodeAsm *code;
+
+  // create the pool
+  list = NULL;
+  length = 0;
+  num = 0;
+  for (i = 0; i < assembler->codes->len; i++) {
+    // if there is already a pool, don't touch anything
+    if (VIVI_IS_CODE_ASM_POOL (g_ptr_array_index (assembler->codes, i))) {
+      g_slist_foreach (list, (GFunc)g_free, NULL);
+      g_slist_free (list);
+      return FALSE;
+    }
+
+    if (VIVI_IS_CODE_ASM_PUSH (g_ptr_array_index (assembler->codes, i))) {
+      ViviCodeAsmPush *push =
+	VIVI_CODE_ASM_PUSH (g_ptr_array_index (assembler->codes, i));
+      for (j = 0; j < vivi_code_asm_push_get_n_values (push); j++) {
+	ViviCodeConstantType type =
+	  vivi_code_asm_push_get_value_type (push, j);
+
+	// if there already is something that triest to access a pool,
+	// don't touch anything
+	if (type == VIVI_CODE_CONSTANT_CONSTANT_POOL ||
+	    type == VIVI_CODE_CONSTANT_CONSTANT_POOL_BIG) {
+	  g_slist_foreach (list, (GFunc)g_free, NULL);
+	  g_slist_free (list);
+	  return FALSE;
+	}
+
+	if (type == VIVI_CODE_CONSTANT_STRING) {
+	  const char *str = vivi_code_asm_push_get_string (push, j);
+	  if (!g_slist_find_custom (list, str, (GCompareFunc)strcmp) &&
+	      length + strlen (str) + 1 < G_MAXUINT16) {
+	    list = g_slist_prepend (list, g_strdup (str));
+	    length += strlen (str) + 1;
+	    num++;
+	  }
+	}
+      }
+    }
+  }
+
+  bots = swfdec_bots_open ();
+  swfdec_bots_put_u16 (bots, num);
+  for (iter = list; iter != NULL; iter = iter->next) {
+    swfdec_bots_put_string (bots, iter->data);
+  }
+  buffer = swfdec_bots_close (bots);
+
+  // FIXME: version
+  pool = swfdec_constant_pool_new (NULL, buffer, 8);
+  g_assert (pool != NULL);
+  code = vivi_code_asm_pool_new (pool);
+  g_assert (code != NULL);
+  swfdec_constant_pool_unref (pool);
+  swfdec_buffer_unref (buffer);
+
+  vivi_code_assembler_insert_code (assembler, 0, code);
+  g_object_unref (code);
+
+  // change the pushes
+  for (i = 0; i < assembler->codes->len; i++) {
+    if (VIVI_IS_CODE_ASM_PUSH (g_ptr_array_index (assembler->codes, i))) {
+      ViviCodeAsmPush *old =
+	VIVI_CODE_ASM_PUSH (g_ptr_array_index (assembler->codes, i));
+      ViviCodeAsmPush *push = VIVI_CODE_ASM_PUSH (vivi_code_asm_push_new ());
+
+      for (j = 0; j < vivi_code_asm_push_get_n_values (old); j++) {
+	if (vivi_code_asm_push_get_value_type (old, j) ==
+	    VIVI_CODE_CONSTANT_STRING) {
+	  const char *str = vivi_code_asm_push_get_string (old, j);
+	  int k = 0;
+
+	  for (iter = list; iter != NULL; iter = iter->next) {
+	    if (strcmp (iter->data, str) == 0)
+	      break;
+	    k++;
+	  }
+	  if (iter != NULL) {
+	    vivi_code_asm_push_add_pool (push, k);
+	  } else {
+	    vivi_code_asm_push_copy_value (push, old, j);
+	  }
+	} else {
+	  vivi_code_asm_push_copy_value (push, old, j);
+	}
+      }
+
+      vivi_code_assembler_remove_code (assembler, VIVI_CODE_ASM (old));
+      vivi_code_assembler_insert_code (assembler, i, VIVI_CODE_ASM (push));
+      g_object_unref (push);
+    }
+  }
+
+  g_slist_foreach (list, (GFunc)g_free, NULL);
+  g_slist_free (list);
+
+  return TRUE;
+}
+
 SwfdecScript *
 vivi_code_assembler_assemble_script (ViviCodeAssembler *assembler,
     guint version, GError **error)
diff --git a/vivified/code/vivi_code_assembler.h b/vivified/code/vivi_code_assembler.h
index 7e6506f..833d2b0 100644
--- a/vivified/code/vivi_code_assembler.h
+++ b/vivified/code/vivi_code_assembler.h
@@ -61,6 +61,8 @@ void			vivi_code_assembler_insert_code  	(ViviCodeAssembler *	assembler,
 void			vivi_code_assembler_remove_code		(ViviCodeAssembler *	assembler,
 								 ViviCodeAsm *		code);
 
+gboolean		vivi_code_assembler_pool		(ViviCodeAssembler *	assembler);
+
 SwfdecScript *		vivi_code_assembler_assemble_script	(ViviCodeAssembler *	assembler,
 								 guint			version,
 								 GError **		error);
commit e9544fa6327d60cbf58dceeb2d21ee796db4ef9c
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 13:06:30 2008 +0300

    Declare output filename for vivi-compile with -o option, not extra argument

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 100bcb2..dba4cd6 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -83,12 +83,14 @@ main (int argc, char *argv[])
   int rate = 15;
   char *size_string = NULL;
   SwfdecRect size_rect = { 0, 0, 2000, 3000 };
+  const char *output_filename = "out.swf";
   GError *error = NULL;
 
   GOptionEntry options[] = {
     { "version", 'v', 0, G_OPTION_ARG_INT, &version, "target version", NULL },
     { "rate", 'r', 0, G_OPTION_ARG_INT, &rate, "the frame rate of the resulting Flash file", NULL },
     { "size", 's', 0, G_OPTION_ARG_STRING, &size_string, "the size give as WxH of the resulting Flash file", NULL },
+    { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_filename, "output filename", NULL },
     { NULL }
   };
   GOptionContext *ctx;
@@ -104,8 +106,8 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  if (argc != 3) {
-    g_printerr ("Usage: %s INFILE OUTFILE\n", argv[0]);
+  if (argc != 2) {
+    g_printerr ("Usage: %s [OPTIONS] INFILE\n", argv[0]);
     return 1;
   }
 
@@ -179,8 +181,8 @@ main (int argc, char *argv[])
   output = create_file (script->buffer, version, rate, size_rect);
   swfdec_script_unref (script);
 
-  if (!g_file_set_contents (argv[2], (char *) output->data, output->length,
-	&error)) {
+  if (!g_file_set_contents (output_filename, (char *) output->data,
+	output->length, &error)) {
     swfdec_buffer_unref (output);
     g_printerr ("Error saving: %s\n", error->message);
     return 1;
commit b96cfad66338bb1881699d6a1b61b56a0be071e6
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 13:00:03 2008 +0300

    Allow specifying version, rate and size for vivi-compile

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 1e744c1..100bcb2 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -31,17 +31,20 @@
 #include "vivi_code_assembler.h"
 
 static SwfdecBuffer *
-create_file (SwfdecBuffer *actions)
+create_file (SwfdecBuffer *actions, guint version, guint rate, SwfdecRect rect)
 {
   SwfdecBots *bots, *full;
-  SwfdecRect rect = { 0, 0, 2000, 3000 };
+
+  g_return_val_if_fail (actions != NULL, NULL);
+  g_return_val_if_fail (version <= 255, NULL);
+  g_return_val_if_fail (rate <= 255, NULL);
 
   bots = swfdec_bots_open ();
 
   // Frame size
   swfdec_bots_put_rect (bots, &rect);
   // Frame rate
-  swfdec_bots_put_u16 (bots, 15 * 256);
+  swfdec_bots_put_u16 (bots, rate * 256);
   // Frame count
   swfdec_bots_put_u16 (bots, 1);
 
@@ -62,7 +65,7 @@ create_file (SwfdecBuffer *actions)
   swfdec_bots_put_u8 (full, 'F');
   swfdec_bots_put_u8 (full, 'W');
   swfdec_bots_put_u8 (full, 'S');
-  swfdec_bots_put_u8 (full, 8);
+  swfdec_bots_put_u8 (full, version);
   swfdec_bots_put_u32 (full, swfdec_bots_get_bytes (bots) + 8);
   swfdec_bots_put_bots (full, bots);
   swfdec_bots_free (bots);
@@ -76,15 +79,76 @@ main (int argc, char *argv[])
   SwfdecBuffer *source, *output;
   ViviCodeStatement *statement, *assembler;
   SwfdecScript *script;
+  int version = 8;
+  int rate = 15;
+  char *size_string = NULL;
+  SwfdecRect size_rect = { 0, 0, 2000, 3000 };
   GError *error = NULL;
 
-  swfdec_init ();
+  GOptionEntry options[] = {
+    { "version", 'v', 0, G_OPTION_ARG_INT, &version, "target version", NULL },
+    { "rate", 'r', 0, G_OPTION_ARG_INT, &rate, "the frame rate of the resulting Flash file", NULL },
+    { "size", 's', 0, G_OPTION_ARG_STRING, &size_string, "the size give as WxH of the resulting Flash file", NULL },
+    { NULL }
+  };
+  GOptionContext *ctx;
+
+  ctx = g_option_context_new ("");
+  g_option_context_add_main_entries (ctx, options, "options");
+  g_option_context_parse (ctx, &argc, &argv, &error);
+  g_option_context_free (ctx);
+
+  if (error) {
+    g_printerr ("Error parsing command line arguments: %s\n", error->message);
+    g_error_free (error);
+    return 1;
+  }
 
   if (argc != 3) {
-    g_printerr ("Usage: %s <input file> <output file>\n", argv[0]);
+    g_printerr ("Usage: %s INFILE OUTFILE\n", argv[0]);
+    return 1;
+  }
+
+  if (version < 0 || version > 255) {
+    g_printerr ("Invalid version number\n");
+    return 1;
+  }
+
+  if (rate < 0 || rate > 255) {
+    g_printerr ("Invalid frame rate\n");
     return 1;
   }
 
+  if (size_string != NULL) {
+    char **parts, *end;
+    guint64 width, height;
+
+    parts = g_strsplit (size_string, "x", 2);
+    if (parts[0] == NULL || parts[1] == NULL) {
+      g_printerr ("Invalid size, use <width>x<height>\n");
+      return 1;
+    }
+
+    width = g_ascii_strtoull (parts[0], &end, 10);
+    if (*end != 0) {
+      g_printerr ("Invalid size, use <width>x<height>\n");
+      return 1;
+    }
+
+    height = g_ascii_strtoull (parts[1], &end, 10);
+    if (*end != 0) {
+      g_printerr ("Invalid size, use <width>x<height>\n");
+      return 1;
+    }
+
+    // FIXME: size limit?
+
+    size_rect.x1 = 20 * width;
+    size_rect.y1 = 20 * height;
+  }
+
+  swfdec_init ();
+
   source = swfdec_buffer_new_from_file (argv[1], &error);
   if (source == NULL) {
     g_printerr ("Couldn't open: %s", error->message);
@@ -103,7 +167,7 @@ main (int argc, char *argv[])
   assembler = vivi_code_assembler_new ();
   vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
   script = vivi_code_assembler_assemble_script (
-      VIVI_CODE_ASSEMBLER (assembler), 8, NULL);
+      VIVI_CODE_ASSEMBLER (assembler), version, NULL);
   g_object_unref (assembler);
   g_object_unref (statement);
 
@@ -112,7 +176,7 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  output = create_file (script->buffer);
+  output = create_file (script->buffer, version, rate, size_rect);
   swfdec_script_unref (script);
 
   if (!g_file_set_contents (argv[2], (char *) output->data, output->length,
commit 66cb1209330659e457ca900926b4ea966f9ebc9e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed May 7 11:37:45 2008 +0300

    Make vivi-compile actually create .swf files

diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index fb396b3..1e744c1 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -22,29 +22,66 @@
 #endif
 
 #include <swfdec/swfdec.h>
+#include <swfdec/swfdec_bots.h>
+#include <swfdec/swfdec_script_internal.h>
+#include <swfdec/swfdec_tag.h>
 
 #include "vivi_parser.h"
 #include "vivi_code_text_printer.h"
 #include "vivi_code_assembler.h"
 
+static SwfdecBuffer *
+create_file (SwfdecBuffer *actions)
+{
+  SwfdecBots *bots, *full;
+  SwfdecRect rect = { 0, 0, 2000, 3000 };
+
+  bots = swfdec_bots_open ();
+
+  // Frame size
+  swfdec_bots_put_rect (bots, &rect);
+  // Frame rate
+  swfdec_bots_put_u16 (bots, 15 * 256);
+  // Frame count
+  swfdec_bots_put_u16 (bots, 1);
+
+  // DoAction
+  swfdec_bots_put_u16 (bots,
+      GUINT16_TO_LE ((SWFDEC_TAG_DOACTION << 6) + 0x3F));
+  swfdec_bots_put_u32 (bots, actions->length);
+  swfdec_bots_put_buffer (bots, actions);
+
+  // ShowFrame
+  swfdec_bots_put_u16 (bots, GUINT16_TO_LE (SWFDEC_TAG_SHOWFRAME << 6));
+
+  // End
+  swfdec_bots_put_u16 (bots, 0);
+
+  // Header
+  full = swfdec_bots_open ();
+  swfdec_bots_put_u8 (full, 'F');
+  swfdec_bots_put_u8 (full, 'W');
+  swfdec_bots_put_u8 (full, 'S');
+  swfdec_bots_put_u8 (full, 8);
+  swfdec_bots_put_u32 (full, swfdec_bots_get_bytes (bots) + 8);
+  swfdec_bots_put_bots (full, bots);
+  swfdec_bots_free (bots);
+
+  return swfdec_bots_close (full);
+}
+
 int
 main (int argc, char *argv[])
 {
-  //char *target_name;
-  SwfdecBuffer *source;
+  SwfdecBuffer *source, *output;
   ViviCodeStatement *statement, *assembler;
-  ViviCodePrinter *printer;
-  /*ViviCodeCompiler *compiler;
-  SwfdecBots *bots;
-  SwfdecBuffer *buffer;
-  unsigned char *length_ptr;
-  SwfdecRect rect = { 0, 0, 2000, 3000 };*/
+  SwfdecScript *script;
   GError *error = NULL;
 
   swfdec_init ();
 
-  if (argc != 2) {
-    g_printerr ("Usage: %s <filename>\n", argv[0]);
+  if (argc != 3) {
+    g_printerr ("Usage: %s <input file> <output file>\n", argv[0]);
     return 1;
   }
 
@@ -63,88 +100,27 @@ main (int argc, char *argv[])
     return 1;
   }
 
-  /*printer = vivi_code_text_printer_new ();
-  vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
-  g_object_unref (printer);*/
-
-
   assembler = vivi_code_assembler_new ();
   vivi_code_statement_compile (statement, VIVI_CODE_ASSEMBLER (assembler));
-  printer = vivi_code_text_printer_new ();
-  vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (assembler));
-  g_object_unref (printer);
+  script = vivi_code_assembler_assemble_script (
+      VIVI_CODE_ASSEMBLER (assembler), 8, NULL);
   g_object_unref (assembler);
+  g_object_unref (statement);
 
-#if 0
-  bots = swfdec_bots_open ();
-
-
-  // header
-
-  // magic
-  swfdec_bots_put_u8 (bots, 'F');
-  swfdec_bots_put_u8 (bots, 'W');
-  swfdec_bots_put_u8 (bots, 'S');
-  // version
-  swfdec_bots_put_u8 (bots, 8);
-  // length
-  swfdec_bots_put_u32 (bots, 0);
-  // frame size
-  swfdec_bots_put_rect (bots, &rect);
-  // frame rate
-  swfdec_bots_put_u16 (bots, 15 * 256);
-  // frame count
-  swfdec_bots_put_u16 (bots, 1);
-
-
-  // tags
-
-  // doaction tag
-
-  compiler = vivi_code_compiler_new ();
-  vivi_code_compiler_compile_token (compiler, VIVI_CODE_TOKEN (statement));
-  buffer = vivi_code_compiler_get_data (compiler);
-  g_object_unref (compiler);
-
-  swfdec_bots_put_u16 (bots, GUINT16_TO_LE ((12 << 6) + 0x3F));
-  swfdec_bots_put_u32 (bots, buffer->length + 1);
-  swfdec_bots_put_buffer (bots, buffer);
-  swfdec_buffer_unref (buffer);
-  // end action
-  swfdec_bots_put_u8 (bots, 0);
-
-  // showframe tag
-  swfdec_bots_put_u16 (bots, GUINT16_TO_LE (1 << 6));
-
-  // end tag
-  swfdec_bots_put_u16 (bots, 0);
-
-
-  // write it
-
-  buffer = swfdec_bots_close (bots);
-
-  // fix length
-  length_ptr = buffer->data + 4;
-  *(guint32 *)length_ptr = GUINT32_TO_LE (buffer->length);
-
-  target_name = g_strdup_printf ("%s.swf", argv[1]);
-  target = fopen (target_name, "w+");
-  g_free (target_name);
-
-  if (fwrite (buffer->data, buffer->length, 1, target) != 1) {
-    g_printerr ("Failed to write the botsput file\n");
-    fclose (target);
-    swfdec_buffer_unref (buffer);
-    g_object_unref (player);
+  if (script == NULL) {
+    g_printerr ("Script assembling failed\n");
     return 1;
   }
 
-  fclose (target);
-  swfdec_buffer_unref (buffer);
-#endif
+  output = create_file (script->buffer);
+  swfdec_script_unref (script);
 
-  g_object_unref (statement);
+  if (!g_file_set_contents (argv[2], (char *) output->data, output->length,
+	&error)) {
+    swfdec_buffer_unref (output);
+    g_printerr ("Error saving: %s\n", error->message);
+    return 1;
+  }
 
-  return (statement == NULL ? -1 : 0);
+  return 0;
 }


More information about the Swfdec-commits mailing list