X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/568c39ad1836f8cf87ccc1b2ba577b6f6ba37e25..b8b1c8789189cf94ec1e1a15623531ebecc3eb85:/test/randomdecl.c diff --git a/test/randomdecl.c b/test/randomdecl.c index 12728cc..8e40448 100644 --- a/test/randomdecl.c +++ b/test/randomdecl.c @@ -31,23 +31,21 @@ #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 } }; -static void print_version() -{ - puts(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION); - puts("Copyright (C) 2011 Nick Bowler."); - puts("License GPLv3+: GNU GPL version 3 or later ."); - puts("This is free software: you are free to change and redistribute it."); - puts("There is NO WARRANTY, to the extent permitted by law."); -} +enum { + MODE_CDECL, + MODE_ENGLISH, +}; static void print_usage(FILE *f) { @@ -87,7 +85,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]; @@ -100,8 +98,14 @@ 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': - print_version(); + test_print_version(PROGNAME); return EXIT_SUCCESS; case 'H': print_help(); @@ -123,11 +127,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; }