support infinite length titles, no buffering - grabtitle - stupid HTML title gr… | |
git clone git://git.codemadness.org/grabtitle | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 0af2d13062af1f2bb254de507233ed28e8f8c459 | |
parent 239ce1bd6d3855175866412b2d9b8c64ddf80930 | |
Author: Hiltjo Posthuma <[email protected]> | |
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(-) | |
--- | |
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 isshor… | |
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 |