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

363 lines
11 KiB
C

#include "rb.h"
#include <inttypes.h>
#include <limits.h>
#include <string.h>
static void put_decimal(FILE *output, uint64_t value)
{
fprintf(output, "%" PRIu64, value);
}
static void put_signed(FILE *output, int value)
{
fprintf(output, "%d", value);
}
static void put_hex(FILE *output, const unsigned char *bytes, size_t length)
{
static const char digits[] = "0123456789abcdef";
size_t index;
for (index = 0; index < length; ++index) {
fputc(digits[bytes[index] >> 4], output);
fputc(digits[bytes[index] & 15u], output);
}
}
static int field_size(uint64_t input, size_t maximum, size_t *output)
{
if (input > maximum) return RB_BAD_ARGUMENT;
*output = (size_t)input;
return RB_OK;
}
static int emit_open(FILE *output, rb_batch *batch, rb_allocator allocator,
const uint64_t fields[4])
{
size_t count;
size_t width;
int result;
if (field_size(fields[0], RB_LIMIT, &count) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &width) != RB_OK ||
fields[2] > UINT32_MAX) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_open(batch, allocator, count, width,
(uint32_t)fields[2]);
}
fputs("OPEN ", output);
put_signed(output, result);
fputc(' ', output);
put_decimal(output, rb_obtained(batch));
fputc(' ', output);
put_decimal(output, batch->count);
fputc(' ', output);
put_decimal(output, batch->width);
fputc('\n', output);
return result;
}
static int emit_put(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t index;
size_t offset;
unsigned char byte;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
fields[2] > 255u) {
result = RB_BAD_ARGUMENT;
} else {
byte = (unsigned char)fields[2];
result = rb_put(batch, index, offset, &byte, 1);
}
fputs("PUT ", output);
put_signed(output, result);
fputc(' ', output);
put_decimal(output, batch->writes);
fputc('\n', output);
return result;
}
static int emit_copy(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t from;
size_t to;
size_t offset;
size_t length;
int result;
if (field_size(fields[0], RB_LIMIT, &from) != RB_OK ||
field_size(fields[1], RB_LIMIT, &to) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[3], RB_MAX_WIDTH, &length) != RB_OK) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_copy(batch, from, to, offset, length);
}
fputs("COPY ", output);
put_signed(output, result);
fputc(' ', output);
put_decimal(output, batch->copies);
fputc('\n', output);
return result;
}
static int emit_get(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
unsigned char bytes[RB_MAX_WIDTH];
size_t index;
size_t offset;
size_t length;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &length) != RB_OK) {
result = RB_BAD_ARGUMENT;
length = 0;
} else {
result = rb_get(batch, index, offset, bytes, length);
}
fputs("GET ", output);
put_signed(output, result);
fputc(' ', output);
if (result == RB_OK && length != 0) put_hex(output, bytes, length);
else fputc('-', output);
fputc('\n', output);
return result;
}
static int emit_hash(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
uint32_t hash = 0;
size_t index;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK)
result = RB_BAD_ARGUMENT;
else
result = rb_digest(batch, index, &hash);
fputs("HASH ", output);
put_signed(output, result);
fputc(' ', output);
if (result == RB_OK) put_decimal(output, hash);
else fputc('-', output);
fputc('\n', output);
return result;
}
static int emit_fill(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t index;
size_t offset;
size_t length;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &length) != RB_OK ||
fields[3] > 255u) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_fill(batch, index, offset, length,
(unsigned char)fields[3]);
}
fputs("FILL ", output);
put_signed(output, result);
fputc(' ', output);
put_decimal(output, batch->writes);
fputc('\n', output);
return result;
}
static int emit_xor(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t index;
size_t offset;
size_t length;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &length) != RB_OK ||
fields[3] > 255u) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_xor(batch, index, offset, length,
(unsigned char)fields[3]);
}
fputs("XOR ", output);
put_signed(output, result);
fputc(' ', output);
put_decimal(output, batch->writes);
fputc('\n', output);
return result;
}
static int emit_equal(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t left;
size_t right;
size_t offset;
size_t length;
int result;
int equal = 0;
if (field_size(fields[0], RB_LIMIT, &left) != RB_OK ||
field_size(fields[1], RB_LIMIT, &right) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[3], RB_MAX_WIDTH, &length) != RB_OK) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_equal(batch, left, right, offset, length, &equal);
}
fputs("EQUAL ", output);
put_signed(output, result);
fputc(' ', output);
if (result == RB_OK) put_decimal(output, (uint64_t)equal);
else fputc('-', output);
fputc('\n', output);
return result;
}
static int emit_find(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t index;
size_t offset;
size_t length;
size_t found = 0;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &length) != RB_OK ||
fields[3] > 255u) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_find(batch, index, offset, length,
(unsigned char)fields[3], &found);
}
fputs("FIND ", output);
put_signed(output, result);
fputc(' ', output);
if (result == RB_OK && found < batch->width) put_decimal(output, found);
else fputc('-', output);
fputc('\n', output);
return result;
}
static int emit_count(FILE *output, rb_batch *batch,
const uint64_t fields[4])
{
size_t index;
size_t offset;
size_t length;
size_t matches = 0;
int result;
if (field_size(fields[0], RB_LIMIT, &index) != RB_OK ||
field_size(fields[1], RB_MAX_WIDTH, &offset) != RB_OK ||
field_size(fields[2], RB_MAX_WIDTH, &length) != RB_OK ||
fields[3] > 255u) {
result = RB_BAD_ARGUMENT;
} else {
result = rb_count_byte(batch, index, offset, length,
(unsigned char)fields[3], &matches);
}
fputs("COUNT ", output);
put_signed(output, result);
fputc(' ', output);
if (result == RB_OK) put_decimal(output, matches);
else fputc('-', output);
fputc('\n', output);
return result;
}
static void emit_stats(FILE *output, const rb_batch *batch)
{
fputs("STATS ", output);
put_decimal(output, batch->count);
fputc(' ', output);
put_decimal(output, batch->width);
fputc(' ', output);
put_decimal(output, rb_obtained(batch));
fputc(' ', output);
put_decimal(output, batch->writes);
fputc(' ', output);
put_decimal(output, batch->copies);
fputc('\n', output);
}
static int handle(FILE *output, rb_batch *batch, rb_allocator allocator,
char verb, const uint64_t fields[4])
{
if (verb == 'O') return emit_open(output, batch, allocator, fields);
if (verb == 'P') return emit_put(output, batch, fields);
if (verb == 'C') return emit_copy(output, batch, fields);
if (verb == 'G') return emit_get(output, batch, fields);
if (verb == 'H') return emit_hash(output, batch, fields);
if (verb == 'F') return emit_fill(output, batch, fields);
if (verb == 'R') return emit_xor(output, batch, fields);
if (verb == 'E') return emit_equal(output, batch, fields);
if (verb == 'N') return emit_find(output, batch, fields);
if (verb == 'T') return emit_count(output, batch, fields);
if (verb == 'S') {
emit_stats(output, batch);
return RB_OK;
}
if (verb == 'X') {
rb_close(batch);
fputs("CLOSE 0\n", output);
return RB_OK;
}
return RB_BAD_ARGUMENT;
}
static int process_line(FILE *output, rb_batch *batch, rb_allocator allocator,
const char *line, size_t length, int overlong)
{
char verb = 0;
uint64_t fields[4] = {0, 0, 0, 0};
size_t field_count = 0;
if (overlong || rb_parse_line(line, length, &verb, fields,
&field_count) != RB_OK) {
fputs("ERROR -1\n", output);
return 0;
}
if (verb == 'Q') {
rb_close(batch);
fputs("QUIT 0\n", output);
return 1;
}
handle(output, batch, allocator, verb, fields);
return 0;
}
int rb_run(FILE *input, FILE *output, rb_allocator allocator)
{
char line[512];
rb_batch batch = {0};
size_t length = 0;
int overlong = 0;
int character;
if (input == NULL || output == NULL || allocator.take == NULL ||
allocator.give == NULL) return RB_BAD_ARGUMENT;
while ((character = fgetc(input)) != EOF) {
if (character == '\n') {
if (length == 511) overlong = 1;
if (process_line(output, &batch, allocator, line, length,
overlong)) break;
length = 0;
overlong = 0;
} else if (length < 511) {
line[length++] = (char)character;
} else {
overlong = 1;
}
}
if (character == EOF && (length != 0 || overlong))
process_line(output, &batch, allocator, line, length, overlong);
rb_close(&batch);
return ferror(input) || ferror(output) ? RB_BAD_ARGUMENT : RB_OK;
}