From f1b1180d52d93122385178620d984597471fa9d0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 9 Aug 2007 22:17:56 +0200 Subject: [PATCH] add vivi_application_run() function This requires hooking up ming --- vivified/core/Makefile.am | 8 ++-- vivified/core/vivi_application.c | 20 +++++++- vivified/core/vivi_application.h | 2 + vivified/core/vivi_ming.c | 98 ++++++++++++++++++++++++++++++++++++++++ vivified/core/vivi_ming.h | 34 ++++++++++++++ 5 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 vivified/core/vivi_ming.c create mode 100644 vivified/core/vivi_ming.h diff --git a/vivified/core/Makefile.am b/vivified/core/Makefile.am index dc150416..0bcac398 100644 --- a/vivified/core/Makefile.am +++ b/vivified/core/Makefile.am @@ -1,11 +1,13 @@ noinst_LTLIBRARIES = libvivified-core.la -libvivified_core_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_GTK_CFLAGS) -libvivified_core_la_LDFLAGS = $(SWFDEC_GTK_LIBS) +libvivified_core_la_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_GTK_CFLAGS) $(VIVI_CFLAGS) +libvivified_core_la_LDFLAGS = $(SWFDEC_GTK_LIBS) $(VIVI_LIBS) libvivified_core_la_SOURCES = \ - vivi_application.c + vivi_application.c \ + vivi_ming.c noinst_HEADERS = \ vivi_application.h \ + vivi_ming.h \ vivified-core.h diff --git a/vivified/core/vivi_application.c b/vivified/core/vivi_application.c index dd85bc44..c526580b 100644 --- a/vivified/core/vivi_application.c +++ b/vivified/core/vivi_application.c @@ -21,8 +21,9 @@ #include "config.h" #endif -#include "vivi_application.h" #include +#include "vivi_application.h" +#include "vivi_ming.h" enum { PROP_0, @@ -143,3 +144,20 @@ vivi_application_get_player (ViviApplication *app) return app->player; } +void +vivi_application_run (ViviApplication *app, const char *command) +{ + SwfdecScript *script; + char *error = NULL; + + g_return_if_fail (VIVI_IS_APPLICATION (app)); + g_return_if_fail (command != NULL); + + script = vivi_ming_compile (command, &error); + if (script == NULL) { + g_free (error); + } + swfdec_as_object_run (SWFDEC_AS_CONTEXT (app)->global, script); + swfdec_script_unref (script); +} + diff --git a/vivified/core/vivi_application.h b/vivified/core/vivi_application.h index 6e0df414..8a21410b 100644 --- a/vivified/core/vivi_application.h +++ b/vivified/core/vivi_application.h @@ -58,6 +58,8 @@ const char * vivi_application_get_filename (ViviApplication * app); SwfdecPlayer * vivi_application_get_player (ViviApplication * app); void vivi_application_reset (ViviApplication * app); +void vivi_application_run (ViviApplication * app, + const char * command); G_END_DECLS #endif diff --git a/vivified/core/vivi_ming.c b/vivified/core/vivi_ming.c new file mode 100644 index 00000000..3ef14b1c --- /dev/null +++ b/vivified/core/vivi_ming.c @@ -0,0 +1,98 @@ +/* Vivified + * Copyright (C) 2007 Benjamin Otte + * + * 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_ming.h" +#include + +static GString *ming_errors = NULL; + +static void +vivi_ming_error (const char *format, ...) +{ + va_list varargs; + char *s; + + if (ming_errors) { + g_string_append_c (ming_errors, '\n'); + } else { + ming_errors = g_string_new (""); + } + va_start (varargs, format); + g_string_append_vprintf (ming_errors, format, varargs); + s = g_strdup_vprintf (format, varargs); + va_end (varargs); +} + +static char * +vivi_ming_get_error (void) +{ + char *ret; + + if (ming_errors == NULL) + return g_strdup ("Unknown error"); + + ret = g_string_free (ming_errors, FALSE); + ming_errors = NULL; + return ret; +} + +static void +vivi_ming_init (void) +{ + static gboolean ming_inited = FALSE; + + if (ming_inited) + return; + + ming_inited = TRUE; + + Ming_init (); + Ming_useSWFVersion (8); + Ming_setErrorFunction (vivi_ming_error); + Ming_setWarnFunction (vivi_ming_error); +} + +SwfdecScript * +vivi_ming_compile (const char *code, char **error) +{ + byte *data; + SWFAction action; + gsize len; + SwfdecBuffer *buffer; + SwfdecScript *script; + + vivi_ming_init (); + + action = newSWFAction (code); + data = SWFAction_getByteCode (action, &len); + if (data == NULL || len == 0) { + if (error) + *error = vivi_ming_get_error (); + return NULL; + } + buffer = swfdec_buffer_new_and_alloc (len); + memcpy (buffer->data, data, len); + script = swfdec_script_new (buffer, "compiled script", 8); + return script; +} + diff --git a/vivified/core/vivi_ming.h b/vivified/core/vivi_ming.h new file mode 100644 index 00000000..98d3b85e --- /dev/null +++ b/vivified/core/vivi_ming.h @@ -0,0 +1,34 @@ +/* Vivified + * Copyright (C) 2007 Benjamin Otte + * + * 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 + */ + +#include +#include + +#ifndef _VIVI_MING_H_ +#define _VIVI_MING_H_ + +G_BEGIN_DECLS + + +SwfdecScript * vivi_ming_compile (const char * code, + char ** error); + + +G_END_DECLS +#endif -- 2.11.4.GIT