2008-07-06 11:34:50 +00:00
|
|
|
/* Copyright (c) 2007, 2008 by Adalin B.V.
|
|
|
|
* Copyright (c) 2007, 2008 by Erik Hofman
|
2008-06-29 13:08:24 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of (any of) the copyrightholder(s) nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HANDLE m;
|
|
|
|
void *p;
|
|
|
|
} SIMPLE_UNMMAP;
|
|
|
|
|
|
|
|
static SIMPLE_UNMMAP un;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* map 'filename' and return a pointer to it.
|
|
|
|
*/
|
|
|
|
void *simple_mmap(int, unsigned int, SIMPLE_UNMMAP *);
|
|
|
|
void simple_unmmap(SIMPLE_UNMMAP *);
|
|
|
|
|
|
|
|
#define mmap(a,b,c,d,e,f) simple_mmap((e), (b), &un)
|
|
|
|
#define munmap(a,b) simple_unmmap(&un)
|
|
|
|
|
|
|
|
#else /* !WIN32 */
|
|
|
|
# include <sys/mman.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2008-07-19 12:18:05 +00:00
|
|
|
#include <assert.h>
|
2008-06-29 13:08:24 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
struct _xml_id
|
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *name;
|
2008-06-29 13:08:24 +00:00
|
|
|
char *start;
|
|
|
|
size_t len;
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char *__xmlCopyNode(char *, size_t, const char *);
|
2008-07-20 09:38:53 +00:00
|
|
|
static char *__xmlGetNode(const char *, size_t *, char **, size_t *, int *);
|
|
|
|
static char *__xmlGetNodePath(const char *, size_t *, char **, size_t *);
|
2008-07-19 12:18:05 +00:00
|
|
|
static char *__xmlSkipComment(const char *, size_t);
|
|
|
|
static char *__xmlSkipInfo(const char *, size_t);
|
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
static void *__xml_memmem(const void *, size_t, const void *, size_t);
|
2008-07-21 12:32:22 +00:00
|
|
|
static void *__xml_memncasecmp(const void *, size_t *, void **, size_t *);
|
2008-07-19 12:18:05 +00:00
|
|
|
static void *__xml_memchr(const void *, int, size_t);
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
#define PRINT(a, b, c) { \
|
|
|
|
if (a) { \
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t q, len = c; \
|
|
|
|
if (b < c) len = b; \
|
|
|
|
if (len < 50000) { \
|
|
|
|
printf("(%i) '", len); \
|
|
|
|
for (q=0; q<len; q++) printf("%c", ((char *)(a))[q]); \
|
|
|
|
printf("'\n"); \
|
|
|
|
} else printf("Length (%u) seems too large at line %i\n",len, __LINE__); \
|
2008-07-06 11:34:50 +00:00
|
|
|
} else printf("NULL pointer at line %i\n", __LINE__); \
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
xmlOpen(char *fn)
|
|
|
|
{
|
|
|
|
struct _xml_id *id = 0;
|
|
|
|
|
|
|
|
if (fn)
|
|
|
|
{
|
|
|
|
int fd = open(fn, O_RDONLY);
|
|
|
|
if (fd > 0)
|
|
|
|
{
|
|
|
|
id = malloc(sizeof(struct _xml_id));
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
fstat(fd, &statbuf);
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
id->nlen = (size_t)fd;
|
2008-06-29 13:08:24 +00:00
|
|
|
id->len = statbuf.st_size;
|
|
|
|
id->start = mmap(0, id->len, PROT_READ, MAP_PRIVATE, fd, 0L);
|
2008-07-20 09:38:53 +00:00
|
|
|
id->name = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void*)id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xmlClose(void *id)
|
|
|
|
{
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-20 09:38:53 +00:00
|
|
|
assert(xid->name == 0);
|
|
|
|
|
2008-06-29 13:08:24 +00:00
|
|
|
munmap(xid->start, xid->len);
|
2008-07-20 09:38:53 +00:00
|
|
|
close((int)xid->nlen);
|
2008-06-29 13:08:24 +00:00
|
|
|
free(id);
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlCopyNode(const void *id, char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xsid = 0;
|
|
|
|
|
|
|
|
if (id && path)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ptr, *node, *p;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t slen, len;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
node = path;
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
ptr = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (ptr)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
xsid = malloc(sizeof(struct _xml_id) + len);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (xsid)
|
|
|
|
{
|
|
|
|
p = (char *)xsid + sizeof(struct _xml_id);
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
xsid->len = len;
|
2008-06-29 13:08:24 +00:00
|
|
|
xsid->start = p;
|
2008-07-20 09:38:53 +00:00
|
|
|
xsid->nlen = slen;
|
|
|
|
xsid->name = node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
memcpy(xsid->start, ptr, len);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void *)xsid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNode(const void *id, char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xsid = 0;
|
|
|
|
|
|
|
|
if (id && path)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ptr, *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
node = path;
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
ptr = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
xsid = malloc(sizeof(struct _xml_id));
|
2008-07-20 09:38:53 +00:00
|
|
|
if (xsid)
|
|
|
|
{
|
|
|
|
xsid->len = len;
|
|
|
|
xsid->start = ptr;
|
|
|
|
xsid->nlen = slen;
|
|
|
|
xsid->name = node;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void *)xsid;
|
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
char *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNodeName(const void *id)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-21 12:32:22 +00:00
|
|
|
size_t len;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ret;
|
|
|
|
|
2008-07-21 12:32:22 +00:00
|
|
|
len = xid->nlen;
|
|
|
|
ret = malloc(len+1);
|
2008-07-20 09:38:53 +00:00
|
|
|
if (ret)
|
|
|
|
{
|
2008-07-21 12:32:22 +00:00
|
|
|
memcpy(ret, xid->name, len);
|
|
|
|
*(ret + len) = 0;
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlCopyNodeName(const void *id, const char *buf, size_t len)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t slen = 0;
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
slen = len-1;
|
|
|
|
if (slen > xid->nlen) slen = xid->nlen;
|
|
|
|
memcpy((char *)buf, xid->name, slen);
|
2008-07-21 12:32:22 +00:00
|
|
|
*((char *)buf + slen) = 0;
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
2008-07-21 12:32:22 +00:00
|
|
|
|
|
|
|
return slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-07-19 12:18:05 +00:00
|
|
|
xmlGetNodeNum(const void *rid, void *id, char *element, int num)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
struct _xml_id *xrid = (struct _xml_id *)rid;
|
2008-07-20 09:38:53 +00:00
|
|
|
void *ret = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
if (id && element)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ptr, *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xrid->len;
|
|
|
|
slen = strlen(element);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = element;
|
|
|
|
ptr = __xmlGetNode(xrid->start, &len, &node, &slen, &num);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (ptr)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
xid->len = len;
|
2008-06-29 13:08:24 +00:00
|
|
|
xid->start = ptr;
|
2008-07-20 09:38:53 +00:00
|
|
|
xid->name = node;
|
|
|
|
xid->nlen = slen;
|
|
|
|
ret = xid;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-06 11:34:50 +00:00
|
|
|
return ret;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xmlCompareString(const void *id, const char *s)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (xid && xid->len && s && (strlen(s) > 0))
|
|
|
|
{
|
2008-07-01 12:15:46 +00:00
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
ps = xid->start;
|
|
|
|
pe = ps + xid->len;
|
|
|
|
pe--;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
pe++;
|
|
|
|
|
|
|
|
ret = strncasecmp(ps, s, pe-ps);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xmlCompareNodeString(const void *id, const char *path, const char *s)
|
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (xid && xid->len && path && s && (strlen(s) > 0))
|
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *node, *str, *ps, *pe;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
|
|
|
str = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
ps = str;
|
|
|
|
pe = ps + len;
|
|
|
|
pe--;
|
2008-07-01 12:15:46 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
pe++;
|
2008-07-01 12:15:46 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
ret = strncasecmp(pe, s, pe-ps);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNodeString(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
char *str = 0;
|
|
|
|
|
|
|
|
if (xid && xid->len && path)
|
|
|
|
{
|
|
|
|
str = __xmlCopyNode(xid->start, xid->len, path);
|
|
|
|
if (str)
|
|
|
|
{
|
2008-07-01 12:15:46 +00:00
|
|
|
char *ps, *pe, *pend;
|
2008-06-29 13:08:24 +00:00
|
|
|
int slen;
|
|
|
|
|
|
|
|
ps = str;
|
2008-07-20 09:38:53 +00:00
|
|
|
slen = strlen(str);
|
2008-07-01 12:15:46 +00:00
|
|
|
pend = ps+slen;
|
|
|
|
pe = pend-1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
|
2008-07-01 12:15:46 +00:00
|
|
|
*++pe = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
slen = (pe-ps);
|
2008-07-01 12:15:46 +00:00
|
|
|
if (slen && (ps>str)) memmove(str, ps, slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
else if (!slen) *str = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetString(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
char *str = 0;
|
|
|
|
|
|
|
|
if (xid && xid->len)
|
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *ps, *pe, *pend;
|
|
|
|
int nlen;
|
|
|
|
|
|
|
|
ps = xid->start;
|
|
|
|
nlen = xid->len;
|
|
|
|
pend = ps+nlen;
|
|
|
|
pe = pend;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
nlen = (pe-ps);
|
|
|
|
if (nlen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
str = malloc(nlen+1);
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
memcpy(str, ps, nlen);
|
|
|
|
*(str+nlen) = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
return str;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlCopyString(const void *id, char *buf, size_t len)
|
2008-07-20 09:38:53 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
size_t nlen = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
if (xid && xid->len && buf && len)
|
|
|
|
{
|
|
|
|
char *ps, *pe, *pend;
|
|
|
|
int slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
nlen = len-1;
|
|
|
|
ps = xid->start;
|
|
|
|
slen = xid->len;
|
|
|
|
pend = ps+slen;
|
|
|
|
pe = pend;
|
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
nlen = (pe-ps);
|
|
|
|
if (nlen > slen) nlen = slen;
|
|
|
|
|
|
|
|
if (nlen)
|
|
|
|
{
|
|
|
|
memcpy(buf, ps, nlen);
|
|
|
|
*(buf+nlen) = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
return nlen;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlCopyNodeString(const void *id, const char *path, char *buffer, size_t buflen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-20 09:38:53 +00:00
|
|
|
size_t len = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
if (xid && xid->len && path && buffer && buflen)
|
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *str, *node;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
*buffer = 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
|
|
|
str = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *ps, *pe;
|
|
|
|
|
|
|
|
ps = str;
|
2008-07-19 12:18:05 +00:00
|
|
|
pe = ps+len-1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
while ((ps<pe) && isspace(*ps)) ps++;
|
|
|
|
while ((pe>ps) && isspace(*pe)) pe--;
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = (pe-ps)+1;
|
|
|
|
if (len >= buflen) len = buflen-1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
memcpy(buffer, ps, len);
|
|
|
|
str = buffer + len;
|
2008-06-29 13:08:24 +00:00
|
|
|
*str = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return len;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long int
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNodeInt(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
long int li = 0;
|
|
|
|
|
|
|
|
if (path && xid && xid->len)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *str, *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
|
|
|
str = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *end = str+len;
|
|
|
|
li = strtol(str, &end, 10);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
|
|
|
long int
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetInt(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
long int li = 0;
|
|
|
|
|
|
|
|
if (xid && xid->len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *end = xid->start + xid->len;
|
|
|
|
li = strtol(xid->start, &end, 10);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNodeDouble(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
double d = 0.0;
|
|
|
|
|
|
|
|
if (path && xid && xid->len)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t len, slen;
|
2008-07-20 09:38:53 +00:00
|
|
|
char *str, *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
|
|
|
str = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
char *end = str+len;
|
|
|
|
d = strtod(str, &end);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetDouble(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
|
|
|
double d = 0.0;
|
|
|
|
|
|
|
|
if (xid && xid->len)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *end = xid->start + xid->len;
|
|
|
|
d = strtod(xid->start, &end);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlGetNumNodes(const void *id, const char *path)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xid = (struct _xml_id *)id;
|
2008-07-19 12:18:05 +00:00
|
|
|
unsigned num = 0;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
if (xid && xid->len && path)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
char *nodename, *pathname;
|
|
|
|
size_t len, slen;
|
|
|
|
char *p;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
nodename = (char *)path;
|
|
|
|
if (*path == '/') nodename++;
|
|
|
|
slen = strlen(nodename);
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
pathname = strchr(nodename, '/');
|
|
|
|
if (pathname)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *node;
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
|
|
|
pathname++;
|
|
|
|
slen -= pathname-nodename;
|
2008-07-20 09:38:53 +00:00
|
|
|
node = pathname;
|
|
|
|
p = __xmlGetNodePath(xid->start, &len, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = (char *)xid->start;
|
2008-07-19 12:18:05 +00:00
|
|
|
len = xid->len;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
char *node = nodename;
|
|
|
|
__xmlGetNode(p, &len, &node, &slen, &num);
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return num;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-07-21 12:32:22 +00:00
|
|
|
xmlMarkId(const void *id)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
|
|
|
struct _xml_id *xmid = 0;
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
xmid = malloc(sizeof(struct _xml_id));
|
|
|
|
if (xmid)
|
|
|
|
{
|
|
|
|
memcpy(xmid, id, sizeof(struct _xml_id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void *)xmid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
static char *
|
2008-06-29 13:08:24 +00:00
|
|
|
__xmlCopyNode(char *start, size_t len, const char *path)
|
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *node, *p, *ret = 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t rlen, slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
rlen = len;
|
|
|
|
slen = strlen(path);
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)path;
|
|
|
|
p = __xmlGetNodePath(start, &rlen, &node, &slen);
|
2008-06-29 13:08:24 +00:00
|
|
|
if (p && rlen)
|
|
|
|
{
|
|
|
|
ret = calloc(1, rlen+1);
|
|
|
|
memcpy(ret, p, rlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-07-20 09:38:53 +00:00
|
|
|
__xmlGetNodePath(const char *start, size_t *len, char **name, size_t *plen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
char *node;
|
2008-06-29 13:08:24 +00:00
|
|
|
char *ret = 0;
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
assert (start != 0);
|
|
|
|
assert (len != 0);
|
|
|
|
assert (name != 0);
|
2008-07-20 09:38:53 +00:00
|
|
|
assert (*name != 0);
|
2008-07-19 12:18:05 +00:00
|
|
|
assert (plen != 0);
|
|
|
|
|
|
|
|
if ((*len == 0) || (*plen == 0) || (*plen > *len))
|
|
|
|
return 0;
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
node = (char *)*name;
|
|
|
|
if (*node == '/') node++;
|
|
|
|
if (*node != 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t plen, slen;
|
|
|
|
char *path;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
slen = strlen(node);
|
|
|
|
path = strchr(node, '/');
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
if (!path) plen = slen;
|
|
|
|
else plen = path++ - node;
|
|
|
|
|
|
|
|
num = 0;
|
2008-07-20 09:38:53 +00:00
|
|
|
ret = __xmlGetNode(start, len, &node, &plen, &num);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (ret && path)
|
2008-07-01 12:15:46 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
plen = slen - (path - *name);
|
|
|
|
ret = __xmlGetNodePath(ret, len, &path, &plen);
|
2008-07-01 12:15:46 +00:00
|
|
|
}
|
2008-07-20 09:38:53 +00:00
|
|
|
|
|
|
|
*name = path;
|
2008-07-19 12:18:05 +00:00
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2008-07-20 09:38:53 +00:00
|
|
|
__xmlGetNode(const char *start, size_t *len, char **name, size_t *rlen, int *nodenum)
|
2008-07-19 12:18:05 +00:00
|
|
|
{
|
|
|
|
char *new, *cur, *ne, *ret = 0;
|
|
|
|
size_t restlen, elementlen;
|
2008-07-21 12:32:22 +00:00
|
|
|
size_t retlen = 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
int found, num;
|
|
|
|
void *element;
|
|
|
|
|
|
|
|
assert (start != 0);
|
|
|
|
assert (len != 0);
|
|
|
|
assert (name != 0);
|
2008-07-20 09:38:53 +00:00
|
|
|
assert (*name != 0);
|
2008-07-19 12:18:05 +00:00
|
|
|
assert (rlen != 0);
|
|
|
|
assert (nodenum != 0);
|
|
|
|
|
|
|
|
if ((*len == 0) || (*rlen == 0) || (*rlen > *len))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
num = *nodenum;
|
|
|
|
restlen = *len;
|
|
|
|
cur = (char *)start;
|
|
|
|
ne = cur + restlen;
|
|
|
|
|
|
|
|
while ((new = memchr(cur, '<', restlen)) != 0)
|
|
|
|
{
|
|
|
|
if (*(new+1) == '/') /* cascading closing tag found */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
*len -= restlen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
new++;
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
|
|
|
|
if (*cur == '!')
|
|
|
|
{
|
|
|
|
new = __xmlSkipComment(cur, restlen);
|
|
|
|
if (!new) return 0;
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (*cur == '?')
|
|
|
|
{
|
|
|
|
new = __xmlSkipInfo(cur, restlen);
|
|
|
|
if (!new) return 0;
|
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
element = (char *)*name;
|
2008-07-19 12:18:05 +00:00
|
|
|
elementlen = *rlen;
|
|
|
|
new = __xml_memncasecmp(cur, &restlen, &element, &elementlen);
|
|
|
|
if (new)
|
|
|
|
{
|
2008-07-21 12:32:22 +00:00
|
|
|
retlen = elementlen;
|
2008-07-19 12:18:05 +00:00
|
|
|
if (found == num ) ret = new+1;
|
2008-07-01 12:15:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
new = cur+elementlen;
|
|
|
|
if (new >= ne) return 0;
|
2008-07-20 09:38:53 +00:00
|
|
|
element = (char *)*name;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
/* restlen -= new-cur; not necessary because of __xml_memncasecmp */
|
|
|
|
cur = new;
|
|
|
|
new = memchr(cur, '<', restlen);
|
|
|
|
if (!new) return 0;
|
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
if (*(cur+1) != '/') /* new node found */
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-20 09:38:53 +00:00
|
|
|
char *node = "*";
|
2008-07-19 12:18:05 +00:00
|
|
|
size_t slen = restlen;
|
|
|
|
size_t nlen = 1;
|
|
|
|
int pos = -1;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-20 09:38:53 +00:00
|
|
|
new = __xmlGetNode(cur, &slen, &node, &nlen, &pos);
|
2008-07-19 12:18:05 +00:00
|
|
|
if (!new)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
if (slen == restlen) return 0;
|
|
|
|
else new = cur + slen;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
restlen -= slen;
|
|
|
|
cur = new;
|
|
|
|
|
|
|
|
new = memchr(cur, '<', restlen);
|
|
|
|
if (!new) return 0;
|
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*(cur+1) == '/') /* closing tag found */
|
|
|
|
{
|
|
|
|
if (!strncasecmp(new+2, element, elementlen))
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
if (found == num) *len = new-ret;
|
2008-07-20 09:38:53 +00:00
|
|
|
*name = element;
|
2008-07-19 12:18:05 +00:00
|
|
|
found++;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
new = memchr(cur, '>', restlen);
|
|
|
|
if (!new) return 0;
|
|
|
|
|
|
|
|
restlen -= new-cur;
|
|
|
|
cur = new;
|
|
|
|
}
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-21 12:32:22 +00:00
|
|
|
*rlen = retlen;
|
2008-07-19 12:18:05 +00:00
|
|
|
*nodenum = found;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
__xmlSkipComment(const char *start, size_t len)
|
|
|
|
{
|
|
|
|
char *cur, *new;
|
|
|
|
|
|
|
|
cur = (char *)start;
|
|
|
|
new = 0;
|
|
|
|
|
|
|
|
if (memcmp(cur, "!--", 3) == 0)
|
|
|
|
{
|
|
|
|
if (len < 6) return 0;
|
|
|
|
|
|
|
|
cur += 3;
|
|
|
|
len -= 3;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
new = memchr(cur, '-', len);
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
len -= new - cur;
|
2008-07-20 09:38:53 +00:00
|
|
|
if ((len > 3) && (memcmp(new, "-->", 3) == 0))
|
2008-06-30 12:00:40 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
new += 3;
|
|
|
|
len -= 3;
|
|
|
|
break;
|
2008-06-30 12:00:40 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
cur = new+1;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-20 09:38:53 +00:00
|
|
|
else break;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
while (new && (len > 2));
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
return new;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
char *
|
|
|
|
__xmlSkipInfo(const char *start, size_t len)
|
|
|
|
{
|
|
|
|
char *cur, *new;
|
|
|
|
|
|
|
|
cur = (char *)start;
|
|
|
|
new = 0;
|
|
|
|
|
|
|
|
if (*cur == '?')
|
|
|
|
{
|
|
|
|
if (len < 3) return 0;
|
|
|
|
|
|
|
|
cur++;
|
|
|
|
len--;
|
|
|
|
new = memchr(cur, '?', len);
|
|
|
|
if (!new || *(new+1) != '>') return 0;
|
|
|
|
|
|
|
|
new += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
void *
|
2008-07-06 11:34:50 +00:00
|
|
|
__xml_memmem(const void *haystack, size_t haystacklen,
|
2008-06-29 13:08:24 +00:00
|
|
|
const void *needle, size_t needlelen)
|
|
|
|
{
|
|
|
|
void *rptr = 0;
|
|
|
|
|
|
|
|
if (haystack && needle && (needlelen > 0) && (haystacklen >= needlelen))
|
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
char *ns, *hs, *ptr;
|
|
|
|
|
|
|
|
hs = (char *)haystack;
|
|
|
|
ns = (char *)needle;
|
2008-06-29 13:08:24 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
ptr = memchr(hs, *ns, haystacklen);
|
|
|
|
if (ptr)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
haystacklen -= (ptr - hs);
|
|
|
|
|
|
|
|
if (haystacklen < needlelen) break;
|
|
|
|
if (memcmp(ptr, needle, needlelen) == 0)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
rptr = ptr;
|
|
|
|
break;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
hs = ptr+1;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
while (haystacklen > needlelen);
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rptr;
|
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
#define NOCASECMP(a,b) ( ((a)^(b)) & 0xdf )
|
2008-07-06 11:34:50 +00:00
|
|
|
void *
|
2008-07-21 12:32:22 +00:00
|
|
|
__xml_memncasecmp(const void *haystack, size_t *haystacklen,
|
2008-07-06 11:34:50 +00:00
|
|
|
void **needle, size_t *needlelen)
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-06 11:34:50 +00:00
|
|
|
void *rptr = 0;
|
2008-07-19 12:18:05 +00:00
|
|
|
char *hs = (char *)haystack;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
if (haystack && needle && needlelen && (*needlelen > 0)
|
2008-07-19 12:18:05 +00:00
|
|
|
&& (*haystacklen >= *needlelen))
|
2008-06-29 13:08:24 +00:00
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
char *ns;
|
2008-07-06 11:34:50 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
ns = (char *)*needle;
|
|
|
|
|
|
|
|
/* search for everything */
|
|
|
|
if ((*ns == '*') && (*needlelen == 1))
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
char *he = hs + *haystacklen;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
while ((hs < he) && (*hs != ' ') && (*hs != '>')) hs++;
|
|
|
|
*needle = (void *)haystack;
|
|
|
|
*needlelen = hs - (char *)haystack;
|
2008-07-19 12:18:05 +00:00
|
|
|
while ((hs < he) && (*hs != '>')) hs++;
|
2008-07-06 11:34:50 +00:00
|
|
|
rptr = hs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t nlen = *needlelen;
|
2008-07-19 12:18:05 +00:00
|
|
|
char *he = hs + *haystacklen;
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
for (i=0; i<nlen; i++)
|
|
|
|
{
|
2008-07-19 12:18:05 +00:00
|
|
|
if (NOCASECMP(*hs,*ns) && (*ns != '?')) break;
|
|
|
|
if ((*hs == ' ') || (*hs == '>')) break;
|
2008-07-06 11:34:50 +00:00
|
|
|
hs++;
|
|
|
|
ns++;
|
|
|
|
}
|
|
|
|
|
2008-07-19 12:18:05 +00:00
|
|
|
if (i != nlen)
|
|
|
|
{
|
|
|
|
while((hs < he) && (*hs != ' ') && (*hs != '>')) hs++;
|
|
|
|
*needle = (void *)haystack;
|
|
|
|
*needlelen = hs - (char *)haystack;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*needle = (void *)haystack;
|
|
|
|
*needlelen = hs - (char *)haystack;
|
|
|
|
while ((hs < he) && (*hs != '>')) hs++;
|
|
|
|
rptr = hs;
|
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
}
|
2008-07-19 12:18:05 +00:00
|
|
|
|
|
|
|
*haystacklen -= hs - (char *)haystack;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
2008-07-06 11:34:50 +00:00
|
|
|
|
|
|
|
return rptr;
|
2008-06-29 13:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
/* Source:
|
|
|
|
* https://mollyrocket.com/forums/viewtopic.php?p=2529
|
|
|
|
*/
|
|
|
|
|
|
|
|
void *
|
|
|
|
simple_mmap(int fd, unsigned int length, SIMPLE_UNMMAP *un)
|
|
|
|
{
|
|
|
|
HANDLE f;
|
|
|
|
HANDLE m;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
f = (HANDLE)_get_osfhandle(fd);
|
|
|
|
if (!f) return NULL;
|
|
|
|
|
|
|
|
m = CreateFileMapping(f, NULL, PAGE_READONLY, 0, 0, NULL);
|
|
|
|
if (!m) return NULL;
|
|
|
|
|
|
|
|
p = MapViewOfFile(m, FILE_MAP_READ, 0,0,0);
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
CloseHandle(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n) *n = GetFileSize(f, NULL);
|
|
|
|
|
|
|
|
if (un)
|
|
|
|
{
|
|
|
|
un->m = m;
|
|
|
|
un->p = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
simple_unmmap(SIMPLE_UNMMAP *un)
|
|
|
|
{
|
|
|
|
UnmapViewOfFile(un->p);
|
|
|
|
CloseHandle(un->m);
|
|
|
|
}
|
|
|
|
#endif
|