summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 15:46:31 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 15:49:24 -0800
commita67a5771ecf2cdce8c4214dec58489ba6eb48219 (patch)
treeb1806fa13a7fc1569dded0beb4cbc472b47d5e29
parent972d4c5c6a4293b7da32194f219e5299e4e33e37 (diff)
Add -help and -version optionsHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xmag.man13
-rw-r--r--xmag.c31
2 files changed, 40 insertions, 4 deletions
diff --git a/man/xmag.man b/man/xmag.man
index b6f850f..e608491 100644
--- a/man/xmag.man
+++ b/man/xmag.man
@@ -37,6 +37,13 @@ xmag \- magnify parts of the screen
] [
.I \-toolkitoption
\&.\|.\|. ]
+.br
+.B xmag
+[
+.B \-help
+|
+.B \-version
+]
.SH DESCRIPTION
The \fIxmag\fP program allows you to magnify portions of an X screen. If no
explicit region is specified, a square with the pointer in the upper left
@@ -95,5 +102,11 @@ an area of the screen.
.TP 15
.B \-mag\fI integer\fP
This option indicates the magnification to be used. 5 is the default.
+.TP 15
+.B \-help
+This option indicates that \fIxmag\fP should print a usage message and exit.
+.TP 15
+.B \-version
+This option indicates that \fIxmag\fP should print version info and exit.
.SH AUTHORS
Dave Sternlicht and Davor Matic, MIT X Consortium.
diff --git a/xmag.c b/xmag.c
index 3dff66c..2776155 100644
--- a/xmag.c
+++ b/xmag.c
@@ -1105,15 +1105,40 @@ ParseSourceGeom(void)
+static void
+usage(const char *progname, int exitval)
+{
+ fprintf (stderr,
+ "usage: %s [-source geom] [-mag magfactor] [-toolkitoption]\n"
+ " %s [-help|-version]\n",
+ progname, progname);
+ exit (exitval);
+}
+
/*
* Main program.
*/
int
main(int argc, char *argv[])
{
+ /* 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(argv[0], 0);
+ }
+ if (strcmp(argn, "-version") == 0) {
+ puts(PACKAGE_STRING);
+ exit(0);
+ }
+ }
+
XSetErrorHandler(Error);
- /* SUPPRESS 594 */
toplevel = XtAppInitialize(&app, "Xmag", optionDesc, XtNumber(optionDesc),
&argc, argv, NULL,
NULL, 0);
@@ -1128,9 +1153,7 @@ main(int argc, char *argv[])
fprintf(stderr, " %s", argv[n]);
}
fputs("\n\n", stderr);
- fprintf (stderr,
- "usage: xmag [-source geom] [-mag magfactor] [-toolkitoption]\n");
- exit(1);
+ usage(argv[0], 1);
}