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

56 lines
2.1 KiB
C

#include "command_port.h"
#include <string.h>
enum phase { ACQUIRE, RECEIVE, CLOSE_STREAM, WAIT_CHILD, COMPLETE };
int command_collect(struct command_port *port, const struct command_request *request, struct command_result *result)
{
enum phase phase = ACQUIRE;
unsigned token = 0;
int failed = 0;
unsigned char byte;
if (result == NULL) return COMMAND_INVALID;
*result = (struct command_result){.status=COMMAND_INVALID,.checksum=UINT32_C(2166136261)};
if (port == NULL || request == NULL || request->capture_limit > COMMAND_MAX_BYTES) return COMMAND_INVALID;
while (phase != COMPLETE) {
switch (phase) {
case ACQUIRE:
if (command_port_open(port, request->tag, &token)) {
result->status = COMMAND_OPEN_ERROR;
phase = COMPLETE;
} else phase = RECEIVE;
break;
case RECEIVE: {
long count = command_port_read(port, token, &byte, 1);
if (count == PORT_INTERRUPTED) break;
if (count <= 0) {
failed = count < 0;
phase = CLOSE_STREAM;
break;
}
result->checksum = (result->checksum ^ byte) * UINT32_C(16777619);
result->bytes_seen++;
if (result->bytes_stored < request->capture_limit) {
result->capture[result->bytes_stored++] = byte;
}
result->truncated = result->bytes_seen != result->bytes_stored;
break;
}
case CLOSE_STREAM:
if (command_port_close(port, token)) failed = 1;
phase = WAIT_CHILD;
break;
case WAIT_CHILD: {
int status = command_port_wait(port, token, &result->child_exit, &result->child_signal);
if (status == PORT_INTERRUPTED) break;
if (status != 0) failed = 1;
result->status = failed ? COMMAND_READ_ERROR :
(result->child_exit || result->child_signal ? COMMAND_CHILD_ERROR : COMMAND_OK);
phase = COMPLETE;
break;
}
case COMPLETE:
break;
}
}
return result->status;
}