tDon't assume key is a single byte - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 66759ed944ee03eb776cc2609172e3e920dfc668
(DIR) parent 7a3ecb9c6b642383aa48123c42911a8f5e8b39c3
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Sat, 2 Jan 2021 21:38:57 -0800
Don't assume key is a single byte
In UTF-8 locales the key may be several bytes,
so look for the terminating colon instead.
Diffstat:
M src/curses_client/curses_client.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_client.c
t@@ -1591,8 +1591,9 @@ void Bank(Player *Play)
/*
* Waits for keyboard input; will only accept a key listed in the
- * "allowed" string. This string may have been translated; thus
- * the "orig_allowed" string contains the untranslated keys.
+ * "allowed" string (in the locale encoding, usually UTF-8). This string
+ * may have been translated; thus the "orig_allowed" string (in ASCII)
+ * contains the untranslated keys.
* Returns the untranslated key corresponding to the key pressed
* (e.g. if allowed[2] is pressed, orig_allowed[2] is returned)
* Case insensitive. If "AllowOther" is TRUE, keys other than the
t@@ -1605,7 +1606,7 @@ int GetKey(char *allowed, char *orig_allowed, gboolean AllowOther,
gboolean PrintAllowed, gboolean ExpandOut)
{
int ch;
- guint AllowInd, WordInd, i;
+ guint AllowInd, WordInd;
/* Expansions of the single-letter keypresses for the benefit of the
user. i.e. "Yes" is printed for the key "Y" etc. You should indicate
t@@ -1634,9 +1635,11 @@ int GetKey(char *allowed, char *orig_allowed, gboolean AllowOther,
WordInd++;
if (ExpandOut && WordInd < numWords) {
- trWord = _(Words[WordInd]);
- for (i = 2; i < strlen(trWord); i++)
- addch((guchar)trWord[i] | TextAttr);
+ trWord = strchr(_(Words[WordInd]), ':');
+ /* Print everything after the colon */
+ if (*trWord) trWord++;
+ attrset(TextAttr);
+ addstr(trWord);
} else
addch((guchar)allowed[AllowInd] | TextAttr);
}