1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/hterror}
\author{The Axiom Team}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{hterror.h}
<<hterror.h>>=
<<license>>
#define HTCONDNODE 1 /* unrecognized condition node */
#define KEYTYPE 2 /* unrecognized keyword found in lex.c */
#define Numerrors 2
#ifdef HTERROR
char *errmess[] = {
"place holder",
"parsing condition node",
"unrecognized keyword" };
#endif
@
\section{hterror.c}
<<hterror.c>>=
#define _HTERROR_C
#define HTERROR
#include "axiom-c-macros.h"
#include "useproto.h"
#include "debug.h"
#include "lex.h"
#include "parse.h"
#include "all_hyper_proto.H1"
char ebuffer[128];
jmp_buf jmpbuf;
/*
* This file is the error handling routine in AXIOM. The main routine is
* called htperror(): arguments: msg - like perror it accepts an error
* message to be printed errno - the errno which occurred. This is so an
* appropriate error message can be printed.
*
* The prints out the page name, and then the filename in which the error
* occurred. If possible it also tries to print out the next ten tokens.
*/
void
jump(void)
{
if (gWindow == NULL)
exit(-1);
longjmp(jmpbuf, 1);
fprintf(stderr, "(HyperDoc) Long Jump failed, Exiting\n");
exit(-1);
}
void
print_page_and_filename(void)
{
char obuff[128];
if (gPageBeingParsed->type == Normal) {
/*
* Now try to inform the user as close to possible where the error
* occurred
*/
sprintf(obuff, "(HyperDoc) While parsing %s on line %d\n\tin the file %s\n",
gPageBeingParsed->name, line_number,
gPageBeingParsed->filename);
}
else if (gPageBeingParsed->type == SpadGen) {
sprintf(obuff, "While parsing %s from the Spad socket\n",
gPageBeingParsed->name);
}
else if (gPageBeingParsed->type == Unixfd) {
sprintf(obuff, "While parsing %s from a Unixpipe\n",
gPageBeingParsed->name);
}
else {
/* Unknown page type */
sprintf(obuff, "While parsing %s\n", gPageBeingParsed->name);
}
fprintf(stderr, "%s", obuff);
}
void
print_next_ten_tokens(void)
{
int i;
int v;
fprintf(stderr, "Trying to print the next ten tokens\n");
for (i = 0; i < 10; i++) {
v = get_token();
if (v == EOF)
break;
print_token();
}
fprintf(stderr, "\n");
}
/* print out a token value */
void
print_token(void)
{
if (token.type == Word)
printf("%s ", token.id);
else {
token_name(token.type);
printf("\\%s ", ebuffer);
}
fflush(stdout);
}
void
token_name(int type)
{
if (type <= NumberUserTokens)
strcpy(ebuffer, token_table[type]);
else {
switch (type) {
case Lbrace:
strcpy(ebuffer, "{");
break;
case Rbrace:
strcpy(ebuffer, "}");
break;
case Macro:
strcpy(ebuffer, token.id);
break;
case Group:
strcpy(ebuffer, "{");
break;
case Pound:
strcpy(ebuffer, "#");
break;
case Lsquarebrace:
strcpy(ebuffer, "[");
break;
case Rsquarebrace:
strcpy(ebuffer, "]");
break;
case Punctuation:
strcpy(ebuffer, token.id);
break;
case Dash:
strcpy(ebuffer, token.id);
break;
case Verbatim:
strcpy(ebuffer, "\\begin{verbatim}");
break;
case Scroll:
strcpy(ebuffer, "\\begin{scroll}");
break;
case Dollar:
strcpy(ebuffer, "$");
break;
case Percent:
strcpy(ebuffer, "%");
break;
case Carrot:
strcpy(ebuffer, "^");
break;
case Underscore:
strcpy(ebuffer, "_");
break;
case Tilde:
strcpy(ebuffer, "~");
break;
case Cond:
sprintf(ebuffer, "\\%s", token.id);
break;
case Icorrection:
strcpy(ebuffer, "\\/");
break;
case Paste:
strcpy(ebuffer, "\\begin{paste}");
break;
case Patch:
strcpy(ebuffer, "\\begin{patch}");
break;
default:
sprintf(ebuffer, " %d ", type);
}
/*return 1;*/
}
}
void
htperror(char *msg, int errno)
{
char obuff[256];
/* The first thing I do is create the error message */
if (errno <= Numerrors) {
sprintf(obuff, "%s:%s\n", msg, errmess[errno]);
}
else {
sprintf(obuff, "%s:\n", msg);
fprintf(stderr, "Unknown error type %d\n", errno);
}
fprintf(stderr, "%s", obuff);
print_page_and_filename();
print_next_ten_tokens();
}
@
\section{License}
<<license>>=
/*
Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@
<<*>>=
<<license>>
<<hterror.c>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}
|