From 9d1f1dbc7edbd39a3d3c962a4dc5e01bfa59bb8d Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 17 Jan 2012 14:53:34 +1000 Subject: Using eina string buffer for ignorable text. --- LuaSL/src/LuaSL_LSL_tree.h | 4 ++-- LuaSL/src/LuaSL_compile.c | 13 +++++++------ LuaSL/src/LuaSL_lexer.l | 15 ++------------- 3 files changed, 11 insertions(+), 21 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index e179295..fd9c65a 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -178,7 +178,7 @@ struct _LSL_Leaf LSL_Leaf *left; LSL_Leaf *right; LSL_Token *token; - char *ignorableText; + Eina_Strbuf *ignorableText; int line, column, len; opType basicType; union @@ -265,7 +265,7 @@ typedef struct FILE *file; LSL_Leaf *ast; LSL_Script script; - char *ignorableText; + Eina_Strbuf *ignorableText; LSL_Leaf *lval; int column, line; LSL_Block *currentBlock; diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 9ebda0f..277e278 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -203,7 +203,7 @@ void burnLeaf(LSL_Leaf *leaf) burnLeaf(leaf->left); burnLeaf(leaf->right); // TODO - Should free up the value to. - free(leaf->ignorableText); + eina_strbuf_free(leaf->ignorableText); free(leaf); } } @@ -447,9 +447,9 @@ LSL_Leaf *addVariable(LuaSL_compiler *compiler, LSL_Leaf *type, LSL_Leaf *identi } if (compiler->currentBlock) { - compiler->currentBlock->vcount++; - compiler->currentBlock->variables = realloc(compiler->currentBlock->variables, compiler->currentBlock->vcount * sizeof(LSL_Identifier *)); - compiler->currentBlock->variables[compiler->currentBlock->vcount - 1] = result; +// compiler->currentBlock->vcount++; +// compiler->currentBlock->variables = realloc(compiler->currentBlock->variables, compiler->currentBlock->vcount * sizeof(LSL_Identifier *)); +// compiler->currentBlock->variables[compiler->currentBlock->vcount - 1] = result; } else { @@ -784,7 +784,7 @@ static void outputLeaf(FILE *file, outputMode mode, LSL_Leaf *leaf) { outputLeaf(file, mode, leaf->left); if ((!(LSL_NOIGNORE & leaf->token->flags)) && (leaf->ignorableText)) - fprintf(file, "%s", leaf->ignorableText); + fwrite(eina_strbuf_string_get(leaf->ignorableText), 1, eina_strbuf_length_get(leaf->ignorableText), file); if (leaf->token->output) leaf->token->output(file, mode, leaf); else @@ -857,7 +857,7 @@ static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) { outputLeaf(file, mode, content->value.statementValue->expressions); if (content->ignorableText) - fprintf(file, "%s", content->ignorableText); + fwrite(eina_strbuf_string_get(content->ignorableText), 1, eina_strbuf_length_get(content->ignorableText), file); fprintf(file, "%s", content->token->token); } } @@ -947,6 +947,7 @@ Eina_Bool compileLSL(gameGlobals *game, char *script) memset(&compiler, 0, sizeof(LuaSL_compiler)); compiler.game = game; + compiler.ignorableText = eina_strbuf_new(); strncpy(compiler.fileName, script, PATH_MAX - 1); compiler.fileName[PATH_MAX - 1] = '\0'; diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index 9c90ed5..3270aff 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l @@ -136,21 +136,10 @@ int common(YYSTYPE *lval, char *text, int len, LuaSL_compiler *compiler, boolean if (checkIgnorable) { lval->ignorableText = compiler->ignorableText; - compiler->ignorableText = NULL; + compiler->ignorableText = eina_strbuf_new(); } else - { - if (compiler->ignorableText) - { - int lenI = strlen(compiler->ignorableText); - int lenT = strlen(text); - - compiler->ignorableText = realloc(compiler->ignorableText, lenI + lenT + 1); - sprintf(&(compiler->ignorableText[lenI]), "%s", text); - } - else - compiler->ignorableText = strdup(text); - } + eina_strbuf_append_length(compiler->ignorableText, text, len); return type; } -- cgit v1.1