From 6deca4cb7bd0293760d0f1e3678387d74ca72251 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 18 Apr 2024 13:27:10 -0700 Subject: Add -help [options|tests|all] and remove tests from default usage message Previously, the error message when giving a bad option was over 350 lines long. This moves the list of tests out into the `-help tests` option and makes the usage error message a much more reasonable 32 lines long. (Also accepts but does not document --help.) Signed-off-by: Alan Coopersmith Part-of: --- configure.ac | 2 +- man/x11perf.man | 12 ++++++ x11perf.c | 111 ++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 80 insertions(+), 45 deletions(-) diff --git a/configure.ac b/configure.ac index fde7a5b..5957379 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ AC_SUBST([x11perfcompdir], [$datadir/X11/x11perfcomp]) AC_PATH_PROG(MKTEMP, mktemp) # Checks for pkg-config packages -PKG_CHECK_MODULES(X11PERF, [x11 xmuu xproto >= 7.0.17]) +PKG_CHECK_MODULES(X11PERF, [x11 xmuu xproto >= 7.0.25]) # Check for Xrender library PKG_CHECK_MODULES(XRENDER, xrender, [xrender_found=yes], [xrender_found=no]) diff --git a/man/x11perf.man b/man/x11perf.man index dccc476..a6471c7 100644 --- a/man/x11perf.man +++ b/man/x11perf.man @@ -260,6 +260,18 @@ Set the backing_store window attribute to the given value on all windows created by x11perf. can be WhenMapped or Always. Default is NotUseful. .TP 14 +.B \-help [options|tests|all] +Print information about available options and exit. +If no argument is specified, or \fBoptions\fR is specified, just prints +information about general options, but does not include the long list of +options for running specific tests. +If \fBtests\fR is specified, just prints the long list of options for +running specific tests. +If \fBall\fR is specified, prints information about both sets of options. +If \fB-v\fR\fIversion\fR is also specified, the list of options for +running specific tests will be limited to the tests for that version. +.SS Options for running specific tests +.TP 14 .B \-dot Dot. .TP 14 diff --git a/x11perf.c b/x11perf.c index cea0351..763d19d 100644 --- a/x11perf.c +++ b/x11perf.c @@ -319,7 +319,12 @@ ReportTimes(double usecs, int64_t n, char *str, int average) ************************************************/ static char *program_name; -static void usage(void) _X_NORETURN; +typedef enum { + USAGE_OPTIONS, + USAGE_TESTS, + USAGE_ALL +} usage_contents; +_X_NORETURN _X_COLD static void usage(usage_contents, int); /* * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obsolete) @@ -337,7 +342,7 @@ Get_Display_Name(int *pargc, /* MODIFIED */ char *arg = argv[i]; if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) { - if (++i >= argc) usage (); + if (++i >= argc) usage (USAGE_OPTIONS, EXIT_FAILURE); displayname = argv[i]; *pargc -= 2; @@ -467,7 +472,7 @@ AbortTest(void) static void -usage(void) +usage(usage_contents show, int exit_status) { int i = 0; static const char *help_message = @@ -503,26 +508,27 @@ usage(void) " -version print version and exit\n" " -su request save unders on windows\n" " -bs WhenMapped or Always (default = NotUseful)\n" +" -help [options|tests|all] list general options, test options, or both\n" ; fflush(stdout); - fprintf(stderr, "usage: %s [-options ...]\n%s", program_name, help_message); - while (test[i].option != NULL) { - if (test[i].versions & xparms.version ) { - fprintf(stderr, " %-24s %s\n", - test[i].option, - test[i].label14 ? test[i].label14 : test[i].label); - } - i++; + if (show == USAGE_OPTIONS || show == USAGE_ALL) { + fprintf(stderr, "usage: %s [-options ...]\n%s", + program_name, help_message); + } + if (show == USAGE_TESTS || show == USAGE_ALL) { + while (test[i].option != NULL) { + if (test[i].versions & xparms.version ) { + fprintf(stderr, " %-24s %s\n", + test[i].option, + test[i].label14 ? test[i].label14 : test[i].label); + } + i++; + } } fprintf(stderr, "\n"); - /* Print out original command line as the above usage message is so long */ - for (i = 0; i != saveargc; i++) { - fprintf(stderr, "%s ", saveargv[i]); - } - fprintf(stderr, "\n\n"); - exit (1); + exit (exit_status); } void @@ -931,7 +937,7 @@ main(int argc, char *argv[]) char *cp2; if (argc <= ++i) - usage(); + usage(USAGE_OPTIONS, EXIT_FAILURE); cp1 = argv[i]; if (*cp1 == '-') cp1++; @@ -953,12 +959,12 @@ main(int argc, char *argv[]) (test[k].versions & xparms.version)) && test[++k].option != NULL); if (*cp2 != '-' && test[k].option == NULL) - usage(); + usage(USAGE_OPTIONS, EXIT_FAILURE); break; } } if (test[j].option == NULL) - usage(); + usage(USAGE_OPTIONS, EXIT_FAILURE); foundOne = True; } else if (strcmp (argv[i], "-sync") == 0) { synchronous = True; @@ -971,44 +977,44 @@ main(int argc, char *argv[]) } else if (strcmp (argv[i], "-repeat") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); repeat = atoi (argv[i]); if (repeat <= 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp (argv[i], "-time") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); seconds = atoi (argv[i]); if (seconds <= 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp (argv[i], "-pause") == 0) { ++i; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); delay = atoi (argv[i]); if (delay < 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp(argv[i], "-fg") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); foreground = argv[i]; } else if (strcmp(argv[i], "-bg") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); background = argv[i]; if(ddbackground == NULL) ddbackground = argv[i]; } else if (strcmp(argv[i], "-clips") == 0 ) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); clips = atoi( argv[i] ); } else if (strcmp(argv[i], "-ddbg") == 0) { if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); i++; ddbackground = argv[i]; } else if (strcmp(argv[i], "-rop") == 0) { @@ -1033,21 +1039,21 @@ main(int argc, char *argv[]) } else if (strcmp(argv[i], "-reps") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); fixedReps = atoi (argv[i]); if (fixedReps <= 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp(argv[i], "-depth") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); depth = atoi(argv[i]); if (depth <= 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp(argv[i], "-vclass") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); for (j = StaticGray; j <= DirectColor; j++) { if (strcmp(argv[i], visualClassNames[j]) == 0) { vclass = j; @@ -1055,7 +1061,7 @@ main(int argc, char *argv[]) } } if (vclass < 0) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); } else if (strcmp(argv[i], "-subs") == 0) { skip = GetNumbers (i+1, argc, argv, subWindows, &numSubWindows); i += skip; @@ -1064,16 +1070,33 @@ main(int argc, char *argv[]) } else if (strcmp(argv[i], "-bs") == 0) { i++; if (argc <= i) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); if (strcmp(argv[i], "WhenMapped") == 0) { xparms.backing_store = WhenMapped; } else if (strcmp(argv[i], "Always") == 0) { xparms.backing_store = Always; - } else usage (); + } else usage (USAGE_OPTIONS, EXIT_FAILURE); } else if ((strcmp(argv[i], "-version") == 0) || (strcmp(argv[i], "--version") == 0)) { puts(PACKAGE_STRING); exit(EXIT_SUCCESS); + } else if ((strcmp(argv[i], "-help") == 0) || + (strcmp(argv[i], "--help") == 0)) { + i++; + /* default is to just show general options */ + if (argc <= i || (strcmp(argv[i], "options") == 0)) { + usage (USAGE_OPTIONS, EXIT_SUCCESS); + } + else if (strcmp(argv[i], "tests") == 0) { + usage (USAGE_TESTS, EXIT_SUCCESS); + } + else if (strcmp(argv[i], "all") == 0) { + usage (USAGE_ALL, EXIT_SUCCESS); + } + else { + fprintf(stderr, "unknown --help argument: %s\n", argv[i]); + usage (USAGE_OPTIONS, EXIT_FAILURE); + } } else { int len,found; ForEachTest (j) { @@ -1100,7 +1123,7 @@ main(int argc, char *argv[]) } } if(!found) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); LegalOption: foundOne = True; } @@ -1176,7 +1199,7 @@ main(int argc, char *argv[]) } if (!foundOne) - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); xparms.d = Open_Display (displayName); screen = DefaultScreen(xparms.d); @@ -1422,7 +1445,7 @@ GetWords (int argi, int argc, char **argv, char **wordsp, int *nump) int count; if (argc <= argi) - usage(); + usage(USAGE_OPTIONS, EXIT_FAILURE); count = 0; while (argv[argi] && *(argv[argi]) != '-') { *wordsp++ = argv[argi]; @@ -1497,7 +1520,7 @@ GetRops (int argi, int argc, char **argv, int *ropsp, int *nump) } } if (rop == NUM_ROPS) { - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); fprintf (stderr, "unknown rop name %s\n", words[i]); } } @@ -1529,7 +1552,7 @@ GetPops (int argi, int argc, char **argv, int *popsp, int *nump) } } if (pop == NUM_POPS) { - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); fprintf (stderr, "unknown picture op name %s\n", words[i]); } } @@ -1574,7 +1597,7 @@ GetFormats (int argi, int argc, char **argv, int *formatsp, int *nump) } format = FormatFromName (words[i]); if (format < 0) { - usage (); + usage (USAGE_OPTIONS, EXIT_FAILURE); fprintf (stderr, "unknown format name %s\n", words[i]); } formatsp[i] = format; -- cgit v1.2.3