sync title parsing from webdump - grabtitle - stupid HTML title grabber
HTML git clone git://git.codemadness.org/grabtitle
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 4fae8cbe5b9ae3180da8ed9ae57bdc1a1559ab93
DIR parent c8065914188f9407353c5e64eef22c170d76ef23
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 13 Jul 2026 21:20:24 +0200
sync title parsing from webdump
Diffstat:
M grabtitle.c | 58 +++++++++++++++---------------
1 file changed, 29 insertions(+), 29 deletions(-)
---
DIR diff --git a/grabtitle.c b/grabtitle.c
@@ -47,9 +47,9 @@ static int
getnext_literal(void)
{
char *p;
- int c, fullmatch;
+ int c;
- /* there is data in the pushback buffer */
+ /* check if there is data in the pushback buffer: process it first. */
if (pushend != pushbuf) {
if (pushoff >= pushend) {
/* reached the offset where the tag ended */
@@ -58,7 +58,8 @@ getnext_literal(void)
getnext_literal_end();
return c; /* end tag */
}
- getnext_literal_reset(); /* reset pushback buffer */
+ /* otherwise reached the end of pushback buffer, proceed normally */
+ getnext_literal_reset();
} else {
return (int)*(pushoff++);
}
@@ -71,40 +72,39 @@ getnext_literal(void)
break;
}
+ /* typical case: regular character */
+ if (ignorestate == endtagmatch)
+ return c;
+
/* process a partial or full match on the tag:
- partial: handle "<" as a data entity "<", full: handle as end tag */
- if (ignorestate != endtagmatch) {
- fullmatch = (*ignorestate == '\0');
- pushoff = pushbuf;
- pushend = pushbuf;
- /* buffer not checked, it should alway fit. */
- if (fullmatch) {
- for (p = endtagmatch; *p && p < ignorestate; p++)
- *(pushend++) = *p;
- pushtagend = pushend; /* offset where the tag ended */
- } else {
- for (p = endtagmatch; *p && p < ignorestate; p++) {
- if (!fullmatch && *p == '<') {
- memcpy(pushend, "<", 4);
- pushend += 4;
- } else {
- *(pushend++) = *p;
- }
- }
- /* append current character to end of pushback buffer */
- if (c == '<') {
+ full: handle as end tag. partial: handle "<" as a data entity "<".
+ buffers are not checked, they always fit (size of tag + space for at least "<<"). */
+ pushoff = pushbuf;
+ pushend = pushbuf;
+ if (*ignorestate == '\0') { /* full match */
+ for (p = endtagmatch; *p && p < ignorestate; p++)
+ *(pushend++) = *p;
+ pushtagend = pushend; /* offset where the tag ended */
+ } else { /* partial match */
+ for (p = endtagmatch; *p && p < ignorestate; p++) {
+ if (*p == '<') {
memcpy(pushend, "<", 4);
pushend += 4;
} else {
- *(pushend++) = c;
+ *(pushend++) = *p;
}
}
- ignorestate = endtagmatch; /* reset state for matching to beginning */
-
- return (int)*(pushoff++);
+ /* append current character to end of pushback buffer */
+ if (c == '<') {
+ memcpy(pushend, "<", 4);
+ pushend += 4;
+ } else {
+ *(pushend++) = c;
+ }
}
+ ignorestate = endtagmatch; /* reset state for matching to beginning */
- return c;
+ return (int)*(pushoff++); /* first character in pushback buffer, always exists */
}
static void