]> granicus.if.org Git - nethack/commitdiff
Compile-time option to allow some prompts remember the input
authorPasi Kallinen <paxed@alt.org>
Mon, 26 Mar 2018 19:58:28 +0000 (22:58 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 26 Mar 2018 20:04:53 +0000 (23:04 +0300)
Define EDIT_GETLIN to make the tty, X11, and Qt4 windowports to
remember the input strings for wishing and annotation.

23 files changed:
doc/fixes36.1
include/config.h
src/botl.c
src/cmd.c
src/do_name.c
src/dungeon.c
src/invent.c
src/mail.c
src/minion.c
src/mon.c
src/music.c
src/options.c
src/pager.c
src/pickup.c
src/polyself.c
src/read.c
src/teleport.c
src/vault.c
src/write.c
src/zap.c
win/Qt4/qt4streq.cpp
win/X11/winX.c
win/tty/getline.c

index f48947ce930428dbf228a0d62a9f09d1105b836b..0e09c8eb86fff78b854e1ff8cbefd434db65c12d 100644 (file)
@@ -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
index d695c40d21a36726f436513eec1ec70f6532d4ac..c3234839ceedbc11e5eeeb1dcb0ae579dd87746f 100644 (file)
@@ -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
 
index 78e9b7e595768fdf8582f46c8d166c38a87a0cf6..94cf59ab058c9389408c2980c86506d94fb10151 100644 (file)
@@ -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);
index da690f23e124ef7707ea9402d1968a40e2220f8a..f10ad1f8fe16f5776ccc8006a19c0eca7e119ddd 100644 (file)
--- 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]";
index ae57474f995d8d51ac3ebc0a25d932a9dd752cf3..ea25eb3e7506d42d492c1d769d0bc5fa385dfd73 100644 (file)
@@ -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)
index bb7bce9b1e046186837dee778c164eb17ef18b00..8408c4aa4736fc23eddfea4330dfd291c1af0934 100644 (file)
@@ -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;
index 1cd0cdd1ab2be8da9f1aa50649f0e31926412fef..b997294bab383b919344b1c73b32f93cc970df81 100644 (file)
@@ -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);
index af5773af1b1a009a327aff3d6caf5eff8ad4425b..8fae06005a252dee155b2410c03d139e5a41e0fd 100644 (file)
@@ -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 */
index e690d22d1b673885892fc003c53a2f0a5663aaef..f15bef3d7d6a26110eb0eef7f33ddfe6cf57168d 100644 (file)
@@ -298,7 +298,7 @@ long
 bribe(mtmp)
 struct monst *mtmp;
 {
-    char buf[BUFSZ];
+    char buf[BUFSZ] = DUMMY;
     long offer;
     long umoney = money_cnt(invent);
 
index 7e82ba651b2cf7b0bb73d1442aecd2c35500a69f..6c87c81ffc232135e05add1d0ba67ce8c58432e5 100644 (file)
--- 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?",
index 6ecd43630c9344d91c851e5525b3ed8c285ac283..f28841edeed282923dd958d49186cf15a8795368 100644 (file)
@@ -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;
index 1228f1a90cdd0dc6fa2e06f20ee52025433ff0da..97a095d9d459fa0ff481653a8a16df33f02685db 100644 (file)
@@ -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:
index 5b57c27d4d2c88d90555bbf2e4b1efd6a765e3c2..2be4a8f93f5a8d4aadf99dfb71c61386aef0aabc 100644 (file)
@@ -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;
index 0f53d8cbb78b0885501e909d96641ee4bef108ed..119f3bf2ebd73489da4b73c949f7e9a455f8e7ba 100644 (file)
@@ -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];
index 227b7d7f7b1bb30f95f1f1921696ec13dd730aed..5111ec41e7ca4b79ea681d9ae5d0a8333ace2aa1 100644 (file)
@@ -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)),
index 34dd9a32e40f2f8a6b353ebf8e56327049db184a..e340b7ebcd30950c30efe4b0451e3955f7693cbc 100644 (file)
@@ -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;
index bd3ada997db7e0ceb985293b980daacfb28382fe..0a931205c54fecec98b74310f554e13fe69c6bc2 100644 (file)
@@ -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))
index 296116c5320ca31e6cb67fc549c4ca3146ca95a1..90a20a0bfab67f55d21a1436ed420c430bdab57c 100644 (file)
@@ -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;
index b73bfb10bc6ace2fad6d9559cd17b20eb467afdd..c9047589f8419d93bc079823fc527c46b3d86fa1 100644 (file)
@@ -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;
index 233ebfee7e21a70e4a514ddea3b3821ecc5cce6f..7e1f084936db620be7899b17e16182745ab0bacc 100644 (file)
--- 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;
 
index 5d03bb996368b8dd760c2d8cc1a654b4596ce6a0..abe910ff7ae4e5942cafa7c2c726720383ce7caa 100644 (file)
@@ -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();
index 6b285a2e550ac901997a3bff20ad0faa4c2abae3..7c3c600f534fbe14e412c0dd742489ba6844ef4d 100644 (file)
@@ -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);
index a73fa4060d01867ca28993f9bd2ae9e82eae5145..a69abd4bd4f67ff7154243c7e02e26c3f7eccfa6 100644 (file)
@@ -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);