From 851c85cba5ec8c0e59fba3aebed7c91e5711431b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 5 Feb 2023 09:36:55 -0800 Subject: Fix -version handling to not require opening a display first Signed-off-by: Alan Coopersmith --- xconsole.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/xconsole.c b/xconsole.c index f3c2bab..20cbacd 100644 --- a/xconsole.c +++ b/xconsole.c @@ -615,14 +615,22 @@ main(int argc, char *argv[]) Cardinal num_args; XtSetLanguageProc(NULL,NULL,NULL); + + /* Handle args that don't require opening a display */ + for (int n = 1; n < argc; n++) { + const char *argn = argv[n]; + /* accept single or double dash for -version */ + if (argn[0] == '-' && argn[1] == '-') { + argn++; + } + if (strcmp(argn, "-version") == 0) { + puts(PACKAGE_STRING); + exit(0); + } + } + top = XtInitialize ("xconsole", "XConsole", options, XtNumber (options), &argc, argv); - if ((argc == 2) && - ((strcmp(argv[1], "-version") == 0) || - (strcmp(argv[1], "--version") == 0))) { - puts(PACKAGE_STRING); - exit(0); - } XtGetApplicationResources (top, (XtPointer)&app_resources, resources, XtNumber (resources), NULL, 0); -- cgit v1.2.3