From 632461227686bb31004fd9cf823bcf1645e7a563 Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Sat, 11 Apr 2020 22:29:47 +0900 Subject: 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 --- xprop.c | 24 ++++++++++++++++++++---- 1 file 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 */ -- cgit v1.2.3