]> git.draconx.ca Git - cdecl99.git/blobdiff - test/randomdecl.c
Add better --help text to the test programs.
[cdecl99.git] / test / randomdecl.c
index 0d53af32c2fe4fb293f2c6ed7686668d13771525..a5b5d3cb39e99833c71a5603f5e70d72ca4ee172 100644 (file)
@@ -1,19 +1,19 @@
 /*
- *  Generate random C declarations for testing.
- *  Copyright © 2011 Nick Bowler
+ * Generate random C declarations for testing.
+ * Copyright © 2012, 2020 Nick Bowler
  *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
 
 #define PROGNAME "randomdecl"
 static const char *progname = PROGNAME;
-static const char sopts[] = "s:n:VH";
+static const char sopts[] = "s:n:ECVH";
 static const struct option lopts[] = {
        { "seed",    1, NULL, 's' },
        { "count",   1, NULL, 'n' },
+       { "cdecl",   0, NULL, 'C' },
+       { "english", 0, NULL, 'E' },
        { "version", 0, NULL, 'V' },
        { "help",    0, NULL, 'H' },
        { 0 }
 };
 
+enum {
+       MODE_CDECL,
+       MODE_ENGLISH,
+};
+
 static void print_usage(FILE *f)
 {
        fprintf(f, "Usage: %s [options]\n", progname);
@@ -47,8 +54,18 @@ static void print_usage(FILE *f)
 
 static void print_help(void)
 {
+       const struct option *opt;
+
        print_usage(stdout);
-       puts("Detailed help coming soon.");
+       puts("Generate random C declarations for testing.\n");
+
+       puts("Options:");
+       for (opt = lopts; opt->val; opt++) {
+               int w = print_option_start(opt, NULL);
+
+               if (w)
+                       putchar('\n');
+       }
 }
 
 static struct cdecl *random_decl(struct gen_rng *rng)
@@ -78,7 +95,7 @@ int main(int argc, char **argv)
        struct gen_rng *rng;
        struct cdecl *decl;
        unsigned long count = 0;
-       int opt;
+       int opt, mode = MODE_CDECL;
 
        if (argc > 0)
                progname = argv[0];
@@ -91,6 +108,12 @@ int main(int argc, char **argv)
                case 'n':
                        count_str = optarg;
                        break;
+               case 'C':
+                       mode = MODE_CDECL;
+                       break;
+               case 'E':
+                       mode = MODE_ENGLISH;
+                       break;
                case 'V':
                        test_print_version(PROGNAME);
                        return EXIT_SUCCESS;
@@ -114,7 +137,12 @@ int main(int argc, char **argv)
 
        for (unsigned long i = 0; !count || i < count; i++) {
                decl = random_decl(rng);
-               test_print_decl(decl);
+
+               if (mode == MODE_ENGLISH) {
+                       test_explain_decl(decl);
+               } else {
+                       test_print_decl(decl);
+               }
 
                gen_free_declspecs(decl->specifiers);
                gen_free_declarators(decl->declarators);