[Swfdec-commits] 12 commits - swfdec/Makefile.am swfdec/swfdec_bots.c swfdec/swfdec_bots.h tools/Makefile.am tools/swfdec_out.c tools/swfdec_out.h tools/swfedit.c tools/swfedit_file.c tools/swfedit_file.h tools/swfedit_list.c tools/swfedit_list.h tools/swfedit_tag.c tools/swfedit_tag.h tools/swfedit_token.c tools/swfedit_token.h tools/swfscript.c vivified/code
Pekka Lampila
medar at kemper.freedesktop.org
Sun Apr 6 07:05:28 PDT 2008
swfdec/Makefile.am | 2
swfdec/swfdec_bots.c | 381 ++++++++++
swfdec/swfdec_bots.h | 88 ++
tools/Makefile.am | 30
tools/swfdec_out.c | 381 ----------
tools/swfdec_out.h | 88 --
tools/swfedit.c | 138 ---
tools/swfedit_file.c | 297 --------
tools/swfedit_file.h | 60 -
tools/swfedit_list.c | 149 ----
tools/swfedit_list.h | 61 -
tools/swfedit_tag.c | 507 --------------
tools/swfedit_tag.h | 83 --
tools/swfedit_token.c | 795 ----------------------
tools/swfedit_token.h | 109 ---
tools/swfscript.c | 298 --------
vivified/code/Makefile.am | 4
vivified/code/compiler.c | 104 ++
vivified/code/vivi_code_assignment.c | 31
vivified/code/vivi_code_block.c | 14
vivified/code/vivi_code_compiler.c | 173 ++++
vivified/code/vivi_code_compiler.h | 83 ++
vivified/code/vivi_code_constant.c | 62 +
vivified/code/vivi_code_get.c | 20
vivified/code/vivi_code_token.h | 3
vivified/code/vivi_code_trace.c | 14
vivified/code/vivi_compiler.c | 49 +
vivified/code/vivi_compiler_scanner.c | 43 +
vivified/code/vivi_compiler_scanner.h | 23
vivified/code/vivi_compiler_scanner_lex.l | 148 +++-
vivified/code/vivi_compiler_scanner_lex_include.h | 3
31 files changed, 1197 insertions(+), 3044 deletions(-)
New commits:
commit f07cf46fd515c87ad228407c01123eecd08fd1bc
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 16:55:25 2008 +0300
Remove swfedit. Move SwfdecOut from tools/ to swfdec/ and rename to SwfdecBots
diff --git a/swfdec/Makefile.am b/swfdec/Makefile.am
index 016c2a9..ed3104b 100644
--- a/swfdec/Makefile.am
+++ b/swfdec/Makefile.am
@@ -47,6 +47,7 @@ libswfdec_source_files = \
swfdec_bitmap_filter.c \
swfdec_bits.c \
swfdec_blur_filter.c \
+ swfdec_bots.c \
swfdec_buffer.c \
swfdec_button.c \
swfdec_button_movie.c \
@@ -226,6 +227,7 @@ noinst_HEADERS = \
swfdec_audio_flv.h \
swfdec_audio_stream.h \
swfdec_bits.h \
+ swfdec_bots.h \
swfdec_button.h \
swfdec_button_movie.h \
swfdec_cache.h \
diff --git a/swfdec/swfdec_bots.c b/swfdec/swfdec_bots.c
new file mode 100644
index 0000000..680108e
--- /dev/null
+++ b/swfdec/swfdec_bots.c
@@ -0,0 +1,381 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include "swfdec_bots.h"
+
+SwfdecBots *
+swfdec_bots_open (void)
+{
+ SwfdecBots *bots = g_new0 (SwfdecBots, 1);
+
+ bots->data = g_malloc (SWFDEC_OUT_INITIAL);
+ bots->ptr = bots->data;
+ bots->end = bots->data + SWFDEC_OUT_INITIAL;
+
+ return bots;
+}
+
+static void
+swfdec_bots_syncbits (SwfdecBots *bots)
+{
+ g_return_if_fail (bots != NULL);
+
+ if (bots->idx > 0) {
+ bots->ptr++;
+ bots->idx = 0;
+ }
+}
+
+SwfdecBuffer *
+swfdec_bots_close (SwfdecBots *bots)
+{
+ SwfdecBuffer *buffer;
+
+ g_return_val_if_fail (bots != NULL, NULL);
+
+ swfdec_bots_syncbits (bots);
+
+ buffer = swfdec_buffer_new_for_data (bots->data, bots->ptr - bots->data);
+
+ g_free (bots);
+
+ return buffer;
+}
+
+unsigned int
+swfdec_bots_get_bits (SwfdecBots *bots)
+{
+ g_return_val_if_fail (bots != NULL, 0);
+
+ return (bots->ptr - bots->data) * 8 + bots->idx;
+}
+
+unsigned int
+swfdec_bots_left (SwfdecBots *bots)
+{
+ g_return_val_if_fail (bots != NULL, 0);
+
+ return (bots->end - bots->ptr) * 8 - bots->idx;
+}
+
+void
+swfdec_bots_ensure_bits (SwfdecBots *bots, unsigned int bits)
+{
+ unsigned int current, taken, needed;
+
+ g_return_if_fail (bots != NULL);
+
+ current = swfdec_bots_left (bots);
+ if (current >= bits)
+ return;
+ taken = bots->ptr - bots->data;
+ needed = (bits - current + 7) / 8;
+ needed += SWFDEC_OUT_STEP;
+ needed -= needed % SWFDEC_OUT_STEP;
+ needed += bots->end - bots->data;
+ bots->data = g_realloc (bots->data, needed);
+ bots->ptr = bots->data + taken;
+ bots->end = bots->data + needed;
+}
+
+void
+swfdec_bots_prepare_bytes (SwfdecBots *bots, unsigned int bytes)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_syncbits (bots);
+ swfdec_bots_ensure_bits (bots, bytes * 8);
+}
+
+void
+swfdec_bots_put_data (SwfdecBots *bots, const guint8 *data, guint length)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_prepare_bytes (bots, length);
+ memcpy (bots->ptr, data, length);
+ bots->ptr += length;
+}
+
+void
+swfdec_bots_put_buffer (SwfdecBots *bots, SwfdecBuffer *buffer)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_prepare_bytes (bots, buffer->length);
+ memcpy (bots->ptr, buffer->data, buffer->length);
+ bots->ptr += buffer->length;
+}
+
+void
+swfdec_bots_put_u8 (SwfdecBots *bots, guint i)
+{
+ g_return_if_fail (i <= G_MAXUINT8);
+
+ swfdec_bots_prepare_bytes (bots, 1);
+ *bots->ptr = i;
+ bots->ptr++;
+}
+
+void
+swfdec_bots_put_u16 (SwfdecBots *bots, guint i)
+{
+ g_return_if_fail (i <= G_MAXUINT16);
+
+ swfdec_bots_prepare_bytes (bots, 2);
+ *(guint16 *)bots->ptr = GUINT16_TO_LE (i);
+ bots->ptr += 2;
+}
+
+void
+swfdec_bots_put_u32 (SwfdecBots *bots, guint i)
+{
+ g_return_if_fail (i <= G_MAXUINT32);
+
+ swfdec_bots_prepare_bytes (bots, 4);
+ *(guint32 *)bots->ptr = GUINT32_TO_LE (i);
+ bots->ptr += 4;
+}
+
+void
+swfdec_bots_put_bit (SwfdecBots *bots, gboolean bit)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_put_bits (bots, bit ? 1 : 0, 1);
+}
+
+void
+swfdec_bots_put_bits (SwfdecBots *bots, guint bits, guint n_bits)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_ensure_bits (bots, n_bits);
+
+ /* FIXME: implement this less braindead */
+ while (n_bits) {
+ guint bits_now = MIN (n_bits, 8 - bots->idx);
+ guint value = bits >> (n_bits - bits_now);
+
+ /* clear data if necessary */
+ if (bots->idx == 0)
+ *bots->ptr = 0;
+ value &= (1 << bits_now) - 1;
+ value <<= 8 - bots->idx - bits_now;
+ *bots->ptr |= value;
+ bots->idx += bits_now;
+ g_assert (bots->idx <= 8);
+ if (bots->idx == 8) {
+ bots->ptr ++;
+ bots->idx = 0;
+ }
+ n_bits -= bits_now;
+ }
+}
+
+void
+swfdec_bots_put_sbits (SwfdecBots *bots, int bits, guint n_bits)
+{
+ g_return_if_fail (bots != NULL);
+ swfdec_bots_put_bits (bots, bits, n_bits);
+}
+
+void
+swfdec_bots_put_string (SwfdecBots *bots, const char *s)
+{
+ guint len;
+
+ g_return_if_fail (bots != NULL);
+ g_return_if_fail (s != NULL);
+
+ len = strlen (s) + 1;
+
+ swfdec_bots_prepare_bytes (bots, len);
+ memcpy (bots->ptr, s, len);
+ bots->ptr += len;
+}
+
+static guint
+swfdec_bots_bits_required (guint x)
+{
+ guint ret = 0;
+
+ while (x > 0) {
+ x >>= 1;
+ ret++;
+ }
+ return ret;
+}
+
+static guint
+swfdec_bots_sbits_required (int x)
+{
+ if (x < 0)
+ x = !x;
+ return swfdec_bots_bits_required (x) + 1;
+}
+
+void
+swfdec_bots_put_rect (SwfdecBots *bots, const SwfdecRect *rect)
+{
+ int x0, x1, y0, y1;
+ guint req, tmp;
+
+ g_return_if_fail (bots != NULL);
+ g_return_if_fail (rect != NULL);
+
+ x0 = rect->x0;
+ y0 = rect->y0;
+ x1 = rect->x1;
+ y1 = rect->y1;
+ req = swfdec_bots_sbits_required (x0);
+ tmp = swfdec_bots_sbits_required (y0);
+ req = MAX (req, tmp);
+ tmp = swfdec_bots_sbits_required (x1);
+ req = MAX (req, tmp);
+ tmp = swfdec_bots_sbits_required (y1);
+ req = MAX (req, tmp);
+ swfdec_bots_syncbits (bots);
+ swfdec_bots_put_bits (bots, req, 5);
+ swfdec_bots_put_sbits (bots, x0, req);
+ swfdec_bots_put_sbits (bots, x1, req);
+ swfdec_bots_put_sbits (bots, y0, req);
+ swfdec_bots_put_sbits (bots, y1, req);
+ swfdec_bots_syncbits (bots);
+}
+
+void
+swfdec_bots_put_matrix (SwfdecBots *bots, const cairo_matrix_t *matrix)
+{
+ int x, y;
+ unsigned int xbits, ybits;
+
+ if (matrix->xx != 1.0 || matrix->yy != 1.0) {
+ swfdec_bots_put_bit (bots, 1);
+ x = SWFDEC_DOUBLE_TO_FIXED (matrix->xx);
+ y = SWFDEC_DOUBLE_TO_FIXED (matrix->yy);
+ xbits = swfdec_bots_sbits_required (x);
+ ybits = swfdec_bots_sbits_required (y);
+ xbits = MAX (xbits, ybits);
+ swfdec_bots_put_bits (bots, xbits, 5);
+ swfdec_bots_put_sbits (bots, x, xbits);
+ swfdec_bots_put_sbits (bots, y, xbits);
+ } else {
+ swfdec_bots_put_bit (bots, 0);
+ }
+ if (matrix->xy != 0.0 || matrix->yx != 0.0) {
+ swfdec_bots_put_bit (bots, 1);
+ x = SWFDEC_DOUBLE_TO_FIXED (matrix->yx);
+ y = SWFDEC_DOUBLE_TO_FIXED (matrix->xy);
+ xbits = swfdec_bots_sbits_required (x);
+ ybits = swfdec_bots_sbits_required (y);
+ xbits = MAX (xbits, ybits);
+ swfdec_bots_put_bits (bots, xbits, 5);
+ swfdec_bots_put_sbits (bots, x, xbits);
+ swfdec_bots_put_sbits (bots, y, xbits);
+ } else {
+ swfdec_bots_put_bit (bots, 0);
+ }
+ x = matrix->x0;
+ y = matrix->y0;
+ xbits = swfdec_bots_sbits_required (x);
+ ybits = swfdec_bots_sbits_required (y);
+ xbits = MAX (xbits, ybits);
+ swfdec_bots_put_bits (bots, xbits, 5);
+ swfdec_bots_put_sbits (bots, x, xbits);
+ swfdec_bots_put_sbits (bots, y, xbits);
+ swfdec_bots_syncbits (bots);
+}
+
+void
+swfdec_bots_put_color_transform (SwfdecBots *bots, const SwfdecColorTransform *trans)
+{
+ gboolean has_add, has_mult;
+ unsigned int n_bits, tmp;
+
+ has_mult = trans->ra != 256 || trans->ga != 256 || trans->ba != 256 || trans->aa != 256;
+ has_add = trans->rb != 0 || trans->gb != 0 || trans->bb != 0 || trans->ab != 0;
+ if (has_mult) {
+ n_bits = swfdec_bots_sbits_required (trans->ra);
+ tmp = swfdec_bots_sbits_required (trans->ga);
+ n_bits = MAX (tmp, n_bits);
+ tmp = swfdec_bots_sbits_required (trans->ba);
+ n_bits = MAX (tmp, n_bits);
+ tmp = swfdec_bots_sbits_required (trans->aa);
+ n_bits = MAX (tmp, n_bits);
+ } else {
+ n_bits = 0;
+ }
+ if (has_add) {
+ tmp = swfdec_bots_sbits_required (trans->rb);
+ n_bits = MAX (tmp, n_bits);
+ tmp = swfdec_bots_sbits_required (trans->gb);
+ n_bits = MAX (tmp, n_bits);
+ tmp = swfdec_bots_sbits_required (trans->bb);
+ n_bits = MAX (tmp, n_bits);
+ tmp = swfdec_bots_sbits_required (trans->ab);
+ n_bits = MAX (tmp, n_bits);
+ }
+ if (n_bits >= (1 << 4))
+ n_bits = (1 << 4) - 1;
+ swfdec_bots_put_bit (bots, has_add);
+ swfdec_bots_put_bit (bots, has_mult);
+ swfdec_bots_put_bits (bots, n_bits, 4);
+ if (has_mult) {
+ swfdec_bots_put_sbits (bots, trans->ra, n_bits);
+ swfdec_bots_put_sbits (bots, trans->ga, n_bits);
+ swfdec_bots_put_sbits (bots, trans->ba, n_bits);
+ swfdec_bots_put_sbits (bots, trans->aa, n_bits);
+ }
+ if (has_add) {
+ swfdec_bots_put_sbits (bots, trans->rb, n_bits);
+ swfdec_bots_put_sbits (bots, trans->gb, n_bits);
+ swfdec_bots_put_sbits (bots, trans->bb, n_bits);
+ swfdec_bots_put_sbits (bots, trans->ab, n_bits);
+ }
+ swfdec_bots_syncbits (bots);
+}
+
+void
+swfdec_bots_put_rgb (SwfdecBots *bots, SwfdecColor color)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_R (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_G (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_B (color));
+}
+
+void
+swfdec_bots_put_rgba (SwfdecBots *bots, SwfdecColor color)
+{
+ g_return_if_fail (bots != NULL);
+
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_R (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_G (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_B (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_A (color));
+}
+
diff --git a/swfdec/swfdec_bots.h b/swfdec/swfdec_bots.h
new file mode 100644
index 0000000..17da233
--- /dev/null
+++ b/swfdec/swfdec_bots.h
@@ -0,0 +1,88 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef __SWFDEC_OUT_H__
+#define __SWFDEC_OUT_H__
+
+#include <swfdec/swfdec_buffer.h>
+#include <swfdec/swfdec_color.h>
+#include <swfdec/swfdec_rect.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _SwfdecBots SwfdecBots;
+
+struct _SwfdecBots {
+ unsigned char * data;
+ unsigned char * ptr;
+ unsigned int idx;
+ unsigned char * end;
+};
+
+#define SWFDEC_OUT_INITIAL (32)
+#define SWFDEC_OUT_STEP (32)
+
+SwfdecBots * swfdec_bots_open (void);
+SwfdecBuffer * swfdec_bots_close (SwfdecBots * bots);
+
+unsigned int swfdec_bots_get_bits (SwfdecBots * bots);
+unsigned int swfdec_bots_left (SwfdecBots * bots);
+void swfdec_bots_ensure_bits (SwfdecBots * bots,
+ unsigned int bits);
+void swfdec_bots_prepare_bytes (SwfdecBots * bots,
+ unsigned int bytes);
+
+void swfdec_bots_put_bit (SwfdecBots * bots,
+ gboolean bit);
+void swfdec_bots_put_bits (SwfdecBots * bots,
+ guint bits,
+ guint n_bits);
+void swfdec_bots_put_sbits (SwfdecBots * bots,
+ int bits,
+ guint n_bits);
+void swfdec_bots_put_data (SwfdecBots * bots,
+ const guint8 * data,
+ guint length);
+void swfdec_bots_put_buffer (SwfdecBots * bots,
+ SwfdecBuffer * buffer);
+void swfdec_bots_put_u8 (SwfdecBots * bots,
+ guint i);
+void swfdec_bots_put_u16 (SwfdecBots * bots,
+ guint i);
+void swfdec_bots_put_u32 (SwfdecBots * bots,
+ guint i);
+void swfdec_bots_put_string (SwfdecBots * bots,
+ const char * s);
+
+void swfdec_bots_put_rgb (SwfdecBots * bots,
+ SwfdecColor color);
+void swfdec_bots_put_rgba (SwfdecBots * bots,
+ SwfdecColor color);
+void swfdec_bots_put_rect (SwfdecBots * bots,
+ const SwfdecRect * rect);
+void swfdec_bots_put_matrix (SwfdecBots * bots,
+ const cairo_matrix_t * matrix);
+void swfdec_bots_put_color_transform (SwfdecBots * bots,
+ const SwfdecColorTransform *trans);
+
+
+G_END_DECLS
+
+#endif
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 9064878..bfaecf2 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,9 +1,4 @@
-if WITH_GTK
-noinst_LTLIBRARIES = libswfedit.la
-noinst_PROGRAMS = swfdec-extract dump swfedit swfscript crashfinder
-else
noinst_PROGRAMS = swfdec-extract dump crashfinder
-endif
crashfinder_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS)
crashfinder_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS)
@@ -14,28 +9,3 @@ dump_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS) $(PANGO_LIBS)
swfdec_extract_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS)
swfdec_extract_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS)
-
-libswfedit_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(GTK_CFLAGS)
-libswfedit_la_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS)
-
-swfedit_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(GTK_CFLAGS)
-swfedit_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS)
-swfedit_LDADD = libswfedit.la
-
-swfscript_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(GTK_CFLAGS)
-swfscript_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS)
-swfscript_LDADD = libswfedit.la
-
-libswfedit_la_SOURCES = \
- swfdec_out.c \
- swfedit_file.c \
- swfedit_list.c \
- swfedit_tag.c \
- swfedit_token.c
-
-noinst_HEADERS = \
- swfdec_out.h \
- swfedit_file.h \
- swfedit_list.h \
- swfedit_tag.h \
- swfedit_token.h
diff --git a/tools/swfdec_out.c b/tools/swfdec_out.c
deleted file mode 100644
index 0684ce1..0000000
--- a/tools/swfdec_out.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-
-#include "swfdec_out.h"
-
-SwfdecOut *
-swfdec_out_open (void)
-{
- SwfdecOut *out = g_new0 (SwfdecOut, 1);
-
- out->data = g_malloc (SWFDEC_OUT_INITIAL);
- out->ptr = out->data;
- out->end = out->data + SWFDEC_OUT_INITIAL;
-
- return out;
-}
-
-static void
-swfdec_out_syncbits (SwfdecOut *out)
-{
- g_return_if_fail (out != NULL);
-
- if (out->idx > 0) {
- out->ptr++;
- out->idx = 0;
- }
-}
-
-SwfdecBuffer *
-swfdec_out_close (SwfdecOut *out)
-{
- SwfdecBuffer *buffer;
-
- g_return_val_if_fail (out != NULL, NULL);
-
- swfdec_out_syncbits (out);
-
- buffer = swfdec_buffer_new_for_data (out->data, out->ptr - out->data);
-
- g_free (out);
-
- return buffer;
-}
-
-unsigned int
-swfdec_out_get_bits (SwfdecOut *out)
-{
- g_return_val_if_fail (out != NULL, 0);
-
- return (out->ptr - out->data) * 8 + out->idx;
-}
-
-unsigned int
-swfdec_out_left (SwfdecOut *out)
-{
- g_return_val_if_fail (out != NULL, 0);
-
- return (out->end - out->ptr) * 8 - out->idx;
-}
-
-void
-swfdec_out_ensure_bits (SwfdecOut *out, unsigned int bits)
-{
- unsigned int current, taken, needed;
-
- g_return_if_fail (out != NULL);
-
- current = swfdec_out_left (out);
- if (current >= bits)
- return;
- taken = out->ptr - out->data;
- needed = (bits - current + 7) / 8;
- needed += SWFDEC_OUT_STEP;
- needed -= needed % SWFDEC_OUT_STEP;
- needed += out->end - out->data;
- out->data = g_realloc (out->data, needed);
- out->ptr = out->data + taken;
- out->end = out->data + needed;
-}
-
-void
-swfdec_out_prepare_bytes (SwfdecOut *out, unsigned int bytes)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_syncbits (out);
- swfdec_out_ensure_bits (out, bytes * 8);
-}
-
-void
-swfdec_out_put_data (SwfdecOut *out, const guint8 *data, guint length)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_prepare_bytes (out, length);
- memcpy (out->ptr, data, length);
- out->ptr += length;
-}
-
-void
-swfdec_out_put_buffer (SwfdecOut *out, SwfdecBuffer *buffer)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_prepare_bytes (out, buffer->length);
- memcpy (out->ptr, buffer->data, buffer->length);
- out->ptr += buffer->length;
-}
-
-void
-swfdec_out_put_u8 (SwfdecOut *out, guint i)
-{
- g_return_if_fail (i <= G_MAXUINT8);
-
- swfdec_out_prepare_bytes (out, 1);
- *out->ptr = i;
- out->ptr++;
-}
-
-void
-swfdec_out_put_u16 (SwfdecOut *out, guint i)
-{
- g_return_if_fail (i <= G_MAXUINT16);
-
- swfdec_out_prepare_bytes (out, 2);
- *(guint16 *)out->ptr = GUINT16_TO_LE (i);
- out->ptr += 2;
-}
-
-void
-swfdec_out_put_u32 (SwfdecOut *out, guint i)
-{
- g_return_if_fail (i <= G_MAXUINT32);
-
- swfdec_out_prepare_bytes (out, 4);
- *(guint32 *)out->ptr = GUINT32_TO_LE (i);
- out->ptr += 4;
-}
-
-void
-swfdec_out_put_bit (SwfdecOut *out, gboolean bit)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_put_bits (out, bit ? 1 : 0, 1);
-}
-
-void
-swfdec_out_put_bits (SwfdecOut *out, guint bits, guint n_bits)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_ensure_bits (out, n_bits);
-
- /* FIXME: implement this less braindead */
- while (n_bits) {
- guint bits_now = MIN (n_bits, 8 - out->idx);
- guint value = bits >> (n_bits - bits_now);
-
- /* clear data if necessary */
- if (out->idx == 0)
- *out->ptr = 0;
- value &= (1 << bits_now) - 1;
- value <<= 8 - out->idx - bits_now;
- *out->ptr |= value;
- out->idx += bits_now;
- g_assert (out->idx <= 8);
- if (out->idx == 8) {
- out->ptr ++;
- out->idx = 0;
- }
- n_bits -= bits_now;
- }
-}
-
-void
-swfdec_out_put_sbits (SwfdecOut *out, int bits, guint n_bits)
-{
- g_return_if_fail (out != NULL);
- swfdec_out_put_bits (out, bits, n_bits);
-}
-
-void
-swfdec_out_put_string (SwfdecOut *out, const char *s)
-{
- guint len;
-
- g_return_if_fail (out != NULL);
- g_return_if_fail (s != NULL);
-
- len = strlen (s) + 1;
-
- swfdec_out_prepare_bytes (out, len);
- memcpy (out->ptr, s, len);
- out->ptr += len;
-}
-
-static guint
-swfdec_out_bits_required (guint x)
-{
- guint ret = 0;
-
- while (x > 0) {
- x >>= 1;
- ret++;
- }
- return ret;
-}
-
-static guint
-swfdec_out_sbits_required (int x)
-{
- if (x < 0)
- x = !x;
- return swfdec_out_bits_required (x) + 1;
-}
-
-void
-swfdec_out_put_rect (SwfdecOut *out, const SwfdecRect *rect)
-{
- int x0, x1, y0, y1;
- guint req, tmp;
-
- g_return_if_fail (out != NULL);
- g_return_if_fail (rect != NULL);
-
- x0 = rect->x0;
- y0 = rect->y0;
- x1 = rect->x1;
- y1 = rect->y1;
- req = swfdec_out_sbits_required (x0);
- tmp = swfdec_out_sbits_required (y0);
- req = MAX (req, tmp);
- tmp = swfdec_out_sbits_required (x1);
- req = MAX (req, tmp);
- tmp = swfdec_out_sbits_required (y1);
- req = MAX (req, tmp);
- swfdec_out_syncbits (out);
- swfdec_out_put_bits (out, req, 5);
- swfdec_out_put_sbits (out, x0, req);
- swfdec_out_put_sbits (out, x1, req);
- swfdec_out_put_sbits (out, y0, req);
- swfdec_out_put_sbits (out, y1, req);
- swfdec_out_syncbits (out);
-}
-
-void
-swfdec_out_put_matrix (SwfdecOut *out, const cairo_matrix_t *matrix)
-{
- int x, y;
- unsigned int xbits, ybits;
-
- if (matrix->xx != 1.0 || matrix->yy != 1.0) {
- swfdec_out_put_bit (out, 1);
- x = SWFDEC_DOUBLE_TO_FIXED (matrix->xx);
- y = SWFDEC_DOUBLE_TO_FIXED (matrix->yy);
- xbits = swfdec_out_sbits_required (x);
- ybits = swfdec_out_sbits_required (y);
- xbits = MAX (xbits, ybits);
- swfdec_out_put_bits (out, xbits, 5);
- swfdec_out_put_sbits (out, x, xbits);
- swfdec_out_put_sbits (out, y, xbits);
- } else {
- swfdec_out_put_bit (out, 0);
- }
- if (matrix->xy != 0.0 || matrix->yx != 0.0) {
- swfdec_out_put_bit (out, 1);
- x = SWFDEC_DOUBLE_TO_FIXED (matrix->yx);
- y = SWFDEC_DOUBLE_TO_FIXED (matrix->xy);
- xbits = swfdec_out_sbits_required (x);
- ybits = swfdec_out_sbits_required (y);
- xbits = MAX (xbits, ybits);
- swfdec_out_put_bits (out, xbits, 5);
- swfdec_out_put_sbits (out, x, xbits);
- swfdec_out_put_sbits (out, y, xbits);
- } else {
- swfdec_out_put_bit (out, 0);
- }
- x = matrix->x0;
- y = matrix->y0;
- xbits = swfdec_out_sbits_required (x);
- ybits = swfdec_out_sbits_required (y);
- xbits = MAX (xbits, ybits);
- swfdec_out_put_bits (out, xbits, 5);
- swfdec_out_put_sbits (out, x, xbits);
- swfdec_out_put_sbits (out, y, xbits);
- swfdec_out_syncbits (out);
-}
-
-void
-swfdec_out_put_color_transform (SwfdecOut *out, const SwfdecColorTransform *trans)
-{
- gboolean has_add, has_mult;
- unsigned int n_bits, tmp;
-
- has_mult = trans->ra != 256 || trans->ga != 256 || trans->ba != 256 || trans->aa != 256;
- has_add = trans->rb != 0 || trans->gb != 0 || trans->bb != 0 || trans->ab != 0;
- if (has_mult) {
- n_bits = swfdec_out_sbits_required (trans->ra);
- tmp = swfdec_out_sbits_required (trans->ga);
- n_bits = MAX (tmp, n_bits);
- tmp = swfdec_out_sbits_required (trans->ba);
- n_bits = MAX (tmp, n_bits);
- tmp = swfdec_out_sbits_required (trans->aa);
- n_bits = MAX (tmp, n_bits);
- } else {
- n_bits = 0;
- }
- if (has_add) {
- tmp = swfdec_out_sbits_required (trans->rb);
- n_bits = MAX (tmp, n_bits);
- tmp = swfdec_out_sbits_required (trans->gb);
- n_bits = MAX (tmp, n_bits);
- tmp = swfdec_out_sbits_required (trans->bb);
- n_bits = MAX (tmp, n_bits);
- tmp = swfdec_out_sbits_required (trans->ab);
- n_bits = MAX (tmp, n_bits);
- }
- if (n_bits >= (1 << 4))
- n_bits = (1 << 4) - 1;
- swfdec_out_put_bit (out, has_add);
- swfdec_out_put_bit (out, has_mult);
- swfdec_out_put_bits (out, n_bits, 4);
- if (has_mult) {
- swfdec_out_put_sbits (out, trans->ra, n_bits);
- swfdec_out_put_sbits (out, trans->ga, n_bits);
- swfdec_out_put_sbits (out, trans->ba, n_bits);
- swfdec_out_put_sbits (out, trans->aa, n_bits);
- }
- if (has_add) {
- swfdec_out_put_sbits (out, trans->rb, n_bits);
- swfdec_out_put_sbits (out, trans->gb, n_bits);
- swfdec_out_put_sbits (out, trans->bb, n_bits);
- swfdec_out_put_sbits (out, trans->ab, n_bits);
- }
- swfdec_out_syncbits (out);
-}
-
-void
-swfdec_out_put_rgb (SwfdecOut *out, SwfdecColor color)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_put_u8 (out, SWFDEC_COLOR_R (color));
- swfdec_out_put_u8 (out, SWFDEC_COLOR_G (color));
- swfdec_out_put_u8 (out, SWFDEC_COLOR_B (color));
-}
-
-void
-swfdec_out_put_rgba (SwfdecOut *out, SwfdecColor color)
-{
- g_return_if_fail (out != NULL);
-
- swfdec_out_put_u8 (out, SWFDEC_COLOR_R (color));
- swfdec_out_put_u8 (out, SWFDEC_COLOR_G (color));
- swfdec_out_put_u8 (out, SWFDEC_COLOR_B (color));
- swfdec_out_put_u8 (out, SWFDEC_COLOR_A (color));
-}
-
diff --git a/tools/swfdec_out.h b/tools/swfdec_out.h
deleted file mode 100644
index 2544f33..0000000
--- a/tools/swfdec_out.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __SWFDEC_OUT_H__
-#define __SWFDEC_OUT_H__
-
-#include <swfdec/swfdec_buffer.h>
-#include <swfdec/swfdec_color.h>
-#include <swfdec/swfdec_rect.h>
-
-G_BEGIN_DECLS
-
-
-typedef struct _SwfdecOut SwfdecOut;
-
-struct _SwfdecOut {
- unsigned char * data;
- unsigned char * ptr;
- unsigned int idx;
- unsigned char * end;
-};
-
-#define SWFDEC_OUT_INITIAL (32)
-#define SWFDEC_OUT_STEP (32)
-
-SwfdecOut * swfdec_out_open (void);
-SwfdecBuffer * swfdec_out_close (SwfdecOut * out);
-
-unsigned int swfdec_out_get_bits (SwfdecOut * out);
-unsigned int swfdec_out_left (SwfdecOut * out);
-void swfdec_out_ensure_bits (SwfdecOut * out,
- unsigned int bits);
-void swfdec_out_prepare_bytes (SwfdecOut * out,
- unsigned int bytes);
-
-void swfdec_out_put_bit (SwfdecOut * out,
- gboolean bit);
-void swfdec_out_put_bits (SwfdecOut * out,
- guint bits,
- guint n_bits);
-void swfdec_out_put_sbits (SwfdecOut * out,
- int bits,
- guint n_bits);
-void swfdec_out_put_data (SwfdecOut * out,
- const guint8 * data,
- guint length);
-void swfdec_out_put_buffer (SwfdecOut * out,
- SwfdecBuffer * buffer);
-void swfdec_out_put_u8 (SwfdecOut * out,
- guint i);
-void swfdec_out_put_u16 (SwfdecOut * out,
- guint i);
-void swfdec_out_put_u32 (SwfdecOut * out,
- guint i);
-void swfdec_out_put_string (SwfdecOut * out,
- const char * s);
-
-void swfdec_out_put_rgb (SwfdecOut * out,
- SwfdecColor color);
-void swfdec_out_put_rgba (SwfdecOut * out,
- SwfdecColor color);
-void swfdec_out_put_rect (SwfdecOut * out,
- const SwfdecRect * rect);
-void swfdec_out_put_matrix (SwfdecOut * out,
- const cairo_matrix_t * matrix);
-void swfdec_out_put_color_transform (SwfdecOut * out,
- const SwfdecColorTransform *trans);
-
-
-G_END_DECLS
-
-#endif
diff --git a/tools/swfedit.c b/tools/swfedit.c
deleted file mode 100644
index 24f2980..0000000
--- a/tools/swfedit.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <gtk/gtk.h>
-#include "swfedit_file.h"
-
-static void
-save (GtkButton *button, SwfeditFile *file)
-{
- GtkWidget *dialog;
- GError *error = NULL;
-
- dialog = gtk_file_chooser_dialog_new ("Save file...",
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))),
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), file->filename);
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
- g_free (file->filename);
- file->filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- if (!swfedit_file_save (file, &error)) {
- g_printerr ("Error saving file: %s\n", error->message);
- g_error_free (error);
- }
- }
- gtk_widget_destroy (dialog);
-}
-
-static void
-cell_renderer_edited (GtkCellRenderer *renderer, char *path,
- char *new_text, SwfeditFile *file)
-{
- GtkTreeIter iter;
-
- if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (file),
- &iter, path)) {
- g_assert_not_reached ();
- }
- swfedit_token_set_iter (SWFEDIT_TOKEN (file), &iter, new_text);
-}
-
-static gboolean
-open_window (char *filename)
-{
- SwfeditFile *file;
- GtkWidget *window, *scroll, *box, *button, *treeview;
- GError *error = NULL;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- char *basename;
-
- file = swfedit_file_new (filename, &error);
- if (file == NULL) {
- g_printerr ("Error opening file %s: %s\n", filename, error->message);
- g_error_free (error);
- return FALSE;
- }
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- basename = g_path_get_basename (filename);
- if (basename) {
- gtk_window_set_title (GTK_WINDOW (window), basename);
- g_free (basename);
- }
- g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
- box = gtk_vbox_new (FALSE, 3);
- gtk_container_add (GTK_CONTAINER (window), box);
-
- scroll = gtk_scrolled_window_new (NULL, NULL);
- gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0);
-
- treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (file));
- gtk_container_add (GTK_CONTAINER (scroll), treeview);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Name", renderer,
- "text", SWFEDIT_COLUMN_NAME, "sensitive", SWFEDIT_COLUMN_VALUE_EDITABLE, NULL);
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
-
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL);
- g_signal_connect (renderer, "edited", G_CALLBACK (cell_renderer_edited), file);
- column = gtk_tree_view_column_new_with_attributes ("Value", renderer,
- "text", SWFEDIT_COLUMN_VALUE, "visible", SWFEDIT_COLUMN_VALUE_VISIBLE,
- "sensitive", SWFEDIT_COLUMN_VALUE_EDITABLE, NULL);
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
-
- button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
- g_signal_connect (button, "clicked", G_CALLBACK (save), file);
- gtk_box_pack_start (GTK_BOX (box), button, FALSE, TRUE, 0);
-
- gtk_widget_show_all (window);
- return TRUE;
-}
-
-int
-main (int argc, char **argv)
-{
- gtk_init (&argc, &argv);
-
- if (argc <= 1) {
- g_print ("Usage: %s FILENAME\n", argv[0]);
- return 1;
- }
- if (open_window (argv[1])) {
- gtk_main ();
- return 0;
- } else {
- return 1;
- }
-}
-
diff --git a/tools/swfedit_file.c b/tools/swfedit_file.c
deleted file mode 100644
index 5883d46..0000000
--- a/tools/swfedit_file.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <zlib.h>
-
-#include "swfdec/swfdec_bits.h"
-#include "swfdec/swfdec_buffer.h"
-#include "swfdec/swfdec_debug.h"
-#include "swfdec/swfdec_swf_decoder.h"
-#include "swfdec_out.h"
-#include "swfedit_file.h"
-#include "swfedit_tag.h"
-
-G_DEFINE_TYPE (SwfeditFile, swfedit_file, SWFEDIT_TYPE_TOKEN)
-
-static void
-swfedit_file_dispose (GObject *object)
-{
- SwfeditFile *file = SWFEDIT_FILE (object);
-
- g_free (file->filename);
-
- G_OBJECT_CLASS (swfedit_file_parent_class)->dispose (object);
-}
-
-static void *
-zalloc (void *opaque, unsigned int items, unsigned int size)
-{
- return g_malloc (items * size);
-}
-
-static void
-zfree (void *opaque, void *addr)
-{
- g_free (addr);
-}
-
-static SwfdecBuffer *
-swfenc_file_inflate (SwfdecBits *bits, guint size)
-{
- SwfdecBuffer *decoded, *encoded;
- z_stream z;
- int ret;
-
- encoded = swfdec_bits_get_buffer (bits, -1);
- if (encoded == NULL)
- return NULL;
- decoded = swfdec_buffer_new (size);
- z.zalloc = zalloc;
- z.zfree = zfree;
- z.opaque = NULL;
- z.next_in = encoded->data;
- z.avail_in = encoded->length;
- z.next_out = decoded->data;
- z.avail_out = decoded->length;
- ret = inflateInit (&z);
- SWFDEC_DEBUG ("inflateInit returned %d", ret);
- if (ret >= Z_OK) {
- ret = inflate (&z, Z_SYNC_FLUSH);
- SWFDEC_DEBUG ("inflate returned %d", ret);
- }
- inflateEnd (&z);
- swfdec_buffer_unref (encoded);
- if (ret < Z_OK) {
- swfdec_buffer_unref (decoded);
- return NULL;
- }
- return decoded;
-}
-
-static SwfdecBuffer *
-swf_parse_header1 (SwfeditFile *file, SwfdecBits *bits, GError **error)
-{
- guint sig1, sig2, sig3, bytes_total;
-
- sig1 = swfdec_bits_get_u8 (bits);
- sig2 = swfdec_bits_get_u8 (bits);
- sig3 = swfdec_bits_get_u8 (bits);
- if ((sig1 != 'F' && sig1 != 'C') || sig2 != 'W' || sig3 != 'S') {
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "This is not a SWF file");
- return NULL;
- }
-
- swfedit_token_add (SWFEDIT_TOKEN (file), "version", SWFEDIT_TOKEN_UINT8,
- GUINT_TO_POINTER (swfdec_bits_get_u8 (bits)));
- bytes_total = swfdec_bits_get_u32 (bits) - 8;
-
- if (sig1 == 'C') {
- /* compressed */
- SwfdecBuffer *ret = swfenc_file_inflate (bits, bytes_total);
- if (ret == NULL)
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "Unable to uncompress file");
- return ret;
- } else {
- SwfdecBuffer *ret = swfdec_bits_get_buffer (bits, bytes_total);
- if (ret == NULL)
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "File too small");
- return ret;
- }
-}
-
-static void
-swf_parse_header2 (SwfeditFile *file, SwfdecBits *bits)
-{
- swfedit_tag_read_token (SWFEDIT_TOKEN (file), bits, "rect", SWFEDIT_TOKEN_RECT, NULL);
- swfedit_tag_read_token (SWFEDIT_TOKEN (file), bits, "rate", SWFEDIT_TOKEN_UINT16, NULL);
- swfedit_tag_read_token (SWFEDIT_TOKEN (file), bits, "frames", SWFEDIT_TOKEN_UINT16, NULL);
-}
-
-static gboolean
-swfedit_file_parse (SwfeditFile *file, SwfdecBits *bits, GError **error)
-{
- SwfdecBuffer *next;
-
- next = swf_parse_header1 (file, bits, error);
- if (next == NULL)
- return FALSE;
- swfdec_bits_init (bits, next);
- swf_parse_header2 (file, bits);
-
- while (swfdec_bits_left (bits)) {
- guint x = swfdec_bits_get_u16 (bits);
- G_GNUC_UNUSED guint tag = (x >> 6) & 0x3ff;
- guint tag_len = x & 0x3f;
- SwfdecBuffer *buffer;
- SwfeditTag *item;
-
- if (tag_len == 0x3f)
- tag_len = swfdec_bits_get_u32 (bits);
- if (tag == 0)
- break;
- if (tag_len > 0)
- buffer = swfdec_bits_get_buffer (bits, tag_len);
- else
- buffer = swfdec_buffer_new (0);
- if (buffer == NULL) {
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "Invalid contents in file");
- return FALSE;
- }
- item = swfedit_tag_new (SWFEDIT_TOKEN (file), tag, buffer);
- swfedit_token_add (SWFEDIT_TOKEN (file),
- swfdec_swf_decoder_get_tag_name (tag),
- SWFEDIT_TOKEN_OBJECT, item);
- }
- swfdec_buffer_unref (next);
- return TRUE;
-}
-
-static void
-swfedit_file_class_init (SwfeditFileClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->dispose = swfedit_file_dispose;
-}
-
-static void
-swfedit_file_init (SwfeditFile *s)
-{
-}
-
-SwfeditFile *
-swfedit_file_new (const char *filename, GError **error)
-{
- SwfeditFile *file;
- SwfdecBuffer *buffer;
- SwfdecBits bits;
- char *absolute;
-
- if (g_path_is_absolute (filename)) {
- absolute = g_strdup (filename);
- } else {
- char *dir = g_get_current_dir ();
- absolute = g_build_filename (dir, filename, NULL);
- g_free (dir);
- }
- buffer = swfdec_buffer_new_from_file (filename, error);
- if (buffer == NULL)
- return NULL;
- swfdec_bits_init (&bits, buffer);
- file = g_object_new (SWFEDIT_TYPE_FILE, NULL);
- file->filename = absolute;
- if (!swfedit_file_parse (file, &bits, error)) {
- swfdec_buffer_unref (buffer);
- g_object_unref (file);
- return NULL;
- }
- swfdec_buffer_unref (buffer);
- return file;
-}
-
-static SwfdecBuffer *
-swfedit_file_write (SwfeditFile *file)
-{
- guint i;
- SwfeditToken *token = SWFEDIT_TOKEN (file);
- SwfdecBufferQueue *queue;
- SwfdecBuffer *buffer;
- SwfdecOut *out;
-
- queue = swfdec_buffer_queue_new ();
- /* write second part of header */
- out = swfdec_out_open ();
- swfedit_tag_write_token (token, out, 1);
- swfedit_tag_write_token (token, out, 2);
- swfedit_tag_write_token (token, out, 3);
- swfdec_buffer_queue_push (queue, swfdec_out_close (out));
-
- for (i = 4; i < token->tokens->len; i++) {
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- g_assert (entry->type == SWFEDIT_TOKEN_OBJECT);
-
- buffer = swfedit_tag_write (entry->value);
- out = swfdec_out_open ();
- swfdec_out_put_u16 (out, SWFEDIT_TAG (entry->value)->tag << 6 |
- MIN (buffer->length, 0x3f));
- if (buffer->length >= 0x3f) {
- swfdec_out_put_u32 (out, buffer->length);
- }
- swfdec_buffer_queue_push (queue, swfdec_out_close (out));
- swfdec_buffer_queue_push (queue, buffer);
- }
- /* write closing tag */
- buffer = swfdec_buffer_new0 (2);
- swfdec_buffer_queue_push (queue, buffer);
-
- /* FIXME: implement compression */
- out = swfdec_out_open ();
- swfdec_out_put_u8 (out, 'F');
- swfdec_out_put_u8 (out, 'W');
- swfdec_out_put_u8 (out, 'S');
- swfedit_tag_write_token (token, out, 0);
- swfdec_out_put_u32 (out, swfdec_buffer_queue_get_depth (queue) + 8);
- swfdec_out_prepare_bytes (out, swfdec_buffer_queue_get_depth (queue));
- while ((buffer = swfdec_buffer_queue_pull_buffer (queue))) {
- swfdec_out_put_buffer (out, buffer);
- swfdec_buffer_unref (buffer);
- }
- swfdec_buffer_queue_unref (queue);
- return swfdec_out_close (out);
-}
-
-gboolean
-swfedit_file_save (SwfeditFile *file, GError **error)
-{
- SwfdecBuffer *buffer;
- gboolean ret;
-
- g_return_val_if_fail (SWFEDIT_IS_FILE (file), FALSE);
-
- buffer = swfedit_file_write (file);
- if (buffer == NULL) {
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "Failed to render file");
- return FALSE;
- }
- ret = g_file_set_contents (file->filename, (char *) buffer->data,
- buffer->length, error);
- swfdec_buffer_unref (buffer);
- return ret;
-}
-
-guint
-swfedit_file_get_version (SwfeditFile *file)
-{
- SwfeditTokenEntry *entry;
-
- g_return_val_if_fail (SWFEDIT_FILE (file), 3);
-
- entry = &g_array_index (SWFEDIT_TOKEN (file)->tokens, SwfeditTokenEntry, 0);
- return GPOINTER_TO_UINT (entry->value);
-}
-
diff --git a/tools/swfedit_file.h b/tools/swfedit_file.h
deleted file mode 100644
index 212c7b7..0000000
--- a/tools/swfedit_file.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __SWFEDIT_FILE_H__
-#define __SWFEDIT_FILE_H__
-
-#include <swfdec/swfdec_rect.h>
-#include "swfedit_token.h"
-
-G_BEGIN_DECLS
-
-typedef struct _SwfeditFile SwfeditFile;
-typedef struct _SwfeditFileClass SwfeditFileClass;
-
-#define SWFEDIT_TYPE_FILE (swfedit_file_get_type())
-#define SWFEDIT_IS_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFEDIT_TYPE_FILE))
-#define SWFEDIT_IS_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFEDIT_TYPE_FILE))
-#define SWFEDIT_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFEDIT_TYPE_FILE, SwfeditFile))
-#define SWFEDIT_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFEDIT_TYPE_FILE, SwfeditFileClass))
-#define SWFEDIT_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFEDIT_TYPE_FILE, SwfeditFileClass))
-
-struct _SwfeditFile {
- SwfeditToken token;
-
- char * filename; /* name this file is saved to */
-};
-
-struct _SwfeditFileClass {
- SwfeditTokenClass token_class;
-};
-
-GType swfedit_file_get_type (void);
-
-SwfeditFile * swfedit_file_new (const char * filename,
- GError ** error);
-
-gboolean swfedit_file_save (SwfeditFile * file,
- GError ** error);
-guint swfedit_file_get_version (SwfeditFile * file);
-
-
-G_END_DECLS
-
-#endif
diff --git a/tools/swfedit_list.c b/tools/swfedit_list.c
deleted file mode 100644
index 45e0dd5..0000000
--- a/tools/swfedit_list.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfedit_list.h"
-
-G_DEFINE_TYPE (SwfeditList, swfedit_list, SWFEDIT_TYPE_TOKEN)
-
-static void
-swfedit_list_dispose (GObject *object)
-{
- //SwfeditList *list = SWFEDIT_LIST (object);
-
- G_OBJECT_CLASS (swfedit_list_parent_class)->dispose (object);
-}
-
-static void
-swfedit_list_changed (SwfeditToken *token, guint i)
-{
- guint j;
- SwfeditList *list = SWFEDIT_LIST (token);
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
-
- /* update visibility */
- for (j = i + 1; j % list->n_defs != 0; j++) {
- if (list->def[j].n_items == (j % list->n_defs) + 1) {
- swfedit_token_set_visible (token, j, entry->value != NULL);
- }
- }
- /* update length */
- j = list->def[i % list->n_defs].n_items;
- if (j != 0) {
- entry = &g_array_index (token->tokens,
- SwfeditTokenEntry, j - 1);
- if (entry->type == SWFEDIT_TOKEN_UINT32) {
- SwfdecOut *out = swfdec_out_open ();
- SwfdecBuffer *buffer;
- swfedit_tag_write_token (token, out, i);
- buffer = swfdec_out_close (out);
- if (entry->value != GUINT_TO_POINTER (buffer->length)) {
- swfedit_token_set (token, i / list->n_defs * list->n_defs + j - 1,
- GUINT_TO_POINTER (buffer->length));
- }
- swfdec_buffer_unref (buffer);
- }
- }
- /* maybe add items */
- if (i == token->tokens->len - 1) {
- for (j = 0; j < list->n_defs; j++) {
- const SwfeditTagDefinition *def = &list->def[(j + 1) % list->n_defs];
- swfedit_tag_add_token (SWFEDIT_TOKEN (list), def->name, def->type, def->hint);
- }
- }
-}
-
-static void
-swfedit_list_class_init (SwfeditListClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- SwfeditTokenClass *token_class = SWFEDIT_TOKEN_CLASS (klass);
-
- object_class->dispose = swfedit_list_dispose;
-
- token_class->changed = swfedit_list_changed;
-}
-
-static void
-swfedit_list_init (SwfeditList *list)
-{
-}
-
-static SwfeditList *
-swfedit_list_new_internal (const SwfeditTagDefinition *def)
-{
- SwfeditList *list;
-
- list = g_object_new (SWFEDIT_TYPE_LIST, NULL);
- list->def = def;
- for (; def->name; def++)
- list->n_defs++;
-
- return list;
-}
-
-SwfeditList *
-swfedit_list_new (const SwfeditTagDefinition *def)
-{
- SwfeditList *list;
-
- g_return_val_if_fail (def != NULL, NULL);
-
- list = swfedit_list_new_internal (def);
- swfedit_tag_add_token (SWFEDIT_TOKEN (list), def->name, def->type, def->hint);
-
- return list;
-}
-
-SwfeditList *
-swfedit_list_new_read (SwfeditToken *parent, SwfdecBits *bits, const SwfeditTagDefinition *def)
-{
- SwfeditList *list;
- SwfeditTokenEntry *entry;
- guint offset;
-
- g_return_val_if_fail (bits != NULL, NULL);
- g_return_val_if_fail (def != NULL, NULL);
-
- list = swfedit_list_new_internal (def);
- SWFEDIT_TOKEN (list)->parent = parent;
- offset = 0;
- while (TRUE) {
- def = list->def;
- swfedit_tag_read_tag (SWFEDIT_TOKEN (list), bits, def);
- entry = &g_array_index (SWFEDIT_TOKEN (list)->tokens, SwfeditTokenEntry,
- SWFEDIT_TOKEN (list)->tokens->len - 1);
- if (GPOINTER_TO_UINT (entry->value) == 0)
- break;
-
- def++;
- for (;def->name != NULL; def++) {
- SwfeditTagDefinition def2 = *def;
- if (def2.n_items)
- def2.n_items += offset;
- swfedit_tag_read_tag (SWFEDIT_TOKEN (list), bits, &def2);
- }
- offset += list->n_defs;
- }
- return list;
-}
-
diff --git a/tools/swfedit_list.h b/tools/swfedit_list.h
deleted file mode 100644
index e0666f7..0000000
--- a/tools/swfedit_list.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __SWFEDIT_LIST_H__
-#define __SWFEDIT_LIST_H__
-
-#include "swfdec_out.h"
-#include "swfedit_tag.h"
-
-G_BEGIN_DECLS
-
-typedef struct _SwfeditList SwfeditList;
-typedef struct _SwfeditListClass SwfeditListClass;
-
-#define SWFEDIT_TYPE_LIST (swfedit_list_get_type())
-#define SWFEDIT_IS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFEDIT_TYPE_LIST))
-#define SWFEDIT_IS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFEDIT_TYPE_LIST))
-#define SWFEDIT_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFEDIT_TYPE_LIST, SwfeditList))
-#define SWFEDIT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFEDIT_TYPE_LIST, SwfeditListClass))
-#define SWFEDIT_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFEDIT_TYPE_LIST, SwfeditListClass))
-
-struct _SwfeditList {
- SwfeditToken token;
-
- const SwfeditTagDefinition * def; /* definition of our items */
- guint n_defs; /* number of items in def */
-};
-
-struct _SwfeditListClass {
- SwfeditTokenClass token_class;
-};
-
-GType swfedit_list_get_type (void);
-
-SwfeditList * swfedit_list_new (const SwfeditTagDefinition * def);
-SwfeditList * swfedit_list_new_read (SwfeditToken * parent,
- SwfdecBits * bits,
- const SwfeditTagDefinition * def);
-
-SwfdecBuffer * swfedit_list_write (SwfeditList * list);
-
-
-G_END_DECLS
-
-#endif
diff --git a/tools/swfedit_tag.c b/tools/swfedit_tag.c
deleted file mode 100644
index ccd3837..0000000
--- a/tools/swfedit_tag.c
+++ /dev/null
@@ -1,507 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <gtk/gtk.h>
-
-#include <swfdec/swfdec_bits.h>
-#include <swfdec/swfdec_debug.h>
-#include <swfdec/swfdec_script_internal.h>
-#include <swfdec/swfdec_tag.h>
-#include "swfedit_tag.h"
-#include "swfdec_out.h"
-#include "swfedit_file.h"
-#include "swfedit_list.h"
-
-/*** LOAD/SAVE ***/
-
-static void
-swfedit_object_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- SwfdecBuffer *buffer;
-
- g_assert (SWFEDIT_IS_TOKEN (data));
- buffer = swfedit_tag_write (data);
- swfdec_out_put_buffer (out, buffer);
- swfdec_buffer_unref (buffer);
-}
-
-static gpointer
-swfedit_object_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return swfedit_list_new_read (token, bits, hint);
-}
-
-static void
-swfedit_binary_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_buffer (out, data);
-}
-
-static gpointer
-swfedit_binary_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- SwfdecBuffer *buffer = swfdec_bits_get_buffer (bits, -1);
- if (buffer == NULL)
- buffer = swfdec_buffer_new (0);
- return buffer;
-}
-
-static void
-swfedit_bit_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_bit (out, data ? TRUE : FALSE);
-}
-
-static gpointer
-swfedit_bit_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER (swfdec_bits_getbit (bits) ? 1 : 0);
-}
-
-static void
-swfedit_u8_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_u8 (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_u8_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER ((gulong) swfdec_bits_get_u8 (bits));
-}
-
-static void
-swfedit_u16_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_u16 (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_u16_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER (swfdec_bits_get_u16 (bits));
-}
-
-static void
-swfedit_u32_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_u32 (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_u32_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER (swfdec_bits_get_u32 (bits));
-}
-
-static void
-swfedit_rect_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_rect (out, data);
-}
-
-static gpointer
-swfedit_rect_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- SwfdecRect *rect = g_new (SwfdecRect, 1);
- swfdec_bits_get_rect (bits, rect);
- swfdec_bits_syncbits (bits);
- return rect;
-}
-
-static void
-swfedit_string_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_string (out, data);
-}
-
-static gpointer
-swfedit_string_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- char *s;
- s = swfdec_bits_get_string (bits, 7);
- if (s == NULL)
- s = g_strdup ("");
- return s;
-}
-
-static void
-swfedit_rgb_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_rgb (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_rgb_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER (swfdec_bits_get_color (bits));
-}
-
-static void
-swfedit_rgba_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_rgba (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_rgba_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- return GUINT_TO_POINTER (swfdec_bits_get_rgba (bits));
-}
-
-static void
-swfedit_matrix_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_matrix (out, data);
-}
-
-static gpointer
-swfedit_matrix_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- cairo_matrix_t *matrix = g_new (cairo_matrix_t, 1);
-
- swfdec_bits_get_matrix (bits, matrix, NULL);
- swfdec_bits_syncbits (bits);
- return matrix;
-}
-
-static void
-swfedit_ctrans_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- swfdec_out_put_color_transform (out, data);
-}
-
-static gpointer
-swfedit_ctrans_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- SwfdecColorTransform *ctrans = g_new (SwfdecColorTransform, 1);
-
- swfdec_bits_get_color_transform (bits, ctrans);
- swfdec_bits_syncbits (bits);
- return ctrans;
-}
-
-static void
-swfedit_script_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- SwfdecScript *script = data;
-
- swfdec_out_put_buffer (out, script->buffer);
-}
-
-static gpointer
-swfedit_script_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- while (token->parent)
- token = token->parent;
- if (!SWFEDIT_IS_FILE (token))
- return NULL;
- return swfdec_script_new_from_bits (bits, "original script", swfedit_file_get_version (SWFEDIT_FILE (token)));
-}
-
-static void
-swfedit_clipeventflags_write (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint)
-{
- while (token->parent)
- token = token->parent;
- g_assert (SWFEDIT_IS_FILE (token));
- if (swfedit_file_get_version (SWFEDIT_FILE (token)) >= 6)
- swfdec_out_put_u32 (out, GPOINTER_TO_UINT (data));
- else
- swfdec_out_put_u16 (out, GPOINTER_TO_UINT (data));
-}
-
-static gpointer
-swfedit_clipeventflags_read (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint)
-{
- while (token->parent)
- token = token->parent;
- g_assert (SWFEDIT_IS_FILE (token));
- if (swfedit_file_get_version (SWFEDIT_FILE (token)) >= 6)
- return GUINT_TO_POINTER (swfdec_bits_get_u32 (bits));
- else
- return GUINT_TO_POINTER (swfdec_bits_get_u16 (bits));
-}
-
-struct {
- void (* write) (SwfeditToken *token, gpointer data, SwfdecOut *out, gconstpointer hint);
- gpointer (* read) (SwfeditToken *token, SwfdecBits *bits, gconstpointer hint);
-} operations[SWFEDIT_N_TOKENS] = {
- { swfedit_object_write, swfedit_object_read },
- { swfedit_binary_write, swfedit_binary_read },
- { swfedit_bit_write, swfedit_bit_read },
- { swfedit_u8_write, swfedit_u8_read },
- { swfedit_u16_write, swfedit_u16_read },
- { swfedit_u32_write, swfedit_u32_read },
- { swfedit_string_write, swfedit_string_read },
- { swfedit_rect_write, swfedit_rect_read },
- { swfedit_rgb_write, swfedit_rgb_read },
- { swfedit_rgba_write, swfedit_rgba_read },
- { swfedit_matrix_write, swfedit_matrix_read },
- { swfedit_ctrans_write, swfedit_ctrans_read },
- { swfedit_script_write, swfedit_script_read },
- { swfedit_clipeventflags_write, swfedit_clipeventflags_read },
-};
-
-void
-swfedit_tag_write_token (SwfeditToken *token, SwfdecOut *out, guint i)
-{
- SwfeditTokenEntry *entry;
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (i < token->tokens->len);
-
- entry = &g_array_index (token->tokens,
- SwfeditTokenEntry, i);
- g_assert (operations[entry->type].write != NULL);
- operations[entry->type].write (token, entry->value, out, NULL);
-}
-
-SwfdecBuffer *
-swfedit_tag_write (SwfeditToken *token)
-{
- guint i;
- SwfdecOut *out;
-
- g_return_val_if_fail (SWFEDIT_IS_TOKEN (token), NULL);
-
- out = swfdec_out_open ();
- for (i = 0; i < token->tokens->len; i++) {
- SwfeditTokenEntry *entry = &g_array_index (token->tokens,
- SwfeditTokenEntry, i);
- if (entry->visible)
- swfedit_tag_write_token (token, out, i);
- }
- return swfdec_out_close (out);
-}
-
-void
-swfedit_tag_read_token (SwfeditToken *token, SwfdecBits *bits,
- const char *name, SwfeditTokenType type, gconstpointer hint)
-{
- gpointer data;
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (name != NULL);
-
- g_assert (operations[type].read != NULL);
- data = operations[type].read (token, bits, hint);
- swfedit_token_add (token, name, type, data);
-}
-
-/*** TAGS ***/
-
-static const SwfeditTagDefinition ShowFrame[] = { { NULL, 0, 0, NULL } };
-static const SwfeditTagDefinition SetBackgroundColor[] = { { "color", SWFEDIT_TOKEN_RGB, 0, NULL }, { NULL, 0, 0, NULL } };
-static const SwfeditTagDefinition PlaceObject2Action[] = {
- { "flags", SWFEDIT_TOKEN_CLIPEVENTFLAGS, 0, NULL },
- { "size", SWFEDIT_TOKEN_UINT32, 0, NULL },
- //{ "key code", SWFEDIT_TOKEN_UINT8, 0, NULL }, /* only if flag foo is set */
- { "script", SWFEDIT_TOKEN_SCRIPT, 2, NULL },
- { NULL, 0, 0, NULL }
-};
-static const SwfeditTagDefinition PlaceObject2[] = {
- { "has clip actions", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has clip depth", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has name", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has ratio", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has color transform", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has matrix", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "has character", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "move", SWFEDIT_TOKEN_BIT, 0, NULL },
- { "depth", SWFEDIT_TOKEN_UINT16, 0, NULL },
- { "character", SWFEDIT_TOKEN_UINT16, 7, NULL },
- { "matrix", SWFEDIT_TOKEN_MATRIX, 6, NULL },
- { "color transform", SWFEDIT_TOKEN_CTRANS, 5, NULL },
- { "ratio", SWFEDIT_TOKEN_UINT16, 4, NULL },
- { "name", SWFEDIT_TOKEN_STRING, 3, NULL },
- { "clip depth", SWFEDIT_TOKEN_UINT16, 2, NULL },
- { "reserved", SWFEDIT_TOKEN_UINT16, 1, NULL },
- { "all flags", SWFEDIT_TOKEN_CLIPEVENTFLAGS, 1, NULL },
- { "actions", SWFEDIT_TOKEN_OBJECT, 1, PlaceObject2Action },
- { NULL, 0, 0, NULL }
-};
-static const SwfeditTagDefinition DoAction[] = {
- { "action", SWFEDIT_TOKEN_SCRIPT, 0, NULL },
- { NULL, 0, 0, NULL }
-};
-static const SwfeditTagDefinition DoInitAction[] = {
- { "character", SWFEDIT_TOKEN_UINT16, 0, NULL },
- { "action", SWFEDIT_TOKEN_SCRIPT, 0, NULL },
- { NULL, 0, 0, NULL }
-};
-
-static const SwfeditTagDefinition *tags[] = {
- [SWFDEC_TAG_SHOWFRAME] = ShowFrame,
- [SWFDEC_TAG_SETBACKGROUNDCOLOR] = SetBackgroundColor,
- [SWFDEC_TAG_PLACEOBJECT2] = PlaceObject2,
- [SWFDEC_TAG_DOACTION] = DoAction,
- [SWFDEC_TAG_DOINITACTION] = DoInitAction,
-};
-
-static const SwfeditTagDefinition *
-swfedit_tag_get_definition (guint tag)
-{
- if (tag >= G_N_ELEMENTS (tags))
- return NULL;
- return tags[tag];
-}
-
-/*** SWFEDIT_TAG ***/
-
-G_DEFINE_TYPE (SwfeditTag, swfedit_tag, SWFEDIT_TYPE_TOKEN)
-
-static void
-swfedit_tag_dispose (GObject *object)
-{
- //SwfeditTag *tag = SWFEDIT_TAG (object);
-
- G_OBJECT_CLASS (swfedit_tag_parent_class)->dispose (object);
-}
-
-static void
-swfedit_tag_changed (SwfeditToken *token, guint i)
-{
- guint j;
- SwfeditTag *tag = SWFEDIT_TAG (token);
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- const SwfeditTagDefinition *def = swfedit_tag_get_definition (tag->tag);
-
- if (def == NULL)
- return;
-
- for (j = i + 1; def[j].name; j++) {
- if (def[j].n_items == i + 1) {
- swfedit_token_set_visible (token, j, entry->value != NULL);
- }
- }
- if (def[i].n_items != 0) {
- entry = &g_array_index (token->tokens,
- SwfeditTokenEntry, def[i].n_items - 1);
- if (entry->type == SWFEDIT_TOKEN_UINT32) {
- SwfdecOut *out = swfdec_out_open ();
- SwfdecBuffer *buffer;
- swfedit_tag_write_token (token, out, def[i].n_items - 1);
- buffer = swfdec_out_close (out);
- if (entry->value != GUINT_TO_POINTER (buffer->length)) {
- swfedit_token_set (token, def[i].n_items - 1,
- GUINT_TO_POINTER (buffer->length));
- }
- swfdec_buffer_unref (buffer);
- }
- }
-}
-
-static void
-swfedit_tag_class_init (SwfeditTagClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- SwfeditTokenClass *token_class = SWFEDIT_TOKEN_CLASS (klass);
-
- object_class->dispose = swfedit_tag_dispose;
-
- token_class->changed = swfedit_tag_changed;
-}
-
-static void
-swfedit_tag_init (SwfeditTag *tag)
-{
-}
-
-void
-swfedit_tag_add_token (SwfeditToken *token, const char *name, SwfeditTokenType type,
- gconstpointer hint)
-{
- gpointer data;
-
- if (type == SWFEDIT_TOKEN_OBJECT) {
- data = swfedit_list_new (hint);
- SWFEDIT_TOKEN (data)->parent = token;
- } else {
- data = swfedit_token_new_token (type);
- }
- swfedit_token_add (token, name, type, data);
-}
-
-void
-swfedit_tag_read_tag (SwfeditToken *token, SwfdecBits *bits,
- const SwfeditTagDefinition *def)
-{
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (bits != NULL);
- g_return_if_fail (def != NULL);
-
- if (def->n_items != 0) {
- SwfeditTokenEntry *entry = &g_array_index (token->tokens,
- SwfeditTokenEntry, def->n_items - 1);
- if (GPOINTER_TO_UINT (entry->value) == 0) {
- swfedit_tag_add_token (token, def->name, def->type, def->hint);
- swfedit_token_set_visible (token, token->tokens->len - 1, FALSE);
- } else if (entry->type == SWFEDIT_TOKEN_BIT) {
- swfedit_tag_read_token (token, bits, def->name, def->type, def->hint);
- } else {
- guint length = GPOINTER_TO_UINT (entry->value);
- SwfdecBuffer *buffer = swfdec_bits_get_buffer (bits, length);
- if (buffer == NULL) {
- swfedit_tag_add_token (token, def->name, def->type, def->hint);
- } else {
- SwfdecBits bits2;
- swfdec_bits_init (&bits2, buffer);
- swfedit_tag_read_token (token, &bits2, def->name, def->type, def->hint);
- swfdec_buffer_unref (buffer);
- }
- }
- } else {
- swfedit_tag_read_token (token, bits, def->name, def->type, def->hint);
- }
-}
-
-SwfeditTag *
-swfedit_tag_new (SwfeditToken *parent, guint tag, SwfdecBuffer *buffer)
-{
- SwfeditTag *item;
- const SwfeditTagDefinition *def;
-
- g_return_val_if_fail (SWFEDIT_IS_TOKEN (parent), NULL);
-
- item = g_object_new (SWFEDIT_TYPE_TAG, NULL);
- item->tag = tag;
- SWFEDIT_TOKEN (item)->parent = parent;
- def = swfedit_tag_get_definition (tag);
- if (def) {
- SwfdecBits bits;
- swfdec_bits_init (&bits, buffer);
- for (;def->name != NULL; def++) {
- swfedit_tag_read_tag (SWFEDIT_TOKEN (item), &bits, def);
- }
- if (swfdec_bits_left (&bits)) {
- SWFDEC_WARNING ("%u bytes %u bits left unparsed",
- swfdec_bits_left (&bits) / 8, swfdec_bits_left (&bits) % 8);
- }
- } else {
- swfedit_token_add (SWFEDIT_TOKEN (item), "contents", SWFEDIT_TOKEN_BINARY, buffer);
- }
- return item;
-}
-
diff --git a/tools/swfedit_tag.h b/tools/swfedit_tag.h
deleted file mode 100644
index b148f24..0000000
--- a/tools/swfedit_tag.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __SWFEDIT_TAG_H__
-#define __SWFEDIT_TAG_H__
-
-#include <swfdec/swfdec_buffer.h>
-#include <swfdec/swfdec_bits.h>
-#include "swfdec_out.h"
-#include "swfedit_token.h"
-
-G_BEGIN_DECLS
-
-typedef struct _SwfeditTag SwfeditTag;
-typedef struct _SwfeditTagClass SwfeditTagClass;
-typedef struct _SwfeditTagDefinition SwfeditTagDefinition;
-
-struct _SwfeditTagDefinition {
- const char * name; /* name to use for this field */
- SwfeditTokenType type; /* type of this field */
- guint n_items; /* 1-indexed field to look at for item count (or 0 to use 1 item) */
- gconstpointer hint; /* hint to pass to field when creating */
-};
-
-#define SWFEDIT_TYPE_TAG (swfedit_tag_get_type())
-#define SWFEDIT_IS_TAG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFEDIT_TYPE_TAG))
-#define SWFEDIT_IS_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFEDIT_TYPE_TAG))
-#define SWFEDIT_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFEDIT_TYPE_TAG, SwfeditTag))
-#define SWFEDIT_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFEDIT_TYPE_TAG, SwfeditTagClass))
-#define SWFEDIT_TAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFEDIT_TYPE_TAG, SwfeditTagClass))
-
-struct _SwfeditTag {
- SwfeditToken token;
-
- guint tag; /* tag type */
-};
-
-struct _SwfeditTagClass {
- SwfeditTokenClass token_class;
-};
-
-GType swfedit_tag_get_type (void);
-
-SwfeditTag * swfedit_tag_new (SwfeditToken * parent,
- guint tag,
- SwfdecBuffer * buffer);
-
-SwfdecBuffer * swfedit_tag_write (SwfeditToken * token);
-void swfedit_tag_write_token (SwfeditToken * token,
- SwfdecOut * out,
- guint i);
-void swfedit_tag_add_token (SwfeditToken * token,
- const char * name,
- SwfeditTokenType type,
- gconstpointer hint);
-void swfedit_tag_read_token (SwfeditToken * token,
- SwfdecBits * bits,
- const char * name,
- SwfeditTokenType type,
- gconstpointer hint);
-void swfedit_tag_read_tag (SwfeditToken * token,
- SwfdecBits * bits,
- const SwfeditTagDefinition *def);
-
-G_END_DECLS
-
-#endif
diff --git a/tools/swfedit_token.c b/tools/swfedit_token.c
deleted file mode 100644
index 587e831..0000000
--- a/tools/swfedit_token.c
+++ /dev/null
@@ -1,795 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, to_string to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <gtk/gtk.h>
-#include <swfdec/swfdec_buffer.h>
-#include <swfdec/swfdec_color.h>
-#include <swfdec/swfdec_script_internal.h>
-#include "swfedit_token.h"
-
-/*** CONVERTERS ***/
-
-static gboolean
-swfedit_parse_hex (const char *s, guint *result)
-{
- guint byte;
-
- if (s[0] >= '0' && s[0] <= '9')
- byte = s[0] - '0';
- else if (s[0] >= 'a' && s[0] <= 'f')
- byte = s[0] + 10 - 'a';
- else if (s[0] >= 'A' && s[0] <= 'F')
- byte = s[0] + 10 - 'A';
- else
- return FALSE;
- s++;
- byte *= 16;
- if (s[0] >= '0' && s[0] <= '9')
- byte += s[0] - '0';
- else if (s[0] >= 'a' && s[0] <= 'f')
- byte += s[0] + 10 - 'a';
- else if (s[0] >= 'A' && s[0] <= 'F')
- byte += s[0] + 10 - 'A';
- else
- return FALSE;
- *result = byte;
- return TRUE;
-}
-
-static gpointer
-swfedit_binary_new (void)
-{
- return swfdec_buffer_new (0);
-}
-
-static gboolean
-swfedit_binary_from_string (const char *s, gpointer* result)
-{
- GByteArray *array = g_byte_array_new ();
- guint byte;
- guint8 add;
-
- while (g_ascii_isspace (*s)) s++;
- do {
- if (!swfedit_parse_hex (s, &byte))
- break;
- s += 2;
- add = byte;
- g_byte_array_append (array, &add, 1);
- while (g_ascii_isspace (*s)) s++;
- } while (*s != '\0');
- if (*s == '\0') {
- SwfdecBuffer *buffer = swfdec_buffer_new_for_data (array->data, array->len);
- g_byte_array_free (array, FALSE);
- *result = buffer;
- return TRUE;
- }
- g_byte_array_free (array, TRUE);
- return FALSE;
-}
-
-static char *
-swfedit_binary_to_string (gconstpointer value)
-{
- guint i;
- const SwfdecBuffer *buffer = value;
- GString *string = g_string_new ("");
-
- for (i = 0; i < buffer->length; i++) {
- if (i && i % 4 == 0)
- g_string_append_c (string, ' ');
- g_string_append_printf (string, "%02X", buffer->data[i]);
- }
- return g_string_free (string, FALSE);
-}
-
-static gboolean
-swfedit_bit_from_string (const char *s, gpointer* result)
-{
- if (s[0] == '1' && s[1] == '\0')
- *result = GUINT_TO_POINTER (1);
- else if (s[0] == '0' && s[1] == '\0')
- *result = GUINT_TO_POINTER (0);
- else
- return FALSE;
- return TRUE;
-}
-
-static char *
-swfedit_bit_to_string (gconstpointer value)
-{
- return g_strdup (value ? "1" : "0");
-}
-
-static gboolean
-swfedit_from_string_unsigned (const char *s, gulong max, gpointer* result)
-{
- char *end;
- gulong u;
-
- g_assert (max <= G_MAXUINT);
- u = strtoul (s, &end, 10);
- if (*end != '\0')
- return FALSE;
- if (u > max)
- return FALSE;
- *result = GUINT_TO_POINTER (u);
- return TRUE;
-}
-
-static gboolean
-swfedit_uint8_from_string (const char *s, gpointer* result)
-{
- return swfedit_from_string_unsigned (s, G_MAXUINT8, result);
-}
-
-static gboolean
-swfedit_uint16_from_string (const char *s, gpointer* result)
-{
- return swfedit_from_string_unsigned (s, G_MAXUINT16, result);
-}
-
-static gboolean
-swfedit_uint32_from_string (const char *s, gpointer* result)
-{
- return swfedit_from_string_unsigned (s, G_MAXUINT32, result);
-}
-
-static char *
-swfedit_to_string_unsigned (gconstpointer value)
-{
- return g_strdup_printf ("%u", GPOINTER_TO_UINT (value));
-}
-
-static char *
-swfedit_string_to_string (gconstpointer value)
-{
- return g_strdup (value);
-}
-
-static gboolean
-swfedit_string_from_string (const char *s, gpointer* result)
-{
- *result = g_strdup (s);
- return TRUE;
-}
-
-static gpointer
-swfedit_rect_new (void)
-{
- return g_new0 (SwfdecRect, 1);
-}
-
-static gboolean
-swfedit_rect_from_string (const char *s, gpointer* result)
-{
- return FALSE;
-}
-
-static char *
-swfedit_rect_to_string (gconstpointer value)
-{
- const SwfdecRect *rect = value;
-
- return g_strdup_printf ("%d, %d, %d, %d", (int) rect->x0, (int) rect->y0,
- (int) rect->x1, (int) rect->y1);
-}
-
-static gboolean
-swfedit_rgb_from_string (const char *s, gpointer* result)
-{
- guint r, g, b;
- if (strlen (s) != 6)
- return FALSE;
- if (!swfedit_parse_hex (s, &r))
- return FALSE;
- s += 2;
- if (!swfedit_parse_hex (s, &g))
- return FALSE;
- s += 2;
- if (!swfedit_parse_hex (s, &b))
- return FALSE;
- *result = GUINT_TO_POINTER (SWFDEC_COLOR_COMBINE (r, g, b, 0xFF));
- return TRUE;
-}
-
-static char *
-swfedit_rgb_to_string (gconstpointer value)
-{
- guint c = GPOINTER_TO_UINT (value);
-
- return g_strdup_printf ("%02X%02X%02X", SWFDEC_COLOR_R (c),
- SWFDEC_COLOR_G (c), SWFDEC_COLOR_B (c));
-}
-
-static gboolean
-swfedit_rgba_from_string (const char *s, gpointer* result)
-{
- guint r, g, b, a;
- if (strlen (s) != 8)
- return FALSE;
- if (!swfedit_parse_hex (s, &a))
- return FALSE;
- s += 2;
- if (!swfedit_parse_hex (s, &r))
- return FALSE;
- s += 2;
- if (!swfedit_parse_hex (s, &g))
- return FALSE;
- s += 2;
- if (!swfedit_parse_hex (s, &b))
- return FALSE;
- *result = GUINT_TO_POINTER (SWFDEC_COLOR_COMBINE (r, g, b, a));
- return TRUE;
-}
-
-static char *
-swfedit_rgba_to_string (gconstpointer value)
-{
- guint c = GPOINTER_TO_UINT (value);
-
- return g_strdup_printf ("%02X%02X%02X%02X", SWFDEC_COLOR_R (c),
- SWFDEC_COLOR_G (c), SWFDEC_COLOR_B (c), SWFDEC_COLOR_A (c));
-}
-
-static gpointer
-swfedit_matrix_new (void)
-{
- cairo_matrix_t *matrix = g_new (cairo_matrix_t, 1);
-
- cairo_matrix_init_identity (matrix);
- return matrix;
-}
-
-static gboolean
-swfedit_matrix_from_string (const char *s, gpointer* result)
-{
- return FALSE;
-}
-
-static char *
-swfedit_matrix_to_string (gconstpointer value)
-{
- const cairo_matrix_t *mat = value;
-
- return g_strdup_printf ("{%g %g, %g %g} + {%g, %g}",
- mat->xx, mat->xy, mat->yx, mat->yy, mat->x0, mat->y0);
-}
-
-static gpointer
-swfedit_ctrans_new (void)
-{
- SwfdecColorTransform *trans = g_new (SwfdecColorTransform, 1);
-
- swfdec_color_transform_init_identity (trans);
- return trans;
-}
-
-static gboolean
-swfedit_ctrans_from_string (const char *s, gpointer* result)
-{
- return FALSE;
-}
-
-static char *
-swfedit_ctrans_to_string (gconstpointer value)
-{
- const SwfdecColorTransform *trans = value;
-
- return g_strdup_printf ("{%d %d} {%d %d} {%d %d} {%d %d}",
- trans->ra, trans->rb, trans->ga, trans->gb,
- trans->ba, trans->bb, trans->aa, trans->ab);
-}
-
-static gpointer
-swfedit_script_new (void)
-{
- return NULL;
-}
-
-static gboolean
-swfedit_script_from_string (const char *s, gpointer* result)
-{
- gpointer buffer;
- SwfdecScript *script;
-
- if (!swfedit_binary_from_string (s, &buffer)) {
- return FALSE;
- }
-
- script = swfdec_script_new (buffer, "unknown", 6 /* FIXME */);
- if (script != NULL) {
- *result = script;
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-static char *
-swfedit_script_to_string (gconstpointer value)
-{
- if (value == NULL)
- return g_strdup ("");
- else
- return swfedit_binary_to_string (((SwfdecScript *) value)->buffer);
-}
-
-static void
-swfedit_script_free (gpointer script)
-{
- if (script)
- swfdec_script_unref (script);
-}
-
-struct {
- gpointer (* new) (void);
- gboolean (* from_string) (const char *s, gpointer *);
- char * (* to_string) (gconstpointer value);
- void (* free) (gpointer value);
-} converters[SWFEDIT_N_TOKENS] = {
- { NULL, NULL, NULL, g_object_unref },
- { swfedit_binary_new, swfedit_binary_from_string, swfedit_binary_to_string, (GDestroyNotify) swfdec_buffer_unref },
- { NULL, swfedit_bit_from_string, swfedit_bit_to_string, NULL },
- { NULL, swfedit_uint8_from_string, swfedit_to_string_unsigned, NULL },
- { NULL, swfedit_uint16_from_string, swfedit_to_string_unsigned, NULL },
- { NULL, swfedit_uint32_from_string, swfedit_to_string_unsigned, NULL },
- { NULL, swfedit_string_from_string, swfedit_string_to_string, g_free },
- { swfedit_rect_new, swfedit_rect_from_string, swfedit_rect_to_string, g_free },
- { NULL, swfedit_rgb_from_string, swfedit_rgb_to_string, NULL },
- { NULL, swfedit_rgba_from_string, swfedit_rgba_to_string, NULL },
- { swfedit_matrix_new, swfedit_matrix_from_string, swfedit_matrix_to_string, g_free },
- { swfedit_ctrans_new, swfedit_ctrans_from_string, swfedit_ctrans_to_string, g_free },
- { swfedit_script_new, swfedit_script_from_string, swfedit_script_to_string, swfedit_script_free },
- { NULL, swfedit_uint32_from_string, swfedit_to_string_unsigned, NULL },
-};
-
-gpointer
-swfedit_token_new_token (SwfeditTokenType type)
-{
- gpointer ret;
-
- g_assert (type < G_N_ELEMENTS (converters));
-
- if (!converters[type].new)
- return NULL;
- ret = converters[type].new ();
- return ret;
-}
-
-/*** GTK_TREE_MODEL ***/
-
-#if 0
-# define REPORT g_print ("%s\n", G_STRFUNC)
-#else
-# define REPORT
-#endif
-static GtkTreeModelFlags
-swfedit_token_get_flags (GtkTreeModel *tree_model)
-{
- REPORT;
- return 0;
-}
-
-static gint
-swfedit_token_get_n_columns (GtkTreeModel *tree_model)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (tree_model);
-
- REPORT;
- return token->tokens->len;
-}
-
-static GType
-swfedit_token_get_column_type (GtkTreeModel *tree_model, gint index_)
-{
- REPORT;
- switch (index_) {
- case SWFEDIT_COLUMN_NAME:
- return G_TYPE_STRING;
- case SWFEDIT_COLUMN_VALUE_VISIBLE:
- return G_TYPE_BOOLEAN;
- case SWFEDIT_COLUMN_VALUE_EDITABLE:
- return G_TYPE_BOOLEAN;
- case SWFEDIT_COLUMN_VALUE:
- return G_TYPE_STRING;
- default:
- break;
- }
- g_assert_not_reached ();
- return G_TYPE_NONE;
-}
-
-static gboolean
-swfedit_token_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (tree_model);
- guint i = gtk_tree_path_get_indices (path)[0];
- SwfeditTokenEntry *entry;
-
- REPORT;
- if (i > token->tokens->len)
- return FALSE;
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- if (gtk_tree_path_get_depth (path) > 1) {
- GtkTreePath *new;
- int j;
- int *indices;
- gboolean ret;
-
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- return FALSE;
- new = gtk_tree_path_new ();
- indices = gtk_tree_path_get_indices (path);
- for (j = 1; j < gtk_tree_path_get_depth (path); j++) {
- gtk_tree_path_append_index (new, indices[j]);
- }
- ret = swfedit_token_get_iter (GTK_TREE_MODEL (entry->value), iter, new);
- gtk_tree_path_free (new);
- return ret;
- } else {
- iter->stamp = 0; /* FIXME */
- iter->user_data = token;
- iter->user_data2 = GINT_TO_POINTER (i);
- return TRUE;
- }
-}
-
-static GtkTreePath *
-swfedit_token_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (iter->user_data);
- GtkTreePath *path = gtk_tree_path_new_from_indices (GPOINTER_TO_INT (iter->user_data2), -1);
-
- REPORT;
- while (token->parent) {
- guint i;
- SwfeditToken *parent = token->parent;
- for (i = 0; i < parent->tokens->len; i++) {
- SwfeditTokenEntry *entry = &g_array_index (parent->tokens, SwfeditTokenEntry, i);
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- continue;
- if (entry->value == token)
- break;
- }
- gtk_tree_path_prepend_index (path, i);
- token = parent;
- }
- return path;
-}
-
-static void
-swfedit_token_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter,
- gint column, GValue *value)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (iter->user_data);
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (iter->user_data2));
-
- REPORT;
- switch (column) {
- case SWFEDIT_COLUMN_NAME:
- g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, entry->name);
- return;
- case SWFEDIT_COLUMN_VALUE_VISIBLE:
- g_value_init (value, G_TYPE_BOOLEAN);
- g_value_set_boolean (value, converters[entry->type].to_string != NULL);
- return;
- case SWFEDIT_COLUMN_VALUE_EDITABLE:
- g_value_init (value, G_TYPE_BOOLEAN);
- g_value_set_boolean (value, entry->visible);
- return;
- case SWFEDIT_COLUMN_VALUE:
- g_value_init (value, G_TYPE_STRING);
- if (converters[entry->type].to_string)
- g_value_take_string (value, converters[entry->type].to_string (entry->value));
- return;
- default:
- break;
- }
- g_assert_not_reached ();
-}
-
-static gboolean
-swfedit_token_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (iter->user_data);
- int i;
-
- REPORT;
- i = GPOINTER_TO_INT (iter->user_data2) + 1;
- if ((guint) i >= token->tokens->len)
- return FALSE;
-
- iter->user_data2 = GINT_TO_POINTER (i);
- return TRUE;
-}
-
-static gboolean
-swfedit_token_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent)
-{
- SwfeditToken *token;
- SwfeditTokenEntry *entry;
-
- REPORT;
- if (parent) {
- token = SWFEDIT_TOKEN (parent->user_data);
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (parent->user_data2));
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- return FALSE;
- token = entry->value;
- } else {
- token = SWFEDIT_TOKEN (tree_model);
- }
- if (token->tokens->len == 0)
- return FALSE;
- iter->stamp = 0; /* FIXME */
- iter->user_data = token;
- iter->user_data2 = GINT_TO_POINTER (0);
- return TRUE;
-}
-
-static gboolean
-swfedit_token_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (iter->user_data);
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (iter->user_data2));
-
- REPORT;
- return entry->type == SWFEDIT_TOKEN_OBJECT && SWFEDIT_TOKEN (entry->value)->tokens->len > 0;
-}
-
-static gint
-swfedit_token_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (iter->user_data);
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (iter->user_data2));
-
- REPORT;
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- return 0;
-
- token = entry->value;
- return token->tokens->len;
-}
-
-static gboolean
-swfedit_token_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter,
- GtkTreeIter *parent, gint n)
-{
- SwfeditToken *token;
- SwfeditTokenEntry *entry;
-
- REPORT;
- if (parent) {
- token = SWFEDIT_TOKEN (parent->user_data);
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (parent->user_data2));
-
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- return FALSE;
-
- token = entry->value;
- } else {
- token = SWFEDIT_TOKEN (tree_model);
- }
- if ((guint) n >= token->tokens->len)
- return FALSE;
- iter->stamp = 0; /* FIXME */
- iter->user_data = token;
- iter->user_data2 = GINT_TO_POINTER (n);
- return TRUE;
-}
-
-static gboolean
-swfedit_token_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child)
-{
- guint i;
- SwfeditToken *token = SWFEDIT_TOKEN (child->user_data);
- SwfeditToken *parent = token->parent;
-
- REPORT;
- if (parent == NULL)
- return FALSE;
-
- for (i = 0; i < parent->tokens->len; i++) {
- SwfeditTokenEntry *entry = &g_array_index (parent->tokens, SwfeditTokenEntry, i);
- if (entry->type != SWFEDIT_TOKEN_OBJECT)
- continue;
- if (entry->value == token)
- break;
- }
- iter->stamp = 0; /* FIXME */
- iter->user_data = parent;
- iter->user_data2 = GINT_TO_POINTER (i);
- return TRUE;
-}
-
-static void
-swfedit_token_tree_model_init (GtkTreeModelIface *iface)
-{
- iface->get_flags = swfedit_token_get_flags;
- iface->get_n_columns = swfedit_token_get_n_columns;
- iface->get_column_type = swfedit_token_get_column_type;
- iface->get_iter = swfedit_token_get_iter;
- iface->get_path = swfedit_token_get_path;
- iface->get_value = swfedit_token_get_value;
- iface->iter_next = swfedit_token_iter_next;
- iface->iter_children = swfedit_token_iter_children;
- iface->iter_has_child = swfedit_token_iter_has_child;
- iface->iter_n_children = swfedit_token_iter_n_children;
- iface->iter_nth_child = swfedit_token_iter_nth_child;
- iface->iter_parent = swfedit_token_iter_parent;
-}
-
-/*** SWFEDIT_TOKEN ***/
-
-G_DEFINE_TYPE_WITH_CODE (SwfeditToken, swfedit_token, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, swfedit_token_tree_model_init))
-
-static void
-swfedit_token_dispose (GObject *object)
-{
- SwfeditToken *token = SWFEDIT_TOKEN (object);
- guint i;
-
- for (i = 0; i < token->tokens->len; i++) {
- SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- g_free (entry->name);
- if (converters[entry->type].free)
- converters[entry->type].free (entry->value);
- }
- g_array_free (token->tokens, TRUE);
-
- G_OBJECT_CLASS (swfedit_token_parent_class)->dispose (object);
-}
-
-static void
-swfedit_token_class_init (SwfeditTokenClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->dispose = swfedit_token_dispose;
-}
-
-static void
-swfedit_token_init (SwfeditToken *token)
-{
- token->tokens = g_array_new (FALSE, FALSE, sizeof (SwfeditTokenEntry));
-}
-
-SwfeditToken *
-swfedit_token_new (void)
-{
- SwfeditToken *token;
-
- token = g_object_new (SWFEDIT_TYPE_TOKEN, NULL);
- return token;
-}
-
-void
-swfedit_token_add (SwfeditToken *token, const char *name, SwfeditTokenType type,
- gpointer value)
-{
- SwfeditTokenEntry entry = { NULL, type, value, TRUE };
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (name != NULL);
- g_return_if_fail (type < SWFEDIT_N_TOKENS);
-
- g_assert (type != SWFEDIT_TOKEN_OBJECT || value != NULL);
- entry.name = g_strdup (name);
- g_array_append_val (token->tokens, entry);
-}
-
-void
-swfedit_token_set (SwfeditToken *token, guint i, gpointer value)
-{
- SwfeditTokenClass *klass;
- SwfeditTokenEntry *entry;
- GtkTreePath *path;
- SwfeditToken *model;
- GtkTreeIter iter;
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (i < token->tokens->len);
-
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- if (converters[entry->type].free != NULL)
- converters[entry->type].free (entry->value);
- entry->value = value;
- klass = SWFEDIT_TOKEN_GET_CLASS (token);
- if (klass->changed)
- klass->changed (token, i);
-
- model = token;
- while (model->parent)
- model = model->parent;
- iter.user_data = token;
- iter.user_data2 = GUINT_TO_POINTER (i);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
-}
-
-void
-swfedit_token_set_iter (SwfeditToken *token, GtkTreeIter *iter, const char *value)
-{
- SwfeditTokenClass *klass;
- GtkTreeModel *model;
- SwfeditTokenEntry *entry;
- guint i;
- gpointer new;
- GtkTreePath *path;
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (iter != NULL);
- g_return_if_fail (value != NULL);
-
- model = GTK_TREE_MODEL (token);
- token = iter->user_data;
- i = GPOINTER_TO_UINT (iter->user_data2);
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- if (converters[entry->type].from_string == NULL)
- return;
- if (!converters[entry->type].from_string (value, &new))
- return;
- if (converters[entry->type].free != NULL)
- converters[entry->type].free (entry->value);
- entry->value = new;
- klass = SWFEDIT_TOKEN_GET_CLASS (token);
- if (klass->changed)
- klass->changed (token, i);
-
- path = gtk_tree_model_get_path (model, iter);
- gtk_tree_model_row_changed (model, path, iter);
- gtk_tree_path_free (path);
-}
-
-void
-swfedit_token_set_visible (SwfeditToken *token, guint i, gboolean visible)
-{
- SwfeditTokenEntry *entry;
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
-
- g_return_if_fail (SWFEDIT_IS_TOKEN (token));
- g_return_if_fail (i < token->tokens->len);
-
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- if (entry->visible == visible)
- return;
-
- entry->visible = visible;
- iter.stamp = 0; /* FIXME */
- iter.user_data = token;
- iter.user_data2 = GINT_TO_POINTER (i);
- while (token->parent)
- token = token->parent;
- model = GTK_TREE_MODEL (token);
- path = gtk_tree_model_get_path (model, &iter);
- gtk_tree_model_row_changed (model, path, &iter);
- gtk_tree_path_free (path);
-}
diff --git a/tools/swfedit_token.h b/tools/swfedit_token.h
deleted file mode 100644
index c46e0ef..0000000
--- a/tools/swfedit_token.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef __SWFEDIT_TOKEN_H__
-#define __SWFEDIT_TOKEN_H__
-
-#include <gtk/gtk.h>
-#include <swfdec/swfdec_rect.h>
-
-G_BEGIN_DECLS
-
-typedef enum {
- SWFEDIT_TOKEN_OBJECT,
- SWFEDIT_TOKEN_BINARY,
- SWFEDIT_TOKEN_BIT,
- SWFEDIT_TOKEN_UINT8,
- SWFEDIT_TOKEN_UINT16,
- SWFEDIT_TOKEN_UINT32,
- SWFEDIT_TOKEN_STRING,
- SWFEDIT_TOKEN_RECT,
- SWFEDIT_TOKEN_RGB,
- SWFEDIT_TOKEN_RGBA,
- SWFEDIT_TOKEN_MATRIX,
- SWFEDIT_TOKEN_CTRANS,
- SWFEDIT_TOKEN_SCRIPT,
- SWFEDIT_TOKEN_CLIPEVENTFLAGS,
- SWFEDIT_N_TOKENS
-} SwfeditTokenType;
-
-typedef enum {
- SWFEDIT_COLUMN_NAME,
- SWFEDIT_COLUMN_VALUE_VISIBLE,
- SWFEDIT_COLUMN_VALUE,
- SWFEDIT_COLUMN_VALUE_EDITABLE
-} SwfeditColumn;
-
-typedef struct _SwfeditTokenEntry SwfeditTokenEntry;
-
-typedef struct _SwfeditToken SwfeditToken;
-typedef struct _SwfeditTokenClass SwfeditTokenClass;
-
-#define SWFEDIT_TYPE_TOKEN (swfedit_token_get_type())
-#define SWFEDIT_IS_TOKEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFEDIT_TYPE_TOKEN))
-#define SWFEDIT_IS_TOKEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFEDIT_TYPE_TOKEN))
-#define SWFEDIT_TOKEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFEDIT_TYPE_TOKEN, SwfeditToken))
-#define SWFEDIT_TOKEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFEDIT_TYPE_TOKEN, SwfeditTokenClass))
-#define SWFEDIT_TOKEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFEDIT_TYPE_TOKEN, SwfeditTokenClass))
-
-struct _SwfeditTokenEntry {
- char * name;
- SwfeditTokenType type;
- gpointer value;
- gboolean visible;
-};
-
-struct _SwfeditToken {
- GObject object;
-
- SwfeditToken * parent; /* parent of this token or NULL */
- gchar * name; /* name of token */
- GArray * tokens; /* of SwfeditTokenEntry */
-};
-
-struct _SwfeditTokenClass {
- GObjectClass object_class;
-
- void (* changed) (SwfeditToken * token,
- guint id);
-};
-
-GType swfedit_token_get_type (void);
-
-gpointer swfedit_token_new_token (SwfeditTokenType type);
-
-SwfeditToken * swfedit_token_new (void);
-void swfedit_token_add (SwfeditToken * token,
- const char * name,
- SwfeditTokenType type,
- gpointer value);
-void swfedit_token_set (SwfeditToken * token,
- guint i,
- gpointer value);
-void swfedit_token_set_iter (SwfeditToken * token,
- GtkTreeIter * iter,
- const char * value);
-void swfedit_token_set_visible (SwfeditToken * token,
- guint i,
- gboolean visible);
-
-
-G_END_DECLS
-
-#endif
diff --git a/tools/swfscript.c b/tools/swfscript.c
deleted file mode 100644
index 71435f4..0000000
--- a/tools/swfscript.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/* Swfedit
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <gtk/gtk.h>
-#include "swfdec/swfdec_script_internal.h"
-#include "swfdec_out.h"
-#include "swfedit_file.h"
-
-/* the stuff we look for */
-guint *add_trace = NULL;
-
-typedef gboolean ( *SwfeditTokenForeachFunc) (SwfeditToken *token, guint idx,
- const char *name, SwfeditTokenType type, gconstpointer value, gpointer data);
-
-static gboolean
-swfedit_token_foreach (SwfeditToken *token, SwfeditTokenForeachFunc func,
- gpointer data)
-{
- SwfeditTokenEntry *entry;
- guint i;
-
- g_return_val_if_fail (SWFEDIT_IS_TOKEN (token), FALSE);
- g_return_val_if_fail (func != NULL, FALSE);
-
- for (i = 0; i < token->tokens->len; i++) {
- entry = &g_array_index (token->tokens, SwfeditTokenEntry, i);
- if (!func (token, i, entry->name, entry->type, entry->value, data))
- return FALSE;
- if (entry->type == SWFEDIT_TOKEN_OBJECT) {
- if (!swfedit_token_foreach (entry->value, func, data))
- return FALSE;
- }
- }
- return TRUE;
-}
-
-typedef struct {
- guint offset; /* offset in bytes from start of script */
- guint new_offset; /* new offset in bytes from start of script */
- guint new_actions; /* number of actions in new script */
-} Action;
-
-typedef struct {
- SwfdecScript * script; /* the original script */
- SwfdecOut * out; /* output for new script or NULL when buffer is set */
- SwfdecBuffer * buffer; /* buffer containing new script or NULL while constructing */
- GArray * actions; /* all actions in the script */
-} State;
-
-static gboolean
-action_in_array (guint *array, guint action)
-{
- if (array == NULL)
- return FALSE;
- while (*array != 0) {
- if (*array == action)
- return TRUE;
- array++;
- }
- return FALSE;
-}
-
-static guint
-lookup_offset (GArray *array, guint offset)
-{
- guint i;
- for (i = 0; i < array->len; i++) {
- Action *action = &g_array_index (array, Action, i);
- if (action->offset == offset)
- return action->new_offset;
- }
- g_assert_not_reached ();
- return 0;
-}
-
-static gboolean
-fixup_jumps_foreach (gconstpointer bytecode, guint action,
- const guint8 *data, guint len, gpointer user_data)
-{
- State *state = user_data;
-
- if (action == 0x99 || action == 0x9d) {
- guint offset = (guint8 *) bytecode - state->script->buffer->data;
- guint jump_offset = offset + 5 + GINT16_FROM_LE (*((gint16 *) data));
- offset = lookup_offset (state->actions, offset);
- jump_offset = lookup_offset (state->actions, jump_offset);
- *((gint16 *) &state->buffer->data[offset + 3]) =
- GINT16_TO_LE (jump_offset - offset - 5);
- }
- if (action == 0x8a || action == 0x8d) {
- Action *cur = NULL; /* silence gcc */
- guint id = action == 0x8a ? 2 : 0;
- guint i, count;
- guint offset = (guint8 *) bytecode - state->script->buffer->data;
- for (i = 0; i < state->actions->len; i++) {
- cur = &g_array_index (state->actions, Action, i);
- if (cur->offset == offset) {
- offset = cur->new_offset;
- break;
- }
- }
- g_assert (i < state->actions->len);
- i = data[id];
- count = cur->new_actions - 1; /* FIXME: only works as long as we append actions */
- while (i > 0) {
- cur++;
- count += cur->new_actions;
- i--;
- }
- g_assert (count < 256);
- state->buffer->data[offset + 3 + id] = count;
- }
- return TRUE;
-}
-
-static gboolean
-modify_script_foreach (gconstpointer bytecode, guint action,
- const guint8 *data, guint len, gpointer user_data)
-{
- Action next;
- State *state = user_data;
-
- next.offset = (guint8 *) bytecode - state->script->buffer->data;
- next.new_offset = swfdec_out_get_bits (state->out) / 8;
- next.new_actions = 1;
- swfdec_out_put_u8 (state->out, action);
- if (action & 0x80) {
- swfdec_out_put_u16 (state->out, len);
- swfdec_out_put_data (state->out, data, len);
- }
- if (action_in_array (add_trace, action)) {
- swfdec_out_put_u8 (state->out, 0x4c); /* PushDuplicate */
- swfdec_out_put_u8 (state->out, 0x26); /* Trace */
- next.new_actions += 2;
- }
- g_array_append_val (state->actions, next);
- return TRUE;
-}
-
-static gboolean
-modify_file (SwfeditToken *token, guint idx, const char *name,
- SwfeditTokenType type, gconstpointer value, gpointer data)
-{
- Action end;
- SwfdecScript *script;
- State state;
-
- if (type != SWFEDIT_TOKEN_SCRIPT)
- return TRUE;
-
- state.script = (SwfdecScript *) value;
- state.out = swfdec_out_open ();
- state.buffer = NULL;
- state.actions = g_array_new (FALSE, FALSE, sizeof (Action));
- swfdec_script_foreach (state.script, modify_script_foreach, &state);
- /* compute end offset */
- end.offset = g_array_index (state.actions, Action, state.actions->len - 1).offset;
- if (state.script->buffer->data[end.offset] & 0x80) {
- end.offset += GUINT16_FROM_LE (*((guint16* ) &state.script->buffer->data[end.offset + 1])) + 3;
- } else {
- end.offset++;
- }
- end.new_offset = swfdec_out_get_bits (state.out) / 8;
- end.new_actions = 0;
- g_array_append_val (state.actions, end);
-#if 0
- {
- guint i;
- for (i = 0; i < state.actions->len; i++) {
- Action *action = &g_array_index (state.actions, Action, i);
- g_print ("%u %u => %u (%u actions)\n", i, action->offset,
- action->new_offset, action->new_actions);
- }
- }
-#endif
- /* maybe append 0 byte */
- if (end.offset + 1 == state.script->buffer->length) {
- swfdec_out_put_u8 (state.out, 0);
- } else {
- g_assert (end.offset == state.script->buffer->length);
- }
- state.buffer = swfdec_out_close (state.out);
- state.out = NULL;
- swfdec_script_foreach (state.script, fixup_jumps_foreach, &state);
- g_array_free (state.actions, TRUE);
-#if 0
- g_print ("got a new script in %u bytes - old script was %u bytes\n",
- state.buffer->length, state.script->buffer->length);
-#endif
- script = swfdec_script_new (state.buffer, state.script->name, state.script->version);
- g_assert (script);
- swfedit_token_set (token, idx, script);
-
- return TRUE;
-}
-
-static guint *
-string_to_action_list (const char *list)
-{
- char **actions = g_strsplit (list, ",", -1);
- guint *ret;
- guint i, len;
-
- len = g_strv_length (actions);
- ret = g_new (guint, len + 1);
- ret[len] = 0;
- for (i = 0; i < len; i++) {
- ret[i] = swfdec_action_get_from_name (actions[i]);
- if (ret[i] == 0) {
- g_printerr ("No such action \"%s\"\n", actions[i]);
- g_free (actions);
- g_free (ret);
- return NULL;
- }
- }
- g_free (actions);
- return ret;
-}
-
-int
-main (int argc, char **argv)
-{
- SwfeditFile *file;
- GError *error = NULL;
- char *add_trace_s = NULL;
- GOptionEntry options[] = {
- { "add-trace", 't', 0, G_OPTION_ARG_STRING, &add_trace_s, "list of actions to trace", "ACTION, ACTION" },
- { NULL }
- };
- GOptionContext *ctx;
-
- ctx = g_option_context_new ("");
- g_option_context_add_main_entries (ctx, options, "options");
- g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
- g_option_context_parse (ctx, &argc, &argv, &error);
- g_option_context_free (ctx);
- if (error) {
- g_printerr ("error parsing arguments: %s\n", error->message);
- g_error_free (error);
- return 1;
- }
-
- if (argc < 2) {
- g_printerr ("Usage: %s FILENAME [OUTPUT-FILENAME]\n", argv[0]);
- return 1;
- }
- if (add_trace_s) {
- add_trace = string_to_action_list (add_trace_s);
- g_free (add_trace_s);
- if (add_trace == NULL)
- return 1;
- }
- file = swfedit_file_new (argv[1], &error);
- if (file == NULL) {
- g_printerr ("error opening file %s: %s\n", argv[1], error->message);
- g_error_free (error);
- return 1;
- }
- if (!swfedit_token_foreach (SWFEDIT_TOKEN (file), modify_file, NULL)) {
- g_printerr ("modifying file %s failed.\n", argv[1]);
- g_object_unref (file);
- return 1;
- }
- g_free (file->filename);
- if (argc > 2) {
- file->filename = g_strdup (argv[2]);
- } else {
- file->filename = g_strdup_printf ("%s.out.swf", argv[1]);
- }
- if (!swfedit_file_save (file, &error)) {
- g_printerr ("Error saving file: %s\n", error->message);
- g_error_free (error);
- }
- g_print ("saved modified file to %s\n", file->filename);
- g_object_unref (file);
- return 0;
-}
-
diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index ededa70..a38f95a 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -53,8 +53,7 @@ libvivified_compiler_la_SOURCES = \
vivi_decompiler_duplicate.c \
vivi_decompiler_state.c \
vivi_decompiler_unknown.c \
- vivi_decompiler.c \
- ../../tools/swfdec_out.c
+ vivi_decompiler.c
noinst_HEADERS = \
vivi_code_assignment.h \
@@ -97,7 +96,6 @@ noinst_HEADERS = \
vivi_decompiler_duplicate.h \
vivi_decompiler_state.h
vivi_decompiler_unknown.h \
- ../../tools/swfdec_out.h \
vivified-compiler.h
noinst_PROGRAMS = vivi-decompile vivi-compile
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index b9ebc52..0b984f5 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -36,7 +36,7 @@ main (int argc, char *argv[])
ViviCodeStatement *statement;
//ViviCodePrinter *printer;
ViviCodeCompiler *compiler;
- SwfdecOut *out;
+ SwfdecBots *bots;
SwfdecBuffer *buffer;
unsigned char *length_ptr;
SwfdecRect rect = { 0, 0, 2000, 3000 };
@@ -69,25 +69,25 @@ main (int argc, char *argv[])
g_object_unref (printer);*/
- out = swfdec_out_open ();
+ bots = swfdec_bots_open ();
// header
// magic
- swfdec_out_put_u8 (out, 'F');
- swfdec_out_put_u8 (out, 'W');
- swfdec_out_put_u8 (out, 'S');
+ swfdec_bots_put_u8 (bots, 'F');
+ swfdec_bots_put_u8 (bots, 'W');
+ swfdec_bots_put_u8 (bots, 'S');
// version
- swfdec_out_put_u8 (out, 8);
+ swfdec_bots_put_u8 (bots, 8);
// length
- swfdec_out_put_u32 (out, 0);
+ swfdec_bots_put_u32 (bots, 0);
// frame size
- swfdec_out_put_rect (out, &rect);
+ swfdec_bots_put_rect (bots, &rect);
// frame rate
- swfdec_out_put_u16 (out, 15 * 256);
+ swfdec_bots_put_u16 (bots, 15 * 256);
// frame count
- swfdec_out_put_u16 (out, 1);
+ swfdec_bots_put_u16 (bots, 1);
// tags
@@ -99,23 +99,23 @@ main (int argc, char *argv[])
buffer = vivi_code_compiler_get_data (compiler);
g_object_unref (compiler);
- swfdec_out_put_u16 (out, GUINT16_TO_LE ((12 << 6) + 0x3F));
- swfdec_out_put_u32 (out, buffer->length + 1);
- swfdec_out_put_buffer (out, buffer);
+ 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_out_put_u8 (out, 0);
+ swfdec_bots_put_u8 (bots, 0);
// showframe tag
- swfdec_out_put_u16 (out, GUINT16_TO_LE (1 << 6));
+ swfdec_bots_put_u16 (bots, GUINT16_TO_LE (1 << 6));
// end tag
- swfdec_out_put_u16 (out, 0);
+ swfdec_bots_put_u16 (bots, 0);
// write it
- buffer = swfdec_out_close (out);
+ buffer = swfdec_bots_close (bots);
// fix length
length_ptr = buffer->data + 4;
@@ -126,7 +126,7 @@ main (int argc, char *argv[])
g_free (target_name);
if (fwrite (buffer->data, buffer->length, 1, target) != 1) {
- g_printerr ("Failed to write the output file\n");
+ g_printerr ("Failed to write the botsput file\n");
fclose (target);
swfdec_buffer_unref (buffer);
g_object_unref (player);
diff --git a/vivified/code/vivi_code_compiler.c b/vivified/code/vivi_code_compiler.c
index cc7d2c1..c2370ea 100644
--- a/vivified/code/vivi_code_compiler.c
+++ b/vivified/code/vivi_code_compiler.c
@@ -32,11 +32,11 @@ vivi_code_compiler_dispose (GObject *object)
GSList *iter;
if (compiler->data)
- swfdec_buffer_unref (swfdec_out_close (compiler->data));
+ swfdec_buffer_unref (swfdec_bots_close (compiler->data));
for (iter = compiler->actions; iter != NULL; iter = iter->next) {
swfdec_buffer_unref (
- swfdec_out_close (((ViviCodeCompilerAction *)iter->data)->data));
+ swfdec_bots_close (((ViviCodeCompilerAction *)iter->data)->data));
}
g_slist_free (compiler->actions);
@@ -55,7 +55,7 @@ vivi_code_compiler_class_init (ViviCodeCompilerClass *klass)
static void
vivi_code_compiler_init (ViviCodeCompiler *compiler)
{
- compiler->data = swfdec_out_open ();
+ compiler->data = swfdec_bots_open ();
}
ViviCodeCompiler *
@@ -72,8 +72,8 @@ vivi_code_compiler_get_data (ViviCodeCompiler *compiler)
g_return_val_if_fail (VIVI_IS_CODE_COMPILER (compiler), NULL);
g_return_val_if_fail (compiler->action == NULL, NULL);
- buffer = swfdec_out_close (compiler->data);
- compiler->data = swfdec_out_open ();
+ buffer = swfdec_bots_close (compiler->data);
+ compiler->data = swfdec_bots_open ();
return buffer;
}
@@ -116,7 +116,7 @@ vivi_code_compiler_add_action (ViviCodeCompiler *compiler,
compiler->action = g_new0 (ViviCodeCompilerAction, 1);
compiler->action->id = action;
- compiler->action->data = swfdec_out_open ();
+ compiler->action->data = swfdec_bots_open ();
}
void
@@ -127,14 +127,14 @@ vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
g_return_if_fail (compiler->action != NULL);
- buffer = swfdec_out_close (compiler->action->data);
+ buffer = swfdec_bots_close (compiler->action->data);
g_assert (compiler->action->id & 0x80 || buffer->length == 0);
- swfdec_out_put_u8 (compiler->data, compiler->action->id);
+ swfdec_bots_put_u8 (compiler->data, compiler->action->id);
if (compiler->action->id & 0x80) {
- swfdec_out_put_u16 (compiler->data, buffer->length);
- swfdec_out_put_buffer (compiler->data, buffer);
+ swfdec_bots_put_u16 (compiler->data, buffer->length);
+ swfdec_bots_put_buffer (compiler->data, buffer);
}
swfdec_buffer_unref (buffer);
@@ -154,7 +154,7 @@ void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
g_return_if_fail (compiler->action != NULL);
- swfdec_out_put_u8 (compiler->action->data, value);
+ swfdec_bots_put_u8 (compiler->action->data, value);
}
void
@@ -169,5 +169,5 @@ vivi_code_compiler_write_string (ViviCodeCompiler *compiler, const char *value)
g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
g_return_if_fail (compiler->action != NULL);
- swfdec_out_put_string (compiler->action->data, value);
+ swfdec_bots_put_string (compiler->action->data, value);
}
diff --git a/vivified/code/vivi_code_compiler.h b/vivified/code/vivi_code_compiler.h
index 22edac1..34bc5e4 100644
--- a/vivified/code/vivi_code_compiler.h
+++ b/vivified/code/vivi_code_compiler.h
@@ -22,12 +22,11 @@
#include <swfdec/swfdec.h>
#include <swfdec/swfdec_as_interpret.h>
+#include <swfdec/swfdec_bots.h>
#include <vivified/code/vivi_code_token.h>
#include <vivified/code/vivi_code_value.h>
-#include <tools/swfdec_out.h>
-
G_BEGIN_DECLS
@@ -42,14 +41,14 @@ typedef struct _ViviCodeCompilerClass ViviCodeCompilerClass;
typedef struct {
SwfdecAsAction id;
- SwfdecOut *data;
+ SwfdecBots *data;
} ViviCodeCompilerAction;
struct _ViviCodeCompiler
{
GObject object;
- SwfdecOut *data;
+ SwfdecBots *data;
ViviCodeCompilerAction *action;
GSList *actions; // ViviCodeCompilerAction
commit 2e272d80e7bdef94264bb946beea9b391b98aa0e
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 16:24:18 2008 +0300
Parse trace statements
diff --git a/vivified/code/vivi_code_trace.c b/vivified/code/vivi_code_trace.c
index 534e91b..4f6b097 100644
--- a/vivified/code/vivi_code_trace.c
+++ b/vivified/code/vivi_code_trace.c
@@ -23,6 +23,7 @@
#include "vivi_code_trace.h"
#include "vivi_code_printer.h"
+#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeTrace, vivi_code_trace, VIVI_TYPE_CODE_STATEMENT)
@@ -48,6 +49,18 @@ vivi_code_trace_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
+vivi_code_trace_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+{
+ ViviCodeTrace *trace = VIVI_CODE_TRACE (token);
+
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_TRACE);
+
+ vivi_code_compiler_compile_value (compiler, trace->value);
+
+ vivi_code_compiler_end_action (compiler);
+}
+
+static void
vivi_code_trace_class_init (ViviCodeTraceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -56,6 +69,7 @@ vivi_code_trace_class_init (ViviCodeTraceClass *klass)
object_class->dispose = vivi_code_trace_dispose;
token_class->print = vivi_code_trace_print;
+ token_class->compile = vivi_code_trace_compile;
}
static void
diff --git a/vivified/code/vivi_compiler.c b/vivified/code/vivi_compiler.c
index 120e216..f09f6ab 100644
--- a/vivified/code/vivi_compiler.c
+++ b/vivified/code/vivi_compiler.c
@@ -1389,6 +1389,48 @@ static ParseStatus
parse_statement (ParseData *data, ViviCodeStatement **statement);
static ParseStatus
+parse_trace_statement (ParseData *data, ViviCodeStatement **statement)
+{
+ ViviCodeValue *value;
+ ViviCodeStatement *expression_statement;
+ ParseStatus status;
+
+ *statement = NULL;
+
+ if (!check_token (data, TOKEN_TRACE))
+ return CANCEL (TOKEN_TRACE);
+
+ if (!check_token (data, TOKEN_PARENTHESIS_LEFT))
+ return FAIL (TOKEN_PARENTHESIS_LEFT);
+
+ status = parse_expression (data, &value, &expression_statement);
+ if (status != STATUS_OK)
+ return FAIL_CHILD (status);
+
+ if (!check_token (data, TOKEN_PARENTHESIS_RIGHT)) {
+ g_object_unref (value);
+ if (expression_statement != NULL)
+ g_object_unref (expression_statement);
+ return FAIL (TOKEN_PARENTHESIS_RIGHT);
+ }
+
+ if (!check_token (data, TOKEN_SEMICOLON)) {
+ g_object_unref (value);
+ if (expression_statement != NULL)
+ g_object_unref (expression_statement);
+ return FAIL (TOKEN_PARENTHESIS_RIGHT);
+ }
+
+ *statement = vivi_code_trace_new (value);
+ g_object_unref (value);
+
+ *statement =
+ vivi_compiler_join_statements (expression_statement, *statement);
+
+ return STATUS_OK;
+}
+
+static ParseStatus
parse_continue_or_break_statement (ParseData *data,
ViviCodeStatement **statement, ViviCompilerScannerToken token)
{
@@ -1947,6 +1989,7 @@ parse_statement (ParseData *data, ViviCodeStatement **statement)
//parse_switch_statement,
parse_throw_statement,
//parse_try_statement,
+ parse_trace_statement,
NULL
};
diff --git a/vivified/code/vivi_compiler_scanner.c b/vivified/code/vivi_compiler_scanner.c
index 1485aed..fd5c378 100644
--- a/vivified/code/vivi_compiler_scanner.c
+++ b/vivified/code/vivi_compiler_scanner.c
@@ -193,6 +193,10 @@ static const struct {
// reserved keywords
{ TOKEN_RESERVED_KEYWORD, "RESERVED KEYWORD" },
+ // ActionScript specific
+ { TOKEN_UNDEFINED, "undefined" },
+ { TOKEN_TRACE, "trace" },
+
{ TOKEN_LAST, NULL }
};
diff --git a/vivified/code/vivi_compiler_scanner.h b/vivified/code/vivi_compiler_scanner.h
index 14e2be9..bcccd2d 100644
--- a/vivified/code/vivi_compiler_scanner.h
+++ b/vivified/code/vivi_compiler_scanner.h
@@ -143,6 +143,7 @@ typedef enum {
// ActionScript specific
TOKEN_UNDEFINED,
+ TOKEN_TRACE,
TOKEN_LAST
} ViviCompilerScannerToken;
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index aac82e9..10167f5 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -180,6 +180,9 @@ identifier_part [$_a-zA-Z0-9]
"transient" { return TOKEN_RESERVED_KEYWORD; }
"volatile" { return TOKEN_RESERVED_KEYWORD; }
+"undefined" { return TOKEN_UNDEFINED; }
+"trace" { return TOKEN_TRACE; }
+
"null" { return TOKEN_NULL; }
"true" {
lex_value.type = VALUE_TYPE_BOOLEAN;
@@ -276,8 +279,6 @@ identifier_part [$_a-zA-Z0-9]
return TOKEN_IDENTIFIER;
}
-"undefined" { return TOKEN_UNDEFINED; }
-
. { return TOKEN_ERROR; }
%%
commit 14b14480cce1163f1709369ee775589c159632eb
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 16:24:06 2008 +0300
Remove debug output
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 445f734..b9ebc52 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -34,7 +34,7 @@ main (int argc, char *argv[])
char *target_name;
FILE *source, *target;
ViviCodeStatement *statement;
- ViviCodePrinter *printer;
+ //ViviCodePrinter *printer;
ViviCodeCompiler *compiler;
SwfdecOut *out;
SwfdecBuffer *buffer;
@@ -64,9 +64,9 @@ main (int argc, char *argv[])
return 1;
}
- printer = vivi_code_text_printer_new ();
+ /*printer = vivi_code_text_printer_new ();
vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
- g_object_unref (printer);
+ g_object_unref (printer);*/
out = swfdec_out_open ();
diff --git a/vivified/code/vivi_code_compiler.c b/vivified/code/vivi_code_compiler.c
index 27a2227..cc7d2c1 100644
--- a/vivified/code/vivi_code_compiler.c
+++ b/vivified/code/vivi_code_compiler.c
@@ -117,8 +117,6 @@ vivi_code_compiler_add_action (ViviCodeCompiler *compiler,
compiler->action = g_new0 (ViviCodeCompilerAction, 1);
compiler->action->id = action;
compiler->action->data = swfdec_out_open ();
-
- g_print ("ADD ACTION %i\n", action);
}
void
@@ -129,8 +127,6 @@ vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
g_return_if_fail (compiler->action != NULL);
- g_print ("END ACTION %i\n", compiler->action->id);
-
buffer = swfdec_out_close (compiler->action->data);
g_assert (compiler->action->id & 0x80 || buffer->length == 0);
@@ -155,7 +151,8 @@ vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
{
- g_print ("write_u8 %i\n", value);
+ g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
+ g_return_if_fail (compiler->action != NULL);
swfdec_out_put_u8 (compiler->action->data, value);
}
@@ -163,13 +160,14 @@ void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
void
vivi_code_compiler_write_double (ViviCodeCompiler *compiler, double value)
{
- g_print ("write_double %g\n", value);
+ // TODO
}
void
vivi_code_compiler_write_string (ViviCodeCompiler *compiler, const char *value)
{
- g_print ("write_string %s\n", value);
+ g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
+ g_return_if_fail (compiler->action != NULL);
swfdec_out_put_string (compiler->action->data, value);
}
commit 622fb3d67c2d0595a0f17b6dc68c504dcd5edccd
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 16:04:34 2008 +0300
Implement writing the compiled byte code to a file
Just a hack at this point
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 494190b..445f734 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -31,8 +31,15 @@ int
main (int argc, char *argv[])
{
SwfdecPlayer *player;
- FILE *file;
+ char *target_name;
+ FILE *source, *target;
ViviCodeStatement *statement;
+ ViviCodePrinter *printer;
+ ViviCodeCompiler *compiler;
+ SwfdecOut *out;
+ SwfdecBuffer *buffer;
+ unsigned char *length_ptr;
+ SwfdecRect rect = { 0, 0, 2000, 3000 };
player = swfdec_player_new (NULL);
@@ -41,35 +48,94 @@ main (int argc, char *argv[])
return 1;
}
- file = fopen (argv[1], "r");
- if (file == NULL) {
- g_printerr ("Couldn't open file %s", argv[1]);
+ source = fopen (argv[1], "r");
+ if (source == NULL) {
+ g_printerr ("Couldn't open source %s", argv[1]);
return -1;
}
- statement = vivi_compile_file (file, argv[1]);
+ statement = vivi_compile_file (source, argv[1]);
- fclose (file);
+ fclose (source);
if (statement == NULL) {
g_printerr ("Compilation failed\n");
- } else {
- ViviCodePrinter *printer;
- ViviCodeCompiler *compiler;
- SwfdecBuffer *buffer;
+ g_object_unref (player);
+ return 1;
+ }
+
+ printer = vivi_code_text_printer_new ();
+ vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
+ g_object_unref (printer);
+
+
+ out = swfdec_out_open ();
+
+
+ // header
+
+ // magic
+ swfdec_out_put_u8 (out, 'F');
+ swfdec_out_put_u8 (out, 'W');
+ swfdec_out_put_u8 (out, 'S');
+ // version
+ swfdec_out_put_u8 (out, 8);
+ // length
+ swfdec_out_put_u32 (out, 0);
+ // frame size
+ swfdec_out_put_rect (out, &rect);
+ // frame rate
+ swfdec_out_put_u16 (out, 15 * 256);
+ // frame count
+ swfdec_out_put_u16 (out, 1);
+
+
+ // tags
- printer = vivi_code_text_printer_new ();
- vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
- g_object_unref (printer);
+ // 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);
+ 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_out_put_u16 (out, GUINT16_TO_LE ((12 << 6) + 0x3F));
+ swfdec_out_put_u32 (out, buffer->length + 1);
+ swfdec_out_put_buffer (out, buffer);
+ swfdec_buffer_unref (buffer);
+ // end action
+ swfdec_out_put_u8 (out, 0);
+
+ // showframe tag
+ swfdec_out_put_u16 (out, GUINT16_TO_LE (1 << 6));
+
+ // end tag
+ swfdec_out_put_u16 (out, 0);
+
+
+ // write it
+
+ buffer = swfdec_out_close (out);
+
+ // 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 output file\n");
+ fclose (target);
swfdec_buffer_unref (buffer);
+ g_object_unref (player);
+ return 1;
}
+ fclose (target);
+ swfdec_buffer_unref (buffer);
+
g_object_unref (player);
return (statement == NULL ? -1 : 0);
diff --git a/vivified/code/vivi_code_compiler.c b/vivified/code/vivi_code_compiler.c
index 361451a..27a2227 100644
--- a/vivified/code/vivi_code_compiler.c
+++ b/vivified/code/vivi_code_compiler.c
@@ -125,18 +125,19 @@ void
vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
{
SwfdecBuffer *buffer;
- gsize length;
g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
g_return_if_fail (compiler->action != NULL);
g_print ("END ACTION %i\n", compiler->action->id);
- swfdec_out_put_u32 (compiler->data, compiler->action->id);
- length = swfdec_out_get_bits (compiler->action->data);
buffer = swfdec_out_close (compiler->action->data);
- if (length > 0) {
- swfdec_out_put_u16 (compiler->data, length / 8);
+
+ g_assert (compiler->action->id & 0x80 || buffer->length == 0);
+
+ swfdec_out_put_u8 (compiler->data, compiler->action->id);
+ if (compiler->action->id & 0x80) {
+ swfdec_out_put_u16 (compiler->data, buffer->length);
swfdec_out_put_buffer (compiler->data, buffer);
}
swfdec_buffer_unref (buffer);
@@ -155,6 +156,8 @@ vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
{
g_print ("write_u8 %i\n", value);
+
+ swfdec_out_put_u8 (compiler->action->data, value);
}
void
@@ -167,4 +170,6 @@ void
vivi_code_compiler_write_string (ViviCodeCompiler *compiler, const char *value)
{
g_print ("write_string %s\n", value);
+
+ swfdec_out_put_string (compiler->action->data, value);
}
commit 97c1a689e43eb16721334b68533203faa8bced93
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 02:21:36 2008 +0300
Start working on a compiler for AST -> byte code
diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index 808ad11..ededa70 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -21,6 +21,7 @@ libvivified_compiler_la_SOURCES = \
vivi_code_block.c \
vivi_code_break.c \
vivi_code_comment.c \
+ vivi_code_compiler.c \
vivi_code_constant.c \
vivi_code_continue.c \
vivi_code_function.c \
@@ -52,7 +53,8 @@ libvivified_compiler_la_SOURCES = \
vivi_decompiler_duplicate.c \
vivi_decompiler_state.c \
vivi_decompiler_unknown.c \
- vivi_decompiler.c
+ vivi_decompiler.c \
+ ../../tools/swfdec_out.c
noinst_HEADERS = \
vivi_code_assignment.h \
@@ -60,6 +62,7 @@ noinst_HEADERS = \
vivi_code_block.h \
vivi_code_break.h \
vivi_code_comment.h \
+ vivi_code_compiler.h \
vivi_code_constant.h \
vivi_code_continue.h \
vivi_code_function.h \
@@ -94,6 +97,7 @@ noinst_HEADERS = \
vivi_decompiler_duplicate.h \
vivi_decompiler_state.h
vivi_decompiler_unknown.h \
+ ../../tools/swfdec_out.h \
vivified-compiler.h
noinst_PROGRAMS = vivi-decompile vivi-compile
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 7570e5a..494190b 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -25,6 +25,7 @@
#include "vivi_compiler.h"
#include "vivi_code_text_printer.h"
+#include "vivi_code_compiler.h"
int
main (int argc, char *argv[])
@@ -53,9 +54,20 @@ main (int argc, char *argv[])
if (statement == NULL) {
g_printerr ("Compilation failed\n");
} else {
- ViviCodePrinter *printer = vivi_code_text_printer_new ();
+ ViviCodePrinter *printer;
+ ViviCodeCompiler *compiler;
+ SwfdecBuffer *buffer;
+
+ printer = vivi_code_text_printer_new ();
vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
g_object_unref (printer);
+
+ 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_buffer_unref (buffer);
}
g_object_unref (player);
diff --git a/vivified/code/vivi_code_assignment.c b/vivified/code/vivi_code_assignment.c
index eee40ee..104eaee 100644
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@ -25,6 +25,7 @@
#include "vivi_code_constant.h"
#include "vivi_code_get.h"
#include "vivi_code_printer.h"
+#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeAssignment, vivi_code_assignment, VIVI_TYPE_CODE_STATEMENT)
@@ -91,6 +92,35 @@ finalize:
}
static void
+vivi_code_assignment_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+{
+ ViviCodeAssignment *assignment = VIVI_CODE_ASSIGNMENT (token);
+
+ if (assignment->local) {
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_DEFINE_LOCAL);
+ } else if (assignment->from) {
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_SET_MEMBER);
+ } else {
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_SET_VARIABLE);
+ }
+
+ if (assignment->local && assignment->from) {
+ ViviCodeValue *get =
+ vivi_code_get_new (assignment->from, assignment->value);
+ vivi_code_compiler_compile_value (compiler, get);
+ g_object_unref (get);
+ } else {
+ vivi_code_compiler_compile_value (compiler, assignment->value);
+ }
+
+ vivi_code_compiler_compile_value (compiler, assignment->name);
+ if (assignment->from && !assignment->local)
+ vivi_code_compiler_compile_value (compiler, assignment->from);
+
+ vivi_code_compiler_end_action (compiler);
+}
+
+static void
vivi_code_assignment_class_init (ViviCodeAssignmentClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -99,6 +129,7 @@ vivi_code_assignment_class_init (ViviCodeAssignmentClass *klass)
object_class->dispose = vivi_code_assignment_dispose;
token_class->print = vivi_code_assignment_print;
+ token_class->compile = vivi_code_assignment_compile;
}
static void
diff --git a/vivified/code/vivi_code_block.c b/vivified/code/vivi_code_block.c
index 39f3c93..2dbec28 100644
--- a/vivified/code/vivi_code_block.c
+++ b/vivified/code/vivi_code_block.c
@@ -28,6 +28,7 @@
#include "vivi_code_comment.h"
#include "vivi_code_label.h"
#include "vivi_code_printer.h"
+#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeBlock, vivi_code_block, VIVI_TYPE_CODE_STATEMENT)
@@ -89,6 +90,18 @@ vivi_code_block_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
static void
+vivi_code_block_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+{
+ ViviCodeBlock *block = VIVI_CODE_BLOCK (token);
+ guint i;
+
+ for (i = 0; i < block->statements->len; i++) {
+ vivi_code_compiler_compile_token (compiler,
+ VIVI_CODE_TOKEN (g_ptr_array_index (block->statements, i)));
+ }
+}
+
+static void
vivi_code_block_class_init (ViviCodeBlockClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -98,6 +111,7 @@ vivi_code_block_class_init (ViviCodeBlockClass *klass)
object_class->dispose = vivi_code_block_dispose;
token_class->print = vivi_code_block_print;
+ token_class->compile = vivi_code_block_compile;
statement_class->optimize = vivi_code_block_optimize;
statement_class->needs_braces = vivi_code_block_needs_braces;
diff --git a/vivified/code/vivi_code_compiler.c b/vivified/code/vivi_code_compiler.c
new file mode 100644
index 0000000..361451a
--- /dev/null
+++ b/vivified/code/vivi_code_compiler.c
@@ -0,0 +1,170 @@
+/* Vivified
+ * Copyright (C) 2008 Pekka Lampila <pekka.lampila at iki.fi>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vivi_code_compiler.h"
+
+G_DEFINE_TYPE (ViviCodeCompiler, vivi_code_compiler, G_TYPE_OBJECT)
+
+static void
+vivi_code_compiler_dispose (GObject *object)
+{
+ ViviCodeCompiler *compiler = VIVI_CODE_COMPILER (object);
+ GSList *iter;
+
+ if (compiler->data)
+ swfdec_buffer_unref (swfdec_out_close (compiler->data));
+
+ for (iter = compiler->actions; iter != NULL; iter = iter->next) {
+ swfdec_buffer_unref (
+ swfdec_out_close (((ViviCodeCompilerAction *)iter->data)->data));
+ }
+
+ g_slist_free (compiler->actions);
+
+ G_OBJECT_CLASS (vivi_code_compiler_parent_class)->dispose (object);
+}
+
+static void
+vivi_code_compiler_class_init (ViviCodeCompilerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = vivi_code_compiler_dispose;
+}
+
+static void
+vivi_code_compiler_init (ViviCodeCompiler *compiler)
+{
+ compiler->data = swfdec_out_open ();
+}
+
+ViviCodeCompiler *
+vivi_code_compiler_new (void)
+{
+ return g_object_new (VIVI_TYPE_CODE_COMPILER, NULL);
+}
+
+SwfdecBuffer *
+vivi_code_compiler_get_data (ViviCodeCompiler *compiler)
+{
+ SwfdecBuffer *buffer;
+
+ g_return_val_if_fail (VIVI_IS_CODE_COMPILER (compiler), NULL);
+ g_return_val_if_fail (compiler->action == NULL, NULL);
+
+ buffer = swfdec_out_close (compiler->data);
+ compiler->data = swfdec_out_open ();
+
+ return buffer;
+}
+
+void
+vivi_code_compiler_compile_token (ViviCodeCompiler *compiler,
+ ViviCodeToken *token)
+{
+ ViviCodeTokenClass *klass;
+ ViviCodeCompilerAction *action;
+
+ g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
+ g_return_if_fail (VIVI_IS_CODE_TOKEN (token));
+
+ action = compiler->action;
+
+ klass = VIVI_CODE_TOKEN_GET_CLASS (token);
+ g_return_if_fail (klass->compile);
+ klass->compile (token, compiler);
+
+ g_assert (compiler->action == action);
+}
+
+void
+vivi_code_compiler_compile_value (ViviCodeCompiler *compiler,
+ ViviCodeValue *value)
+{
+ vivi_code_compiler_compile_token (compiler, VIVI_CODE_TOKEN (value));
+}
+
+
+void
+vivi_code_compiler_add_action (ViviCodeCompiler *compiler,
+ SwfdecAsAction action)
+{
+ g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
+
+ if (compiler->action != NULL)
+ compiler->actions = g_slist_prepend (compiler->actions, compiler->action);
+
+ compiler->action = g_new0 (ViviCodeCompilerAction, 1);
+ compiler->action->id = action;
+ compiler->action->data = swfdec_out_open ();
+
+ g_print ("ADD ACTION %i\n", action);
+}
+
+void
+vivi_code_compiler_end_action (ViviCodeCompiler *compiler)
+{
+ SwfdecBuffer *buffer;
+ gsize length;
+
+ g_return_if_fail (VIVI_IS_CODE_COMPILER (compiler));
+ g_return_if_fail (compiler->action != NULL);
+
+ g_print ("END ACTION %i\n", compiler->action->id);
+
+ swfdec_out_put_u32 (compiler->data, compiler->action->id);
+ length = swfdec_out_get_bits (compiler->action->data);
+ buffer = swfdec_out_close (compiler->action->data);
+ if (length > 0) {
+ swfdec_out_put_u16 (compiler->data, length / 8);
+ swfdec_out_put_buffer (compiler->data, buffer);
+ }
+ swfdec_buffer_unref (buffer);
+
+ g_free (compiler->action);
+
+ if (compiler->actions != NULL) {
+ compiler->action = compiler->actions->data;
+ compiler->actions =
+ g_slist_delete_link (compiler->actions, compiler->actions);
+ } else {
+ compiler->action = NULL;
+ }
+}
+
+void vivi_code_compiler_write_u8 (ViviCodeCompiler *compiler, guint value)
+{
+ g_print ("write_u8 %i\n", value);
+}
+
+void
+vivi_code_compiler_write_double (ViviCodeCompiler *compiler, double value)
+{
+ g_print ("write_double %g\n", value);
+}
+
+void
+vivi_code_compiler_write_string (ViviCodeCompiler *compiler, const char *value)
+{
+ g_print ("write_string %s\n", value);
+}
diff --git a/vivified/code/vivi_code_compiler.h b/vivified/code/vivi_code_compiler.h
new file mode 100644
index 0000000..22edac1
--- /dev/null
+++ b/vivified/code/vivi_code_compiler.h
@@ -0,0 +1,84 @@
+/* Vivified
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef _VIVI_CODE_COMPILER_H_
+#define _VIVI_CODE_COMPILER_H_
+
+#include <swfdec/swfdec.h>
+#include <swfdec/swfdec_as_interpret.h>
+
+#include <vivified/code/vivi_code_token.h>
+#include <vivified/code/vivi_code_value.h>
+
+#include <tools/swfdec_out.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _ViviCodeCompilerClass ViviCodeCompilerClass;
+
+#define VIVI_TYPE_CODE_COMPILER (vivi_code_compiler_get_type())
+#define VIVI_IS_CODE_COMPILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_COMPILER))
+#define VIVI_IS_CODE_COMPILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_COMPILER))
+#define VIVI_CODE_COMPILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_COMPILER, ViviCodeCompiler))
+#define VIVI_CODE_COMPILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_COMPILER, ViviCodeCompilerClass))
+#define VIVI_CODE_COMPILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_COMPILER, ViviCodeCompilerClass))
+
+typedef struct {
+ SwfdecAsAction id;
+ SwfdecOut *data;
+} ViviCodeCompilerAction;
+
+struct _ViviCodeCompiler
+{
+ GObject object;
+
+ SwfdecOut *data;
+
+ ViviCodeCompilerAction *action;
+ GSList *actions; // ViviCodeCompilerAction
+};
+
+struct _ViviCodeCompilerClass
+{
+ GObjectClass object_class;
+};
+
+GType vivi_code_compiler_get_type (void);
+
+ViviCodeCompiler *vivi_code_compiler_new (void);
+
+SwfdecBuffer * vivi_code_compiler_get_data (ViviCodeCompiler * compiler);
+
+void vivi_code_compiler_compile_token (ViviCodeCompiler * compiler,
+ ViviCodeToken * token);
+void vivi_code_compiler_compile_value (ViviCodeCompiler * compiler,
+ ViviCodeValue * value);
+
+void vivi_code_compiler_add_action (ViviCodeCompiler * compiler,
+ SwfdecAsAction action);
+void vivi_code_compiler_end_action (ViviCodeCompiler * compiler);
+
+void vivi_code_compiler_write_u8 (ViviCodeCompiler * compiler, guint value);
+void vivi_code_compiler_write_double (ViviCodeCompiler * compiler, double value);
+void vivi_code_compiler_write_string (ViviCodeCompiler * compiler, const char *value);
+
+
+G_END_DECLS
+#endif
diff --git a/vivified/code/vivi_code_constant.c b/vivified/code/vivi_code_constant.c
index 935b905..2bf3fcf 100644
--- a/vivified/code/vivi_code_constant.c
+++ b/vivified/code/vivi_code_constant.c
@@ -27,6 +27,7 @@
#include "vivi_code_constant.h"
#include "vivi_code_printer.h"
+#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeConstant, vivi_code_constant, VIVI_TYPE_CODE_VALUE)
@@ -118,6 +119,44 @@ vivi_code_constant_print (ViviCodeToken *token, ViviCodePrinter *printer)
}
}
+static void
+vivi_code_constant_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+{
+ ViviCodeConstant *constant = VIVI_CODE_CONSTANT (token);
+
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_PUSH);
+
+ switch (constant->value.type) {
+ case SWFDEC_AS_TYPE_UNDEFINED:
+ vivi_code_compiler_write_u8 (compiler, 3);
+ break;
+ case SWFDEC_AS_TYPE_NULL:
+ vivi_code_compiler_write_u8 (compiler, 2);
+ break;
+ case SWFDEC_AS_TYPE_BOOLEAN:
+ vivi_code_compiler_write_u8 (compiler, 5);
+ vivi_code_compiler_write_u8 (compiler,
+ SWFDEC_AS_VALUE_GET_BOOLEAN (&constant->value));
+ break;
+ case SWFDEC_AS_TYPE_NUMBER:
+ vivi_code_compiler_write_u8 (compiler, 6);
+ vivi_code_compiler_write_double (compiler,
+ SWFDEC_AS_VALUE_GET_NUMBER (&constant->value));
+ break;
+ case SWFDEC_AS_TYPE_STRING:
+ vivi_code_compiler_write_u8 (compiler, 0);
+ vivi_code_compiler_write_string (compiler,
+ SWFDEC_AS_VALUE_GET_STRING (&constant->value));
+ break;
+ case SWFDEC_AS_TYPE_INT:
+ case SWFDEC_AS_TYPE_OBJECT:
+ default:
+ g_assert_not_reached ();
+ }
+
+ vivi_code_compiler_end_action (compiler);
+}
+
static gboolean
vivi_code_constant_is_constant (ViviCodeValue *value)
{
@@ -134,6 +173,7 @@ vivi_code_constant_class_init (ViviCodeConstantClass *klass)
object_class->dispose = vivi_code_constant_dispose;
token_class->print = vivi_code_constant_print;
+ token_class->compile = vivi_code_constant_compile;
value_class->is_constant = vivi_code_constant_is_constant;
}
diff --git a/vivified/code/vivi_code_get.c b/vivified/code/vivi_code_get.c
index d90731a..687274c 100644
--- a/vivified/code/vivi_code_get.c
+++ b/vivified/code/vivi_code_get.c
@@ -24,6 +24,7 @@
#include "vivi_code_get.h"
#include "vivi_code_constant.h"
#include "vivi_code_printer.h"
+#include "vivi_code_compiler.h"
G_DEFINE_TYPE (ViviCodeGet, vivi_code_get, VIVI_TYPE_CODE_VALUE)
@@ -72,6 +73,24 @@ vivi_code_get_print (ViviCodeToken *token, ViviCodePrinter*printer)
g_free (varname);
}
+static void
+vivi_code_get_compile (ViviCodeToken *token, ViviCodeCompiler *compiler)
+{
+ ViviCodeGet *get = VIVI_CODE_GET (token);
+
+ if (get->from) {
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_GET_MEMBER);
+ } else {
+ vivi_code_compiler_add_action (compiler, SWFDEC_AS_ACTION_GET_VARIABLE);
+ }
+
+ vivi_code_compiler_compile_value (compiler, get->name);
+ if (get->from)
+ vivi_code_compiler_compile_value (compiler, get->from);
+
+ vivi_code_compiler_end_action (compiler);
+}
+
static gboolean
vivi_code_get_is_constant (ViviCodeValue *value)
{
@@ -88,6 +107,7 @@ vivi_code_get_class_init (ViviCodeGetClass *klass)
object_class->dispose = vivi_code_get_dispose;
token_class->print = vivi_code_get_print;
+ token_class->compile = vivi_code_get_compile;
value_class->is_constant = vivi_code_get_is_constant;
}
diff --git a/vivified/code/vivi_code_token.h b/vivified/code/vivi_code_token.h
index afdee1a..f23054a 100644
--- a/vivified/code/vivi_code_token.h
+++ b/vivified/code/vivi_code_token.h
@@ -26,6 +26,7 @@ G_BEGIN_DECLS
typedef struct _ViviCodePrinter ViviCodePrinter;
+typedef struct _ViviCodeCompiler ViviCodeCompiler;
typedef struct _ViviCodeToken ViviCodeToken;
typedef struct _ViviCodeTokenClass ViviCodeTokenClass;
@@ -48,6 +49,8 @@ struct _ViviCodeTokenClass
void (* print) (ViviCodeToken * token,
ViviCodePrinter * printer);
+ void (* compile) (ViviCodeToken * token,
+ ViviCodeCompiler * compiler);
};
GType vivi_code_token_get_type (void);
commit 625bd080fd196b09ea817762beffd0cb10389365
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sun Apr 6 02:20:45 2008 +0300
Fix a memleak in parse_expression. Fix suppressing extra statements in parse_expression_statement
diff --git a/vivified/code/vivi_compiler.c b/vivified/code/vivi_compiler.c
index acdbdf1..120e216 100644
--- a/vivified/code/vivi_compiler.c
+++ b/vivified/code/vivi_compiler.c
@@ -1368,6 +1368,8 @@ parse_expression (ParseData *data, ViviCodeValue **value,
if (!check_token (data, TOKEN_COMMA))
break;
+ g_object_unref (*value);
+
status = parse_assignment_expression (data, value, &statement_one);
if (status != STATUS_OK) {
g_object_unref (*value);
@@ -1844,10 +1846,10 @@ parse_expression_statement (ParseData *data, ViviCodeStatement **statement)
last = *statement;
}
- if (VIVI_IS_CODE_ASSIGNMENT (last)) {
+ if (VIVI_IS_CODE_ASSIGNMENT (last) && VIVI_IS_CODE_GET (value)) {
ViviCodeAssignment *assignment = VIVI_CODE_ASSIGNMENT (last);
- if (assignment->from == NULL && assignment->name == value) {
+ if (assignment->from == NULL && assignment->name == VIVI_CODE_GET (value)->name) {
g_object_unref (value);
return STATUS_OK;
}
commit 1b49e39bb90656bb13ac6c13d95a0da4d39685c2
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 23:13:46 2008 +0300
Clean up the flex file somewhat
diff --git a/vivified/code/Makefile.am b/vivified/code/Makefile.am
index 0adf79f..808ad11 100644
--- a/vivified/code/Makefile.am
+++ b/vivified/code/Makefile.am
@@ -3,7 +3,7 @@ SUBDIRS = test
noinst_LTLIBRARIES = libvivified-compiler-lex.la libvivified-compiler.la
# we create own .la for lex generated code, so we can disable some warnings
-libvivified_compiler_lex_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) -Wno-redundant-decls -Wno-switch-default -Wno-missing-declarations -Wno-missing-prototypes -Wno-sign-compare -Wno-unused-function -Wno-missing-noreturn
+libvivified_compiler_lex_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) -Wno-switch-default -Wno-missing-declarations -Wno-missing-prototypes -Wno-sign-compare -Wno-unused-function -Wno-missing-noreturn
libvivified_compiler_lex_la_LDFLAGS = $(SWFDEC_LIBS)
libvivified_compiler_lex_la_SOURCES = \
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index eeb7608..aac82e9 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -22,8 +22,9 @@
%}
%option noyywrap
+%option nostdinit
+%option never-interactive
-digit [0-9]
identifier_start [$_a-zA-Z]
identifier_part [$_a-zA-Z0-9]
@@ -34,23 +35,33 @@ identifier_part [$_a-zA-Z0-9]
GString *string;
-"/*" { BEGIN(comment); }
+<<EOF>> { return TOKEN_EOF; }
+"/*" { BEGIN(comment); }
<comment>{
[^*\n]* /* skip */
- \n lex_line_number++;
- "*/" BEGIN(INITIAL);
- <<EOF>> { BEGIN(INITIAL); return TOKEN_ERROR; }
+ \n { lex_line_number++; }
+ "*/" { BEGIN(INITIAL); }
+ <<EOF>> {
+ BEGIN(INITIAL);
+ return TOKEN_ERROR;
+ }
}
+"//"[^\r\n]* {
+ lex_line_number++;
+ return TOKEN_LINE_TERMINATOR;
+ }
-"//"[^\r\n]* { lex_line_number++;
- return TOKEN_LINE_TERMINATOR; }
-[ \t] /* skip whitespace */
-<<EOF>> { return TOKEN_EOF; }
-\r\n { lex_line_number++;
- return TOKEN_LINE_TERMINATOR; }
-[\r\n] { lex_line_number++;
- return TOKEN_LINE_TERMINATOR; }
+[ \t] /* skip */
+
+\r\n {
+ lex_line_number++;
+ return TOKEN_LINE_TERMINATOR;
+ }
+[\r\n] {
+ lex_line_number++;
+ return TOKEN_LINE_TERMINATOR;
+ }
"{" { return TOKEN_BRACE_LEFT; }
"}" { return TOKEN_BRACE_RIGHT; }
@@ -170,84 +181,103 @@ identifier_part [$_a-zA-Z0-9]
"volatile" { return TOKEN_RESERVED_KEYWORD; }
"null" { return TOKEN_NULL; }
-"true" { lex_value.type = VALUE_TYPE_BOOLEAN;
+"true" {
+ lex_value.type = VALUE_TYPE_BOOLEAN;
lex_value.v_boolean = 1;
- return TOKEN_BOOLEAN; }
-"false" { lex_value.type = VALUE_TYPE_BOOLEAN;
+ return TOKEN_BOOLEAN;
+ }
+"false" {
+ lex_value.type = VALUE_TYPE_BOOLEAN;
lex_value.v_boolean = 0;
- return TOKEN_BOOLEAN; }
+ return TOKEN_BOOLEAN;
+ }
-0[xX][0-9a-fA-F]+ { lex_value.type = VALUE_TYPE_NUMBER;
+0[xX][0-9a-fA-F]+ {
+ lex_value.type = VALUE_TYPE_NUMBER;
lex_value.v_number =
g_ascii_strtoull (yytext, NULL, 16);
- return TOKEN_NUMBER; }
+ return TOKEN_NUMBER;
+ }
([1-9][0-9]*|0)(\.[0-9]*)?([eE][+-]?[0-9]+)? {
lex_value.type = VALUE_TYPE_NUMBER;
lex_value.v_number = g_ascii_strtod (yytext, NULL);
- return TOKEN_NUMBER; }
+ return TOKEN_NUMBER;
+ }
\.[0-9]+([eE][+-]?[0-9]+)? {
lex_value.type = VALUE_TYPE_NUMBER;
lex_value.v_number = g_ascii_strtod (yytext, NULL);
- return TOKEN_NUMBER; }
+ return TOKEN_NUMBER;
+ }
-\" { string = g_string_new ("");
+\" {
+ string = g_string_new ("");
BEGIN(str);
}
<str>{
- \" { BEGIN(INITIAL);
- lex_value.type = VALUE_TYPE_STRING;
- lex_value.v_string = g_string_free (string, FALSE);
- return TOKEN_STRING; }
- \n { BEGIN(INITIAL);
- g_string_free (string, TRUE);
- return TOKEN_ERROR; }
- \\0 g_string_append_c (string, '0');
- \\[0-7]{1,3} { guint64 result;
- result = g_ascii_strtoull (yytext + 1, NULL, 8);
- if (result > 0xff) {
- g_string_free (string, TRUE);
- return TOKEN_ERROR;
- } else {
- g_string_append_c (string, result);
- }
- }
- \\[0-9]+ { g_string_free (string, TRUE);
- return TOKEN_ERROR; }
- \\x[0-9a-fA-F]{2} { guint64 result;
- result = g_ascii_strtoull (yytext + 2, NULL, 16);
- if (result == 0) {
- BEGIN(INITIAL);
- g_string_free (string, TRUE);
- return TOKEN_ERROR;
- } else {
- g_string_append_c (string, result);
- }
- }
- \\b g_string_append_c (string, '\b');
- \\f g_string_append_c (string, '\f');
- \\n g_string_append_c (string, '\n');
- \\r g_string_append_c (string, '\r');
- \\t g_string_append_c (string, '\t');
- \\v g_string_append_c (string, '\v');
- \\. g_string_append_c (string, yytext[1]);
- [^\\\n\"]+ { char *p = yytext;
- while (*p != '\0') {
- g_string_append_c (string, *p);
- p++;
- }
- }
+ \" {
+ BEGIN(INITIAL);
+ lex_value.type = VALUE_TYPE_STRING;
+ lex_value.v_string = g_string_free (string, FALSE);
+ return TOKEN_STRING;
+ }
+ \n {
+ BEGIN(INITIAL);
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ }
+ \\0 { g_string_append_c (string, '0'); }
+ \\[0-7]{1,3} {
+ guint64 result;
+ result = g_ascii_strtoull (yytext + 1, NULL, 8);
+ if (result > 0xff || result == 0) {
+ BEGIN(INITIAL);
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ } else {
+ g_string_append_c (string, result);
+ }
+ }
+ \\[0-9]+ {
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ }
+ \\x[0-9a-fA-F]{2} {
+ guint64 result;
+ result = g_ascii_strtoull (yytext + 2, NULL, 16);
+ if (result == 0) {
+ BEGIN(INITIAL);
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ } else {
+ g_string_append_c (string, result);
+ }
+ }
+ \\b { g_string_append_c (string, '\b'); }
+ \\f { g_string_append_c (string, '\f'); }
+ \\n { g_string_append_c (string, '\n'); }
+ \\r { g_string_append_c (string, '\r'); }
+ \\t { g_string_append_c (string, '\t'); }
+ \\v { g_string_append_c (string, '\v'); }
+ \\. { g_string_append_c (string, yytext[1]); }
+ [^\\\n\"]+ {
+ char *p;
+ for (p = yytext; *p != '\0'; p++) {
+ g_string_append_c (string, *p);
+ }
+ }
}
{identifier_start}({identifier_part})* {
lex_value.type = VALUE_TYPE_IDENTIFIER;
lex_value.v_identifier = g_strdup (yytext);
- return TOKEN_IDENTIFIER; }
+ return TOKEN_IDENTIFIER;
+ }
"undefined" { return TOKEN_UNDEFINED; }
-. { printf("Unknown character [%c]\n",yytext[0]);
- return TOKEN_UNKNOWN; }
+. { return TOKEN_ERROR; }
+
%%
commit 29e8a70bc6d758b75ffdb8e080698676c9a0aa78
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 22:49:20 2008 +0300
Do better number parsing
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index a335dbd..eeb7608 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -27,9 +27,6 @@ digit [0-9]
identifier_start [$_a-zA-Z]
identifier_part [$_a-zA-Z0-9]
-/* r'([1-9][0-9]*|0)(\.[0-9]*)?([eE][+-][0-9]+)? */
-/* '\.[0-9]+([eE][+-][0-9]+)?' */
-
%x str
%x comment
@@ -180,8 +177,19 @@ identifier_part [$_a-zA-Z0-9]
lex_value.v_boolean = 0;
return TOKEN_BOOLEAN; }
-[-+]*{digit}+ { lex_value.type = VALUE_TYPE_NUMBER;
- lex_value.v_number = atoi(yytext);
+0[xX][0-9a-fA-F]+ { lex_value.type = VALUE_TYPE_NUMBER;
+ lex_value.v_number =
+ g_ascii_strtoull (yytext, NULL, 16);
+ return TOKEN_NUMBER; }
+
+([1-9][0-9]*|0)(\.[0-9]*)?([eE][+-]?[0-9]+)? {
+ lex_value.type = VALUE_TYPE_NUMBER;
+ lex_value.v_number = g_ascii_strtod (yytext, NULL);
+ return TOKEN_NUMBER; }
+
+\.[0-9]+([eE][+-]?[0-9]+)? {
+ lex_value.type = VALUE_TYPE_NUMBER;
+ lex_value.v_number = g_ascii_strtod (yytext, NULL);
return TOKEN_NUMBER; }
\" { string = g_string_new ("");
commit 3f2f9cef589b3c014ea7dd66fa3cff049aad9fc2
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 22:01:07 2008 +0300
Handle line number counting better and parse multi-line comments
diff --git a/vivified/code/vivi_compiler_scanner.c b/vivified/code/vivi_compiler_scanner.c
index 888e793..1485aed 100644
--- a/vivified/code/vivi_compiler_scanner.c
+++ b/vivified/code/vivi_compiler_scanner.c
@@ -233,11 +233,11 @@ vivi_compiler_scanner_advance (ViviCompilerScanner *scanner)
scanner->next_line_terminator = FALSE;
}
while (scanner->next_token == TOKEN_LINE_TERMINATOR) {
- scanner->next_line_number++;
scanner->next_token = yylex ();
}
- scanner->next_value = yylval;
- yylval.type = VALUE_TYPE_NONE;
+ scanner->next_value = lex_value;
+ scanner->next_line_number = lex_line_number;
+ lex_value.type = VALUE_TYPE_NONE;
}
}
@@ -250,8 +250,7 @@ vivi_compiler_scanner_new (FILE *file)
scanner = g_object_new (VIVI_TYPE_COMPILER_SCANNER, NULL);
scanner->file = file;
- scanner->line_number = 1;
- scanner->next_line_number = 1;
+ scanner->line_number = scanner->next_line_number = lex_line_number = 1;
yyrestart (file);
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index 3c2f9d4..a335dbd 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -31,15 +31,29 @@ identifier_part [$_a-zA-Z0-9]
/* '\.[0-9]+([eE][+-][0-9]+)?' */
%x str
+%x comment
%%
GString *string;
-"//"[^\r\n]* { return TOKEN_LINE_TERMINATOR; }
+"/*" { BEGIN(comment); }
+
+<comment>{
+ [^*\n]* /* skip */
+ \n lex_line_number++;
+ "*/" BEGIN(INITIAL);
+ <<EOF>> { BEGIN(INITIAL); return TOKEN_ERROR; }
+}
+
+"//"[^\r\n]* { lex_line_number++;
+ return TOKEN_LINE_TERMINATOR; }
[ \t] /* skip whitespace */
<<EOF>> { return TOKEN_EOF; }
-[\n\r]* { return TOKEN_LINE_TERMINATOR; }
+\r\n { lex_line_number++;
+ return TOKEN_LINE_TERMINATOR; }
+[\r\n] { lex_line_number++;
+ return TOKEN_LINE_TERMINATOR; }
"{" { return TOKEN_BRACE_LEFT; }
"}" { return TOKEN_BRACE_RIGHT; }
@@ -159,14 +173,15 @@ identifier_part [$_a-zA-Z0-9]
"volatile" { return TOKEN_RESERVED_KEYWORD; }
"null" { return TOKEN_NULL; }
-"true" { yylval.type = VALUE_TYPE_BOOLEAN;
- yylval.v_boolean = 1;
+"true" { lex_value.type = VALUE_TYPE_BOOLEAN;
+ lex_value.v_boolean = 1;
return TOKEN_BOOLEAN; }
-"false" { yylval.type = VALUE_TYPE_BOOLEAN;
- yylval.v_boolean = 0;
+"false" { lex_value.type = VALUE_TYPE_BOOLEAN;
+ lex_value.v_boolean = 0;
return TOKEN_BOOLEAN; }
-[-+]*{digit}+ { yylval.type = VALUE_TYPE_NUMBER;
- yylval.v_number = atoi(yytext);
+
+[-+]*{digit}+ { lex_value.type = VALUE_TYPE_NUMBER;
+ lex_value.v_number = atoi(yytext);
return TOKEN_NUMBER; }
\" { string = g_string_new ("");
@@ -175,8 +190,8 @@ identifier_part [$_a-zA-Z0-9]
<str>{
\" { BEGIN(INITIAL);
- yylval.type = VALUE_TYPE_STRING;
- yylval.v_string = g_string_free (string, FALSE);
+ lex_value.type = VALUE_TYPE_STRING;
+ lex_value.v_string = g_string_free (string, FALSE);
return TOKEN_STRING; }
\n { BEGIN(INITIAL);
g_string_free (string, TRUE);
@@ -219,8 +234,8 @@ identifier_part [$_a-zA-Z0-9]
}
{identifier_start}({identifier_part})* {
- yylval.type = VALUE_TYPE_IDENTIFIER;
- yylval.v_identifier = g_strdup (yytext);
+ lex_value.type = VALUE_TYPE_IDENTIFIER;
+ lex_value.v_identifier = g_strdup (yytext);
return TOKEN_IDENTIFIER; }
"undefined" { return TOKEN_UNDEFINED; }
diff --git a/vivified/code/vivi_compiler_scanner_lex_include.h b/vivified/code/vivi_compiler_scanner_lex_include.h
index 5527862..f85f00e 100644
--- a/vivified/code/vivi_compiler_scanner_lex_include.h
+++ b/vivified/code/vivi_compiler_scanner_lex_include.h
@@ -22,6 +22,7 @@
#include "vivi_compiler_scanner.h"
-ViviCompilerScannerValue yylval;
+ViviCompilerScannerValue lex_value;
+guint lex_line_number;
#endif // _VIVI_COMPILER_SCANNER_LEX_INCLUDE_H_
commit fd117f3041a886f1ebc01a975e2e539ba6da0605
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 21:31:43 2008 +0300
Oops, an error in \x parsing in strings
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index 58e1e14..3c2f9d4 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -193,9 +193,9 @@ identifier_part [$_a-zA-Z0-9]
}
\\[0-9]+ { g_string_free (string, TRUE);
return TOKEN_ERROR; }
- \\x[0-9a-fA-F]{1,2} { guint64 result;
+ \\x[0-9a-fA-F]{2} { guint64 result;
result = g_ascii_strtoull (yytext + 2, NULL, 16);
- if (result > 0xff || result == 0) {
+ if (result == 0) {
BEGIN(INITIAL);
g_string_free (string, TRUE);
return TOKEN_ERROR;
commit c377c63bec5ef87c4da000ccf13f68277d8624c3
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 20:59:20 2008 +0300
Don't leak memory in yylval
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index 08d85b6..7570e5a 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -52,11 +52,13 @@ main (int argc, char *argv[])
if (statement == NULL) {
g_printerr ("Compilation failed\n");
- return -1;
} else {
ViviCodePrinter *printer = vivi_code_text_printer_new ();
vivi_code_printer_print_token (printer, VIVI_CODE_TOKEN (statement));
g_object_unref (printer);
- return 0;
}
+
+ g_object_unref (player);
+
+ return (statement == NULL ? -1 : 0);
}
diff --git a/vivified/code/vivi_compiler_scanner.c b/vivified/code/vivi_compiler_scanner.c
index 8020b1d..888e793 100644
--- a/vivified/code/vivi_compiler_scanner.c
+++ b/vivified/code/vivi_compiler_scanner.c
@@ -29,9 +29,35 @@
G_DEFINE_TYPE (ViviCompilerScanner, vivi_compiler_scanner, G_TYPE_OBJECT)
static void
+vivi_compiler_scanner_free_type_value (ViviCompilerScannerValue *value)
+{
+ switch (value->type) {
+ case VALUE_TYPE_STRING:
+ g_free (value->v_string);
+ break;
+ case VALUE_TYPE_IDENTIFIER:
+ g_free (value->v_identifier);
+ break;
+ case VALUE_TYPE_NONE:
+ case VALUE_TYPE_BOOLEAN:
+ case VALUE_TYPE_NUMBER:
+ /* nothing */
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ value->type = VALUE_TYPE_NONE;
+}
+
+static void
vivi_compiler_scanner_dispose (GObject *object)
{
- //ViviCompilerScanner *scanner = VIVI_COMPILER_SCANNER (object);
+ ViviCompilerScanner *scanner = VIVI_COMPILER_SCANNER (object);
+
+ vivi_compiler_scanner_free_type_value (&scanner->value);
+ vivi_compiler_scanner_free_type_value (&scanner->next_value);
G_OBJECT_CLASS (vivi_compiler_scanner_parent_class)->dispose (object);
}
@@ -189,6 +215,8 @@ vivi_compiler_scanner_advance (ViviCompilerScanner *scanner)
{
g_return_if_fail (VIVI_IS_COMPILER_SCANNER (scanner));
+ vivi_compiler_scanner_free_type_value (&scanner->value);
+
scanner->token = scanner->next_token;
scanner->value = scanner->next_value;
scanner->line_number = scanner->next_line_number;
@@ -209,6 +237,7 @@ vivi_compiler_scanner_advance (ViviCompilerScanner *scanner)
scanner->next_token = yylex ();
}
scanner->next_value = yylval;
+ yylval.type = VALUE_TYPE_NONE;
}
}
diff --git a/vivified/code/vivi_compiler_scanner.h b/vivified/code/vivi_compiler_scanner.h
index ad5f2d6..14e2be9 100644
--- a/vivified/code/vivi_compiler_scanner.h
+++ b/vivified/code/vivi_compiler_scanner.h
@@ -147,11 +147,22 @@ typedef enum {
TOKEN_LAST
} ViviCompilerScannerToken;
-typedef union {
- gboolean v_boolean;
- double v_number;
- char * v_string;
- char * v_identifier;
+typedef enum {
+ VALUE_TYPE_NONE,
+ VALUE_TYPE_BOOLEAN,
+ VALUE_TYPE_NUMBER,
+ VALUE_TYPE_STRING,
+ VALUE_TYPE_IDENTIFIER
+} ViviCompilerScannerValueType;
+
+typedef struct {
+ ViviCompilerScannerValueType type;
+ union {
+ gboolean v_boolean;
+ double v_number;
+ char * v_string;
+ char * v_identifier;
+ };
} ViviCompilerScannerValue;
typedef struct _ViviCompilerScanner ViviCompilerScanner;
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index ce90856..58e1e14 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -159,11 +159,14 @@ identifier_part [$_a-zA-Z0-9]
"volatile" { return TOKEN_RESERVED_KEYWORD; }
"null" { return TOKEN_NULL; }
-"true" { yylval.v_boolean = 1;
+"true" { yylval.type = VALUE_TYPE_BOOLEAN;
+ yylval.v_boolean = 1;
return TOKEN_BOOLEAN; }
-"false" { yylval.v_boolean = 0;
+"false" { yylval.type = VALUE_TYPE_BOOLEAN;
+ yylval.v_boolean = 0;
return TOKEN_BOOLEAN; }
-[-+]*{digit}+ { yylval.v_number = atoi(yytext);
+[-+]*{digit}+ { yylval.type = VALUE_TYPE_NUMBER;
+ yylval.v_number = atoi(yytext);
return TOKEN_NUMBER; }
\" { string = g_string_new ("");
@@ -172,6 +175,7 @@ identifier_part [$_a-zA-Z0-9]
<str>{
\" { BEGIN(INITIAL);
+ yylval.type = VALUE_TYPE_STRING;
yylval.v_string = g_string_free (string, FALSE);
return TOKEN_STRING; }
\n { BEGIN(INITIAL);
@@ -215,6 +219,7 @@ identifier_part [$_a-zA-Z0-9]
}
{identifier_start}({identifier_part})* {
+ yylval.type = VALUE_TYPE_IDENTIFIER;
yylval.v_identifier = g_strdup (yytext);
return TOKEN_IDENTIFIER; }
commit c6596079445d6091d326348fb559109cf094ff1c
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Sat Apr 5 20:34:57 2008 +0300
Do proper string parsing
diff --git a/vivified/code/vivi_code_constant.c b/vivified/code/vivi_code_constant.c
index 10ab8c9..935b905 100644
--- a/vivified/code/vivi_code_constant.c
+++ b/vivified/code/vivi_code_constant.c
@@ -48,14 +48,32 @@ escape_string (const char *s)
char *next;
str = g_string_new ("\"");
- while ((next = strpbrk (s, "\"\n"))) {
+ while ((next = strpbrk (s, "\"\\\b\f\n\r\t\v"))) {
g_string_append_len (str, s, next - s);
switch (*next) {
case '"':
g_string_append (str, "\\\"");
break;
+ case '\\':
+ g_string_append (str, "\\\\");
+ break;
+ case '\b':
+ g_string_append (str, "\\b");
+ break;
+ case '\f':
+ g_string_append (str, "\\f");
+ break;
case '\n':
- g_string_append (str, "\n");
+ g_string_append (str, "\\n");
+ break;
+ case '\r':
+ g_string_append (str, "\\r");
+ break;
+ case '\t':
+ g_string_append (str, "\\t");
+ break;
+ case '\v':
+ g_string_append (str, "\\v");
break;
default:
g_assert_not_reached ();
diff --git a/vivified/code/vivi_compiler_scanner.c b/vivified/code/vivi_compiler_scanner.c
index 2f36db0..8020b1d 100644
--- a/vivified/code/vivi_compiler_scanner.c
+++ b/vivified/code/vivi_compiler_scanner.c
@@ -56,6 +56,7 @@ static const struct {
// special
{ TOKEN_NONE, "NONE" },
{ TOKEN_EOF, "EOF" },
+ { TOKEN_ERROR, "ERROR" },
{ TOKEN_UNKNOWN, "UNKNOWN" },
{ TOKEN_LINE_TERMINATOR, "NEW LINE" },
diff --git a/vivified/code/vivi_compiler_scanner.h b/vivified/code/vivi_compiler_scanner.h
index e5d349f..ad5f2d6 100644
--- a/vivified/code/vivi_compiler_scanner.h
+++ b/vivified/code/vivi_compiler_scanner.h
@@ -30,6 +30,7 @@ typedef enum {
// special
TOKEN_NONE = 0,
TOKEN_EOF,
+ TOKEN_ERROR,
TOKEN_UNKNOWN,
TOKEN_LINE_TERMINATOR,
diff --git a/vivified/code/vivi_compiler_scanner_lex.l b/vivified/code/vivi_compiler_scanner_lex.l
index 55f9e44..ce90856 100644
--- a/vivified/code/vivi_compiler_scanner_lex.l
+++ b/vivified/code/vivi_compiler_scanner_lex.l
@@ -30,8 +30,12 @@ identifier_part [$_a-zA-Z0-9]
/* r'([1-9][0-9]*|0)(\.[0-9]*)?([eE][+-][0-9]+)? */
/* '\.[0-9]+([eE][+-][0-9]+)?' */
+%x str
+
%%
+ GString *string;
+
"//"[^\r\n]* { return TOKEN_LINE_TERMINATOR; }
[ \t] /* skip whitespace */
<<EOF>> { return TOKEN_EOF; }
@@ -161,9 +165,54 @@ identifier_part [$_a-zA-Z0-9]
return TOKEN_BOOLEAN; }
[-+]*{digit}+ { yylval.v_number = atoi(yytext);
return TOKEN_NUMBER; }
-("\""[^\"]*"\""|"'"[^']*"'") {
- yylval.v_string = g_strndup (yytext + 1, yyleng - 2);
- return TOKEN_STRING; }
+
+\" { string = g_string_new ("");
+ BEGIN(str);
+ }
+
+<str>{
+ \" { BEGIN(INITIAL);
+ yylval.v_string = g_string_free (string, FALSE);
+ return TOKEN_STRING; }
+ \n { BEGIN(INITIAL);
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR; }
+ \\0 g_string_append_c (string, '0');
+ \\[0-7]{1,3} { guint64 result;
+ result = g_ascii_strtoull (yytext + 1, NULL, 8);
+ if (result > 0xff) {
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ } else {
+ g_string_append_c (string, result);
+ }
+ }
+ \\[0-9]+ { g_string_free (string, TRUE);
+ return TOKEN_ERROR; }
+ \\x[0-9a-fA-F]{1,2} { guint64 result;
+ result = g_ascii_strtoull (yytext + 2, NULL, 16);
+ if (result > 0xff || result == 0) {
+ BEGIN(INITIAL);
+ g_string_free (string, TRUE);
+ return TOKEN_ERROR;
+ } else {
+ g_string_append_c (string, result);
+ }
+ }
+ \\b g_string_append_c (string, '\b');
+ \\f g_string_append_c (string, '\f');
+ \\n g_string_append_c (string, '\n');
+ \\r g_string_append_c (string, '\r');
+ \\t g_string_append_c (string, '\t');
+ \\v g_string_append_c (string, '\v');
+ \\. g_string_append_c (string, yytext[1]);
+ [^\\\n\"]+ { char *p = yytext;
+ while (*p != '\0') {
+ g_string_append_c (string, *p);
+ p++;
+ }
+ }
+}
{identifier_start}({identifier_part})* {
yylval.v_identifier = g_strdup (yytext);
More information about the Swfdec-commits
mailing list