One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
2.5 KiB
C
82 lines
2.5 KiB
C
#include "rules.h"
|
|
#include <stdlib.h>
|
|
typedef struct node {
|
|
compiled_rule *program;
|
|
int id;
|
|
int priority;
|
|
int order;
|
|
struct node *next;
|
|
} node;
|
|
static void dispose(node *head)
|
|
{
|
|
while (head) {
|
|
node *next = head->next;
|
|
port_release(head->program);
|
|
free(head);
|
|
head = next;
|
|
}
|
|
}
|
|
void bank_init(rule_bank *b)
|
|
{
|
|
if (b) *b = (rule_bank){NULL, 0, 0};
|
|
}
|
|
void bank_clear(rule_bank *b)
|
|
{
|
|
if (!b) return;
|
|
dispose(b->state);
|
|
b->state = NULL;
|
|
b->count = 0;
|
|
b->generation++;
|
|
}
|
|
int bank_replace(rule_bank *b, const rule_input *r, size_t count)
|
|
{
|
|
if (!b || count > RULE_LIMIT || (!r && count)) return PORT_ARGUMENT;
|
|
for (size_t i=0; i<count; i++) {
|
|
if (r[i].identifier < 1 || r[i].identifier > 1000000 ||
|
|
r[i].priority < -1000 || r[i].priority > 1000 ||
|
|
r[i].length > PATTERN_LIMIT || (!r[i].pattern && r[i].length))
|
|
return PORT_ARGUMENT;
|
|
for (size_t j=i+1; j<count; j++)
|
|
if (r[i].identifier == r[j].identifier) return PORT_ARGUMENT;
|
|
}
|
|
node *prepared = NULL;
|
|
for (size_t i=0; i<count; i++) {
|
|
node *entry = calloc(1, sizeof(*entry));
|
|
if (!entry) { dispose(prepared); return PORT_MEMORY; }
|
|
int status = port_compile(r[i].pattern, r[i].length, &entry->program);
|
|
if (status) { free(entry); dispose(prepared); return status; }
|
|
entry->id = r[i].identifier;
|
|
entry->priority = r[i].priority;
|
|
entry->order = (int)i;
|
|
node **place = &prepared;
|
|
while (*place && ((*place)->priority > entry->priority ||
|
|
((*place)->priority == entry->priority && (*place)->order < entry->order)))
|
|
place = &(*place)->next;
|
|
entry->next = *place;
|
|
*place = entry;
|
|
}
|
|
node *old = b->state;
|
|
b->state = prepared;
|
|
b->count = count;
|
|
b->generation++;
|
|
dispose(old);
|
|
return PORT_OK;
|
|
}
|
|
int bank_match(const rule_bank *b, const unsigned char *m, size_t length, rule_result *out)
|
|
{
|
|
if (!b || !out || (!m && length) || length > MESSAGE_LIMIT) return PORT_ARGUMENT;
|
|
rule_result result = {0, 0, 0, -1};
|
|
for (const node *n=b->state; n; n=n->next) {
|
|
if (port_matches(n->program, m, length)) {
|
|
if (!result.hits) {
|
|
result.identifier=n->id;
|
|
result.priority=n->priority;
|
|
result.input_index=n->order;
|
|
}
|
|
result.hits++;
|
|
}
|
|
}
|
|
*out=result;
|
|
return PORT_OK;
|
|
}
|