#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 <http://gnu.org/licenses/gpl.html>.");
- 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)
{
struct gen_rng *rng;
struct cdecl *decl;
unsigned long count = 0;
- int opt;
+ int opt, mode = MODE_CDECL;
if (argc > 0)
progname = argv[0];
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();
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;
}