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>
178 lines
4.6 KiB
C
178 lines
4.6 KiB
C
#include "parser.h"
|
|
#include <string.h>
|
|
|
|
void rp_builder_init(struct rp_builder *builder)
|
|
{
|
|
size_t i;
|
|
memset(builder, 0, sizeof(*builder));
|
|
builder->model.rate = 1;
|
|
for (i = 0; i < RP_SENSORS; ++i) {
|
|
builder->model.sensors[i].gain = 1;
|
|
builder->model.sensors[i].kind = 'T';
|
|
}
|
|
}
|
|
|
|
static int set_site(struct rp_builder *builder, const struct rp_tokens *tokens)
|
|
{
|
|
if (builder->saw_site || builder->saw_rate || builder->model.count != 0) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (!rp_keyword(tokens, "SITE", 2) || !rp_name(tokens->words[1])) {
|
|
return RP_FORMAT;
|
|
}
|
|
strcpy(builder->model.site, tokens->words[1]);
|
|
builder->saw_site = 1;
|
|
return RP_OK;
|
|
}
|
|
|
|
static int set_rate(struct rp_builder *builder, const struct rp_tokens *tokens)
|
|
{
|
|
int rate;
|
|
if (!builder->saw_site || builder->saw_rate || builder->model.count != 0) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (!rp_keyword(tokens, "RATE", 2)) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (rp_number(tokens->words[1], 1, 1000, &rate) != RP_OK) {
|
|
return RP_FORMAT;
|
|
}
|
|
builder->model.rate = rate;
|
|
builder->saw_rate = 1;
|
|
return RP_OK;
|
|
}
|
|
|
|
static struct rp_sensor *find_sensor(struct rp_builder *builder, int id)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < builder->model.count; ++i) {
|
|
if (builder->model.sensors[i].id == id) {
|
|
return &builder->model.sensors[i];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static int parse_sensor(const struct rp_tokens *tokens, struct rp_sensor *sensor)
|
|
{
|
|
int status;
|
|
if (!rp_keyword(tokens, "SENSOR", 5)) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (strlen(tokens->words[2]) != 1) {
|
|
return RP_FORMAT;
|
|
}
|
|
sensor->kind = tokens->words[2][0];
|
|
if (sensor->kind != 'T' && sensor->kind != 'V' && sensor->kind != 'I') {
|
|
return RP_FORMAT;
|
|
}
|
|
status = rp_number(tokens->words[1], 0, 31, &sensor->id);
|
|
if (status != RP_OK) {
|
|
return status;
|
|
}
|
|
status = rp_number(tokens->words[3], 1, 1000, &sensor->gain);
|
|
if (status != RP_OK) {
|
|
return status;
|
|
}
|
|
status = rp_number(tokens->words[4], -100000, 100000, &sensor->bias);
|
|
if (status != RP_OK) {
|
|
return status;
|
|
}
|
|
sensor->has_limit = 0;
|
|
sensor->low = 0;
|
|
sensor->high = 0;
|
|
return RP_OK;
|
|
}
|
|
|
|
static int add_sensor(struct rp_builder *builder, const struct rp_tokens *tokens)
|
|
{
|
|
struct rp_sensor sensor;
|
|
int status;
|
|
if (!builder->saw_site) {
|
|
return RP_FORMAT;
|
|
}
|
|
memset(&sensor, 0, sizeof(sensor));
|
|
status = parse_sensor(tokens, &sensor);
|
|
if (status != RP_OK) {
|
|
return status;
|
|
}
|
|
if (find_sensor(builder, sensor.id) != NULL) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (builder->model.count == RP_SENSORS) {
|
|
return RP_CAPACITY;
|
|
}
|
|
builder->model.sensors[builder->model.count] = sensor;
|
|
builder->model.count += 1;
|
|
return RP_OK;
|
|
}
|
|
|
|
static int set_limit(struct rp_builder *builder, const struct rp_tokens *tokens)
|
|
{
|
|
int id;
|
|
int low;
|
|
int high;
|
|
struct rp_sensor *sensor;
|
|
if (!rp_keyword(tokens, "LIMIT", 4)) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (rp_number(tokens->words[1], 0, 31, &id) != RP_OK) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (rp_number(tokens->words[2], -100000, 100000, &low) != RP_OK) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (rp_number(tokens->words[3], -100000, 100000, &high) != RP_OK) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (low > high) {
|
|
return RP_FORMAT;
|
|
}
|
|
sensor = find_sensor(builder, id);
|
|
if (sensor == NULL || sensor->has_limit) {
|
|
return RP_FORMAT;
|
|
}
|
|
sensor->has_limit = 1;
|
|
sensor->low = low;
|
|
sensor->high = high;
|
|
return RP_OK;
|
|
}
|
|
|
|
int rp_builder_line(struct rp_builder *builder, const struct rp_tokens *tokens)
|
|
{
|
|
if (tokens->count == 0) {
|
|
return RP_OK;
|
|
}
|
|
if (builder->ended) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (strcmp(tokens->words[0], "SITE") == 0) {
|
|
return set_site(builder, tokens);
|
|
}
|
|
if (strcmp(tokens->words[0], "RATE") == 0) {
|
|
return set_rate(builder, tokens);
|
|
}
|
|
if (strcmp(tokens->words[0], "SENSOR") == 0) {
|
|
return add_sensor(builder, tokens);
|
|
}
|
|
if (strcmp(tokens->words[0], "LIMIT") == 0) {
|
|
return set_limit(builder, tokens);
|
|
}
|
|
if (rp_keyword(tokens, "END", 1)) {
|
|
if (!builder->saw_site || builder->model.count == 0) {
|
|
return RP_FORMAT;
|
|
}
|
|
builder->ended = 1;
|
|
return RP_OK;
|
|
}
|
|
return RP_FORMAT;
|
|
}
|
|
|
|
int rp_builder_done(const struct rp_builder *builder)
|
|
{
|
|
if (!builder->saw_site || !builder->ended || builder->model.count == 0) {
|
|
return RP_FORMAT;
|
|
}
|
|
return RP_OK;
|
|
}
|