X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/e031b4f0220432aef6e1864ea6359353dbd8aed3..879d69d46fdf7ddf33beac6c32c7f2646d97d0ca:/test/randomdecl.c diff --git a/test/randomdecl.c b/test/randomdecl.c index 5e8a4a9..a5b5d3c 100644 --- a/test/randomdecl.c +++ b/test/randomdecl.c @@ -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 . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -31,15 +31,22 @@ #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,11 +137,19 @@ int main(int argc, char **argv) for (unsigned long i = 0; !count || i < count; i++) { decl = random_decl(rng); - if (!decl) - return EXIT_FAILURE; - 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); + free(decl); } + gen_free_rng(rng); + return EXIT_SUCCESS; }