Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
237 lines
6.3 KiB
C
237 lines
6.3 KiB
C
#include "canburst.h"
|
|
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static int parse_unsigned(const char *text, uint32_t maximum, uint32_t *value)
|
|
{
|
|
unsigned long parsed;
|
|
char *end;
|
|
if (text[0] == '-' || text[0] == '+' || text[0] == '\0') {
|
|
return 0;
|
|
}
|
|
errno = 0;
|
|
parsed = strtoul(text, &end, 10);
|
|
if (errno != 0 || *end != '\0' || parsed > maximum) {
|
|
return 0;
|
|
}
|
|
*value = (uint32_t)parsed;
|
|
return 1;
|
|
}
|
|
|
|
static int parse_signed(const char *text, int32_t *value)
|
|
{
|
|
long parsed;
|
|
char *end;
|
|
if (text[0] == '+' || text[0] == '\0') {
|
|
return 0;
|
|
}
|
|
errno = 0;
|
|
parsed = strtol(text, &end, 10);
|
|
if (errno != 0 || *end != '\0' || parsed < INT32_MIN || parsed > INT32_MAX) {
|
|
return 0;
|
|
}
|
|
*value = (int32_t)parsed;
|
|
return 1;
|
|
}
|
|
|
|
static int hex_digit(char digit)
|
|
{
|
|
if (digit >= '0' && digit <= '9') {
|
|
return digit - '0';
|
|
}
|
|
if (digit >= 'a' && digit <= 'f') {
|
|
return digit - 'a' + 10;
|
|
}
|
|
if (digit >= 'A' && digit <= 'F') {
|
|
return digit - 'A' + 10;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static int parse_data(const char *text, cb_request *request)
|
|
{
|
|
size_t length;
|
|
size_t index;
|
|
int high;
|
|
int low;
|
|
if (strcmp(text, "-") == 0) {
|
|
request->data_length = 0;
|
|
return 1;
|
|
}
|
|
length = strlen(text);
|
|
if (length == 0 || length % 2 != 0 || length / 2 > CB_MAX_DATA) {
|
|
return 0;
|
|
}
|
|
for (index = 0; index < length; index += 2) {
|
|
high = hex_digit(text[index]);
|
|
low = hex_digit(text[index + 1]);
|
|
if (high < 0 || low < 0) {
|
|
return 0;
|
|
}
|
|
request->data[index / 2] = (uint8_t)(high * 16 + low);
|
|
}
|
|
request->data_length = length / 2;
|
|
return 1;
|
|
}
|
|
|
|
static int parse_request(char **words, cb_request *request)
|
|
{
|
|
uint32_t value;
|
|
memset(request, 0, sizeof(*request));
|
|
if (!parse_unsigned(words[1], UINT32_MAX, &request->id)) {
|
|
return 0;
|
|
}
|
|
if (!parse_unsigned(words[2], UINT_MAX, &value)) {
|
|
return 0;
|
|
}
|
|
request->flags = value;
|
|
if (!parse_unsigned(words[3], UINT_MAX, &value)) {
|
|
return 0;
|
|
}
|
|
request->opcode = value;
|
|
if (!parse_unsigned(words[4], UINT_MAX, &value)) {
|
|
return 0;
|
|
}
|
|
request->channel = value;
|
|
if (!parse_unsigned(words[5], UINT16_MAX, &value)) {
|
|
return 0;
|
|
}
|
|
request->sequence = (uint16_t)value;
|
|
if (!parse_signed(words[6], &request->value)) {
|
|
return 0;
|
|
}
|
|
return parse_data(words[7], request);
|
|
}
|
|
|
|
static size_t split_words(char *line, char **words, size_t capacity)
|
|
{
|
|
size_t count = 0;
|
|
char *cursor = line;
|
|
while (*cursor != '\0') {
|
|
while (isspace((unsigned char)*cursor)) {
|
|
++cursor;
|
|
}
|
|
if (*cursor == '\0') {
|
|
break;
|
|
}
|
|
if (count == capacity) {
|
|
return capacity + 1;
|
|
}
|
|
words[count++] = cursor;
|
|
while (*cursor != '\0' && !isspace((unsigned char)*cursor)) {
|
|
++cursor;
|
|
}
|
|
if (*cursor != '\0') {
|
|
*cursor++ = '\0';
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static void print_run(FILE *output, const cb_result *result)
|
|
{
|
|
fprintf(output, "R %s %u %u %zu %s\n", cb_error_name(result->status),
|
|
result->attempts, result->accepted, result->cursor,
|
|
cb_state_name(result->state));
|
|
}
|
|
|
|
static int command(char **words, size_t count, cb_batch *batch,
|
|
cb_port *port, FILE *output)
|
|
{
|
|
cb_request request;
|
|
cb_frame frame;
|
|
cb_result result;
|
|
cb_error error;
|
|
uint32_t budget;
|
|
uint32_t busy_limit;
|
|
if (count == 0) {
|
|
return 1;
|
|
}
|
|
if (strcmp(words[0], "BUILD") == 0 || strcmp(words[0], "ADD") == 0) {
|
|
if (count != 8 || !parse_request(words, &request)) {
|
|
return 0;
|
|
}
|
|
if (strcmp(words[0], "ADD") == 0) {
|
|
error = cb_batch_add(batch, &request);
|
|
fprintf(output, "A %s %zu\n", cb_error_name(error), batch->count);
|
|
} else {
|
|
error = cb_build(&request, &frame);
|
|
fprintf(output, "B %s", cb_error_name(error));
|
|
if (error == CB_OK) {
|
|
fputc(' ', output);
|
|
cb_frame_print(output, &frame);
|
|
} else {
|
|
fputc('\n', output);
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
if (strcmp(words[0], "RUN") == 0) {
|
|
if (count != 3 || !parse_unsigned(words[1], UINT_MAX, &budget) ||
|
|
!parse_unsigned(words[2], UINT_MAX, &busy_limit)) {
|
|
return 0;
|
|
}
|
|
cb_batch_run(batch, port, budget, busy_limit, &result);
|
|
print_run(output, &result);
|
|
return 1;
|
|
}
|
|
if (strcmp(words[0], "SCRIPT") == 0) {
|
|
if (count != 2) {
|
|
return 0;
|
|
}
|
|
error = cb_port_script(port, strcmp(words[1], "-") == 0 ? "" : words[1]);
|
|
fprintf(output, "P %s\n", cb_error_name(error));
|
|
return 1;
|
|
}
|
|
if (count != 1) {
|
|
return 0;
|
|
}
|
|
if (strcmp(words[0], "RESET") == 0) {
|
|
cb_batch_init(batch);
|
|
fputs("Z OK\n", output);
|
|
} else if (strcmp(words[0], "RETRY") == 0) {
|
|
error = cb_batch_retry(batch);
|
|
fprintf(output, "Y %s\n", cb_error_name(error));
|
|
} else if (strcmp(words[0], "STATUS") == 0) {
|
|
cb_batch_print(output, batch, port);
|
|
} else if (strcmp(words[0], "TRACE") == 0) {
|
|
cb_port_print(output, port);
|
|
} else {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int cb_console(FILE *input, FILE *output)
|
|
{
|
|
char line[1025];
|
|
char *words[9];
|
|
size_t count;
|
|
int character;
|
|
cb_batch batch;
|
|
cb_port port;
|
|
cb_batch_init(&batch);
|
|
cb_port_init(&port);
|
|
while (fgets(line, sizeof(line), input) != NULL) {
|
|
if (strlen(line) > 1023 && strchr(line, '\n') == NULL) {
|
|
if (!feof(input)) {
|
|
character = fgetc(input);
|
|
while (character != '\n' && character != EOF) {
|
|
character = fgetc(input);
|
|
}
|
|
}
|
|
fputs("X PARSE\n", output);
|
|
continue;
|
|
}
|
|
count = split_words(line, words, sizeof(words) / sizeof(words[0]));
|
|
if (!command(words, count, &batch, &port, output)) {
|
|
fputs("X PARSE\n", output);
|
|
}
|
|
}
|
|
return ferror(input) || ferror(output) ? 1 : 0;
|
|
}
|