This commit is contained in:
kento2 2026-09-04 19:59:24 +02:00
commit 55385f8857
69 changed files with 1125 additions and 0 deletions

44
strff/strff_read.c Normal file
View file

@ -0,0 +1,44 @@
#include "../strff.h"
#include <errno.h>
int strff_read(struct strff *strff, size_t buflen, char buf[buflen])
{
size_t nread;
int r;
char c;
int isnewline;
if (strff->fieldtype == STRFF_TYPE_NONE) {
errno = EINVAL; /* cannot read NONE field */
return -1;
}
isnewline = 1;
nread = 0;
while (nread < buflen) {
r = buffer_peekc(&strff->b, &c);
if (r < 0) return -1;
if (r == 0) {
if (isnewline && nread > 0)
nread--; /* remove last \n */
break;
}
if (strff->fieldtype == STRFF_TYPE_EQUAL && c == '\n')
break;
else if (strff->fieldtype == STRFF_TYPE_BRACKET) {
if (isnewline && c == '[') {
if (nread > 0)
nread--; /* remove last \n */
break;
}
isnewline = 0;
if (c == '\n')
isnewline = 1;
}
buf[nread++] = c;
strff->b.p++;
}
return nread;
}