From 03579181022489d95b6a1361a1d3568a1d4b47e0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 5 Feb 2023 18:52:45 -0800 Subject: bitmap: Print which option was in error along with usage message Signed-off-by: Alan Coopersmith --- BitEdit.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/BitEdit.c b/BitEdit.c index 72ff26d..c098862 100644 --- a/BitEdit.c +++ b/BitEdit.c @@ -980,6 +980,7 @@ int main(int argc, char *argv[]) Widget w; Widget radio_group = NULL; XtPointer radio_data = NULL; + const char *filename = NULL; /* Handle args that don't require opening a display */ for (int a = 1; a < argc; a++) { @@ -1001,9 +1002,19 @@ int main(int argc, char *argv[]) top_widget = XtInitialize(NULL, "Bitmap", options, XtNumber(options), &argc, argv); - if (argc > 2) { - fputs(usage, stderr); - exit (0); + if (argc > 1) { + if ((argv[argc - 1][0] != '-') && (argv[argc - 1][0] != '+')) { + filename = argv[--argc]; + } + if (argc > 1) { + fputs("Unknown argument(s):", stderr); + for (int a = 1; a < argc; a++) { + fprintf(stderr, " %s", argv[a]); + } + fputs("\n\n", stderr); + fprintf(stderr, "usage: %s %s", argv[0], usage); + exit (1); + } } check_mark = XCreateBitmapFromData(XtDisplay(top_widget), @@ -1095,8 +1106,8 @@ int main(int argc, char *argv[]) bitmap_widget = XtCreateManagedWidget("bitmap", bitmapWidgetClass, pane_widget, NULL, 0); XtRealizeWidget(top_widget); - if (argc > 1) - if (BWReadFile(bitmap_widget, argv[1], NULL)) + if (filename != NULL) + BWReadFile(bitmap_widget, filename, NULL); wm_delete_window = XInternAtom(XtDisplay(top_widget), "WM_DELETE_WINDOW", False); -- cgit v1.2.3