[Swfdec-commits] 11 commits - configure.ac vivified/code
Benjamin Otte
company at kemper.freedesktop.org
Fri Apr 25 14:56:03 PDT 2008
configure.ac | 2
vivified/code/compiler.c | 18 +++----
vivified/code/rewrite.c | 61 +++++++++++++++++++++++--
vivified/code/vivi_code_asm_code_default.h | 7 ++
vivified/code/vivi_code_assignment.c | 2
vivified/code/vivi_code_function_call.c | 2
vivified/code/vivi_code_get.c | 2
vivified/code/vivi_parser.c | 50 +++++++++++++--------
vivified/code/vivi_parser.h | 8 +--
vivified/code/vivi_parser_scanner.c | 35 ++++++--------
vivified/code/vivi_parser_scanner.h | 8 +--
vivified/code/vivi_parser_scanner_lex.l | 69 ++++++++++++++++++-----------
12 files changed, 174 insertions(+), 90 deletions(-)
New commits:
commit d9ebc559ced4e908ef11ca4d779a6f0dfd4c7178
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 23:55:45 2008 +0200
disbale debugging again
diff --git a/vivified/code/vivi_parser_scanner.c b/vivified/code/vivi_parser_scanner.c
index 32503d6..54ab5fb 100644
--- a/vivified/code/vivi_parser_scanner.c
+++ b/vivified/code/vivi_parser_scanner.c
@@ -233,7 +233,7 @@ vivi_parser_scanner_advance (ViviParserScanner *scanner)
/* we set the position to "0" here so that we know if we initialized it already */
value->position = G_MAXSIZE;
value->token = vivi_parser_scanner_lex (scanner->scanner, value);
-#if 1
+#if 0
g_print ("%u:%u %5zu %c %s\n", value->line_number, value->column,
value->position, value->line_terminator ? '+' : '-',
vivi_parser_scanner_token_name (value->token));
commit 35229a130680b413b4bd4a24fcad970bd0dacd49
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 23:55:02 2008 +0200
fix order of arguments
diff --git a/vivified/code/vivi_code_assignment.c b/vivified/code/vivi_code_assignment.c
index 0163c16..4ace08c 100644
--- a/vivified/code/vivi_code_assignment.c
+++ b/vivified/code/vivi_code_assignment.c
@@ -98,9 +98,9 @@ vivi_code_assignment_compile (ViviCodeToken *token,
ViviCodeAssignment *assignment = VIVI_CODE_ASSIGNMENT (token);
ViviCodeAsm *code;
- vivi_code_value_compile (assignment->name, assembler);
if (assignment->from && !assignment->local)
vivi_code_value_compile (assignment->from, assembler);
+ vivi_code_value_compile (assignment->name, assembler);
if (assignment->local && assignment->from) {
ViviCodeValue *get =
diff --git a/vivified/code/vivi_code_function_call.c b/vivified/code/vivi_code_function_call.c
index ab131a9..ee61a26 100644
--- a/vivified/code/vivi_code_function_call.c
+++ b/vivified/code/vivi_code_function_call.c
@@ -130,7 +130,7 @@ vivi_code_function_call_compile (ViviCodeToken *token,
ViviCodeAsm *code;
guint i;
- for (i = 0; i < call->arguments->len; i++) {
+ for (i = call->arguments->len - 1; i < call->arguments->len; i--) {
vivi_code_value_compile (g_ptr_array_index (call->arguments, i),
assembler);
}
diff --git a/vivified/code/vivi_code_get.c b/vivified/code/vivi_code_get.c
index 9fd0ec8..be801f9 100644
--- a/vivified/code/vivi_code_get.c
+++ b/vivified/code/vivi_code_get.c
@@ -80,9 +80,9 @@ vivi_code_get_compile (ViviCodeToken *token, ViviCodeAssembler *assembler)
ViviCodeGet *get = VIVI_CODE_GET (token);
ViviCodeAsm *code;
- vivi_code_value_compile (get->name, assembler);
if (get->from)
vivi_code_value_compile (get->from, assembler);
+ vivi_code_value_compile (get->name, assembler);
if (get->from) {
code = vivi_code_asm_get_member_new ();
commit 9f77404badcaa9a3492140730c0c7f3d21894ccb
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 23:54:40 2008 +0200
fix refcounting bug
diff --git a/vivified/code/rewrite.c b/vivified/code/rewrite.c
index 11950c2..47014b0 100644
--- a/vivified/code/rewrite.c
+++ b/vivified/code/rewrite.c
@@ -184,7 +184,8 @@ replace_random (ViviCodeAssembler *assembler, guint init)
vivi_code_statement_compile (statement, asm2);
g_object_unref (statement);
for (j = 0; j < vivi_code_assembler_get_n_codes (asm2); j++) {
- INSERT_CODE (assembler, i, vivi_code_assembler_get_code (asm2, j));
+ vivi_code_assembler_insert_code (assembler, i++,
+ vivi_code_assembler_get_code (asm2, j));
}
g_object_unref (asm2);
}
commit 8833c954427790c952bb671fd85faf0680b70901
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 21:57:26 2008 +0200
set column to 0 instead of yycolumn
yycolumn isn't initialized and so contains weird values at times
diff --git a/vivified/code/vivi_parser_scanner_lex.l b/vivified/code/vivi_parser_scanner_lex.l
index a0d7224..47dfde8 100644
--- a/vivified/code/vivi_parser_scanner_lex.l
+++ b/vivified/code/vivi_parser_scanner_lex.l
@@ -39,7 +39,7 @@ extern YY_DECL;
#define YY_USER_ACTION \
if (value->position == G_MAXSIZE) { \
value->line_number = yylineno; \
- value->column = yycolumn; \
+ value->column = 0; \
/* FIXME: is this supportable? */ \
value->position = yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; \
}
commit c559f800e2d5802533826727b2c55cca0d6c313f
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 21:56:23 2008 +0200
make rewrite replace calls to random() with 0
Also adds RANDOM macros to vivi_code_asm_code_default.h
Feel free to add your own if you need them
diff --git a/vivified/code/rewrite.c b/vivified/code/rewrite.c
index 8aabf4c..11950c2 100644
--- a/vivified/code/rewrite.c
+++ b/vivified/code/rewrite.c
@@ -33,9 +33,13 @@
#include <vivified/code/vivi_code_asm_push.h>
#include <vivified/code/vivi_code_assembler.h>
#include <vivified/code/vivi_decompiler.h>
+#include <vivified/code/vivi_parser.h>
typedef enum {
- REWRITE_TRACE_FUNCTION_NAME = (1 << 0)
+ REWRITE_TRACE_FUNCTION_NAME = (1 << 0),
+ REWRITE_RANDOM = (1 << 1),
+
+ REWRITE_INIT = (1 << 17)
} RewriteOptions;
static const char *
@@ -158,6 +162,46 @@ insert_function_trace (ViviCodeAssembler *assembler, const char *name)
}
}
+static void
+replace_random (ViviCodeAssembler *assembler, guint init)
+{
+ guint i = 0;
+
+ if (init) {
+ guint j;
+ ViviCodeStatement *statement;
+ ViviCodeAssembler *asm2;
+ if (VIVI_IS_CODE_ASM_POOL (vivi_code_assembler_get_code (assembler, i)))
+ i++;
+
+ statement = vivi_parse_string (
+ "ASSetPropFlags (Math, \"random\", 0, 0-1);"
+ "Math.random = function () { return 0; };"
+ "ASSetPropFlags (Math, \"random\", 7);"
+ );
+ g_assert (statement);
+ asm2 = VIVI_CODE_ASSEMBLER (vivi_code_assembler_new ());
+ vivi_code_statement_compile (statement, asm2);
+ g_object_unref (statement);
+ for (j = 0; j < vivi_code_assembler_get_n_codes (asm2); j++) {
+ INSERT_CODE (assembler, i, vivi_code_assembler_get_code (asm2, j));
+ }
+ g_object_unref (asm2);
+ }
+
+ for (; i < vivi_code_assembler_get_n_codes (assembler); i++) {
+ ViviCodeAsm *code = vivi_code_assembler_get_code (assembler, i);
+ if (VIVI_IS_CODE_ASM_RANDOM (code)) {
+ ViviCodeAsm *push = vivi_code_asm_push_new ();
+ vivi_code_assembler_remove_code (assembler, code);
+ INSERT_CODE (assembler, i, vivi_code_asm_pop_new ());
+ vivi_code_asm_push_add_integer (VIVI_CODE_ASM_PUSH (push), 0);
+ INSERT_CODE (assembler, i, push);
+ i--;
+ }
+ }
+}
+
/*** INFRASTRUCTURE ***/
static SwfdecBuffer *
@@ -172,9 +216,10 @@ do_script (SwfdecBuffer *buffer, guint flags, const char *name, guint version)
assembler = VIVI_CODE_ASSEMBLER (vivi_disassemble_script (script));
swfdec_script_unref (script);
- /* FIXME: modify script here! */
if (flags & REWRITE_TRACE_FUNCTION_NAME)
insert_function_trace (assembler, name);
+ if (flags & REWRITE_RANDOM)
+ replace_random (assembler, flags & REWRITE_INIT);
script = vivi_code_assembler_assemble_script (assembler, version, &error);
g_object_unref (assembler);
@@ -200,7 +245,7 @@ process_buffer (SwfdecBuffer *original, guint flags)
SwfdecBots *bots, *full;
SwfdecBuffer *buffer;
guint version, tag, len;
- gboolean long_header;
+ gboolean long_header, needs_init = TRUE;
bots = swfdec_bots_open ();
swfdec_bits_init (&bits, original);
@@ -239,7 +284,9 @@ process_buffer (SwfdecBuffer *original, guint flags)
guint sprite = buffer->data[0] | buffer->data[1] << 8;
char *name = g_strdup_printf ("DoInitAction %u", sprite);
swfdec_bots_put_u16 (bots2, sprite);
- sub = do_script (sub, flags, name, version);
+ sub = do_script (sub, flags | (needs_init ? REWRITE_INIT : 0), name, version);
+ /* FIXME: we should add init when there's no init actions, too */
+ needs_init = FALSE;
g_free (name);
if (sub == NULL) {
swfdec_bots_free (bots2);
@@ -328,9 +375,11 @@ main (int argc, char *argv[])
GError *error = NULL;
SwfdecBuffer *buffer;
gboolean trace_function_names = FALSE;
+ gboolean random = FALSE;
GOptionEntry options[] = {
{ "trace-function-names", 'n', 0, G_OPTION_ARG_NONE, &trace_function_names, "trace names of called functions", NULL },
+ { "no-random", 'r', 0, G_OPTION_ARG_NONE, &random, "replace all random values with 0", NULL },
{ NULL }
};
GOptionContext *ctx;
@@ -366,7 +415,8 @@ main (int argc, char *argv[])
}
buffer = process_buffer (buffer,
- (trace_function_names ? REWRITE_TRACE_FUNCTION_NAME : 0));
+ (trace_function_names ? REWRITE_TRACE_FUNCTION_NAME : 0) |
+ (random ? REWRITE_RANDOM : 0));
if (buffer == NULL) {
g_printerr ("\"%s\": Broken Flash file\n", argv[1]);
return 1;
diff --git a/vivified/code/vivi_code_asm_code_default.h b/vivified/code/vivi_code_asm_code_default.h
index 72bdfba..179fc53 100644
--- a/vivified/code/vivi_code_asm_code_default.h
+++ b/vivified/code/vivi_code_asm_code_default.h
@@ -36,6 +36,13 @@ ViviCodeAsm * vivi_code_asm_ ## underscore_name ## _new (void);
#include "vivi_code_defaults.h"
+#define VIVI_TYPE_CODE_ASM_RANDOM (vivi_code_asm_random_get_type())
+#define VIVI_IS_CODE_ASM_RANDOM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIVI_TYPE_CODE_ASM_RANDOM))
+#define VIVI_IS_CODE_ASM_RANDOM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIVI_TYPE_CODE_ASM_RANDOM))
+#define VIVI_CODE_ASM_RANDOM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIVI_TYPE_CODE_ASM_RANDOM, ViviCodeAsmRandom))
+#define VIVI_CODE_ASM_RANDOM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIVI_TYPE_CODE_ASM_RANDOM, ViviCodeAsmRandomClass))
+#define VIVI_CODE_ASM_RANDOM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIVI_TYPE_CODE_ASM_RANDOM, ViviCodeAsmRandomClass))
+
G_END_DECLS
#endif
commit f8d3cab5b0f655ae64ccd6fe43fc864ea6191c6c
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 21:39:44 2008 +0200
use the right header marker
diff --git a/vivified/code/vivi_parser.h b/vivified/code/vivi_parser.h
index 63456ed..ec6f180 100644
--- a/vivified/code/vivi_parser.h
+++ b/vivified/code/vivi_parser.h
@@ -17,8 +17,8 @@
* Boston, MA 02110-1301 USA
*/
-#ifndef _VIVI_DECOMPILER_H_
-#define _VIVI_DECOMPILER_H_
+#ifndef _VIVI_PARSER_H_
+#define _VIVI_PARSER_H_
#include <stdio.h>
commit 8a58d77649f2cb25e16df5a2edfe16eebcd724dc
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 21:10:30 2008 +0200
update cairo dependency to 1.6
This is the previously mentioned update necessary to us using CAIRO_EXTEND_PAD
on images
diff --git a/configure.ac b/configure.ac
index 4437d73..612f6ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,7 +196,7 @@ if test "$HAVE_LIBOIL" = "no"; then
AC_MSG_ERROR([liboil-0.3 >= $LIBOIL_VER is required to build swfdec])
fi
-CAIRO_VER=1.2.0
+CAIRO_VER=1.6.0
PKG_CHECK_MODULES(CAIRO, cairo >= $CAIRO_VER cairo-png >= $CAIRO_VER, HAVE_CAIRO=yes, HAVE_CAIRO=no)
AC_SUBST(CAIRO_LIBS)
AC_SUBST(CAIRO_CFLAGS)
commit 760f82c23ed35176d5c505e58b5cbbb49171cec5
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 20:54:15 2008 +0200
remove the static GString and put it into the value
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 55c931e..4ca6ccb 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -716,7 +716,7 @@ peek_string_value (ParseData *data)
{
const ViviParserValue *value = vivi_parser_scanner_get_value (data->scanner, 1);
if (value->token == TOKEN_STRING) {
- return value->value.v_string;
+ return value->value.v_string->str;
} else {
return "undefined";
}
@@ -731,7 +731,7 @@ parse_string_value (ParseData *data)
value = vivi_parser_scanner_get_value (data->scanner, 0);
if (value->token == TOKEN_STRING) {
- return value->value.v_string;
+ return value->value.v_string->str;
} else {
return "undefined";
}
diff --git a/vivified/code/vivi_parser_scanner.c b/vivified/code/vivi_parser_scanner.c
index e0447de..32503d6 100644
--- a/vivified/code/vivi_parser_scanner.c
+++ b/vivified/code/vivi_parser_scanner.c
@@ -31,7 +31,7 @@ static void
vivi_parser_value_reset (ViviParserValue *value)
{
if (value->token == TOKEN_STRING) {
- g_free (value->value.v_string);
+ g_string_free (value->value.v_string, TRUE);
} else if (value->token == TOKEN_IDENTIFIER) {
g_free (value->value.v_identifier);
}
diff --git a/vivified/code/vivi_parser_scanner.h b/vivified/code/vivi_parser_scanner.h
index 78e603e..2346e5e 100644
--- a/vivified/code/vivi_parser_scanner.h
+++ b/vivified/code/vivi_parser_scanner.h
@@ -150,9 +150,8 @@ typedef struct {
union {
gboolean v_boolean;
double v_number;
- char * v_string;
+ GString * v_string;
char * v_identifier;
- char * v_error;
} value;
gboolean line_terminator;
guint line_number;
diff --git a/vivified/code/vivi_parser_scanner_lex.l b/vivified/code/vivi_parser_scanner_lex.l
index 8093c28..a0d7224 100644
--- a/vivified/code/vivi_parser_scanner_lex.l
+++ b/vivified/code/vivi_parser_scanner_lex.l
@@ -27,8 +27,6 @@ extern YY_DECL;
}
%{
-static GString *string = NULL;
-
#define RESET_POSITION value->position = G_MAXSIZE
#define ERROR(...) vivi_parser_scanner_error (yyextra, yylineno, yycolumn, __VA_ARGS__)
@@ -239,19 +237,18 @@ identifier_part [$_a-zA-Z0-9]
}
\" {
- string = g_string_new ("");
+ value->value.v_string = g_string_new ("");
BEGIN(str);
}
<str>{
\" {
BEGIN(INITIAL);
- value->value.v_string = g_string_free (string, FALSE);
return TOKEN_STRING;
}
\n {
BEGIN(INITIAL);
- g_string_free (string, TRUE);
+ g_string_free (value->value.v_string, TRUE);
ERROR ("Unterminated string constant");
RESET_POSITION;
}
@@ -261,7 +258,7 @@ identifier_part [$_a-zA-Z0-9]
if (result > 0xff || result == 0) {
ERROR ("Invalid escape sequence %s", yytext);
} else {
- g_string_append_c (string, result);
+ g_string_append_c (value->value.v_string, result);
}
}
\\[0-9]+ { ERROR ("Invalid escape sequence %s", yytext); }
@@ -271,20 +268,20 @@ identifier_part [$_a-zA-Z0-9]
if (result == 0) {
ERROR ("Invalid escape sequence %s", yytext);
} else {
- g_string_append_c (string, result);
+ g_string_append_c (value->value.v_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]); }
+ \\b { g_string_append_c (value->value.v_string, '\b'); }
+ \\f { g_string_append_c (value->value.v_string, '\f'); }
+ \\n { g_string_append_c (value->value.v_string, '\n'); }
+ \\r { g_string_append_c (value->value.v_string, '\r'); }
+ \\t { g_string_append_c (value->value.v_string, '\t'); }
+ \\v { g_string_append_c (value->value.v_string, '\v'); }
+ \\. { g_string_append_c (value->value.v_string, yytext[1]); }
[^\\\n\"]+ {
char *p;
for (p = yytext; *p != '\0'; p++) {
- g_string_append_c (string, *p);
+ g_string_append_c (value->value.v_string, *p);
}
}
}
commit b2383a4dca19cbd4d7b0ca1fb41fc8ccc26dbf80
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 20:50:22 2008 +0200
shuffle APIs around to add vivi_parse_string()
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 8f0b638..55c931e 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -2987,30 +2987,44 @@ parse_value_statement_list (ParseData *data, PeekFunction peek,
*list = (ViviCodeValue **)g_ptr_array_free (array, FALSE);
}
-// public
-
-ViviCodeStatement *
-vivi_parse_buffer (SwfdecBuffer *buffer)
+static ViviCodeStatement *
+vivi_do_parse (const guint8 *data, gsize length)
{
- ParseData data;
+ ParseData parse;
ViviCodeStatement *statement;
- g_return_val_if_fail (buffer != NULL, NULL);
+ parse.scanner = vivi_parser_scanner_new (data, length);
+ vivi_parser_scanner_set_error_handler (parse.scanner,
+ vivi_parser_error_handler, &parse);
+ parse.levels = NULL;
+ parse.level = NULL;
+ parse.error_count = 0;
- data.scanner = vivi_parser_scanner_new (buffer);
- vivi_parser_scanner_set_error_handler (data.scanner,
- vivi_parser_error_handler, &data);
- data.levels = NULL;
- data.level = NULL;
- data.error_count = 0;
-
- statement = parse_program (&data);
- if (data.error_count != 0) {
+ statement = parse_program (&parse);
+ if (parse.error_count != 0) {
g_object_unref (statement);
statement = NULL;
}
- g_object_unref (data.scanner);
+ g_object_unref (parse.scanner);
return statement;
}
+
+// public
+
+ViviCodeStatement *
+vivi_parse_buffer (SwfdecBuffer *buffer)
+{
+ g_return_val_if_fail (buffer != NULL, NULL);
+
+ return vivi_do_parse (buffer->data, buffer->length);
+}
+
+ViviCodeStatement *
+vivi_parse_string (const char *string)
+{
+ g_return_val_if_fail (string != NULL, NULL);
+
+ return vivi_do_parse ((const guint8 *) string, strlen (string));
+}
diff --git a/vivified/code/vivi_parser.h b/vivified/code/vivi_parser.h
index c73afa5..63456ed 100644
--- a/vivified/code/vivi_parser.h
+++ b/vivified/code/vivi_parser.h
@@ -28,6 +28,7 @@
G_BEGIN_DECLS
+ViviCodeStatement * vivi_parse_string (const char * string);
ViviCodeStatement * vivi_parse_buffer (SwfdecBuffer * buffer);
diff --git a/vivified/code/vivi_parser_scanner.c b/vivified/code/vivi_parser_scanner.c
index efdcbe1..e0447de 100644
--- a/vivified/code/vivi_parser_scanner.c
+++ b/vivified/code/vivi_parser_scanner.c
@@ -253,16 +253,16 @@ vivi_parser_scanner_get_value (ViviParserScanner *scanner, guint i)
}
ViviParserScanner *
-vivi_parser_scanner_new (SwfdecBuffer *buffer)
+vivi_parser_scanner_new (const guint8 *data, gsize length)
{
ViviParserScanner *scanner;
ViviParserValue *value;
- g_return_val_if_fail (buffer != NULL, NULL);
+ g_return_val_if_fail (data != NULL || length == 0, NULL);
scanner = g_object_new (VIVI_TYPE_PARSER_SCANNER, NULL);
- vivi_parser_scanner__scan_bytes ((char *) buffer->data, buffer->length, scanner->scanner);
+ vivi_parser_scanner__scan_bytes ((const char *) data, length, scanner->scanner);
/* seems flex is too stupid to reset the line number for buffers */
vivi_parser_scanner_set_lineno (1, scanner->scanner);
diff --git a/vivified/code/vivi_parser_scanner.h b/vivified/code/vivi_parser_scanner.h
index 7fd90d9..78e603e 100644
--- a/vivified/code/vivi_parser_scanner.h
+++ b/vivified/code/vivi_parser_scanner.h
@@ -190,7 +190,8 @@ struct _ViviParserScannerClass
GType vivi_parser_scanner_get_type (void);
-ViviParserScanner * vivi_parser_scanner_new (SwfdecBuffer * buffer);
+ViviParserScanner * vivi_parser_scanner_new (const guint8 * data,
+ gsize len);
void vivi_parser_scanner_set_error_handler (ViviParserScanner * scanner,
ViviParserScannerFunction error_handler,
gpointer user_data);
commit de55597ba9f770b555d68d15d17e39575de0abae
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 20:42:57 2008 +0200
get the position of the token
diff --git a/vivified/code/vivi_parser_scanner.c b/vivified/code/vivi_parser_scanner.c
index 1873073..efdcbe1 100644
--- a/vivified/code/vivi_parser_scanner.c
+++ b/vivified/code/vivi_parser_scanner.c
@@ -230,11 +230,12 @@ vivi_parser_scanner_advance (ViviParserScanner *scanner)
}
value->line_terminator = FALSE;
- value->position = 0; /* FIXME */
+ /* we set the position to "0" here so that we know if we initialized it already */
+ value->position = G_MAXSIZE;
value->token = vivi_parser_scanner_lex (scanner->scanner, value);
-#if 0
- g_print ("%u:%u %c %s\n", value->line_number, value->column,
- value->line_terminator ? '+' : '-',
+#if 1
+ g_print ("%u:%u %5zu %c %s\n", value->line_number, value->column,
+ value->position, value->line_terminator ? '+' : '-',
vivi_parser_scanner_token_name (value->token));
#endif
value->line_number = vivi_parser_scanner_get_lineno (scanner->scanner);
@@ -262,6 +263,8 @@ vivi_parser_scanner_new (SwfdecBuffer *buffer)
scanner = g_object_new (VIVI_TYPE_PARSER_SCANNER, NULL);
vivi_parser_scanner__scan_bytes ((char *) buffer->data, buffer->length, scanner->scanner);
+ /* seems flex is too stupid to reset the line number for buffers */
+ vivi_parser_scanner_set_lineno (1, scanner->scanner);
value = swfdec_ring_buffer_push (scanner->values);
value->token = TOKEN_UNKNOWN;
diff --git a/vivified/code/vivi_parser_scanner_lex.l b/vivified/code/vivi_parser_scanner_lex.l
index dde4fec..8093c28 100644
--- a/vivified/code/vivi_parser_scanner_lex.l
+++ b/vivified/code/vivi_parser_scanner_lex.l
@@ -28,11 +28,23 @@ extern YY_DECL;
%{
static GString *string = NULL;
+
+#define RESET_POSITION value->position = G_MAXSIZE
+
#define ERROR(...) vivi_parser_scanner_error (yyextra, yylineno, yycolumn, __VA_ARGS__)
+#define LINE_TERMINATOR G_STMT_START {\
+ value->line_terminator = TRUE; \
+ RESET_POSITION; \
+}G_STMT_END
+
#define YY_USER_ACTION \
- value->line_number = yylineno; \
- value->column = yycolumn;
+ if (value->position == G_MAXSIZE) { \
+ value->line_number = yylineno; \
+ value->column = yycolumn; \
+ /* FIXME: is this supportable? */ \
+ value->position = yytext - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; \
+ }
%}
%option header-file="vivi_parser_scanner_lex.h"
@@ -55,23 +67,31 @@ identifier_part [$_a-zA-Z0-9]
"/*" { BEGIN(comment); }
<comment>{
- "*/" { BEGIN(INITIAL); }
+ "*/" {
+ BEGIN(INITIAL);
+ /* FIXME: use the comment somehow */
+ RESET_POSITION;
+ }
. { /* skip */ }
- \n { value->line_terminator = TRUE; }
+ \n { LINE_TERMINATOR; }
<<EOF>> {
BEGIN(INITIAL);
ERROR ("Unterminated comment");
+ RESET_POSITION;
}
}
-"//"[^\r\n]* { /* skip */ }
+"//"[^\r\n]* { /* skip - the newline will reset the position */ }
-<<EOF>> { return TOKEN_NONE; }
+<<EOF>> {
+ /* wtf? no user action on EOF? */
+ YY_USER_ACTION;
+ return TOKEN_NONE;
+ }
-[ \t] { /* skip */ }
+[ \t] { RESET_POSITION; }
-\r\n { value->line_terminator = TRUE; }
-[\r\n] { value->line_terminator = TRUE; }
+[\r\n] { LINE_TERMINATOR; }
"{" { return TOKEN_BRACE_LEFT; }
"}" { return TOKEN_BRACE_RIGHT; }
@@ -233,6 +253,7 @@ identifier_part [$_a-zA-Z0-9]
BEGIN(INITIAL);
g_string_free (string, TRUE);
ERROR ("Unterminated string constant");
+ RESET_POSITION;
}
\\[0-7]{1,3} {
guint64 result;
@@ -273,7 +294,10 @@ identifier_part [$_a-zA-Z0-9]
return TOKEN_IDENTIFIER;
}
-. { ERROR ("Unknown character '%c'", yytext[0]); }
+. {
+ ERROR ("Unknown character '%c'", yytext[0]);
+ RESET_POSITION;
+ }
%%
commit 590f3b5e980539eb4236ebdcff94e9dfebdc7a69
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Apr 25 20:14:35 2008 +0200
change to use buffers
diff --git a/vivified/code/compiler.c b/vivified/code/compiler.c
index fd75ee8..fb396b3 100644
--- a/vivified/code/compiler.c
+++ b/vivified/code/compiler.c
@@ -30,9 +30,8 @@
int
main (int argc, char *argv[])
{
- SwfdecPlayer *player;
//char *target_name;
- FILE *source;//, *target;
+ SwfdecBuffer *source;
ViviCodeStatement *statement, *assembler;
ViviCodePrinter *printer;
/*ViviCodeCompiler *compiler;
@@ -40,27 +39,27 @@ main (int argc, char *argv[])
SwfdecBuffer *buffer;
unsigned char *length_ptr;
SwfdecRect rect = { 0, 0, 2000, 3000 };*/
+ GError *error = NULL;
- player = swfdec_player_new (NULL);
+ swfdec_init ();
if (argc != 2) {
g_printerr ("Usage: %s <filename>\n", argv[0]);
return 1;
}
- source = fopen (argv[1], "r");
+ source = swfdec_buffer_new_from_file (argv[1], &error);
if (source == NULL) {
- g_printerr ("Couldn't open source %s", argv[1]);
+ g_printerr ("Couldn't open: %s", error->message);
+ g_error_free (error);
return -1;
}
- statement = vivi_parse_file (source, argv[1]);
-
- fclose (source);
+ statement = vivi_parse_buffer (source);
+ swfdec_buffer_unref (source);
if (statement == NULL) {
g_printerr ("Compilation failed\n");
- g_object_unref (player);
return 1;
}
@@ -146,7 +145,6 @@ main (int argc, char *argv[])
#endif
g_object_unref (statement);
- g_object_unref (player);
return (statement == NULL ? -1 : 0);
}
diff --git a/vivified/code/vivi_parser.c b/vivified/code/vivi_parser.c
index 41c4218..8f0b638 100644
--- a/vivified/code/vivi_parser.c
+++ b/vivified/code/vivi_parser.c
@@ -2990,14 +2990,14 @@ parse_value_statement_list (ParseData *data, PeekFunction peek,
// public
ViviCodeStatement *
-vivi_parse_file (FILE *file, const char *input_name)
+vivi_parse_buffer (SwfdecBuffer *buffer)
{
ParseData data;
ViviCodeStatement *statement;
- g_return_val_if_fail (file != NULL, NULL);
+ g_return_val_if_fail (buffer != NULL, NULL);
- data.scanner = vivi_parser_scanner_new (file);
+ data.scanner = vivi_parser_scanner_new (buffer);
vivi_parser_scanner_set_error_handler (data.scanner,
vivi_parser_error_handler, &data);
data.levels = NULL;
diff --git a/vivified/code/vivi_parser.h b/vivified/code/vivi_parser.h
index 82cbe89..c73afa5 100644
--- a/vivified/code/vivi_parser.h
+++ b/vivified/code/vivi_parser.h
@@ -28,8 +28,7 @@
G_BEGIN_DECLS
-ViviCodeStatement * vivi_parse_file (FILE * file,
- const char * input_name);
+ViviCodeStatement * vivi_parse_buffer (SwfdecBuffer * buffer);
G_END_DECLS
diff --git a/vivified/code/vivi_parser_scanner.c b/vivified/code/vivi_parser_scanner.c
index a73b930..1873073 100644
--- a/vivified/code/vivi_parser_scanner.c
+++ b/vivified/code/vivi_parser_scanner.c
@@ -229,23 +229,15 @@ vivi_parser_scanner_advance (ViviParserScanner *scanner)
value = swfdec_ring_buffer_push (scanner->values);
}
- if (scanner->file == NULL) {
- value->token = TOKEN_NONE;
- value->column = 0;
- value->position = 0;
- value->line_number = 0;
- value->line_terminator = FALSE;
- } else {
- value->line_terminator = FALSE;
- value->position = 0; /* FIXME */
- value->token = vivi_parser_scanner_lex (scanner->scanner, value);
+ value->line_terminator = FALSE;
+ value->position = 0; /* FIXME */
+ value->token = vivi_parser_scanner_lex (scanner->scanner, value);
#if 0
- g_print ("%u:%u %c %s\n", value->line_number, value->column,
- value->line_terminator ? '+' : '-',
- vivi_parser_scanner_token_name (value->token));
+ g_print ("%u:%u %c %s\n", value->line_number, value->column,
+ value->line_terminator ? '+' : '-',
+ vivi_parser_scanner_token_name (value->token));
#endif
- value->line_number = vivi_parser_scanner_get_lineno (scanner->scanner);
- }
+ value->line_number = vivi_parser_scanner_get_lineno (scanner->scanner);
}
const ViviParserValue *
@@ -260,17 +252,17 @@ vivi_parser_scanner_get_value (ViviParserScanner *scanner, guint i)
}
ViviParserScanner *
-vivi_parser_scanner_new (FILE *file)
+vivi_parser_scanner_new (SwfdecBuffer *buffer)
{
ViviParserScanner *scanner;
ViviParserValue *value;
- g_return_val_if_fail (file != NULL, NULL);
+ g_return_val_if_fail (buffer != NULL, NULL);
scanner = g_object_new (VIVI_TYPE_PARSER_SCANNER, NULL);
- scanner->file = file;
- vivi_parser_scanner_restart (file, scanner->scanner);
+ vivi_parser_scanner__scan_bytes ((char *) buffer->data, buffer->length, scanner->scanner);
+
value = swfdec_ring_buffer_push (scanner->values);
value->token = TOKEN_UNKNOWN;
value->line_number = value->column = 0;
diff --git a/vivified/code/vivi_parser_scanner.h b/vivified/code/vivi_parser_scanner.h
index cc39a65..7fd90d9 100644
--- a/vivified/code/vivi_parser_scanner.h
+++ b/vivified/code/vivi_parser_scanner.h
@@ -176,8 +176,6 @@ struct _ViviParserScanner
{
GObject object;
- FILE * file;
-
ViviParserScannerFunction error_handler;
gpointer error_handler_data;
@@ -192,7 +190,7 @@ struct _ViviParserScannerClass
GType vivi_parser_scanner_get_type (void);
-ViviParserScanner * vivi_parser_scanner_new (FILE * file);
+ViviParserScanner * vivi_parser_scanner_new (SwfdecBuffer * buffer);
void vivi_parser_scanner_set_error_handler (ViviParserScanner * scanner,
ViviParserScannerFunction error_handler,
gpointer user_data);
More information about the Swfdec-commits
mailing list