1 /* SCCS Id: @(#)macerrs.c 3.1 93/01/24 */
2 /* Copyright (c) Michael Hamel, 1991 */
3 /* NetHack may be freely redistributed. See license for details. */
5 #if defined(macintosh) && defined(__SC__) && !defined(__FAR_CODE__)
6 /* this needs to be resident always */
12 #if !TARGET_API_MAC_CARBON
14 #include <TextUtils.h>
15 #include <Resources.h>
19 void error(const char *format,...)
25 vsprintf((char *)buf, format, ap);
28 C2P((char *)buf, buf);
29 ParamText(buf, (StringPtr)"", (StringPtr)"", (StringPtr)"");
30 Alert(128, (ModalFilterUPP) NULL);
35 #if 0 /* Remainder of file is obsolete and will be removed */
38 #define errAlertID 129
39 #define stdIOErrID 1999
41 static Str255 gActivities[stackDepth] = {""};
42 static short gTopactivity = 0;
44 void showerror(char * errdesc, const char * errcomment)
51 if (errcomment == nil) errcomment = "";
52 C2P (errcomment, pascomment);
53 C2P (errdesc, paserr);
54 ParamText(paserr,pascomment,gActivities[gTopactivity],(StringPtr)"");
55 itemHit = Alert(errAlertID, (ModalFilterUPP)nil);
58 Boolean itworked(short errcode)
59 /* Return TRUE if it worked, do an error message and return false if it didn't. Error
60 strings for native C errors are in STR#1999, Mac errs in STR 2000-errcode, e.g
61 2108 for not enough memory */
70 if (errcode > 0) GetIndString(errdesc,stdIOErrID,errcode); /* STDIO file rres, etc */
72 strh = GetString(2000-errcode);
73 if (strh != (StringHandle) nil) {
74 memcpy(errdesc,*strh,256);
75 ReleaseResource((Handle)strh);
78 if (errdesc[0] == '\0') { /* No description found, just give the number */
79 sprintf((char *)&errdesc[1],"a %d error occurred",errcode);
80 errdesc[0] = strlen((char*)&errdesc[1]);
83 ParamText(errdesc,(StringPtr)"",gActivities[gTopactivity],(StringPtr)"");
84 itemHit = Alert(errAlertID, (ModalFilterUPP)nil);
89 void mustwork(short errcode)
90 /* For cases where we can't recover from the error by any means */
92 if (itworked(errcode)) ;
97 #if defined(USE_STDARG) || defined(USE_VARARGS)
99 static void vprogerror(const char *line, va_list the_args);
101 static void vprogerror();
104 /* Macro substitute for error() */
105 void error VA_DECL(const char *, line)
107 VA_INIT(line, char *);
108 vprogerror(line, VA_ARGS);
114 vprogerror(const char *line, va_list the_args) {
117 vprogerror(line, the_args) const char *line; va_list the_args; {
120 #else /* USE_STDARG | USE_VARARG */
123 error VA_DECL(const char *, line)
125 /* Do NOT use VA_START and VA_END in here... see above */
128 if(index(line, '%')) {
129 Vsprintf(pbuf,line,VA_ARGS);
132 showerror("of an internal error",line);
136 void attemptingto(char * activity)
137 /* Say what we are trying to do for subsequent error-handling: will appear as x in an
138 alert in the form "Could not x because y" */
139 { C2P(activity,gActivities[gTopactivity]);
142 void comment(char *s, long n)
147 sprintf((char *)&paserr[1], "%s - %d",s,n);
148 paserr[0] = strlen ((char*)&paserr[1]);
149 ParamText(paserr,(StringPtr)"",(StringPtr)"",(StringPtr)"");
150 itemHit = Alert(128, (ModalFilterUPP)nil);
153 void pushattemptingto(char * activity)
154 /* Push a new description onto stack so we can pop later to previous state */
156 if (gTopactivity < stackDepth) {
158 attemptingto(activity);
160 else error("activity stack overflow");
163 void popattempt(void)
164 /* Pop to previous state */
166 if (gTopactivity > 1) --gTopactivity;
167 else error("activity stack underflow");
170 #endif /* Obsolete */