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>
132 lines
4.1 KiB
C
132 lines
4.1 KiB
C
#include "rules.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
static int hex_digit(int byte)
|
|
{
|
|
if (byte >= '0' && byte <= '9')
|
|
return byte - '0';
|
|
if (byte >= 'a' && byte <= 'f')
|
|
return byte - 'a' + 10;
|
|
if (byte >= 'A' && byte <= 'F')
|
|
return byte - 'A' + 10;
|
|
return -1;
|
|
}
|
|
static int read_bytes(unsigned char *destination, size_t capacity, size_t *length)
|
|
{
|
|
char encoded[2049];
|
|
if (scanf("%2048s", encoded) != 1)
|
|
return 0;
|
|
if (strcmp(encoded, "-") == 0) {
|
|
*length = 0;
|
|
return 1;
|
|
}
|
|
size_t size = strlen(encoded);
|
|
if (size % 2 || size / 2 > capacity)
|
|
return 0;
|
|
for (size_t i = 0; i < size / 2; i++) {
|
|
int high = hex_digit(encoded[2 * i]);
|
|
int low = hex_digit(encoded[2 * i + 1]);
|
|
if (high < 0 || low < 0)
|
|
return 0;
|
|
destination[i] = (unsigned char)(high * 16 + low);
|
|
}
|
|
*length = size / 2;
|
|
return 1;
|
|
}
|
|
static void bank_observation(int status, const rule_bank *bank)
|
|
{
|
|
port_usage usage = port_current_usage();
|
|
printf("%d %zu %u %zu %zu\n", status, bank->count, bank->generation,
|
|
usage.programs, usage.terms);
|
|
}
|
|
static int read_replacement(rule_bank *bank)
|
|
{
|
|
rule_input rules[64];
|
|
unsigned char storage[64][1024];
|
|
size_t count;
|
|
if (scanf("%zu", &count) != 1 || count > 64)
|
|
return 0;
|
|
for (size_t i = 0; i < count; i++) {
|
|
if (scanf("%d %d", &rules[i].identifier, &rules[i].priority) != 2)
|
|
return 0;
|
|
if (!read_bytes(storage[i], sizeof(storage[i]), &rules[i].length))
|
|
return 0;
|
|
rules[i].pattern = storage[i];
|
|
}
|
|
int status = bank_replace(bank, rules, count);
|
|
bank_observation(status, bank);
|
|
return 1;
|
|
}
|
|
static int read_match(rule_bank *bank)
|
|
{
|
|
unsigned char message[1024];
|
|
size_t length;
|
|
if (!read_bytes(message, sizeof(message), &length))
|
|
return 0;
|
|
rule_result result = {999, 999, 999, 999};
|
|
int status = bank_match(bank, message, length, &result);
|
|
port_usage usage = port_current_usage();
|
|
printf("%d %zu %d %d %d %u %zu %zu\n", status, result.hits,
|
|
result.identifier, result.priority, result.input_index,
|
|
bank->generation, usage.programs, usage.terms);
|
|
return 1;
|
|
}
|
|
static void default_demo(rule_bank *bank)
|
|
{
|
|
const unsigned char first[] = "^err";
|
|
const unsigned char second[] = "warn";
|
|
const unsigned char third[] = "fatal";
|
|
rule_input rules[] = {
|
|
{11, 4, first, sizeof(first) - 1},
|
|
{12, 2, second, sizeof(second) - 1},
|
|
{13, 8, third, sizeof(third) - 1}
|
|
};
|
|
bank_observation(bank_replace(bank, rules, 3), bank);
|
|
rule_result result = {999, 999, 999, 999};
|
|
const unsigned char text[] = "warning: disk full";
|
|
int status = bank_match(bank, text, sizeof(text) - 1, &result);
|
|
port_usage usage = port_current_usage();
|
|
printf("%d %zu %d %d %d %u %zu %zu\n", status, result.hits,
|
|
result.identifier, result.priority, result.input_index,
|
|
bank->generation, usage.programs, usage.terms);
|
|
bank_clear(bank);
|
|
bank_observation(0, bank);
|
|
}
|
|
int main(int argc, char **argv)
|
|
{
|
|
rule_bank bank;
|
|
bank_init(&bank);
|
|
port_budget(-1);
|
|
if (argc == 2 && strcmp(argv[1], "--demo") == 0) {
|
|
default_demo(&bank);
|
|
return 0;
|
|
}
|
|
char operation[16];
|
|
while (scanf("%15s", operation) == 1) {
|
|
if (strcmp(operation, "B") == 0) {
|
|
if (!read_replacement(&bank))
|
|
return 20;
|
|
} else if (strcmp(operation, "M") == 0) {
|
|
if (!read_match(&bank))
|
|
return 21;
|
|
} else if (strcmp(operation, "F") == 0) {
|
|
int budget;
|
|
if (scanf("%d", &budget) != 1 || budget < -1)
|
|
return 22;
|
|
port_budget(budget);
|
|
printf("%d\n", budget);
|
|
} else if (strcmp(operation, "C") == 0) {
|
|
bank_clear(&bank);
|
|
bank_observation(0, &bank);
|
|
} else if (strcmp(operation, "S") == 0) {
|
|
bank_observation(0, &bank);
|
|
} else {
|
|
return 23;
|
|
}
|
|
}
|
|
bank_clear(&bank);
|
|
bank_observation(0, &bank);
|
|
return 0;
|
|
}
|