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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user