trefactor bsearch to findtag() - webdump - [FORK] git://git.codemadness.org/webdump
HTML git clone git://git.z3bra.org/webdump.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit a7a2ba6114f500856fbe532006fb15d9a18f5e2f
DIR parent a49448ef41b7d425b1b7c5a29119f52d1c735cd5
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 9 Dec 2019 19:05:27 +0100
refactor bsearch to findtag()
Diffstat:
M webdump.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
---
DIR diff --git a/webdump.c b/webdump.c
t@@ -579,10 +579,20 @@ tagcmp(const void *v1, const void *v2)
return strcasecmp(t1->name, t2->name);
}
+struct tag *
+findtag(const char *t)
+{
+ struct tag find;
+
+ find.name = t;
+ return bsearch(&find, tags, sizeof(tags) / sizeof(*tags),
+ sizeof(*tags), tagcmp);
+}
+
static void
xmltagstart(XMLParser *x, const char *t, size_t tl)
{
- struct tag find, *found;
+ struct tag *found;
struct node *cur;
if (curnode >= MAX_DEPTH - 2)
t@@ -597,10 +607,7 @@ xmltagstart(XMLParser *x, const char *t, size_t tl)
src[0] = '\0'; /* src, href */
/* match tag */
- find.name = t;
- found = bsearch(&find, tags, sizeof(tags) / sizeof(*tags),
- sizeof(*tags), tagcmp);
- if (found) {
+ if ((found = findtag(t))) {
cur->nchildren = 0;
memcpy(&(cur->tag), found, sizeof(*found));
return;