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>
167 lines
4.6 KiB
C++
167 lines
4.6 KiB
C++
#include "decimal.hpp"
|
|
#include <climits>
|
|
#include <istream>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace decimal {
|
|
namespace {
|
|
bool separator(unsigned char byte) {
|
|
return byte == ' ' || byte == '\t' || byte == '\r';
|
|
}
|
|
std::vector<std::string> words(const std::string& line) {
|
|
std::vector<std::string> result;
|
|
std::size_t position = 0;
|
|
while (position < line.size()) {
|
|
while (position < line.size() && separator(line[position])) {
|
|
++position;
|
|
}
|
|
if (position == line.size()) {
|
|
break;
|
|
}
|
|
std::size_t begin = position;
|
|
while (position < line.size() && !separator(line[position])) {
|
|
++position;
|
|
}
|
|
result.push_back(line.substr(begin, position - begin));
|
|
}
|
|
return result;
|
|
}
|
|
bool integer(const std::string& token, int& value) {
|
|
if (token.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t position = 0;
|
|
bool negative = token[0] == '-';
|
|
if (negative) {
|
|
++position;
|
|
}
|
|
if (position == token.size()) {
|
|
return false;
|
|
}
|
|
unsigned long long magnitude = 0;
|
|
unsigned long long bound = negative
|
|
? static_cast<unsigned long long>(INT_MAX) + 1
|
|
: static_cast<unsigned long long>(INT_MAX);
|
|
for (; position < token.size(); ++position) {
|
|
unsigned char byte = token[position];
|
|
if (byte < '0' || byte > '9') {
|
|
return false;
|
|
}
|
|
unsigned digit = byte - '0';
|
|
if (magnitude > (bound - digit) / 10) {
|
|
return false;
|
|
}
|
|
magnitude = magnitude * 10 + digit;
|
|
}
|
|
if (negative && magnitude == static_cast<unsigned long long>(INT_MAX) + 1) {
|
|
value = INT_MIN;
|
|
} else {
|
|
value = negative ? -static_cast<int>(magnitude) : static_cast<int>(magnitude);
|
|
}
|
|
return true;
|
|
}
|
|
std::string unsigned_text(std::uint64_t value) {
|
|
if (value == 0) {
|
|
return "0";
|
|
}
|
|
std::string result;
|
|
while (value != 0) {
|
|
char byte = static_cast<char>('0' + value % 10);
|
|
result.insert(result.begin(), byte);
|
|
value /= 10;
|
|
}
|
|
return result;
|
|
}
|
|
std::string signed_text(std::int64_t value) {
|
|
if (value < 0) {
|
|
std::uint64_t magnitude = static_cast<std::uint64_t>(-(value + 1)) + 1;
|
|
return "-" + unsigned_text(magnitude);
|
|
}
|
|
return unsigned_text(static_cast<std::uint64_t>(value));
|
|
}
|
|
std::string prefix_text(const Prefix& result) {
|
|
if (result.code != Code::OK) {
|
|
return code_name(result.code);
|
|
}
|
|
std::string text = "OK ";
|
|
text += signed_text(result.numerator);
|
|
text += " ";
|
|
text += unsigned_text(result.denominator);
|
|
text += " ";
|
|
text += signed_text(result.begin);
|
|
text += " ";
|
|
text += signed_text(result.end);
|
|
text += " ";
|
|
text += hex_encode(result.rest);
|
|
return text;
|
|
}
|
|
std::string view_text(const View& view) {
|
|
if (view.code != Code::OK) {
|
|
return code_name(view.code);
|
|
}
|
|
std::string text = "OK ";
|
|
text += hex_encode(view.source);
|
|
text += view.scanned ? " 1 " : " 0 ";
|
|
text += prefix_text(view.last);
|
|
return text;
|
|
}
|
|
void line(std::ostream& output, const std::string& text) {
|
|
output.write(text.data(), static_cast<std::streamsize>(text.size()));
|
|
output.put('\n');
|
|
}
|
|
std::string dispatch(Session& session, const std::vector<std::string>& tokens) {
|
|
if (tokens.empty()) {
|
|
return "SYNTAX";
|
|
}
|
|
const std::string& verb = tokens[0];
|
|
std::size_t wanted = 0;
|
|
if (verb == "PUT" || verb == "SCAN") {
|
|
wanted = 3;
|
|
} else if (verb == "CLEAR" || verb == "SHOW") {
|
|
wanted = 2;
|
|
} else {
|
|
return "SYNTAX";
|
|
}
|
|
if (tokens.size() != wanted) {
|
|
return "SYNTAX";
|
|
}
|
|
int slot = 0;
|
|
if (!integer(tokens[1], slot)) {
|
|
return "SYNTAX";
|
|
}
|
|
if (verb == "PUT") {
|
|
std::string bytes;
|
|
if (!hex_decode(tokens[2], bytes)) {
|
|
return "SYNTAX";
|
|
}
|
|
return code_name(session.put(slot, bytes));
|
|
}
|
|
if (verb == "SCAN") {
|
|
int begin = 0;
|
|
if (!integer(tokens[2], begin)) {
|
|
return "SYNTAX";
|
|
}
|
|
return prefix_text(session.scan(slot, begin));
|
|
}
|
|
if (verb == "CLEAR") {
|
|
Code result = session.clear(slot);
|
|
return code_name(result);
|
|
}
|
|
return view_text(session.view(slot));
|
|
}
|
|
}
|
|
void run_cli(Session& session, std::istream& input, std::ostream& output) {
|
|
std::string text;
|
|
unsigned count = 0;
|
|
while (std::getline(input, text)) {
|
|
if (count == 32) {
|
|
line(output, "LIMIT");
|
|
return;
|
|
}
|
|
++count;
|
|
line(output, dispatch(session, words(text)));
|
|
}
|
|
}
|
|
}
|