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:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions

View File

@@ -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*/