mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
remove start argument in literal matcher callbacks
This commit is contained in:
committed by
Matthew Barr
parent
482e1ef931
commit
ebb1b0006b
@@ -79,9 +79,9 @@ struct HWLM;
|
||||
|
||||
/** \brief The type for an HWLM callback.
|
||||
*
|
||||
* This callback receives a start-of-match offset, an end-of-match offset, the
|
||||
* ID of the match and the context pointer that was passed into \ref
|
||||
* hwlmExec or \ref hwlmExecStreaming.
|
||||
* This callback receives an end-of-match offset, the ID of the match and
|
||||
* the context pointer that was passed into \ref hwlmExec or
|
||||
* \ref hwlmExecStreaming.
|
||||
*
|
||||
* A callback return of \ref HWLM_TERMINATE_MATCHING will stop matching.
|
||||
*
|
||||
@@ -95,8 +95,7 @@ struct HWLM;
|
||||
* belonging to the literal which was active at the when the end match location
|
||||
* was first reached.
|
||||
*/
|
||||
typedef hwlmcb_rv_t (*HWLMCallback)(size_t start, size_t end, u32 id,
|
||||
void *context);
|
||||
typedef hwlmcb_rv_t (*HWLMCallback)(size_t end, u32 id, void *context);
|
||||
|
||||
/** \brief Match strings in table.
|
||||
*
|
||||
|
@@ -121,9 +121,8 @@ bytecode_ptr<noodTable> noodBuildTable(const hwlmLiteral &lit) {
|
||||
size_t key_offset = findNoodFragOffset(lit);
|
||||
|
||||
n->id = lit.id;
|
||||
n->lit_len = s.length();
|
||||
n->single = s.length() == 1 ? 1 : 0;
|
||||
n->key_offset = verify_u8(n->lit_len - key_offset);
|
||||
n->key_offset = verify_u8(s.length() - key_offset);
|
||||
n->nocase = lit.nocase ? 1 : 0;
|
||||
n->key0 = s[key_offset];
|
||||
if (n->single) {
|
||||
@@ -151,12 +150,12 @@ namespace ue2 {
|
||||
|
||||
void noodPrintStats(const noodTable *n, FILE *f) {
|
||||
fprintf(f, "Noodle table\n");
|
||||
fprintf(f, "Len: %u Key Offset: %u\n", n->lit_len, n->key_offset);
|
||||
fprintf(f, "Key Offset: %u\n", n->key_offset);
|
||||
fprintf(f, "Msk: %llx Cmp: %llx MskLen %u\n",
|
||||
n->msk >> 8 * (8 - n->msk_len), n->cmp >> 8 * (8 - n->msk_len),
|
||||
n->msk_len);
|
||||
fprintf(f, "String: ");
|
||||
for (u32 i = n->msk_len - n->lit_len; i < n->msk_len; i++) {
|
||||
for (u32 i = 0; i < n->msk_len; i++) {
|
||||
const u8 *m = (const u8 *)&n->cmp;
|
||||
if (isgraph(m[i]) && m[i] != '\\') {
|
||||
fprintf(f, "%c", m[i]);
|
||||
|
@@ -128,10 +128,8 @@ hwlm_error_t final(const struct noodTable *n, const u8 *buf, UNUSED size_t len,
|
||||
|
||||
match:
|
||||
pos -= cbi->offsetAdj;
|
||||
DEBUG_PRINTF("match @ %zu->%zu\n", pos + n->key_offset - n->lit_len,
|
||||
pos + n->key_offset);
|
||||
hwlmcb_rv_t rv = cbi->cb(pos + n->key_offset - n->lit_len,
|
||||
pos + n->key_offset - 1, cbi->id, cbi->ctx);
|
||||
DEBUG_PRINTF("match @ %zu\n", pos + n->key_offset);
|
||||
hwlmcb_rv_t rv = cbi->cb(pos + n->key_offset - 1, cbi->id, cbi->ctx);
|
||||
if (rv == HWLM_TERMINATE_MATCHING) {
|
||||
return HWLM_TERMINATED;
|
||||
}
|
||||
@@ -377,8 +375,8 @@ hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len,
|
||||
assert(n && buf);
|
||||
|
||||
struct cb_info cbi = {cb, n->id, ctxt, 0};
|
||||
DEBUG_PRINTF("nood scan of %zu bytes for %*s @ %p\n", len, n->lit_len,
|
||||
(const char *)&n->cmp + n->msk_len - n->lit_len, buf);
|
||||
DEBUG_PRINTF("nood scan of %zu bytes for %*s @ %p\n", len, n->msk_len,
|
||||
(const char *)&n->cmp, buf);
|
||||
|
||||
return scan(n, buf, len, start, n->single, n->nocase, &cbi);
|
||||
}
|
||||
@@ -396,8 +394,7 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
|
||||
struct cb_info cbi = {cb, n->id, ctxt, 0};
|
||||
DEBUG_PRINTF("nood scan of %zu bytes (%zu hlen) for %*s @ %p\n", len, hlen,
|
||||
n->lit_len, (const char *)&n->cmp + n->msk_len - n->lit_len,
|
||||
buf);
|
||||
n->msk_len, (const char *)&n->cmp, buf);
|
||||
|
||||
if (hlen && n->msk_len > 1) {
|
||||
/*
|
||||
@@ -427,9 +424,8 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
u64a v = unaligned_load_u64a(temp_buf + i);
|
||||
if ((v & n->msk) == n->cmp) {
|
||||
size_t m_end = -tl1 + i + n->msk_len - 1;
|
||||
size_t m_start = m_end - n->lit_len;
|
||||
DEBUG_PRINTF("match @ %zu->%zu (i %zu)\n", m_start, m_end, i);
|
||||
hwlmcb_rv_t rv = cb(m_start, m_end, n->id, ctxt);
|
||||
DEBUG_PRINTF("match @ %zu (i %zu)\n", m_end, i);
|
||||
hwlmcb_rv_t rv = cb(m_end, n->id, ctxt);
|
||||
if (rv == HWLM_TERMINATE_MATCHING) {
|
||||
return HWLM_TERMINATED;
|
||||
}
|
||||
|
@@ -39,7 +39,6 @@ struct noodTable {
|
||||
u32 id;
|
||||
u64a msk;
|
||||
u64a cmp;
|
||||
u8 lit_len;
|
||||
u8 msk_len;
|
||||
u8 key_offset;
|
||||
u8 nocase;
|
||||
|
Reference in New Issue
Block a user