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>
156 lines
4.2 KiB
C
156 lines
4.2 KiB
C
#include "scan.h"
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <inttypes.h>
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static int words(char *line, char **tokens, int maximum)
|
|
{
|
|
int count = 0;
|
|
char *at = line;
|
|
while (*at != '\0') {
|
|
while (isspace((unsigned char)*at)) {
|
|
at++;
|
|
}
|
|
if (*at == '\0' || *at == '#') {
|
|
break;
|
|
}
|
|
if (count == maximum) {
|
|
return -1;
|
|
}
|
|
tokens[count++] = at;
|
|
while (*at != '\0' && !isspace((unsigned char)*at)) {
|
|
at++;
|
|
}
|
|
if (*at != '\0') {
|
|
*at++ = '\0';
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static int integer(const char *text, int *value)
|
|
{
|
|
if (*text == '\0') {
|
|
return 0;
|
|
}
|
|
errno = 0;
|
|
char *end = NULL;
|
|
long parsed = strtol(text, &end, 10);
|
|
if (errno != 0 || *end != '\0' || parsed < INT_MIN || parsed > INT_MAX) {
|
|
return 0;
|
|
}
|
|
*value = (int)parsed;
|
|
return 1;
|
|
}
|
|
|
|
static int numbers(char **tokens, int count, int *values)
|
|
{
|
|
for (int index = 0; index < count; index++) {
|
|
if (!integer(tokens[index], &values[index])) {
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void result_dump(int status, const ScanResult *result)
|
|
{
|
|
printf("S %d %d %d %" PRIu64 "\n", status, result->visited,
|
|
result->found, result->digest);
|
|
for (int address = 3; address <= 119; address++) {
|
|
if (result->seen[address]) {
|
|
printf("D %d %d\n", address, result->values[address]);
|
|
}
|
|
}
|
|
}
|
|
|
|
static int command(Scanner *scanner, Port *port, char **tokens, int count)
|
|
{
|
|
int args[6];
|
|
const char *op = tokens[0];
|
|
if (count > 7 || !numbers(tokens + 1, count - 1, args)) {
|
|
return 0;
|
|
}
|
|
if (strcmp(op, "R") == 0 && count == 3) {
|
|
if (args[0] < 1 || args[0] > HANDLE_COUNT || args[1] < 0 || args[1] > 65535) {
|
|
printf("R %d\n", ERR_INVALID);
|
|
} else {
|
|
scanner_finish(scanner);
|
|
int status = port_init(port, args[0], (unsigned)args[1]);
|
|
scanner_init(scanner, port);
|
|
printf("R %d\n", status);
|
|
}
|
|
} else if (strcmp(op, "D") == 0 && count == 4) {
|
|
printf("R %d\n", port_device(port, args[0], args[1], args[2]));
|
|
} else if (strcmp(op, "F") == 0 && count == 5) {
|
|
printf("R %d\n", port_fault(port, args[0], args[1], args[2], args[3]));
|
|
} else if (strcmp(op, "S") == 0 && count == 6) {
|
|
ScanResult result;
|
|
int status = scanner_run(scanner, args[0], args[1], args[2],
|
|
args[3], args[4], &result);
|
|
result_dump(status, &result);
|
|
} else if (strcmp(op, "X") == 0 && count == 2) {
|
|
printf("R %d\n", scanner_close(scanner, args[0]));
|
|
} else if (strcmp(op, "Q") == 0 && count == 1) {
|
|
scanner_dump(scanner, stdout);
|
|
port_dump(port, stdout);
|
|
} else if (strcmp(op, "Z") == 0 && count == 1) {
|
|
scanner_finish(scanner);
|
|
printf("R 0\n");
|
|
} else {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void demo(Scanner *scanner)
|
|
{
|
|
for (int sweep = 0; sweep < 24; sweep++) {
|
|
ScanResult result;
|
|
int status = scanner_run(scanner, 0, 0, 3, 119, 0, &result);
|
|
result_dump(status, &result);
|
|
}
|
|
scanner_dump(scanner, stdout);
|
|
port_dump(scanner->port, stdout);
|
|
scanner_finish(scanner);
|
|
port_dump(scanner->port, stdout);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
Port port;
|
|
Scanner scanner;
|
|
port_init(&port, 8, 1);
|
|
scanner_init(&scanner, &port);
|
|
if (argc == 2 && strcmp(argv[1], "--demo") == 0) {
|
|
demo(&scanner);
|
|
return 0;
|
|
}
|
|
if (argc != 1) {
|
|
return 2;
|
|
}
|
|
char line[1024];
|
|
char *tokens[8];
|
|
int status = 0;
|
|
while (fgets(line, sizeof(line), stdin) != NULL) {
|
|
size_t size = strlen(line);
|
|
if (size == sizeof(line) - 1 && line[size - 1] != '\n') {
|
|
status = 2;
|
|
break;
|
|
}
|
|
int count = words(line, tokens, 8);
|
|
if (count < 0 || (count > 0 && !command(&scanner, &port, tokens, count))) {
|
|
status = 2;
|
|
break;
|
|
}
|
|
}
|
|
if (ferror(stdin)) {
|
|
status = 2;
|
|
}
|
|
scanner_finish(&scanner);
|
|
return status;
|
|
}
|