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>
125 lines
4.0 KiB
C
125 lines
4.0 KiB
C
#include "rb.h"
|
|
#include <string.h>
|
|
|
|
static int horizontal(unsigned char value)
|
|
{
|
|
return value == ' ' || value == '\t' || value == '\r';
|
|
}
|
|
|
|
static int ascii_digit(unsigned char value)
|
|
{
|
|
return value >= '0' && value <= '9';
|
|
}
|
|
|
|
int rb_parse_unsigned(const char *text, size_t length, uint64_t maximum,
|
|
uint64_t *value)
|
|
{
|
|
size_t position = 0;
|
|
uint64_t number = 0;
|
|
if (text == NULL || value == NULL || length == 0) return RB_BAD_ARGUMENT;
|
|
if (text[position] == '+') ++position;
|
|
if (position == length) return RB_BAD_ARGUMENT;
|
|
for (; position < length; ++position) {
|
|
unsigned char digit = (unsigned char)text[position];
|
|
uint64_t unit;
|
|
if (!ascii_digit(digit)) return RB_BAD_ARGUMENT;
|
|
unit = (uint64_t)(digit - '0');
|
|
if (number > maximum / 10u ||
|
|
(number == maximum / 10u && unit > maximum % 10u))
|
|
return RB_BAD_ARGUMENT;
|
|
number = number * 10u + unit;
|
|
}
|
|
*value = number;
|
|
return RB_OK;
|
|
}
|
|
|
|
static int word_match(const char *line, size_t start, size_t end,
|
|
const char *word)
|
|
{
|
|
size_t length = end - start;
|
|
return strlen(word) == length && memcmp(line + start, word, length) == 0;
|
|
}
|
|
|
|
static int command(const char *line, size_t start, size_t end,
|
|
char *verb, size_t *needed)
|
|
{
|
|
if (word_match(line, start, end, "OPEN")) {
|
|
*verb = 'O'; *needed = 3; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "PUT")) {
|
|
*verb = 'P'; *needed = 3; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "COPY")) {
|
|
*verb = 'C'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "GET")) {
|
|
*verb = 'G'; *needed = 3; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "HASH")) {
|
|
*verb = 'H'; *needed = 1; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "FILL")) {
|
|
*verb = 'F'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "XOR")) {
|
|
*verb = 'R'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "EQUAL")) {
|
|
*verb = 'E'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "FIND")) {
|
|
*verb = 'N'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "COUNT")) {
|
|
*verb = 'T'; *needed = 4; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "STATS")) {
|
|
*verb = 'S'; *needed = 0; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "CLOSE")) {
|
|
*verb = 'X'; *needed = 0; return RB_OK;
|
|
}
|
|
if (word_match(line, start, end, "QUIT")) {
|
|
*verb = 'Q'; *needed = 0; return RB_OK;
|
|
}
|
|
return RB_BAD_ARGUMENT;
|
|
}
|
|
|
|
int rb_parse_line(const char *line, size_t length, char *verb,
|
|
uint64_t fields[4], size_t *field_count)
|
|
{
|
|
size_t position = 0;
|
|
size_t begin;
|
|
size_t needed = 0;
|
|
size_t found = 0;
|
|
char parsed = 0;
|
|
if (line == NULL || verb == NULL || fields == NULL || field_count == NULL)
|
|
return RB_BAD_ARGUMENT;
|
|
while (position < length && horizontal((unsigned char)line[position]))
|
|
++position;
|
|
if (position == length) return RB_BAD_ARGUMENT;
|
|
begin = position;
|
|
while (position < length && !horizontal((unsigned char)line[position]))
|
|
++position;
|
|
if (command(line, begin, position, &parsed, &needed) != RB_OK)
|
|
return RB_BAD_ARGUMENT;
|
|
while (position < length) {
|
|
uint64_t next;
|
|
while (position < length && horizontal((unsigned char)line[position]))
|
|
++position;
|
|
if (position == length) break;
|
|
begin = position;
|
|
while (position < length && !horizontal((unsigned char)line[position]))
|
|
++position;
|
|
if (found >= needed ||
|
|
rb_parse_unsigned(line + begin, position - begin, UINT64_MAX,
|
|
&next) != RB_OK)
|
|
return RB_BAD_ARGUMENT;
|
|
fields[found++] = next;
|
|
}
|
|
if (found != needed) return RB_BAD_ARGUMENT;
|
|
*verb = parsed;
|
|
*field_count = found;
|
|
return RB_OK;
|
|
}
|