summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 18:04:48 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 18:14:14 -0800
commit1e9e2cd20ea446ed5ff83c605d49a8989790758a (patch)
treeea144ad8ad0f985fdcbe126b3b89cc4809acacf6
parent952240d4e40de2f22897b4795bc207ddc675a60e (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xvidtune.man10
-rw-r--r--xvidtune.c49
2 files changed, 47 insertions, 12 deletions
diff --git a/man/xvidtune.man b/man/xvidtune.man
index 413af99..43a6092 100644
--- a/man/xvidtune.man
+++ b/man/xvidtune.man
@@ -42,6 +42,10 @@ xvidtune \- video mode tuner for __xservername__
|
.B -timeout
.I sec
+|
+.B -help
+|
+.B -version
] [
.I \-toolkitoption
\&.\|.\|. ]
@@ -171,6 +175,12 @@ combinations.
.TP 10
.B \-timeout \fIsec\fP
Set testmode timeout in seconds.
+.TP 10
+.B \-help
+Print usage message and exit.
+.TP 10
+.B \-version
+Print version info and exit.
.SH SEE ALSO
.BR xrandr (__appmansuffix__),
.BR __xservername__ (__appmansuffix__),
diff --git a/xvidtune.c b/xvidtune.c
index 2f73bf1..85cd9ce 100644
--- a/xvidtune.c
+++ b/xvidtune.c
@@ -30,6 +30,10 @@ from Kaleb S. KEITHLEY.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
@@ -1477,16 +1481,21 @@ PrevModeAction(Widget w, XEvent* e, String* vector, Cardinal* count)
static void
-usage(void)
+usage(int exitval)
{
- fprintf(stderr, "Usage: %s [-show|-prev|-next|-unlock|-timeout <sec>] [-toolkitoption...]\n", progname);
- fprintf(stderr, " where option is one of:\n");
- fprintf(stderr, " -show Print current modeline to stdout\n");
- fprintf(stderr, " -next Switch to next video mode\n");
- fprintf(stderr, " -prev Switch to previous video mode\n");
- fprintf(stderr, " -unlock Enable mode switch hot-keys\n");
- fprintf(stderr, " -timeout <sec> Set testmode timeout in seconds\n");
- exit(1);
+ FILE *out = (exitval == 0) ? stdout : stderr;
+
+ fprintf(out, "Usage: %s [option] [-toolkitoption...]\n", progname);
+ fprintf(out, " where option is one of:\n"
+ " -show Print current modeline to stdout\n"
+ " -next Switch to next video mode\n"
+ " -prev Switch to previous video mode\n"
+ " -unlock Enable mode switch hot-keys\n"
+ " -timeout <sec> Set testmode timeout in seconds\n"
+ " -help Print this message\n"
+ " -version Print version info\n"
+ );
+ exit(exitval);
}
@@ -1499,6 +1508,22 @@ main (int argc, char** argv)
Bool modeSettable = TRUE;
progname = argv[0];
+
+ /* 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);
+ }
+ }
static XtActionsRec actions[] = { { "xvidtune-quit", QuitAction },
{ "xvidtune-restore", RestoreAction },
@@ -1555,14 +1580,14 @@ main (int argc, char** argv)
TestTimeout = ((unsigned long) atol( argv[2] )) * 1000L;
}
else
- usage();
+ usage(1);
}
if (argc > 1) {
int i = 0;
if (argc != 2)
- usage();
+ usage(1);
if (!strcmp(argv[1], "-show")) {
if (!GetModeLine(XtDisplay (top), DefaultScreen (XtDisplay (top)))) {
fprintf(stderr, "Unable to get mode info\n");
@@ -1580,7 +1605,7 @@ main (int argc, char** argv)
XSync(XtDisplay (top), True);
return 0;
} else
- usage();
+ usage(1);
if (i != 0) {
XF86VidModeSwitchMode(XtDisplay (top),
DefaultScreen (XtDisplay (top)), i);