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

90 lines
2.9 KiB
C

#include "stream.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int parse_size(const char *text, size_t *value) {
unsigned long long parsed = 0;
const unsigned char *cursor = (const unsigned char *)text;
if (text == NULL || *text == '\0') return -1;
while (*cursor != '\0') {
unsigned digit;
if (*cursor < '0' || *cursor > '9') return -1;
digit = (unsigned)(*cursor - '0');
if (parsed > (256ull - digit) / 10ull) return -1;
parsed = parsed * 10ull + digit;
++cursor;
}
*value = (size_t)parsed;
return 0;
}
static int parse_arguments(int argc, char **argv, StreamOptions *options,
const char **path, int *json, int *csv) {
int i;
int have_limit = 0;
int have_window = 0;
options->limit = 64;
options->window = 16;
*path = NULL;
*json = 0;
*csv = 0;
for (i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--csv") == 0) {
if (*csv || *json) return -1;
*csv = 1;
} else if (strcmp(argv[i], "--json") == 0) {
if (*json || *csv) return -1;
*json = 1;
} else if (strcmp(argv[i], "--limit") == 0) {
if (have_limit || i + 1 >= argc) return -1;
if (parse_size(argv[++i], &options->limit) != 0) return -1;
have_limit = 1;
} else if (strcmp(argv[i], "--window") == 0) {
if (have_window || i + 1 >= argc) return -1;
if (parse_size(argv[++i], &options->window) != 0) return -1;
have_window = 1;
} else if (argv[i][0] == '-' || *path != NULL) {
return -1;
} else {
*path = argv[i];
}
}
return *path != NULL && stream_options_valid(options) ? 0 : -1;
}
int main(int argc, char **argv) {
StreamOptions options;
StreamResult result;
StreamFileContext context;
StreamPort port;
const char *path;
char line[2048];
int captured;
int used;
int json;
int csv;
if (parse_arguments(argc, argv, &options, &path, &json, &csv) != 0) {
fputs("usage: stream-app [--json|--csv] [--limit 1..256] [--window 1..32] PATH\n", stderr);
return 2;
}
context.path = path;
stream_file_port(&port, &context);
captured = stream_capture(&port, &options, &result);
if (captured != 0) {
fputs("stream capture rejected arguments\n", stderr);
return 2;
}
used = json ? stream_report_json(&result, line, sizeof(line)) :
csv ? stream_report_csv(&result, line, sizeof(line)) :
stream_report_format(&result, line, sizeof(line));
if (used < 0 || fwrite(line, 1, (size_t)used, stdout) != (size_t)used) {
fputs("stream report output failed\n", stderr);
return 2;
}
return result.status == STREAM_OPEN_ERROR ||
result.status == STREAM_READ_ERROR ||
result.status == STREAM_CLOSE_ERROR ? 1 : 0;
}