Skip to content

Commit ed81eca

Browse files
author
Peter Kosyh
committed
cleanups
1 parent caeaf6f commit ed81eca

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

main.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,18 @@ static void reopen_stdin(const char *fname)
200200
}
201201
}
202202

203-
static char *get_input(void)
203+
static char *get_input(const char *prompt)
204204
{
205205
static char input[256];
206206
char *p;
207+
printf("\n%s", prompt); fflush(stdout);
207208
input[0] = 0;
208209
p = fgets(input, sizeof(input), stdin);
209210
if (p && *p) {
210211
p[strcspn(p, "\n\r")] = 0;
211212
}
213+
if (opt_echo && p)
214+
printf("%s\n", p);
212215
return p;
213216
}
214217

@@ -380,8 +383,7 @@ int main(int argc, const char **argv)
380383
mmedia(0); mmedia(1);
381384
if (opt_autoload) {
382385
snprintf(cmd, sizeof(cmd), "load %s", opt_autoload);
383-
if (opt_echo)
384-
printf("%s\n", cmd);
386+
printf("/%s\n", cmd);
385387
str = instead_cmd(cmd, &rc);
386388
} else
387389
str = instead_cmd("look", &rc);
@@ -398,14 +400,11 @@ int main(int argc, const char **argv)
398400
while (1) {
399401
char *p;
400402
int cmd_mode = 0;
401-
printf("> "); fflush(stdout);
402-
p = get_input();
403+
p = get_input("> ");
403404
if (!p || !strcmp(p, "/quit")) {
404405
printf("\n");
405406
break;
406407
}
407-
if (opt_echo)
408-
fprintf(stdout, "%s\n", p);
409408
rc = 1; str = NULL;
410409

411410
if (*p == '/') {
@@ -457,19 +456,19 @@ int main(int argc, const char **argv)
457456
}
458457
if (need_save) {
459458
puts("?(autosave)"); fflush(stdout);
460-
p = get_input();
459+
p = get_input("> ");
461460
if (p && *p)
462461
snprintf(cmd, sizeof(cmd), "save %s", p);
463462
else
464463
snprintf(cmd, sizeof(cmd), "save autosave");
465-
printf("%s\n", cmd);
464+
printf("/%s\n", cmd);
466465
str = instead_cmd(cmd, NULL);
467466
if (str)
468467
free(str);
469468
need_save = 0;
470469
} else if (need_load) {
471470
puts("?(autosave)"); fflush(stdout);
472-
p = get_input();
471+
p = get_input("> ");
473472
if (opt_autoload)
474473
free(opt_autoload);
475474
if (p && *p)

0 commit comments

Comments
 (0)