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

164 lines
4.7 KiB
C

#include "render_api.h"
#include <limits.h>
#include <string.h>
struct input_cursor {
const unsigned char *position;
};
static int horizontal(unsigned char value)
{
return value == ' ' || value == '\t' || value == '\r';
}
static void skip_space(struct input_cursor *cursor)
{
while (horizontal(*cursor->position)) {
cursor->position++;
}
}
static int token(struct input_cursor *cursor, char *output, size_t capacity)
{
size_t length = 0;
skip_space(cursor);
while (*cursor->position != '\0' && *cursor->position != '\n' &&
!horizontal(*cursor->position)) {
if (length + 1 >= capacity) {
return 0;
}
output[length++] = (char)*cursor->position++;
}
output[length] = '\0';
return length != 0;
}
static int decimal(const char *text, int64_t minimum, int64_t maximum, int64_t *result)
{
const unsigned char *cursor = (const unsigned char *)text;
uint64_t magnitude = 0;
uint64_t bound;
int negative = 0;
if (*cursor == '+' || *cursor == '-') {
negative = *cursor == '-';
cursor++;
}
if (*cursor == '\0') {
return 0;
}
bound = negative ? (minimum < 0 ? (uint64_t)(-minimum) : 0) : (uint64_t)maximum;
while (*cursor != '\0') {
unsigned digit;
if (*cursor < '0' || *cursor > '9') {
return 0;
}
digit = *cursor - '0';
if (magnitude > bound / 10 ||
(magnitude == bound / 10 && digit > bound % 10)) {
return 0;
}
magnitude = magnitude * 10 + digit;
cursor++;
}
*result = negative ? -(int64_t)magnitude : (int64_t)magnitude;
return *result >= minimum && *result <= maximum;
}
static int number(struct input_cursor *cursor, int64_t minimum, int64_t maximum,
int64_t *result)
{
char text[1024];
if (!token(cursor, text, sizeof(text))) {
return 0;
}
return decimal(text, minimum, maximum, result);
}
void session_init(struct session *session)
{
session->accepted = 0;
session->rejected = 0;
session->last_sequence = 0;
session->successful = 0;
session->failed = 0;
session->digest = 0;
}
int session_parse(const char *line, struct command *command)
{
struct input_cursor cursor;
char operation[8];
char label[LABEL_LIMIT * 2 + 2];
int64_t value;
struct command parsed;
memset(&parsed, 0, sizeof(parsed));
cursor.position = (const unsigned char *)line;
if (!token(&cursor, operation, sizeof(operation)) || strcmp(operation, "R") != 0) {
return 0;
}
if (!number(&cursor, 1, SESSION_LIMIT, &value)) {
return 0;
}
parsed.sequence = (unsigned)value;
if (!number(&cursor, INT32_MIN, INT32_MAX, &value)) {
return 0;
}
parsed.record.identifier = (int32_t)value;
if (!number(&cursor, 0, 7, &value)) {
return 0;
}
parsed.record.level = (unsigned)value;
if (!number(&cursor, INT32_MIN, INT32_MAX, &value)) {
return 0;
}
parsed.record.value = (int32_t)value;
if (!number(&cursor, 0, TEXT_LIMIT, &value)) {
return 0;
}
parsed.capacity = (size_t)value;
if (!number(&cursor, 0, 1, &value)) {
return 0;
}
parsed.allocation_failure = (int)value;
if (!number(&cursor, 0, 1, &value)) {
return 0;
}
parsed.sink_failure = (int)value;
if (!token(&cursor, label, sizeof(label)) ||
!codec_hex_decode(label, parsed.record.label, &parsed.record.label_length)) {
return 0;
}
skip_space(&cursor);
if (*cursor.position == '\n') {
cursor.position++;
}
if (*cursor.position != '\0') {
return 0;
}
*command = parsed;
return 1;
}
static struct render_result invalid_result(void)
{
struct render_result result;
result.status = RENDER_INVALID;
result.required = 0;
result.emitted = 0;
return result;
}
struct render_result session_apply(struct session *session,
const struct command *command)
{
struct render_result result;
if (command->sequence <= session->last_sequence ||
command->sequence > SESSION_LIMIT) {
session->rejected++;
return invalid_result();
}
session->accepted++;
session->last_sequence = command->sequence;
result = render_record(command);
if (result.status == RENDER_OK) {
char canonical[TEXT_LIMIT];
size_t length = codec_record_write(&command->record, canonical, sizeof(canonical));
session->successful++;
session->digest = codec_digest(session->digest,
(const unsigned char *)canonical, length);
} else {
session->failed++;
}
return result;
}