From b975c2652da201c9e84f4b817c18408814364f36 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Mon, 18 May 2015 14:43:10 +0200 Subject: [PATCH] read: Allow to unget up to 3 characters Some parsers need to unget more than one characters, so add support for this. X-Universal-CTags-Commit-ID: 956af0555d3a8ef33304c5ae6ed873f22b4e4284 --- tagmanager/ctags/read.c | 12 ++++++++---- tagmanager/ctags/read.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tagmanager/ctags/read.c b/tagmanager/ctags/read.c index 554c1e64..c29b3b9f 100644 --- a/tagmanager/ctags/read.c +++ b/tagmanager/ctags/read.c @@ -428,7 +428,12 @@ readnext: extern void fileUngetc (int c) { - File.ungetch = c; + const size_t len = sizeof File.ungetchBuf / sizeof File.ungetchBuf[0]; + + Assert (File.ungetchIdx < len); + /* we cannot rely on the assertion that might be disabled in non-debug mode */ + if (File.ungetchIdx < len) + File.ungetchBuf[File.ungetchIdx++] = c; } static vString *iFileGetLine (void) @@ -468,10 +473,9 @@ extern int fileGetc (void) * other processing on it, though, because we already did that the * first time it was read through fileGetc (). */ - if (File.ungetch != '\0') + if (File.ungetchIdx > 0) { - c = File.ungetch; - File.ungetch = '\0'; + c = File.ungetchBuf[--File.ungetchIdx]; return c; /* return here to avoid re-calling debugPutc () */ } do diff --git a/tagmanager/ctags/read.h b/tagmanager/ctags/read.h index cbe4d79c..36976184 100644 --- a/tagmanager/ctags/read.h +++ b/tagmanager/ctags/read.h @@ -70,7 +70,8 @@ typedef struct sInputFile { MIO *mio; /* stream used for reading the file */ unsigned long lineNumber; /* line number in the input file */ MIOPos filePosition; /* file position of current line */ - int ungetch; /* a single character that was ungotten */ + unsigned int ungetchIdx; + int ungetchBuf[3]; /* characters that were ungotten */ boolean eof; /* have we reached the end of file? */ boolean newLine; /* will the next character begin a new line? */