From f7bf56555e56e05dd62893b62f70ada90595a865 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 5 Oct 2019 16:42:13 -0700 Subject: [PATCH 1/4] fix pull request #227 - running over engravings Fixes #227 Travel, , all stop on engravings, but told the player what the engraving said and kept going. The message output is buffered until map update or another message, so player couldn't tell where hero was at the time the engraving got shown. Make running stop on engravings. --- doc/fixes36.3 | 6 +++++- src/engrave.c | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 5ea4594cc..0ca806da6 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.124 $ $NHDT-Date: 1570232224 2019/10/04 23:37:04 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.125 $ $NHDT-Date: 1570318925 2019/10/05 23:42:05 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -173,6 +173,10 @@ avoid 'object lost' panic when polymorph causes loss of levitation boots or disrobing/dropping in order to crawl out chooses to drop those boots 'sortloot's attempt to group musical instruments separately from other tools didn't work as intended due to missing 'break' in sortloot_classify() + running told player about engravings as they were being moved + over but buffered output didn't show it until hero stopped, so it + wasn't possible to tell where they were, unlike all other forms of + multiple movement; stop running if/when an engraving is reached Fixes to Post-3.6.2 Problems that Were Exposed Via git Repository diff --git a/src/engrave.c b/src/engrave.c index d127c4495..a1fa986e4 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 engrave.c $NHDT-Date: 1456304550 2016/02/24 09:02:30 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.61 $ */ +/* NetHack 3.6 engrave.c $NHDT-Date: 1570318925 2019/10/05 23:42:05 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.75 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -314,7 +314,6 @@ int x, y; { register struct engr *ep = engr_at(x, y); int sensed = 0; - char buf[BUFSZ]; /* Sensing an engraving does not require sight, * nor does it necessarily imply comprehension (literacy). @@ -363,17 +362,22 @@ int x, y; impossible("%s is written in a very strange way.", Something); sensed = 1; } + if (sensed) { - char *et; - unsigned maxelen = BUFSZ - sizeof("You feel the words: \"\". "); - if (strlen(ep->engr_txt) > maxelen) { - (void) strncpy(buf, ep->engr_txt, (int) maxelen); + char *et, buf[BUFSZ]; + int maxelen = (int) (sizeof buf + /* sizeof "literal" counts terminating \0 */ + - sizeof "You feel the words: \"\"."); + + if ((int) strlen(ep->engr_txt) > maxelen) { + (void) strncpy(buf, ep->engr_txt, maxelen); buf[maxelen] = '\0'; et = buf; - } else + } else { et = ep->engr_txt; + } You("%s: \"%s\".", (Blind) ? "feel the words" : "read", et); - if (context.run > 1) + if (context.run > 0) nomul(0); } } From 0d76f68f2c233c18eebf16d6e5f2afce2f7c0726 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 5 Oct 2019 16:49:34 -0700 Subject: [PATCH 2/4] tty xputc() Another part of github issue 227. Casting a function pointer when passing it to another function is iffy when lying about the return type. tputs() expects a routine which returns int, so give it one. Other xputc() usage is equivalent to putchar(), so define xputc() with the same function signature as that has. The tputs() declarations in system.h should probably be changed (third argument is a function which takes an int rather than unspecified parameters) but I've left them alone. I made that change to tputs() in sys/share/tclib.c though. NT and MSDOS changes are untested. tclib.c compiles ok with clang- as-gcc on OSX but hasn't been tested with the port that uses it (VMS). --- include/wintty.h | 11 +------- sys/msdos/video.c | 13 ++++++---- sys/share/tclib.c | 9 ++++--- sys/winnt/nttty.c | 10 +++++--- sys/winnt/stubs.c | 6 ++--- win/tty/termcap.c | 64 +++++++++++++++++++++++------------------------ 6 files changed, 54 insertions(+), 59 deletions(-) diff --git a/include/wintty.h b/include/wintty.h index 4863d6e10..a42ed22d4 100644 --- a/include/wintty.h +++ b/include/wintty.h @@ -114,16 +114,7 @@ E void FDECL(tty_startup, (int *, int *)); #ifndef NO_TERMS E void NDECL(tty_shutdown); #endif -#if defined(apollo) -/* Apollos don't widen old-style function definitions properly -- they try to - * be smart and use the prototype, or some such strangeness. So we have to - * define UNWIDENDED_PROTOTYPES (in tradstdc.h), which makes CHAR_P below a - * char. But the tputs termcap call was compiled as if xputc's argument - * actually would be expanded. So here, we have to make an exception. */ -E void FDECL(xputc, (int)); -#else -E void FDECL(xputc, (CHAR_P)); -#endif +E int FDECL(xputc, (int)); E void FDECL(xputs, (const char *)); #if defined(SCREEN_VGA) || defined(SCREEN_8514) E void FDECL(xputg, (int, int, unsigned)); diff --git a/sys/msdos/video.c b/sys/msdos/video.c index 76002cdf6..1429ade16 100644 --- a/sys/msdos/video.c +++ b/sys/msdos/video.c @@ -571,8 +571,10 @@ const char *s; } } -void xputc(ch) /* write out character (and attribute) */ -char ch; +/* same signature as 'putchar()' with potential failure result ignored */ +int +xputc(ch) /* write out character (and attribute) */ +int ch; { int i; char attribute; @@ -591,16 +593,17 @@ char ch; vesa_xputc(ch, attribute); #endif /*SCREEN_VESA*/ } + return 0; } -void xputg(glyphnum, ch, - special) /* write out a glyph picture at current location */ +/* write out a glyph picture at current location */ +void xputg(glyphnum, ch, special) int glyphnum; int ch; unsigned special; { if (!iflags.grmode || !iflags.tile_view) { - xputc((char) ch); + (void) xputc((char) ch); #ifdef SCREEN_VGA } else if (iflags.grmode && iflags.usevga) { vga_xputg(glyphnum, ch, special); diff --git a/sys/share/tclib.c b/sys/share/tclib.c index c158741e5..b47f41815 100644 --- a/sys/share/tclib.c +++ b/sys/share/tclib.c @@ -27,7 +27,7 @@ int FDECL(tgetnum, (const char *)); char *FDECL(tgetstr, (const char *, char **)); char *FDECL(tgoto, (const char *, int, int)); char *FDECL(tparam, (const char *, char *, int, int, int, int, int)); -void FDECL(tputs, (const char *, int, int (*)())); +void FDECL(tputs, (const char *, int, int (*)(int))); /* local support data */ static char *tc_entry; @@ -502,9 +502,10 @@ int row, col, row2, col2; /* send a string to the terminal, possibly padded with trailing NULs */ void tputs(string, range, output_func) -const char *string; /* characters to output */ -int range; /* number of lines affected, used for `*' delays */ -int (*output_func)(); /* actual output routine; return value ignored */ +const char *string; /* characters to output */ +int range; /* number of lines affected, used for `*' delays */ +int FDECL((*output_func),(int)); /* actual output routine; + * return value ignored */ { register int c, num = 0; register const char *p = string; diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 3233dc9cb..60d9db128 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -530,12 +530,14 @@ int x, y; set_console_cursor(x, y); } -void +/* same signature as 'putchar()' with potential failure result ignored */ +int xputc(ch) -char ch; +int ch; { set_console_cursor(ttyDisplay->curx, ttyDisplay->cury); - xputc_core(ch); + xputc_core((char) ch); + return 0; } void @@ -543,7 +545,7 @@ xputs(s) const char *s; { int k; - int slen = strlen(s); + int slen = (int) strlen(s); if (ttyDisplay) set_console_cursor(ttyDisplay->curx, ttyDisplay->cury); diff --git a/sys/winnt/stubs.c b/sys/winnt/stubs.c index ca7313b5b..fa4a9361c 100644 --- a/sys/winnt/stubs.c +++ b/sys/winnt/stubs.c @@ -82,11 +82,11 @@ int mode; return; } -void +int xputc(ch) -char ch; +int ch; { - return; + return 0; } void diff --git a/win/tty/termcap.c b/win/tty/termcap.c index 9e0a76eb9..0e256ee91 100644 --- a/win/tty/termcap.c +++ b/win/tty/termcap.c @@ -495,12 +495,10 @@ tty_end_screen() /* Cursor movements */ /* Note to overlay tinkerers. The placement of this overlay controls the - location - of the function xputc(). This function is not currently in trampoli.[ch] - files for what is deemed to be performance reasons. If this define is - moved - and or xputc() is taken out of the ROOT overlay, then action must be taken - in trampoli.[ch]. */ + location of the function xputc(). This function is not currently in + trampoli.[ch] files for what is deemed to be performance reasons. If + this define is moved and or xputc() is taken out of the ROOT overlay, + then action must be taken in trampoli.[ch]. */ void nocmov(x, y) @@ -528,7 +526,7 @@ int x, y; cmov(x, y); } else { while ((int) ttyDisplay->cury < y) { - xputc('\n'); + (void) xputc('\n'); ttyDisplay->curx = 0; ttyDisplay->cury++; } @@ -561,16 +559,27 @@ register int x, y; ttyDisplay->curx = x; } -/* See note above. xputc() is a special function. */ -void +/* See note above. xputc() is a special function for overlays. */ +int xputc(c) -#if defined(apollo) - int c; -#else - char c; -#endif +int c; /* actually char, but explicitly specify its widened type */ { - (void) putchar(c); + /* + * Note: xputc() as a direct all to putchar() doesn't make any + * sense _if_ putchar() is a function. But if it is a macro, an + * overlay configuration would want to avoid hidden code bloat + * from multiple putchar() expansions. And it gets passed as an + * argument to tputs() so we have to guarantee an actual function + * (while possibly lacking ANSI's (func) syntax to override macro). + * + * xputc() used to be declared as 'void xputc(c) char c; {}' but + * avoiding the proper type 'int' just to avoid (void) casts when + * ignoring the result can't have been sufficent reason to add it. + * It also had '#if apollo' conditional to have the arg be int. + * Matching putchar()'s declaration and using explicit casts where + * warranted is more robust, so we're just a jacket around that. + */ + return putchar(c); } void @@ -579,13 +588,9 @@ const char *s; { #ifndef TERMLIB (void) fputs(s, stdout); -#else -#if defined(NHSTDC) || defined(ULTRIX_PROTO) - tputs(s, 1, (int (*) ()) xputc); #else tputs(s, 1, xputc); #endif -#endif } void @@ -599,7 +604,7 @@ cl_end() /* this looks terrible, especially on a slow terminal but is better than nothing */ while (cx < CO) { - xputc(' '); + (void) xputc(' '); cx++; } tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, @@ -754,25 +759,18 @@ tty_delay_output() /* BUG: if the padding character is visible, as it is on the 5620 then this looks terrible. */ if (flags.null) { + tputs( #ifdef TERMINFO -/* cbosgd!cbcephus!pds for SYS V R2 */ -#ifdef NHSTDC - tputs("$<50>", 1, (int (*) ()) xputc); + "$<50>", #else - tputs("$<50>", 1, xputc); -#endif -#else -#if defined(NHSTDC) || defined(ULTRIX_PROTO) - tputs("50", 1, (int (*) ()) xputc); -#else - tputs("50", 1, xputc); -#endif + "50", #endif + 1, xputc); } else if (ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) { /* delay by sending cm(here) an appropriate number of times */ register int cmlen = - strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury)); + (int) strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury)); register int i = 500 + tmspc10[ospeed] / 2; while (i > 0) { @@ -794,7 +792,7 @@ cl_eos() /* free after Robert Viduya */ while (cy <= LI - 2) { cl_end(); - xputc('\n'); + (void) xputc('\n'); cy++; } cl_end(); From 57d87db92cf6a9ccde7717889661adb01bff59c6 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 5 Oct 2019 22:17:48 -0400 Subject: [PATCH 3/4] tty condition_size() name and return value the return value from condition_size() was unused so eliminate an unused variable warning and rename the function to better reflect that it updates tty_status[NOW][BL_CONDITION].lth --- win/tty/wintty.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 85c1ca59d..09fe76470 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -206,7 +206,7 @@ STATIC_DCL boolean FDECL(check_fields, (BOOLEAN_P, int *)); STATIC_DCL void NDECL(render_status); STATIC_DCL void FDECL(tty_putstatusfield, (const char *, int, int)); STATIC_DCL boolean NDECL(check_windowdata); -STATIC_DCL int NDECL(condition_size); +STATIC_DCL void NDECL(set_condition_length); STATIC_DCL int FDECL(make_things_fit, (BOOLEAN_P)); STATIC_DCL void FDECL(shrink_enc, (int)); STATIC_DCL void FDECL(shrink_dlvl, (int)); @@ -3615,7 +3615,7 @@ char *posbar; * and tries a few different ways to squish a representation * of the status window values onto the 80 column tty display. * ->check_fields() - * ->condition_size() - get the width of all conditions + * ->set_condition_length() - update the width of conditions * ->shrink_enc() - shrink encumbrance message word * ->shrink_dlvl() - reduce the width of Dlvl:42 * @@ -3969,7 +3969,7 @@ STATIC_OVL int make_things_fit(force_update) boolean force_update; { - int trycnt, fitting = 0, condsz, requirement; + int trycnt, fitting = 0, requirement; int rowsz[3], num_rows, condrow, otheroptions = 0; num_rows = (iflags.wc2_statuslines < 3) ? 2 : 3; @@ -3979,7 +3979,7 @@ boolean force_update; shrink_enc(0); if (dlvl_shrinklvl > 0) shrink_dlvl(0); - condsz = condition_size(); + set_condition_length(); for (trycnt = 0; trycnt < 6 && !fitting; ++trycnt) { /* FIXME: this remeasures each line every time even though it is only attempting to shrink one of them and the other one @@ -3997,7 +3997,7 @@ boolean force_update; if (trycnt < 2) { if (cond_shrinklvl < trycnt + 1) { cond_shrinklvl = trycnt + 1; - condsz = condition_size(); + set_condition_length(); } continue; } @@ -4219,13 +4219,12 @@ int x, y; } /* caller must set cond_shrinklvl (0..2) before calling us */ -STATIC_OVL int -condition_size() +STATIC_OVL void +set_condition_length() { long mask; - int c, lth; + int c, lth = 0; - lth = 0; if (tty_condition_bits) { for (c = 0; c < SIZE(conditions); ++c) { mask = conditions[c].mask; @@ -4234,7 +4233,6 @@ condition_size() } } tty_status[NOW][BL_CONDITION].lth = lth; - return lth; } STATIC_OVL void From 193f8c39bd84f77555d4414ace84a2b210849765 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 6 Oct 2019 09:07:49 -0400 Subject: [PATCH 4/4] clear up some reported curses warnings --- win/curses/cursdial.c | 1 + win/curses/cursinit.c | 2 +- win/curses/cursmesg.c | 2 +- win/curses/cursmisc.c | 13 ++++++------- win/curses/cursstat.c | 3 +++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index 0df4921fb..0dea1d26e 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -392,6 +392,7 @@ curses_ext_cmd() extwin = newwin(1, w - 2, y0 + 1, x0 + 1); if (w - 4 < maxlen) maxlen = w - 4; + nhUse(h); /* needed only to give getmaxyx three arguments */ } else { curses_get_window_xy(MESSAGE_WIN, &winx, &winy); curses_get_window_size(MESSAGE_WIN, &messageh, &messagew); diff --git a/win/curses/cursinit.c b/win/curses/cursinit.c index de8730fb5..594849ae2 100644 --- a/win/curses/cursinit.c +++ b/win/curses/cursinit.c @@ -462,7 +462,7 @@ curses_choose_character() tmpchoice[count] = toupper(tmpchoice[count]); } - sprintf(choice, "%s%s", choice, tmpchoice); + strcat(choice, tmpchoice); /* prevent an unnecessary prompt */ rigid_role_checks(); diff --git a/win/curses/cursmesg.c b/win/curses/cursmesg.c index dfca09397..f55085c8a 100644 --- a/win/curses/cursmesg.c +++ b/win/curses/cursmesg.c @@ -202,7 +202,7 @@ curses_block(boolean noscroll) /* noscroll - blocking because of msgtype prev_x = mx, prev_y = my; blink = 0; } - moreattr = !iflags.wc2_guicolor ? A_REVERSE : NONE; + moreattr = !iflags.wc2_guicolor ? (int) A_REVERSE : NONE; curses_toggle_color_attr(win, MORECOLOR, moreattr, ON); if (blink) { wattron(win, A_BLINK); diff --git a/win/curses/cursmisc.c b/win/curses/cursmisc.c index 1eb42fa1e..80ff91c65 100644 --- a/win/curses/cursmisc.c +++ b/win/curses/cursmisc.c @@ -40,13 +40,18 @@ static int parse_escape_sequence(void); int curses_read_char() { - int ch, tmpch; + int ch; +#if defined(ALT_0) || defined(ALT_9) || defined(ALT_A) || defined(ALT_Z) + int tmpch; +#endif /* cancel message suppression; all messages have had a chance to be read */ curses_got_input(); ch = getch(); +#if defined(ALT_0) || defined(ALT_9) || defined(ALT_A) || defined(ALT_Z) tmpch = ch; +#endif ch = curses_convert_keys(ch); if (ch == 0) { @@ -372,7 +377,6 @@ curses_str_remainder(const char *str, int width, int line_num) int strsize = strlen(str) + 1; #if __STDC_VERSION__ >= 199901L char substr[strsize]; - char curstr[strsize]; char tmpstr[strsize]; strcpy(substr, str); @@ -381,7 +385,6 @@ curses_str_remainder(const char *str, int width, int line_num) #define BUFSZ 256 #endif char substr[BUFSZ * 2]; - char curstr[BUFSZ * 2]; char tmpstr[BUFSZ * 2]; if (strsize > (BUFSZ * 2) - 1) { @@ -409,10 +412,6 @@ curses_str_remainder(const char *str, int width, int line_num) if (last_space == 0) { /* No spaces found */ last_space = count - 1; } - for (count = 0; count < last_space; count++) { - curstr[count] = substr[count]; - } - curstr[count] = '\0'; if (substr[count] == '\0') { break; } diff --git a/win/curses/cursstat.c b/win/curses/cursstat.c index 664b9e31e..69f0f758c 100644 --- a/win/curses/cursstat.c +++ b/win/curses/cursstat.c @@ -228,6 +228,7 @@ draw_status() curs_reset_windows(TRUE, TRUE); win = curses_get_nhwin(STATUS_WIN); } + nhUse(ax); /* getmaxyx macro isn't sufficient */ } werase(win); @@ -513,6 +514,7 @@ boolean border; conditions would go if they were on this line */ condstart += (cap_and_hunger == 2) ? spacing[BL_CAP] : (cap_and_hunger == 0) ? 1 : 0; + nhUse(conddummy); /* getyx needed 3 args */ } if (!(cap_and_hunger & 1)) continue; @@ -533,6 +535,7 @@ boolean border; t = (width - (border ? 0 : 1)) - (ex - 1); ebuf[max(t, 2)] = '\0'; /* might still wrap... */ } + nhUse(ey); /* getyx needed 3 args */ } break; case BL_SCORE: