amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

191 lines
4.8 KiB
C

#include "text.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
static int horizontal(char value)
{
return value == ' ' || value == '\t' || value == '\r' || value == '\n';
}
static int split(char *line, char **words, size_t capacity)
{
size_t used = 0;
char *cursor = line;
while (*cursor != 0) {
while (horizontal(*cursor)) {
cursor += 1;
}
if (*cursor == 0) {
break;
}
if (used == capacity) {
return -1;
}
words[used++] = cursor;
while (*cursor != 0 && !horizontal(*cursor)) {
cursor += 1;
}
if (*cursor != 0) {
*cursor++ = 0;
}
}
return (int)used;
}
static int hex_digit(char value)
{
if (value >= '0' && value <= '9') {
return value - '0';
}
if (value >= 'a' && value <= 'f') {
return value - 'a' + 10;
}
if (value >= 'A' && value <= 'F') {
return value - 'A' + 10;
}
return -1;
}
static int bytes(const char *word, unsigned char *data, size_t *length)
{
size_t size;
size_t index;
if (strcmp(word, "-") == 0) {
*length = 0;
return 1;
}
size = strlen(word);
if (size > TEXT_CAPACITY * 2 || size % 2 != 0) {
return 0;
}
for (index = 0; index < size; index += 2) {
int high = hex_digit(word[index]);
int low = hex_digit(word[index + 1]);
if (high < 0 || low < 0) {
return 0;
}
data[index / 2] = (unsigned char)(high * 16 + low);
}
*length = size / 2;
return 1;
}
static int limit_value(const char *word, size_t *result)
{
size_t value = 0;
if (*word == '+') {
word += 1;
}
if (*word == 0) {
return 0;
}
while (*word != 0) {
if (*word < '0' || *word > '9') {
return 0;
}
value = value * 10 + (size_t)(*word - '0');
if (value > TEXT_RECORDS) {
return 0;
}
word += 1;
}
*result = value;
return 1;
}
static void mutation(const char *name, int status, const struct text_store *store)
{
printf("%s %d %zu %" PRIu32 "\n", name, status, store->count, store->revision);
}
static void get(const struct text_store *store, const char *key)
{
struct text_measure result;
int status = text_measure(store, key, &result);
printf("GET %d %d %zu %zu %zu %" PRIu32 "\n", status, (int)result.kind,
result.stored, result.logical, result.wire, result.digest);
}
static void view(const struct text_store *store, const char *prefix, size_t limit)
{
struct text_report result;
int status = text_report(store, prefix, limit, &result);
printf("VIEW %d %zu %zu %zu %" PRIu32 "\n", status, result.selected,
result.logical, result.wire, result.digest);
}
static void dispatch(struct text_store *store, char **words, int count)
{
unsigned char data[TEXT_CAPACITY];
size_t length;
size_t limit;
int status;
if (count == 0) {
return;
}
if (count == 1 && strcmp(words[0], "RESET") == 0) {
text_store_reset(store);
mutation("RESET", 0, store);
return;
}
if (count == 4 && strcmp(words[0], "SET") == 0) {
enum text_kind kind;
if (strcmp(words[2], "C") == 0) {
kind = TEXT_CSTR;
} else if (strcmp(words[2], "B") == 0) {
kind = TEXT_COUNTED;
} else {
puts("ERR -1");
return;
}
if (!bytes(words[3], data, &length)) {
puts("ERR -1");
return;
}
status = text_store_set(store, words[1], kind, data, length);
mutation("SET", status, store);
return;
}
if (count == 2 && strcmp(words[0], "GET") == 0) {
get(store, words[1]);
return;
}
if (count == 2 && strcmp(words[0], "DEL") == 0) {
status = text_store_delete(store, words[1]);
mutation("DEL", status, store);
return;
}
if (count == 3 && strcmp(words[0], "COPY") == 0) {
status = text_store_copy(store, words[1], words[2]);
mutation("COPY", status, store);
return;
}
if (count == 3 && strcmp(words[0], "VIEW") == 0) {
if (!limit_value(words[2], &limit)) {
puts("ERR -1");
return;
}
view(store, strcmp(words[1], "-") == 0 ? "" : words[1], limit);
return;
}
puts("ERR -1");
}
int main(void)
{
struct text_store store;
char line[1024];
char *words[5];
text_store_init(&store);
while (fgets(line, sizeof(line), stdin) != NULL) {
int count = split(line, words, 5);
if (count < 0) {
puts("ERR -1");
} else {
dispatch(&store, words, count);
}
}
return ferror(stdin) || ferror(stdout) ? 1 : 0;
}