From: Pasi Kallinen Date: Mon, 26 Mar 2018 19:58:28 +0000 (+0300) Subject: Compile-time option to allow some prompts remember the input X-Git-Tag: NetHack-3.6.1_RC01~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94ad7512a66fd96b8939b3fa7246f0d36764438f;p=nethack Compile-time option to allow some prompts remember the input Define EDIT_GETLIN to make the tty, X11, and Qt4 windowports to remember the input strings for wishing and annotation. --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index f48947ce9..0e09c8eb8 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -831,6 +831,7 @@ win32gui: save and load map colors from registry X11: add new character selection dialog, and obey player_selection:dialog unix: reduce makefile verbosity by default win32gui: new player selection dialog +tty, x11, qt4: compile-time option to allow some prompts remember the input NetHack Community Patches (or Variation) Included diff --git a/include/config.h b/include/config.h index d695c40d2..c3234839c 100644 --- a/include/config.h +++ b/include/config.h @@ -514,6 +514,11 @@ typedef unsigned char uchar; but it isn't necessary for successful operation of the program */ #define FREE_ALL_MEMORY /* free all memory at exit */ +/* EDIT_GETLIN makes the string input in TTY, Qt4, and X11 + so some prompts will remember the previously input text + (within the same session) */ +/* #define EDIT_GETLIN */ + /* #define DUMPLOG */ /* End-of-game dump logs */ #ifdef DUMPLOG diff --git a/src/botl.c b/src/botl.c index 78e9b7e59..94cf59ab0 100644 --- a/src/botl.c +++ b/src/botl.c @@ -2740,7 +2740,7 @@ choose_value: if (behavior == BL_TH_VAL_PERCENTAGE || behavior == BL_TH_VAL_ABSOLUTE) { - char inbuf[BUFSZ], buf[BUFSZ]; + char inbuf[BUFSZ] = DUMMY, buf[BUFSZ]; int val; boolean skipltgt = FALSE; boolean gotnum = FALSE; @@ -2902,7 +2902,7 @@ choose_value: hilite.rel = TXT_VALUE; Strcpy(hilite.textmatch, rolelist[rv]); } else { - char inbuf[BUFSZ]; + char inbuf[BUFSZ] = DUMMY; inbuf[0] = '\0'; getlin(qry_buf, inbuf); diff --git a/src/cmd.c b/src/cmd.c index da690f23e..f10ad1f8f 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -750,7 +750,7 @@ wiz_mon_polycontrol(VOID_ARGS) STATIC_PTR int wiz_level_change(VOID_ARGS) { - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; int newlevel; int ret; @@ -3697,7 +3697,7 @@ static int wiz_migrate_mons() { int mcount = 0; - char inbuf[BUFSZ]; + char inbuf[BUFSZ] = DUMMY; struct permonst *ptr; struct monst *mtmp; d_level tolevel; @@ -5449,7 +5449,7 @@ const char *prompt; to give the go-ahead for this query; default is "no" unless the ParanoidConfirm flag is set in which case there's no default */ if (be_paranoid) { - char qbuf[QBUFSZ], ans[BUFSZ]; + char qbuf[QBUFSZ], ans[BUFSZ] = DUMMY; const char *promptprefix = "", *responsetype = ParanoidConfirm ? "(yes|no)" : "(yes) [no]"; diff --git a/src/do_name.c b/src/do_name.c index ae57474f9..ea25eb3e7 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -1109,7 +1109,7 @@ char *monnambuf, *usrbuf; STATIC_OVL void do_mname() { - char buf[BUFSZ], monnambuf[BUFSZ], qbuf[QBUFSZ]; + char buf[BUFSZ] = DUMMY, monnambuf[BUFSZ], qbuf[QBUFSZ]; coord cc; int cx, cy; struct monst *mtmp = 0; @@ -1188,7 +1188,7 @@ void do_oname(obj) register struct obj *obj; { - char *bufp, buf[BUFSZ], bufcpy[BUFSZ], qbuf[QBUFSZ]; + char *bufp, buf[BUFSZ] = DUMMY, bufcpy[BUFSZ], qbuf[QBUFSZ]; const char *aname; short objtyp; @@ -1443,7 +1443,7 @@ void docall(obj) struct obj *obj; { - char buf[BUFSZ], qbuf[QBUFSZ]; + char buf[BUFSZ] = DUMMY, qbuf[QBUFSZ]; char **str1; if (!obj->dknown) diff --git a/src/dungeon.c b/src/dungeon.c index bb7bce9b1..8408c4aa4 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -2034,17 +2034,24 @@ int donamelevel() { mapseen *mptr; - char nbuf[BUFSZ]; /* Buffer for response */ + char nbuf[BUFSZ] = DUMMY; /* Buffer for response */ if (!(mptr = find_mapseen(&u.uz))) return 0; +#ifdef EDIT_GETLIN + if (mptr->custom) { + (void) strncpy(nbuf, mptr->custom, BUFSZ); + nbuf[BUFSZ-1] = '\0'; + } +#else if (mptr->custom) { char tmpbuf[BUFSZ]; Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom, strlen(mptr->custom) > 30 ? "..." : ""); getlin(tmpbuf, nbuf); } else +#endif getlin("What do you want to call this dungeon level?", nbuf); if (index(nbuf, '\033')) return 0; diff --git a/src/invent.c b/src/invent.c index 1cd0cdd1a..b997294ba 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1593,7 +1593,7 @@ unsigned *resultflags; int oletct, iletct, unpaid, oc_of_sym; char sym, *ip, olets[MAXOCLASSES + 5], ilets[MAXOCLASSES + 10]; char extra_removeables[3 + 1]; /* uwep,uswapwep,uquiver */ - char buf[BUFSZ], qbuf[QBUFSZ]; + char buf[BUFSZ] = DUMMY, qbuf[QBUFSZ]; if (!invent) { You("have nothing to %s.", word); diff --git a/src/mail.c b/src/mail.c index af5773af1..8fae06005 100644 --- a/src/mail.c +++ b/src/mail.c @@ -691,7 +691,7 @@ struct obj *otmp; { #ifdef SHELL /* can't access mail reader without spawning subprocess */ const char *txt, *cmd; - char *p, buf[BUFSZ], qbuf[BUFSZ]; + char *p, buf[BUFSZ] = DUMMY, qbuf[BUFSZ]; int len; /* there should be a command in OMAILCMD */ diff --git a/src/minion.c b/src/minion.c index e690d22d1..f15bef3d7 100644 --- a/src/minion.c +++ b/src/minion.c @@ -298,7 +298,7 @@ long bribe(mtmp) struct monst *mtmp; { - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; long offer; long umoney = money_cnt(invent); diff --git a/src/mon.c b/src/mon.c index 7e82ba651..6c87c81ff 100644 --- a/src/mon.c +++ b/src/mon.c @@ -3266,7 +3266,7 @@ struct monst *mon; /* for debugging: allow control of polymorphed monster */ if (wizard && iflags.mon_polycontrol) { - char pprompt[BUFSZ], buf[BUFSZ]; + char pprompt[BUFSZ], buf[BUFSZ] = DUMMY; int monclass; Sprintf(pprompt, "Change %s @ %s into what kind of monster?", diff --git a/src/music.c b/src/music.c index 6ecd43630..f28841ede 100644 --- a/src/music.c +++ b/src/music.c @@ -609,7 +609,7 @@ int do_play_instrument(instr) struct obj *instr; { - char buf[BUFSZ], c = 'y'; + char buf[BUFSZ] = DUMMY, c = 'y'; char *s; int x, y; boolean ok; diff --git a/src/options.c b/src/options.c index 1228f1a90..97a095d9d 100644 --- a/src/options.c +++ b/src/options.c @@ -2836,7 +2836,7 @@ boolean tinitial, tfrom_file; fullname = "pickup_types"; if (match_optname(opts, fullname, 8, TRUE)) { char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], qbuf[QBUFSZ], - abuf[BUFSZ]; + abuf[BUFSZ] = DUMMY; int oc_sym; boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu; @@ -4100,7 +4100,7 @@ int doset() /* changing options via menu by Per Liboriussen */ { static boolean made_fmtstr = FALSE; - char buf[BUFSZ], buf2[BUFSZ]; + char buf[BUFSZ], buf2[BUFSZ] = DUMMY; const char *name; int i = 0, pass, boolcount, pick_cnt, pick_idx, opt_indx; boolean *bool_p; @@ -4779,7 +4779,7 @@ boolean setinitial, setfromfile; iflags.menu_headings = mhattr; } else if (!strcmp("msgtype", optname)) { int opt_idx, nmt, mttyp; - char mtbuf[BUFSZ]; + char mtbuf[BUFSZ] = DUMMY; msgtypes_again: nmt = msgtype_count(); @@ -4841,7 +4841,7 @@ boolean setinitial, setfromfile; } } else if (!strcmp("menucolors", optname)) { int opt_idx, nmc, mcclr, mcattr; - char mcbuf[BUFSZ]; + char mcbuf[BUFSZ] = DUMMY; menucolors_again: nmc = count_menucolors(); @@ -4912,7 +4912,7 @@ boolean setinitial, setfromfile; } } else if (!strcmp("autopickup_exception", optname)) { int opt_idx, pass, totalapes = 0, numapes[2] = { 0, 0 }; - char apebuf[1 + BUFSZ]; /* so &apebuf[1] is BUFSZ long for getlin() */ + char apebuf[1 + BUFSZ] = DUMMY; /* so &apebuf[1] is BUFSZ long for getlin() */ struct autopickup_exception *ape; ape_again: diff --git a/src/pager.c b/src/pager.c index 5b57c27d4..2be4a8f93 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1033,7 +1033,7 @@ coord *click_cc; { boolean quick = (mode == 1); /* use cursor; don't search for "more info" */ boolean clicklook = (mode == 2); /* right mouse-click method */ - char out_str[BUFSZ]; + char out_str[BUFSZ] = DUMMY; const char *firstmatch = 0; struct permonst *pm = 0; int i = '\0', ans = 0; diff --git a/src/pickup.c b/src/pickup.c index 0f53d8cbb..119f3bf2e 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -149,7 +149,7 @@ struct obj *objs; boolean here; int *menu_on_demand; { - char ilets[36], inbuf[BUFSZ]; /* FIXME: hardcoded ilets[] length */ + char ilets[36], inbuf[BUFSZ] = DUMMY; /* FIXME: hardcoded ilets[] length */ int iletct, oclassct; boolean not_everything, filtered; char qbuf[QBUFSZ]; diff --git a/src/polyself.c b/src/polyself.c index 227b7d7f7..5111ec41e 100644 --- a/src/polyself.c +++ b/src/polyself.c @@ -384,7 +384,7 @@ void polyself(psflags) int psflags; { - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; int old_light, new_light, mntmp, class, tryct; boolean forcecontrol = (psflags == 1), monsterpoly = (psflags == 2), draconian = (uarm && Is_dragon_armor(uarm)), diff --git a/src/read.c b/src/read.c index 34dd9a32e..e340b7ebc 100644 --- a/src/read.c +++ b/src/read.c @@ -2017,7 +2017,7 @@ STATIC_OVL void do_class_genocide() { int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0; - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; boolean gameover = FALSE; /* true iff killed self */ for (j = 0;; j++) { @@ -2169,7 +2169,7 @@ int how; /* 3 = forced genocide of player */ /* 5 (4 | 1) = normal genocide from throne */ { - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; register int i, killplayer = 0; register int mndx; register struct permonst *ptr; @@ -2425,7 +2425,7 @@ struct obj *from_obj; boolean create_particular() { - char buf[BUFSZ], *bufp, monclass; + char buf[BUFSZ] = DUMMY, *bufp, monclass; char *tmpp; int which, tryct, i, firstchoice = NON_PM; struct permonst *whichpm = NULL; diff --git a/src/teleport.c b/src/teleport.c index bd3ada997..0a931205c 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -595,7 +595,7 @@ level_tele() register int newlev; d_level newlevel; const char *escape_by_flying = 0; /* when surviving dest of -N */ - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; boolean force_dest = FALSE; if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz)) diff --git a/src/vault.c b/src/vault.c index 296116c53..90a20a0bf 100644 --- a/src/vault.c +++ b/src/vault.c @@ -230,7 +230,7 @@ invault() guard = findgd(); if (++u.uinvault % VAULT_GUARD_TIME == 0 && !guard) { /* if time ok and no guard now. */ - char buf[BUFSZ]; + char buf[BUFSZ] = DUMMY; register int x, y, dd, gx, gy; int lx = 0, ly = 0; long umoney; diff --git a/src/write.c b/src/write.c index b73bfb10b..c9047589f 100644 --- a/src/write.c +++ b/src/write.c @@ -95,7 +95,7 @@ dowrite(pen) register struct obj *pen; { register struct obj *paper; - char namebuf[BUFSZ], *nm, *bp; + char namebuf[BUFSZ] = DUMMY, *nm, *bp; register struct obj *new_obj; int basecost, actualcost; int curseval; diff --git a/src/zap.c b/src/zap.c index 233ebfee7..7e1f08493 100644 --- a/src/zap.c +++ b/src/zap.c @@ -5050,7 +5050,8 @@ int triesleft; void makewish() { - char buf[BUFSZ], promptbuf[BUFSZ]; + static char buf[BUFSZ] = DUMMY; + char promptbuf[BUFSZ]; struct obj *otmp, nothing; int tries = 0; diff --git a/win/Qt4/qt4streq.cpp b/win/Qt4/qt4streq.cpp index 5d03bb996..abe910ff7 100644 --- a/win/Qt4/qt4streq.cpp +++ b/win/Qt4/qt4streq.cpp @@ -83,6 +83,9 @@ bool NetHackQtStringRequestor::Get(char* buffer, int maxchar) resize(fontMetrics().width(prompt.text())*2+50,fontMetrics().height()*4); } +#ifdef EDIT_GETLIN + input.setText(buffer); +#endif centerOnMain(this); show(); input.setFocus(); diff --git a/win/X11/winX.c b/win/X11/winX.c index 6b285a2e5..7c3c600f5 100644 --- a/win/X11/winX.c +++ b/win/X11/winX.c @@ -1623,7 +1623,11 @@ char *input; slide left hiding some chars at the beginning of the response but making room to type more. [Prior to 3.6.1, width wasn't specifiable and answer box always got sized to match the width of the prompt.] */ +#ifdef EDIT_GETLIN + SetDialogResponse(getline_dialog, input, 60); /* set default answer */ +#else SetDialogResponse(getline_dialog, nhStr(""), 60); /* set default answer */ +#endif positionpopup(getline_popup, TRUE); /* center,bottom */ nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog); diff --git a/win/tty/getline.c b/win/tty/getline.c index a73fa4060..a69abd4bd 100644 --- a/win/tty/getline.c +++ b/win/tty/getline.c @@ -56,8 +56,13 @@ getlin_hook_proc hook; cw->flags &= ~WIN_STOP; ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->inread++; +#ifdef EDIT_GETLIN + custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s %s", query, bufp); + bufp = eos(obufp); +#else custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s ", query); *obufp = 0; +#endif for (;;) { (void) fflush(stdout); Strcat(strcat(strcpy(toplines, query), " "), obufp);