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>
145 lines
3.4 KiB
C
145 lines
3.4 KiB
C
#include "config.h"
|
|
#include <string.h>
|
|
static int horizontal(unsigned char c)
|
|
{
|
|
return c == ' ' || c == '\t' || c == '\r';
|
|
}
|
|
static char *trim_left(char *text)
|
|
{
|
|
while (horizontal((unsigned char)*text)) {
|
|
++text;
|
|
}
|
|
return text;
|
|
}
|
|
static void trim_right(char *text)
|
|
{
|
|
size_t length = strlen(text);
|
|
while (length > 0 && horizontal((unsigned char)text[length - 1])) {
|
|
text[--length] = 0;
|
|
}
|
|
}
|
|
static int read_line(FILE *stream, char *line, size_t capacity, unsigned long *bytes)
|
|
{
|
|
size_t used = 0;
|
|
int c;
|
|
int invalid = 0;
|
|
while ((c = fgetc(stream)) != EOF) {
|
|
++*bytes;
|
|
if (c == '\n') {
|
|
break;
|
|
}
|
|
if (c == 0 || c > 126 || (c < 32 && c != '\t' && c != '\r')) {
|
|
invalid = 1;
|
|
}
|
|
if (used + 1 < capacity) {
|
|
line[used++] = (char)c;
|
|
} else {
|
|
invalid = 1;
|
|
}
|
|
}
|
|
line[used] = 0;
|
|
if (ferror(stream)) {
|
|
return -1;
|
|
}
|
|
if (c == EOF && used == 0 && !invalid) {
|
|
return 0;
|
|
}
|
|
return invalid ? -1 : 1;
|
|
}
|
|
static int section_line(char *text, char *section)
|
|
{
|
|
char *end = strchr(text + 1, ']');
|
|
char *name;
|
|
if (end == NULL) {
|
|
return -1;
|
|
}
|
|
*end = 0;
|
|
if (*trim_left(end + 1) != 0) {
|
|
return -1;
|
|
}
|
|
name = trim_left(text + 1);
|
|
trim_right(name);
|
|
if (!cfg_name_valid(name)) {
|
|
return -1;
|
|
}
|
|
strcpy(section, name);
|
|
return 0;
|
|
}
|
|
static int delete_line(char *text, const char *section, cfg_table *table)
|
|
{
|
|
char *key = trim_left(text + 1);
|
|
trim_right(key);
|
|
if (!cfg_name_valid(key)) {
|
|
return -1;
|
|
}
|
|
return cfg_delete(table, section, key);
|
|
}
|
|
static int assign_line(char *text, const char *section, cfg_table *table)
|
|
{
|
|
char *separator = strchr(text, '=');
|
|
char *key;
|
|
char *value;
|
|
if (separator == NULL) {
|
|
return -1;
|
|
}
|
|
*separator = 0;
|
|
key = trim_left(text);
|
|
trim_right(key);
|
|
value = trim_left(separator + 1);
|
|
trim_right(value);
|
|
if (!cfg_name_valid(key) || !cfg_value_valid(value)) {
|
|
return -1;
|
|
}
|
|
return cfg_set(table, section, key, value);
|
|
}
|
|
static int apply_line(char *line, char *section, cfg_table *table, cfg_parse_report *report)
|
|
{
|
|
char *text = trim_left(line);
|
|
trim_right(text);
|
|
if (*text == 0 || *text == '#') {
|
|
return 0;
|
|
}
|
|
if (*text == '[') {
|
|
return section_line(text, section);
|
|
}
|
|
if (*text == '!') {
|
|
if (delete_line(text, section, table) != 0) {
|
|
return -1;
|
|
}
|
|
++report->deletions;
|
|
return 0;
|
|
}
|
|
if (assign_line(text, section, table) != 0) {
|
|
return -1;
|
|
}
|
|
++report->assignments;
|
|
return 0;
|
|
}
|
|
int cfg_parse(FILE *stream, cfg_table *table, cfg_parse_report *report)
|
|
{
|
|
char section[CFG_NAME] = "global";
|
|
char line[CFG_LINE];
|
|
unsigned long number = 0;
|
|
int state;
|
|
int valid = 1;
|
|
memset(report, 0, sizeof(*report));
|
|
while ((state = read_line(stream, line, sizeof(line), &report->bytes)) != 0) {
|
|
++number;
|
|
if (state < 0) {
|
|
valid = 0;
|
|
if (report->error_line == 0) {
|
|
report->error_line = number;
|
|
}
|
|
if (ferror(stream)) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (valid && apply_line(line, section, table, report) != 0) {
|
|
valid = 0;
|
|
report->error_line = number;
|
|
}
|
|
}
|
|
return valid ? 0 : -1;
|
|
}
|