+05-05-2009
+ * Various bugfixes, required to get fgrun working
+ * add testxml as sort of a stress test application
+
30-04-2009
* Add support for CDATA
* Fix an off by one problem.
-noinst_PROGRAMS = xmlgrep printxml
-
-xmlgrep_SOURCES = xmlgrep.c xml.c xml.h
+noinst_PROGRAMS = testxml printxml xmlgrep
+testxml_SOURCES = testxml.c xml.c
printxml_SOURCES = printxml.c xml.c
+xmlgrep_SOURCES = xmlgrep.c xml.c xml.h
--- /dev/null
+<?xml version="1.0"?>
+
+<Configuration>
+
+ <output>
+ <frequency-hz>48000</frequency-hz>
+ <interval-hz>20</interval-hz>
+ <num-speakers>2</num-speakers>
+
+ <tmp><!-- --></tmp>
+ <test n="0" ëlémènt="bjôrn"/>
+ <test n="1"/>
+ <test n="2"/>
+
+ <menu><name>* Traffic, # taxiing to runway (.</name></menu>
+ <menu><name>* Traffic, # holding short runway (.</name></menu>
+
+ <!--
+ - x is positive to the right
+ - y is positive upwards
+ - z is positive backwards
+ -->
+ <speaker n="0">
+ <channel>0</channel>
+ <volume-norm>1.0</volume-norm>
+ <desc><!-- empty --></desc>
+ </speaker>
+
+ <speaker n="1">
+ <channel>1</channel>
+ <volume-norm>1.0</volume-norm>
+ <desc>
+ <!--
+ empty --></desc>
+ </speaker>
+
+ <script><![CDATA[
+ getprop(call(sprintf, size(arg));
+ c--; x >>= 33;
+ // --> comment ]>
+ ;]]></script>
+ </output>
+
+ <backend>
+ <name type="stereo">ALSA Hardware</name>
+ <Output>
+ <renderer>hw:0</renderer>
+ <channels>2</channels>
+ <!-- periods>16</periods -->
+ <frequency-hz>44100</frequency-hz>
+ <bits-per-sample>16</bits-per-sample>
+ </Output>
+ <Input>
+ <renderer>default</renderer>
+ <frequency-hz>44100</frequency-hz>
+ </Input>
+ </backend>
+
+ <nasal>
+ <YF23>
+ <script><![CDATA[
+ # If the ground-roll-heading-hold has been reset (<-999) set:
+ if(agl > 50) {
+ ]]></script>
+ </YF23>
+ </nasal>
+
+</Configuration>
--- /dev/null
+#include <stdio.h>
+#include <malloc.h>
+#include "xml.h"
+
+#define ROOTNODE "/Configuration/output/menu"
+#define LEAFNODE "name"
+#define PATH ROOTNODE"/"LEAFNODE
+#define BUFLEN 4096
+int main()
+{
+ void *root_id;
+
+ root_id = xmlOpen("sample.xml");
+ if (root_id)
+ {
+ void *path_id, *node_id;
+
+ path_id = xmlNodeGet(root_id, PATH);
+ node_id = xmlNodeGet(root_id, ROOTNODE);
+
+ if (path_id && node_id)
+ {
+ char buf[BUFLEN];
+ size_t len;
+ char *s;
+
+ len = xmlNodeCopyString(root_id, PATH, buf, BUFLEN);
+ printf("%s = '%s'\n", PATH, buf);
+
+ printf("Testing value of /Configuration/output/test:\t\t\t\t");
+ s = xmlNodeGetString(root_id , "/Configuration/output/test");
+ if (s)
+ {
+ printf("failed.\n\t'%s' shoudl be empty\n", s);
+ free(s);
+ }
+ else
+ printf("succes.\n");
+
+ printf("Testing xmlNodeCopyString against xmlGetString:\t\t\t\t");
+ if ((s = xmlGetString(path_id)) != 0)
+ {
+ if (strcmp(s, buf)) /* not the same */
+ printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
+ else
+ printf("succes.\n");
+
+ printf("Testing xmlCopyString against xmlGetString:\t\t\t\t");
+ xmlCopyString(path_id, buf, BUFLEN);
+ if (strcmp(s, buf)) /* not the same */
+ printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
+ else
+ printf("succes.\n");
+ free(s);
+ }
+ else
+ printf("Error while fetching node's value.\n");
+
+ printf("Testing xmlCopyString against xmlCompareString:\t\t\t\t");
+ if (xmlCompareString(path_id, buf)) /* not the same */
+ printf ("failed.\n\t'%s' differs\n", buf);
+ else
+ printf("succes.\n");
+
+ printf("Testing xmlCopyString against xmlNodeCompareString:\t\t\t");
+ if (xmlNodeCompareString(node_id, LEAFNODE, buf)) /* not the same */
+ printf ("failed.\n\t'%s' differs\n", buf);
+ else
+ printf("succes.\n");
+
+ printf("Testing xmlCopyString against xmlNodeGetString:\t\t\t\t");
+ if ((s = xmlNodeGetString(node_id, LEAFNODE)) != 0)
+ {
+ if (strcmp(s, buf)) /* not the same */
+ printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
+ else
+ printf("succes.\n");
+ free(s);
+ }
+ else
+ printf("Error while fetching value from node.\n");
+
+ free(path_id);
+ path_id = xmlNodeGet(root_id, "/Configuration/backend/name");
+ if (path_id)
+ {
+ xmlAttributeCopyString(path_id, "type", buf, BUFLEN);
+
+ printf("Testing xmlAttributeCopyString against xmlAttributeCompareString:\t");
+ if (xmlAttributeCompareString(path_id, "type", buf)) /* no match */
+ printf("failed.\n\t'%s' differs\n", buf);
+ else
+ printf("succes.\n");
+
+ printf("Testing xmlAttributeCopyString against xmlAttributeGetString:\t\t");
+ if ((s = xmlAttributeGetString(path_id, "type")) != 0)
+ {
+ if (strcmp(s, buf)) /* not the same */
+ printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
+ else
+ printf("succes.\n");
+ free(s);
+ }
+ else
+ printf("Error while fetching value from attribute.\n");
+
+ }
+ else
+ printf("Error while fetching node's attribute.\n");
+
+ free(node_id);
+ free(path_id);
+ }
+ else
+ {
+ printf("Error: %s\n", xmlErrorGetString(root_id, 1));
+ }
+
+ xmlClose(root_id);
+ }
+
+ return 0;
+}
# include <stdio.h>
#endif
#include <stdlib.h> /* free, malloc */
+#include <malloc.h>
#include <string.h> /* memcmp */
#ifndef _MSC_VER
#include <strings.h> /* strncasecmp */
#endif
};
-static char *__xmlNodeCopy(const char *, size_t *, const char **);
static char *__xmlNodeGetPath(const char *, size_t *, char **, size_t *);
static char *__xmlNodeGet(const char *, size_t *, char **, size_t *, size_t *);
static char *__xmlProcessCDATA(char **, size_t *);
assert(buffer != 0);
assert(buflen > 0);
+ *buffer = '\0';
if (xid->len)
{
size_t len;
- char *ps,
+ char *p;
- *buffer = '\0';
- ps = xid->start;
+ p = xid->start;
len = xid->len;
- __xmlPrepareData(&ps, &len);
-
+ __xmlPrepareData(&p, &len);
if (len)
{
if (len >= buflen)
len = buflen-1;
xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
}
- memcpy(buffer, ps, len);
+ memcpy(buffer, p, len);
*(buffer+len) = 0;
- ret = len;
}
+ ret = len;
}
return ret;
if (xid->len)
{
+ char *p, *node = (char *)path;
+ size_t slen = strlen(node);
size_t len = xid->len;
- char *node = (char *)path;
- str = __xmlNodeCopy(xid->start, &len, &path);
- if (str)
+ slen = strlen(node);
+ p = __xmlNodeGetPath(xid->start, &len, &node, &slen);
+ if (p && len)
{
- size_t len;
- char *ps, *pe;
+ __xmlPrepareData(&p, &len);
- ps = str;
- len = strlen(str);
- __xmlPrepareData(&ps, &len);
- pe = ps + len;
-
- *++pe = 0;
- if (len && (ps>str)) memmove(str, ps, len);
- else if (!len) *str = 0;
+ str = malloc(len+1);
+ if (str)
+ {
+ memcpy(str, p, len);
+ *(str+len) = '\0';
+ }
+ else
+ {
+ xmlErrorSet(xid, 0, XML_OUT_OF_MEMORY);
+ }
}
else
{
assert(buffer != 0);
assert(buflen > 0);
+ *buffer = '\0';
if (xid->len)
{
- char *str, *node;
- size_t slen, len;
+ char *p, *node = (char *)path;
+ size_t slen = strlen(node);
+ size_t len = xid->len;
- *buffer = '\0';
- len = xid->len;
- slen = strlen(path);
- node = (char *)path;
- str = __xmlNodeGetPath(xid->start, &len, &node, &slen);
- if (str)
+ p = __xmlNodeGetPath(xid->start, &len, &node, &slen);
+ if (p)
{
- char *ps = str;
- __xmlPrepareData(&ps, &len);
-
- if (len >= buflen)
+ __xmlPrepareData(&p, &len);
+ if (len)
{
- len = buflen-1;
- xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
- }
+ if (len >= buflen)
+ {
+ len = buflen-1;
+ xmlErrorSet(xid, 0, XML_TRUNCATE_RESULT);
+ }
- memcpy(buffer, ps, len);
- *(buffer + len) = '\0';
- ret = len;
+ memcpy(buffer, p, len);
+ *(buffer+len) = '\0';
+ }
+ ret = 0;
}
else if (slen == 0)
{
};
#endif
-char *
-__xmlNodeCopy(const char *start, size_t *len, const char **path)
-{
- char *node, *p, *ret = 0;
- size_t rlen, slen;
-
- rlen = *len;
- slen = strlen(*path);
- node = (char *)*path;
- p = __xmlNodeGetPath(start, &rlen, &node, &slen);
- if (p && rlen)
- {
- ret = malloc(rlen+1);
- if (ret)
- {
- memcpy(ret, p, rlen);
- *(ret+rlen) = '\0';
- }
- else
- {
- xmlErrorSet(0, 0, XML_OUT_OF_MEMORY);
- }
- }
- else if (slen == 0)
- {
- *path = node;
- *len = rlen;
- }
-
- return ret;
-}
-
char *
__xmlNodeGetPath(const char *start, size_t *len, char **name, size_t *nlen)
{
- char *node;
+ char *path;
char *ret = 0;
assert(start != 0);
if (*nlen > *len) return 0;
- node = *name;
- if (*node == '/') node++;
- if (*node != 0)
+ path = *name;
+ if (*path == '/') path++;
+ if (*path != '\0')
{
- size_t blen, plen, slen;
- char *path;
- size_t num;
+ size_t num, blocklen, pathlen, nodelen;
+ char *node;
- slen = strlen(node);
+ node = path;
+ pathlen = strlen(path);
path = strchr(node, '/');
- if (!path) plen = slen;
- else plen = path++ - node;
+ if (!path) nodelen = pathlen;
+ else nodelen = path++ - node;
num = 0;
- blen = *len;
- ret = __xmlNodeGet(start, &blen, &node, &plen, &num);
+ blocklen = *len;
+ ret = __xmlNodeGet(start, &blocklen, &node, &nodelen, &num);
if (ret)
{
if (path)
{
- plen = slen - (path - *name);
- ret = __xmlNodeGetPath(ret, &blen, &path, &plen);
+ ret = __xmlNodeGetPath(ret, &blocklen, &path, &pathlen);
*name = path;
+ *len = blocklen;
+ *nlen = pathlen;
}
else
{
*name = node;
- *nlen = plen;
- *len = blen;
+ *nlen = nodelen;
+ *len = blocklen;
}
}
else
if (start_tag)
{
*len = new-ret-1;
-#if 0
- if (cdata == ret)
- {
- ret += 9; /* ![CDATA[[ */
- *len -= 12; /* ![CDATA[[ ]]> */
- }
-#endif
open_element = start_tag;
cdata = (char *)start;
start_tag = 0;