X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/e031b4f0220432aef6e1864ea6359353dbd8aed3..8ba5dbed14fc225893f8ad4b935e0e4b9f77db78:/test/randomdecl.c?ds=sidebyside
diff --git a/test/randomdecl.c b/test/randomdecl.c
index 5e8a4a9..9e9271e 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, 2022 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,11 +54,14 @@ 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");
+ test_print_options(lopts);
}
-static struct cdecl *random_decl(struct gen_rng *rng)
+static struct cdecl *random_decl(struct test_rng *rng)
{
struct cdecl *decl;
unsigned flags = 0;
@@ -75,10 +85,10 @@ static struct cdecl *random_decl(struct gen_rng *rng)
int main(int argc, char **argv)
{
const char *seed = "", *count_str = NULL;
- struct gen_rng *rng;
+ struct test_rng *rng;
struct cdecl *decl;
unsigned long count = 0;
- int opt;
+ int opt, mode = MODE_CDECL;
if (argc > 0)
progname = argv[0];
@@ -91,6 +101,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;
@@ -108,17 +124,25 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- rng = gen_alloc_rng(seed);
+ rng = test_rng_alloc(seed);
if (!rng)
return EXIT_FAILURE;
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);
}
+ test_rng_free(rng);
+
return EXIT_SUCCESS;
}