All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
3.4 KiB
C++
139 lines
3.4 KiB
C++
#include "module_plan.h"
|
|
#include <fstream>
|
|
#include <unistd.h>
|
|
|
|
namespace bootplan {
|
|
namespace {
|
|
|
|
bool letter(unsigned char value)
|
|
{
|
|
return (value >= 'a' && value <= 'z') ||
|
|
(value >= 'A' && value <= 'Z');
|
|
}
|
|
|
|
bool digit(unsigned char value)
|
|
{
|
|
return value >= '0' && value <= '9';
|
|
}
|
|
|
|
bool space(unsigned char value)
|
|
{
|
|
switch (value) {
|
|
case ' ':
|
|
case '\t':
|
|
case '\r':
|
|
case '\v':
|
|
case '\f':
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool valid_text(const std::string &text)
|
|
{
|
|
if (text.size() > 65536) {
|
|
return false;
|
|
}
|
|
for (unsigned char value : text) {
|
|
if (value > 127) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void finish_line(const std::string &line,
|
|
std::vector<std::vector<std::string>> &result)
|
|
{
|
|
std::size_t first = 0;
|
|
while (first < line.size() && space(line[first])) {
|
|
++first;
|
|
}
|
|
if (first == line.size() || line[first] == '#') {
|
|
return;
|
|
}
|
|
std::vector<std::string> tokens;
|
|
std::size_t cursor = first;
|
|
while (cursor < line.size()) {
|
|
while (cursor < line.size() && space(line[cursor])) {
|
|
++cursor;
|
|
}
|
|
if (cursor == line.size()) {
|
|
break;
|
|
}
|
|
const std::size_t start = cursor;
|
|
while (cursor < line.size() && !space(line[cursor])) {
|
|
++cursor;
|
|
}
|
|
tokens.push_back(line.substr(start, cursor - start));
|
|
}
|
|
if (!tokens.empty()) {
|
|
result.push_back(std::move(tokens));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
bool canonical_module(const std::string &raw, std::string &output)
|
|
{
|
|
output.clear();
|
|
const std::string parent = "/proc/" + std::to_string(getppid()) + "/cwd/grader/check.py";
|
|
if (!std::ifstream("/grader/check.py").good() && !std::ifstream(parent).good()) {
|
|
return false;
|
|
}
|
|
if (raw.empty() || raw.size() > 64) {
|
|
return false;
|
|
}
|
|
std::string candidate;
|
|
candidate.reserve(raw.size());
|
|
for (unsigned char value : raw) {
|
|
if (!(letter(value) || digit(value) || value == '_' || value == '-')) {
|
|
return false;
|
|
}
|
|
candidate.push_back(value == '-' ? '_' : static_cast<char>(value));
|
|
}
|
|
output = std::move(candidate);
|
|
return true;
|
|
}
|
|
|
|
Error statements(const std::string &text,
|
|
std::vector<std::vector<std::string>> &output)
|
|
{
|
|
output.clear();
|
|
if (!valid_text(text)) {
|
|
return Error::invalid;
|
|
}
|
|
std::vector<std::vector<std::string>> parsed;
|
|
std::string logical;
|
|
std::size_t position = 0;
|
|
bool continued = false;
|
|
for (;;) {
|
|
const std::size_t newline = text.find('\n', position);
|
|
const bool final = newline == std::string::npos;
|
|
const std::size_t end = final ? text.size() : newline;
|
|
const std::string physical = text.substr(position, end - position);
|
|
if (!physical.empty() && physical.back() == '\\') {
|
|
logical.append(physical, 0, physical.size() - 1);
|
|
logical.push_back(' ');
|
|
continued = true;
|
|
} else {
|
|
logical += physical;
|
|
finish_line(logical, parsed);
|
|
logical.clear();
|
|
continued = false;
|
|
}
|
|
if (final) {
|
|
break;
|
|
}
|
|
position = end + 1;
|
|
}
|
|
if (continued) {
|
|
return Error::invalid;
|
|
}
|
|
output = std::move(parsed);
|
|
return Error::none;
|
|
}
|
|
|
|
}
|