Reformat all C files.
I'll push a formatting guide at some point. There may still be outstanding changes, but please feel free to resolve those as you arrive a them. To the best of my knowledge, there is no changes to the actual code content, but the formatter does have the occasional bug. If you run into an issue, please fix it!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 dprintf.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 dprintf.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
|
||||
/* NetHack 3.6 dprintf.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.3 $ */
|
||||
/* SCCS Id: @(#)dprintf.c 3.5 1994/01/29 */
|
||||
/* Copyright (c) Jon W{tte, 1993. */
|
||||
@@ -8,42 +8,43 @@
|
||||
#include "macwin.h"
|
||||
|
||||
static Boolean
|
||||
KeyDown (unsigned short code) {
|
||||
unsigned char keys [16];
|
||||
KeyDown(unsigned short code)
|
||||
{
|
||||
unsigned char keys[16];
|
||||
|
||||
GetKeys ((void *) keys);
|
||||
return ((keys [code >> 3] >> (code & 7)) & 1) != 0;
|
||||
GetKeys((void *) keys);
|
||||
return ((keys[code >> 3] >> (code & 7)) & 1) != 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dprintf (char *format, ...)
|
||||
dprintf(char *format, ...)
|
||||
{
|
||||
char buffer [500];
|
||||
va_list list;
|
||||
int doit;
|
||||
char buffer[500];
|
||||
va_list list;
|
||||
int doit;
|
||||
#define DO_DEBUGSTR 1
|
||||
#define DO_PLINE 2
|
||||
|
||||
if (flags.debug) {
|
||||
doit = 0;
|
||||
if (macFlags.hasDebugger && KeyDown (0x39)) { /* Caps Lock */
|
||||
doit = DO_DEBUGSTR;
|
||||
} else if (KeyDown (0x3B) && iflags.window_inited && /* Control */
|
||||
(WIN_MESSAGE != -1) && theWindows [WIN_MESSAGE].its_window) {
|
||||
doit = DO_PLINE;
|
||||
}
|
||||
|
||||
if (doit) {
|
||||
va_start (list, format);
|
||||
vsprintf (&buffer [1], format, list);
|
||||
va_end (list) ;
|
||||
if (flags.debug) {
|
||||
doit = 0;
|
||||
if (macFlags.hasDebugger && KeyDown(0x39)) { /* Caps Lock */
|
||||
doit = DO_DEBUGSTR;
|
||||
} else if (KeyDown(0x3B) && iflags.window_inited && /* Control */
|
||||
(WIN_MESSAGE != -1)
|
||||
&& theWindows[WIN_MESSAGE].its_window) {
|
||||
doit = DO_PLINE;
|
||||
}
|
||||
|
||||
if (doit == DO_DEBUGSTR) {
|
||||
buffer [0] = strlen (&buffer [1]);
|
||||
DebugStr ((uchar *) buffer);
|
||||
} else if (doit == DO_PLINE)
|
||||
pline ("%s", &buffer [1]);
|
||||
}
|
||||
}
|
||||
if (doit) {
|
||||
va_start(list, format);
|
||||
vsprintf(&buffer[1], format, list);
|
||||
va_end(list);
|
||||
|
||||
if (doit == DO_DEBUGSTR) {
|
||||
buffer[0] = strlen(&buffer[1]);
|
||||
DebugStr((uchar *) buffer);
|
||||
} else if (doit == DO_PLINE)
|
||||
pline("%s", &buffer[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 maccurs.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 maccurs.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
|
||||
/* NetHack 3.6 maccurs.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.5 $ */
|
||||
/* SCCS Id: @(#)maccurs.c 3.5 1993/01/24 */
|
||||
/* Copyright (c) Jon W{tte, 1992. */
|
||||
@@ -14,212 +14,201 @@
|
||||
#include <Resources.h>
|
||||
#endif
|
||||
|
||||
|
||||
static Boolean winFileInit = 0;
|
||||
static unsigned char winFileName [32] = "\pNetHack Preferences";
|
||||
static unsigned char winFileName[32] = "\pNetHack Preferences";
|
||||
static long winFileDir;
|
||||
static short winFileVol;
|
||||
|
||||
typedef struct WinPosSave {
|
||||
char validPos;
|
||||
char validSize;
|
||||
short top;
|
||||
short left;
|
||||
short height;
|
||||
short width;
|
||||
char validPos;
|
||||
char validSize;
|
||||
short top;
|
||||
short left;
|
||||
short height;
|
||||
short width;
|
||||
} WinPosSave;
|
||||
|
||||
static WinPosSave savePos [kLastWindowKind + 1];
|
||||
|
||||
static WinPosSave savePos[kLastWindowKind + 1];
|
||||
|
||||
static void
|
||||
InitWinFile (void)
|
||||
InitWinFile(void)
|
||||
{
|
||||
StringHandle sh;
|
||||
long len;
|
||||
short ref = 0;
|
||||
StringHandle sh;
|
||||
long len;
|
||||
short ref = 0;
|
||||
|
||||
if (winFileInit) {
|
||||
return;
|
||||
}
|
||||
/* We trust the glue. If there's an error, store in game dir. */
|
||||
if (FindFolder (kOnSystemDisk, kPreferencesFolderType, kCreateFolder ,
|
||||
&winFileVol, &winFileDir)) {
|
||||
winFileVol = 0;
|
||||
winFileDir = 0;
|
||||
}
|
||||
sh = GetString (128);
|
||||
if (sh && *sh) {
|
||||
BlockMove (*sh, winFileName, **sh + 1);
|
||||
ReleaseResource ((Handle) sh);
|
||||
}
|
||||
if (HOpen (winFileVol, winFileDir, winFileName, fsRdPerm, &ref)) {
|
||||
return;
|
||||
}
|
||||
len = sizeof (savePos);
|
||||
if (!FSRead (ref, &len, savePos)) {
|
||||
winFileInit = 1;
|
||||
}
|
||||
FSClose (ref);
|
||||
if (winFileInit) {
|
||||
return;
|
||||
}
|
||||
/* We trust the glue. If there's an error, store in game dir. */
|
||||
if (FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
|
||||
&winFileVol, &winFileDir)) {
|
||||
winFileVol = 0;
|
||||
winFileDir = 0;
|
||||
}
|
||||
sh = GetString(128);
|
||||
if (sh && *sh) {
|
||||
BlockMove(*sh, winFileName, **sh + 1);
|
||||
ReleaseResource((Handle) sh);
|
||||
}
|
||||
if (HOpen(winFileVol, winFileDir, winFileName, fsRdPerm, &ref)) {
|
||||
return;
|
||||
}
|
||||
len = sizeof(savePos);
|
||||
if (!FSRead(ref, &len, savePos)) {
|
||||
winFileInit = 1;
|
||||
}
|
||||
FSClose(ref);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
FlushWinFile (void)
|
||||
FlushWinFile(void)
|
||||
{
|
||||
short ref;
|
||||
long len;
|
||||
short ref;
|
||||
long len;
|
||||
|
||||
if (!winFileInit) {
|
||||
if (!winFileName [0]) {
|
||||
return;
|
||||
}
|
||||
HCreate (winFileVol, winFileDir, winFileName, MAC_CREATOR, PREF_TYPE);
|
||||
HCreateResFile (winFileVol, winFileDir, winFileName);
|
||||
}
|
||||
if (HOpen (winFileVol, winFileDir, winFileName, fsWrPerm, &ref)) {
|
||||
return;
|
||||
}
|
||||
winFileInit = 1;
|
||||
len = sizeof (savePos);
|
||||
(void) FSWrite (ref, &len, savePos); /* Don't care about error */
|
||||
FSClose (ref);
|
||||
if (!winFileInit) {
|
||||
if (!winFileName[0]) {
|
||||
return;
|
||||
}
|
||||
HCreate(winFileVol, winFileDir, winFileName, MAC_CREATOR, PREF_TYPE);
|
||||
HCreateResFile(winFileVol, winFileDir, winFileName);
|
||||
}
|
||||
if (HOpen(winFileVol, winFileDir, winFileName, fsWrPerm, &ref)) {
|
||||
return;
|
||||
}
|
||||
winFileInit = 1;
|
||||
len = sizeof(savePos);
|
||||
(void) FSWrite(ref, &len, savePos); /* Don't care about error */
|
||||
FSClose(ref);
|
||||
}
|
||||
|
||||
Boolean
|
||||
RetrievePosition (short kind, short *top, short *left) {
|
||||
Point p;
|
||||
RetrievePosition(short kind, short *top, short *left)
|
||||
{
|
||||
Point p;
|
||||
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf ("Retrieve Bad kind %d", kind);
|
||||
return 0;
|
||||
}
|
||||
InitWinFile ();
|
||||
if (!savePos [kind].validPos) {
|
||||
dprintf ("Retrieve Not stored kind %d", kind);
|
||||
return 0;
|
||||
}
|
||||
p.v = savePos [kind].top;
|
||||
p.h = savePos [kind].left;
|
||||
*left = p.h;
|
||||
*top = p.v;
|
||||
dprintf ("Retrieve Kind %d Pt (%d,%d)", kind, p.h, p.v);
|
||||
return (PtInRgn (p, GetGrayRgn ()));
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf("Retrieve Bad kind %d", kind);
|
||||
return 0;
|
||||
}
|
||||
InitWinFile();
|
||||
if (!savePos[kind].validPos) {
|
||||
dprintf("Retrieve Not stored kind %d", kind);
|
||||
return 0;
|
||||
}
|
||||
p.v = savePos[kind].top;
|
||||
p.h = savePos[kind].left;
|
||||
*left = p.h;
|
||||
*top = p.v;
|
||||
dprintf("Retrieve Kind %d Pt (%d,%d)", kind, p.h, p.v);
|
||||
return (PtInRgn(p, GetGrayRgn()));
|
||||
}
|
||||
|
||||
|
||||
Boolean
|
||||
RetrieveSize (short kind, short top, short left, short *height, short *width)
|
||||
RetrieveSize(short kind, short top, short left, short *height, short *width)
|
||||
{
|
||||
Point p;
|
||||
Point p;
|
||||
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
return 0;
|
||||
}
|
||||
InitWinFile ();
|
||||
if (!savePos [kind].validSize) {
|
||||
return 0;
|
||||
}
|
||||
*width = savePos [kind].width;
|
||||
*height = savePos [kind].height;
|
||||
p.h = left + *width;
|
||||
p.v = top + *height;
|
||||
return PtInRgn (p, GetGrayRgn ());
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
return 0;
|
||||
}
|
||||
InitWinFile();
|
||||
if (!savePos[kind].validSize) {
|
||||
return 0;
|
||||
}
|
||||
*width = savePos[kind].width;
|
||||
*height = savePos[kind].height;
|
||||
p.h = left + *width;
|
||||
p.v = top + *height;
|
||||
return PtInRgn(p, GetGrayRgn());
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SavePosition (short kind, short top, short left)
|
||||
SavePosition(short kind, short top, short left)
|
||||
{
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf ("Save bad kind %d", kind);
|
||||
return;
|
||||
}
|
||||
InitWinFile();
|
||||
savePos[kind].validPos = 1;
|
||||
savePos[kind].top = top;
|
||||
savePos[kind].left = left;
|
||||
dprintf("Save kind %d pt (%d,%d)", kind, left, top);
|
||||
FlushWinFile();
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf("Save bad kind %d", kind);
|
||||
return;
|
||||
}
|
||||
InitWinFile();
|
||||
savePos[kind].validPos = 1;
|
||||
savePos[kind].top = top;
|
||||
savePos[kind].left = left;
|
||||
dprintf("Save kind %d pt (%d,%d)", kind, left, top);
|
||||
FlushWinFile();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SaveSize (short kind, short height, short width)
|
||||
SaveSize(short kind, short height, short width)
|
||||
{
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf ("Save bad kind %d", kind);
|
||||
return;
|
||||
}
|
||||
InitWinFile ();
|
||||
savePos [kind].validSize = 1;
|
||||
savePos [kind].width = width;
|
||||
savePos [kind].height = height;
|
||||
FlushWinFile ();
|
||||
if (kind < 0 || kind > kLastWindowKind) {
|
||||
dprintf("Save bad kind %d", kind);
|
||||
return;
|
||||
}
|
||||
InitWinFile();
|
||||
savePos[kind].validSize = 1;
|
||||
savePos[kind].width = width;
|
||||
savePos[kind].height = height;
|
||||
FlushWinFile();
|
||||
}
|
||||
|
||||
|
||||
static short
|
||||
GetWinKind (WindowPtr win)
|
||||
GetWinKind(WindowPtr win)
|
||||
{
|
||||
short kind;
|
||||
short kind;
|
||||
|
||||
if (!CheckNhWin (win)) {
|
||||
return -1;
|
||||
}
|
||||
kind = GetWindowKind(win) - WIN_BASE_KIND;
|
||||
if (kind < 0 || kind > NHW_TEXT) {
|
||||
return -1;
|
||||
}
|
||||
dprintf ("In win kind %d (%lx)", kind, win);
|
||||
switch (kind) {
|
||||
case NHW_MAP :
|
||||
case NHW_STATUS :
|
||||
case NHW_BASE :
|
||||
kind = kMapWindow;
|
||||
break;
|
||||
case NHW_MESSAGE :
|
||||
kind = kMessageWindow;
|
||||
break;
|
||||
case NHW_MENU :
|
||||
kind = kMenuWindow;
|
||||
break;
|
||||
default :
|
||||
kind = kTextWindow;
|
||||
break;
|
||||
}
|
||||
dprintf ("Out kind %d", kind);
|
||||
return kind;
|
||||
if (!CheckNhWin(win)) {
|
||||
return -1;
|
||||
}
|
||||
kind = GetWindowKind(win) - WIN_BASE_KIND;
|
||||
if (kind < 0 || kind > NHW_TEXT) {
|
||||
return -1;
|
||||
}
|
||||
dprintf("In win kind %d (%lx)", kind, win);
|
||||
switch (kind) {
|
||||
case NHW_MAP:
|
||||
case NHW_STATUS:
|
||||
case NHW_BASE:
|
||||
kind = kMapWindow;
|
||||
break;
|
||||
case NHW_MESSAGE:
|
||||
kind = kMessageWindow;
|
||||
break;
|
||||
case NHW_MENU:
|
||||
kind = kMenuWindow;
|
||||
break;
|
||||
default:
|
||||
kind = kTextWindow;
|
||||
break;
|
||||
}
|
||||
dprintf("Out kind %d", kind);
|
||||
return kind;
|
||||
}
|
||||
|
||||
|
||||
Boolean
|
||||
RetrieveWinPos(WindowPtr win, short *top, short *left)
|
||||
{
|
||||
return RetrievePosition(GetWinKind (win), top, left);
|
||||
return RetrievePosition(GetWinKind(win), top, left);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SaveWindowPos(WindowPtr win)
|
||||
{
|
||||
Rect r;
|
||||
Rect r;
|
||||
|
||||
|
||||
GetWindowBounds(win, kWindowContentRgn, &r);
|
||||
SavePosition(GetWinKind(win), r.top, r.left);
|
||||
GetWindowBounds(win, kWindowContentRgn, &r);
|
||||
SavePosition(GetWinKind(win), r.top, r.left);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SaveWindowSize(WindowPtr win)
|
||||
{
|
||||
short width, height;
|
||||
Rect r;
|
||||
short width, height;
|
||||
Rect r;
|
||||
|
||||
|
||||
GetWindowBounds(win, kWindowContentRgn, &r);
|
||||
width = r.right - r.left;
|
||||
height = r.bottom - r.top;
|
||||
SaveSize(GetWinKind (win), height, width);
|
||||
GetWindowBounds(win, kWindowContentRgn, &r);
|
||||
width = r.right - r.left;
|
||||
height = r.bottom - r.top;
|
||||
SaveSize(GetWinKind(win), height, width);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 macerrs.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 macerrs.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
|
||||
/* NetHack 3.6 macerrs.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.5 $ */
|
||||
/* SCCS Id: @(#)macerrs.c 3.5 1993/01/24 */
|
||||
/* Copyright (c) Michael Hamel, 1991 */
|
||||
@@ -17,26 +17,25 @@
|
||||
#include <Resources.h>
|
||||
#endif
|
||||
|
||||
|
||||
void error(const char *format,...)
|
||||
void
|
||||
error(const char *format, ...)
|
||||
{
|
||||
Str255 buf;
|
||||
va_list ap;
|
||||
Str255 buf;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vsprintf((char *)buf, format, ap);
|
||||
va_end(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();
|
||||
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 */
|
||||
|
||||
#if 0 /* Remainder of file is obsolete and will be removed */
|
||||
|
||||
#define stackDepth 1
|
||||
#define stackDepth 1
|
||||
#define errAlertID 129
|
||||
#define stdIOErrID 1999
|
||||
|
||||
@@ -95,34 +94,33 @@ void mustwork(short errcode)
|
||||
else ExitToShell();
|
||||
}
|
||||
|
||||
|
||||
#if defined(USE_STDARG) || defined(USE_VARARGS)
|
||||
# ifdef USE_STDARG
|
||||
#ifdef USE_STDARG
|
||||
static void vprogerror(const char *line, va_list the_args);
|
||||
# else
|
||||
#else
|
||||
static void vprogerror();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Macro substitute for error() */
|
||||
void error VA_DECL(const char *, line)
|
||||
void error VA_DECL(const char *, line){
|
||||
VA_START(line);
|
||||
VA_INIT(line, char *);
|
||||
vprogerror(line, VA_ARGS);
|
||||
VA_END();
|
||||
}
|
||||
|
||||
# ifdef USE_STDARG
|
||||
#ifdef USE_STDARG
|
||||
static void
|
||||
vprogerror(const char *line, va_list the_args) {
|
||||
# else
|
||||
#else
|
||||
static void
|
||||
vprogerror(line, the_args) const char *line; va_list the_args; {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#else /* USE_STDARG | USE_VARARG */
|
||||
#else /* USE_STDARG | USE_VARARG */
|
||||
|
||||
void
|
||||
error VA_DECL(const char *, line)
|
||||
error VA_DECL(const char *, line){
|
||||
#endif
|
||||
/* Do NOT use VA_START and VA_END in here... see above */
|
||||
char pbuf[BUFSZ];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 macfile.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 macfile.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
|
||||
/* NetHack 3.6 macfile.c $Date: 2009/05/06 10:49:10 $ $Revision: 1.7 $ */
|
||||
/* SCCS Id: @(#)macfile.c 3.5 1993/01/24 */
|
||||
/* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */
|
||||
@@ -27,201 +27,200 @@
|
||||
* the situation at startup... For now, this will have to do.
|
||||
*/
|
||||
|
||||
|
||||
/* The HandleFiles are resources built into the application which are treated
|
||||
as read-only files: if we fail to open a file we look for a resource */
|
||||
|
||||
#define FIRST_HF 32000 /* file ID of first HandleFile */
|
||||
#define MAX_HF 6 /* Max # of open HandleFiles */
|
||||
|
||||
#define APP_NAME_RES_ID (-16396)
|
||||
#define FIRST_HF 32000 /* file ID of first HandleFile */
|
||||
#define MAX_HF 6 /* Max # of open HandleFiles */
|
||||
|
||||
#define APP_NAME_RES_ID (-16396)
|
||||
|
||||
typedef struct handlefile {
|
||||
long type; /* Resource type */
|
||||
short id; /* Resource id */
|
||||
long mark; /* Current position */
|
||||
long size; /* total size */
|
||||
Handle data; /* The resource, purgeable */
|
||||
long type; /* Resource type */
|
||||
short id; /* Resource id */
|
||||
long mark; /* Current position */
|
||||
long size; /* total size */
|
||||
Handle data; /* The resource, purgeable */
|
||||
} HandleFile;
|
||||
|
||||
static HandleFile *FDECL(IsHandleFile,(int));
|
||||
static int FDECL(OpenHandleFile,(const unsigned char *, long));
|
||||
static int FDECL(CloseHandleFile,(int));
|
||||
static int FDECL(ReadHandleFile,(int, void *, unsigned));
|
||||
static long FDECL(SetHandleFilePos,(int, short, long));
|
||||
|
||||
HandleFile theHandleFiles [MAX_HF];
|
||||
MacDirs theDirs; /* also referenced in macwin.c */
|
||||
static HandleFile *FDECL(IsHandleFile, (int));
|
||||
static int FDECL(OpenHandleFile, (const unsigned char *, long));
|
||||
static int FDECL(CloseHandleFile, (int));
|
||||
static int FDECL(ReadHandleFile, (int, void *, unsigned));
|
||||
static long FDECL(SetHandleFilePos, (int, short, long));
|
||||
|
||||
HandleFile theHandleFiles[MAX_HF];
|
||||
MacDirs theDirs; /* also referenced in macwin.c */
|
||||
|
||||
static HandleFile *
|
||||
IsHandleFile(int fd)
|
||||
{
|
||||
HandleFile *hfp = NULL;
|
||||
HandleFile *hfp = NULL;
|
||||
|
||||
if (fd >= FIRST_HF && fd < FIRST_HF+MAX_HF) {
|
||||
/* in valid range, check for data */
|
||||
hfp = &theHandleFiles[fd-FIRST_HF];
|
||||
if (!hfp->data) hfp = NULL;
|
||||
}
|
||||
return hfp;
|
||||
if (fd >= FIRST_HF && fd < FIRST_HF + MAX_HF) {
|
||||
/* in valid range, check for data */
|
||||
hfp = &theHandleFiles[fd - FIRST_HF];
|
||||
if (!hfp->data)
|
||||
hfp = NULL;
|
||||
}
|
||||
return hfp;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
OpenHandleFile (const unsigned char *name, long fileType)
|
||||
OpenHandleFile(const unsigned char *name, long fileType)
|
||||
{
|
||||
int i;
|
||||
Handle h;
|
||||
Str255 s;
|
||||
int i;
|
||||
Handle h;
|
||||
Str255 s;
|
||||
|
||||
for (i = 0; i < MAX_HF; i ++) {
|
||||
if (theHandleFiles[i].data == 0L) break;
|
||||
}
|
||||
|
||||
if (i >= MAX_HF)
|
||||
return -1;
|
||||
for (i = 0; i < MAX_HF; i++) {
|
||||
if (theHandleFiles[i].data == 0L)
|
||||
break;
|
||||
}
|
||||
|
||||
h = GetNamedResource (fileType, name);
|
||||
if (!h) return (-1);
|
||||
|
||||
theHandleFiles[i].data = h;
|
||||
theHandleFiles[i].size = GetHandleSize (h);
|
||||
GetResInfo (h, &theHandleFiles[i].id, (void*) &theHandleFiles[i].type, s);
|
||||
theHandleFiles[i].mark = 0L;
|
||||
if (i >= MAX_HF)
|
||||
return -1;
|
||||
|
||||
return(i + FIRST_HF);
|
||||
h = GetNamedResource(fileType, name);
|
||||
if (!h)
|
||||
return (-1);
|
||||
|
||||
theHandleFiles[i].data = h;
|
||||
theHandleFiles[i].size = GetHandleSize(h);
|
||||
GetResInfo(h, &theHandleFiles[i].id, (void *) &theHandleFiles[i].type, s);
|
||||
theHandleFiles[i].mark = 0L;
|
||||
|
||||
return (i + FIRST_HF);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
CloseHandleFile (int fd)
|
||||
CloseHandleFile(int fd)
|
||||
{
|
||||
if (!IsHandleFile (fd)) {
|
||||
return -1;
|
||||
}
|
||||
fd -= FIRST_HF;
|
||||
ReleaseResource (theHandleFiles[fd].data);
|
||||
theHandleFiles[fd].data = 0L;
|
||||
return(0);
|
||||
if (!IsHandleFile(fd)) {
|
||||
return -1;
|
||||
}
|
||||
fd -= FIRST_HF;
|
||||
ReleaseResource(theHandleFiles[fd].data);
|
||||
theHandleFiles[fd].data = 0L;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ReadHandleFile (int fd, void *ptr, unsigned len)
|
||||
ReadHandleFile(int fd, void *ptr, unsigned len)
|
||||
{
|
||||
unsigned maxBytes;
|
||||
Handle h;
|
||||
unsigned maxBytes;
|
||||
Handle h;
|
||||
|
||||
if (!IsHandleFile (fd)) return -1;
|
||||
|
||||
fd -= FIRST_HF;
|
||||
maxBytes = theHandleFiles[fd].size - theHandleFiles[fd].mark;
|
||||
if (len > maxBytes) len = maxBytes;
|
||||
|
||||
h = theHandleFiles[fd].data;
|
||||
|
||||
HLock(h);
|
||||
BlockMove (*h + theHandleFiles[fd].mark, ptr, len);
|
||||
HUnlock(h);
|
||||
theHandleFiles[fd].mark += len;
|
||||
|
||||
return(len);
|
||||
if (!IsHandleFile(fd))
|
||||
return -1;
|
||||
|
||||
fd -= FIRST_HF;
|
||||
maxBytes = theHandleFiles[fd].size - theHandleFiles[fd].mark;
|
||||
if (len > maxBytes)
|
||||
len = maxBytes;
|
||||
|
||||
h = theHandleFiles[fd].data;
|
||||
|
||||
HLock(h);
|
||||
BlockMove(*h + theHandleFiles[fd].mark, ptr, len);
|
||||
HUnlock(h);
|
||||
theHandleFiles[fd].mark += len;
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
static long
|
||||
SetHandleFilePos (int fd, short whence, long pos)
|
||||
SetHandleFilePos(int fd, short whence, long pos)
|
||||
{
|
||||
long curpos;
|
||||
|
||||
if (!IsHandleFile (fd)) return -1;
|
||||
|
||||
fd -= FIRST_HF;
|
||||
|
||||
curpos = theHandleFiles [fd].mark;
|
||||
switch (whence) {
|
||||
case SEEK_CUR :
|
||||
curpos += pos;
|
||||
break;
|
||||
case SEEK_END :
|
||||
curpos = theHandleFiles[fd].size - pos;
|
||||
break;
|
||||
default : /* set */
|
||||
curpos = pos;
|
||||
break;
|
||||
}
|
||||
long curpos;
|
||||
|
||||
if (curpos < 0)
|
||||
curpos = 0;
|
||||
else if (curpos > theHandleFiles [fd].size)
|
||||
curpos = theHandleFiles [fd].size;
|
||||
|
||||
theHandleFiles [fd].mark = curpos;
|
||||
|
||||
return curpos;
|
||||
}
|
||||
if (!IsHandleFile(fd))
|
||||
return -1;
|
||||
|
||||
fd -= FIRST_HF;
|
||||
|
||||
void
|
||||
C2P (const char *c, unsigned char *p)
|
||||
{
|
||||
int len = strlen (c), i;
|
||||
curpos = theHandleFiles[fd].mark;
|
||||
switch (whence) {
|
||||
case SEEK_CUR:
|
||||
curpos += pos;
|
||||
break;
|
||||
case SEEK_END:
|
||||
curpos = theHandleFiles[fd].size - pos;
|
||||
break;
|
||||
default: /* set */
|
||||
curpos = pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (len > 255) len = 255;
|
||||
if (curpos < 0)
|
||||
curpos = 0;
|
||||
else if (curpos > theHandleFiles[fd].size)
|
||||
curpos = theHandleFiles[fd].size;
|
||||
|
||||
for (i = len; i > 0; i--)
|
||||
p[i] = c[i-1];
|
||||
p[0] = len;
|
||||
theHandleFiles[fd].mark = curpos;
|
||||
|
||||
return curpos;
|
||||
}
|
||||
|
||||
void
|
||||
P2C (const unsigned char *p, char *c)
|
||||
C2P(const char *c, unsigned char *p)
|
||||
{
|
||||
int idx = *p++;
|
||||
for (; idx > 0; idx--)
|
||||
*c++ = *p++;
|
||||
*c = '\0';
|
||||
int len = strlen(c), i;
|
||||
|
||||
if (len > 255)
|
||||
len = 255;
|
||||
|
||||
for (i = len; i > 0; i--)
|
||||
p[i] = c[i - 1];
|
||||
p[0] = len;
|
||||
}
|
||||
|
||||
void
|
||||
P2C(const unsigned char *p, char *c)
|
||||
{
|
||||
int idx = *p++;
|
||||
for (; idx > 0; idx--)
|
||||
*c++ = *p++;
|
||||
*c = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
replace_resource(Handle new_res, ResType its_type, short its_id, Str255 its_name)
|
||||
replace_resource(Handle new_res, ResType its_type, short its_id,
|
||||
Str255 its_name)
|
||||
{
|
||||
Handle old_res;
|
||||
Handle old_res;
|
||||
|
||||
SetResLoad(false);
|
||||
old_res = Get1Resource(its_type, its_id);
|
||||
SetResLoad(true);
|
||||
if (old_res) {
|
||||
RemoveResource(old_res);
|
||||
DisposeHandle(old_res);
|
||||
}
|
||||
SetResLoad(false);
|
||||
old_res = Get1Resource(its_type, its_id);
|
||||
SetResLoad(true);
|
||||
if (old_res) {
|
||||
RemoveResource(old_res);
|
||||
DisposeHandle(old_res);
|
||||
}
|
||||
|
||||
AddResource(new_res, its_type, its_id, its_name);
|
||||
AddResource(new_res, its_type, its_id, its_name);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
maccreat (const char *name, long fileType){
|
||||
return macopen (name, O_RDWR | O_CREAT | O_TRUNC, fileType);
|
||||
maccreat(const char *name, long fileType)
|
||||
{
|
||||
return macopen(name, O_RDWR | O_CREAT | O_TRUNC, fileType);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
macopen (const char *name, int flags, long fileType)
|
||||
macopen(const char *name, int flags, long fileType)
|
||||
{
|
||||
short refNum;
|
||||
short perm;
|
||||
Str255 s;
|
||||
short refNum;
|
||||
short perm;
|
||||
Str255 s;
|
||||
|
||||
C2P (name, s);
|
||||
if (flags & O_CREAT) {
|
||||
if (HCreate (theDirs.dataRefNum, theDirs.dataDirID, s ,
|
||||
TEXT_CREATOR, fileType) && (flags & O_EXCL)) {
|
||||
return -1;
|
||||
}
|
||||
#if 0 /* Fails during makedefs */
|
||||
C2P(name, s);
|
||||
if (flags & O_CREAT) {
|
||||
if (HCreate(theDirs.dataRefNum, theDirs.dataDirID, s, TEXT_CREATOR,
|
||||
fileType) && (flags & O_EXCL)) {
|
||||
return -1;
|
||||
}
|
||||
#if 0 /* Fails during makedefs */
|
||||
if (fileType == SAVE_TYPE) {
|
||||
short resRef;
|
||||
HCreateResFile(theDirs.dataRefNum, theDirs.dataDirID, s);
|
||||
@@ -249,66 +248,63 @@ macopen (const char *name, int flags, long fileType)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
/*
|
||||
* Here, we should check for file type, maybe a SFdialog if
|
||||
* we fail with default, etc. etc. Besides, we should use HOpen
|
||||
* and permissions.
|
||||
*/
|
||||
if ((flags & O_RDONLY) == O_RDONLY) {
|
||||
perm = fsRdPerm;
|
||||
}
|
||||
if ((flags & O_WRONLY) == O_WRONLY) {
|
||||
perm = fsWrPerm;
|
||||
}
|
||||
if ((flags & O_RDWR) == O_RDWR) {
|
||||
perm = fsRdWrPerm;
|
||||
}
|
||||
if (HOpen (theDirs.dataRefNum, theDirs.dataDirID, s, perm, &refNum)) {
|
||||
return OpenHandleFile (s, fileType);
|
||||
}
|
||||
if (flags & O_TRUNC) {
|
||||
if (SetEOF (refNum, 0L)) {
|
||||
FSClose (refNum);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return refNum;
|
||||
}
|
||||
/*
|
||||
* Here, we should check for file type, maybe a SFdialog if
|
||||
* we fail with default, etc. etc. Besides, we should use HOpen
|
||||
* and permissions.
|
||||
*/
|
||||
if ((flags & O_RDONLY) == O_RDONLY) {
|
||||
perm = fsRdPerm;
|
||||
}
|
||||
if ((flags & O_WRONLY) == O_WRONLY) {
|
||||
perm = fsWrPerm;
|
||||
}
|
||||
if ((flags & O_RDWR) == O_RDWR) {
|
||||
perm = fsRdWrPerm;
|
||||
}
|
||||
if (HOpen(theDirs.dataRefNum, theDirs.dataDirID, s, perm, &refNum)) {
|
||||
return OpenHandleFile(s, fileType);
|
||||
}
|
||||
if (flags & O_TRUNC) {
|
||||
if (SetEOF(refNum, 0L)) {
|
||||
FSClose(refNum);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return refNum;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
macclose (int fd)
|
||||
macclose(int fd)
|
||||
{
|
||||
if (IsHandleFile (fd)) {
|
||||
CloseHandleFile (fd);
|
||||
} else {
|
||||
if (FSClose (fd)) {
|
||||
return -1;
|
||||
}
|
||||
FlushVol ((StringPtr) 0, theDirs . dataRefNum);
|
||||
}
|
||||
return 0;
|
||||
if (IsHandleFile(fd)) {
|
||||
CloseHandleFile(fd);
|
||||
} else {
|
||||
if (FSClose(fd)) {
|
||||
return -1;
|
||||
}
|
||||
FlushVol((StringPtr) 0, theDirs.dataRefNum);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
macread (int fd, void *ptr, unsigned len)
|
||||
macread(int fd, void *ptr, unsigned len)
|
||||
{
|
||||
long amt = len;
|
||||
|
||||
if (IsHandleFile (fd)) {
|
||||
return ReadHandleFile (fd, ptr, amt);
|
||||
} else {
|
||||
short err = FSRead (fd, &amt, ptr);
|
||||
long amt = len;
|
||||
|
||||
return ((err == noErr) || (err == eofErr && len)) ? amt : -1;
|
||||
}
|
||||
if (IsHandleFile(fd)) {
|
||||
return ReadHandleFile(fd, ptr, amt);
|
||||
} else {
|
||||
short err = FSRead(fd, &amt, ptr);
|
||||
|
||||
return ((err == noErr) || (err == eofErr && len)) ? amt : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0 /* this function isn't used, if you use it, uncomment prototype in macwin.h */
|
||||
#if 0 /* this function isn't used, if you use it, uncomment prototype in \
|
||||
macwin.h */
|
||||
char *
|
||||
macgets (int fd, char *ptr, unsigned len)
|
||||
{
|
||||
@@ -327,142 +323,160 @@ macgets (int fd, char *ptr, unsigned len)
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
|
||||
int
|
||||
macwrite (int fd, void *ptr, unsigned len)
|
||||
macwrite(int fd, void *ptr, unsigned len)
|
||||
{
|
||||
long amt = len;
|
||||
long amt = len;
|
||||
|
||||
if (IsHandleFile (fd)) return -1;
|
||||
if (FSWrite(fd, &amt, ptr) == noErr)
|
||||
return (amt);
|
||||
else
|
||||
return (-1);
|
||||
if (IsHandleFile(fd))
|
||||
return -1;
|
||||
if (FSWrite(fd, &amt, ptr) == noErr)
|
||||
return (amt);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
long
|
||||
macseek (int fd, long where, short whence)
|
||||
macseek(int fd, long where, short whence)
|
||||
{
|
||||
short posMode;
|
||||
long curPos;
|
||||
short posMode;
|
||||
long curPos;
|
||||
|
||||
if (IsHandleFile (fd)) {
|
||||
return SetHandleFilePos (fd, whence, where);
|
||||
}
|
||||
if (IsHandleFile(fd)) {
|
||||
return SetHandleFilePos(fd, whence, where);
|
||||
}
|
||||
|
||||
switch (whence) {
|
||||
default :
|
||||
posMode = fsFromStart;
|
||||
break;
|
||||
case SEEK_CUR :
|
||||
posMode = fsFromMark;
|
||||
break;
|
||||
case SEEK_END :
|
||||
posMode = fsFromLEOF;
|
||||
break;
|
||||
}
|
||||
switch (whence) {
|
||||
default:
|
||||
posMode = fsFromStart;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
posMode = fsFromMark;
|
||||
break;
|
||||
case SEEK_END:
|
||||
posMode = fsFromLEOF;
|
||||
break;
|
||||
}
|
||||
|
||||
if (SetFPos(fd, posMode, where) == noErr && GetFPos(fd, &curPos) == noErr)
|
||||
return (curPos);
|
||||
else
|
||||
return(-1);
|
||||
if (SetFPos(fd, posMode, where) == noErr && GetFPos(fd, &curPos) == noErr)
|
||||
return (curPos);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
macunlink(const char *name)
|
||||
{
|
||||
Str255 pname;
|
||||
Str255 pname;
|
||||
|
||||
|
||||
C2P(name, pname);
|
||||
return (HDelete(theDirs.dataRefNum, theDirs.dataDirID, pname) == noErr ? 0 : -1);
|
||||
C2P(name, pname);
|
||||
return (HDelete(theDirs.dataRefNum, theDirs.dataDirID, pname) == noErr
|
||||
? 0
|
||||
: -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
boolean rsrc_dlb_init(void) {
|
||||
return TRUE;
|
||||
boolean
|
||||
rsrc_dlb_init(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void rsrc_dlb_cleanup(void) {
|
||||
void
|
||||
rsrc_dlb_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode) {
|
||||
boolean
|
||||
rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode)
|
||||
{
|
||||
#if defined(__SC__) || defined(__MRC__)
|
||||
# pragma unused(mode)
|
||||
#pragma unused(mode)
|
||||
#endif
|
||||
Str255 pname;
|
||||
|
||||
C2P(name, pname);
|
||||
dp->fd = OpenHandleFile(pname, 'File'); /* automatically read-only */
|
||||
return dp->fd >= 0;
|
||||
Str255 pname;
|
||||
|
||||
C2P(name, pname);
|
||||
dp->fd = OpenHandleFile(pname, 'File'); /* automatically read-only */
|
||||
return dp->fd >= 0;
|
||||
}
|
||||
|
||||
int rsrc_dlb_fclose(dlb *dp) {
|
||||
return CloseHandleFile(dp->fd);
|
||||
int
|
||||
rsrc_dlb_fclose(dlb *dp)
|
||||
{
|
||||
return CloseHandleFile(dp->fd);
|
||||
}
|
||||
|
||||
int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp) {
|
||||
int nread;
|
||||
int
|
||||
rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp)
|
||||
{
|
||||
int nread;
|
||||
|
||||
if (size < 0 || quan < 0) return 0;
|
||||
nread = ReadHandleFile(dp->fd, buf, (unsigned)size * (unsigned)quan);
|
||||
|
||||
return nread/size; /* # of whole pieces (== quan in normal case) */
|
||||
if (size < 0 || quan < 0)
|
||||
return 0;
|
||||
nread = ReadHandleFile(dp->fd, buf, (unsigned) size * (unsigned) quan);
|
||||
|
||||
return nread / size; /* # of whole pieces (== quan in normal case) */
|
||||
}
|
||||
|
||||
int rsrc_dlb_fseek(dlb *dp, long pos, int whence) {
|
||||
return SetHandleFilePos(dp->fd, whence, pos);
|
||||
int
|
||||
rsrc_dlb_fseek(dlb *dp, long pos, int whence)
|
||||
{
|
||||
return SetHandleFilePos(dp->fd, whence, pos);
|
||||
}
|
||||
|
||||
char *rsrc_dlb_fgets(char *buf, int len, dlb *dp) {
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
char *p;
|
||||
int bytesLeft, n = 0;
|
||||
char *
|
||||
rsrc_dlb_fgets(char *buf, int len, dlb *dp)
|
||||
{
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
char *p;
|
||||
int bytesLeft, n = 0;
|
||||
|
||||
if (hfp && hfp->mark < hfp->size) {
|
||||
bytesLeft = hfp->size - hfp->mark;
|
||||
if (bytesLeft < len)
|
||||
len = bytesLeft;
|
||||
if (hfp && hfp->mark < hfp->size) {
|
||||
bytesLeft = hfp->size - hfp->mark;
|
||||
if (bytesLeft < len)
|
||||
len = bytesLeft;
|
||||
|
||||
HLock(hfp->data);
|
||||
for (n = 0, p = *hfp->data+hfp->mark; n < len; n++, p++) {
|
||||
buf[n] = *p;
|
||||
if (*p == '\r') buf[n] = '\n';
|
||||
if (buf[n] == '\n') {
|
||||
n++; /* we want the return in the buffer */
|
||||
break;
|
||||
}
|
||||
}
|
||||
HUnlock(hfp->data);
|
||||
HLock(hfp->data);
|
||||
for (n = 0, p = *hfp->data + hfp->mark; n < len; n++, p++) {
|
||||
buf[n] = *p;
|
||||
if (*p == '\r')
|
||||
buf[n] = '\n';
|
||||
if (buf[n] == '\n') {
|
||||
n++; /* we want the return in the buffer */
|
||||
break;
|
||||
}
|
||||
}
|
||||
HUnlock(hfp->data);
|
||||
|
||||
hfp->mark += n;
|
||||
if (n != 0)
|
||||
buf[n] = '\0'; /* null terminate result */
|
||||
}
|
||||
hfp->mark += n;
|
||||
if (n != 0)
|
||||
buf[n] = '\0'; /* null terminate result */
|
||||
}
|
||||
|
||||
return n ? buf : NULL;
|
||||
return n ? buf : NULL;
|
||||
}
|
||||
|
||||
int rsrc_dlb_fgetc(dlb *dp) {
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
int ret;
|
||||
int
|
||||
rsrc_dlb_fgetc(dlb *dp)
|
||||
{
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
int ret;
|
||||
|
||||
if (!hfp || hfp->size <= hfp->mark) return EOF;
|
||||
if (!hfp || hfp->size <= hfp->mark)
|
||||
return EOF;
|
||||
|
||||
ret = *(unsigned char *)(*hfp->data + hfp->mark);
|
||||
hfp->mark++;
|
||||
return ret;
|
||||
ret = *(unsigned char *) (*hfp->data + hfp->mark);
|
||||
hfp->mark++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
long rsrc_dlb_ftell(dlb *dp) {
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
long
|
||||
rsrc_dlb_ftell(dlb *dp)
|
||||
{
|
||||
HandleFile *hfp = IsHandleFile(dp->fd);
|
||||
|
||||
if (!hfp) return 0;
|
||||
return hfp->mark;
|
||||
if (!hfp)
|
||||
return 0;
|
||||
return hfp->mark;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 macmain.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 macmain.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */
|
||||
/* NetHack 3.6 macmain.c $Date: 2009/05/06 10:49:11 $ $Revision: 1.15 $ */
|
||||
/* SCCS Id: @(#)macmain.c 3.5 2008/01/30 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -33,230 +33,232 @@ int main(void);
|
||||
QDGlobals qd;
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
main(void)
|
||||
{
|
||||
register int fd = -1;
|
||||
int argc = 1;
|
||||
boolean resuming = FALSE; /* assume new game */
|
||||
register int fd = -1;
|
||||
int argc = 1;
|
||||
boolean resuming = FALSE; /* assume new game */
|
||||
|
||||
sys_early_init();
|
||||
windowprocs = mac_procs;
|
||||
InitMac ();
|
||||
sys_early_init();
|
||||
windowprocs = mac_procs;
|
||||
InitMac();
|
||||
|
||||
hname = "Mac Hack";
|
||||
hackpid = getpid();
|
||||
hname = "Mac Hack";
|
||||
hackpid = getpid();
|
||||
|
||||
setrandom();
|
||||
initoptions();
|
||||
init_nhwindows(&argc, (char **)&hname);
|
||||
setrandom();
|
||||
initoptions();
|
||||
init_nhwindows(&argc, (char **) &hname);
|
||||
|
||||
/*
|
||||
* It seems you really want to play.
|
||||
*/
|
||||
u.uhp = 1; /* prevent RIP on early quits */
|
||||
/*
|
||||
* It seems you really want to play.
|
||||
*/
|
||||
u.uhp = 1; /* prevent RIP on early quits */
|
||||
|
||||
finder_file_request ();
|
||||
finder_file_request();
|
||||
|
||||
dlb_init(); /* must be before newgame() */
|
||||
dlb_init(); /* must be before newgame() */
|
||||
|
||||
/*
|
||||
* Initialize the vision system. This must be before mklev() on a
|
||||
* new game or before a level restore on a saved game.
|
||||
*/
|
||||
vision_init();
|
||||
/*
|
||||
* Initialize the vision system. This must be before mklev() on a
|
||||
* new game or before a level restore on a saved game.
|
||||
*/
|
||||
vision_init();
|
||||
|
||||
display_gamewindows();
|
||||
display_gamewindows();
|
||||
|
||||
set_playmode(); /* sets plname to "wizard" for wizard mode */
|
||||
/* strip role,race,&c suffix; calls askname() if plname[] is empty
|
||||
or holds a generic user name like "player" or "games" */
|
||||
plnamesuffix();
|
||||
/* unlike Unix where the game might be invoked with a script
|
||||
which forces a particular character name for each player
|
||||
using a shared account, we always allow player to rename
|
||||
the character during role/race/&c selection */
|
||||
iflags.renameallowed = TRUE;
|
||||
set_playmode(); /* sets plname to "wizard" for wizard mode */
|
||||
/* strip role,race,&c suffix; calls askname() if plname[] is empty
|
||||
or holds a generic user name like "player" or "games" */
|
||||
plnamesuffix();
|
||||
/* unlike Unix where the game might be invoked with a script
|
||||
which forces a particular character name for each player
|
||||
using a shared account, we always allow player to rename
|
||||
the character during role/race/&c selection */
|
||||
iflags.renameallowed = TRUE;
|
||||
|
||||
getlock();
|
||||
getlock();
|
||||
|
||||
/*
|
||||
* First, try to find and restore a save file for specified character.
|
||||
* We'll return here if new game player_selection() renames the hero.
|
||||
*/
|
||||
attempt_restore:
|
||||
if ((fd = restore_saved_game()) >= 0) {
|
||||
/*
|
||||
* First, try to find and restore a save file for specified character.
|
||||
* We'll return here if new game player_selection() renames the hero.
|
||||
*/
|
||||
attempt_restore:
|
||||
if ((fd = restore_saved_game()) >= 0) {
|
||||
#ifdef NEWS
|
||||
if(iflags.news) {
|
||||
display_file(NEWS, FALSE);
|
||||
iflags.news = FALSE; /* in case dorecover() fails */
|
||||
}
|
||||
if (iflags.news) {
|
||||
display_file(NEWS, FALSE);
|
||||
iflags.news = FALSE; /* in case dorecover() fails */
|
||||
}
|
||||
#endif
|
||||
pline("Restoring save file...");
|
||||
mark_synch(); /* flush output */
|
||||
game_active = 1;
|
||||
if (dorecover(fd)) {
|
||||
resuming = TRUE; /* not starting new game */
|
||||
if (discover)
|
||||
You("are in non-scoring discovery mode.");
|
||||
if (discover || wizard) {
|
||||
if(yn("Do you want to keep the save file?") == 'n')
|
||||
(void) delete_savefile();
|
||||
else {
|
||||
nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pline("Restoring save file...");
|
||||
mark_synch(); /* flush output */
|
||||
game_active = 1;
|
||||
if (dorecover(fd)) {
|
||||
resuming = TRUE; /* not starting new game */
|
||||
if (discover)
|
||||
You("are in non-scoring discovery mode.");
|
||||
if (discover || wizard) {
|
||||
if (yn("Do you want to keep the save file?") == 'n')
|
||||
(void) delete_savefile();
|
||||
else {
|
||||
nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!resuming) {
|
||||
/* new game: start by choosing role, race, etc;
|
||||
player might change the hero's name while doing that,
|
||||
in which case we try to restore under the new name
|
||||
and skip selection this time if that didn't succeed */
|
||||
if (!iflags.renameinprogress) {
|
||||
player_selection();
|
||||
if (iflags.renameinprogress) {
|
||||
/* player has renamed the hero while selecting role;
|
||||
discard current lock file and create another for
|
||||
the new character name */
|
||||
delete_levelfile(0); /* remove empty lock file */
|
||||
getlock();
|
||||
goto attempt_restore;
|
||||
}
|
||||
}
|
||||
game_active = 1; /* done with selection, draw active game window */
|
||||
newgame();
|
||||
if (discover)
|
||||
You("are in non-scoring discovery mode.");
|
||||
}
|
||||
if (!resuming) {
|
||||
/* new game: start by choosing role, race, etc;
|
||||
player might change the hero's name while doing that,
|
||||
in which case we try to restore under the new name
|
||||
and skip selection this time if that didn't succeed */
|
||||
if (!iflags.renameinprogress) {
|
||||
player_selection();
|
||||
if (iflags.renameinprogress) {
|
||||
/* player has renamed the hero while selecting role;
|
||||
discard current lock file and create another for
|
||||
the new character name */
|
||||
delete_levelfile(0); /* remove empty lock file */
|
||||
getlock();
|
||||
goto attempt_restore;
|
||||
}
|
||||
}
|
||||
game_active = 1; /* done with selection, draw active game window */
|
||||
newgame();
|
||||
if (discover)
|
||||
You("are in non-scoring discovery mode.");
|
||||
}
|
||||
|
||||
UndimMenuBar (); /* Yes, this is the place for it (!) */
|
||||
UndimMenuBar(); /* Yes, this is the place for it (!) */
|
||||
|
||||
moveloop(resuming);
|
||||
moveloop(resuming);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static OSErr
|
||||
copy_file(short src_vol, long src_dir, short dst_vol, long dst_dir,
|
||||
Str255 fName,
|
||||
pascal OSErr (*opener)(short vRefNum, long dirID,
|
||||
ConstStr255Param fileName,
|
||||
signed char permission, short *refNum)) {
|
||||
short src_ref, dst_ref;
|
||||
OSErr err = (*opener)(src_vol, src_dir, fName, fsRdPerm, &src_ref);
|
||||
if (err == noErr) {
|
||||
err = (*opener)(dst_vol, dst_dir, fName, fsWrPerm, &dst_ref);
|
||||
if (err == noErr) {
|
||||
Str255 fName,
|
||||
pascal OSErr (*opener)(short vRefNum, long dirID,
|
||||
ConstStr255Param fileName,
|
||||
signed char permission, short *refNum))
|
||||
{
|
||||
short src_ref, dst_ref;
|
||||
OSErr err = (*opener)(src_vol, src_dir, fName, fsRdPerm, &src_ref);
|
||||
if (err == noErr) {
|
||||
err = (*opener)(dst_vol, dst_dir, fName, fsWrPerm, &dst_ref);
|
||||
if (err == noErr) {
|
||||
long file_len;
|
||||
err = GetEOF(src_ref, &file_len);
|
||||
if (err == noErr) {
|
||||
Handle buf;
|
||||
long count = MaxBlock();
|
||||
if (count > file_len)
|
||||
count = file_len;
|
||||
|
||||
long file_len;
|
||||
err = GetEOF(src_ref, &file_len);
|
||||
if (err == noErr) {
|
||||
Handle buf;
|
||||
long count = MaxBlock();
|
||||
if (count > file_len)
|
||||
count = file_len;
|
||||
buf = NewHandle(count);
|
||||
err = MemError();
|
||||
if (err == noErr) {
|
||||
while (count > 0) {
|
||||
OSErr rd_err = FSRead(src_ref, &count, *buf);
|
||||
err = FSWrite(dst_ref, &count, *buf);
|
||||
if (err == noErr)
|
||||
err = rd_err;
|
||||
file_len -= count;
|
||||
}
|
||||
if (file_len == 0)
|
||||
err = noErr;
|
||||
|
||||
buf = NewHandle(count);
|
||||
err = MemError();
|
||||
if (err == noErr) {
|
||||
DisposeHandle(buf);
|
||||
}
|
||||
}
|
||||
FSClose(dst_ref);
|
||||
}
|
||||
FSClose(src_ref);
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
OSErr rd_err = FSRead(src_ref, &count, *buf);
|
||||
err = FSWrite(dst_ref, &count, *buf);
|
||||
if (err == noErr)
|
||||
err = rd_err;
|
||||
file_len -= count;
|
||||
}
|
||||
if (file_len == 0)
|
||||
err = noErr;
|
||||
|
||||
DisposeHandle(buf);
|
||||
|
||||
}
|
||||
}
|
||||
FSClose(dst_ref);
|
||||
}
|
||||
FSClose(src_ref);
|
||||
}
|
||||
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
force_hdelete(short vol, long dir, Str255 fName)
|
||||
{
|
||||
HRstFLock(vol, dir, fName);
|
||||
HDelete (vol, dir, fName);
|
||||
HRstFLock(vol, dir, fName);
|
||||
HDelete(vol, dir, fName);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
process_openfile (short src_vol, long src_dir, Str255 fName, OSType ftype)
|
||||
process_openfile(short src_vol, long src_dir, Str255 fName, OSType ftype)
|
||||
{
|
||||
OSErr err = noErr;
|
||||
|
||||
if (ftype != SAVE_TYPE)
|
||||
return; /* only deal with save files */
|
||||
|
||||
if (src_vol != theDirs.dataRefNum || src_dir != theDirs.dataDirID &&
|
||||
CatMove(src_vol, src_dir, fName, theDirs.dataDirID, "\p:") != noErr) {
|
||||
OSErr err = noErr;
|
||||
|
||||
HCreate(theDirs.dataRefNum, theDirs.dataDirID, fName, MAC_CREATOR, SAVE_TYPE);
|
||||
err = copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID,
|
||||
fName, &HOpen); /* HOpenDF is only there under 7.0 */
|
||||
if (err == noErr)
|
||||
err = copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID,
|
||||
fName, &HOpenRF);
|
||||
if (err == noErr)
|
||||
force_hdelete(src_vol, src_dir, fName);
|
||||
else
|
||||
HDelete(theDirs.dataRefNum, theDirs.dataDirID, fName);
|
||||
}
|
||||
if (ftype != SAVE_TYPE)
|
||||
return; /* only deal with save files */
|
||||
|
||||
if (err == noErr) {
|
||||
short ref;
|
||||
if (src_vol != theDirs.dataRefNum
|
||||
|| src_dir != theDirs.dataDirID
|
||||
&& CatMove(src_vol, src_dir, fName, theDirs.dataDirID, "\p:")
|
||||
!= noErr) {
|
||||
HCreate(theDirs.dataRefNum, theDirs.dataDirID, fName, MAC_CREATOR,
|
||||
SAVE_TYPE);
|
||||
err =
|
||||
copy_file(src_vol, src_dir, theDirs.dataRefNum, theDirs.dataDirID,
|
||||
fName, &HOpen); /* HOpenDF is only there under 7.0 */
|
||||
if (err == noErr)
|
||||
err = copy_file(src_vol, src_dir, theDirs.dataRefNum,
|
||||
theDirs.dataDirID, fName, &HOpenRF);
|
||||
if (err == noErr)
|
||||
force_hdelete(src_vol, src_dir, fName);
|
||||
else
|
||||
HDelete(theDirs.dataRefNum, theDirs.dataDirID, fName);
|
||||
}
|
||||
|
||||
ref = HOpenResFile(theDirs.dataRefNum, theDirs.dataDirID, fName, fsRdPerm);
|
||||
if (ref != -1) {
|
||||
Handle name = Get1Resource('STR ', PLAYER_NAME_RES_ID);
|
||||
if (name) {
|
||||
Str255 save_f_p;
|
||||
P2C(*(StringHandle)name, plname);
|
||||
set_savefile_name(TRUE);
|
||||
C2P(fqname(SAVEF, SAVEPREFIX, 0), save_f_p);
|
||||
force_hdelete(theDirs.dataRefNum, theDirs.dataDirID, save_f_p);
|
||||
if (err == noErr) {
|
||||
short ref;
|
||||
|
||||
if (HRename(theDirs.dataRefNum, theDirs.dataDirID, fName, save_f_p) == noErr)
|
||||
macFlags.gotOpen = 1;
|
||||
}
|
||||
CloseResFile(ref);
|
||||
}
|
||||
}
|
||||
ref = HOpenResFile(theDirs.dataRefNum, theDirs.dataDirID, fName,
|
||||
fsRdPerm);
|
||||
if (ref != -1) {
|
||||
Handle name = Get1Resource('STR ', PLAYER_NAME_RES_ID);
|
||||
if (name) {
|
||||
Str255 save_f_p;
|
||||
P2C(*(StringHandle) name, plname);
|
||||
set_savefile_name(TRUE);
|
||||
C2P(fqname(SAVEF, SAVEPREFIX, 0), save_f_p);
|
||||
force_hdelete(theDirs.dataRefNum, theDirs.dataDirID,
|
||||
save_f_p);
|
||||
|
||||
if (HRename(theDirs.dataRefNum, theDirs.dataDirID, fName,
|
||||
save_f_p) == noErr)
|
||||
macFlags.gotOpen = 1;
|
||||
}
|
||||
CloseResFile(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
finder_file_request(void)
|
||||
{
|
||||
if (macFlags.hasAE) {
|
||||
/* we're capable of handling Apple Events, so let's see if we have any */
|
||||
EventRecord event;
|
||||
long toWhen = TickCount () + 20; /* wait a third of a second for all initial AE */
|
||||
if (macFlags.hasAE) {
|
||||
/* we're capable of handling Apple Events, so let's see if we have any
|
||||
*/
|
||||
EventRecord event;
|
||||
long toWhen = TickCount()
|
||||
+ 20; /* wait a third of a second for all initial AE */
|
||||
|
||||
while (TickCount () < toWhen) {
|
||||
if (WaitNextEvent (highLevelEventMask, &event, 3L, 0)) {
|
||||
AEProcessAppleEvent(&event);
|
||||
if (macFlags.gotOpen)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (TickCount() < toWhen) {
|
||||
if (WaitNextEvent(highLevelEventMask, &event, 3L, 0)) {
|
||||
AEProcessAppleEvent(&event);
|
||||
if (macFlags.gotOpen)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
#ifdef MAC68K
|
||||
else {
|
||||
@@ -284,8 +286,8 @@ finder_file_request(void)
|
||||
boolean
|
||||
authorize_wizard_mode()
|
||||
{
|
||||
/* other ports validate user name or character name here */
|
||||
return TRUE;
|
||||
/* other ports validate user name or character name here */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*macmain.c*/
|
||||
|
||||
1641
sys/mac/macmenu.c
1641
sys/mac/macmenu.c
File diff suppressed because it is too large
Load Diff
146
sys/mac/macsnd.c
146
sys/mac/macsnd.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 macsnd.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 macsnd.c $NHDT-Date: 1431192786 2015/05/09 17:33:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
|
||||
/* NetHack 3.6 macsnd.c $Date: 2009/05/06 10:49:14 $ $Revision: 1.6 $ */
|
||||
/* SCCS Id: @(#)macsnd.c 3.5 1992/11/28 */
|
||||
/* Copyright (c) 1992 by Jon Watte */
|
||||
@@ -20,92 +20,94 @@
|
||||
#include "mactty.h"
|
||||
#include "macwin.h"
|
||||
#if 1 /*!TARGET_API_MAC_CARBON*/
|
||||
# include <Sound.h>
|
||||
# include <Resources.h>
|
||||
#include <Sound.h>
|
||||
#include <Resources.h>
|
||||
#endif
|
||||
|
||||
#ifndef freqDurationCmd
|
||||
# define freqDurationCmd 40
|
||||
#define freqDurationCmd 40
|
||||
#endif
|
||||
|
||||
#define SND_BUFFER(s) (&(*s)[20])
|
||||
#define SND_LEN(s) (GetHandleSize(s)-42)
|
||||
|
||||
#define SND_LEN(s) (GetHandleSize(s) - 42)
|
||||
|
||||
void
|
||||
mac_speaker (struct obj *instr, char *melody) {
|
||||
SndChannelPtr theChannel = (SndChannelPtr) 0;
|
||||
SndCommand theCmd;
|
||||
Handle theSound;
|
||||
unsigned char theName [32];
|
||||
char *n = (char *) &theName [1];
|
||||
int typ = instr->otyp;
|
||||
const char *actualn = OBJ_NAME (objects [typ]);
|
||||
mac_speaker(struct obj *instr, char *melody)
|
||||
{
|
||||
SndChannelPtr theChannel = (SndChannelPtr) 0;
|
||||
SndCommand theCmd;
|
||||
Handle theSound;
|
||||
unsigned char theName[32];
|
||||
char *n = (char *) &theName[1];
|
||||
int typ = instr->otyp;
|
||||
const char *actualn = OBJ_NAME(objects[typ]);
|
||||
|
||||
/*
|
||||
* First: are we in the library ?
|
||||
*/
|
||||
if (flags.silent) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* First: are we in the library ?
|
||||
*/
|
||||
if (flags.silent) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Is this a known instrument ?
|
||||
*/
|
||||
strcpy (n, actualn);
|
||||
theName [0] = strlen (n);
|
||||
theSound = GetNamedResource ('snd ', theName);
|
||||
if (! theSound) {
|
||||
return;
|
||||
}
|
||||
HLock (theSound);
|
||||
/*
|
||||
* Is this a known instrument ?
|
||||
*/
|
||||
strcpy(n, actualn);
|
||||
theName[0] = strlen(n);
|
||||
theSound = GetNamedResource('snd ', theName);
|
||||
if (!theSound) {
|
||||
return;
|
||||
}
|
||||
HLock(theSound);
|
||||
|
||||
/*
|
||||
* Set up the synth
|
||||
*/
|
||||
if (SndNewChannel(&theChannel, sampledSynth, initMono +
|
||||
initNoInterp, (void *) 0) == noErr) {
|
||||
char midi_note [] = {57, 59, 60, 62, 64, 65, 67};
|
||||
/*
|
||||
* Set up the synth
|
||||
*/
|
||||
if (SndNewChannel(&theChannel, sampledSynth, initMono + initNoInterp,
|
||||
(void *) 0) == noErr) {
|
||||
char midi_note[] = { 57, 59, 60, 62, 64, 65, 67 };
|
||||
|
||||
short err;
|
||||
short snd_len = SND_LEN (theSound) / 18;
|
||||
short err;
|
||||
short snd_len = SND_LEN(theSound) / 18;
|
||||
|
||||
theCmd.cmd = soundCmd;
|
||||
theCmd.param1 = 0;
|
||||
theCmd.param2 = (long) SND_BUFFER (theSound);
|
||||
err = SndDoCommand (theChannel, &theCmd, false);
|
||||
theCmd.cmd = soundCmd;
|
||||
theCmd.param1 = 0;
|
||||
theCmd.param2 = (long) SND_BUFFER(theSound);
|
||||
err = SndDoCommand(theChannel, &theCmd, false);
|
||||
|
||||
/*
|
||||
* We rack 'em up all in a row
|
||||
* The mac will play them correctly and then end, since
|
||||
* we do a sync close below.
|
||||
*
|
||||
*/
|
||||
while (*melody && ! err) {
|
||||
while (*melody > 'G') {
|
||||
*melody -= 8;
|
||||
}
|
||||
while (*melody < 'A') {
|
||||
*melody += 8;
|
||||
}
|
||||
theCmd.cmd = freqDurationCmd;
|
||||
theCmd.param1 = snd_len;
|
||||
theCmd.param2 = midi_note [*melody - 'A'];
|
||||
err = SndDoCommand (theChannel, &theCmd, false);
|
||||
melody ++;
|
||||
}
|
||||
SndDisposeChannel (theChannel, false); /* Sync wait for completion */
|
||||
ReleaseResource (theSound);
|
||||
}
|
||||
/*
|
||||
* We rack 'em up all in a row
|
||||
* The mac will play them correctly and then end, since
|
||||
* we do a sync close below.
|
||||
*
|
||||
*/
|
||||
while (*melody && !err) {
|
||||
while (*melody > 'G') {
|
||||
*melody -= 8;
|
||||
}
|
||||
while (*melody < 'A') {
|
||||
*melody += 8;
|
||||
}
|
||||
theCmd.cmd = freqDurationCmd;
|
||||
theCmd.param1 = snd_len;
|
||||
theCmd.param2 = midi_note[*melody - 'A'];
|
||||
err = SndDoCommand(theChannel, &theCmd, false);
|
||||
melody++;
|
||||
}
|
||||
SndDisposeChannel(theChannel, false); /* Sync wait for completion */
|
||||
ReleaseResource(theSound);
|
||||
}
|
||||
}
|
||||
|
||||
void tty_nhbell (void) {
|
||||
Handle h = GetNamedResource ('snd ', "\pNetHack Bell");
|
||||
void
|
||||
tty_nhbell(void)
|
||||
{
|
||||
Handle h = GetNamedResource('snd ', "\pNetHack Bell");
|
||||
|
||||
if (h) {
|
||||
HLock (h);
|
||||
SndPlay ((SndChannelPtr) 0, (SndListHandle) h, 0);
|
||||
ReleaseResource (h);
|
||||
} else
|
||||
SysBeep (30);
|
||||
if (h) {
|
||||
HLock(h);
|
||||
SndPlay((SndChannelPtr) 0, (SndListHandle) h, 0);
|
||||
ReleaseResource(h);
|
||||
} else
|
||||
SysBeep(30);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 mactopl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 mactopl.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
|
||||
/* NetHack 3.6 mactopl.c $Date: 2009/05/06 10:49:14 $ $Revision: 1.5 $ */
|
||||
/* SCCS Id: @(#)mactopl.c 3.5 1991/07/23 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -10,48 +10,48 @@
|
||||
#include "macpopup.h"
|
||||
|
||||
char
|
||||
queued_resp(char *resp) {
|
||||
char buf[30];
|
||||
if (try_key_queue(buf)) {
|
||||
if (!resp || strchr(resp, buf[0]))
|
||||
return buf[0];
|
||||
if (digit(buf[0]) && strchr(resp, '#')) {
|
||||
yn_number = atoi(buf);
|
||||
return '#';
|
||||
}
|
||||
}
|
||||
return '\0';
|
||||
queued_resp(char *resp)
|
||||
{
|
||||
char buf[30];
|
||||
if (try_key_queue(buf)) {
|
||||
if (!resp || strchr(resp, buf[0]))
|
||||
return buf[0];
|
||||
if (digit(buf[0]) && strchr(resp, '#')) {
|
||||
yn_number = atoi(buf);
|
||||
return '#';
|
||||
}
|
||||
}
|
||||
return '\0';
|
||||
}
|
||||
|
||||
|
||||
char
|
||||
topl_yn_function(const char *query, const char *resp, char def) {
|
||||
char buf[30];
|
||||
char c = queued_resp((char *) resp);
|
||||
if (!c) {
|
||||
enter_topl_mode((char *) query);
|
||||
topl_set_resp((char *) resp, def);
|
||||
topl_yn_function(const char *query, const char *resp, char def)
|
||||
{
|
||||
char buf[30];
|
||||
char c = queued_resp((char *) resp);
|
||||
if (!c) {
|
||||
enter_topl_mode((char *) query);
|
||||
topl_set_resp((char *) resp, def);
|
||||
|
||||
do {
|
||||
c = readchar();
|
||||
if (c && resp && !strchr(resp, c)) {
|
||||
nhbell();
|
||||
c = '\0';
|
||||
}
|
||||
} while (!c);
|
||||
do {
|
||||
c = readchar();
|
||||
if (c && resp && !strchr(resp, c)) {
|
||||
nhbell();
|
||||
c = '\0';
|
||||
}
|
||||
} while (!c);
|
||||
|
||||
topl_set_resp("", '\0');
|
||||
leave_topl_mode(buf);
|
||||
if (c == '#')
|
||||
yn_number = atoi(buf);
|
||||
}
|
||||
return c;
|
||||
topl_set_resp("", '\0');
|
||||
leave_topl_mode(buf);
|
||||
if (c == '#')
|
||||
yn_number = atoi(buf);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
char
|
||||
mac_yn_function(query, resp, def)
|
||||
const char *query,*resp;
|
||||
const char *query, *resp;
|
||||
char def;
|
||||
/*
|
||||
* Generic yes/no function. 'def' is the default (returned by space or
|
||||
@@ -61,7 +61,7 @@ char def;
|
||||
* If resp is NULL, any single character is accepted and returned.
|
||||
*/
|
||||
{
|
||||
return topl_yn_function(query, resp, def);
|
||||
return topl_yn_function(query, resp, def);
|
||||
}
|
||||
|
||||
/* mactopl.c */
|
||||
|
||||
1599
sys/mac/mactty.c
1599
sys/mac/mactty.c
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 macunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 macunix.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
|
||||
/* NetHack 3.6 macunix.c $Date: 2009/05/06 10:49:16 $ $Revision: 1.6 $ */
|
||||
/* SCCS Id: @(#)macunix.c 3.5 1994/11/07 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -11,31 +11,31 @@
|
||||
void
|
||||
regularize(char *s)
|
||||
{
|
||||
register char *lp;
|
||||
register char *lp;
|
||||
|
||||
for (lp = s; *lp; lp++) {
|
||||
if (*lp == '.' || *lp == ':')
|
||||
*lp = '_';
|
||||
}
|
||||
for (lp = s; *lp; lp++) {
|
||||
if (*lp == '.' || *lp == ':')
|
||||
*lp = '_';
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
getlock(void)
|
||||
{
|
||||
int fd;
|
||||
int pid = getpid(); /* Process ID */
|
||||
int fd;
|
||||
int pid = getpid(); /* Process ID */
|
||||
|
||||
Sprintf(lock, "%d%s", getuid(), plname);
|
||||
set_levelfile_name (lock, 0);
|
||||
Sprintf(lock, "%d%s", getuid(), plname);
|
||||
set_levelfile_name(lock, 0);
|
||||
|
||||
if ((fd = open (lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
|
||||
raw_printf ("Could not lock the game %s.", lock);
|
||||
panic ("Another game in progress?");
|
||||
}
|
||||
if ((fd = open(lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
|
||||
raw_printf("Could not lock the game %s.", lock);
|
||||
panic("Another game in progress?");
|
||||
}
|
||||
|
||||
if (write (fd, (char *)&pid, sizeof (pid)) != sizeof (pid)) {
|
||||
raw_printf ("Could not lock the game %s.", lock);
|
||||
panic("Disk locked?");
|
||||
}
|
||||
close (fd);
|
||||
if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) {
|
||||
raw_printf("Could not lock the game %s.", lock);
|
||||
panic("Disk locked?");
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
4173
sys/mac/macwin.c
4173
sys/mac/macwin.c
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 mgetline.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 mgetline.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
|
||||
/* NetHack 3.6 mgetline.c $Date: 2009/05/06 10:49:18 $ $Revision: 1.6 $ */
|
||||
/* SCCS Id: @(#)getline.c 3.5 1990/22/02 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -10,38 +10,38 @@
|
||||
#include "macpopup.h"
|
||||
#include "func_tab.h"
|
||||
|
||||
extern int NDECL(extcmd_via_menu); /* cmd.c */
|
||||
extern int NDECL(extcmd_via_menu); /* cmd.c */
|
||||
|
||||
typedef Boolean FDECL ((* key_func), (unsigned char));
|
||||
typedef Boolean FDECL((*key_func), (unsigned char));
|
||||
|
||||
int
|
||||
get_line_from_key_queue (char * bufp) {
|
||||
* bufp = 0;
|
||||
if (try_key_queue (bufp)) {
|
||||
while (* bufp) {
|
||||
if (* bufp == 10 || * bufp == 13) {
|
||||
* bufp = 0;
|
||||
}
|
||||
bufp ++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
get_line_from_key_queue(char *bufp)
|
||||
{
|
||||
*bufp = 0;
|
||||
if (try_key_queue(bufp)) {
|
||||
while (*bufp) {
|
||||
if (*bufp == 10 || *bufp == 13) {
|
||||
*bufp = 0;
|
||||
}
|
||||
bufp++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
topl_getlin(const char *query, char *bufp, Boolean ext) {
|
||||
if (get_line_from_key_queue (bufp))
|
||||
return;
|
||||
topl_getlin(const char *query, char *bufp, Boolean ext)
|
||||
{
|
||||
if (get_line_from_key_queue(bufp))
|
||||
return;
|
||||
|
||||
enter_topl_mode((char *) query);
|
||||
while (topl_key(nhgetch(), ext))
|
||||
;
|
||||
leave_topl_mode(bufp);
|
||||
enter_topl_mode((char *) query);
|
||||
while (topl_key(nhgetch(), ext))
|
||||
;
|
||||
leave_topl_mode(bufp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read a line closed with '\n' into the array char bufp[BUFSZ].
|
||||
* (The '\n' is not stored. The string is closed with a '\0'.)
|
||||
@@ -49,28 +49,31 @@ topl_getlin(const char *query, char *bufp, Boolean ext) {
|
||||
* resulting string is "\033".
|
||||
*/
|
||||
void
|
||||
mac_getlin(const char *query, char *bufp) {
|
||||
topl_getlin (query, bufp, false);
|
||||
mac_getlin(const char *query, char *bufp)
|
||||
{
|
||||
topl_getlin(query, bufp, false);
|
||||
}
|
||||
|
||||
|
||||
/* Read in an extended command - doing command line completion for
|
||||
* when enough characters have been entered to make a unique command.
|
||||
* This is just a modified getlin() followed by a lookup. -jsb
|
||||
*/
|
||||
int
|
||||
mac_get_ext_cmd() {
|
||||
char bufp[BUFSZ];
|
||||
int i;
|
||||
mac_get_ext_cmd()
|
||||
{
|
||||
char bufp[BUFSZ];
|
||||
int i;
|
||||
|
||||
if (iflags.extmenu) return extcmd_via_menu();
|
||||
topl_getlin("# ", bufp, true);
|
||||
for (i = 0; extcmdlist[i].ef_txt != (char *)0; i++)
|
||||
if (!strcmp(bufp, extcmdlist[i].ef_txt)) break;
|
||||
if (extcmdlist[i].ef_txt == (char *)0) i = -1; /* not found */
|
||||
if (iflags.extmenu)
|
||||
return extcmd_via_menu();
|
||||
topl_getlin("# ", bufp, true);
|
||||
for (i = 0; extcmdlist[i].ef_txt != (char *) 0; i++)
|
||||
if (!strcmp(bufp, extcmdlist[i].ef_txt))
|
||||
break;
|
||||
if (extcmdlist[i].ef_txt == (char *) 0)
|
||||
i = -1; /* not found */
|
||||
|
||||
return i;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/* macgetline.c */
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
/* NetHack 3.6 mmodal.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 mmodal.c $NHDT-Date: 1431192785 2015/05/09 17:33:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
|
||||
/* NetHack 3.6 mmodal.c $Date: 2009/05/06 10:49:18 $ $Revision: 1.7 $ */
|
||||
/* SCCS Id: @(#)mmodal.c 3.5 1993/01/24 */
|
||||
/* Copyright (c) Jon W{tte, Hao-Yang Wang, Jonathan Handler 1992. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
#if 1 /*!TARGET_API_MAC_CARBON*/
|
||||
# include <Dialogs.h>
|
||||
# include <ControlDefinitions.h>
|
||||
#include <Dialogs.h>
|
||||
#include <ControlDefinitions.h>
|
||||
#else
|
||||
# include <Carbon/Carbon.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
#include "macpopup.h"
|
||||
|
||||
/* Flash a dialog button when its accelerator key is pressed */
|
||||
void
|
||||
FlashButton(DialogRef wind, short item) {
|
||||
short type;
|
||||
Handle handle;
|
||||
Rect rect;
|
||||
unsigned long ticks;
|
||||
FlashButton(DialogRef wind, short item)
|
||||
{
|
||||
short type;
|
||||
Handle handle;
|
||||
Rect rect;
|
||||
unsigned long ticks;
|
||||
|
||||
/* Apple recommends 8 ticks */
|
||||
GetDialogItem(wind, item, &type, &handle, &rect);
|
||||
HiliteControl((ControlHandle)handle, kControlButtonPart);
|
||||
Delay(8, &ticks);
|
||||
HiliteControl((ControlHandle)handle, 0);
|
||||
return;
|
||||
/* Apple recommends 8 ticks */
|
||||
GetDialogItem(wind, item, &type, &handle, &rect);
|
||||
HiliteControl((ControlHandle) handle, kControlButtonPart);
|
||||
Delay(8, &ticks);
|
||||
HiliteControl((ControlHandle) handle, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1803
sys/mac/mrecover.c
1803
sys/mac/mrecover.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user