1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /* Error handling
24  * This package defines a set of macros that allows code to raise and
25  * handle exceptions.A macro is provided which signals an error, which
26  * does a non - local goto to the innermost enclosing exception handler.
27  * A set of macros sets up exception handling code.
28  *
29  * To catch exceptions that occur inside a block of code(i.e., in the
30  * code or in any subroutines called by the code), begin the block with
31  * ERRBEGIN.At the end of the protected code, place the exception
32  * handler, which starts with ERRCATCH.At the end of the exception
33  * handler, place ERREND.If no exception occurs, execution goes
34  * through the protected code, then resumes at the code following
35  * the ERREND.
36  *
37  * The exception handler can signal another error, which will cause
38  * the next enclosing frame to catch the error.Alternatively, if
39  * the exception handler doesn't signal an error or return, execution
40  * continues at the code following the ERREND.Exceptions that are
41  * signalled during exception handling will be caught by the next
42  * enclosing frame, unless the exception handler code is itself
43  * protected by another ERRBEGIN - ERREND block.
44  *
45  * To signal an error, use errsig().
46  *
47  * To use a string argument in a signalled error, cover the string
48  * with errstr(ctx, str, len); for example:
49  *
50  * errsig1(ctx, ERR_XYZ, ERRTSTR, errstr(ctx, buf, strlen(buf)));
51  *
52  * This copies the string into a buffer that is unaffected by
53  * stack resetting during error signalling.
54  */
55 
56 #ifndef GLK_TADS_TADS2_ERROR
57 #define GLK_TADS_TADS2_ERROR
58 
59 #include "glk/tads/tads2/lib.h"
60 
61 namespace Glk {
62 namespace TADS {
63 namespace TADS2 {
64 
65 /*
66  *   for compatility with old facility-free mechanism, signal with
67  *   facility "TADS"
68  */
69 #define errsig(ctx, err) errsigf(ctx, "TADS", err)
70 #define errsig1(c, e, t, a) errsigf1(c,"TADS",e,t,a)
71 #define errsig2(c, e, t1, a1, t2, a2) errsigf2(c,"TADS",e,t1,a1,t2,a2)
72 #define errlog(c, e) errlogf(c, "TADS", e)
73 #define errlog1(c, e, t, a) errlogf1(c,"TADS",e,t,a)
74 #define errlog2(c, e, t1, a1, t2, a2) errlogf2(c,"TADS",e,t1,a1,t2,a2)
75 
76 
77 
78 /*---------------------------- TADS Error Codes ----------------------------*/
79 /* memory/cache manager errors */
80 #define ERR_NOMEM   1                                      /* out of memory */
81 #define ERR_FSEEK   2                              /* error seeking in file */
82 #define ERR_FREAD   3                            /* error reading from file */
83 #define ERR_NOPAGE  4                                 /* no more page slots */
84 #define ERR_REALCK  5           /* attempting to reallocate a locked object */
85 #define ERR_SWAPBIG 6     /* swapfile limit reached - out of virtual memory */
86 #define ERR_FWRITE  7                                 /* error writing file */
87 #define ERR_SWAPPG  8                     /* exceeded swap page table limit */
88 #define ERR_CLIUSE  9      /* requested client object number already in use */
89 #define ERR_CLIFULL 10                      /* client mapping table is full */
90 #define ERR_NOMEM1  11   /* swapping/garbage collection failed to find enuf */
91 #define ERR_NOMEM2  12            /* no memory to resize (expand) an object */
92 #define ERR_OPSWAP  13                          /* unable to open swap file */
93 #define ERR_NOHDR   14                     /* can't get a new object header */
94 #define ERR_NOLOAD  15   /* mcm cannot find object to load (internal error) */
95 #define ERR_LCKFRE  16     /* attempting to free a locked object (internal) */
96 #define ERR_INVOBJ  17                                    /* invalid object */
97 #define ERR_BIGOBJ  18  /* object too big - exceeds memory allocation limit */
98 
99 /* lexical analysis errors */
100 #define ERR_INVTOK  100                                    /* invalid token */
101 #define ERR_STREOF  101                /* end of file while scanning string */
102 #define ERR_TRUNC   102                      /* symbol too long - truncated */
103 #define ERR_NOLCLSY 103                   /* no space in local symbol table */
104 #define ERR_PRPDIR  104               /* invalid preprocessor (#) directive */
105 #define ERR_INCNOFN 105                /* no filename in #include directive */
106 #define ERR_INCSYN  106                          /* invalid #include syntax */
107 #define ERR_INCSEAR 107                         /* can't find included file */
108 #define ERR_INCMTCH 108       /* no matching delimiter in #include filename */
109 #define ERR_MANYSYM 109                    /* out of space for symbol table */
110 #define ERR_LONGLIN 110                                    /* line too long */
111 #define ERR_INCRPT  111           /* header file already included - ignored */
112 #define ERR_PRAGMA  112                         /* unknown pragma (ignored) */
113 #define ERR_BADPELSE 113                                /* unexpected #else */
114 #define ERR_BADENDIF 114                               /* unexpected #endif */
115 #define ERR_BADELIF 115                                 /* unexpected #elif */
116 #define ERR_MANYPIF 116                             /* #if nesting too deep */
117 #define ERR_DEFREDEF  117                 /* #define symbol already defined */
118 #define ERR_PUNDEF  118                        /* #undef symbol not defined */
119 #define ERR_NOENDIF 119                                   /* missing #endif */
120 #define ERR_MACNEST 120                         /* macros nested too deeply */
121 #define ERR_BADISDEF 121         /* invalid argument for defined() operator */
122 #define ERR_PIF_NA  122                           /* #if is not implemented */
123 #define ERR_PELIF_NA 123                        /* #elif is not implemented */
124 #define ERR_P_ERROR 124                              /* error directive: %s */
125 #define ERR_LONG_FILE_MACRO 125              /* __FILE__ expansion too long */
126 #define ERR_LONG_LINE_MACRO 126              /* __LINE__ expansion too long */
127 
128 /* undo errors */
129 #define ERR_UNDOVF  200                /* operation is too big for undo log */
130 #define ERR_NOUNDO  201                         /* no more undo information */
131 #define ERR_ICUNDO  202          /* incomplete undo (no previous savepoint) */
132 
133 /* parser errors */
134 #define ERR_REQTOK  300    /* expected token (arg 1) - found something else */
135 #define ERR_REQSYM  301                                  /* expected symbol */
136 #define ERR_REQPRP  302                         /* expected a property name */
137 #define ERR_REQOPN  303                                 /* expected operand */
138 #define ERR_REQARG  304       /* expected comma or closing paren (arg list) */
139 #define ERR_NONODE  305                      /* no space for new parse node */
140 #define ERR_REQOBJ  306                             /* epxected object name */
141 #define ERR_REQEXT  307           /* redefining symbol as external function */
142 #define ERR_REQFCN  308                    /* redefining symbol as function */
143 #define ERR_NOCLASS 309  /* can't use CLASS with function/external function */
144 #define ERR_REQUNO  310                          /* required unary operator */
145 #define ERR_REQBIN  311                         /* required binary operator */
146 #define ERR_INVBIN  312                          /* invalid binary operator */
147 #define ERR_INVASI  313                               /* invalid assignment */
148 #define ERR_REQVAR  314                           /* required variable name */
149 #define ERR_LCLSYN  315        /* required comma or semicolon in local list */
150 #define ERR_REQRBR  316   /* required right brace (eof before end of group) */
151 #define ERR_BADBRK  317                          /* 'break' without 'while' */
152 #define ERR_BADCNT  318                       /* 'continue' without 'while' */
153 #define ERR_BADELS  319                              /* 'else' without 'if' */
154 #define ERR_WEQASI  320 /* warning: possible use of '=' where ':=' intended */
155 #define ERR_EOF     321                           /* unexpected end of file */
156 #define ERR_SYNTAX  322                             /* general syntax error */
157 #define ERR_INVOP   323                             /* invalid operand type */
158 #define ERR_NOMEMLC 324             /* no memory for new local symbol table */
159 #define ERR_NOMEMAR 325              /* no memory for argument symbol table */
160 #define ERR_FREDEF  326   /* redefining a function which is already defined */
161 #define ERR_NOSW    327      /* 'case' or 'default' and not in switch block */
162 #define ERR_SWRQCN  328           /* constant required in switch case value */
163 #define ERR_REQLBL  329                        /* label required for 'goto' */
164 #define ERR_NOGOTO  330                       /* 'goto' label never defined */
165 #define ERR_MANYSC  331                 /* too many superclasses for object */
166 #define ERR_OREDEF  332                      /* redefining symbol as object */
167 #define ERR_PREDEF  333               /* property being redefined in object */
168 #define ERR_BADPVL  334                           /* invalid property value */
169 #define ERR_BADVOC  335                    /* bad vocabulary property value */
170 #define ERR_BADTPL  336       /* bad template property value (need sstring) */
171 #define ERR_LONGTPL 337             /* template base property name too long */
172 #define ERR_MANYTPL 338     /* too many templates (internal compiler limit) */
173 #define ERR_BADCMPD 339   /* bad value for compound word (sstring required) */
174 #define ERR_BADFMT  340     /* bad value for format string (sstring needed) */
175 #define ERR_BADSYN  341     /* invalid value for synonym (sstring required) */
176 #define ERR_UNDFSYM 342                                 /* undefined symbol */
177 #define ERR_BADSPEC 343                                 /* bad special word */
178 #define ERR_NOSELF  344                 /* "self" not valid in this context */
179 #define ERR_STREND  345            /* warning: possible unterminated string */
180 #define ERR_MODRPLX 346    /* modify/replace not allowed with external func */
181 #define ERR_MODFCN  347                 /* modify not allowed with function */
182 #define ERR_MODFWD  348     /* modify/replace not allowed with forward func */
183 #define ERR_MODOBJ  349    /* modify can only be used with a defined object */
184 #define ERR_RPLSPEC 350                 /* warning - replacing specialWords */
185 #define ERR_SPECNIL 351        /* nil only allowed with modify specialWords */
186 #define ERR_BADLCL  353   /* 'local' statement must precede executable code */
187 #define ERR_IMPPROP 354          /* implied verifier '%s' is not a property */
188 #define ERR_BADTPLF 355                    /* invalid command template flag */
189 #define ERR_NOTPLFLG 356      /* flags are not allowed with old file format */
190 #define ERR_AMBIGBIN 357          /* warning: operator '%s' could be binary */
191 #define ERR_PIA     358           /* warning: possibly incorrect assignment */
192 #define ERR_BADSPECEXPR 359               /* invalid speculation evaluation */
193 
194 /* code generation errors */
195 #define ERR_OBJOVF  400     /* object cannot grow any bigger - code too big */
196 #define ERR_NOLBL   401                  /* no more temporary labels/fixups */
197 #define ERR_LBNOSET 402                 /* (internal error) label never set */
198 #define ERR_INVLSTE 403                /* invalid datatype for list element */
199 #define ERR_MANYDBG 404  /* too many debugger line records (internal limit) */
200 
201 /* vocabulary setup errors */
202 #define ERR_VOCINUS 450            /* vocabulary being redefined for object */
203 #define ERR_VOCMNPG 451          /* too many vocwdef pages (internal limit) */
204 #define ERR_VOCREVB 452                             /* redefining same verb */
205 #define ERR_VOCREVB2 453            /* redefining same verb - two arguments */
206 
207 /* set-up errors */
208 #define ERR_LOCNOBJ 500           /* location of object %s is not an object */
209 #define ERR_CNTNLST 501                /* contents of object %s is not list */
210 #define ERR_SUPOVF  502           /* overflow trying to build contents list */
211 #define ERR_RQOBJNF 503                     /* required object %s not found */
212 #define ERR_WRNONF  504                    /* warning - object %s not found */
213 #define ERR_MANYBIF 505     /* too many built-in functions (internal error) */
214 
215 /* fio errors */
216 #define ERR_OPWGAM  600                  /* unable to open game for writing */
217 #define ERR_WRTGAM  601                       /* error writing to game file */
218 #define ERR_FIOMSC  602              /* too many sc's for writing in fiowrt */
219 #define ERR_UNDEFF  603                               /* undefined function */
220 #define ERR_UNDEFO  604                                 /* undefined object */
221 #define ERR_UNDEF   605                          /* undefined symbols found */
222 #define ERR_OPRGAM  606                  /* unable to open game for reading */
223 #define ERR_RDGAM   607                          /* error reading game file */
224 #define ERR_BADHDR  608     /* file has invalid header - not TADS game file */
225 #define ERR_UNKRSC  609               /* unknown resource type in .gam file */
226 #define ERR_UNKOTYP 610              /* unknown object type in OBJ resource */
227 #define ERR_BADVSN  611     /* file saved by different incompatible version */
228 #define ERR_LDGAM   612                   /* error loading object on demand */
229 #define ERR_LDBIG   613  /* object too big for load region (prob. internal) */
230 #define ERR_UNXEXT  614                 /* did not expect external function */
231 #define ERR_WRTVSN  615      /* compiler cannot write the requested version */
232 #define ERR_VNOCTAB 616         /* format version cannot be used with -ctab */
233 #define ERR_BADHDRRSC 617        /* invalid resource file header in file %s */
234 #define ERR_RDRSC   618                /* error reading resource file "xxx" */
235 
236 /* character mapping errors */
237 #define ERR_CHRNOFILE 700          /* unable to load character mapping file */
238 
239 /* user interrupt */
240 #define ERR_USRINT  990       /* user requested cancel of current operation */
241 
242 /* run-time errors */
243 #define ERR_STKOVF  1001                                  /* stack overflow */
244 #define ERR_HPOVF   1002                                   /* heap overflow */
245 #define ERR_REQNUM  1003                          /* numeric value required */
246 #define ERR_STKUND  1004                                 /* stack underflow */
247 #define ERR_REQLOG  1005                          /* logical value required */
248 #define ERR_INVCMP  1006      /* invalid datatypes for magnitude comparison */
249 #define ERR_REQSTR  1007                           /* string value required */
250 #define ERR_INVADD  1008              /* invalid datatypes for '+' operator */
251 #define ERR_INVSUB  1009       /* invalid datatypes for binary '-' operator */
252 #define ERR_REQVOB  1010                            /* require object value */
253 #define ERR_REQVFN  1011                       /* required function pointer */
254 #define ERR_REQVPR  1012                  /* required property number value */
255 
256 /* non-error conditions:  run-time EXIT, ABORT, ASKIO, ASKDO */
257 #define ERR_RUNEXIT 1013                       /* 'exit' statement executed */
258 #define ERR_RUNABRT 1014                      /* 'abort' statement executed */
259 #define ERR_RUNASKD 1015                      /* 'askdo' statement executed */
260 #define ERR_RUNASKI 1016             /* 'askio' executed; int arg 1 is prep */
261 #define ERR_RUNQUIT 1017                                 /* 'quit' executed */
262 #define ERR_RUNRESTART 1018                             /* 'reset' executed */
263 #define ERR_RUNEXITOBJ 1019                           /* 'exitobj' executed */
264 
265 #define ERR_REQVLS  1020                             /* list value required */
266 #define ERR_LOWINX  1021              /* index value too low (must be >= 1) */
267 #define ERR_HIGHINX 1022  /* index value too high (must be <= length(list)) */
268 #define ERR_INVTBIF 1023              /* invalid type for built-in function */
269 #define ERR_INVVBIF 1024             /* invalid value for built-in function */
270 #define ERR_BIFARGC 1025           /* wrong number of arguments to built-in */
271 #define ERR_ARGC    1026      /* wrong number of arguments to user function */
272 #define ERR_FUSEVAL 1027     /* string/list not allowed for fuse/daemon arg */
273 #define ERR_BADSETF 1028      /* internal error in setfuse/setdaemon/notify */
274 #define ERR_MANYFUS 1029                                  /* too many fuses */
275 #define ERR_MANYDMN 1030                                /* too many daemons */
276 #define ERR_MANYNFY 1031                              /* too many notifiers */
277 #define ERR_NOFUSE  1032                       /* fuse not found in remfuse */
278 #define ERR_NODMN   1033                   /* daemon not found in remdaemon */
279 #define ERR_NONFY   1034                  /* notifier not found in unnotify */
280 #define ERR_BADREMF 1035    /* internal error in remfuse/remdaemon/unnotify */
281 #define ERR_DMDLOOP 1036     /* load-on-demand loop: property not being set */
282 #define ERR_UNDFOBJ 1037             /* undefined object in vocabulary tree */
283 #define ERR_BIFCSTR 1038            /* c-string conversion overflows buffer */
284 #define ERR_INVOPC  1039                                  /* invalid opcode */
285 #define ERR_RUNNOBJ 1040     /* runtime error: property taken of non-object */
286 #define ERR_EXTLOAD 1041           /* unable to load external function "%s" */
287 #define ERR_EXTRUN  1042          /* error executing external function "%s" */
288 #define ERR_CIRCSYN 1043                                /* circular synonym */
289 #define ERR_DIVZERO 1044                                  /* divide by zero */
290 #define ERR_BADDEL  1045      /* can only delete objects created with "new" */
291 #define ERR_BADNEWSC 1046    /* superclass for "new" cannot be a new object */
292 #define ERR_VOCSTK  1047              /* insufficient space in parser stack */
293 #define ERR_BADFILE 1048                             /* invalid file handle */
294 
295 #define ERR_RUNEXITPRECMD 1049                    /* exited from preCommand */
296 
297 /* run-time parser errors */
298 #define ERR_PRS_SENT_UNK  1200         /* sentence structure not recognized */
299 #define ERR_PRS_VERDO_FAIL 1201                         /* verDoVerb failed */
300 #define ERR_PRS_VERIO_FAIL 1202                         /* verIoVerb failed */
301 #define ERR_PRS_NO_VERDO  1203            /* no verDoVerb for direct object */
302 #define ERR_PRS_NO_VERIO  1204            /* no verIoVerb for direct object */
303 #define ERR_PRS_VAL_DO_FAIL  1205        /* direct object validation failed */
304 #define ERR_PRS_VAL_IO_FAIL  1206      /* indirect object validation failed */
305 
306 /* compiler/runtime/debugger driver errors */
307 #define ERR_USAGE   1500                                   /* invalid usage */
308 #define ERR_OPNINP  1501                        /* error opening input file */
309 #define ERR_NODBG   1502                 /* game not compiled for debugging */
310 #define ERR_ERRFIL  1503               /* unable to open error capture file */
311 #define ERR_PRSCXSIZ 1504              /* parse pool + local size too large */
312 #define ERR_STKSIZE 1505                            /* stack size too large */
313 #define ERR_OPNSTRFIL 1506             /* error opening string capture file */
314 #define ERR_INVCMAP 1507                      /* invalid character map file */
315 
316 /* debugger errors */
317 #define ERR_BPSYM   2000                 /* symbol not found for breakpoint */
318 #define ERR_BPPROP  2002             /* breakpoint symbol is not a property */
319 #define ERR_BPFUNC  2003             /* breakpoint symbol is not a function */
320 #define ERR_BPNOPRP 2004              /* property is not defined for object */
321 #define ERR_BPPRPNC 2005                            /* property is not code */
322 #define ERR_BPSET   2006         /* breakpoint already set at this location */
323 #define ERR_BPNOTLN 2007     /* breakpoint is not at a line (OPCLINE instr) */
324 #define ERR_MANYBP  2008                            /* too many breakpoints */
325 #define ERR_BPNSET  2009            /* breakpoint to be deleted was not set */
326 #define ERR_DBGMNSY 2010  /* too many symbols in debug expression (int lim) */
327 #define ERR_NOSOURC 2011                   /* unable to find source file %s */
328 #define ERR_WTCHLCL 2012        /* illegal to assign to local in watch expr */
329 #define ERR_INACTFR 2013 /* inactive frame (expression value not available) */
330 #define ERR_MANYWX  2014                      /* too many watch expressions */
331 #define ERR_WXNSET  2015                              /* watchpoint not set */
332 #define ERR_EXTRTXT 2016               /* extraneous text at end of command */
333 #define ERR_BPOBJ   2017              /* breakpoint symbol is not an object */
334 #define ERR_DBGINACT 2018                         /* debugger is not active */
335 #define ERR_BPINUSE 2019                      /* breakpoint is already used */
336 #define ERR_RTBADSPECEXPR 2020            /* invalid speculative expression */
337 #define ERR_NEEDLIN2 2021    /* -ds2 information not found - must recompile */
338 
339 /* usage error messages */
340 #define ERR_TCUS1   3000                          /* first tc usage message */
341 #define ERR_TCUSL   3024                           /* last tc usage message */
342 #define ERR_TCTGUS1 3030                         /* first tc toggle message */
343 #define ERR_TCTGUSL 3032
344 #define ERR_TCZUS1  3040            /* first tc -Z suboptions usage message */
345 #define ERR_TCZUSL  3041
346 #define ERR_TC1US1  3050            /* first tc -1 suboptions usage message */
347 #define ERR_TC1USL  3058
348 #define ERR_TCMUS1  3070            /* first tc -m suboptions usage message */
349 #define ERR_TCMUSL  3076
350 #define ERR_TCVUS1  3080                /* first -v suboption usage message */
351 #define ERR_TCVUSL  3082
352 #define ERR_TRUSPARM 3099
353 #define ERR_TRUS1   3100                          /* first tr usage message */
354 #define ERR_TRUSL   3117
355 #define ERR_TRUSFT1 3118                       /* first tr "footer" message */
356 #define ERR_TRUSFTL 3119                        /* last tr "footer" message */
357 #define ERR_TRSUS1  3150            /* first tr -s suboptions usage message */
358 #define ERR_TRSUSL  3157
359 #define ERR_TDBUSPARM 3199
360 #define ERR_TDBUS1  3200                         /* first tdb usage message */
361 #define ERR_TDBUSL  3214                          /* last tdb usage message */
362 
363 /* TR 16-bit MSDOS-specific usage messages */
364 #define ERR_TRUS_DOS_1 3300
365 #define ERR_TRUS_DOS_L 3300
366 
367 /* TR 32-bit MSDOS console mode usage messages */
368 #define ERR_TRUS_DOS32_1  3310
369 #define ERR_TRUS_DOS32_L  3312
370 
371 /* TADS/Graphic errors */
372 #define ERR_GNOFIL  4001                     /* can't find graphics file %s */
373 #define ERR_GNORM   4002                              /* can't find room %s */
374 #define ERR_GNOOBJ  4003                   /* can't find hot spot object %s */
375 #define ERR_GNOICN  4004                       /* can't find icon object %s */
376 
377 
378 /*
379  *   Special error flag - this is returned from execmd() when preparseCmd
380  *   returns a command list.  This indicates to voc1cmd that it should try
381  *   the command over again, using the words in the new list.
382  */
383 #define ERR_PREPRSCMDREDO  30000             /* preparseCmd returned a list */
384 #define ERR_PREPRSCMDCAN   30001    /* preparseCmd returned 'nil' to cancel */
385 
386 } // End of namespace TADS2
387 } // End of namespace TADS
388 } // End of namespace Glk
389 
390 #endif
391