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>
100 lines
2.1 KiB
C
100 lines
2.1 KiB
C
#include "line_port.h"
|
|
#include <string.h>
|
|
|
|
static int source_valid(struct lp_source source)
|
|
{
|
|
if (source.read == NULL) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int lp_cursor_init(struct lp_cursor *cursor, struct lp_source source)
|
|
{
|
|
if (cursor == NULL) {
|
|
return LP_ARGUMENT;
|
|
}
|
|
memset(cursor, 0, sizeof(*cursor));
|
|
if (!source_valid(source)) {
|
|
cursor->terminal = LP_ARGUMENT;
|
|
return LP_ARGUMENT;
|
|
}
|
|
cursor->source = source;
|
|
return LP_END;
|
|
}
|
|
|
|
static int refill(struct lp_cursor *cursor)
|
|
{
|
|
size_t amount = 0;
|
|
int status;
|
|
if (cursor->terminal != 0) {
|
|
return cursor->terminal;
|
|
}
|
|
cursor->begin = 0;
|
|
cursor->end = 0;
|
|
status = cursor->source.read(cursor->source.context, cursor->cache,
|
|
1, &amount);
|
|
if (status < 0) {
|
|
cursor->terminal = LP_IO;
|
|
return LP_IO;
|
|
}
|
|
if (amount > sizeof(cursor->cache)) {
|
|
cursor->terminal = LP_IO;
|
|
return LP_IO;
|
|
}
|
|
if (status == 0) {
|
|
if (amount != 0) {
|
|
cursor->terminal = LP_IO;
|
|
return LP_IO;
|
|
}
|
|
cursor->terminal = 2;
|
|
return LP_END;
|
|
}
|
|
if (amount == 0) {
|
|
cursor->terminal = LP_IO;
|
|
return LP_IO;
|
|
}
|
|
cursor->end = amount;
|
|
return LP_OK;
|
|
}
|
|
|
|
int lp_cursor_next(struct lp_cursor *cursor, unsigned char *value)
|
|
{
|
|
int status;
|
|
if (cursor == NULL || value == NULL) {
|
|
return LP_ARGUMENT;
|
|
}
|
|
if (cursor->begin == cursor->end) {
|
|
if (cursor->terminal == 2) {
|
|
return LP_END;
|
|
}
|
|
status = refill(cursor);
|
|
if (status != LP_OK) {
|
|
return status;
|
|
}
|
|
}
|
|
*value = cursor->cache[cursor->begin];
|
|
cursor->begin += 1;
|
|
cursor->delivered += 1;
|
|
return LP_OK;
|
|
}
|
|
|
|
size_t lp_cursor_delivered(const struct lp_cursor *cursor)
|
|
{
|
|
if (cursor == NULL) {
|
|
return 0;
|
|
}
|
|
return cursor->delivered;
|
|
}
|
|
|
|
int lp_cursor_terminal(const struct lp_cursor *cursor)
|
|
{
|
|
if (cursor == NULL) {
|
|
return LP_ARGUMENT;
|
|
}
|
|
if (cursor->terminal == 2) {
|
|
return LP_END;
|
|
}
|
|
return cursor->terminal;
|
|
}
|