diff options
Diffstat (limited to 'editres.c')
-rw-r--r-- | editres.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -65,7 +65,7 @@ Widget global_toplevel; AppResources global_resources; -static void Syntax ( XtAppContext app_con, char *call ) _X_NORETURN; +static void Syntax (XtAppContext, const char *, int) _X_NORETURN; static String fallback_resources[] = { NULL, @@ -93,12 +93,28 @@ main(int argc, char **argv) { XtAppContext app_con; + /* 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 -help & -version */ + if (argn[0] == '-' && argn[1] == '-') { + argn++; + } + if (strcmp(argn, "-help") == 0) { + Syntax(NULL, argv[0], 0); + } + if (strcmp(argn, "-version") == 0) { + puts(PACKAGE_STRING); + exit(0); + } + } + global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO, &argc, argv, fallback_resources, NULL, ZERO); if (argc != 1) - Syntax(app_con, argv[0]); + Syntax(app_con, argv[0], 1); SetApplicationActions(app_con); XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources, @@ -140,9 +156,10 @@ main(int argc, char **argv) */ static void -Syntax(XtAppContext app_con, char *call) +Syntax(XtAppContext app_con, const char *call, int exit_val) { - XtDestroyApplicationContext(app_con); - fprintf(stderr, "Usage: %s\n", call); - exit(1); + if (app_con != NULL) + XtDestroyApplicationContext(app_con); + fprintf(stderr, "Usage: %s [ toolkitoptions ] [-help] [-version]\n", call); + exit(exit_val); } |