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.
This commit is contained in:
Pasi Kallinen
2018-03-26 23:04:53 +03:00
parent 66e50aeeac
commit 94ad7512a6
23 changed files with 55 additions and 29 deletions
+1
View File
@@ -831,6 +831,7 @@ win32gui: save and load map colors from registry
X11: add new character selection dialog, and obey player_selection:dialog X11: add new character selection dialog, and obey player_selection:dialog
unix: reduce makefile verbosity by default unix: reduce makefile verbosity by default
win32gui: new player selection dialog win32gui: new player selection dialog
tty, x11, qt4: compile-time option to allow some prompts remember the input
NetHack Community Patches (or Variation) Included NetHack Community Patches (or Variation) Included
+5
View File
@@ -514,6 +514,11 @@ typedef unsigned char uchar;
but it isn't necessary for successful operation of the program */ but it isn't necessary for successful operation of the program */
#define FREE_ALL_MEMORY /* free all memory at exit */ #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 */ /* #define DUMPLOG */ /* End-of-game dump logs */
#ifdef DUMPLOG #ifdef DUMPLOG
+2 -2
View File
@@ -2740,7 +2740,7 @@ choose_value:
if (behavior == BL_TH_VAL_PERCENTAGE if (behavior == BL_TH_VAL_PERCENTAGE
|| behavior == BL_TH_VAL_ABSOLUTE) { || behavior == BL_TH_VAL_ABSOLUTE) {
char inbuf[BUFSZ], buf[BUFSZ]; char inbuf[BUFSZ] = DUMMY, buf[BUFSZ];
int val; int val;
boolean skipltgt = FALSE; boolean skipltgt = FALSE;
boolean gotnum = FALSE; boolean gotnum = FALSE;
@@ -2902,7 +2902,7 @@ choose_value:
hilite.rel = TXT_VALUE; hilite.rel = TXT_VALUE;
Strcpy(hilite.textmatch, rolelist[rv]); Strcpy(hilite.textmatch, rolelist[rv]);
} else { } else {
char inbuf[BUFSZ]; char inbuf[BUFSZ] = DUMMY;
inbuf[0] = '\0'; inbuf[0] = '\0';
getlin(qry_buf, inbuf); getlin(qry_buf, inbuf);
+3 -3
View File
@@ -750,7 +750,7 @@ wiz_mon_polycontrol(VOID_ARGS)
STATIC_PTR int STATIC_PTR int
wiz_level_change(VOID_ARGS) wiz_level_change(VOID_ARGS)
{ {
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
int newlevel; int newlevel;
int ret; int ret;
@@ -3697,7 +3697,7 @@ static int
wiz_migrate_mons() wiz_migrate_mons()
{ {
int mcount = 0; int mcount = 0;
char inbuf[BUFSZ]; char inbuf[BUFSZ] = DUMMY;
struct permonst *ptr; struct permonst *ptr;
struct monst *mtmp; struct monst *mtmp;
d_level tolevel; d_level tolevel;
@@ -5449,7 +5449,7 @@ const char *prompt;
to give the go-ahead for this query; default is "no" unless the to give the go-ahead for this query; default is "no" unless the
ParanoidConfirm flag is set in which case there's no default */ ParanoidConfirm flag is set in which case there's no default */
if (be_paranoid) { if (be_paranoid) {
char qbuf[QBUFSZ], ans[BUFSZ]; char qbuf[QBUFSZ], ans[BUFSZ] = DUMMY;
const char *promptprefix = "", *responsetype = ParanoidConfirm const char *promptprefix = "", *responsetype = ParanoidConfirm
? "(yes|no)" ? "(yes|no)"
: "(yes) [no]"; : "(yes) [no]";
+3 -3
View File
@@ -1109,7 +1109,7 @@ char *monnambuf, *usrbuf;
STATIC_OVL void STATIC_OVL void
do_mname() do_mname()
{ {
char buf[BUFSZ], monnambuf[BUFSZ], qbuf[QBUFSZ]; char buf[BUFSZ] = DUMMY, monnambuf[BUFSZ], qbuf[QBUFSZ];
coord cc; coord cc;
int cx, cy; int cx, cy;
struct monst *mtmp = 0; struct monst *mtmp = 0;
@@ -1188,7 +1188,7 @@ void
do_oname(obj) do_oname(obj)
register struct obj *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; const char *aname;
short objtyp; short objtyp;
@@ -1443,7 +1443,7 @@ void
docall(obj) docall(obj)
struct obj *obj; struct obj *obj;
{ {
char buf[BUFSZ], qbuf[QBUFSZ]; char buf[BUFSZ] = DUMMY, qbuf[QBUFSZ];
char **str1; char **str1;
if (!obj->dknown) if (!obj->dknown)
+8 -1
View File
@@ -2034,17 +2034,24 @@ int
donamelevel() donamelevel()
{ {
mapseen *mptr; mapseen *mptr;
char nbuf[BUFSZ]; /* Buffer for response */ char nbuf[BUFSZ] = DUMMY; /* Buffer for response */
if (!(mptr = find_mapseen(&u.uz))) if (!(mptr = find_mapseen(&u.uz)))
return 0; return 0;
#ifdef EDIT_GETLIN
if (mptr->custom) {
(void) strncpy(nbuf, mptr->custom, BUFSZ);
nbuf[BUFSZ-1] = '\0';
}
#else
if (mptr->custom) { if (mptr->custom) {
char tmpbuf[BUFSZ]; char tmpbuf[BUFSZ];
Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom, Sprintf(tmpbuf, "Replace annotation \"%.30s%s\" with?", mptr->custom,
strlen(mptr->custom) > 30 ? "..." : ""); strlen(mptr->custom) > 30 ? "..." : "");
getlin(tmpbuf, nbuf); getlin(tmpbuf, nbuf);
} else } else
#endif
getlin("What do you want to call this dungeon level?", nbuf); getlin("What do you want to call this dungeon level?", nbuf);
if (index(nbuf, '\033')) if (index(nbuf, '\033'))
return 0; return 0;
+1 -1
View File
@@ -1593,7 +1593,7 @@ unsigned *resultflags;
int oletct, iletct, unpaid, oc_of_sym; int oletct, iletct, unpaid, oc_of_sym;
char sym, *ip, olets[MAXOCLASSES + 5], ilets[MAXOCLASSES + 10]; char sym, *ip, olets[MAXOCLASSES + 5], ilets[MAXOCLASSES + 10];
char extra_removeables[3 + 1]; /* uwep,uswapwep,uquiver */ char extra_removeables[3 + 1]; /* uwep,uswapwep,uquiver */
char buf[BUFSZ], qbuf[QBUFSZ]; char buf[BUFSZ] = DUMMY, qbuf[QBUFSZ];
if (!invent) { if (!invent) {
You("have nothing to %s.", word); You("have nothing to %s.", word);
+1 -1
View File
@@ -691,7 +691,7 @@ struct obj *otmp;
{ {
#ifdef SHELL /* can't access mail reader without spawning subprocess */ #ifdef SHELL /* can't access mail reader without spawning subprocess */
const char *txt, *cmd; const char *txt, *cmd;
char *p, buf[BUFSZ], qbuf[BUFSZ]; char *p, buf[BUFSZ] = DUMMY, qbuf[BUFSZ];
int len; int len;
/* there should be a command in OMAILCMD */ /* there should be a command in OMAILCMD */
+1 -1
View File
@@ -298,7 +298,7 @@ long
bribe(mtmp) bribe(mtmp)
struct monst *mtmp; struct monst *mtmp;
{ {
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
long offer; long offer;
long umoney = money_cnt(invent); long umoney = money_cnt(invent);
+1 -1
View File
@@ -3266,7 +3266,7 @@ struct monst *mon;
/* for debugging: allow control of polymorphed monster */ /* for debugging: allow control of polymorphed monster */
if (wizard && iflags.mon_polycontrol) { if (wizard && iflags.mon_polycontrol) {
char pprompt[BUFSZ], buf[BUFSZ]; char pprompt[BUFSZ], buf[BUFSZ] = DUMMY;
int monclass; int monclass;
Sprintf(pprompt, "Change %s @ %s into what kind of monster?", Sprintf(pprompt, "Change %s @ %s into what kind of monster?",
+1 -1
View File
@@ -609,7 +609,7 @@ int
do_play_instrument(instr) do_play_instrument(instr)
struct obj *instr; struct obj *instr;
{ {
char buf[BUFSZ], c = 'y'; char buf[BUFSZ] = DUMMY, c = 'y';
char *s; char *s;
int x, y; int x, y;
boolean ok; boolean ok;
+5 -5
View File
@@ -2836,7 +2836,7 @@ boolean tinitial, tfrom_file;
fullname = "pickup_types"; fullname = "pickup_types";
if (match_optname(opts, fullname, 8, TRUE)) { if (match_optname(opts, fullname, 8, TRUE)) {
char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], qbuf[QBUFSZ], char ocl[MAXOCLASSES + 1], tbuf[MAXOCLASSES + 1], qbuf[QBUFSZ],
abuf[BUFSZ]; abuf[BUFSZ] = DUMMY;
int oc_sym; int oc_sym;
boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu; boolean badopt = FALSE, compat = (strlen(opts) <= 6), use_menu;
@@ -4100,7 +4100,7 @@ int
doset() /* changing options via menu by Per Liboriussen */ doset() /* changing options via menu by Per Liboriussen */
{ {
static boolean made_fmtstr = FALSE; static boolean made_fmtstr = FALSE;
char buf[BUFSZ], buf2[BUFSZ]; char buf[BUFSZ], buf2[BUFSZ] = DUMMY;
const char *name; const char *name;
int i = 0, pass, boolcount, pick_cnt, pick_idx, opt_indx; int i = 0, pass, boolcount, pick_cnt, pick_idx, opt_indx;
boolean *bool_p; boolean *bool_p;
@@ -4779,7 +4779,7 @@ boolean setinitial, setfromfile;
iflags.menu_headings = mhattr; iflags.menu_headings = mhattr;
} else if (!strcmp("msgtype", optname)) { } else if (!strcmp("msgtype", optname)) {
int opt_idx, nmt, mttyp; int opt_idx, nmt, mttyp;
char mtbuf[BUFSZ]; char mtbuf[BUFSZ] = DUMMY;
msgtypes_again: msgtypes_again:
nmt = msgtype_count(); nmt = msgtype_count();
@@ -4841,7 +4841,7 @@ boolean setinitial, setfromfile;
} }
} else if (!strcmp("menucolors", optname)) { } else if (!strcmp("menucolors", optname)) {
int opt_idx, nmc, mcclr, mcattr; int opt_idx, nmc, mcclr, mcattr;
char mcbuf[BUFSZ]; char mcbuf[BUFSZ] = DUMMY;
menucolors_again: menucolors_again:
nmc = count_menucolors(); nmc = count_menucolors();
@@ -4912,7 +4912,7 @@ boolean setinitial, setfromfile;
} }
} else if (!strcmp("autopickup_exception", optname)) { } else if (!strcmp("autopickup_exception", optname)) {
int opt_idx, pass, totalapes = 0, numapes[2] = { 0, 0 }; 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; struct autopickup_exception *ape;
ape_again: ape_again:
+1 -1
View File
@@ -1033,7 +1033,7 @@ coord *click_cc;
{ {
boolean quick = (mode == 1); /* use cursor; don't search for "more info" */ boolean quick = (mode == 1); /* use cursor; don't search for "more info" */
boolean clicklook = (mode == 2); /* right mouse-click method */ boolean clicklook = (mode == 2); /* right mouse-click method */
char out_str[BUFSZ]; char out_str[BUFSZ] = DUMMY;
const char *firstmatch = 0; const char *firstmatch = 0;
struct permonst *pm = 0; struct permonst *pm = 0;
int i = '\0', ans = 0; int i = '\0', ans = 0;
+1 -1
View File
@@ -149,7 +149,7 @@ struct obj *objs;
boolean here; boolean here;
int *menu_on_demand; 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; int iletct, oclassct;
boolean not_everything, filtered; boolean not_everything, filtered;
char qbuf[QBUFSZ]; char qbuf[QBUFSZ];
+1 -1
View File
@@ -384,7 +384,7 @@ void
polyself(psflags) polyself(psflags)
int psflags; int psflags;
{ {
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
int old_light, new_light, mntmp, class, tryct; int old_light, new_light, mntmp, class, tryct;
boolean forcecontrol = (psflags == 1), monsterpoly = (psflags == 2), boolean forcecontrol = (psflags == 1), monsterpoly = (psflags == 2),
draconian = (uarm && Is_dragon_armor(uarm)), draconian = (uarm && Is_dragon_armor(uarm)),
+3 -3
View File
@@ -2017,7 +2017,7 @@ STATIC_OVL void
do_class_genocide() do_class_genocide()
{ {
int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0; int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0;
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
boolean gameover = FALSE; /* true iff killed self */ boolean gameover = FALSE; /* true iff killed self */
for (j = 0;; j++) { for (j = 0;; j++) {
@@ -2169,7 +2169,7 @@ int how;
/* 3 = forced genocide of player */ /* 3 = forced genocide of player */
/* 5 (4 | 1) = normal genocide from throne */ /* 5 (4 | 1) = normal genocide from throne */
{ {
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
register int i, killplayer = 0; register int i, killplayer = 0;
register int mndx; register int mndx;
register struct permonst *ptr; register struct permonst *ptr;
@@ -2425,7 +2425,7 @@ struct obj *from_obj;
boolean boolean
create_particular() create_particular()
{ {
char buf[BUFSZ], *bufp, monclass; char buf[BUFSZ] = DUMMY, *bufp, monclass;
char *tmpp; char *tmpp;
int which, tryct, i, firstchoice = NON_PM; int which, tryct, i, firstchoice = NON_PM;
struct permonst *whichpm = NULL; struct permonst *whichpm = NULL;
+1 -1
View File
@@ -595,7 +595,7 @@ level_tele()
register int newlev; register int newlev;
d_level newlevel; d_level newlevel;
const char *escape_by_flying = 0; /* when surviving dest of -N */ const char *escape_by_flying = 0; /* when surviving dest of -N */
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
boolean force_dest = FALSE; boolean force_dest = FALSE;
if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz)) if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz))
+1 -1
View File
@@ -230,7 +230,7 @@ invault()
guard = findgd(); guard = findgd();
if (++u.uinvault % VAULT_GUARD_TIME == 0 && !guard) { if (++u.uinvault % VAULT_GUARD_TIME == 0 && !guard) {
/* if time ok and no guard now. */ /* if time ok and no guard now. */
char buf[BUFSZ]; char buf[BUFSZ] = DUMMY;
register int x, y, dd, gx, gy; register int x, y, dd, gx, gy;
int lx = 0, ly = 0; int lx = 0, ly = 0;
long umoney; long umoney;
+1 -1
View File
@@ -95,7 +95,7 @@ dowrite(pen)
register struct obj *pen; register struct obj *pen;
{ {
register struct obj *paper; register struct obj *paper;
char namebuf[BUFSZ], *nm, *bp; char namebuf[BUFSZ] = DUMMY, *nm, *bp;
register struct obj *new_obj; register struct obj *new_obj;
int basecost, actualcost; int basecost, actualcost;
int curseval; int curseval;
+2 -1
View File
@@ -5050,7 +5050,8 @@ int triesleft;
void void
makewish() makewish()
{ {
char buf[BUFSZ], promptbuf[BUFSZ]; static char buf[BUFSZ] = DUMMY;
char promptbuf[BUFSZ];
struct obj *otmp, nothing; struct obj *otmp, nothing;
int tries = 0; int tries = 0;
+3
View File
@@ -83,6 +83,9 @@ bool NetHackQtStringRequestor::Get(char* buffer, int maxchar)
resize(fontMetrics().width(prompt.text())*2+50,fontMetrics().height()*4); resize(fontMetrics().width(prompt.text())*2+50,fontMetrics().height()*4);
} }
#ifdef EDIT_GETLIN
input.setText(buffer);
#endif
centerOnMain(this); centerOnMain(this);
show(); show();
input.setFocus(); input.setFocus();
+4
View File
@@ -1623,7 +1623,11 @@ char *input;
slide left hiding some chars at the beginning of the response but 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 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.] */ 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 */ SetDialogResponse(getline_dialog, nhStr(""), 60); /* set default answer */
#endif
positionpopup(getline_popup, TRUE); /* center,bottom */ positionpopup(getline_popup, TRUE); /* center,bottom */
nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog); nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog);
+5
View File
@@ -56,8 +56,13 @@ getlin_hook_proc hook;
cw->flags &= ~WIN_STOP; cw->flags &= ~WIN_STOP;
ttyDisplay->toplin = 3; /* special prompt state */ ttyDisplay->toplin = 3; /* special prompt state */
ttyDisplay->inread++; 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); custompline(OVERRIDE_MSGTYPE | SUPPRESS_HISTORY, "%s ", query);
*obufp = 0; *obufp = 0;
#endif
for (;;) { for (;;) {
(void) fflush(stdout); (void) fflush(stdout);
Strcat(strcat(strcpy(toplines, query), " "), obufp); Strcat(strcat(strcpy(toplines, query), " "), obufp);