#include "input.h" enum { LIBSCOMP_READ, LIBSCOMP_DISCARD }; void libscomp_reset(struct libscomp_input *in) { in->state = LIBSCOMP_READ; in->len = 0; } static enum libscomp_input_r libscomp_parse( struct libscomp_input *in, struct libscomp_line *line) { char *s = in->intbuf; enum libscomp_input_r r = LIBSCOMP_ARG_OVERFLOW; line->name = (*s == ':'); line->len = 0; while (line->len < LIBSCOMP_MAXARG) { line->buf[line->len++] = s; for (; *s && *s != '\t'; s++); if (!*s) { r = LIBSCOMP_COMPLETE; break; } else { *s = 0; s++; } } libscomp_reset(in); return r; } enum libscomp_input_r libscomp_read(struct libscomp_input *in, char **s, struct libscomp_line *line) { char c; while ((c = **s)) { (*s)++; if (in->state == LIBSCOMP_DISCARD) { if (c == '\n') { libscomp_reset(in); return LIBSCOMP_OVERFLOW; } } else { switch (c) { case '\n': in->intbuf[in->len] = 0; return libscomp_parse(in, line); default: in->intbuf[in->len++] = c; if (in->len == LIBSCOMP_MAXBUF) in->state = LIBSCOMP_DISCARD; } } } return LIBSCOMP_MORE; }