summaryrefslogtreecommitdiffstats
path: root/src/lib.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2024-01-05 16:44:26 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2024-01-05 16:44:26 +0100
commitdd08d816dca127808b2343005ec8a728b6cb2a2a (patch)
treec9b0bd578e38ddb42570471adff4e3f117177a20 /src/lib.c
parent0.0.25 (diff)
downloadsear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.gz
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.bz2
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.lz
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.xz
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.tar.zst
sear.c-dd08d816dca127808b2343005ec8a728b6cb2a2a.zip
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/lib.c b/src/lib.c
index 2377ec9..62ddf84 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -46,18 +46,23 @@ void eachNodeX (htmlDocPtr doc, const char * xpath, node_function_t f, void * da
eachNode(nodes, f, data);
xmlXPathFreeObject(nodes);
}
-xmlNodePtr nthNodeXN (xmlNodePtr node, const char * xpath, int n) {
- xmlXPathObjectPtr nodes = findNodesN(node, xpath);
- if (!nodes)
- return NULL;
- xmlNodeSetPtr nodeset = nodes->nodesetval;
- int size = nodeset->nodeNr;
- if (size <= n)
- return NULL;
- xmlNodePtr toreturn = (xmlNodePtr) nodeset->nodeTab[n];
- xmlXPathFreeObject(nodes);
- return toreturn;
+#define nthNodeFunctionGenerator(type, x) \
+xmlNodePtr nthNodeX##x (type node, const char * xpath, int n) { \
+ xmlXPathObjectPtr nodes = findNodes##x(node, xpath); \
+ if (!nodes) \
+ return NULL; \
+ xmlNodeSetPtr nodeset = nodes->nodesetval; \
+ int size = nodeset->nodeNr; \
+ if (size <= n) { \
+ xmlXPathFreeObject(nodes); \
+ return NULL; \
+ } \
+ xmlNodePtr toreturn = (xmlNodePtr) nodeset->nodeTab[n]; \
+ xmlXPathFreeObject(nodes); \
+ return toreturn; \
}
+nthNodeFunctionGenerator(htmlDocPtr,) // this one gets doc
+nthNodeFunctionGenerator(xmlNodePtr, N)
#define EACHNODE(node, nodes) /* you can instead use eachNodeX with anonymous function - no need to free and findnodes separatl */ \
for (int EACHNODE_i = 0; \
nodes ? nodes->nodesetval ? \
@@ -110,6 +115,9 @@ char * htmlspecialchars (const char * i) { /* remember to free the output */
case '"':
w += sprintf(o+w, "&quot;");
break;
+ case '\'':
+ w += sprintf(o+w, "&apos;");
+ break;
default:
o[w++] = *i;
break;