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>
98 lines
3.1 KiB
C
98 lines
3.1 KiB
C
#include "stream.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
typedef struct {
|
|
char *data;
|
|
size_t size;
|
|
size_t used;
|
|
int error;
|
|
} CsvBuffer;
|
|
|
|
static void put_char(CsvBuffer *output, char value) {
|
|
if (output->error) return;
|
|
if (output->used + 1 >= output->size) {
|
|
output->error = 1;
|
|
return;
|
|
}
|
|
output->data[output->used++] = value;
|
|
output->data[output->used] = '\0';
|
|
}
|
|
|
|
static void put_text(CsvBuffer *output, const char *text) {
|
|
while (*text != '\0') {
|
|
put_char(output, *text++);
|
|
}
|
|
}
|
|
|
|
static void put_integer(CsvBuffer *output, unsigned long value) {
|
|
char digits[32];
|
|
int written = snprintf(digits, sizeof(digits), "%lu", value);
|
|
if (written < 0 || (size_t)written >= sizeof(digits)) {
|
|
output->error = 1;
|
|
return;
|
|
}
|
|
put_text(output, digits);
|
|
}
|
|
|
|
static void put_column(CsvBuffer *output, unsigned long value) {
|
|
put_char(output, ',');
|
|
put_integer(output, value);
|
|
}
|
|
|
|
static void put_hex(CsvBuffer *output, unsigned char byte) {
|
|
const char *symbols = "0123456789abcdef";
|
|
put_char(output, symbols[byte >> 4]);
|
|
put_char(output, symbols[byte & 15]);
|
|
}
|
|
|
|
static const char *status_text(StreamStatus status) {
|
|
if (status == STREAM_EOF) return "EOF";
|
|
if (status == STREAM_LIMIT) return "LIMIT";
|
|
if (status == STREAM_OPEN_ERROR) return "OPEN_ERROR";
|
|
if (status == STREAM_READ_ERROR) return "READ_ERROR";
|
|
if (status == STREAM_CLOSE_ERROR) return "CLOSE_ERROR";
|
|
return "INVALID";
|
|
}
|
|
|
|
int stream_report_csv(const StreamResult *result, char *dst, size_t capacity) {
|
|
CsvBuffer output;
|
|
size_t index;
|
|
if (!result || !dst || !capacity) return -1;
|
|
output.data = dst;
|
|
output.size = capacity;
|
|
output.used = 0;
|
|
output.error = 0;
|
|
dst[0] = '\0';
|
|
put_text(&output, status_text(result->status));
|
|
put_column(&output, (unsigned long)result->error_number);
|
|
put_column(&output, (unsigned long)result->close_error_number);
|
|
put_column(&output, (unsigned long)result->length);
|
|
put_column(&output, result->read_attempts);
|
|
put_column(&output, result->interruption_count);
|
|
put_column(&output, result->short_reads);
|
|
put_column(&output, result->line_count);
|
|
put_column(&output, result->crlf_count);
|
|
put_column(&output, result->max_line_length);
|
|
put_column(&output, result->ascii_letters);
|
|
put_column(&output, result->ascii_digits);
|
|
put_column(&output, result->ascii_spaces);
|
|
put_column(&output, result->ascii_controls);
|
|
put_column(&output, result->ascii_other);
|
|
put_column(&output, result->byte_sum);
|
|
put_column(&output, result->runs);
|
|
put_column(&output, result->transition_count);
|
|
put_column(&output, result->longest_run);
|
|
put_column(&output, result->fnv1a);
|
|
put_column(&output, result->crc32);
|
|
for (index = 0; index < 16; ++index) {
|
|
put_column(&output, result->histogram[index]);
|
|
}
|
|
put_char(&output, ',');
|
|
for (index = 0; index < result->length && index < 256; ++index) {
|
|
put_hex(&output, result->prefix[index]);
|
|
}
|
|
put_char(&output, '\n');
|
|
return output.error ? -1 : (int)output.used;
|
|
}
|