summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-06 18:19:29 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-06 18:30:30 -0800
commitad1da487b343ffdbeda09563984869cc56ab29a0 (patch)
tree2adc1e2f9e18790068364b603f7278667d187c3c
parent80959deec664cd80cd5dbf84af86b52ded4eaee0 (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--editres.c29
-rw-r--r--man/editres.man11
2 files changed, 33 insertions, 7 deletions
diff --git a/editres.c b/editres.c
index 9826b40..309aaa9 100644
--- a/editres.c
+++ b/editres.c
@@ -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);
}
diff --git a/man/editres.man b/man/editres.man
index 0792136..9b94bc2 100644
--- a/man/editres.man
+++ b/man/editres.man
@@ -28,12 +28,21 @@
.SH NAME
editres \- a dynamic resource editor for X Toolkit applications
.SH SYNTAX
-\fBeditres\fP [ \fI\-toolkitoption\fP .\|.\|. ]
+\fBeditres\fP [ \fI\-toolkitoption\fP .\|.\|. ] [\fB\-help\fP] [\fB\-version\fP]
.SH OPTIONS
.I Editres
accepts all of the standard X Toolkit command line
options (see \fIX(__miscmansuffix__)\fP). The order of the command line options is
not important.
+.PP
+.I Editres
+also accepts the following additional options:
+.TP 12
+.B \-help
+Prints a usage message and exits.
+.TP 12
+.B \-version
+Prints version info and exits.
.SH DESCRIPTION
Editres is a tool that allows users and application developers to view
the full widget hierarchy of any X Toolkit application that speaks the