コード例 #1
0
int
main(int argc, char **argv)
{
    if (argc != 3) die(": requires args: acism_file text_file");

    plan_tests(2);

    FILE *pfp = fopen(argv[1], "r");
    if (!pfp) die(": unable to open %s:", argv[1]);

    MEMREF text = bufref(slurp(argv[2]));
    if (nilref(text)) die(": unable to load %s:", argv[2]);

    ACISM *psp = acism_mmap(pfp);
    ok(psp, "acism_mmap returned");
    fclose(pfp);
    double t0 = tick();
    ok(!acism_scan(psp, text, on_match, NULL),
        "mmap-ed acism object works");

    fprintf(stderr, "# nmatches: %d %.4f secs\n", nmatches, tick() - t0);
    acism_dump(psp, PS_STATS, stderr, NULL);
    acism_destroy(psp);

    return exit_status();
}
コード例 #2
0
ファイル: lua_trie.c プロジェクト: LlsDimple/rspamd
static gint
lua_trie_destroy (lua_State *L)
{
	ac_trie_t *trie = lua_check_trie (L, 1);

	if (trie) {
		acism_destroy (trie);
	}

	return 0;
}
コード例 #3
0
ファイル: acism_x.c プロジェクト: mischasan/aho-corasick
int
main(int argc, char **argv)
{
    if (argc < 2 || argc > 4)
        usage("pattern_file target_file [[-]expected]\ne.g. acism_x patts act.txt -5");

    MEMBUF patt = chomp(slurp(argv[1]));
    if (!patt.ptr)
        die("cannot read %s", argv[1]);

    int npatts;
    MEMREF *pattv = refsplit(patt.ptr, '\n', &npatts);

    double t = tick();
    ACISM *psp = acism_create(pattv, npatts);
    t = tick() - t;

    plan_tests(argc < 3 ? 1 : 3);

    ok(psp, "acism_create(pattv[%d]) compiled, in %.3f secs", npatts, t);
    acism_dump(psp, PS_ALL, stderr, pattv);
#ifdef ACISM_STATS
    {
    int i;
    for (i = 1; i < (int)psstat[0].val; ++i)
        if (psstat[i].val)
            fprintf(stderr, "%11llu %s\n", psstat[i].val, psstat[i].name);
    }
#endif//ACISM_STATS

    diag("state machine saved as acism.tmp");
    FILE *fp = FOPEN("acism.tmp", "w");
    acism_save(fp, psp);
    fclose(fp);

    if (argc > 2) {
        // Negative count => print match details
        int expected = argc > 3 ? atoi(argv[3]) : 0;
        int details = expected < 0;
        if (details) expected = -expected;
        FILE*	textfp = FOPEN(argv[2], "r");		// REUSE PATTERN FILE AS A TARGET
        if (!fp) die("cannot open %s", argv[2]);
        static char buf[1024*1024];
        MEMREF		text = {buf, 0};
        int			state = 0;
        double		elapsed = 0, start = tick();
        while (0 < (text.len = fread(buf, sizeof*buf, sizeof buf, textfp))) {
            t = tick();
            (void)acism_more(psp, text, (ACISM_ACTION*)on_match, pattv, &state);
            elapsed += tick() - t;
            putc('.', stderr);
        }
        putc('\n', stderr);
        fclose(textfp);
        ok(text.len == 0, "text_file scanned in 1M blocks; read(s) took %.3f secs", tick() - start - elapsed);

        if (!ok(actual == expected || expected == 0, "%d matches found, in %.3f secs", actual, elapsed))
            diag("actual: %d\n", actual);
    }

    buffree(patt);
    free(pattv);
    acism_destroy(psp);

    return exit_status();
}