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

192 lines
5.4 KiB
C

#include "pin.h"
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#define LINE_CAPACITY 4096
#define TOKEN_CAPACITY 128
struct token {
const unsigned char *start;
size_t length;
};
static int space(unsigned char value)
{
return value == ' ' || value == '\t' || value == '\r' || value == '\n';
}
static int tokenize(const unsigned char *line, size_t length,
struct token *tokens, size_t *count)
{
size_t offset = 0;
size_t used = 0;
while (offset < length) {
size_t begin;
while (offset < length && space(line[offset])) {
++offset;
}
if (offset == length) {
break;
}
if (used == TOKEN_CAPACITY) {
return -1;
}
begin = offset;
while (offset < length && !space(line[offset])) {
if (line[offset] < 33 || line[offset] > 126) {
return -1;
}
++offset;
}
tokens[used].start = line + begin;
tokens[used].length = offset - begin;
++used;
}
*count = used;
return 0;
}
static int number(const struct token *token, unsigned maximum, unsigned *value)
{
unsigned result = 0;
size_t index;
if (token->length == 0) {
return -1;
}
for (index = 0; index < token->length; ++index) {
unsigned char byte = token->start[index];
unsigned digit;
if (byte < '0' || byte > '9') {
return -1;
}
digit = (unsigned)(byte - '0');
if (result > maximum / 10 ||
(result == maximum / 10 && digit > maximum % 10)) {
return -1;
}
result = result * 10 + digit;
}
*value = result;
return 0;
}
static int parse(const unsigned char *line, size_t length, unsigned *budget,
size_t *count, struct pin_request *requests)
{
struct token tokens[TOKEN_CAPACITY];
unsigned size;
unsigned occupied[PIN_CAPACITY] = {0};
size_t used;
size_t index;
static const unsigned limits[7] = {31, 1, 8, 8, 8, 8, 4};
if (tokenize(line, length, tokens, &used) != 0 || used < 3) {
return -1;
}
if (tokens[0].length != 1 || tokens[0].start[0] != 'B') {
return -1;
}
if (number(&tokens[1], 8, budget) != 0 || *budget == 0 ||
number(&tokens[2], PIN_MAX_BATCH, &size) != 0) {
return -1;
}
if (used != 3 + (size_t)size * 7) {
return -1;
}
for (index = 0; index < size; ++index) {
unsigned values[7];
size_t field;
for (field = 0; field < 7; ++field) {
if (number(&tokens[3 + index * 7 + field], limits[field],
&values[field]) != 0) {
return -1;
}
}
if (occupied[values[0]]) {
return -1;
}
occupied[values[0]] = 1;
requests[index].pin = values[0];
requests[index].value = values[1];
requests[index].ready_delay = values[2];
requests[index].export_busy = values[3];
requests[index].direction_busy = values[4];
requests[index].value_busy = values[5];
requests[index].fatal_stage = values[6];
}
*count = size;
return 0;
}
static int execute(unsigned sequence, const unsigned char *line, size_t length)
{
struct pin_request requests[PIN_MAX_BATCH];
struct pin_result results[PIN_MAX_BATCH];
struct pin_bus *bus;
unsigned budget;
size_t count;
size_t index;
unsigned completed = 0;
unsigned failed = 0;
int rc;
if (parse(line, length, &budget, &count, requests) != 0) {
printf("REJECT %u\n", sequence);
return 0;
}
bus = pin_bus_create();
if (bus == NULL) {
return -1;
}
if (pin_bus_configure(bus, requests, count) != 0) {
pin_bus_destroy(bus);
return -1;
}
memset(results, 0, sizeof(results));
rc = pin_bringup(bus, requests, count, budget, results);
for (index = 0; index < count; ++index) {
if (results[index].rc == 0) {
++completed;
} else {
++failed;
}
}
printf("R %u %d %u %u\n", sequence, rc, completed, failed);
for (index = 0; index < count; ++index) {
struct pin_observation observation;
if (pin_observe(bus, requests[index].pin, &observation) != 0) {
pin_bus_destroy(bus);
return -1;
}
pin_print_observation(stdout, sequence, requests[index].pin,
&results[index], &observation);
}
pin_bus_destroy(bus);
return 0;
}
int main(void)
{
unsigned char line[LINE_CAPACITY];
size_t length = 0;
unsigned sequence = 0;
int overflow = 0;
int byte;
while ((byte = getchar()) != EOF) {
if (byte == '\n') {
++sequence;
if (overflow) {
printf("REJECT %u\n", sequence);
} else if (execute(sequence, line, length) != 0) {
return 2;
}
length = 0;
overflow = 0;
} else if (length < sizeof(line)) {
line[length++] = (unsigned char)byte;
} else {
overflow = 1;
}
}
if (length != 0 || overflow) {
++sequence;
if (overflow) {
printf("REJECT %u\n", sequence);
} else if (execute(sequence, line, length) != 0) {
return 2;
}
}
return ferror(stdin) ? 2 : 0;
}