// fsm-generate.c --- generate n pseudorandom strings using a finite state machine // Usage: fsm-generate [options] // Options: // --usage Print this usage string. // --count Number of strings to generate (default = 1). // --seed Seed number for srand (default = current time). #include #include #include #include #include "utils.h" #include "string-builder.h" #include "fsm.h" #include "regex.h" const char *progname; void usage () { fprintf (stderr, "Usage: %s [options]\n", progname); fprintf (stderr, "Options:\n"); fprintf (stderr, " --usage Print this usage string.\n"); fprintf (stderr, " --count Number of strings to generate.\n"); fprintf (stderr, " --seed Seed number for srand.\n"); } int main (int argc, char *argv[]) { UNUSED (argc); progname = *argv++; unsigned int count = 1; int seed = time (NULL); for (const char *arg = *argv++; arg; arg = *argv++) { if (!strcmp (arg, "--usage")) { usage (progname); exit (EXIT_SUCCESS); } if (!strcmp (arg, "--count")) { arg = *argv++; if (!arg) break; if (sscanf (arg, "%d", &count) != 1) { usage (progname); exit (EXIT_FAILURE); } } if (!strcmp (arg, "--seed")) { arg = *argv++; if (!arg) break; if (sscanf (arg, "%d", &seed) != 1) { usage (progname); exit (EXIT_FAILURE); } } } srand (seed); for (unsigned int i = 0; i < count; ++i) { const char *string = fsm_generate (); if (!regex_match (string)) printf ("regex not matching: "); if (! fsm_match (string)) printf ("fsm not matching: "); puts (string); } return EXIT_SUCCESS; } // fsm-generate.c ends here