<commit_before>/* $Id$ */

/*
 * An example illustrating glob(3)-like matching for strings by internally
 * constructing a DFA from the given globing string. A similar technique
 * could be used to implement regular expressions.
 *
 * The minimised DFA constructed is output to stdout, unless the -q option
 * is passed to quieten the output.
 *
 * Supported special characters are:
 *
 *  * - Zero or more occurrences of any character
 *  ? - Exactly one occurrence of any character.
 *
 * All other characters are verbatim. No escaping for special characters is
 * provided. A complete match is tested for; no trailing characters are
 * permitted.
 *
 * For example: ./glob "a??*b" "axxzzzb"
 *
 * Returns 0 on successful matching, 1 otherwise.
 */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <unistd.h>

#include <fsm/fsm.h>
#include <fsm/pred.h>
#include <fsm/out.h>

static void
usage(void)
{
	printf("usage: glob [-h] [-q] <glob> <string>\n");
}

static int
match_getc(void *opaque)
{
	const char **s = opaque;
	unsigned char c;

	assert(opaque != NULL);
	assert(*s != NULL);

	/* TODO: simplify? */
	c = **s;
	(*s)++;

	return c == '\0' ? EOF : c;
}

static int
match(const struct fsm *fsm, const char *s)
{
	assert(fsm != NULL);
	assert(fsm_predicate(fsm, fsm_isdfa));
	assert(s != NULL);

	return fsm_exec(fsm, match_getc, &s);
}

static struct fsm *
compile(const char *glob)
{
	struct fsm *fsm;
	struct fsm_state *state;
	const char *p;

	assert(glob != NULL);

	fsm = fsm_new();
	if (!fsm) {
		perror("fsm_new");
		exit(2);
	}<commit_msg>`fsm_predicate()` was replaced by `fsm_all()`.<commit_after>/* $Id$ */

/*
 * An example illustrating glob(3)-like matching for strings by internally
 * constructing a DFA from the given globing string. A similar technique
 * could be used to implement regular expressions.
 *
 * The minimised DFA constructed is output to stdout, unless the -q option
 * is passed to quieten the output.
 *
 * Supported special characters are:
 *
 *  * - Zero or more occurrences of any character
 *  ? - Exactly one occurrence of any character.
 *
 * All other characters are verbatim. No escaping for special characters is
 * provided. A complete match is tested for; no trailing characters are
 * permitted.
 *
 * For example: ./glob "a??*b" "axxzzzb"
 *
 * Returns 0 on successful matching, 1 otherwise.
 */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <unistd.h>

#include <fsm/fsm.h>
#include <fsm/pred.h>
#include <fsm/out.h>

static void
usage(void)
{
	printf("usage: glob [-h] [-q] <glob> <string>\n");
}

static int
match_getc(void *opaque)
{
	const char **s = opaque;
	unsigned char c;

	assert(opaque != NULL);
	assert(*s != NULL);

	/* TODO: simplify? */
	c = **s;
	(*s)++;

	return c == '\0' ? EOF : c;
}

static int
match(const struct fsm *fsm, const char *s)
{
	assert(fsm != NULL);
	assert(fsm_all(fsm, fsm_isdfa));
	assert(s != NULL);

	return fsm_exec(fsm, match_getc, &s);
}

static struct fsm *
compile(const char *glob)
{
	struct fsm *fsm;
	struct fsm_state *state;
	const char *p;

	assert(glob != NULL);

	fsm = fsm_new();
	if (!fsm) {
		perror("fsm_new");
		exit(2);
	}
{'fraction_non_alphanumeric': 0.1434715821812596, 'fraction_numerical': 0.0030721966205837174, 'mean_word_length': 3.8023598820059, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3265157', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1155, 'n_words': 390}