intermediate update to wintty.c as work continues
authornhmall <nhmall@nethack.org>
Mon, 7 May 2018 22:52:50 +0000 (18:52 -0400)
committernhmall <nhmall@nethack.org>
Mon, 7 May 2018 22:52:50 +0000 (18:52 -0400)
win/tty/wintty.c

index d0f364574659ea3993c8855d31765561345f15b2..81335192043069cc31af0761d538767421c283f3 100644 (file)
@@ -176,21 +176,7 @@ STATIC_DCL void FDECL(setup_racemenu, (winid, BOOLEAN_P, int, int, int));
 STATIC_DCL void FDECL(setup_gendmenu, (winid, BOOLEAN_P, int, int, int));
 STATIC_DCL void FDECL(setup_algnmenu, (winid, BOOLEAN_P, int, int, int));
 STATIC_DCL boolean NDECL(reset_role_filtering);
-
-#ifdef STATUS_HILITES
-static long tty_condition_bits;
-static struct tty_status_fields {
-    int color;
-    int attr;
-    coord loc;
-    boolean valid;
-} tty_status[MAXBLSTATS], prev_tty_status[MAXBLSTATS];
-static int st_fld;
-int hpbar_percent, hpbar_color;
-
-static int FDECL(condcolor, (long, unsigned long *));
-static int FDECL(condattr, (long, unsigned long *));
-#endif /* STATUS_HILITES */
+STATIC_DCL void FDECL(status_content, (winid, struct WinDesc *, const char *));
 
 /*
  * A string containing all the default commands -- to add to a list
@@ -2504,8 +2490,7 @@ const char *str;
 {
     register struct WinDesc *cw = 0;
     register char *ob;
-    register const char *nb;
-    register long i, j, n0;
+    register long i, n0;
     boolean attr_match = FALSE;
 
     /* Assume there's a real problem if the window is missing --
@@ -2536,55 +2521,7 @@ const char *str;
         break;
 
     case NHW_STATUS:
-        ob = &cw->data[cw->cury][j = cw->curx];
-        if (context.botlx)
-            *ob = 0;
-        if (!cw->cury && (int) strlen(str) >= CO) {
-            /* the characters before "St:" are unnecessary */
-            nb = index(str, ':');
-            if (nb && nb > str + 2)
-                str = nb - 2;
-        }
-        nb = str;
-#ifdef STATUS_HILITES
-        if (prev_tty_status[st_fld].valid
-            && tty_status[st_fld].loc.x == prev_tty_status[st_fld].loc.x
-            && tty_status[st_fld].loc.y == prev_tty_status[st_fld].loc.y
-            && tty_status[st_fld].color == prev_tty_status[st_fld].color
-            && tty_status[st_fld].attr  == prev_tty_status[st_fld].attr)
-#endif
-        attr_match = TRUE;
-        for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) {
-            if (!*nb) {
-#ifndef STATUS_HILITES
-                if (*ob || context.botlx) {
-#else
-                if (context.botlx) {
-#endif
-                    /* last char printed may be in middle of line */
-                    tty_curs(WIN_STATUS, i, cw->cury);
-                    cl_end();
-                }
-                break;
-            }
-            if (*ob != *nb || !attr_match) {
-#ifdef STATUS_HILITES
-                tty_curs(WIN_STATUS,
-                         tty_status[st_fld].loc.x,
-                         tty_status[st_fld].loc.y);                                
-#endif
-                tty_putsym(WIN_STATUS, i, cw->cury, *nb);
-           }
-            if (*ob)
-                ob++;
-        }
-
-        (void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1);
-        cw->data[cw->cury][cw->cols - 1] = '\0'; /* null terminate */
-#ifndef STATUS_HILITES
-        cw->cury = (cw->cury + 1) % 2;
-        cw->curx = 0;
-#endif
+        status_content(window, cw, str);
         break;
     case NHW_MAP:
         tty_curs(window, cw->curx + 1, cw->cury);
@@ -3444,6 +3381,13 @@ char *posbar;
 }
 #endif /* POSITIONBAR */
 
+
+/*
+ * +------------------+
+ * |  STATUS CODE     |
+ * +------------------+
+ */
 /*
  * The following data structures come from the genl_ routines in
  * src/windows.c and as such are considered to be on the window-port
@@ -3455,6 +3399,20 @@ extern char *status_vals[MAXBLSTATS];
 extern boolean status_activefields[MAXBLSTATS];
 extern winid WIN_STATUS;
 
+#ifdef STATUS_HILITES
+static int FDECL(condcolor, (long, unsigned long *));
+static int FDECL(condattr, (long, unsigned long *));
+static long tty_condition_bits;
+static struct tty_status_fields {
+    int color;
+    int attr;
+    coord loc;
+    boolean valid;
+} tty_status[MAXBLSTATS], prev_tty_status[MAXBLSTATS];
+static int st_fld;
+int hpbar_percent, hpbar_color;
+#endif
+
 void
 tty_status_init()
 {
@@ -3477,60 +3435,70 @@ tty_status_init()
     genl_status_init();
 }
 
-/*
- *  *_status_update()
- *      -- update the value of a status field.
- *      -- the fldindex identifies which field is changing and
- *         is an integer index value from botl.h
- *      -- fldindex could be any one of the following from botl.h:
- *         BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
- *         BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
- *         BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
- *         BL_LEVELDESC, BL_EXP, BL_CONDITION
- *      -- fldindex could also be BL_FLUSH (-1), which is not really
- *         a field index, but is a special trigger to tell the
- *         windowport that it should redisplay all its status fields,
- *         even if no changes have been presented to it.
- *      -- ptr is usually a "char *", unless fldindex is BL_CONDITION.
- *         If fldindex is BL_CONDITION, then ptr is a long value with
- *         any or none of the following bits set (from botl.h):
- *              BL_MASK_STONE           0x00000001L
- *              BL_MASK_SLIME           0x00000002L
- *              BL_MASK_STRNGL          0x00000004L
- *              BL_MASK_FOODPOIS        0x00000008L
- *              BL_MASK_TERMILL         0x00000010L
- *              BL_MASK_BLIND           0x00000020L
- *              BL_MASK_DEAF            0x00000040L
- *              BL_MASK_STUN            0x00000080L
- *              BL_MASK_CONF            0x00000100L
- *              BL_MASK_HALLU           0x00000200L
- *              BL_MASK_LEV             0x00000400L
- *              BL_MASK_FLY             0x00000800L
- *              BL_MASK_RIDE            0x00001000L
- *      -- The value passed for BL_GOLD includes an encoded leading
- *         symbol for GOLD "\GXXXXNNNN:nnn". If the window port needs to use
- *         the textual gold amount without the leading "$:" the port will
- *         have to skip past ':' in the passed "ptr" for the BL_GOLD case.
- *      -- color is an unsigned int.
- *               color_index = color & 0x00FF;       CLR_* value
- *               attribute   = color & 0xFF00 >> 8;  BL_* values
- *         This holds the color and attribute that the field should
- *         be displayed in.
- *         This is relevant for everything except BL_CONDITION fldindex.
- *         If fldindex is BL_CONDITION, this parameter should be ignored,
- *         as condition hilighting is done via the next colormasks
- *         parameter instead.
- *
- *      -- colormasks - pointer to cond_hilites[] array of colormasks.
- *         Only relevant for BL_CONDITION fldindex. The window port
- *         should ignore this parameter for other fldindex values.
- *         Each condition bit must only ever appear in one of the
- *         CLR_ array members, but can appear in multiple HL_ATTCLR_
- *         offsets (because more than one attribute can co-exist).
- *         See doc/window.doc for more details.
- */
+void
+status_content(window, cw, str)
+winid window;
+struct WinDesc *cw;
+const char *str;
+{
+    char *ob;
+    long i, j, n0;
+    const char *nb;
+    boolean attr_match = FALSE;
+    
+    ob = &cw->data[cw->cury][j = cw->curx];
+    if (context.botlx)
+        *ob = 0;
+    if (!cw->cury && (int) strlen(str) >= CO) {
+        /* the characters before "St:" are unnecessary */
+        nb = index(str, ':');
+        if (nb && nb > str + 2)
+            str = nb - 2;
+    }
+    nb = str;
+#ifdef STATUS_HILITES
+    if (prev_tty_status[st_fld].valid
+        && tty_status[st_fld].loc.x == prev_tty_status[st_fld].loc.x
+        && tty_status[st_fld].loc.y == prev_tty_status[st_fld].loc.y
+        && tty_status[st_fld].color == prev_tty_status[st_fld].color
+        && tty_status[st_fld].attr  == prev_tty_status[st_fld].attr)
+#endif
+    attr_match = TRUE;
+    for (i = cw->curx + 1, n0 = cw->cols; i < n0; i++, nb++) {
+        if (!*nb) {
+#ifndef STATUS_HILITES
+            if (*ob || context.botlx) {
+#else
+            if (context.botlx) {
+#endif
+                /* last char printed may be in middle of line */
+                tty_curs(WIN_STATUS, i, cw->cury);
+                cl_end();
+            }
+            break;
+        }
+        if (*ob != *nb || !attr_match) {
+#ifdef STATUS_HILITES
+            tty_curs(WIN_STATUS,
+                     tty_status[st_fld].loc.x,
+                     tty_status[st_fld].loc.y);                                
+#endif
+            tty_putsym(WIN_STATUS, i, cw->cury, *nb);
+        }
+        if (*ob)
+            ob++;
+    }
 
+    (void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1);
+    cw->data[cw->cury][cw->cols - 1] = '\0'; /* null terminate */
+#ifndef STATUS_HILITES
+    cw->cury = (cw->cury + 1) % 2;
+    cw->curx = 0;
+#endif
+    return;
+}
 
+#ifdef STATUS_HILITES
 /* new approach through status_update() only */
 #define Begin_Attr(m) \
             if (m) {                                                          \
@@ -3560,8 +3528,6 @@ tty_status_init()
                     term_end_attr(ATR_BOLD);                                  \
            }
 
-#ifdef STATUS_HILITES
-
 #ifdef TEXTCOLOR
 #define MaybeDisplayCond(bm,txt) \
             if (tty_condition_bits & (bm)) {                                  \
@@ -3593,12 +3559,71 @@ tty_status_init()
                }                                                             \
             }
 #endif
-#define status_putstr(s) \
+
+#define Status_Putstr(s) \
                 tty_status[st_fld].loc.x = (xchar) cw->curx;                  \
                 tty_status[st_fld].loc.y = (xchar) cw->cury;                  \
                 tty_status[st_fld].valid = TRUE;                              \
                 tty_putstr(WIN_STATUS, 0, s);
 
+/*
+ *  tty_status_init()
+ *      -- initialize the tty-specific data structures.
+ *      -- call genl_status_init() to initialize the general data.
+ */
+
+/*
+ *  *_status_update()
+ *      -- update the value of a status field.
+ *      -- the fldindex identifies which field is changing and
+ *         is an integer index value from botl.h
+ *      -- fldindex could be any one of the following from botl.h:
+ *         BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
+ *         BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
+ *         BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
+ *         BL_LEVELDESC, BL_EXP, BL_CONDITION
+ *      -- fldindex could also be BL_FLUSH (-1), which is not really
+ *         a field index, but is a special trigger to tell the
+ *         windowport that it should redisplay all its status fields,
+ *         even if no changes have been presented to it.
+ *      -- ptr is usually a "char *", unless fldindex is BL_CONDITION.
+ *         If fldindex is BL_CONDITION, then ptr is a long value with
+ *         any or none of the following bits set (from botl.h):
+ *              BL_MASK_STONE           0x00000001L
+ *              BL_MASK_SLIME           0x00000002L
+ *              BL_MASK_STRNGL          0x00000004L
+ *              BL_MASK_FOODPOIS        0x00000008L
+ *              BL_MASK_TERMILL         0x00000010L
+ *              BL_MASK_BLIND           0x00000020L
+ *              BL_MASK_DEAF            0x00000040L
+ *              BL_MASK_STUN            0x00000080L
+ *              BL_MASK_CONF            0x00000100L
+ *              BL_MASK_HALLU           0x00000200L
+ *              BL_MASK_LEV             0x00000400L
+ *              BL_MASK_FLY             0x00000800L
+ *              BL_MASK_RIDE            0x00001000L
+ *      -- The value passed for BL_GOLD includes an encoded leading
+ *         symbol for GOLD "\GXXXXNNNN:nnn". If the window port needs to use
+ *         the textual gold amount without the leading "$:" the port will
+ *         have to skip past ':' in the passed "ptr" for the BL_GOLD case.
+ *      -- color is an unsigned int.
+ *               color_index = color & 0x00FF;       CLR_* value
+ *               attribute   = color & 0xFF00 >> 8;  BL_* values
+ *         This holds the color and attribute that the field should
+ *         be displayed in.
+ *         This is relevant for everything except BL_CONDITION fldindex.
+ *         If fldindex is BL_CONDITION, this parameter should be ignored,
+ *         as condition hilighting is done via the next colormasks
+ *         parameter instead.
+ *
+ *      -- colormasks - pointer to cond_hilites[] array of colormasks.
+ *         Only relevant for BL_CONDITION fldindex. The window port
+ *         should ignore this parameter for other fldindex values.
+ *         Each condition bit must only ever appear in one of the
+ *         CLR_ array members, but can appear in multiple HL_ATTCLR_
+ *         offsets (because more than one attribute can co-exist).
+ *         See doc/window.doc for more details.
+ */
 
 void
 tty_status_update(fldidx, ptr, chg, percent, color, colormasks)
@@ -3678,7 +3703,7 @@ unsigned long *colormasks;
                 text = status_vals[fldidx1];
                 if (iflags.hilite_delta) {
                     if (*text == ' ') {
-                        status_putstr(" ");
+                        Status_Putstr(" ");
                         text++;
                     }
                     /* multiple attributes can be in effect concurrently */
@@ -3689,7 +3714,7 @@ unsigned long *colormasks;
 #endif
                }
 
-                status_putstr(text);
+                Status_Putstr(text);
 
                 if (iflags.hilite_delta) {
 #ifdef TEXTCOLOR
@@ -3722,7 +3747,7 @@ unsigned long *colormasks;
                     }
                }
                 if (iflags.hilite_delta && iflags.wc2_hitpointbar) {
-                    status_putstr("[");
+                    Status_Putstr("[");
 #ifdef TEXTCOLOR
                     coloridx = hpbar_color & 0x00FF;
                     /* attridx = (hpbar_color & 0xFF00) >> 8; */
@@ -3778,7 +3803,7 @@ unsigned long *colormasks;
                     /* putmixed() due to GOLD glyph */
                     putmixed(WIN_STATUS, 0, text);
                 } else {
-                    status_putstr(text);
+                    Status_Putstr(text);
                 }
 
                 if (iflags.hilite_delta) {