diff --git a/include/decl.h b/include/decl.h index adbb92322..aa5012734 100644 --- a/include/decl.h +++ b/include/decl.h @@ -98,7 +98,7 @@ E NEARDATA char tune[6]; #define MAXLINFO (MAXDUNGEON * MAXLEVEL) -E NEARDATA struct sinfo { +struct sinfo { int gameover; /* self explanatory? */ int stopprint; /* inhibit further end of game disclosure */ #ifdef HANGUPHANDLING @@ -115,7 +115,7 @@ E NEARDATA struct sinfo { int in_paniclog; #endif int wizkit_wishing; -} program_state; +}; E const char quitchars[]; E const char vowels[]; @@ -713,6 +713,7 @@ struct instance_globals { const char *alllevels = "levels.*"; const char *allbones = "bones*.*"; #endif + struct sinfo program_state; /* dig.c */ diff --git a/src/allmain.c b/src/allmain.c index f68437ce1..7bb088b38 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -72,10 +72,10 @@ boolean resuming; g.youmonst.movement = NORMAL_SPEED; /* give the hero some movement points */ g.context.move = 0; - program_state.in_moveloop = 1; + g.program_state.in_moveloop = 1; for (;;) { #ifdef SAFERHANGUP - if (program_state.done_hup) + if (g.program_state.done_hup) end_of_input(); #endif get_nh_event(); @@ -623,7 +623,7 @@ newgame() #ifdef INSURANCE save_currentstate(); #endif - program_state.something_worth_saving++; /* useful data now exists */ + g.program_state.something_worth_saving++; /* useful data now exists */ /* Success! */ welcome(TRUE); diff --git a/src/cmd.c b/src/cmd.c index fcaea4670..c61e81de6 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4475,7 +4475,7 @@ register char *cmd; iflags.menu_requested = FALSE; #ifdef SAFERHANGUP - if (program_state.done_hup) + if (g.program_state.done_hup) end_of_input(); #endif if (firsttime) { @@ -5612,8 +5612,8 @@ void hangup(sig_unused) /* called as signal() handler, so sent at least one arg */ int sig_unused UNUSED; { - if (program_state.exiting) - program_state.in_moveloop = 0; + if (g.program_state.exiting) + g.program_state.in_moveloop = 0; nhwindows_hangup(); #ifdef SAFERHANGUP /* When using SAFERHANGUP, the done_hup flag it tested in rhack @@ -5622,9 +5622,9 @@ int sig_unused UNUSED; protects against losing objects in the process of being thrown, but also potentially riskier because the disconnected program must continue running longer before attempting a hangup save. */ - program_state.done_hup++; + g.program_state.done_hup++; /* defer hangup iff game appears to be in progress */ - if (program_state.in_moveloop && program_state.something_worth_saving) + if (g.program_state.in_moveloop && g.program_state.something_worth_saving) return; #endif /* SAFERHANGUP */ end_of_input(); @@ -5635,16 +5635,16 @@ end_of_input() { #ifdef NOSAVEONHANGUP #ifdef INSURANCE - if (flags.ins_chkpt && program_state.something_worth_saving) + if (flags.ins_chkpt && g.program_state.something_worth_saving) program_statue.preserve_locks = 1; /* keep files for recovery */ #endif - program_state.something_worth_saving = 0; /* don't save */ + g.program_state.something_worth_saving = 0; /* don't save */ #endif #ifndef SAFERHANGUP - if (!program_state.done_hup++) + if (!g.program_state.done_hup++) #endif - if (program_state.something_worth_saving) + if (g.program_state.something_worth_saving) (void) dosave0(); if (iflags.window_inited) exit_nhwindows((char *) 0); diff --git a/src/decl.c b/src/decl.c index abdbc3188..34bb2ad0c 100644 --- a/src/decl.c +++ b/src/decl.c @@ -5,8 +5,6 @@ #include "hack.h" -/* from xxxmain.c */ - const char quitchars[] = " \r\n\033"; const char vowels[] = "aeiouAEIOU"; const char ynchars[] = "yn"; @@ -17,8 +15,6 @@ NEARDATA long yn_number = 0L; const char disclosure_options[] = "iavgco"; -NEARDATA struct sinfo program_state; - /* x/y/z deltas for the 10 movement directions (8 compass pts, 2 up/down) */ const schar xdir[10] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 }; const schar ydir[10] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 }; @@ -108,9 +104,7 @@ const char *materialnm[] = { "mysterious", "liquid", "wax", "organic", "gemstone", "stone" }; /* Global windowing data, defined here for multi-window-system support */ -NEARDATA winid WIN_MESSAGE = WIN_ERR; -NEARDATA winid WIN_STATUS = WIN_ERR; -NEARDATA winid WIN_MAP = WIN_ERR, WIN_INVEN = WIN_ERR; +NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN; #ifdef PREFIXES_IN_USE const char *fqn_prefix_names[PREFIX_COUNT] = { @@ -296,6 +290,7 @@ const struct instance_globals g_init = { "levels.*", /* alllevels */ "bones*.*", /* allbones */ #endif + UNDEFINED_VALUES, /* program_state */ /* dig.c */ UNDEFINED_VALUE, /* did_dig_msg */ @@ -628,6 +623,9 @@ decl_globals_init() uarmh = uarms = uarmg = uarmf = uamul = uright = uleft = NULL; ublindf = uchain = uball = NULL; + WIN_MESSAGE = WIN_STATUS = WIN_MAP = WIN_INVEN = WIN_ERR; + + } /*decl.c*/ diff --git a/src/display.c b/src/display.c index 0ba3f4c01..7e9f98814 100644 --- a/src/display.c +++ b/src/display.c @@ -719,7 +719,7 @@ register int x, y; if (g.in_mklev) return; #ifdef HANGUPHANDLING - if (program_state.done_hup) + if (g.program_state.done_hup) return; #endif @@ -1561,7 +1561,7 @@ int cursor_on_u; return; /* if already flushing then return */ flushing = 1; #ifdef HANGUPHANDLING - if (program_state.done_hup) + if (g.program_state.done_hup) return; #endif diff --git a/src/do.c b/src/do.c index 0440c4891..c3779b369 100644 --- a/src/do.c +++ b/src/do.c @@ -744,7 +744,7 @@ struct obj *obj; */ if (!obj->oerodeproof || !rn2(10)) { /* if monsters aren't moving, assume player is responsible */ - if (!g.context.mon_moving && !program_state.gameover) + if (!g.context.mon_moving && !g.program_state.gameover) costly_alteration(obj, COST_DEGRD); obj->otyp = WORM_TOOTH; obj->oerodeproof = 0; diff --git a/src/do_name.c b/src/do_name.c index 56f997d4c..a7d680bf8 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1622,7 +1622,7 @@ boolean called; boolean name_at_start, has_adjectives; char *bp; - if (program_state.gameover) + if (g.program_state.gameover) suppress |= SUPPRESS_HALLUCINATION; if (article == ARTICLE_YOUR && !mtmp->mtame) article = ARTICLE_THE; @@ -1630,7 +1630,7 @@ boolean called; do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION); do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE); do_it = !canspotmon(mtmp) && article != ARTICLE_YOUR - && !program_state.gameover && mtmp != u.usteed + && !g.program_state.gameover && mtmp != u.usteed && !(u.uswallow && mtmp == u.ustuck) && !(suppress & SUPPRESS_IT); do_saddle = !(suppress & SUPPRESS_SADDLE); do_name = !(suppress & SUPPRESS_NAME) || type_is_pname(mdat); diff --git a/src/end.c b/src/end.c index d8edcb030..1f0eb0d8f 100644 --- a/src/end.c +++ b/src/end.c @@ -49,7 +49,7 @@ extern void FDECL(nethack_exit, (int)); #define nethack_exit exit #endif -#define done_stopprint program_state.stopprint +#define done_stopprint g.program_state.stopprint #ifndef PANICTRACE #define NH_abort NH_abort_ @@ -380,7 +380,7 @@ static void done_hangup(sig) int sig; { - program_state.done_hup++; + g.program_state.done_hup++; sethanguphandler((void FDECL((*), (int) )) SIG_IGN); done_intr(sig); return; @@ -545,7 +545,7 @@ VA_DECL(const char *, str) VA_START(str); VA_INIT(str, char *); - if (program_state.panicking++) + if (g.program_state.panicking++) NH_abort(); /* avoid loops - this should never happen*/ if (iflags.window_inited) { @@ -555,9 +555,9 @@ VA_DECL(const char *, str) iflags.window_inited = 0; /* they're gone; force raw_print()ing */ } - raw_print(program_state.gameover + raw_print(g.program_state.gameover ? "Postgame wrapup disrupted." - : !program_state.something_worth_saving + : !g.program_state.something_worth_saving ? "Program initialization has failed." : "Suddenly, the dungeon collapses."); #ifndef MICRO @@ -565,11 +565,11 @@ VA_DECL(const char *, str) if (!wizard) raw_printf("Report the following error to \"%s\" or at \"%s\".", DEVTEAM_EMAIL, DEVTEAM_URL); - else if (program_state.something_worth_saving) + else if (g.program_state.something_worth_saving) raw_print("\nError save file being written.\n"); #else /* !NOTIFY_NETHACK_BUGS */ if (!wizard) { - const char *maybe_rebuild = !program_state.something_worth_saving + const char *maybe_rebuild = !g.program_state.something_worth_saving ? "." : "\nand it may be possible to rebuild."; @@ -587,7 +587,7 @@ VA_DECL(const char *, str) /* XXX can we move this above the prints? Then we'd be able to * suppress "it may be possible to rebuild" based on dosave0() * or say it's NOT possible to rebuild. */ - if (program_state.something_worth_saving && !iflags.debug_fuzzer) { + if (g.program_state.something_worth_saving && !iflags.debug_fuzzer) { set_error_savefile(); if (dosave0()) { /* os/win port specific recover instructions */ @@ -1018,9 +1018,9 @@ int how; return; } } - if (program_state.panicking + if (g.program_state.panicking #ifdef HANGUPHANDLING - || program_state.done_hup + || g.program_state.done_hup #endif ) { /* skip status update if panicking or disconnected */ @@ -1032,7 +1032,7 @@ int how; } if (iflags.debug_fuzzer) { - if (!(program_state.panicking || how == PANICKED)) { + if (!(g.program_state.panicking || how == PANICKED)) { savelife(how); /* periodically restore characteristics and lost exp levels or cure lycanthropy */ @@ -1123,9 +1123,9 @@ int how; /* * The game is now over... */ - program_state.gameover = 1; + g.program_state.gameover = 1; /* in case of a subsequent panic(), there's no point trying to save */ - program_state.something_worth_saving = 0; + g.program_state.something_worth_saving = 0; /* render vision subsystem inoperative */ iflags.vision_inited = 0; @@ -1611,13 +1611,13 @@ void nh_terminate(status) int status; { - program_state.in_moveloop = 0; /* won't be returning to normal play */ + g.program_state.in_moveloop = 0; /* won't be returning to normal play */ #ifdef MAC getreturn("to exit"); #endif /* don't bother to try to release memory if we're in panic mode, to avoid trouble in case that happens to be due to memory problems */ - if (!program_state.panicking) { + if (!g.program_state.panicking) { freedynamicdata(); dlb_cleanup(); } @@ -1630,10 +1630,10 @@ int status; */ /* don't call exit() if already executing within an exit handler; that would cancel any other pending user-mode handlers */ - if (program_state.exiting) + if (g.program_state.exiting) return; #endif - program_state.exiting = 1; + g.program_state.exiting = 1; nethack_exit(status); } diff --git a/src/files.c b/src/files.c index f0e271a1a..14daab94a 100644 --- a/src/files.c +++ b/src/files.c @@ -577,7 +577,7 @@ void clearlocks() { #ifdef HANGUPHANDLING - if (program_state.preserve_locks) + if (g.program_state.preserve_locks) return; #endif #if !defined(PC_LOCKING) && defined(MFLOPPY) && !defined(AMIGA) @@ -1611,7 +1611,7 @@ static int lockfd; /* for lock_file() to pass to unlock_file() */ struct flock sflock; /* for unlocking, same as above */ #endif -#define HUP if (!program_state.done_hup) +#define HUP if (!g.program_state.done_hup) #ifndef USE_FCNTL STATIC_OVL char * @@ -2341,13 +2341,13 @@ char *origbuf; *ptr = '\0'; #ifdef MFLOPPY if (*(ptr + 1) == 'n' || *(ptr + 1) == 'N') { - g.g.saveprompt = FALSE; + g.saveprompt = FALSE; } #endif } #if defined(SYSFLAGS) && defined(MFLOPPY) else - g.g.g.saveprompt = sysflags.asksavedisk; + g.saveprompt = sysflags.asksavedisk; #endif (void) strncpy(SAVEP, bufp, SAVESIZE - 1); @@ -2974,14 +2974,14 @@ read_wizkit() if (!wizard || !(fp = fopen_wizkit_file())) return; - program_state.wizkit_wishing = 1; + g.program_state.wizkit_wishing = 1; config_error_init(TRUE, "WIZKIT", FALSE); parse_conf_file(fp, proc_wizkit_line); (void) fclose(fp); config_error_done(); - program_state.wizkit_wishing = 0; + g.program_state.wizkit_wishing = 0; return; } @@ -3531,8 +3531,8 @@ const char *reason; /* explanation */ FILE *lfile; char buf[BUFSZ]; - if (!program_state.in_paniclog) { - program_state.in_paniclog = 1; + if (!g.program_state.in_paniclog) { + g.program_state.in_paniclog = 1; lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX); if (lfile) { #ifdef PANICLOG_FMT2 @@ -3550,7 +3550,7 @@ const char *reason; /* explanation */ #endif /* !PANICLOG_FMT2 */ (void) fclose(lfile); } - program_state.in_paniclog = 0; + g.program_state.in_paniclog = 0; } #endif /* PANICLOG */ return; diff --git a/src/invent.c b/src/invent.c index d4d9a48c1..cb6a483e8 100644 --- a/src/invent.c +++ b/src/invent.c @@ -220,7 +220,7 @@ struct obj *obj; if (wizard) { /* flags.debug */ /* paranoia: before toggling off wizard mode, guard against a panic in xname() producing a normal mode panic save file */ - program_state.something_worth_saving = 0; + g.program_state.something_worth_saving = 0; flags.debug = FALSE; } @@ -228,7 +228,7 @@ struct obj *obj; if (save_debug) { flags.debug = TRUE; - program_state.something_worth_saving = 1; + g.program_state.something_worth_saving = 1; } /* restore the object */ if (obj->oclass == POTION_CLASS) { diff --git a/src/mon.c b/src/mon.c index 52cbb2c91..ed915cb03 100644 --- a/src/mon.c +++ b/src/mon.c @@ -739,7 +739,7 @@ movemon() if (u.utotype #ifdef SAFERHANGUP /* or if the program has lost contact with the user */ - || program_state.done_hup + || g.program_state.done_hup #endif ) { somebody_can_move = FALSE; diff --git a/src/o_init.c b/src/o_init.c index 482010ae3..2f37afba6 100644 --- a/src/o_init.c +++ b/src/o_init.c @@ -360,7 +360,7 @@ boolean credit_hero; exercise(A_WIS, TRUE); } /* moves==1L => initial inventory, gameover => final disclosure */ - if (g.moves > 1L && !program_state.gameover) { + if (g.moves > 1L && !g.program_state.gameover) { if (objects[oindx].oc_class == GEM_CLASS) gem_learned(oindx); /* could affect price of unpaid gems */ update_inventory(); diff --git a/src/objnam.c b/src/objnam.c index cfa65b4b3..2dca18cac 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -204,7 +204,7 @@ struct obj *obj; { if (!obj->oartifact || !has_oname(obj)) return FALSE; - if (!program_state.gameover && !iflags.override_ID) { + if (!g.program_state.gameover && !iflags.override_ID) { if (not_fully_identified(obj)) return FALSE; } @@ -692,7 +692,7 @@ unsigned cxn_flags; /* bitmask of CXN_xxx values */ if (pluralize) Strcpy(buf, makeplural(buf)); - if (obj->otyp == T_SHIRT && program_state.gameover) { + if (obj->otyp == T_SHIRT && g.program_state.gameover) { char tmpbuf[BUFSZ]; Sprintf(eos(buf), " with text \"%s\"", tshirt_text(obj, tmpbuf)); @@ -3550,7 +3550,7 @@ srch: * Disallow such topology tweaks for WIZKIT startup wishes. */ wiztrap: - if (wizard && !program_state.wizkit_wishing) { + if (wizard && !g.program_state.wizkit_wishing) { struct rm *lev; int trap, x = u.ux, y = u.uy; diff --git a/src/pline.c b/src/pline.c index 26ae18c5b..b1abb4c01 100644 --- a/src/pline.c +++ b/src/pline.c @@ -103,10 +103,10 @@ VA_DECL(const char *, line) if (!line || !*line) return; #ifdef HANGUPHANDLING - if (program_state.done_hup) + if (g.program_state.done_hup) return; #endif - if (program_state.wizkit_wishing) + if (g.program_state.wizkit_wishing) return; if (index(line, '%')) { @@ -445,10 +445,10 @@ VA_DECL(const char *, s) VA_START(s); VA_INIT(s, const char *); - if (program_state.in_impossible) + if (g.program_state.in_impossible) panic("impossible called impossible"); - program_state.in_impossible = 1; + g.program_state.in_impossible = 1; Vsprintf(pbuf, s, VA_ARGS); pbuf[BUFSZ - 1] = '\0'; /* sanity */ paniclog("impossible", pbuf); @@ -457,11 +457,11 @@ VA_DECL(const char *, s) pline("%s", VA_PASS1(pbuf)); /* reuse pbuf[] */ Strcpy(pbuf, "Program in disorder!"); - if (program_state.something_worth_saving) + if (g.program_state.something_worth_saving) Strcat(pbuf, " (Saving and reloading may fix this problem.)"); pline("%s", VA_PASS1(pbuf)); - program_state.in_impossible = 0; + g.program_state.in_impossible = 0; VA_END(); } diff --git a/src/priest.c b/src/priest.c index 26e981f08..2c0c67913 100644 --- a/src/priest.c +++ b/src/priest.c @@ -335,7 +335,7 @@ char *pname; /* caller-supplied output buffer */ Strcat(pname, what); /* same as distant_monnam(), more or less... */ if (do_hallu || !high_priest || !Is_astralevel(&u.uz) - || distu(mon->mx, mon->my) <= 2 || program_state.gameover) { + || distu(mon->mx, mon->my) <= 2 || g.program_state.gameover) { Strcat(pname, " of "); Strcat(pname, halu_gname(mon_aligntyp(mon))); } diff --git a/src/questpgr.c b/src/questpgr.c index 1799ce8de..26dc238d6 100644 --- a/src/questpgr.c +++ b/src/questpgr.c @@ -574,7 +574,7 @@ skip_pager(common) boolean common; { /* WIZKIT: suppress plot feedback if starting with quest artifact */ - if (program_state.wizkit_wishing) + if (g.program_state.wizkit_wishing) return TRUE; if (!(common ? g.qt_list.common : g.qt_list.chrole)) { panic("%s: no %s quest text data available", diff --git a/src/restore.c b/src/restore.c index 61b7d6057..e059384ad 100644 --- a/src/restore.c +++ b/src/restore.c @@ -888,7 +888,7 @@ register int fd; reset_restpref(); restlevelstate(stuckid, steedid); - program_state.something_worth_saving = 1; /* useful data now exists */ + g.program_state.something_worth_saving = 1; /* useful data now exists */ if (!wizard && !discover) (void) delete_savefile(); diff --git a/src/rumors.c b/src/rumors.c index 3d64203d1..eeb47e9e3 100644 --- a/src/rumors.c +++ b/src/rumors.c @@ -544,16 +544,16 @@ STATIC_OVL void couldnt_open_file(filename) const char *filename; { - int save_something = program_state.something_worth_saving; + int save_something = g.program_state.something_worth_saving; /* most likely the file is missing, so suppress impossible()'s "saving and restoring might fix this" (unless the fuzzer, which escalates impossible to panic, is running) */ if (!iflags.debug_fuzzer) - program_state.something_worth_saving = 0; + g.program_state.something_worth_saving = 0; impossible("Can't open '%s' file.", filename); - program_state.something_worth_saving = save_something; + g.program_state.something_worth_saving = save_something; } /*rumors.c*/ diff --git a/src/save.c b/src/save.c index 41851abae..dd7915790 100644 --- a/src/save.c +++ b/src/save.c @@ -66,7 +66,7 @@ static struct save_procs { }; #if defined(UNIX) || defined(VMS) || defined(__EMX__) || defined(WIN32) -#define HUP if (!program_state.done_hup) +#define HUP if (!g.program_state.done_hup) #else #define HUP #endif @@ -85,7 +85,7 @@ dosave() clear_nhwindow(WIN_MESSAGE); pline("Saving..."); #if defined(UNIX) || defined(VMS) || defined(__EMX__) - program_state.done_hup = 0; + g.program_state.done_hup = 0; #endif if (dosave0()) { u.uhp = -1; /* universal game's over indicator */ @@ -120,7 +120,7 @@ dosave0() if (iflags.save_uburied) u.uburied = 1, iflags.save_uburied = 0; - if (!program_state.something_worth_saving || !SAVEF[0]) + if (!g.program_state.something_worth_saving || !SAVEF[0]) return 0; fq_save = fqname(SAVEF, SAVEPREFIX, 1); /* level files take 0 */ @@ -269,7 +269,7 @@ dosave0() delete_levelfile(0); nh_compress(fq_save); /* this should probably come sooner... */ - program_state.something_worth_saving = 0; + g.program_state.something_worth_saving = 0; return 1; } @@ -726,7 +726,7 @@ register unsigned num; if (failed) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) + if (g.program_state.done_hup) nh_terminate(EXIT_FAILURE); else #endif @@ -832,7 +832,7 @@ register int fd; if (outbufp) { if (write(fd, outbuf, outbufp) != outbufp) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) + if (g.program_state.done_hup) nh_terminate(EXIT_FAILURE); else #endif @@ -858,7 +858,7 @@ register unsigned num; #endif if ((unsigned) write(fd, loc, num) != num) { #if defined(UNIX) || defined(VMS) || defined(__EMX__) - if (program_state.done_hup) + if (g.program_state.done_hup) nh_terminate(EXIT_FAILURE); else #endif diff --git a/src/shknam.c b/src/shknam.c index 91c5d12e7..5bec59922 100644 --- a/src/shknam.c +++ b/src/shknam.c @@ -851,7 +851,7 @@ struct monst *mtmp; } else { const char *shknm = ESHK(mtmp)->shknam; - if (Hallucination && !program_state.gameover) { + if (Hallucination && !g.program_state.gameover) { const char *const *nlp; int num; diff --git a/src/topten.c b/src/topten.c index 03a32f094..66b56a2d1 100644 --- a/src/topten.c +++ b/src/topten.c @@ -27,7 +27,7 @@ static long final_fpos; #endif -#define done_stopprint program_state.stopprint +#define done_stopprint g.program_state.stopprint #define newttentry() (struct toptenentry *) alloc(sizeof (struct toptenentry)) #define dealloc_ttentry(ttent) free((genericptr_t) (ttent)) @@ -511,7 +511,7 @@ time_t when; * topten uses alloc() several times, which will lead to * problems if the panic was the result of an alloc() failure. */ - if (program_state.panicking) + if (g.program_state.panicking) return; if (iflags.toptenwin) { @@ -519,7 +519,7 @@ time_t when; } #if defined(UNIX) || defined(VMS) || defined(__EMX__) -#define HUP if (!program_state.done_hup) +#define HUP if (!g.program_state.done_hup) #else #define HUP #endif diff --git a/src/vision.c b/src/vision.c index 7e2f5cdb8..9b3294fe5 100644 --- a/src/vision.c +++ b/src/vision.c @@ -812,9 +812,9 @@ skip: /* This newsym() caused a crash delivering msg about failure to open * dungeon file init_dungeons() -> panic() -> done(11) -> * vision_recalc(2) -> newsym() -> crash! u.ux and u.uy are 0 and - * program_state.panicking == 1 under those circumstances + * g.program_state.panicking == 1 under those circumstances */ - if (!program_state.panicking) + if (!g.program_state.panicking) newsym(u.ux, u.uy); /* Make sure the hero shows up! */ /* Set the new min and max pointers. */ diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 90950ad28..b2a37d77a 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -191,7 +191,7 @@ char *argv[]; * It seems you really want to play. */ u.uhp = 1; /* prevent RIP on early quits */ - program_state.preserve_locks = 1; + g.program_state.preserve_locks = 1; #ifndef NO_SIGNAL sethanguphandler((SIG_RET_TYPE) hangup); #endif @@ -277,7 +277,7 @@ attempt_restore: */ if (*g.plname) { getlock(); - program_state.preserve_locks = 0; /* after getlock() */ + g.program_state.preserve_locks = 0; /* after getlock() */ } if (*g.plname && (fd = restore_saved_game()) >= 0) { diff --git a/sys/unix/unixunix.c b/sys/unix/unixunix.c index 3fa83ae8a..126fab629 100644 --- a/sys/unix/unixunix.c +++ b/sys/unix/unixunix.c @@ -75,7 +75,7 @@ eraseoldlocks() { register int i; - program_state.preserve_locks = 0; /* not required but shows intent */ + g.program_state.preserve_locks = 0; /* not required but shows intent */ /* cannot use maxledgerno() here, because we need to find a lock name * before starting everything (including the dungeon initialization * that sets astral_level, needed for maxledgerno()) up diff --git a/sys/vms/vmsmain.c b/sys/vms/vmsmain.c index 0764b1d7b..17ff9ad06 100644 --- a/sys/vms/vmsmain.c +++ b/sys/vms/vmsmain.c @@ -391,7 +391,7 @@ byebye() /* SIGHUP doesn't seem to do anything on VMS, so we fudge it here... */ hup = (void FDECL((*), (int) )) signal(SIGHUP, SIG_IGN); - if (!program_state.exiting++ && hup != (void FDECL((*), (int) )) SIG_DFL + if (!g.program_state.exiting++ && hup != (void FDECL((*), (int) )) SIG_DFL && hup != (void FDECL((*), (int) )) SIG_IGN) { (*hup)(SIGHUP); } @@ -414,7 +414,7 @@ genericptr_t sigargs, mechargs; /* [0] is argc, [1..argc] are the real args */ if (condition == SS$_ACCVIO /* access violation */ || (condition >= SS$_ASTFLT && condition <= SS$_TBIT) || (condition >= SS$_ARTRES && condition <= SS$_INHCHME)) { - program_state.done_hup = TRUE; /* pretend hangup has been attempted */ + g.program_state.done_hup = TRUE; /* pretend hangup has been attempted */ #ifndef BETA if (wizard) #endif diff --git a/sys/vms/vmstty.c b/sys/vms/vmstty.c index 4c0cafa82..a04928839 100644 --- a/sys/vms/vmstty.c +++ b/sys/vms/vmstty.c @@ -146,7 +146,7 @@ vms_getchar() static volatile int recurse = 0; /* SMG is not AST re-entrant! */ #endif - if (program_state.done_hup) { + if (g.program_state.done_hup) { /* hangup has occurred; do not attempt to get further user input */ return ESC; } diff --git a/sys/wince/mhinput.c b/sys/wince/mhinput.c index a7b169342..c5f981835 100644 --- a/sys/wince/mhinput.c +++ b/sys/wince/mhinput.c @@ -39,7 +39,7 @@ mswin_have_input() return #ifdef SAFERHANGUP /* we always have input (ESC) if hangup was requested */ - program_state.done_hup || + g.program_state.done_hup || #endif (nhi_read_pos != nhi_write_pos); } @@ -69,7 +69,7 @@ mswin_input_pop() #ifdef SAFERHANGUP /* always return ESC when hangup was requested */ - if (program_state.done_hup) { + if (g.program_state.done_hup) { static MSNHEvent hangup_event; hangup_event.type = NHEVENT_CHAR; hangup_event.kbd.ch = '\033'; @@ -98,7 +98,7 @@ mswin_input_peek() #ifdef SAFERHANGUP /* always return ESC when hangup was requested */ - if (program_state.done_hup) { + if (g.program_state.done_hup) { static MSNHEvent hangup_event; hangup_event.type = NHEVENT_CHAR; hangup_event.kbd.ch = '\033'; diff --git a/sys/wince/mhmenu.c b/sys/wince/mhmenu.c index 4aa5f19f4..2aa5044c0 100644 --- a/sys/wince/mhmenu.c +++ b/sys/wince/mhmenu.c @@ -533,7 +533,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) if (!data->text.text) { data->text.text = mswin_init_text_buffer( - program_state.gameover ? FALSE : GetNHApp()->bWrapText); + g.program_state.gameover ? FALSE : GetNHApp()->bWrapText); if (!data->text.text) break; } diff --git a/sys/wince/mhtext.c b/sys/wince/mhtext.c index a6b813507..f8bde98c5 100644 --- a/sys/wince/mhtext.c +++ b/sys/wince/mhtext.c @@ -39,7 +39,7 @@ mswin_init_text_window() ZeroMemory(data, sizeof(NHTextWindow)); data->window_text = mswin_init_text_buffer( - program_state.gameover ? FALSE : GetNHApp()->bWrapText); + g.program_state.gameover ? FALSE : GetNHApp()->bWrapText); SetWindowLong(ret, GWL_USERDATA, (LONG) data); return ret; } diff --git a/sys/winnt/nhdefkey.c b/sys/winnt/nhdefkey.c index f6d110adb..e82f0d9dd 100644 --- a/sys/winnt/nhdefkey.c +++ b/sys/winnt/nhdefkey.c @@ -25,7 +25,6 @@ static char author[] = "The NetHack Development Team"; extern HANDLE hConIn; extern INPUT_RECORD ir; -extern struct sinfo program_state; char dllname[512]; char *shortdllname; diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 47d1af63f..76d59a14c 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -443,7 +443,7 @@ tgetch() really_move_cursor(); if (iflags.debug_fuzzer) return randomkey(); - return (program_state.done_hup) + return (g.program_state.done_hup) ? '\033' : keyboard_handler.pCheckInput( console.hConIn, &ir, &count, iflags.num_pad, 0, &mod, &cc); @@ -459,7 +459,7 @@ int *x, *y, *mod; really_move_cursor(); if (iflags.debug_fuzzer) return randomkey(); - ch = (program_state.done_hup) + ch = (g.program_state.done_hup) ? '\033' : keyboard_handler.pCheckInput( console.hConIn, &ir, &count, iflags.num_pad, 1, mod, &cc); diff --git a/win/Qt/qt_win.cpp b/win/Qt/qt_win.cpp index bb6800359..4f90adb56 100644 --- a/win/Qt/qt_win.cpp +++ b/win/Qt/qt_win.cpp @@ -4029,7 +4029,7 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event) void NetHackQtMainWindow::closeEvent(QCloseEvent* e) { - if ( program_state.something_worth_saving ) { + if ( g.program_state.something_worth_saving ) { switch ( QMessageBox::information( this, "NetHack", "This will end your NetHack session", "&Save", "&Cancel", 0, 1 ) ) @@ -4840,7 +4840,7 @@ void NetHackQtBind::qt_update_inventory() if (main) main->updateInventory(); /* doesn't work yet - if (program_state.something_worth_saving && iflags.perm_invent) + if (g.program_state.something_worth_saving && iflags.perm_invent) display_inventory(NULL, FALSE); */ } @@ -4894,14 +4894,14 @@ int NetHackQtBind::qt_nhgetch() // while (keybuffer.Empty() #ifdef SAFERHANGUP - && !program_state.done_hup + && !g.program_state.done_hup #endif ) { qApp->enter_loop(); } #ifdef SAFERHANGUP - if (program_state.done_hup && keybuffer.Empty()) return '\033'; + if (g.program_state.done_hup && keybuffer.Empty()) return '\033'; #endif return keybuffer.GetAscii(); } @@ -4915,13 +4915,13 @@ int NetHackQtBind::qt_nh_poskey(int *x, int *y, int *mod) // while (keybuffer.Empty() && clickbuffer.Empty() #ifdef SAFERHANGUP - && !program_state.done_hup + && !g.program_state.done_hup #endif ) { qApp->enter_loop(); } #ifdef SAFERHANGUP - if (program_state.done_hup && keybuffer.Empty()) return '\033'; + if (g.program_state.done_hup && keybuffer.Empty()) return '\033'; #endif if (!keybuffer.Empty()) { return keybuffer.GetAscii(); @@ -5170,7 +5170,7 @@ bool NetHackQtBind::notify(QObject *receiver, QEvent *event) bool result=QApplication::notify(receiver,event); #ifdef SAFERHANGUP - if (program_state.done_hup) { + if (g.program_state.done_hup) { keybuffer.Put('\033'); qApp->exit_loop(); return TRUE; diff --git a/win/Qt4/qt4bind.cpp b/win/Qt4/qt4bind.cpp index 3cfbb43bd..f6cf3196d 100644 --- a/win/Qt4/qt4bind.cpp +++ b/win/Qt4/qt4bind.cpp @@ -401,7 +401,7 @@ void NetHackQtBind::qt_update_inventory() if (main) main->updateInventory(); /* doesn't work yet - if (program_state.something_worth_saving && iflags.perm_invent) + if (g.program_state.something_worth_saving && iflags.perm_invent) display_inventory(NULL, false); */ } diff --git a/win/Qt4/qt4main.cpp b/win/Qt4/qt4main.cpp index 0a28399bb..291bddc35 100644 --- a/win/Qt4/qt4main.cpp +++ b/win/Qt4/qt4main.cpp @@ -1029,7 +1029,7 @@ void NetHackQtMainWindow::keyPressEvent(QKeyEvent* event) void NetHackQtMainWindow::closeEvent(QCloseEvent* e) { - if ( program_state.something_worth_saving ) { + if ( g.program_state.something_worth_saving ) { switch ( QMessageBox::information( this, "NetHack", "This will end your NetHack session", "&Save", "&Cancel", 0, 1 ) ) diff --git a/win/X11/winmap.c b/win/X11/winmap.c index 3d5ab1d99..b8f0be3d4 100644 --- a/win/X11/winmap.c +++ b/win/X11/winmap.c @@ -1701,7 +1701,7 @@ int exit_condition; inptr = (inptr + 1) % INBUF_SIZE; /* pkey(retval); */ keep_going = FALSE; - } else if (program_state.done_hup) { + } else if (g.program_state.done_hup) { retval = '\033'; inptr = (inptr + 1) % INBUF_SIZE; keep_going = FALSE; @@ -1720,7 +1720,7 @@ int exit_condition; /* pkey(retval); */ } keep_going = FALSE; - } else if (program_state.done_hup) { + } else if (g.program_state.done_hup) { retval = '\033'; inptr = (inptr + 1) % INBUF_SIZE; keep_going = FALSE; diff --git a/win/X11/winmisc.c b/win/X11/winmisc.c index eca5f81fa..ee3e2a079 100644 --- a/win/X11/winmisc.c +++ b/win/X11/winmisc.c @@ -1266,7 +1266,7 @@ X11_player_selection_dialog() if (plsel_align_radios) free(plsel_align_radios); - if (ps_selected == PS_QUIT || program_state.done_hup) { + if (ps_selected == PS_QUIT || g.program_state.done_hup) { clearlocks(); X11_exit_nhwindows((char *) 0); nh_terminate(0); @@ -1341,7 +1341,7 @@ X11_player_selection_prompts() XtDestroyWidget(popup); free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { + if (ps_selected == PS_QUIT || g.program_state.done_hup) { clearlocks(); X11_exit_nhwindows((char *) 0); nh_terminate(0); @@ -1410,7 +1410,7 @@ X11_player_selection_prompts() XtDestroyWidget(popup); free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { + if (ps_selected == PS_QUIT || g.program_state.done_hup) { clearlocks(); X11_exit_nhwindows((char *) 0); nh_terminate(0); @@ -1478,7 +1478,7 @@ X11_player_selection_prompts() XtDestroyWidget(popup); free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { + if (ps_selected == PS_QUIT || g.program_state.done_hup) { clearlocks(); X11_exit_nhwindows((char *) 0); nh_terminate(0); @@ -1544,7 +1544,7 @@ X11_player_selection_prompts() XtDestroyWidget(popup); free((genericptr_t) choices), choices = 0; - if (ps_selected == PS_QUIT || program_state.done_hup) { + if (ps_selected == PS_QUIT || g.program_state.done_hup) { clearlocks(); X11_exit_nhwindows((char *) 0); nh_terminate(0); diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index a81f4292d..96ad3f22a 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -623,7 +623,7 @@ curses_display_nhmenu(winid wid, int how, MENU_ITEM_P ** _selected) menu_determine_pages(current_menu); /* Display pre and post-game menus centered */ - if (((g.moves <= 1) && !g.invent) || program_state.gameover) { + if (((g.moves <= 1) && !g.invent) || g.program_state.gameover) { win = curses_create_window(current_menu->width, current_menu->height, CENTER); } else { /* Display during-game menus on the right out of the way */ diff --git a/win/gnome/gnbind.c b/win/gnome/gnbind.c index f3dbb8c5f..44e09ee6a 100644 --- a/win/gnome/gnbind.c +++ b/win/gnome/gnbind.c @@ -907,7 +907,7 @@ gnome_nhgetch() g_askingQuestion = 1; /* Process events until a key press event arrives. */ while (g_numKeys == 0) { - if (program_state.done_hup) + if (g.program_state.done_hup) return '\033'; gtk_main_iteration(); } @@ -945,7 +945,7 @@ gnome_nh_poskey(int *x, int *y, int *mod) g_askingQuestion = 0; /* Process events until a key or map-click arrives. */ while (g_numKeys == 0 && g_numClicks == 0) { - if (program_state.done_hup) + if (g.program_state.done_hup) return '\033'; gtk_main_iteration(); } diff --git a/win/tty/getline.c b/win/tty/getline.c index 45a968ca0..0164c02b9 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -218,7 +218,7 @@ register const char *s; /* chars allowed besides return */ morc = 0; while ( #ifdef HANGUPHANDLING - !program_state.done_hup && + !g.program_state.done_hup && #endif (c = tty_nhgetch()) != EOF) { if (c == '\n' || c == '\r') diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 54f77d838..161a95cd3 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -56,7 +56,7 @@ extern short glyph2tile[]; */ #define HUPSKIP() \ do { \ - if (program_state.done_hup) { \ + if (g.program_state.done_hup) { \ morc = '\033'; \ return; \ } \ @@ -64,7 +64,7 @@ extern short glyph2tile[]; /* morc=ESC - in case we bypass xwaitforspace() which sets that */ #define HUPSKIP_RESULT(RES) \ do { \ - if (program_state.done_hup) \ + if (g.program_state.done_hup) \ return (RES); \ } while (0) #else /* !HANGUP_HANDLING */ @@ -3085,7 +3085,7 @@ tty_wait_synch() if (ttyDisplay->inmore) { addtopl("--More--"); (void) fflush(stdout); - } else if (ttyDisplay->inread > program_state.gameover) { + } else if (ttyDisplay->inread > g.program_state.gameover) { /* this can only happen if we were reading and got interrupted */ ttyDisplay->toplin = 3; /* do this twice; 1st time gets the Quit? message again */ diff --git a/win/win32/mhinput.c b/win/win32/mhinput.c index d0e3c7076..4a9b15b61 100644 --- a/win/win32/mhinput.c +++ b/win/win32/mhinput.c @@ -39,7 +39,7 @@ mswin_have_input() return #ifdef SAFERHANGUP /* we always have input (ESC) if hangup was requested */ - program_state.done_hup || + g.program_state.done_hup || #endif (nhi_read_pos != nhi_write_pos); } @@ -69,7 +69,7 @@ mswin_input_pop() #ifdef SAFERHANGUP /* always return ESC when hangup was requested */ - if (program_state.done_hup) { + if (g.program_state.done_hup) { static MSNHEvent hangup_event; hangup_event.type = NHEVENT_CHAR; hangup_event.kbd.ch = '\033'; @@ -98,7 +98,7 @@ mswin_input_peek() #ifdef SAFERHANGUP /* always return ESC when hangup was requested */ - if (program_state.done_hup) { + if (g.program_state.done_hup) { static MSNHEvent hangup_event; hangup_event.type = NHEVENT_CHAR; hangup_event.kbd.ch = '\033'; diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index d1e53cdc6..15da747ce 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -452,16 +452,16 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_CLOSE: { /* exit gracefully */ - if (program_state.gameover) { + if (g.program_state.gameover) { /* assume the user really meant this, as the game is already * over... */ /* to make sure we still save bones, just set stop printing flag */ - program_state.stopprint++; + g.program_state.stopprint++; NHEVENT_KBD( '\033'); /* and send keyboard input as if user pressed ESC */ /* additional code for this is done in menu and rip windows */ - } else if (!program_state.something_worth_saving) { + } else if (!g.program_state.something_worth_saving) { /* User exited before the game started, e.g. during splash display */ /* Just get out. */ @@ -837,7 +837,7 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) case IDM_SAVE: if (iflags.debug_fuzzer) break; - if (!program_state.gameover && !program_state.done_hup) + if (!g.program_state.gameover && !g.program_state.done_hup) dosave(); else MessageBeep(0); diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 62e78480f..ffc164908 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -348,10 +348,10 @@ MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; case WM_CLOSE: - if (program_state.gameover) { + if (g.program_state.gameover) { data->result = -1; data->done = 1; - program_state.stopprint++; + g.program_state.stopprint++; return TRUE; } else return FALSE; diff --git a/win/win32/mhrip.c b/win/win32/mhrip.c index f00004f09..a7cfcde69 100644 --- a/win/win32/mhrip.c +++ b/win/win32/mhrip.c @@ -227,7 +227,7 @@ NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) GetNHApp()->hMainWnd = NULL; DestroyWindow(hWnd); SetFocus(GetNHApp()->hMainWnd); - program_state.stopprint++; + g.program_state.stopprint++; return TRUE; case WM_DESTROY: diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index c8ebe8be4..bb463a13d 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -1224,7 +1224,7 @@ void mswin_update_inventory() { logDebug("mswin_update_inventory()\n"); - if (iflags.perm_invent && program_state.something_worth_saving + if (iflags.perm_invent && g.program_state.something_worth_saving && iflags.window_inited && WIN_INVEN != WIN_ERR) display_inventory(NULL, FALSE); }