summary refs log tree commit diff
path: root/src/input.h
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-01-05 22:42:32 +1100
committerHerbert Xu <herbert@gondor.apana.org.au>2015-01-05 22:58:52 +1100
commit51781428ead9a2142795764d0c42abfd9bb47171 (patch)
tree3a1109598708b81a945dbaa411cb575e22308fa2 /src/input.h
parentinput: Remove HETIO (diff)
downloaddash-51781428ead9a2142795764d0c42abfd9bb47171.tar.gz
dash-51781428ead9a2142795764d0c42abfd9bb47171.zip
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 <herbert@gondor.apana.org.au>
Diffstat (limited to 'src/input.h')
-rw-r--r--src/input.h33
1 files changed, 30 insertions, 3 deletions
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);