Merge back to main trunk
diff --git a/Parser/acceler.c b/Parser/acceler.c
index 22df3cf..aee54ab 100644
--- a/Parser/acceler.c
+++ b/Parser/acceler.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -35,6 +35,7 @@
 
 #include "pgenheaders.h"
 #include "grammar.h"
+#include "node.h"
 #include "token.h"
 #include "parser.h"
 
@@ -104,7 +105,7 @@
 			for (ibit = 0; ibit < g->g_ll.ll_nlabels; ibit++) {
 				if (testbit(d1->d_first, ibit)) {
 #ifdef applec
-#define MPW_881_bug			/* Undefine if bug below is fixed */
+#define MPW_881_BUG			/* Undefine if bug below is fixed */
 #endif
 #ifdef MPW_881_BUG
 					/* In 881 mode MPW 3.1 has a code
diff --git a/Parser/bitset.c b/Parser/bitset.c
index e7249c8..84c268c 100644
--- a/Parser/bitset.c
+++ b/Parser/bitset.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/firstsets.c b/Parser/firstsets.c
index 3d1b3a7..57bdb96 100644
--- a/Parser/firstsets.c
+++ b/Parser/firstsets.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/grammar.c b/Parser/grammar.c
index 81b51de..1285fb3 100644
--- a/Parser/grammar.c
+++ b/Parser/grammar.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -203,7 +203,7 @@
 	
 	if (lb->lb_type == STRING) {
 		if (isalpha(lb->lb_str[1])) {
-			char *p, *strchr();
+			char *p;
 			if (debugging)
 				printf("Label %s is a keyword\n", lb->lb_str);
 			lb->lb_type = NAME;
diff --git a/Parser/grammar1.c b/Parser/grammar1.c
index 716f8b6..612f491 100644
--- a/Parser/grammar1.c
+++ b/Parser/grammar1.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/intrcheck.c b/Parser/intrcheck.c
index f5891ee..12cfe61 100644
--- a/Parser/intrcheck.c
+++ b/Parser/intrcheck.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -25,17 +25,66 @@
 /* Check for interrupts */
 
 #ifdef THINK_C
-/* This is for THINK C 4.0.
-   For 3.0, you may have to remove the signal stuff. */
 #include <MacHeaders>
 #define macintosh
 #endif
 
-#include "PROTO.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "myproto.h"
 #include "intrcheck.h"
 
 
-#ifdef MSDOS
+#ifdef QUICKWIN
+
+#include <io.h>
+
+void
+initintr()
+{
+}
+
+int
+intrcheck()
+{
+	_wyield();
+}
+
+#define OK
+
+#endif /* QUICKWIN */
+
+#ifdef _M_IX86
+#include <io.h>
+#endif
+
+#if defined(MSDOS) && !defined(QUICKWIN)
+
+#ifdef __GNUC__
+
+/* This is for DJGPP's GO32 extender.  I don't know how to trap
+ * control-C  (There's no API for ctrl-C, and I don't want to mess with
+ * the interrupt vectors.)  However, this DOES catch control-break.
+ * --Amrit
+ */
+
+#include <go32.h>
+
+void
+initintr()
+{
+	_go32_want_ctrl_break(1 /* TRUE */);
+}
+
+int
+intrcheck()
+{
+	return _go32_was_ctrl_break_hit();
+}
+
+#else /* !__GNUC__ */
 
 /* This might work for MS-DOS (untested though): */
 
@@ -55,9 +104,11 @@
 	return interrupted;
 }
 
+#endif /* __GNUC__ */
+
 #define OK
 
-#endif
+#endif /* MSDOS && !QUICKWIN */
 
 
 #ifdef macintosh
@@ -65,15 +116,14 @@
 #ifdef applec /* MPW */
 #include <OSEvents.h>
 #include <SysEqu.h>
-#endif
+#endif /* applec */
 
 #include <signal.h>
-#include "sigtype.h"
 
 static int interrupted;
 
-static SIGTYPE intcatcher PROTO((int));
-static SIGTYPE
+static RETSIGTYPE intcatcher PROTO((int));
+static RETSIGTYPE
 intcatcher(sig)
 	int sig;
 {
@@ -121,15 +171,19 @@
 /* Default version -- for real operating systems and for Standard C */
 
 #include <stdio.h>
+#include <string.h>
 #include <signal.h>
-#include "sigtype.h"
 
 static int interrupted;
 
 /* ARGSUSED */
-static SIGTYPE
+static RETSIGTYPE
+#ifdef _M_IX86
+intcatcher(int sig)	/* So the C compiler shuts up */
+#else /* _M_IX86 */
 intcatcher(sig)
 	int sig; /* Not used by required by interface */
+#endif /* _M_IX86 */
 {
 	extern void goaway PROTO((int));
 	static char message[] =
@@ -153,7 +207,7 @@
 {
 	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
 		signal(SIGINT, intcatcher);
-#ifdef SV_INTERRUPT
+#ifdef HAVE_SIGINTERRUPT
 	/* This is for SunOS and other modern BSD derivatives.
 	   It means that system calls (like read()) are not restarted
 	   after an interrupt.  This is necessary so interrupting a
@@ -161,7 +215,7 @@
 	   XXX On old BSD (pure 4.2 or older) you may have to do this
 	   differently! */
 	siginterrupt(SIGINT, 1);
-#endif
+#endif /* HAVE_SIGINTERRUPT */
 }
 
 int
diff --git a/Parser/listnode.c b/Parser/listnode.c
index d566e78..6d0eb45 100644
--- a/Parser/listnode.c
+++ b/Parser/listnode.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/metagrammar.c b/Parser/metagrammar.c
index c670555..5d0b5b3 100644
--- a/Parser/metagrammar.c
+++ b/Parser/metagrammar.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/node.c b/Parser/node.c
index 1362f8b..afeb99e 100644
--- a/Parser/node.c
+++ b/Parser/node.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/parser.c b/Parser/parser.c
index 8a85a32..9167a9d 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/parser.h b/Parser/parser.h
index b025a50..ed45d2e 100644
--- a/Parser/parser.h
+++ b/Parser/parser.h
@@ -5,7 +5,7 @@
 #endif
 
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -32,25 +32,25 @@
 
 #define MAXSTACK 500
 
-typedef struct _stackentry {
+typedef struct {
 	int		 s_state;	/* State in current DFA */
 	dfa		*s_dfa;		/* Current DFA */
 	struct _node	*s_parent;	/* Where to add next node */
 } stackentry;
 
-typedef struct _stack {
+typedef struct {
 	stackentry	*s_top;		/* Top entry */
 	stackentry	 s_base[MAXSTACK];/* Array of stack entries */
 					/* NB The stack grows down */
 } stack;
 
 typedef struct {
-	struct _stack	 p_stack;	/* Stack of parser states */
-	struct _grammar	*p_grammar;	/* Grammar to use */
-	struct _node	*p_tree;	/* Top of parse tree */
+	stack	 	p_stack;	/* Stack of parser states */
+	grammar		*p_grammar;	/* Grammar to use */
+	node		*p_tree;	/* Top of parse tree */
 } parser_state;
 
-parser_state *newparser PROTO((struct _grammar *g, int start));
+parser_state *newparser PROTO((grammar *g, int start));
 void delparser PROTO((parser_state *ps));
 int addtoken PROTO((parser_state *ps, int type, char *str, int lineno));
 void addaccelerators PROTO((grammar *g));
diff --git a/Parser/pgen.c b/Parser/pgen.c
index a1e03fe..0232a76 100644
--- a/Parser/pgen.c
+++ b/Parser/pgen.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/pgen.h b/Parser/pgen.h
index 872a3fa..d9d1d09 100644
--- a/Parser/pgen.h
+++ b/Parser/pgen.h
@@ -5,7 +5,7 @@
 #endif
 
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -30,8 +30,6 @@
 
 /* Parser generator interface */
 
-extern grammar gram;
-
 extern grammar *meta_grammar PROTO((void));
 
 struct _node;
diff --git a/Parser/pgenmain.c b/Parser/pgenmain.c
index 1b759d5..96a3b3c 100644
--- a/Parser/pgenmain.c
+++ b/Parser/pgenmain.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -32,6 +32,10 @@
    Error messages and status info during the generation process are
    written to stdout, or sometimes to stderr. */
 
+/* XXX TO DO:
+   - check for duplicate definitions of names (instead of fatal err)
+*/
+
 #include "pgenheaders.h"
 #include "grammar.h"
 #include "node.h"
@@ -42,7 +46,7 @@
 
 /* Forward */
 grammar *getgrammar PROTO((char *filename));
-#ifdef macintosh
+#ifdef THINK_C
 int main PROTO((int, char **));
 char *askfile PROTO((void));
 #endif
@@ -64,7 +68,7 @@
 	FILE *fp;
 	char *filename;
 	
-#ifdef macintosh
+#ifdef THINK_C
 	filename = askfile();
 #else
 	if (argc != 2) {
@@ -100,6 +104,7 @@
 	FILE *fp;
 	node *n;
 	grammar *g0, *g;
+	perrdetail err;
 	
 	fp = fopen(filename, "r");
 	if (fp == NULL) {
@@ -107,11 +112,27 @@
 		goaway(1);
 	}
 	g0 = meta_grammar();
-	n = NULL;
-	parsefile(fp, filename, g0, g0->g_start, (char *)NULL, (char *)NULL, &n);
+	n = parsefile(fp, filename, g0, g0->g_start,
+		      (char *)NULL, (char *)NULL, &err);
 	fclose(fp);
 	if (n == NULL) {
-		fprintf(stderr, "Parsing error.\n");
+		fprintf(stderr, "Parsing error %d, line %d.\n",
+			err.error, err.lineno);
+		if (err.text != NULL) {
+			int i;
+			fprintf(stderr, "%s", err.text);
+			i = strlen(err.text);
+			if (i == 0 || err.text[i-1] != '\n')
+				fprintf(stderr, "\n");
+			for (i = 0; i < err.offset; i++) {
+				if (err.text[i] == '\t')
+					putc('\t', stderr);
+				else
+					putc(' ', stderr);
+			}
+			fprintf(stderr, "^\n");
+			free(err.text);
+		}
 		goaway(1);
 	}
 	g = pgen(n);
@@ -122,7 +143,7 @@
 	return g;
 }
 
-#ifdef macintosh
+#ifdef THINK_C
 char *
 askfile()
 {
@@ -160,6 +181,25 @@
 }
 #endif
 
-/* XXX TO DO:
-   - check for duplicate definitions of names (instead of fatal err)
-*/
+/* No-nonsense my_readline() for tokenizer.c */
+
+char *
+my_readline(prompt)
+	char *prompt;
+{
+	int n = 1000;
+	char *p = malloc(n);
+	char *q;
+	if (p == NULL)
+		return NULL;
+	fprintf(stderr, "%s", prompt);
+	q = fgets(p, n, stdin);
+	if (q == NULL) {
+		*p = '\0';
+		return p;
+	}
+	n = strlen(p);
+	if (n > 0 && p[n-1] != '\n')
+		p[n-1] = '\n';
+	return realloc(p, n+1);
+}
diff --git a/Parser/printgrammar.c b/Parser/printgrammar.c
index 67a7f02..6699726 100644
--- a/Parser/printgrammar.c
+++ b/Parser/printgrammar.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h
index b5a71ca..edd0d19 100644
--- a/Parser/tokenizer.h
+++ b/Parser/tokenizer.h
@@ -5,7 +5,7 @@
 #endif
 
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -42,6 +42,7 @@
 	char *cur;	/* Next character in buffer */
 	char *inp;	/* End of data in buffer */
 	char *end;	/* End of input buffer if buf != NULL */
+	char *start;	/* Start of current token if not NULL */
 	int done;	/* E_OK normally, E_EOF at EOF, otherwise error code */
 	/* NB If done != E_OK, cur must be == inp!!! */
 	FILE *fp;	/* Rest of input; NULL if tokenizing a string */