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>
131 lines
3.2 KiB
C
131 lines
3.2 KiB
C
#include "parser.h"
|
|
#include <string.h>
|
|
|
|
static int horizontal(unsigned char ch)
|
|
{
|
|
return ch == ' ' || ch == '\t' || ch == '\r';
|
|
}
|
|
|
|
static int legal_byte(unsigned char ch)
|
|
{
|
|
return ch >= 33 && ch <= 126;
|
|
}
|
|
|
|
static int add_character(struct rp_tokens *tokens, size_t index,
|
|
size_t *length, unsigned char ch)
|
|
{
|
|
if (*length >= RP_LINE) {
|
|
return RP_FORMAT;
|
|
}
|
|
tokens->words[index][*length] = (char)ch;
|
|
*length += 1;
|
|
tokens->words[index][*length] = '\0';
|
|
return RP_OK;
|
|
}
|
|
|
|
static void clear_tokens(struct rp_tokens *tokens)
|
|
{
|
|
size_t word;
|
|
size_t ch;
|
|
tokens->count = 0;
|
|
for (word = 0; word < 6; ++word) {
|
|
for (ch = 0; ch <= RP_LINE; ++ch) {
|
|
tokens->words[word][ch] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
int rp_tokenize(const char *line, struct rp_tokens *tokens)
|
|
{
|
|
const unsigned char *cursor = (const unsigned char *)line;
|
|
clear_tokens(tokens);
|
|
while (horizontal(*cursor)) {
|
|
++cursor;
|
|
}
|
|
if (*cursor == '#' || *cursor == '\0') {
|
|
return RP_OK;
|
|
}
|
|
while (*cursor != '\0') {
|
|
size_t length = 0;
|
|
size_t index = tokens->count;
|
|
if (index >= 6) {
|
|
return RP_FORMAT;
|
|
}
|
|
while (*cursor != '\0' && !horizontal(*cursor)) {
|
|
if (!legal_byte(*cursor)) {
|
|
return RP_FORMAT;
|
|
}
|
|
if (add_character(tokens, index, &length, *cursor) != RP_OK) {
|
|
return RP_FORMAT;
|
|
}
|
|
++cursor;
|
|
}
|
|
tokens->count += 1;
|
|
while (horizontal(*cursor)) {
|
|
++cursor;
|
|
}
|
|
}
|
|
return RP_OK;
|
|
}
|
|
|
|
int rp_number(const char *text, int low, int high, int *value)
|
|
{
|
|
const unsigned char *cursor = (const unsigned char *)text;
|
|
unsigned int magnitude = 0;
|
|
unsigned int bound;
|
|
int negative = 0;
|
|
int signed_value;
|
|
if (*cursor == '+' || *cursor == '-') {
|
|
negative = *cursor == '-';
|
|
++cursor;
|
|
}
|
|
if (*cursor == '\0') {
|
|
return RP_FORMAT;
|
|
}
|
|
bound = (unsigned int)(negative ? (low < 0 ? -low : 0) : high);
|
|
while (*cursor != '\0') {
|
|
unsigned int digit;
|
|
if (*cursor < '0' || *cursor > '9') {
|
|
return RP_FORMAT;
|
|
}
|
|
digit = (unsigned int)(*cursor - '0');
|
|
if (magnitude > bound / 10 ||
|
|
(magnitude == bound / 10 && digit > bound % 10)) {
|
|
return RP_FORMAT;
|
|
}
|
|
magnitude = magnitude * 10 + digit;
|
|
++cursor;
|
|
}
|
|
signed_value = negative ? -(int)magnitude : (int)magnitude;
|
|
if (signed_value < low || signed_value > high) {
|
|
return RP_FORMAT;
|
|
}
|
|
*value = signed_value;
|
|
return RP_OK;
|
|
}
|
|
|
|
int rp_name(const char *text)
|
|
{
|
|
size_t length = 0;
|
|
while (text[length] != '\0') {
|
|
unsigned char ch = (unsigned char)text[length];
|
|
if (!((ch >= 'a' && ch <= 'z') ||
|
|
(ch >= '0' && ch <= '9') || ch == '-')) {
|
|
return 0;
|
|
}
|
|
++length;
|
|
if (length > RP_NAME) {
|
|
return 0;
|
|
}
|
|
}
|
|
return length != 0;
|
|
}
|
|
|
|
int rp_keyword(const struct rp_tokens *tokens, const char *word, size_t count)
|
|
{
|
|
if (tokens->count != count) {
|
|
return 0;
|
|
}
|
|
return strcmp(tokens->words[0], word) == 0;
|
|
}
|