commit 27dce34fb57e3639875005f21f7ed651fad9c2db from: Omar Polo date: Tue Jul 06 18:19:52 2021 UTC drop the in_body field and use a bit in the flags field commit - c0b634ddc444df1c2391e8262cf707e4422287a6 commit + 27dce34fb57e3639875005f21f7ed651fad9c2db blob - 75fbbfd2af004a74260964309e270c81b3519b15 blob + ffff9bad5b5abbed54e6cd22bc6c0d1d5350ddbf --- gemtext.c +++ gemtext.c @@ -362,11 +362,11 @@ gemtext_foreach_line(struct parser *p, const char *lin { enum line_type t; - t = detect_line_type(line, linelen, p->flags); + t = detect_line_type(line, linelen, p->flags & PARSER_IN_PRE); if (t == LINE_PRE_START) - p->flags = 1; + p->flags ^= PARSER_IN_PRE; if (t == LINE_PRE_END) - p->flags = 0; + p->flags ^= PARSER_IN_PRE; return parsers[t](p, t, line, linelen); } @@ -377,10 +377,11 @@ gemtext_free(struct parser *p) /* flush the buffer */ if (p->len != 0) { - t = detect_line_type(p->buf, p->len, p->flags); + t = detect_line_type(p->buf, p->len, p->flags & PARSER_IN_PRE); if (!parsers[t](p, t, p->buf, p->len)) return 0; - if (p->flags && !emit_line(p, LINE_PRE_END, NULL, NULL)) + if ((p->flags & PARSER_IN_PRE) && + !emit_line(p, LINE_PRE_END, NULL, NULL)) return 0; } blob - 0434603c519c7ff93382ba4dc6e6f938b55a2ad2 blob + ff6e96006043734d2287e6f8b03e476e9280c979 --- parser.c +++ parser.c @@ -75,11 +75,11 @@ parser_foreach_line(struct parser *p, const char *buf, b = p->buf; len = p->len; - if (!p->in_body && len < 3) + if (!(p->flags & PARSER_IN_BODY) && len < 3) return 1; - if (!p->in_body) { - p->in_body = 1; + if (!(p->flags & PARSER_IN_BODY)) { + p->flags |= PARSER_IN_BODY; /* * drop the BOM: only UTF-8 is supported, and there blob - c0397fc1e674ee0325c190c22d9ef8a6b70529ca blob + c3bf19a86c41d7b406d8c52f127e5b90e1afa5d1 --- telescope.h +++ telescope.h @@ -158,9 +158,11 @@ struct parser { const char *name; char title[32+1]; char *buf; - int in_body; /* used to deal with BOM */ size_t len; size_t cap; + +#define PARSER_IN_BODY 1 +#define PARSER_IN_PRE 2 int flags; parsechunkfn parse; parserfreefn free;