/*
- * 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);
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)
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':
test_print_version(PROGNAME);
return EXIT_SUCCESS;
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;
}