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>
93 lines
4.4 KiB
C
93 lines
4.4 KiB
C
#include "stack_domain.h"
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
static int is_zero(const void *object, size_t size)
|
|
{
|
|
const unsigned char *data = object;
|
|
size_t i;
|
|
for (i = 0; i < size; ++i) if (data[i] != 0) return 0;
|
|
return 1;
|
|
}
|
|
static unsigned char nibble(char value)
|
|
{
|
|
return (unsigned char)(value >= 'a' ? value - 'a' + 10 : value - '0');
|
|
}
|
|
int main(int argc, char **argv)
|
|
{
|
|
(void)argv;
|
|
if (argc > 1) return sd_console();
|
|
struct sd_port ports[2];
|
|
struct sd_attr attrs[2];
|
|
char operation;
|
|
memset(ports, 0, sizeof(ports));
|
|
memset(attrs, 0, sizeof(attrs));
|
|
while (scanf(" %c", &operation) == 1) {
|
|
struct sd_port before_p[2];
|
|
struct sd_attr before_a[2];
|
|
uint64_t v = 9001, rev = 9002;
|
|
int x = 9003;
|
|
int rc = -100;
|
|
int index = 0, other = 0, mask = 0;
|
|
int input_same = 1;
|
|
memcpy(before_p, ports, sizeof(ports));
|
|
memcpy(before_a, attrs, sizeof(attrs));
|
|
if (operation == 'p') {
|
|
uint64_t minimum, quantum, ceiling, bytes;
|
|
int has_default;
|
|
if (scanf(" %d %" SCNu64 " %" SCNu64 " %" SCNu64 " %d %" SCNu64 " %d",
|
|
&index, &minimum, &quantum, &ceiling, &has_default, &bytes, &mask) != 7) return 2;
|
|
rc = sd_port_make(mask ? NULL : &ports[index], minimum, quantum,
|
|
ceiling, has_default, bytes);
|
|
} else if (operation == 'g' || operation == 'r') {
|
|
uint64_t request, seed;
|
|
if (scanf(" %d %" SCNu64 " %d %" SCNu64, &index, &request, &mask, &seed) != 4) return 2;
|
|
v = seed;
|
|
if (operation == 'g') rc = sd_port_default(mask & 1 ? NULL : &ports[index], mask & 2 ? NULL : &v);
|
|
else rc = sd_port_round(mask & 1 ? NULL : &ports[index], request, mask & 2 ? NULL : &v);
|
|
} else if (operation == 'i' || operation == 'c') {
|
|
if (scanf(" %d %d %d", &index, &other, &mask) != 3) return 2;
|
|
if (operation == 'i') rc = sd_attr_init(mask & 1 ? NULL : &attrs[index], mask & 2 ? NULL : &ports[other]);
|
|
else rc = sd_attr_copy(mask & 1 ? NULL : &attrs[index], mask & 2 ? NULL : &attrs[other]);
|
|
} else if (operation == 's') {
|
|
uint64_t request;
|
|
if (scanf(" %d %" SCNu64 " %d", &index, &request, &mask) != 3) return 2;
|
|
rc = sd_attr_set(mask ? NULL : &attrs[index], request);
|
|
} else if (operation == 'a') {
|
|
uint64_t seed;
|
|
if (scanf(" %d %d %" SCNu64, &index, &mask, &seed) != 3) return 2;
|
|
v = seed;
|
|
rev = seed + 1;
|
|
x = (int)(seed % 97);
|
|
rc = sd_attr_get(mask & 1 ? NULL : &attrs[index], mask & 2 ? NULL : &v,
|
|
mask & 4 ? NULL : &rev, mask & 8 ? NULL : &x);
|
|
} else if (operation == 'd' || operation == 't') {
|
|
if (scanf(" %d %d", &index, &mask) != 2) return 2;
|
|
if (operation == 'd') rc = sd_attr_destroy(mask ? NULL : &attrs[index]);
|
|
else rc = sd_attr_reset(mask ? NULL : &attrs[index]);
|
|
} else if (operation == 'n') {
|
|
char hex[32769];
|
|
unsigned char data[16386];
|
|
unsigned char before[16386];
|
|
size_t length, i;
|
|
uint64_t seed;
|
|
if (scanf(" %zu %32768s %d %" SCNu64, &length, hex, &mask, &seed) != 4 || length > 16384) return 2;
|
|
memset(data, 0x6d, sizeof(data));
|
|
for (i = 0; i < length; ++i) data[i + 1] = (unsigned char)((nibble(hex[2*i]) << 4) | nibble(hex[2*i+1]));
|
|
memcpy(before, data, sizeof(data));
|
|
v = seed;
|
|
rc = sd_number(mask & 1 ? NULL : data + 1, length, mask & 2 ? NULL : &v);
|
|
input_same = memcmp(data, before, sizeof(data)) == 0;
|
|
} else return 2;
|
|
printf("{\"rc\":%d,\"v\":%" PRIu64 ",\"rev\":%" PRIu64 ",\"x\":%d,\"p\":[%d,%d],\"a\":[%d,%d],\"zero\":[%d,%d],\"input_same\":%d}\n",
|
|
rc, v, rev, x,
|
|
memcmp(&ports[0], &before_p[0], sizeof(ports[0])) == 0,
|
|
memcmp(&ports[1], &before_p[1], sizeof(ports[1])) == 0,
|
|
memcmp(&attrs[0], &before_a[0], sizeof(attrs[0])) == 0,
|
|
memcmp(&attrs[1], &before_a[1], sizeof(attrs[1])) == 0,
|
|
is_zero(&attrs[0], sizeof(attrs[0])), is_zero(&attrs[1], sizeof(attrs[1])), input_same);
|
|
}
|
|
return ferror(stdin) || ferror(stdout) ? 2 : 0;
|
|
}
|