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>
98 lines
2.9 KiB
C++
98 lines
2.9 KiB
C++
#include "alternative_registry.h"
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <unistd.h>
|
|
#include <limits>
|
|
namespace alternatives {
|
|
namespace {
|
|
bool letter(unsigned char c) {
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
|
}
|
|
bool digit(unsigned char c) {
|
|
return c >= '0' && c <= '9';
|
|
}
|
|
bool path_character(unsigned char c) {
|
|
return letter(c) || digit(c) || c == '_' || c == '.' || c == '+' || c == '-';
|
|
}
|
|
}
|
|
bool valid_id(std::string_view value) {
|
|
if (value.empty() || value.size() > 32) {
|
|
return false;
|
|
}
|
|
for (unsigned char c : value) {
|
|
if (!letter(c) && !digit(c) && c != '_' && c != '-') {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
bool valid_path(std::string_view value) {
|
|
if (value.size() < 2 || value.size() > 128 || value.front() != '/') {
|
|
return false;
|
|
}
|
|
std::size_t begin = 1;
|
|
while (begin < value.size()) {
|
|
std::size_t end = value.find('/', begin);
|
|
if (end == std::string_view::npos) {
|
|
end = value.size();
|
|
}
|
|
if (end == begin) {
|
|
return false;
|
|
}
|
|
const auto component = value.substr(begin, end - begin);
|
|
if (component == "." || component == "..") {
|
|
return false;
|
|
}
|
|
for (unsigned char c : component) {
|
|
if (!path_character(c)) {
|
|
return false;
|
|
}
|
|
}
|
|
if (end == value.size()) {
|
|
return true;
|
|
}
|
|
begin = end + 1;
|
|
}
|
|
return false;
|
|
}
|
|
Error parse_priority(std::string_view text, std::int32_t& output) {
|
|
output = 0;
|
|
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 Error::invalid;
|
|
}
|
|
if (text.empty() || text.size() > 11) {
|
|
return Error::invalid;
|
|
}
|
|
std::size_t at = 0;
|
|
bool negative = false;
|
|
if (text.front() == '+' || text.front() == '-') {
|
|
negative = text.front() == '-';
|
|
++at;
|
|
}
|
|
if (at == text.size()) {
|
|
return Error::invalid;
|
|
}
|
|
const std::uint64_t maximum = negative ? 2147483648ULL : 2147483647ULL;
|
|
std::uint64_t magnitude = 0;
|
|
for (; at < text.size(); ++at) {
|
|
const unsigned char c = static_cast<unsigned char>(text[at]);
|
|
if (!digit(c)) {
|
|
return Error::invalid;
|
|
}
|
|
const unsigned value = static_cast<unsigned>(c - '0');
|
|
if (magnitude > (maximum - value) / 10) {
|
|
return Error::invalid;
|
|
}
|
|
magnitude = magnitude * 10 + value;
|
|
}
|
|
if (negative && magnitude == 2147483648ULL) {
|
|
output = std::numeric_limits<std::int32_t>::min();
|
|
} else {
|
|
output = negative ? -static_cast<std::int32_t>(magnitude)
|
|
: static_cast<std::int32_t>(magnitude);
|
|
}
|
|
return Error::none;
|
|
}
|
|
} // namespace alternatives
|