summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2023-02-03 23:12:54 +0100
committerpgen <p.gen.progs@gmail.com>2023-02-03 23:12:54 +0100
commit6a1f442b986f52ecca5ebb12c2147eb694b5782e (patch)
treec15865091852cb7ba9a806f1a27374113b13a0cc
parent6061eb0c3fbbe8026e7692fd4e335da89dc6cad0 (diff)
Improve usage display
Do not display the full usage if the input file cannot be read.
-rw-r--r--ctxopt.c10
-rw-r--r--smenu.c4
2 files changed, 10 insertions, 4 deletions
diff --git a/ctxopt.c b/ctxopt.c
index e5ba754..efc211c 100644
--- a/ctxopt.c
+++ b/ctxopt.c
@@ -478,7 +478,7 @@ fatal(errors e, char * errmsg)
if (e == CTXOPTUNKPAR && *errmsg != '\0')
ctxopt_disp_usage(continue_after);
else
- ctxopt_ctx_disp_usage(cur_state->ctx_name, continue_after);
+ ctxopt_ctx_disp_usage(NULL, continue_after);
exit(e); /* Exit with the error id e as return code. */
}
@@ -4196,7 +4196,13 @@ ctxopt_ctx_disp_usage(char * ctx_name, usage_behaviour action)
if (!flags.display_usage_on_error)
return;
- ctx = locate_ctx(ctx_name);
+ ctx = NULL;
+
+ if (ctx_name != NULL)
+ ctx = locate_ctx(ctx_name);
+ else
+ ctx = locate_ctx(cur_state->ctx_name);
+
if (ctx == NULL)
fatal_internal("Unknown context %s.", ctx_name);
diff --git a/smenu.c b/smenu.c
index b03cad6..8c616de 100644
--- a/smenu.c
+++ b/smenu.c
@@ -7741,7 +7741,7 @@ main(int argc, char * argv[])
{
fprintf(stderr, "The file \"%s\" does not exist or cannot be read.\n",
rem_args[0]);
- ctxopt_disp_usage(exit_after);
+ ctxopt_ctx_disp_usage(NULL, exit_after);
exit(EXIT_FAILURE); /* Avoid a compiler warning. */
}
}
@@ -7756,7 +7756,7 @@ main(int argc, char * argv[])
fprintf(stderr, ", %s", rem_args[i]);
fprintf(stderr, ".\n");
- ctxopt_disp_usage(exit_after);
+ ctxopt_ctx_disp_usage(NULL, exit_after);
exit(EXIT_FAILURE); /* Avoid a compiler warning. */
}