From 3f36aca66e1ac6c872300059e8db691a473614d4 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 08:23:31 +0300 Subject: publish --- src/fsm-match.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/fsm-match.c (limited to 'src/fsm-match.c') diff --git a/src/fsm-match.c b/src/fsm-match.c new file mode 100644 index 0000000..6bce408 --- /dev/null +++ b/src/fsm-match.c @@ -0,0 +1,37 @@ +// fsm-match.c --- match string against a pattern using a finate state machine +// Usage: fsm-match string +#include +#include +#include +#include "utils.h" +#include "fsm.h" + +int +main (int argc, char *argv[]) +{ + const char *progname = *argv++; + + if (argc != 2) { + fprintf (stderr, "Usage: %s string\n", progname); + return EXIT_FAILURE; + } + + const char *string = *argv++; + for (const char *p = string; *p; ++p) { + char s = C2A (*p); + if (0 > s || s >= ALPHABET_SYMBOL_COUNT) { + fprintf (stderr, "error: symbols not from alphabet " + "(starting from `%c' at column %ld)\n", *p, p - string); + return EXIT_FAILURE; + } + } + + if (fsm_match (string)) { + fprintf (stderr, "info: string matches\n"); + return EXIT_SUCCESS; + } else { + fprintf (stderr, "info: string doesn't match\n"); + return EXIT_FAILURE; + } +} +// fsm-match.c ends here -- cgit v1.3.1