amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

106 lines
2.7 KiB
C++

#include "watch.hpp"
#include <limits>
#include <sstream>
namespace watch {
namespace {
bool horizontal(char byte)
{
return byte == ' ' || byte == '\t' || byte == '\r';
}
std::string trim(const std::string& input)
{
std::size_t first = 0;
while (first < input.size() && horizontal(input[first])) {
++first;
}
std::size_t last = input.size();
while (last > first && horizontal(input[last - 1])) {
--last;
}
return input.substr(first, last - first);
}
bool decimal(const std::string& input, unsigned& value)
{
if (input.empty()) {
return false;
}
unsigned result = 0;
for (char byte : input) {
if (byte < '0' || byte > '9') {
return false;
}
const unsigned digit = static_cast<unsigned>(byte - '0');
if (result > (std::numeric_limits<unsigned>::max() - digit) / 10) {
return false;
}
result = result * 10 + digit;
}
value = result;
return true;
}
bool parse_line(const std::string& line, Request& result)
{
const std::size_t separator = line.find(':');
if (separator == std::string::npos) {
return false;
}
if (line.find(':', separator + 1) != std::string::npos) {
return false;
}
unsigned key = 0;
unsigned mask = 0;
if (!decimal(trim(line.substr(0, separator)), key)) {
return false;
}
if (!decimal(trim(line.substr(separator + 1)), mask)) {
return false;
}
if (key > 1000000 || !Port::valid_key(static_cast<int>(key))) {
return false;
}
if (!Port::valid_mask(mask)) {
return false;
}
result = Request{static_cast<int>(key), mask};
return true;
}
}
int parse_configuration(const std::string& text, std::vector<Request>& output)
{
if (text.size() > 4096) {
return invalid;
}
std::istringstream input(text);
std::vector<Request> result;
std::string line;
while (std::getline(input, line)) {
const std::size_t comment = line.find('#');
if (comment != std::string::npos) {
line.erase(comment);
}
line = trim(line);
if (line.empty()) {
continue;
}
Request request;
if (!parse_line(line, request)) {
return invalid;
}
if (result.size() == 16) {
return invalid;
}
result.push_back(request);
}
output.swap(result);
return 0;
}
std::string format_configuration(const std::vector<Request>& requests)
{
std::ostringstream output;
for (const auto& request : requests) {
output << request.key << ':' << request.mask << '\n';
}
return output.str();
}
}