1 /* aNetHack 0.0.1 macerrs.c $ANH-Date: 1432512797 2015/05/25 00:13:17 $ $ANH-Branch: master $:$ANH-Revision: 1.10 $ */
2 /* Copyright (c) Michael Hamel, 1991 */
3 /* aNetHack 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 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
);
34 #if 0 /* Remainder of file is obsolete and will be removed */
37 #define errAlertID 129
38 #define stdIOErrID 1999
40 static Str255 gActivities
[stackDepth
] = {""};
41 static short gTopactivity
= 0;
43 void showerror(char * errdesc
, const char * errcomment
)
50 if (errcomment
== nil
) errcomment
= "";
51 C2P (errcomment
, pascomment
);
52 C2P (errdesc
, paserr
);
53 ParamText(paserr
,pascomment
,gActivities
[gTopactivity
],(StringPtr
)"");
54 itemHit
= Alert(errAlertID
, (ModalFilterUPP
)nil
);
57 Boolean
itworked(short errcode
)
58 /* Return TRUE if it worked, do an error message and return false if it didn't. Error
59 strings for native C errors are in STR#1999, Mac errs in STR 2000-errcode, e.g
60 2108 for not enough memory */
69 if (errcode
> 0) GetIndString(errdesc
,stdIOErrID
,errcode
); /* STDIO file rres, etc */
71 strh
= GetString(2000-errcode
);
72 if (strh
!= (StringHandle
) nil
) {
73 memcpy(errdesc
,*strh
,256);
74 ReleaseResource((Handle
)strh
);
77 if (errdesc
[0] == '\0') { /* No description found, just give the number */
78 sprintf((char *)&errdesc
[1],"a %d error occurred",errcode
);
79 errdesc
[0] = strlen((char*)&errdesc
[1]);
82 ParamText(errdesc
,(StringPtr
)"",gActivities
[gTopactivity
],(StringPtr
)"");
83 itemHit
= Alert(errAlertID
, (ModalFilterUPP
)nil
);
88 void mustwork(short errcode
)
89 /* For cases where we can't recover from the error by any means */
91 if (itworked(errcode
)) ;
95 #if defined(USE_STDARG) || defined(USE_VARARGS)
97 static void vprogerror(const char *line
, va_list the_args
);
99 static void vprogerror();
102 /* Macro substitute for error() */
103 void error
VA_DECL(const char *, line
)
106 VA_INIT(line
, char *);
107 vprogerror(line
, VA_ARGS
);
113 vprogerror(const char *line
, va_list the_args
)
116 vprogerror(line
, the_args
) const char *line
; va_list the_args
;
119 #else /* USE_STDARG | USE_VARARG */
122 error
VA_DECL(const char *, line
)
124 { /* opening brace for vprogerror(), nested block for USE_OLDARG error() */
127 if(index(line
, '%')) {
128 Vsprintf(pbuf
,line
,VA_ARGS
);
131 showerror("of an internal error",line
);
133 #if !(defined(USE_STDARG) || defined(USE_VARARGS))
134 VA_END(); /* provides closing brace for USE_OLDARGS's nested block */
139 void attemptingto(char * activity
)
140 /* Say what we are trying to do for subsequent error-handling: will appear as x in an
141 alert in the form "Could not x because y" */
142 { C2P(activity
,gActivities
[gTopactivity
]);
145 void comment(char *s
, long n
)
150 sprintf((char *)&paserr
[1], "%s - %d",s
,n
);
151 paserr
[0] = strlen ((char*)&paserr
[1]);
152 ParamText(paserr
,(StringPtr
)"",(StringPtr
)"",(StringPtr
)"");
153 itemHit
= Alert(128, (ModalFilterUPP
)nil
);
156 void pushattemptingto(char * activity
)
157 /* Push a new description onto stack so we can pop later to previous state */
159 if (gTopactivity
< stackDepth
) {
161 attemptingto(activity
);
163 else error("activity stack overflow");
166 void popattempt(void)
167 /* Pop to previous state */
169 if (gTopactivity
> 1) --gTopactivity
;
170 else error("activity stack underflow");
173 #endif /* Obsolete */