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

98 lines
2.6 KiB
C

#include "observer.h"
#include "text.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
static int header(FILE *stream, size_t *count)
{
char *buffer = NULL;
size_t capacity = 0;
unsigned long values[1];
if (text_line(stream, &buffer, &capacity)) { free(buffer); return -1; }
if (text_fields(buffer, values, 1)) { free(buffer); return -1; }
free(buffer);
if (values[0] < 1 || values[0] > 128) return -1;
*count = (size_t)values[0];
return 0;
}
static int job_header(FILE *stream, Job *job)
{
char *buffer = NULL;
size_t capacity = 0;
unsigned long values[5];
if (text_line(stream, &buffer, &capacity)) { free(buffer); return -1; }
if (text_fields(buffer, values, 5)) { free(buffer); return -1; }
free(buffer);
if (values[0] > INT_MAX) return -1;
if (values[1] < 1 || values[1] > UINT16_MAX) return -1;
if (values[2] < 1 || values[2] > 256) return -1;
if (values[3] < 1 || values[3] > values[2]) return -1;
if (values[4] != values[2]) return -1;
job->id = (uint32_t)values[0];
job->mask = (uint16_t)values[1];
job->budget = (unsigned)values[2];
job->hold = (unsigned)values[3];
job->count = (size_t)values[4];
return 0;
}
static int job_frames(FILE *stream, Job *job)
{
char *buffer = NULL;
size_t capacity = 0;
unsigned long values[1];
size_t at;
for (at = 0; at < job->count; ++at) {
if (text_line(stream, &buffer, &capacity)) { free(buffer); return -1; }
if (text_fields(buffer, values, 1)) { free(buffer); return -1; }
if (values[0] > UINT16_MAX) { free(buffer); return -1; }
job->frames[at] = (uint16_t)values[0];
}
free(buffer);
return 0;
}
static int unique_ids(const Job *jobs, size_t count)
{
size_t a;
size_t b;
for (a = 0; a < count; ++a) {
for (b = a + 1; b < count; ++b) {
if (jobs[a].id == jobs[b].id) return -1;
}
}
return 0;
}
int read_jobs(FILE *stream, Job **out_jobs, size_t *out_count)
{
Job *jobs = NULL;
size_t count;
size_t at;
if (out_jobs == NULL || out_count == NULL) return -1;
*out_jobs = NULL;
*out_count = 0;
if (header(stream, &count)) return -1;
jobs = calloc(count, sizeof(*jobs));
if (jobs == NULL) return -1;
for (at = 0; at < count; ++at) {
if (job_header(stream, &jobs[at])) goto fail;
if (job_frames(stream, &jobs[at])) goto fail;
}
if (unique_ids(jobs, count)) goto fail;
if (text_end(stream)) goto fail;
*out_jobs = jobs;
*out_count = count;
return 0;
fail:
free(jobs);
return -1;
}
void free_jobs(Job *jobs)
{
free(jobs);
}