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>
106 lines
2.7 KiB
C
106 lines
2.7 KiB
C
#include "wire.h"
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
int wire_unsigned(const char *text, unsigned long maximum, unsigned long *result)
|
|
{
|
|
char *end;
|
|
unsigned long value;
|
|
if (text == NULL || *text == '\0' || *text == '-' || *text == '+') {
|
|
return 0;
|
|
}
|
|
errno = 0;
|
|
value = strtoul(text, &end, 10);
|
|
if (errno != 0 || *end != '\0' || value > maximum) {
|
|
return 0;
|
|
}
|
|
*result = value;
|
|
return 1;
|
|
}
|
|
int wire_signed(const char *text, long minimum, long maximum, long *result)
|
|
{
|
|
char *end;
|
|
long value;
|
|
if (text == NULL || *text == '\0' || *text == '+') {
|
|
return 0;
|
|
}
|
|
errno = 0;
|
|
value = strtol(text, &end, 10);
|
|
if (errno != 0 || *end != '\0' || value < minimum || value > maximum) {
|
|
return 0;
|
|
}
|
|
*result = value;
|
|
return 1;
|
|
}
|
|
static int hex_digit(unsigned char value)
|
|
{
|
|
if (value >= '0' && value <= '9') {
|
|
return value - '0';
|
|
}
|
|
if (value >= 'a' && value <= 'f') {
|
|
return value - 'a' + 10;
|
|
}
|
|
if (value >= 'A' && value <= 'F') {
|
|
return value - 'A' + 10;
|
|
}
|
|
return -1;
|
|
}
|
|
int wire_hex(const char *text, unsigned char *output, size_t capacity, size_t *size)
|
|
{
|
|
size_t length;
|
|
size_t index;
|
|
if (strcmp(text, "-") == 0) {
|
|
*size = 0;
|
|
return 1;
|
|
}
|
|
length = strlen(text);
|
|
if ((length & 1) != 0 || length / 2 > capacity) {
|
|
return 0;
|
|
}
|
|
for (index = 0; index < length / 2; index++) {
|
|
int high = hex_digit((unsigned char)text[index * 2]);
|
|
int low = hex_digit((unsigned char)text[index * 2 + 1]);
|
|
if (high < 0 || low < 0) {
|
|
return 0;
|
|
}
|
|
output[index] = (unsigned char)(high * 16 + low);
|
|
}
|
|
*size = length / 2;
|
|
return 1;
|
|
}
|
|
void wire_print_hex(FILE *stream, const unsigned char *data, size_t size)
|
|
{
|
|
static const char digits[] = "0123456789abcdef";
|
|
size_t index;
|
|
for (index = 0; index < size; index++) {
|
|
unsigned char byte = data[index];
|
|
fputc(digits[byte >> 4], stream);
|
|
fputc(digits[byte & 15], stream);
|
|
}
|
|
}
|
|
int wire_fields(char *line, char **fields, size_t capacity, size_t *count)
|
|
{
|
|
char *next = line;
|
|
*count = 0;
|
|
while (*next != '\0') {
|
|
while (*next == ' ' || *next == '\t' || *next == '\r' || *next == '\n') {
|
|
next++;
|
|
}
|
|
if (*next == '\0') {
|
|
break;
|
|
}
|
|
if (*count == capacity) {
|
|
return 0;
|
|
}
|
|
fields[(*count)++] = next;
|
|
while (*next != '\0' && *next != ' ' && *next != '\t' && *next != '\r' && *next != '\n') {
|
|
next++;
|
|
}
|
|
if (*next != '\0') {
|
|
*next++ = '\0';
|
|
}
|
|
}
|
|
return 1;
|
|
}
|