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>
164 lines
4.6 KiB
C
164 lines
4.6 KiB
C
#include "cli.h"
|
|
#include <stdio.h>
|
|
#include <sys/stat.h>
|
|
#include <string.h>
|
|
|
|
static int same_option(const char *value, const char *wanted)
|
|
{
|
|
return strcmp(value, wanted) == 0;
|
|
}
|
|
|
|
static int is_option(const char *value)
|
|
{
|
|
return value[0] == '-';
|
|
}
|
|
|
|
static int assign_path(const char **slot, const char *value)
|
|
{
|
|
if (*slot != NULL) return -1;
|
|
if (value == NULL || value[0] == '\0') return -1;
|
|
if (is_option(value)) return -1;
|
|
*slot = value;
|
|
return 0;
|
|
}
|
|
|
|
static int alias(const char *left, const char *right)
|
|
{
|
|
struct stat a;
|
|
struct stat b;
|
|
int first;
|
|
int second;
|
|
if (left == NULL || right == NULL) return 0;
|
|
first = stat(left, &a);
|
|
second = stat(right, &b);
|
|
if (first != 0 || second != 0) return 0;
|
|
if (a.st_dev == b.st_dev && a.st_ino == b.st_ino) return 1;
|
|
return 0;
|
|
}
|
|
|
|
static int parse(Cli *cli, int argc, char **argv,
|
|
const char **input_path, const char **output_path, const char **trace_path)
|
|
{
|
|
int at;
|
|
for (at = 1; at < argc; ++at) {
|
|
const char *arg = argv[at];
|
|
if (same_option(arg, "--input")) {
|
|
if (++at >= argc || assign_path(input_path, argv[at])) return -1;
|
|
continue;
|
|
}
|
|
if (same_option(arg, "--output")) {
|
|
if (++at >= argc || assign_path(output_path, argv[at])) return -1;
|
|
continue;
|
|
}
|
|
if (same_option(arg, "--trace")) {
|
|
if (++at >= argc || assign_path(trace_path, argv[at])) return -1;
|
|
continue;
|
|
}
|
|
if (same_option(arg, "--json")) {
|
|
if (cli->json) return -1;
|
|
cli->json = 1;
|
|
continue;
|
|
}
|
|
if (same_option(arg, "--summary")) {
|
|
if (cli->summary) return -1;
|
|
cli->summary = 1;
|
|
continue;
|
|
}
|
|
if (same_option(arg, "--validate-only")) {
|
|
if (cli->validate_only) return -1;
|
|
cli->validate_only = 1;
|
|
continue;
|
|
}
|
|
return -1;
|
|
}
|
|
if (cli->summary && cli->validate_only) return -1;
|
|
if (cli->json && cli->validate_only) return -1;
|
|
if (cli->validate_only && (*output_path != NULL || *trace_path != NULL)) return -1;
|
|
if (*input_path && *output_path && strcmp(*input_path, *output_path) == 0) return -1;
|
|
if (*trace_path && *input_path && strcmp(*trace_path, *input_path) == 0) return -1;
|
|
if (*trace_path && *output_path && strcmp(*trace_path, *output_path) == 0) return -1;
|
|
if (alias(*input_path, *output_path)) return -1;
|
|
if (alias(*input_path, *trace_path)) return -1;
|
|
if (alias(*output_path, *trace_path)) return -1;
|
|
return 0;
|
|
}
|
|
|
|
static int open_input(Cli *cli, const char *path)
|
|
{
|
|
if (path == NULL) return 0;
|
|
cli->input = fopen(path, "rb");
|
|
if (cli->input == NULL) return -1;
|
|
cli->owns_input = 1;
|
|
return 0;
|
|
}
|
|
|
|
static int open_trace(Cli *cli, const char *path)
|
|
{
|
|
if (path == NULL) return 0;
|
|
cli->trace = fopen(path, "wb");
|
|
if (cli->trace == NULL) return -1;
|
|
cli->owns_trace = 1;
|
|
return 0;
|
|
}
|
|
|
|
static int open_output(Cli *cli, const char *path)
|
|
{
|
|
if (path == NULL) return 0;
|
|
cli->output = fopen(path, "wb");
|
|
if (cli->output == NULL) return -1;
|
|
cli->owns_output = 1;
|
|
return 0;
|
|
}
|
|
|
|
int cli_open(Cli *cli, int argc, char **argv)
|
|
{
|
|
const char *input_path = NULL;
|
|
const char *output_path = NULL;
|
|
const char *trace_path = NULL;
|
|
memset(cli, 0, sizeof(*cli));
|
|
cli->input = stdin;
|
|
cli->output = stdout;
|
|
if (parse(cli, argc, argv, &input_path, &output_path, &trace_path)) return -1;
|
|
if (open_input(cli, input_path)) return -1;
|
|
if (open_output(cli, output_path)) {
|
|
if (cli->owns_input) {
|
|
fclose(cli->input);
|
|
cli->input = stdin;
|
|
cli->owns_input = 0;
|
|
}
|
|
return -1;
|
|
}
|
|
if (open_trace(cli, trace_path)) {
|
|
cli_close(cli);
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int cli_close(Cli *cli)
|
|
{
|
|
int failed = 0;
|
|
if (cli->owns_trace) {
|
|
if (fclose(cli->trace)) failed = 1;
|
|
cli->trace = NULL;
|
|
cli->owns_trace = 0;
|
|
}
|
|
if (cli->owns_input) {
|
|
if (fclose(cli->input)) failed = 1;
|
|
cli->input = stdin;
|
|
cli->owns_input = 0;
|
|
}
|
|
if (cli->owns_output) {
|
|
if (fclose(cli->output)) failed = 1;
|
|
cli->output = stdout;
|
|
cli->owns_output = 0;
|
|
} else if (fflush(cli->output)) failed = 1;
|
|
return failed ? -1 : 0;
|
|
}
|
|
|
|
void cli_usage(FILE *stream)
|
|
{
|
|
fputs("usage: ready_replay [--input FILE] [--output FILE] [--summary] [--json] [--trace FILE]\n", stream);
|
|
fputs(" ready_replay [--input FILE] --validate-only\n", stream);
|
|
}
|