X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=main.c;h=acbabb65027cece7668515d90655fd065ad3cfc5;hb=25230068fe3afb9d1faa9c606413784294700cef;hp=371b3b67d7a1af9ae14e018f1d372f00927e7d2f;hpb=b125fe7b2ad09754364f8bef1f3d72a5837c7b82;p=open-adventure.git diff --git a/main.c b/main.c index 371b3b6..acbabb6 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,7 @@ /* - * Copyright (c) 1977, 2005 by Will Crowther and Don Woods - * Copyright (c) 2017 by Eric S. Raymond - * SPDX-License-Identifier: BSD-2-clause + * SPDX-FileCopyrightText: 1977, 2005 by Will Crowther and Don Woods + * SPDX-FileCopyrightText: 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-Clause */ #include @@ -55,8 +55,13 @@ char *myreadline(const char *prompt) * logfiles for testing purposes. */ /* Normal case - no script arguments */ - if (settings.argc == 0) - return readline(prompt); + if (settings.argc == 0) { + char *ln = readline(prompt); + if (ln == NULL) { + fputs(prompt, stdout); + } + return ln; + } char *buf = malloc(LINESIZE + 1); for (;;) { @@ -82,9 +87,9 @@ char *myreadline(const char *prompt) } else { char *ln = fgets(buf, LINESIZE, settings.scriptfp); if (ln != NULL) { - fputs(PROMPT, stdout); + fputs(prompt, stdout); fputs(ln, stdout); - return ln; + return ln; } } } @@ -1074,7 +1079,7 @@ static bool do_move(void) return true; } -static bool do_command() +static bool do_command(void) /* Get and execute a command */ { static command_t command; @@ -1256,20 +1261,23 @@ int main(int argc, char *argv[]) /* Options. */ #if defined ADVENT_AUTOSAVE - const char* opts = "l:oa:"; + const char* opts = "dl:oa:"; const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n"; FILE *rfp = NULL; const char* autosave_filename = NULL; #elif !defined ADVENT_NOSAVE - const char* opts = "l:or:"; + const char* opts = "dl:or:"; const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n"; FILE *rfp = NULL; #else - const char* opts = "l:o"; + const char* opts = "dl:o"; const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n"; #endif while ((ch = getopt(argc, argv, opts)) != EOF) { switch (ch) { + case 'd': // LCOV_EXCL_LINE + settings.debug +=1; // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE case 'l': settings.logfp = fopen(optarg, "w"); if (settings.logfp == NULL)