summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Nader <jason.nader@protonmail.com>2020-04-11 22:29:47 +0900
committerJason Nader <jason.nader@protonmail.com>2020-04-11 22:41:24 +0900
commit632461227686bb31004fd9cf823bcf1645e7a563 (patch)
tree8c8c3f165ac95438a2924a5eda06b9c88961e710
parente81642bacc58388c223bc157f37c2311a7dbe070 (diff)
Add missing `-help` function
`-help` is mentioned in the manpages, but actually running `xprop -help` results in xprop exiting with status 1 as it doesn't recognise the option. This has been the source of major confusion here: https://github.com/franciscolourenco/done/issues/77#issuecomment-612404448 Signed-off-by: Jason Nader <jason.nader@protonmail.com>
-rw-r--r--xprop.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/xprop.c b/xprop.c
index 88229e8..4d38c30 100644
--- a/xprop.c
+++ b/xprop.c
@@ -1772,10 +1772,11 @@ Set_Property (Display *dpy, Window w, const char *propname, const char *value)
*/
void
-usage (const char *errmsg)
+print_help (void)
{
static const char *help_message =
"where options include:\n"
+" -help print out a summary of command line options\n"
" -grammar print out full grammar for command line\n"
" -display host:dpy the X server to contact\n"
" -id id resource id of window to examine\n"
@@ -1795,13 +1796,24 @@ usage (const char *errmsg)
fflush (stdout);
- if (errmsg != NULL)
- fprintf (stderr, "%s: %s\n\n", program_name, errmsg);
-
fprintf (stderr,
"usage: %s [-options ...] [[format [dformat]] atom] ...\n\n",
program_name);
fprintf (stderr, "%s\n", help_message);
+}
+
+void help (void) {
+ print_help();
+ exit(0);
+}
+
+void
+usage (const char *errmsg)
+{
+ if (errmsg != NULL)
+ fprintf (stderr, "%s: %s\n\n", program_name, errmsg);
+
+ print_help();
exit (1);
}
@@ -1918,6 +1930,10 @@ main (int argc, char **argv)
while (argv++, --argc>0 && **argv == '-') {
if (!strcmp(argv[0], "-"))
continue;
+ if (!strcmp(argv[0], "-help")) {
+ help ();
+ /* NOTREACHED */
+ }
if (!strcmp(argv[0], "-grammar")) {
grammar ();
/* NOTREACHED */