split g into multiple structures

The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
This commit is contained in:
nhmall
2022-11-29 21:53:21 -05:00
parent e64ed2859d
commit 02a48aa8cf
193 changed files with 10764 additions and 10148 deletions

View File

@@ -81,8 +81,8 @@ nhmain(int argc, char *argv[])
early_init();
g.hname = argv[0];
g.hackpid = getpid();
gh.hname = argv[0];
gh.hackpid = getpid();
(void) umask(0777 & ~FCMASK);
choose_windows(DEFAULT_WINDOW_SYS);
@@ -150,7 +150,7 @@ nhmain(int argc, char *argv[])
initoptions();
#endif
#ifdef PANICTRACE
ARGV0 = g.hname; /* save for possible stack trace */
ARGV0 = gh.hname; /* save for possible stack trace */
#ifndef NO_SIGNAL
panictrace_setsignals(TRUE);
#endif
@@ -178,7 +178,7 @@ nhmain(int argc, char *argv[])
#endif
initoptions();
#ifdef PANICTRACE
ARGV0 = g.hname; /* save for possible stack trace */
ARGV0 = gh.hname; /* save for possible stack trace */
#ifndef NO_SIGNAL
panictrace_setsignals(TRUE);
#endif
@@ -189,7 +189,7 @@ nhmain(int argc, char *argv[])
* It seems you really want to play.
*/
u.uhp = 1; /* prevent RIP on early quits */
g.program_state.preserve_locks = 1;
gp.program_state.preserve_locks = 1;
#ifndef NO_SIGNAL
sethanguphandler((SIG_RET_TYPE) hangup);
#endif
@@ -212,9 +212,9 @@ nhmain(int argc, char *argv[])
#endif
#ifdef DEF_PAGER
if (!(g.catmore = nh_getenv("HACKPAGER"))
&& !(g.catmore = nh_getenv("PAGER")))
g.catmore = DEF_PAGER;
if (!(gc.catmore = nh_getenv("HACKPAGER"))
&& !(gc.catmore = nh_getenv("PAGER")))
gc.catmore = DEF_PAGER;
#endif
#ifdef MAIL
getmailstatus();
@@ -223,14 +223,14 @@ nhmain(int argc, char *argv[])
/* wizard mode access is deferred until here */
set_playmode(); /* sets plname to "wizard" for wizard mode */
/* hide any hyphens from plnamesuffix() */
g.plnamelen = exact_username ? (int) strlen(g.plname) : 0;
gp.plnamelen = exact_username ? (int) strlen(gp.plname) : 0;
/* strip role,race,&c suffix; calls askname() if plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
if (wizard) {
/* use character name rather than lock letter for file names */
g.locknum = 0;
gl.locknum = 0;
} else {
#ifndef NO_SIGNAL
/* suppress interrupts while processing lock file */
@@ -257,22 +257,22 @@ nhmain(int argc, char *argv[])
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when g.locknum == 0)
* or if there are too many active games (when g.locknum > 0).
* in progress for current character name (when gl.locknum == 0)
* or if there are too many active games (when gl.locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !g.locknum) or on first available of alock, block,
* name (for !gl.locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for g.locknum > 0).
* (for gl.locknum > 0).
*/
if (*g.plname) {
if (*gp.plname) {
getlock();
g.program_state.preserve_locks = 0; /* after getlock() */
gp.program_state.preserve_locks = 0; /* after getlock() */
}
if (*g.plname && (nhfp = restore_saved_game()) != 0) {
const char *fq_save = fqname(g.SAVEF, SAVEPREFIX, 1);
if (*gp.plname && (nhfp = restore_saved_game()) != 0) {
const char *fq_save = fqname(gs.SAVEF, SAVEPREFIX, 1);
(void) chmod(fq_save, 0); /* disallow parallel restores */
#ifndef NO_SIGNAL
@@ -302,7 +302,7 @@ nhmain(int argc, char *argv[])
}
if (!resuming) {
boolean neednewlock = (!*g.plname);
boolean neednewlock = (!*gp.plname);
/* 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
@@ -311,14 +311,14 @@ nhmain(int argc, char *argv[])
if (!plsel_once)
player_selection();
plsel_once = TRUE;
if (neednewlock && *g.plname)
if (neednewlock && *gp.plname)
goto attempt_restore;
if (iflags.renameinprogress) {
/* player has renamed the hero while selecting role;
if locking alphabetically, the existing lock file
can still be used; otherwise, discard current one
and create another for the new character name */
if (!g.locknum) {
if (!gl.locknum) {
delete_levelfile(0); /* remove empty lock file */
getlock();
}
@@ -377,13 +377,13 @@ process_options(int argc, char *argv[])
#endif
case 'u':
if (argv[0][2]) {
(void) strncpy(g.plname, argv[0] + 2, sizeof g.plname - 1);
g.plnamelen = 0; /* plname[] might have -role-race attached */
(void) strncpy(gp.plname, argv[0] + 2, sizeof gp.plname - 1);
gp.plnamelen = 0; /* plname[] might have -role-race attached */
} else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof g.plname - 1);
g.plnamelen = 0;
(void) strncpy(gp.plname, argv[0], sizeof gp.plname - 1);
gp.plnamelen = 0;
} else {
raw_print("Player name expected after -u");
}
@@ -443,17 +443,17 @@ process_options(int argc, char *argv[])
#else
/* XXX This is deprecated in favor of SYSCF with MAXPLAYERS */
if (argc > 1)
g.locknum = atoi(argv[1]);
gl.locknum = atoi(argv[1]);
#endif
#ifdef MAX_NR_OF_PLAYERS
/* limit to compile-time limit */
if (!g.locknum || g.locknum > MAX_NR_OF_PLAYERS)
g.locknum = MAX_NR_OF_PLAYERS;
if (!gl.locknum || gl.locknum > MAX_NR_OF_PLAYERS)
gl.locknum = MAX_NR_OF_PLAYERS;
#endif
#ifdef SYSCF
/* let syscf override compile-time limit */
if (!g.locknum || (sysopt.maxplayers && g.locknum > sysopt.maxplayers))
g.locknum = sysopt.maxplayers;
if (!gl.locknum || (sysopt.maxplayers && gl.locknum > sysopt.maxplayers))
gl.locknum = sysopt.maxplayers;
#endif
}
@@ -478,11 +478,11 @@ chdirx(const char *dir, boolean wr)
#ifdef VAR_PLAYGROUND
int len = strlen(VAR_PLAYGROUND);
g.fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2);
Strcpy(g.fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND);
if (g.fqn_prefix[SCOREPREFIX][len - 1] != '/') {
g.fqn_prefix[SCOREPREFIX][len] = '/';
g.fqn_prefix[SCOREPREFIX][len + 1] = '\0';
gf.fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2);
Strcpy(gf.fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND);
if (gf.fqn_prefix[SCOREPREFIX][len - 1] != '/') {
gf.fqn_prefix[SCOREPREFIX][len] = '/';
gf.fqn_prefix[SCOREPREFIX][len + 1] = '\0';
}
#endif
@@ -504,11 +504,11 @@ chdirx(const char *dir, boolean wr)
*/
if (wr) {
#ifdef VAR_PLAYGROUND
g.fqn_prefix[LEVELPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[SAVEPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[BONESPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[LOCKPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[TROUBLEPREFIX] = g.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[LEVELPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[SAVEPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[BONESPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[LOCKPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[TROUBLEPREFIX] = gf.fqn_prefix[SCOREPREFIX];
#endif
check_recordfile(dir);
}
@@ -530,7 +530,7 @@ whoami(void)
* Note that we trust the user here; it is possible to play under
* somebody else's name.
*/
if (!*g.plname) {
if (!*gp.plname) {
register const char *s;
s = nh_getenv("USER");
@@ -540,8 +540,8 @@ whoami(void)
s = getlogin();
if (s && *s) {
(void) strncpy(g.plname, s, sizeof g.plname - 1);
if (strchr(g.plname, '-'))
(void) strncpy(gp.plname, s, sizeof gp.plname - 1);
if (strchr(gp.plname, '-'))
return TRUE;
}
}
@@ -648,7 +648,7 @@ check_user_string(const char *optstr)
if (optstr[0] == '*')
return TRUE; /* allow any user */
if (sysopt.check_plname)
pwname = g.plname;
pwname = gp.plname;
else if ((pw = get_unix_pw()) != 0)
pwname = pw->pw_name;
if (!pwname || !*pwname)
@@ -1041,7 +1041,7 @@ void js_globals_init() {
});
/* globals */
CREATE_GLOBAL(g.plname, "s");
CREATE_GLOBAL(gp.plname, "s");
/* window globals */
CREATE_GLOBAL(WIN_MAP, "i");

View File

@@ -36,7 +36,7 @@ pckeys(unsigned char scancode, unsigned char shift)
{
boolean opening_dialog;
opening_dialog = g.pl_character[0] ? FALSE : TRUE;
opening_dialog = gp.pl_character[0] ? FALSE : TRUE;
switch (scancode) {
#ifdef SIMULATE_CURSOR
case 0x3d: /* F3 = toggle cursor type */

View File

@@ -772,7 +772,7 @@ vesa_cliparound(int x, int y)
clipymax = ROWNO - 1;
}
if (clipx != oldx || clipy != oldy) {
if (on_level(&u.uz0, &u.uz) && !g.program_state.restoring)
if (on_level(&u.uz0, &u.uz) && !gp.program_state.restoring)
/* (void) doredraw(); */
vesa_redrawmap();
}

View File

@@ -454,7 +454,7 @@ vga_cliparound(int x, int y UNUSED)
clipx = clipxmax - (viewport_size - 1);
}
if (clipx != oldx) {
if (on_level(&u.uz0, &u.uz) && !g.program_state.restoring)
if (on_level(&u.uz0, &u.uz) && !gp.program_state.restoring)
/* (void) doredraw(); */
vga_redrawmap(1);
}

View File

@@ -128,11 +128,11 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
#ifdef TOS
long clock_time;
if (*argv[0]) { /* only a CLI can give us argv[0] */
g.hname = argv[0];
gh.hname = argv[0];
run_from_desktop = FALSE;
} else
#endif
g.hname = "NetHack"; /* used for syntax messages */
gh.hname = "NetHack"; /* used for syntax messages */
choose_windows(DEFAULT_WINDOW_SYS);
@@ -182,17 +182,17 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
int fd;
boolean have_syscf = FALSE;
(void) strncpy(g.hackdir, dir, PATHLEN - 1);
g.hackdir[PATHLEN - 1] = '\0';
(void) strncpy(gh.hackdir, dir, PATHLEN - 1);
gh.hackdir[PATHLEN - 1] = '\0';
#ifdef NOCWD_ASSUMPTIONS
{
int prefcnt;
g.fqn_prefix[0] = (char *) alloc(strlen(g.hackdir) + 2);
Strcpy(g.fqn_prefix[0], g.hackdir);
append_slash(g.fqn_prefix[0]);
gf.fqn_prefix[0] = (char *) alloc(strlen(gh.hackdir) + 2);
Strcpy(gf.fqn_prefix[0], gh.hackdir);
append_slash(gf.fqn_prefix[0]);
for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++)
g.fqn_prefix[prefcnt] = g.fqn_prefix[0];
gf.fqn_prefix[prefcnt] = gf.fqn_prefix[0];
#if defined(MSDOS)
/* sysconf should be searched for in this location */
@@ -201,11 +201,11 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if ((sptr = strchr(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
g.fqn_prefix[SYSCONFPREFIX] =
gf.fqn_prefix[SYSCONFPREFIX] =
(char *) alloc(strlen(envp) + 10);
Strcpy(g.fqn_prefix[SYSCONFPREFIX], envp);
append_slash(g.fqn_prefix[SYSCONFPREFIX]);
Strcat(g.fqn_prefix[SYSCONFPREFIX], "NetHack\\");
Strcpy(gf.fqn_prefix[SYSCONFPREFIX], envp);
append_slash(gf.fqn_prefix[SYSCONFPREFIX]);
Strcat(gf.fqn_prefix[SYSCONFPREFIX], "NetHack\\");
}
}
@@ -226,7 +226,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
/* No SYSCF_FILE where there should be one, and
without an installer, a user may not be able
to place one there. So, let's try somewhere else... */
g.fqn_prefix[SYSCONFPREFIX] = g.fqn_prefix[0];
gf.fqn_prefix[SYSCONFPREFIX] = gf.fqn_prefix[0];
/* Is there a SYSCF_FILE there? */
fd = open(fqname(SYSCF_FILE, SYSCONFPREFIX, 0), O_RDONLY);
@@ -244,10 +244,10 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if ((sptr = strchr(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
g.fqn_prefix[CONFIGPREFIX] =
gf.fqn_prefix[CONFIGPREFIX] =
(char *) alloc(strlen(envp) + 2);
Strcpy(g.fqn_prefix[CONFIGPREFIX], envp);
append_slash(g.fqn_prefix[CONFIGPREFIX]);
Strcpy(gf.fqn_prefix[CONFIGPREFIX], envp);
append_slash(gf.fqn_prefix[CONFIGPREFIX]);
}
}
#endif
@@ -283,11 +283,11 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (iflags.BIOS && iflags.use_color)
set_colors();
#endif
if (!g.hackdir[0])
if (!gh.hackdir[0])
#if !defined(LATTICE) && !defined(AMIGA)
Strcpy(g.hackdir, orgdir);
Strcpy(gh.hackdir, orgdir);
#else
Strcpy(g.hackdir, HACKDIR);
Strcpy(gh.hackdir, HACKDIR);
#endif
if (argc > 1) {
if (argcheck(argc, argv, ARG_VERSION) == 2)
@@ -314,7 +314,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
}
if (!*dir)
error("Flag -d must be followed by a directory name.");
Strcpy(g.hackdir, dir);
Strcpy(gh.hackdir, dir);
}
if (argc > 1) {
/*
@@ -323,7 +323,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
*/
if (!strncmp(argv[1], "-s", 2)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(g.hackdir, 0);
chdirx(gh.hackdir, 0);
#endif
#ifdef SYSCF
initoptions();
@@ -363,7 +363,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
* code parallel to other ports.
*/
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(g.hackdir, 1);
chdirx(gh.hackdir, 1);
#endif
#if defined(MSDOS)
@@ -411,21 +411,21 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
* overwritten without confirmation when a user starts up
* another game with the same player name.
*/
Strcpy(g.lock, g.plname);
regularize(g.lock);
Strcpy(gl.lock, gp.plname);
regularize(gl.lock);
getlock();
#else /* What follows is !PC_LOCKING */
#ifdef AMIGA /* We'll put the bones & levels in the user specified directory \
-jhsa */
Strcat(g.lock, g.plname);
Strcat(g.lock, ".99");
Strcat(gl.lock, gp.plname);
Strcat(gl.lock, ".99");
#else
/* I'm not sure what, if anything, is left here, but old MFLOPPY had
* conflicts with set_lock_and_bones() in files.c.
*/
Strcpy(g.lock, g.plname);
Strcat(g.lock, ".99");
regularize(g.lock); /* is this necessary? */
Strcpy(gl.lock, gp.plname);
Strcat(gl.lock, ".99");
regularize(gl.lock); /* is this necessary? */
/* not compatible with full path a la AMIGA */
#endif
#endif /* PC_LOCKING */
@@ -436,9 +436,9 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (!nhfp) {
raw_print("Cannot create lock file");
} else {
g.hackpid = 1;
gh.hackpid = 1;
if (nhfp->structlevel)
write(nhfp->fd, (genericptr_t) &g.hackpid, sizeof(g.hackpid));
write(nhfp->fd, (genericptr_t) &gh.hackpid, sizeof(gh.hackpid));
close_nhfile(nhfp);
}
@@ -475,7 +475,7 @@ attempt_restore:
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(g.SAVEF, SAVEPREFIX, 0));
nh_compress(fqname(gs.SAVEF, SAVEPREFIX, 0));
}
}
}
@@ -549,11 +549,11 @@ process_options(int argc, char *argv[])
#endif
case 'u':
if (argv[0][2])
(void) strncpy(g.plname, argv[0] + 2, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0] + 2, sizeof(gp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0], sizeof(gp.plname) - 1);
} else
raw_print("Player name expected after -u");
break;
@@ -650,12 +650,12 @@ nhusage(void)
*/
(void) Sprintf(buf2, "\nUsage:\n%s [-d dir] -s [-r race] [-p profession] "
"[maxrank] [name]...\n or",
g.hname);
gh.hname);
ADD_USAGE(buf2);
(void) Sprintf(
buf2, "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]",
g.hname);
gh.hname);
ADD_USAGE(buf2);
#ifdef NEWS
ADD_USAGE(" [-n]");
@@ -715,7 +715,7 @@ port_help(void)
boolean
authorize_wizard_mode(void)
{
if (!strcmp(g.plname, WIZARD_NAME))
if (!strcmp(gp.plname, WIZARD_NAME))
return TRUE;
return FALSE;
}

View File

@@ -50,12 +50,12 @@ uptodate(int fd)
#else
#if (defined(MICRO)) && !defined(NO_FSTAT)
if(fstat(fd, &buf)) {
if(g.moves > 1) pline("Cannot get status of saved level? ");
if(gm.moves > 1) pline("Cannot get status of saved level? ");
else pline("Cannot get status of saved game.");
return(0);
}
if(comp_times(buf.st_mtime)) {
if(g.moves > 1) pline("Saved level is out of date.");
if(gm.moves > 1) pline("Saved level is out of date.");
else pline("Saved game is out of date. ");
/* This problem occurs enough times we need to give the player
* some more information about what causes it, and how to fix.
@@ -85,14 +85,14 @@ eraseoldlocks(void)
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(g.lock, i);
(void) unlink(fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, i);
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
}
set_levelfile_name(g.lock, 0);
set_levelfile_name(gl.lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
#endif
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
@@ -118,9 +118,9 @@ getlock(void)
}
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(g.lock, 0);
fq_lock = fqname(g.lock, LEVELPREFIX, 1);
Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, 0);
fq_lock = fqname(gl.lock, LEVELPREFIX, 1);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
@@ -217,8 +217,8 @@ gotlock:
#endif
error("cannot creat file (%s.)", fq_lock);
} else {
if (write(fd, (char *) &g.hackpid, sizeof(g.hackpid))
!= sizeof(g.hackpid)) {
if (write(fd, (char *) &gh.hackpid, sizeof(gh.hackpid))
!= sizeof(gh.hackpid)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif

View File

@@ -96,8 +96,8 @@ main(int argc, char *argv[])
}
#endif
g.hname = argv[0];
g.hackpid = getpid();
gh.hname = argv[0];
gh.hackpid = getpid();
(void) umask(0777 & ~FCMASK);
choose_windows(DEFAULT_WINDOW_SYS);
@@ -136,7 +136,7 @@ main(int argc, char *argv[])
initoptions();
#ifdef PANICTRACE
ARGV0 = g.hname; /* save for possible stack trace */
ARGV0 = gh.hname; /* save for possible stack trace */
#ifndef NO_SIGNAL
panictrace_setsignals(TRUE);
#endif
@@ -147,7 +147,7 @@ main(int argc, char *argv[])
* It seems you really want to play.
*/
u.uhp = 1; /* prevent RIP on early quits */
g.program_state.preserve_locks = 1;
gp.program_state.preserve_locks = 1;
#ifndef NO_SIGNAL
sethanguphandler((SIG_RET_TYPE) hangup);
#endif
@@ -165,10 +165,10 @@ main(int argc, char *argv[])
#endif
#ifdef DEF_PAGER
if (!(g.catmore = nh_getenv("NETHACKPAGER"))
&& !(g.catmore = nh_getenv("HACKPAGER"))
&& !(g.catmore = nh_getenv("PAGER")))
g.catmore = DEF_PAGER;
if (!(gc.catmore = nh_getenv("NETHACKPAGER"))
&& !(gc.catmore = nh_getenv("HACKPAGER"))
&& !(gc.catmore = nh_getenv("PAGER")))
gc.catmore = DEF_PAGER;
#endif
#ifdef MAIL
getmailstatus();
@@ -177,14 +177,14 @@ main(int argc, char *argv[])
/* wizard mode access is deferred until here */
set_playmode(); /* sets plname to "wizard" for wizard mode */
/* hide any hyphens from plnamesuffix() */
g.plnamelen = exact_username ? (int) strlen(g.plname) : 0;
gp.plnamelen = exact_username ? (int) strlen(gp.plname) : 0;
/* strip role,race,&c suffix; calls askname() if plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
if (wizard) {
/* use character name rather than lock letter for file names */
g.locknum = 0;
gl.locknum = 0;
} else {
/* suppress interrupts while processing lock file */
(void) signal(SIGQUIT, SIG_IGN);
@@ -209,22 +209,22 @@ main(int argc, char *argv[])
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when g.locknum == 0)
* or if there are too many active games (when g.locknum > 0).
* in progress for current character name (when gl.locknum == 0)
* or if there are too many active games (when gl.locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !g.locknum) or on first available of alock, block,
* name (for !gl.locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for g.locknum > 0).
* (for gl.locknum > 0).
*/
if (*g.plname) {
if (*gp.plname) {
getlock();
g.program_state.preserve_locks = 0; /* after getlock() */
gp.program_state.preserve_locks = 0; /* after getlock() */
}
if (*g.plname && (nhfp = restore_saved_game()) != 0) {
const char *fq_save = fqname(g.SAVEF, SAVEPREFIX, 1);
if (*gp.plname && (nhfp = restore_saved_game()) != 0) {
const char *fq_save = fqname(gs.SAVEF, SAVEPREFIX, 1);
(void) chmod(fq_save, 0); /* disallow parallel restores */
#ifndef NO_SIGNAL
@@ -238,7 +238,7 @@ main(int argc, char *argv[])
#endif
/* if there are early trouble-messages issued, let's
* not go overtop of them with a pline just yet */
if (g.early_raw_messages)
if (ge.early_raw_messages)
raw_print("Restoring save file...");
else
pline("Restoring save file...");
@@ -259,7 +259,7 @@ main(int argc, char *argv[])
}
if (!resuming) {
boolean neednewlock = (!*g.plname);
boolean neednewlock = (!*gp.plname);
/* 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
@@ -268,14 +268,14 @@ main(int argc, char *argv[])
if (!plsel_once)
player_selection();
plsel_once = TRUE;
if (neednewlock && *g.plname)
if (neednewlock && *gp.plname)
goto attempt_restore;
if (iflags.renameinprogress) {
/* player has renamed the hero while selecting role;
if locking alphabetically, the existing lock file
can still be used; otherwise, discard current one
and create another for the new character name */
if (!g.locknum) {
if (!gl.locknum) {
delete_levelfile(0); /* remove empty lock file */
getlock();
}
@@ -441,13 +441,13 @@ process_options(int argc, char *argv[])
break;
case 'u':
if (arg[2]) {
(void) strncpy(g.plname, arg + 2, sizeof g.plname - 1);
g.plnamelen = 0; /* plname[] might have -role-race attached */
(void) strncpy(gp.plname, arg + 2, sizeof gp.plname - 1);
gp.plnamelen = 0; /* plname[] might have -role-race attached */
} else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof g.plname - 1);
g.plnamelen = 0;
(void) strncpy(gp.plname, argv[0], sizeof gp.plname - 1);
gp.plnamelen = 0;
} else {
config_error_add("Character name expected after -u");
}
@@ -514,20 +514,20 @@ process_options(int argc, char *argv[])
#else
/* XXX This is deprecated in favor of SYSCF with MAXPLAYERS */
if (mx_ok)
g.locknum = mxplyrs;
gl.locknum = mxplyrs;
else
config_error_add("Invalid MAXPLATERS \"%s\"", argv[1]);
#endif
}
#ifdef MAX_NR_OF_PLAYERS
/* limit to compile-time limit */
if (!g.locknum || g.locknum > MAX_NR_OF_PLAYERS)
g.locknum = MAX_NR_OF_PLAYERS;
if (!gl.locknum || gl.locknum > MAX_NR_OF_PLAYERS)
gl.locknum = MAX_NR_OF_PLAYERS;
#endif
#ifdef SYSCF
/* let syscf override compile-time limit */
if (!g.locknum || (sysopt.maxplayers && g.locknum > sysopt.maxplayers))
g.locknum = sysopt.maxplayers;
if (!gl.locknum || (sysopt.maxplayers && gl.locknum > sysopt.maxplayers))
gl.locknum = sysopt.maxplayers;
#endif
/* empty or "N errors on command line" */
config_error_done();
@@ -643,7 +643,7 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
arg = lopt(arg, (ArgValRequired | ArgErrComplain),
"-nethackrc", origarg, &argc, &argv);
if (arg) {
g.cmdline_rcfile = dupstr(arg);
gc.cmdline_rcfile = dupstr(arg);
if (oldargc == argc)
consume_arg(ndx, argc_p, argv_p), consumed = 1;
else
@@ -686,9 +686,9 @@ early_options(int *argc_p, char ***argv_p, char **hackdir_p)
arg = lopt(arg,
(ArgValRequired | ArgNamOneLetter | ArgErrComplain),
"-windowtype", origarg, &argc, &argv);
if (g.cmdline_windowsys)
free((genericptr_t) g.cmdline_windowsys);
g.cmdline_windowsys = arg ? dupstr(arg) : NULL;
if (gc.cmdline_windowsys)
free((genericptr_t) gc.cmdline_windowsys);
gc.cmdline_windowsys = arg ? dupstr(arg) : NULL;
break;
default:
break;
@@ -762,7 +762,7 @@ scores_only(int argc, char **argv, const char *dir)
iflags.initoptions_noterminate = FALSE;
#endif
#ifdef PANICTRACE
ARGV0 = g.hname; /* save for possible stack trace */
ARGV0 = gh.hname; /* save for possible stack trace */
#ifndef NO_SIGNAL
panictrace_setsignals(TRUE);
#endif
@@ -798,11 +798,11 @@ chdirx(const char *dir, boolean wr)
/* FIXME: this allocation never gets freed.
*/
g.fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2);
Strcpy(g.fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND);
if (g.fqn_prefix[SCOREPREFIX][len - 1] != '/') {
g.fqn_prefix[SCOREPREFIX][len] = '/';
g.fqn_prefix[SCOREPREFIX][len + 1] = '\0';
gf.fqn_prefix[SCOREPREFIX] = (char *) alloc(len + 2);
Strcpy(gf.fqn_prefix[SCOREPREFIX], VAR_PLAYGROUND);
if (gf.fqn_prefix[SCOREPREFIX][len - 1] != '/') {
gf.fqn_prefix[SCOREPREFIX][len] = '/';
gf.fqn_prefix[SCOREPREFIX][len + 1] = '\0';
}
#endif
}
@@ -830,11 +830,11 @@ chdirx(const char *dir, boolean wr)
* fqn_prefix[j] can check [j+1] through [N-1] for duplicated
* pointer and just set the value to Null.
*/
g.fqn_prefix[LEVELPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[SAVEPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[BONESPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[LOCKPREFIX] = g.fqn_prefix[SCOREPREFIX];
g.fqn_prefix[TROUBLEPREFIX] = g.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[LEVELPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[SAVEPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[BONESPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[LOCKPREFIX] = gf.fqn_prefix[SCOREPREFIX];
gf.fqn_prefix[TROUBLEPREFIX] = gf.fqn_prefix[SCOREPREFIX];
#endif
check_recordfile(dir);
}
@@ -857,7 +857,7 @@ whoami(void)
* Note that we trust the user here; it is possible to play under
* somebody else's name.
*/
if (!*g.plname) {
if (!*gp.plname) {
register const char *s;
s = nh_getenv("USER");
@@ -867,8 +867,8 @@ whoami(void)
s = getlogin();
if (s && *s) {
(void) strncpy(g.plname, s, sizeof g.plname - 1);
if (strchr(g.plname, '-'))
(void) strncpy(gp.plname, s, sizeof gp.plname - 1);
if (strchr(gp.plname, '-'))
return TRUE;
}
}
@@ -973,7 +973,7 @@ check_user_string(const char *optstr)
if (optstr[0] == '*')
return TRUE; /* allow any user */
if (sysopt.check_plname)
pwname = g.plname;
pwname = gp.plname;
else if ((pw = get_unix_pw()) != 0)
pwname = pw->pw_name;
if (!pwname || !*pwname)

View File

@@ -74,18 +74,18 @@ eraseoldlocks(void)
{
register int i;
g.program_state.preserve_locks = 0; /* not required but shows intent */
gp.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
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(g.lock, i);
(void) unlink(fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, i);
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
}
set_levelfile_name(g.lock, 0);
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
set_levelfile_name(gl.lock, 0);
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return 1; /* success! */
}
@@ -115,22 +115,22 @@ getlock(void)
error("%s", "");
}
/* default value of g.lock[] is "1lock" where '1' gets changed to
/* default value of gl.lock[] is "1lock" where '1' gets changed to
'a','b',&c below; override the default and use <uid><charname>
if we aren't restricting the number of simultaneous games */
if (!g.locknum)
Sprintf(g.lock, "%u%s", (unsigned) getuid(), g.plname);
if (!gl.locknum)
Sprintf(gl.lock, "%u%s", (unsigned) getuid(), gp.plname);
regularize(g.lock);
set_levelfile_name(g.lock, 0);
regularize(gl.lock);
set_levelfile_name(gl.lock, 0);
if (g.locknum) {
if (g.locknum > 25)
g.locknum = 25;
if (gl.locknum) {
if (gl.locknum > 25)
gl.locknum = 25;
do {
g.lock[0] = 'a' + i++;
fq_lock = fqname(g.lock, LEVELPREFIX, 0);
gl.lock[0] = 'a' + i++;
fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
@@ -144,12 +144,12 @@ getlock(void)
if (veryold(fd) && eraseoldlocks())
goto gotlock;
(void) close(fd);
} while (i < g.locknum);
} while (i < gl.locknum);
unlock_file(HLOCK);
error("Too many hacks running now.");
} else {
fq_lock = fqname(g.lock, LEVELPREFIX, 0);
fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
@@ -202,8 +202,8 @@ gotlock:
if (fd == -1) {
error("cannot creat lock file (%s).", fq_lock);
} else {
if (write(fd, (genericptr_t) &g.hackpid, sizeof g.hackpid)
!= sizeof g.hackpid) {
if (write(fd, (genericptr_t) &gh.hackpid, sizeof gh.hackpid)
!= sizeof gh.hackpid) {
error("cannot write lock (%s)", fq_lock);
}
if (close(fd) == -1) {

View File

@@ -285,10 +285,10 @@ parse_brdcst(char *buf) /* called by parse_next_broadcast() */
if (txt && strlen(txt) > BUFSZ - 50)
txt[BUFSZ - 50] = '\0';
msg.message_typ = typ; /* simple index */
msgm.message_typ = typ; /* simple index */
msg.display_txt = txt; /* text for daemon to pline() */
msg.object_nam = nam; /* 'name' for mail scroll */
msg.response_cmd = cmd; /* command to spawn when scroll read */
msgr.response_cmd = cmd; /* command to spawn when scroll read */
return &msg;
}

View File

@@ -45,9 +45,9 @@ main(int argc, char *argv[])
early_init();
atexit(byebye);
g.hname = argv[0];
g.hname = vms_basename(g.hname); /* name used in 'usage' type messages */
g.hackpid = getpid();
gh.hname = argv[0];
gh.hname = vms_basename(gh.hname); /* name used in 'usage' type messages */
gh.hackpid = getpid();
(void) umask(0);
choose_windows(DEFAULT_WINDOW_SYS);
@@ -156,7 +156,7 @@ main(int argc, char *argv[])
if (wizard) {
/* use character name rather than lock letter for file names */
g.locknum = 0;
gl.locknum = 0;
} else {
/* suppress interrupts while processing lock file */
(void) signal(SIGQUIT, SIG_IGN);
@@ -164,14 +164,14 @@ main(int argc, char *argv[])
}
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when g.locknum == 0)
* or if there are too many active games (when g.locknum > 0).
* in progress for current character name (when gl.locknum == 0)
* or if there are too many active games (when gl.locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !g.locknum) or on first available of alock, block,
* name (for !gl.locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for g.locknum > 0).
* (for gl.locknum > 0).
*/
getlock();
@@ -191,7 +191,7 @@ main(int argc, char *argv[])
*/
attempt_restore:
if ((nhfp = restore_saved_game()) != 0) {
const char *fq_save = fqname(g.SAVEF, SAVEPREFIX, 1);
const char *fq_save = fqname(gs.SAVEF, SAVEPREFIX, 1);
(void) chmod(fq_save, 0); /* disallow parallel restores */
(void) signal(SIGINT, (SIG_RET_TYPE) done1);
@@ -227,7 +227,7 @@ attempt_restore:
if locking alphabetically, the existing lock file
can still be used; otherwise, discard current one
and create another for the new character name */
if (!g.locknum) {
if (!gl.locknum) {
delete_levelfile(0); /* remove empty lock file */
getlock();
}
@@ -270,11 +270,11 @@ process_options(int argc, char *argv[])
#endif
case 'u':
if (argv[0][2])
(void) strncpy(g.plname, argv[0] + 2, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0] + 2, sizeof(gp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0], sizeof(gp.plname) - 1);
} else
raw_print("Player name expected after -u");
break;
@@ -328,10 +328,10 @@ process_options(int argc, char *argv[])
}
if (argc > 1)
g.locknum = atoi(argv[1]);
gl.locknum = atoi(argv[1]);
#ifdef MAX_NR_OF_PLAYERS
if (!g.locknum || g.locknum > MAX_NR_OF_PLAYERS)
g.locknum = MAX_NR_OF_PLAYERS;
if (!gl.locknum || gl.locknum > MAX_NR_OF_PLAYERS)
gl.locknum = MAX_NR_OF_PLAYERS;
#endif
}
@@ -379,8 +379,8 @@ whoami(void)
*/
register char *s;
if (!*g.plname && (s = nh_getenv("USER")))
(void) lcase(strncpy(g.plname, s, sizeof(g.plname) - 1));
if (!*gp.plname && (s = nh_getenv("USER")))
(void) lcase(strncpy(gp.plname, s, sizeof(gp.plname) - 1));
}
static void
@@ -401,7 +401,7 @@ byebye(void)
/* SIGHUP doesn't seem to do anything on VMS, so we fudge it here... */
hup = (void (*)(int) ) signal(SIGHUP, SIG_IGN);
if (!g.program_state.exiting++ && hup != (void (*)(int) ) SIG_DFL
if (!gp.program_state.exiting++ && hup != (void (*)(int) ) SIG_DFL
&& hup != (void (*)(int) ) SIG_IGN) {
(*hup)(SIGHUP);
}
@@ -425,7 +425,7 @@ genericptr_t 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)) {
g.program_state.done_hup = TRUE; /* pretend hangup has been attempted */
gp.program_state.done_hup = TRUE; /* pretend hangup has been attempted */
#if (NH_DEVEL_STATUS == NH_STATUS_RELEASED)
if (wizard)
#endif

View File

@@ -146,7 +146,7 @@ vms_getchar(void)
static volatile int recurse = 0; /* SMG is not AST re-entrant! */
#endif
if (g.program_state.done_hup) {
if (gp.program_state.done_hup) {
/* hangup has occurred; do not attempt to get further user input */
return ESC;
}
@@ -171,16 +171,16 @@ vms_getchar(void)
} else if (kb_buf == ESC || kb_buf == CSI || kb_buf == SS3) {
switch (parse_function_key((int) kb_buf)) {
case SMG$K_TRM_UP:
key = g.Cmd.move_N;
key = gc.Cmd.move_N;
break;
case SMG$K_TRM_DOWN:
key = g.Cmd.move_S;
key = gc.Cmd.move_S;
break;
case SMG$K_TRM_LEFT:
key = g.Cmd.move_W;
key = gc.Cmd.move_W;
break;
case SMG$K_TRM_RIGHT:
key = g.Cmd.move_E;
key = gc.Cmd.move_E;
break;
default:
key = ESC;
@@ -201,16 +201,16 @@ vms_getchar(void)
smg$read_keystroke(&kb, &key);
switch (key) {
case SMG$K_TRM_UP:
key = g.Cmd.move_N;
key = gc.Cmd.move_N;
break;
case SMG$K_TRM_DOWN:
key = g.Cmd.move_S;
key = gc.Cmd.move_S;
break;
case SMG$K_TRM_LEFT:
key = g.Cmd.move_W;
key = gc.Cmd.move_W;
break;
case SMG$K_TRM_RIGHT:
key = g.Cmd.move_E;
key = gc.Cmd.move_E;
break;
case '\r':
key = '\n';

View File

@@ -76,11 +76,11 @@ veryold(int fd)
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(g.lock, i);
(void) delete (g.lock);
set_levelfile_name(gl.lock, i);
(void) delete (gl.lock);
}
set_levelfile_name(g.lock, 0);
if (delete (g.lock))
set_levelfile_name(gl.lock, 0);
if (delete (gl.lock))
return 0; /* cannot remove it */
return 1; /* success! */
}
@@ -105,46 +105,46 @@ getlock(void)
error("Quitting.");
}
/* default value of g.lock[] is "1lock" where '1' gets changed to
/* default value of gl.lock[] is "1lock" where '1' gets changed to
'a','b',&c below; override the default and use <uid><charname>
if we aren't restricting the number of simultaneous games */
if (!g.locknum)
Sprintf(g.lock, "_%u%s", (unsigned) getuid(), g.plname);
if (!gl.locknum)
Sprintf(gl.lock, "_%u%s", (unsigned) getuid(), gp.plname);
regularize(g.lock);
set_levelfile_name(g.lock, 0);
if (g.locknum > 25)
g.locknum = 25;
regularize(gl.lock);
set_levelfile_name(gl.lock, 0);
if (gl.locknum > 25)
gl.locknum = 25;
do {
if (g.locknum)
g.lock[0] = 'a' + i++;
if (gl.locknum)
gl.lock[0] = 'a' + i++;
if ((fd = open(g.lock, 0, 0)) == -1) {
if ((fd = open(gl.lock, 0, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
perror(g.lock);
perror(gl.lock);
unlock_file(HLOCK);
error("Cannot open %s", g.lock);
error("Cannot open %s", gl.lock);
}
if (veryold(fd)) /* if true, this closes fd and unlinks lock */
goto gotlock;
(void) close(fd);
} while (i < g.locknum);
} while (i < gl.locknum);
unlock_file(HLOCK);
error(g.locknum ? "Too many hacks running now."
error(gl.locknum ? "Too many hacks running now."
: "There is a game in progress under your name.");
gotlock:
fd = creat(g.lock, FCMASK);
fd = creat(gl.lock, FCMASK);
unlock_file(HLOCK);
if (fd == -1) {
error("cannot creat lock file.");
} else {
if (write(fd, (char *) &g.hackpid, sizeof(g.hackpid))
!= sizeof(g.hackpid)) {
if (write(fd, (char *) &gh.hackpid, sizeof(gh.hackpid))
!= sizeof(gh.hackpid)) {
error("cannot write lock");
}
if (close(fd) == -1) {
@@ -595,7 +595,7 @@ vms_get_saved_games(const char *savetemplate, /* wildcarded save file name in na
char *charname, wildcard[255 + 1], filename[255 + 1];
genericptr_t context = 0;
Strcpy(wildcard, savetemplate); /* plname_from_file overwrites g.SAVEF */
Strcpy(wildcard, savetemplate); /* plname_from_file overwrites gs.SAVEF */
in.mbz = 0; /* class and type; leave them unspecified */
in.len = (unsigned short) strlen(wildcard);
in.adr = wildcard;

View File

@@ -884,7 +884,7 @@ void buffer_fill_to_end(cell_t * buffer, cell_t * fill, int x, int y)
while (dst != sentinel)
*dst++ = *fill;
if ((iflags.debug.immediateflips || !g.program_state.in_moveloop)
if ((iflags.debug.immediateflips || !gp.program_state.in_moveloop)
&& buffer == console.back_buffer)
back_buffer_flip();
}
@@ -900,7 +900,7 @@ static void buffer_clear_to_end_of_line(cell_t * buffer, int x, int y)
while (dst != sentinel)
*dst++ = clear_cell;
if (iflags.debug.immediateflips || !g.program_state.in_moveloop)
if (iflags.debug.immediateflips || !gp.program_state.in_moveloop)
back_buffer_flip();
}
@@ -912,7 +912,7 @@ void buffer_write(cell_t * buffer, cell_t * cell, COORD pos)
cell_t * dst = buffer + (console.width * pos.Y) + pos.X;
*dst = *cell;
if ((iflags.debug.immediateflips || !g.program_state.in_moveloop)
if ((iflags.debug.immediateflips || !gp.program_state.in_moveloop)
&& buffer == console.back_buffer)
back_buffer_flip();
}
@@ -1071,7 +1071,7 @@ process_keystroke(
int ch;
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numberpad |= 0x10;
#endif
ch = keyboard_handling.pProcessKeystroke(
@@ -1103,11 +1103,11 @@ tgetch(void)
if (iflags.debug_fuzzer)
return randomkey();
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numpad |= 0x10;
#endif
return (g.program_state.done_hup)
return (gp.program_state.done_hup)
? '\033'
: keyboard_handling.pCheckInput(
console.hConIn, &ir, &count, numpad, 0, &mod, &cc);
@@ -1132,10 +1132,10 @@ console_poskey(coordxy *x, coordxy *y, int *mod)
return poskey;
}
#ifdef QWERTZ_SUPPORT
if (g.Cmd.swap_yz)
if (gc.Cmd.swap_yz)
numpad |= 0x10;
#endif
ch = (g.program_state.done_hup)
ch = (gp.program_state.done_hup)
? '\033'
: keyboard_handling.pCheckInput(
console.hConIn, &ir, &count, numpad, 1, mod, &cc);
@@ -2104,8 +2104,8 @@ check_font_widths(void)
boolean used[256];
memset(used, 0, sizeof(used));
for (int i = 0; i < SYM_MAX; i++) {
used[g.primary_syms[i]] = TRUE;
used[g.rogue_syms[i]] = TRUE;
used[gp.primary_syms[i]] = TRUE;
used[gr.rogue_syms[i]] = TRUE;
}
int wcUsedCount = 0;

View File

@@ -263,16 +263,16 @@ set_default_prefix_locations(const char *programPath)
if (test_portable_config(executable_path,
portable_device_path, sizeof portable_device_path)) {
g.fqn_prefix[SYSCONFPREFIX] = executable_path;
g.fqn_prefix[CONFIGPREFIX] = portable_device_path;
g.fqn_prefix[HACKPREFIX] = portable_device_path;
g.fqn_prefix[SAVEPREFIX] = portable_device_path;
g.fqn_prefix[LEVELPREFIX] = portable_device_path;
g.fqn_prefix[BONESPREFIX] = portable_device_path;
g.fqn_prefix[SCOREPREFIX] = portable_device_path;
g.fqn_prefix[LOCKPREFIX] = portable_device_path;
g.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
g.fqn_prefix[DATAPREFIX] = executable_path;
gf.fqn_prefix[SYSCONFPREFIX] = executable_path;
gf.fqn_prefix[CONFIGPREFIX] = portable_device_path;
gf.fqn_prefix[HACKPREFIX] = portable_device_path;
gf.fqn_prefix[SAVEPREFIX] = portable_device_path;
gf.fqn_prefix[LEVELPREFIX] = portable_device_path;
gf.fqn_prefix[BONESPREFIX] = portable_device_path;
gf.fqn_prefix[SCOREPREFIX] = portable_device_path;
gf.fqn_prefix[LOCKPREFIX] = portable_device_path;
gf.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
gf.fqn_prefix[DATAPREFIX] = executable_path;
} else {
if(!build_known_folder_path(&FOLDERID_Profile, profile_path,
sizeof(profile_path), FALSE))
@@ -290,16 +290,16 @@ set_default_prefix_locations(const char *programPath)
versioned_global_data_path, sizeof(versioned_global_data_path), TRUE))
strcpy(versioned_global_data_path, executable_path);
g.fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
g.fqn_prefix[CONFIGPREFIX] = profile_path;
g.fqn_prefix[HACKPREFIX] = versioned_profile_path;
g.fqn_prefix[SAVEPREFIX] = versioned_user_data_path;
g.fqn_prefix[LEVELPREFIX] = versioned_user_data_path;
g.fqn_prefix[BONESPREFIX] = versioned_global_data_path;
g.fqn_prefix[SCOREPREFIX] = versioned_global_data_path;
g.fqn_prefix[LOCKPREFIX] = versioned_global_data_path;
g.fqn_prefix[TROUBLEPREFIX] = versioned_profile_path;
g.fqn_prefix[DATAPREFIX] = executable_path;
gf.fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
gf.fqn_prefix[CONFIGPREFIX] = profile_path;
gf.fqn_prefix[HACKPREFIX] = versioned_profile_path;
gf.fqn_prefix[SAVEPREFIX] = versioned_user_data_path;
gf.fqn_prefix[LEVELPREFIX] = versioned_user_data_path;
gf.fqn_prefix[BONESPREFIX] = versioned_global_data_path;
gf.fqn_prefix[SCOREPREFIX] = versioned_global_data_path;
gf.fqn_prefix[LOCKPREFIX] = versioned_global_data_path;
gf.fqn_prefix[TROUBLEPREFIX] = versioned_profile_path;
gf.fqn_prefix[DATAPREFIX] = executable_path;
}
}
@@ -370,18 +370,18 @@ void copy_sysconf_content(void)
/* Using the SYSCONFPREFIX path, lock it so that it does not change */
fqn_prefix_locked[SYSCONFPREFIX] = TRUE;
update_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
update_file(gf.fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
gf.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
// update_file(g.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE,
// g.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
// update_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS_TEMPLATE,
// gf.fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
copy_file(g.fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
g.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
copy_file(gf.fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
gf.fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
update_file(g.fqn_prefix[SYSCONFPREFIX], SYMBOLS,
g.fqn_prefix[DATAPREFIX], SYMBOLS, TRUE);
update_file(gf.fqn_prefix[SYSCONFPREFIX], SYMBOLS,
gf.fqn_prefix[DATAPREFIX], SYMBOLS, TRUE);
}
@@ -391,13 +391,13 @@ void copy_config_content(void)
fqn_prefix_locked[CONFIGPREFIX] = TRUE;
/* Keep templates up to date */
update_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
update_file(gf.fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
gf.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
/* NOTE: We never replace .nethackrc or sysconf */
copy_file(g.fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
g.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
copy_file(gf.fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
gf.fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
}
void
@@ -406,10 +406,10 @@ copy_hack_content(void)
nhassert(fqn_prefix_locked[HACKPREFIX]);
/* Keep Guidebook and opthelp up to date */
update_file(g.fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
g.fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
update_file(g.fqn_prefix[HACKPREFIX], OPTIONFILE,
g.fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
update_file(gf.fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
gf.fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
update_file(gf.fqn_prefix[HACKPREFIX], OPTIONFILE,
gf.fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
}
extern const char *known_handling[]; /* symbols.c */
extern const char *known_restrictions[]; /* symbols.c */
@@ -466,7 +466,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
#endif
#endif
g.hname = "NetHack"; /* used for syntax messages */
gh.hname = "NetHack"; /* used for syntax messages */
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
/* Save current directory and make sure it gets restored when
@@ -479,7 +479,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
set_default_prefix_locations(argv[0]);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdir(g.fqn_prefix[HACKPREFIX]);
chdir(gf.fqn_prefix[HACKPREFIX]);
#endif
if (GUILaunched || IsDebuggerPresent())
@@ -544,8 +544,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
Strcpy(default_window_sys, "curses");
#endif /* CURSES */
#endif /* TTY */
if (iflags.windowtype_deferred && g.chosen_windowtype[0])
windowtype = g.chosen_windowtype;
if (iflags.windowtype_deferred && gc.chosen_windowtype[0])
windowtype = gc.chosen_windowtype;
}
choose_windows(windowtype);
@@ -564,8 +564,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (WINDOWPORT(tty))
toggle_mouse_support();
if (g.symset[PRIMARYSET].handling
&& !symset_is_compatible(g.symset[PRIMARYSET].handling,
if (gs.symset[PRIMARYSET].handling
&& !symset_is_compatible(gs.symset[PRIMARYSET].handling,
windowprocs.wincap2)) {
/* current symset handling and windowtype are
not compatible, feature-wise. Use IBM defaults */
@@ -591,21 +591,21 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
(*utf8graphics_mode_callback)();
#endif
/* strip role,race,&c suffix; calls askname() if g.plname[] is empty
/* strip role,race,&c suffix; calls askname() if gp.plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
set_playmode(); /* sets g.plname to "wizard" for wizard mode */
set_playmode(); /* sets gp.plname to "wizard" for wizard mode */
/* until the getlock code is resolved, override askname()'s
setting of renameallowed; when False, player_selection()
won't resent renaming as an option */
iflags.renameallowed = FALSE;
/* Obtain the name of the logged on user and incorporate
* it into the name. */
Sprintf(fnamebuf, "%s", g.plname);
Sprintf(fnamebuf, "%s", gp.plname);
(void) fname_encode(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
fnamebuf, encodedfnamebuf, BUFSZ);
Sprintf(g.lock, "%s", encodedfnamebuf);
Sprintf(gl.lock, "%s", encodedfnamebuf);
/* regularize(lock); */ /* we encode now, rather than substitute */
if ((getlock_result = getlock()) == 0)
nethack_exit(EXIT_SUCCESS);
@@ -619,8 +619,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
if (!nhfp) {
raw_print("Cannot create lock file");
} else {
g.hackpid = GetCurrentProcessId();
write(nhfp->fd, (genericptr_t) &g.hackpid, sizeof(g.hackpid));
gh.hackpid = GetCurrentProcessId();
write(nhfp->fd, (genericptr_t) &gh.hackpid, sizeof(gh.hackpid));
close_nhfile(nhfp);
}
/*
@@ -641,7 +641,7 @@ attempt_restore:
iflags.news = FALSE;
}
#endif
if (g.early_raw_messages)
if (ge.early_raw_messages)
raw_print("Restoring save file...");
else
pline("Restoring save file...");
@@ -654,12 +654,12 @@ attempt_restore:
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(g.SAVEF, SAVEPREFIX, 0));
nh_compress(fqname(gs.SAVEF, SAVEPREFIX, 0));
}
}
}
if (g.program_state.in_self_recover) {
g.program_state.in_self_recover = FALSE;
if (gp.program_state.in_self_recover) {
gp.program_state.in_self_recover = FALSE;
set_savefile_name(TRUE);
}
}
@@ -744,7 +744,7 @@ process_options(int argc, char * argv[])
}
if (!*dir)
error("Flag -d must be followed by a directory name.");
Strcpy(g.hackdir, dir);
Strcpy(gh.hackdir, dir);
}
if (argc > 1) {
@@ -801,11 +801,11 @@ process_options(int argc, char * argv[])
#endif
case 'u':
if (argv[0][2])
(void) strncpy(g.plname, argv[0] + 2, sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0] + 2, sizeof(gp.plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(g.plname, argv[0], sizeof(g.plname) - 1);
(void) strncpy(gp.plname, argv[0], sizeof(gp.plname) - 1);
} else
raw_print("Player name expected after -u");
break;
@@ -845,7 +845,7 @@ process_options(int argc, char * argv[])
case 'w': /* windowtype */
config_error_init(FALSE, "command line", FALSE);
if (strlen(&argv[0][2]) < (WINTYPELEN - 1))
Strcpy(g.chosen_windowtype, &argv[0][2]);
Strcpy(gc.chosen_windowtype, &argv[0][2]);
config_error_done();
break;
case '@':
@@ -882,18 +882,18 @@ nhusage(void)
*/
(void) Sprintf(buf2, "\nUsage:\n%s [-d dir] -s [-r race] [-p profession] "
"[maxrank] [name]...\n or",
g.hname);
gh.hname);
ADD_USAGE(buf2);
(void) Sprintf(
buf2, "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]",
g.hname);
gh.hname);
ADD_USAGE(buf2);
#ifdef NEWS
ADD_USAGE(" [-n]");
#endif
(void) Sprintf(buf2, "\n or\n%s [--showpaths]",
g.hname);
gh.hname);
ADD_USAGE(buf2);
if (!iflags.window_inited)
raw_printf("%s\n", buf1);
@@ -928,7 +928,7 @@ port_help(void)
boolean
authorize_wizard_mode(void)
{
if (!strcmp(g.plname, WIZARD_NAME))
if (!strcmp(gp.plname, WIZARD_NAME))
return TRUE;
return FALSE;
}
@@ -1141,14 +1141,14 @@ eraseoldlocks(void)
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(g.lock, i);
(void) unlink(fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(gl.lock, i);
(void) unlink(fqname(gl.lock, LEVELPREFIX, 0));
}
set_levelfile_name(g.lock, 0);
set_levelfile_name(gl.lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
#endif
if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
if (unlink(fqname(gl.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
@@ -1178,9 +1178,9 @@ getlock(void)
}
/* regularize(lock); */ /* already done in pcmain */
/*Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0)); */
set_levelfile_name(g.lock, 0);
fq_lock = fqname(g.lock, LEVELPREFIX, 1);
/*Sprintf(tbuf, "%s", fqname(gl.lock, LEVELPREFIX, 0)); */
set_levelfile_name(gl.lock, 0);
fq_lock = fqname(gl.lock, LEVELPREFIX, 1);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
@@ -1261,11 +1261,11 @@ gotlock:
#endif
Sprintf(oops, "cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock,
strerror(ern), " Are you sure that the directory",
g.fqn_prefix[LEVELPREFIX]);
gf.fqn_prefix[LEVELPREFIX]);
raw_print(oops);
} else {
if (write(fd, (char *) &g.hackpid, sizeof(g.hackpid))
!= sizeof(g.hackpid)) {
if (write(fd, (char *) &gh.hackpid, sizeof(gh.hackpid))
!= sizeof(gh.hackpid)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif