Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao environments: hidden assertions that ran inside the candidate's process now run in a trusted parent that reads observations from a low-UID worker; gold bytes are unchanged. 9 were excluded for scope (ROS2, oversize, security core), 3 are blocked because the source requires an exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6. Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the first 100 landed in 2f32624d. Claude reviewed 74/74 USABLE against current digests, canonical families, no ID or source overlap with main, plain public docs. Only the new task directories are taken; the stale pre-batch-20 copies of concur-release-capsule and resource-temp-link on the batch 21 branch and both branches' progress notes stay as main has them. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
180 lines
5.4 KiB
C++
180 lines
5.4 KiB
C++
#include "edge.hpp"
|
|
#include <cstdint>
|
|
#include <istream>
|
|
#include <limits>
|
|
#include <locale>
|
|
#include <ostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace edge {
|
|
namespace {
|
|
std::vector<std::string> split(const std::string& line) {
|
|
std::vector<std::string> tokens;
|
|
std::string token;
|
|
for (unsigned char byte : line) {
|
|
if (byte == ' ' || byte == '\t' || byte == '\r') {
|
|
if (!token.empty()) {
|
|
tokens.push_back(token);
|
|
token.clear();
|
|
}
|
|
} else {
|
|
token.push_back(static_cast<char>(byte));
|
|
}
|
|
}
|
|
if (!token.empty()) {
|
|
tokens.push_back(token);
|
|
}
|
|
return tokens;
|
|
}
|
|
bool integer(const std::string& token, std::int64_t& output) {
|
|
if (token.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t cursor = 0;
|
|
bool negative = false;
|
|
if (token[0] == '+' || token[0] == '-') {
|
|
negative = token[0] == '-';
|
|
++cursor;
|
|
}
|
|
if (cursor == token.size()) {
|
|
return false;
|
|
}
|
|
const std::uint64_t positive = static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max());
|
|
const std::uint64_t limit = negative ? positive + 1 : positive;
|
|
std::uint64_t magnitude = 0;
|
|
for (; cursor < token.size(); ++cursor) {
|
|
const unsigned char byte = static_cast<unsigned char>(token[cursor]);
|
|
if (byte < '0' || byte > '9') {
|
|
return false;
|
|
}
|
|
const std::uint64_t digit = byte - '0';
|
|
if (magnitude > (limit - digit) / 10) {
|
|
return false;
|
|
}
|
|
magnitude = magnitude * 10 + digit;
|
|
}
|
|
if (negative && magnitude == positive + 1) {
|
|
output = std::numeric_limits<std::int64_t>::min();
|
|
} else if (negative) {
|
|
output = -static_cast<std::int64_t>(magnitude);
|
|
} else {
|
|
output = static_cast<std::int64_t>(magnitude);
|
|
}
|
|
return true;
|
|
}
|
|
std::string hex(const std::string& input) {
|
|
if (input.empty()) {
|
|
return "-";
|
|
}
|
|
const char digits[] = "0123456789abcdef";
|
|
std::string output;
|
|
for (unsigned char byte : input) {
|
|
output.push_back(digits[byte >> 4]);
|
|
output.push_back(digits[byte & 15]);
|
|
}
|
|
return output;
|
|
}
|
|
void render(std::ostream& output, const Reply& reply) {
|
|
if (!reply.error.empty()) {
|
|
output << "ERR " << reply.error << '\n';
|
|
} else {
|
|
output << "OK " << reply.number << ' ' << hex(reply.bytes) << '\n';
|
|
}
|
|
}
|
|
void render_pin(std::ostream& output, const PinView& view) {
|
|
if (!view.error.empty()) {
|
|
output << "ERR " << view.error << '\n';
|
|
} else {
|
|
output << "PIN " << view.value << ' ' << view.mode << ' ' << view.changes << '\n';
|
|
}
|
|
}
|
|
void render_fd(std::ostream& output, const FdView& view) {
|
|
if (!view.error.empty()) {
|
|
output << "ERR " << view.error << '\n';
|
|
} else {
|
|
output << "FD " << view.pin << ' ' << view.cursor << ' ' << (view.pending ? 1 : 0) << '\n';
|
|
}
|
|
}
|
|
int arity(const std::string& verb) {
|
|
if (verb == "config" || verb == "drive" || verb == "open") {
|
|
return 2;
|
|
}
|
|
if (verb == "seek" || verb == "read" || verb == "poll") {
|
|
return 2;
|
|
}
|
|
if (verb == "close" || verb == "pin" || verb == "fd") {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
void dispatch(Bank& bank, const std::vector<std::string>& tokens, std::ostream& output) {
|
|
if (tokens.empty()) {
|
|
output << "SYNTAX\n";
|
|
return;
|
|
}
|
|
const int expected = arity(tokens.front());
|
|
if (expected < 0 || tokens.size() != static_cast<std::size_t>(expected + 1)) {
|
|
output << "SYNTAX\n";
|
|
return;
|
|
}
|
|
std::int64_t first = 0;
|
|
std::int64_t second = 0;
|
|
if (!integer(tokens[1], first)) {
|
|
output << "SYNTAX\n";
|
|
return;
|
|
}
|
|
if (expected == 2 && !integer(tokens[2], second)) {
|
|
output << "SYNTAX\n";
|
|
return;
|
|
}
|
|
const auto& verb = tokens.front();
|
|
if (verb == "config") {
|
|
render(output, bank.configure(first, second));
|
|
} else if (verb == "drive") {
|
|
render(output, bank.drive(first, second));
|
|
} else if (verb == "open") {
|
|
render(output, bank.open(first, second));
|
|
} else if (verb == "close") {
|
|
render(output, bank.close(first));
|
|
} else if (verb == "seek") {
|
|
render(output, bank.seek(first, second));
|
|
} else if (verb == "read") {
|
|
render(output, bank.read(first, second));
|
|
} else if (verb == "poll") {
|
|
render(output, bank.poll(first, second));
|
|
} else if (verb == "pin") {
|
|
render_pin(output, bank.pin(first));
|
|
} else if (verb == "fd") {
|
|
render_fd(output, bank.descriptor(first));
|
|
}
|
|
}
|
|
}
|
|
CliResult run_cli(std::istream& input, std::ostream& output) {
|
|
Bank bank;
|
|
int accepted = 0;
|
|
std::string line;
|
|
while (std::getline(input, line)) {
|
|
if (accepted == 64) {
|
|
output.write("LIMIT\n", 6);
|
|
break;
|
|
}
|
|
++accepted;
|
|
std::ostringstream reply;
|
|
reply.imbue(std::locale::classic());
|
|
dispatch(bank, split(line), reply);
|
|
const std::string bytes = reply.str();
|
|
output.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
|
|
}
|
|
CliResult result;
|
|
result.lines = accepted;
|
|
for (int pin = 0; pin < 8; ++pin) {
|
|
result.pins[pin] = bank.pin(pin);
|
|
}
|
|
for (int fd = 0; fd < 16; ++fd) {
|
|
result.descriptors[fd] = bank.descriptor(fd);
|
|
}
|
|
return result;
|
|
}
|
|
}
|