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

195 lines
6.4 KiB
C

#include "store.h"
#include "wire.h"
#include "stream.h"
#include "batch.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int digit(char character)
{
if (character >= '0' && character <= '9') return character - '0';
if (character >= 'a' && character <= 'f') return character - 'a' + 10;
return -1;
}
static size_t unhex(const char *word, unsigned char *output, size_t capacity)
{
size_t index, count;
if (word == NULL || (word[0] == '-' && word[1] == 0)) return 0;
count = strlen(word) / 2;
if (count > capacity) return 0;
for (index = 0; index < count; ++index) {
output[index] = (unsigned char)((digit(word[index * 2]) << 4) |
digit(word[index * 2 + 1]));
}
return count;
}
static void hexout(const unsigned char *data, size_t count)
{
static const char symbols[] = "0123456789abcdef";
size_t index;
if (count == 0) {
putchar('-');
return;
}
for (index = 0; index < count; ++index) {
putchar(symbols[data[index] >> 4]);
putchar(symbols[data[index] & 15]);
}
}
static char *next(void)
{
return strtok(NULL, " \t\r\n");
}
static int number(void)
{
const char *word = next();
return word ? (int)strtol(word, NULL, 10) : 0;
}
static size_t amount(void)
{
const char *word = next();
return word ? (size_t)strtoull(word, NULL, 10) : 0;
}
static void state(int result, int aux, const unsigned char *bytes, size_t count,
const stream_decoder *decoder)
{
int slot;
printf("%d %d ", result, aux);
hexout(bytes, count);
for (slot = 0; slot < STORE_SLOTS; ++slot) {
unsigned char *data = store_span(slot);
size_t length = store_length(slot);
printf(" %lu:%lu:", (unsigned long)((uintptr_t)data % 32u),
(unsigned long)length);
hexout(data, length);
}
printf(" %lu:%lu:%lu:%lu:%d\n", stream_accepted(decoder),
stream_rejected(decoder), stream_discarded(decoder),
(unsigned long)stream_pending(decoder), stream_last_slot(decoder));
fflush(stdout);
}
static void read_operation(batch_operation *op)
{
const char *word;
memset(op, 0, sizeof(*op));
op->kind = number();
op->slot = number();
op->peer = number();
op->offset = amount();
op->length = amount();
op->value = (unsigned char)number();
word = next();
unhex(word, op->data, sizeof(op->data));
}
int main(void)
{
char line[4096];
unsigned char input[2048];
unsigned char output[2048];
stream_decoder decoder;
store_reset();
stream_init(&decoder);
while (fgets(line, sizeof(line), stdin) != NULL) {
char *command = strtok(line, " \t\r\n");
const char *word;
int result = 0, aux = 0, first, second;
size_t length, count = 0, offset, written = 0;
if (command == NULL) continue;
switch (command[0]) {
case 'R':
store_reset();
stream_init(&decoder);
break;
case 'W':
first = number(); word = next(); length = unhex(word, input, sizeof(input));
result = store_write(first, input, length);
break;
case 'A':
first = number(); word = next(); length = unhex(word, input, sizeof(input));
result = store_append(first, input, length);
break;
case 'P':
first = number(); offset = amount(); word = next();
length = unhex(word, input, sizeof(input));
result = store_patch(first, offset, input, length);
break;
case 'F':
first = number(); second = number(); length = amount();
result = store_fill(first, (unsigned char)second, length);
break;
case 'C':
first = number(); second = number(); result = store_copy(first, second);
break;
case 'E':
first = number(); offset = amount(); length = amount();
result = store_erase(first, offset, length);
break;
case 'V': result = store_reverse(number()); break;
case 'O': first = number(); offset = amount(); result = store_rotate(first, offset); break;
case 'X': first = number(); second = number(); result = store_xor(first, (unsigned char)second); break;
case 'Q': first = number(); second = number(); result = store_find(first, (unsigned char)second); break;
case 'M': first = number(); second = number(); result = store_compare(first, second); break;
case 'K': first = number(); result = store_checksum(first); break;
case 'Z':
first = number(); length = amount();
result = wire_pack(first, output, length, &written);
if (result == 0) count = written;
break;
case 'U':
word = next(); length = unhex(word, input, sizeof(input));
result = wire_unpack(input, length, &aux);
break;
case 'T':
word = next(); length = unhex(word, input, sizeof(input));
result = stream_feed(&decoder, input, length);
break;
case 'L': result = stream_flush(&decoder); break;
case 'B': {
batch_operation op;
size_t failed;
read_operation(&op);
result = batch_apply(&op, 1, &failed);
aux = (int)failed;
break;
}
case 'J': {
batch_operation ops[2];
size_t failed;
read_operation(&ops[0]);
read_operation(&ops[1]);
result = batch_apply(ops, 2, &failed);
aux = (int)failed;
break;
}
case 'H': result = (int)batch_fingerprint(); break;
case 'D':
first = number(); length = amount();
result = batch_export(first, output, length, &written);
if (result == 0) count = written;
break;
case 'I':
first = number(); word = next(); length = unhex(word, input, sizeof(input));
result = batch_import(first, input, length);
break;
case 'S':
first = number(); offset = amount(); length = amount(); second = number();
result = batch_slice(first, offset, length, output, (size_t)second, &written);
if (result == 0) count = written;
break;
default: return 3;
}
state(result, aux, output, count, &decoder);
}
return ferror(stdin) ? 2 : 0;
}