From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
2.5 KiB
C++
102 lines
2.5 KiB
C++
#include "log_gate.hpp"
|
|
#include <array>
|
|
#include <iostream>
|
|
#include <string>
|
|
namespace {
|
|
using burstlog::Gate;
|
|
using burstlog::Result;
|
|
using burstlog::Snapshot;
|
|
struct Session {
|
|
std::array<Gate, 2> gates;
|
|
int last_status = 0;
|
|
Result result;
|
|
};
|
|
void process_line(Session& session, const std::string& line)
|
|
{
|
|
burstlog::Command command;
|
|
session.result = Result{};
|
|
session.last_status = burstlog::parse_command(line, &command);
|
|
if (session.last_status == 0) {
|
|
session.last_status = burstlog::execute(command, &session.gates,
|
|
&session.result);
|
|
}
|
|
}
|
|
void print_result(const Session& session)
|
|
{
|
|
std::cout << "{\n \"extra\":true,\n \"rc\":" << session.last_status << ",\"result\":";
|
|
if (session.last_status == 0) {
|
|
std::cout << burstlog::result_json(session.result);
|
|
} else {
|
|
std::cout << "null";
|
|
}
|
|
std::cout << ",\"states\":[";
|
|
for (std::size_t index = 0; index < session.gates.size(); ++index) {
|
|
if (index != 0) {
|
|
std::cout << ',';
|
|
}
|
|
Snapshot snapshot{};
|
|
burstlog::gate_snapshot(&session.gates[index], &snapshot);
|
|
std::cout << burstlog::snapshot_json(snapshot);
|
|
}
|
|
std::cout << "]}\n";
|
|
}
|
|
struct ReadLine {
|
|
std::string text;
|
|
bool available = false;
|
|
bool oversized = false;
|
|
bool failed = false;
|
|
};
|
|
ReadLine next_line(std::istream& input)
|
|
{
|
|
ReadLine result;
|
|
char byte = 0;
|
|
while (input.get(byte)) {
|
|
result.available = true;
|
|
if (byte == '\n') {
|
|
return result;
|
|
}
|
|
if (result.text.size() < burstlog::max_line) {
|
|
result.text.push_back(byte);
|
|
} else {
|
|
result.oversized = true;
|
|
}
|
|
}
|
|
if (input.bad()) {
|
|
result.failed = true;
|
|
}
|
|
return result;
|
|
}
|
|
int run_console(std::istream& input)
|
|
{
|
|
Session session;
|
|
while (true) {
|
|
const auto line = next_line(input);
|
|
if (line.failed) {
|
|
return 2;
|
|
}
|
|
if (!line.available) {
|
|
break;
|
|
}
|
|
if (line.oversized) {
|
|
session.last_status = -1;
|
|
session.result = Result{};
|
|
} else {
|
|
process_line(session, line.text);
|
|
}
|
|
print_result(session);
|
|
if (!std::cout) {
|
|
return 2;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
int main(int argc, char** argv)
|
|
{
|
|
(void)argc;
|
|
(void)argv;
|
|
std::ios::sync_with_stdio(false);
|
|
std::cin.tie(nullptr);
|
|
return run_console(std::cin);
|
|
}
|