status 'fieldorder'

DEC C in one of its non-ANSI modes didn't like
 fieldorder = test ? &array1 : &array2;
It first complained that '&' applied to an array has no effect (which
was typically true in pre-ANSI environments) and once those '&'s are
ignored, the attempted assignment didn't match the variable's type.
That code was actually more complicated that it needed to be; slightly
simpler code works as intended.
This commit is contained in:
PatR
2019-04-19 12:28:14 -07:00
parent 4aa673c20e
commit 6c84ccc241
2 changed files with 13 additions and 13 deletions

View File

@@ -287,7 +287,7 @@ boolean border;
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD,
blPAD, blPAD, blPAD, blPAD }
};
const enum statusfields (*fieldorder)[3][15];
const enum statusfields (*fieldorder)[15];
xchar spacing[MAXBLSTATS], valline[MAXBLSTATS];
enum statusfields fld, prev_fld;
char *text, *p, cbuf[BUFSZ], ebuf[STATVAL_WIDTH];
@@ -327,7 +327,7 @@ boolean border;
*/
number_of_lines = (iflags.wc2_statuslines < 3) ? 2 : 3;
fieldorder = (number_of_lines != 3) ? &twolineorder : &threelineorder;
fieldorder = (number_of_lines != 3) ? twolineorder : threelineorder;
cbuf[0] = '\0';
x = y = border ? 1 : 0; /* origin; ignored by curs_stat_conds(0) */
@@ -349,7 +349,7 @@ boolean border;
/* simplify testing which fields reside on which lines; assume line #0 */
(void) memset((genericptr_t) valline, 0, sizeof valline);
for (j = 1; j < number_of_lines; ++j)
for (i = 0; (fld = (*fieldorder)[j][i]) != BL_FLUSH; ++i)
for (i = 0; (fld = fieldorder[j][i]) != BL_FLUSH; ++i)
valline[fld] = j;
/* iterate 0 and 1 and maybe 2 for status lines 1 and 2 and maybe 3 */
@@ -360,7 +360,7 @@ boolean border;
(void) memset((genericptr_t) spacing, 0, sizeof spacing);
w = xtra = 0; /* w: width so far; xtra: number of extra spaces */
prev_fld = BL_FLUSH;
for (i = 0; (fld = (*fieldorder)[j][i]) != BL_FLUSH; ++i) {
for (i = 0; (fld = fieldorder[j][i]) != BL_FLUSH; ++i) {
/* when the core marks a field as disabled, it doesn't call
status_update() to tell us to throw away the old value, so
polymorph leaves stale XP and rehumanize leaves stale HD */
@@ -484,7 +484,7 @@ boolean border;
/* second pass for line #j -- render it */
x = y = border ? 1 : 0;
wmove(win, y + j, x);
for (i = 0; (fld = (*fieldorder)[j][i]) != BL_FLUSH; ++i) {
for (i = 0; (fld = fieldorder[j][i]) != BL_FLUSH; ++i) {
if (!status_activefields[fld])
continue;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 wintty.c $NHDT-Date: 1554554181 2019/04/06 12:36:21 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.201 $ */
/* NetHack 3.6 wintty.c $NHDT-Date: 1555702074 2019/04/19 19:27:54 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.202 $ */
/* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */
@@ -3698,7 +3698,7 @@ static const enum statusfields
{ BL_LEVELDESC, BL_TIME, BL_CONDITION, BL_FLUSH, blPAD, blPAD,
blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD }
};
static const enum statusfields (*fieldorder)[3][MAX_PER_ROW];
static const enum statusfields (*fieldorder)[MAX_PER_ROW];
static int finalx[3][2]; /* [rows][NOW or BEFORE] */
static boolean windowdata_init = FALSE;
@@ -3738,7 +3738,7 @@ tty_status_init()
int i, num_rows;
num_rows = (iflags.wc2_statuslines < 3) ? 2 : 3;
fieldorder = (num_rows != 3) ? &twolineorder : &threelineorder;
fieldorder = (num_rows != 3) ? twolineorder : threelineorder;
for (i = 0; i < MAXBLSTATS; ++i) {
tty_status[NOW][i].idx = BL_FLUSH;
@@ -3876,9 +3876,9 @@ unsigned long *colormasks;
/* should be checking for first enabled field here rather than
just first field, but 'fieldorder' doesn't start any rows
with fields which can be disabled so [any_row][0] suffices */
if (*fmt == ' ' && (fldidx == (*fieldorder)[0][0]
|| fldidx == (*fieldorder)[1][0]
|| fldidx == (*fieldorder)[2][0]))
if (*fmt == ' ' && (fldidx == fieldorder[0][0]
|| fldidx == fieldorder[1][0]
|| fldidx == fieldorder[2][0]))
++fmt; /* skip leading space for first field on line */
Sprintf(status_vals[fldidx], fmt, text);
tty_status[NOW][fldidx].idx = fldidx;
@@ -4025,7 +4025,7 @@ int sz[3];
sz[row] = 0;
col = 1;
update_right = FALSE;
for (i = 0; (idx = (*fieldorder)[row][i]) != BL_FLUSH; ++i) {
for (i = 0; (idx = fieldorder[row][i]) != BL_FLUSH; ++i) {
if (!status_activefields[idx])
continue;
if (!tty_status[NOW][idx].valid)
@@ -4328,7 +4328,7 @@ render_status(VOID_ARGS)
HUPSKIP();
y = row;
tty_curs(WIN_STATUS, 1, y);
for (i = 0; (idx = (*fieldorder)[row][i]) != BL_FLUSH; ++i) {
for (i = 0; (idx = fieldorder[row][i]) != BL_FLUSH; ++i) {
if (!status_activefields[idx])
continue;
x = tty_status[NOW][idx].x;