amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

126 lines
2.9 KiB
C

#include "line_port.h"
#include <stdint.h>
int lp_line_init(struct lp_line *line, size_t maximum,
struct lp_allocator allocator)
{
if (line == NULL) {
return LP_ARGUMENT;
}
line->data = NULL;
line->length = 0;
line->capacity = 0;
line->maximum = maximum;
line->allocator = allocator;
if (maximum == 0 || maximum > 65536 || allocator.resize == NULL ||
allocator.release == NULL) {
return LP_ARGUMENT;
}
return LP_END;
}
int lp_line_reserve(struct lp_line *line, size_t needed)
{
size_t capacity;
unsigned char *replacement;
if (line == NULL || needed > line->maximum + 1) {
return LP_ARGUMENT;
}
if (needed <= line->capacity) {
return LP_END;
}
capacity = line->capacity;
if (capacity == 0) {
capacity = 16;
}
while (capacity < needed) {
if (capacity > (line->maximum + 1) / 2) {
capacity = line->maximum + 1;
break;
}
capacity *= 2;
}
if (capacity > line->maximum + 1) {
capacity = line->maximum + 1;
}
replacement = line->allocator.resize(line->allocator.context,
line->data, capacity);
if (replacement == NULL) {
return LP_MEMORY;
}
line->data = replacement;
line->capacity = capacity;
return LP_END;
}
int lp_line_append(struct lp_line *line, unsigned char value)
{
int status;
if (line == NULL) {
return LP_ARGUMENT;
}
if (line->length >= line->maximum) {
return LP_LIMIT;
}
status = lp_line_reserve(line, line->length + 2);
if (status != LP_END) {
return status;
}
line->data[line->length] = value;
line->length += 1;
line->data[line->length] = 0;
return LP_END;
}
void lp_line_clear(struct lp_line *line)
{
if (line == NULL) {
return;
}
line->length = 0;
if (line->data != NULL) {
line->data[0] = 0;
}
}
int lp_line_read(struct lp_line *line, struct lp_cursor *cursor)
{
unsigned char value;
int status;
if (line == NULL || cursor == NULL) {
return LP_ARGUMENT;
}
lp_line_clear(line);
for (;;) {
status = lp_cursor_next(cursor, &value);
if (status == LP_END) {
return line->length == 0 ? LP_END : LP_OK;
}
if (status != LP_OK) {
lp_line_clear(line);
return status;
}
status = lp_line_append(line, value);
if (status != LP_END) {
lp_line_clear(line);
return status;
}
if (value == '\n') {
return LP_OK;
}
}
}
void lp_line_destroy(struct lp_line *line)
{
if (line == NULL) {
return;
}
if (line->data != NULL) {
line->allocator.release(line->allocator.context, line->data);
}
line->data = NULL;
line->length = 0;
line->capacity = 0;
}