summaryrefslogtreecommitdiff
path: root/src/block-parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/block-parser.c')
-rw-r--r--src/block-parser.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/block-parser.c b/src/block-parser.c
index ab679df..5c806cf 100644
--- a/src/block-parser.c
+++ b/src/block-parser.c
@@ -29,10 +29,6 @@
#include "replace-table.h"
-
-#define BUFFER_SIZE 65536 /* line cannot be longer than this */
-
-
struct BlockParser {
GHashTable *table;
GQueue *active_tree;
@@ -231,7 +227,7 @@ push_string (BlockParser *parser, const gchar *piece)
/* Actually push the string */
if (data) {
if (data->data)
- s = g_strdup_printf ("%s%s", data->data, piece);
+ s = g_strconcat (data->data, piece, NULL);
else
s = g_strdup (piece);
g_free (data->data);
@@ -239,7 +235,7 @@ push_string (BlockParser *parser, const gchar *piece)
data->used = FALSE;
}
else {
- s = g_strdup_printf ("%s%s", parser->current_line, piece);
+ s = g_strconcat (parser->current_line, piece, NULL);
g_free (parser->current_line);
parser->current_line = s;
}
@@ -288,7 +284,7 @@ in_block_retrieval (BlockParser *parser)
}
/*
- * block_parser_read_and_parse: reads input from the file and returns parsed line
+ * block_parser_process: parse input data
* - if there's a multiline block, string before the opening placeholder and
* string after closing placeholder are returned on one line,
* separated by "replace_key" placeholder as specified in registered blocks
@@ -298,10 +294,8 @@ in_block_retrieval (BlockParser *parser)
*
*/
gchar *
-block_parser_read_and_parse (BlockParser *parser, FILE *stream)
+block_parser_process (BlockParser *parser, const gchar *buffer)
{
- gchar *buffer;
- gchar *b;
gchar *token;
gchar *start, *end;
gchar *s;
@@ -314,21 +308,16 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream)
BlockParserFuncData *func_data;
g_return_val_if_fail (parser != NULL, NULL);
+ g_return_val_if_fail (buffer != NULL, NULL);
- buffer = g_malloc0 (BUFFER_SIZE);
- if (! fgets (buffer, BUFFER_SIZE, stream) || strlen (buffer) == 0) {
- g_free (buffer);
- return NULL;
- }
parser->current_line = g_strdup ("");
/* find tokens */
- b = buffer;
- while ((token = get_next_token (b, &start, &end, NULL))) {
+ while ((token = get_next_token (buffer, &start, &end, NULL))) {
handled = FALSE;
/* push the string before the token */
- s = g_strndup (b, start - b);
+ s = g_strndup (buffer, start - buffer);
push_string (parser, s);
g_free (s);
@@ -446,12 +435,11 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream)
}
g_free (token);
- b = end + 1;
+ buffer = end + 1;
}
/* push rest of the buffer till the end of the line */
- push_string (parser, b);
+ push_string (parser, buffer);
- g_free (buffer);
return parser->current_line;
}