input: switch inbuf to char double pointer

This commit is contained in:
Peter McGoron 2021-07-10 15:17:56 -04:00
parent b7ca22ba79
commit 2accea96f0
3 changed files with 22 additions and 12 deletions

View File

@ -30,13 +30,12 @@ static enum libscomm_input_r parse(struct libscomm_input *in,
}
enum libscomm_input_r libscomm_read(struct libscomm_input *in,
struct libscomm_inbuf *buf,
char **s,
struct libscomm_line *line) {
char c;
while (buf->l > 0) {
buf->l--;
c = *buf->s++;
while ((c = **s)) {
(*s)++;
if (in->state == DISCARD) {
if (c == '\n') {

View File

@ -10,11 +10,6 @@ struct libscomm_line {
size_t len;
};
struct libscomm_inbuf {
const char *s;
size_t l;
};
struct libscomm_input {
int state;
@ -31,5 +26,5 @@ enum libscomm_input_r {
void libscomm_reset(struct libscomm_input *);
enum libscomm_input_r libscomm_read(struct libscomm_input *,
struct libscomm_inbuf *,
char **,
struct libscomm_line *);

View File

@ -5,13 +5,16 @@
TEST one_pass(void) {
struct libscomm_input in;
struct libscomm_inbuf b = s("Arg 1\tArg \r\v\t!\n");
char s[] = "Arg 1\tArg \r\v\t!\n";
char *p = s;
struct libscomm_line l;
libscomm_reset(&in);
ASSERT_EQ(libscomm_read(&in, &b, &l), LIBSCOMM_COMPLETE);
ASSERT_EQ(libscomm_read(&in, &p, &l), LIBSCOMM_COMPLETE);
ASSERT_EQ(l.len, 3);
ASSERT_EQ(l.name, 0);
ASSERT_EQ(*p, 0);
ASSERT_EQ(p, &s[sizeof s - 1]);
ASSERT_STR_EQ(l.buf[0], "Arg 1");
ASSERT_STR_EQ(l.buf[1], "Arg \r\v");
@ -20,6 +23,19 @@ TEST one_pass(void) {
PASS();
}
#if 0
TEST single_arg_too_large(void) {
struct libscomm_input in;
struct libscomm_inbuf b;
struct libscomm_line l;
char s[LIBSCOMM_MAXBUF + 12];
size_t i;
for (i = 0; i < sizeof s; i++)
s[i] = 'a';
}
#endif
GREATEST_MAIN_DEFS();
int main(int argc, char *argv[]) {