summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-11-24 17:30:40 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-24 17:30:40 +0100
commit77694e40515b98b3d231dd4e0e19e80575539c58 (patch)
tree3f1052caa03409d2414d0a1d80f6c241ee1599a3
parentb0188aef0df9dc5d782ab576f62b5263a88259e3 (diff)
downloadeo_tokenizer-77694e40515b98b3d231dd4e0e19e80575539c58.zip
eo_tokenizer-77694e40515b98b3d231dd4e0e19e80575539c58.tar.gz
take care of saved token before buffer feed
-rw-r--r--eo_tokenizer.rl19
1 files changed, 16 insertions, 3 deletions
diff --git a/eo_tokenizer.rl b/eo_tokenizer.rl
index 6f45f05..a01ed32 100644
--- a/eo_tokenizer.rl
+++ b/eo_tokenizer.rl
@@ -124,6 +124,7 @@ eo_tokenizer_walk(Eo_Tokenizer *toknz, const char *source)
int done = 0;
int have = 0;
+ int offset = 0;
stream = fopen(toknz->source, "r");
if (!stream)
@@ -170,12 +171,24 @@ eo_tokenizer_walk(Eo_Tokenizer *toknz, const char *source)
have = 0;
else
{
- /* There is a prefix to preserve, shift it over. */
+ DBG("move data and pointers before buffer feed");
have = toknz->pe - toknz->ts;
- memmove( toknz->buf, toknz->ts, have);
- toknz->te = toknz->buf + (toknz->te - toknz->ts);
+ offset = toknz->ts - toknz->buf;
+ memmove(toknz->buf, toknz->ts, have);
+ toknz->te -= offset;
toknz->ts = toknz->buf;
}
+
+ if (toknz->saved.tok != NULL)
+ {
+ if ((have == 0) || ((toknz->saved.tok - offset) < toknz->buf))
+ {
+ WRN("reset lost saved token %p", toknz->saved.tok);
+ toknz->saved.tok = NULL;
+ }
+ else
+ toknz->saved.tok -= offset;
+ }
}
fclose(stream);