From e7a54da926969631340942c5f850dd196a0df97b Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 4 Feb 2023 14:35:07 -0800 Subject: Add -help & -version options Processed before the display is opened so they work even if a connection to the display can't be opened. Signed-off-by: Alan Coopersmith --- man/xeyes.man | 6 ++++++ xeyes.c | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/man/xeyes.man b/man/xeyes.man index 50e5a26..298e152 100644 --- a/man/xeyes.man +++ b/man/xeyes.man @@ -51,6 +51,12 @@ disables Xrender and draws traditional eyes. .TP 8 .B \-distance uses an alternative mapping, as if the eyes were set back from the screen, thus following the mouse more precisely. +.TP 8 +.B \-help +print a usage message and exit. +.TP 8 +.B \-version +print the version number and exit. .SH "SEE ALSO" X(__miscmansuffix__), X Toolkit documentation .SH AUTHOR diff --git a/xeyes.c b/xeyes.c index 5fea24b..a13f0d5 100644 --- a/xeyes.c +++ b/xeyes.c @@ -44,24 +44,23 @@ from the X Consortium. /* Exit with message describing command line format */ static void _X_NORETURN -usage(void) +usage(int exitval) { fprintf(stderr, - "usage: xeyes\n" - " [-display [{host}]:[{vs}]]\n" - " [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n" - " [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n" - " [-shape | +shape] [-outline {color}] [-center {color}]\n" - " [-backing {backing-store}] [-distance]\n"); + "usage: xeyes [-display [{host}]:{vs}]\n" + " [-geometry [{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]]\n" + " [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n" + " [-shape | +shape] [-outline {color}] [-center {color}]\n" + " [-backing {backing-store}] [-distance]\n" #ifdef XRENDER - fprintf(stderr, - " [-render | +render]\n"); + " [-render | +render]\n" #endif #ifdef PRESENT - fprintf(stderr, - " [-present | +present]\n"); + " [-present | +present]\n" #endif - exit(1); + " xeyes -help\n" + " xeyes -version\n"); + exit(exitval); } /* Command line options table. Only resources are entered here...there is a @@ -113,10 +112,27 @@ main(int argc, char **argv) XtSetLanguageProc(NULL, (XtLanguageProc) 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 -help & -version */ + if (argn[0] == '-' && argn[1] == '-') { + argn++; + } + if (strcmp(argn, "-help") == 0) { + usage(0); + } + if (strcmp(argn, "-version") == 0) { + puts(PACKAGE_STRING); + exit(0); + } + } + toplevel = XtAppInitialize(&app_context, "XEyes", options, XtNumber(options), &argc, argv, NULL, arg, (Cardinal) 0); - if (argc != 1) usage(); + if (argc != 1) + usage(1); wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False); -- cgit v1.2.3