From 51781428ead9a2142795764d0c42abfd9bb47171 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Mon, 5 Jan 2015 22:42:32 +1100 Subject: input: Move all input state into parsefile Currently we maintain a copy of the input state outside of parsefile. This is redundant and makes reentrancy difficult. This patch kills the duplicate global states and now everyone simply uses parsefile. Signed-off-by: Herbert Xu --- src/input.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/input.h') diff --git a/src/input.h b/src/input.h index 90ff6c3..ad8b463 100644 --- a/src/input.h +++ b/src/input.h @@ -41,14 +41,41 @@ enum { INPUT_NOFILE_OK = 2, }; +struct alias; + +struct strpush { + struct strpush *prev; /* preceding string on stack */ + char *prevstring; + int prevnleft; + struct alias *ap; /* if push was associated with an alias */ + char *string; /* remember the string since it may change */ +}; + +/* + * The parsefile structure pointed to by the global variable parsefile + * contains information about the current file being read. + */ + +struct parsefile { + struct parsefile *prev; /* preceding file on stack */ + int linno; /* current line */ + int fd; /* file descriptor (or -1 if string) */ + int nleft; /* number of chars left in this line */ + int lleft; /* number of chars left in this buffer */ + char *nextc; /* next char in buffer */ + char *buf; /* input buffer */ + struct strpush *strpush; /* for pushing strings at this level */ + struct strpush basestrpush; /* so pushing one is fast */ +}; + +extern struct parsefile *parsefile; + /* * The input line number. Input.c just defines this variable, and saves * and restores it when files are pushed and popped. The user of this * package must set its value. */ -extern int plinno; -extern int parsenleft; /* number of characters left in input buffer */ -extern char *parsenextc; /* next character in input buffer */ +#define plinno (parsefile->linno) int pgetc(void); int pgetc2(void); -- cgit 1.4.1