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

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