ref: 47a288683dbdc55c5df9b9f65db9909de6021af0
dir: /libxpath/fns.c/
#include <u.h>
#include <libc.h>
#include <xml.h>
#include <xpath.h>
#include "dat.h"
int
position(Elem *e)
{
Elem *p;
p = e->parent;
int i;
i = 0;
for (p = p->child; p; p = p->next) {
if (strcmp(p->name, e->name) == 0)
i++;
if (p == e)
return i;
}
return i;
}
int
last(Elem *e)
{
Elem *p;
p = e->parent;
int i;
i = 0;
for (p = p->child; p; p = p->next) {
if (strcmp(p->name, e->name) == 0)
i++;
}
return i;
}
void
ftext(XpResult *r, Elem *ep)
{
buildsinglestring(r, ep->pcdata);
}
void
fposition(XpResult *r, Elem *ep)
{
buildsinglenum(r, position(ep));
}
void
fprocinst(XpResult *r, Elem *ep)
{
fprint(2, "function processing-instruction()");
}
void
fcomment(XpResult *r, Elem *ep)
{
fprint(2, "function comment()");
}
void
fnode(XpResult *r, Elem *ep)
{
buildsingleelem(r, ep);
}
void
flast(XpResult *r, Elem *ep)
{
buildsinglenum(r, last(ep));
}
void
initfuncs()
{
#define F(name, func) addfunc(addname(name), func)
F("text", ftext);
F("position", fposition);
F("processing-instruction", fprocinst);
F("comment", fcomment);
F("node", fnode);
F("last", flast);
#undef F
}