support infinite length titles, no buffering - grabtitle - stupid HTML title grabber
(HTM) git clone git://git.codemadness.org/grabtitle
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 0af2d13062af1f2bb254de507233ed28e8f8c459
(DIR) parent 239ce1bd6d3855175866412b2d9b8c64ddf80930
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sat, 31 Mar 2018 16:35:56 +0200
support infinite length titles, no buffering
Diffstat:
M grabtitle.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
---
(DIR) diff --git a/grabtitle.c b/grabtitle.c
@@ -16,8 +16,7 @@
#endif
static XMLParser parser;
-static int istitle, titlelen;
-static char title[4096];
+static int istitle;
static void
xmltagstart(XMLParser *p, const char *t, size_t tl)
@@ -30,7 +29,7 @@ static void
xmltagend(XMLParser *p, const char *t, size_t tl, int isshort)
{
if (istitle && tl == 5 && !strcasecmp(t, "title")) {
- puts(title);
+ putchar('\n');
exit(0);
}
}
@@ -39,11 +38,9 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort)
static void
xmldata(XMLParser *p, const char *d, size_t dl)
{
- if (!istitle || titlelen + dl + 1 >= sizeof(title))
+ if (!istitle)
return;
- memcpy(title + titlelen, d, dl);
- titlelen += dl;
- title[titlelen] = '\0';
+ fwrite(d, 1, dl, stdout);
}
static void
@@ -55,16 +52,10 @@ xmldataentity(XMLParser *p, const char *d, size_t dl)
if (!istitle)
return;
- if ((len = xml_entitytostr(d, buf, sizeof(buf)))) {
- d = buf;
- dl = len;
- }
-
- if (titlelen + dl + 1 >= sizeof(title))
- return;
- memcpy(title + titlelen, d, dl);
- titlelen += dl;
- title[titlelen] = '\0';
+ if ((len = xml_entitytostr(d, buf, sizeof(buf))))
+ fwrite(buf, 1, len, stdout);
+ else
+ fwrite(d, 1, dl, stdout);
}
int