summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2015-02-24 14:02:31 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2015-02-24 14:04:30 +0100
commit8c82fc3f6ddd3915d07f5563c7d5b0d3783ab88d (patch)
treea1903e65c94d91729907d799bad70b645e58335d
parent0145ba12ecb20583adda4e4b03dd5b7cfb15d1f4 (diff)
downloadcalcurse-8c82fc3f6ddd3915d07f5563c7d5b0d3783ab88d.tar.gz
calcurse-8c82fc3f6ddd3915d07f5563c7d5b0d3783ab88d.zip
Simplify code in status_ask_choice()
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/utils.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/utils.c b/src/utils.c
index 613e4bc..f726260 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -197,19 +197,17 @@ void status_mesg(const char *msg1, const char *msg2)
int status_ask_choice(const char *message, const char choice[],
int nb_choice)
{
- int i, ch;
- char *tmp;
/* "[4/2/f/t/w/.../Z] " */
char avail_choice[2 * nb_choice + 3];
+ int i, ch;
avail_choice[0] = '[';
- avail_choice[1] = '\0';
-
for (i = 1; i <= nb_choice; i++) {
- asprintf(&tmp, (i == nb_choice) ? "%c] " : "%c/", choice[i]);
- strcat(avail_choice, tmp);
- mem_free(tmp);
+ avail_choice[i * 2 - 1] = choice[i];
+ avail_choice[i * 2] = '/';
}
+ avail_choice[nb_choice * 2] = ']';
+ avail_choice[nb_choice * 2 + 1] = '\0';
status_mesg(message, avail_choice);