summaryrefslogtreecommitdiff
path: root/xload.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 12:51:58 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 12:51:58 -0800
commitef450fb99630a406c4638d8ba251eac45e434411 (patch)
tree855b66183ffe9d85fd582a6f97ea7bca6fdf0fa1 /xload.c
parent7063169a70b6ce49de777f5daa1c256552a9e32a (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xload.c')
-rw-r--r--xload.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/xload.c b/xload.c
index 0559769..73d675f 100644
--- a/xload.c
+++ b/xload.c
@@ -28,7 +28,7 @@ from the X Consortium.
*/
/*
- * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2023, Oracle and/or its affiliates.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -140,7 +140,7 @@ static int light_update = 10 * 1000;
*/
static void _X_NORETURN
-usage(void)
+usage(int exitval)
{
fprintf (stderr, gettext("usage: %s [-options ...]\n\n%s\n"),
ProgramName, gettext(
@@ -157,8 +157,10 @@ usage(void)
" -nolabel removes the label from above the chart.\n"
" -jumpscroll <value> number of pixels to scroll on overflow\n"
" -lights use keyboard leds to display current load\n"
+ " -help print this message\n"
+ " -version print version info\n"
));
- exit(1);
+ exit(exitval);
}
int
@@ -175,6 +177,22 @@ main(int argc, char **argv)
ProgramName = argv[0];
+ /* Handle args that don't require opening a display or load info source */
+ 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);
+ }
+ }
+
/* For security reasons, we reset our uid/gid after doing the necessary
system initialization and before calling any X routines. */
InitLoadPoint();
@@ -213,7 +231,7 @@ main(int argc, char **argv)
fprintf(stderr, " %s", argv[n]);
}
fputs("\n\n", stderr);
- usage();
+ usage(1);
}
XtGetApplicationResources( toplevel, (XtPointer) &resources,