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
|
/* SCCS Id: @(#)macerrs.c 3.1 93/01/24 */
/* Copyright (c) Michael Hamel, 1991 */
/* NetHack may be freely redistributed. See license for details. */
#if defined(macintosh) && defined(__SC__) && !defined(__FAR_CODE__)
/* this needs to be resident always */
#pragma segment Main
#endif
#include "hack.h"
#include "macwin.h"
#if !TARGET_API_MAC_CARBON
#include <Dialogs.h>
#include <TextUtils.h>
#include <Resources.h>
#endif
void error(const char *format,...)
{
Str255 buf;
va_list ap;
va_start(ap, format);
vsprintf((char *)buf, format, ap);
va_end(ap);
C2P((char *)buf, buf);
ParamText(buf, (StringPtr)"", (StringPtr)"", (StringPtr)"");
Alert(128, (ModalFilterUPP) NULL);
ExitToShell();
}
#if 0 /* Remainder of file is obsolete and will be removed */
#define stackDepth 1
#define errAlertID 129
#define stdIOErrID 1999
static Str255 gActivities[stackDepth] = {""};
static short gTopactivity = 0;
void showerror(char * errdesc, const char * errcomment)
{
short itemHit;
Str255 paserr,
pascomment;
SetCursor(&qd.arrow);
if (errcomment == nil) errcomment = "";
C2P (errcomment, pascomment);
C2P (errdesc, paserr);
ParamText(paserr,pascomment,gActivities[gTopactivity],(StringPtr)"");
itemHit = Alert(errAlertID, (ModalFilterUPP)nil);
}
Boolean itworked(short errcode)
/* Return TRUE if it worked, do an error message and return false if it didn't. Error
strings for native C errors are in STR#1999, Mac errs in STR 2000-errcode, e.g
2108 for not enough memory */
{
if (errcode != 0) {
short itemHit;
Str255 errdesc;
StringHandle strh;
errdesc[0] = '\0';
if (errcode > 0) GetIndString(errdesc,stdIOErrID,errcode); /* STDIO file rres, etc */
else {
strh = GetString(2000-errcode);
if (strh != (StringHandle) nil) {
memcpy(errdesc,*strh,256);
ReleaseResource((Handle)strh);
}
}
if (errdesc[0] == '\0') { /* No description found, just give the number */
sprintf((char *)&errdesc[1],"a %d error occurred",errcode);
errdesc[0] = strlen((char*)&errdesc[1]);
}
SetCursor(&qd.arrow);
ParamText(errdesc,(StringPtr)"",gActivities[gTopactivity],(StringPtr)"");
itemHit = Alert(errAlertID, (ModalFilterUPP)nil);
}
return(errcode==0);
}
void mustwork(short errcode)
/* For cases where we can't recover from the error by any means */
{
if (itworked(errcode)) ;
else ExitToShell();
}
#if defined(USE_STDARG) || defined(USE_VARARGS)
# ifdef USE_STDARG
static void vprogerror(const char *line, va_list the_args);
# else
static void vprogerror();
# endif
/* Macro substitute for error() */
void error VA_DECL(const char *, line)
VA_START(line);
VA_INIT(line, char *);
vprogerror(line, VA_ARGS);
VA_END();
}
# ifdef USE_STDARG
static void
vprogerror(const char *line, va_list the_args) {
# else
static void
vprogerror(line, the_args) const char *line; va_list the_args; {
# endif
#else /* USE_STDARG | USE_VARARG */
void
error VA_DECL(const char *, line)
#endif
/* Do NOT use VA_START and VA_END in here... see above */
char pbuf[BUFSZ];
if(index(line, '%')) {
Vsprintf(pbuf,line,VA_ARGS);
line = pbuf;
}
showerror("of an internal error",line);
}
void attemptingto(char * activity)
/* Say what we are trying to do for subsequent error-handling: will appear as x in an
alert in the form "Could not x because y" */
{ C2P(activity,gActivities[gTopactivity]);
}
void comment(char *s, long n)
{
Str255 paserr;
short itemHit;
sprintf((char *)&paserr[1], "%s - %d",s,n);
paserr[0] = strlen ((char*)&paserr[1]);
ParamText(paserr,(StringPtr)"",(StringPtr)"",(StringPtr)"");
itemHit = Alert(128, (ModalFilterUPP)nil);
}
void pushattemptingto(char * activity)
/* Push a new description onto stack so we can pop later to previous state */
{
if (gTopactivity < stackDepth) {
gTopactivity++;
attemptingto(activity);
}
else error("activity stack overflow");
}
void popattempt(void)
/* Pop to previous state */
{
if (gTopactivity > 1) --gTopactivity;
else error("activity stack underflow");
}
#endif /* Obsolete */
|