]> git.mxchange.org Git - flightgear.git/commitdiff
* Various bugfixes, required to get fgrun working
authorehofman <ehofman>
Wed, 6 May 2009 14:29:12 +0000 (14:29 +0000)
committerTim Moore <timoore@redhat.com>
Mon, 18 May 2009 10:24:16 +0000 (12:24 +0200)
  * add testxml as sort of a stress test application

utils/xmlgrep/ChangeLog
utils/xmlgrep/Makefile.am
utils/xmlgrep/sample.xml [new file with mode: 0644]
utils/xmlgrep/testxml.c [new file with mode: 0644]
utils/xmlgrep/xml.c

index b15eb15157de033b75177d2daeccc9c3355b4931..789549a2a7540a26e8faad73f5e47940a0b76492 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 160aca75d936d79c7c6dd73956544e242182b1cc..84db180516e84531016c03639d9a1f19b513d4fa 100644 (file)
@@ -1,5 +1,5 @@
-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
diff --git a/utils/xmlgrep/sample.xml b/utils/xmlgrep/sample.xml
new file mode 100644 (file)
index 0000000..8510890
--- /dev/null
@@ -0,0 +1,68 @@
+<?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>
diff --git a/utils/xmlgrep/testxml.c b/utils/xmlgrep/testxml.c
new file mode 100644 (file)
index 0000000..318002b
--- /dev/null
@@ -0,0 +1,123 @@
+#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;
+}
index 433828ce2c5111e570f1fc8b6c63a02901975ef8..f319dbfc25f1769c50667345dc635a7bc1729b8c 100644 (file)
@@ -45,6 +45,7 @@ typedef struct
 # include <stdio.h>
 #endif
 #include <stdlib.h>     /* free, malloc */
+#include <malloc.h>
 #include <string.h>    /* memcmp */
 #ifndef _MSC_VER
 #include <strings.h>   /* strncasecmp */
@@ -117,7 +118,6 @@ struct _xml_id
 #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 *);
@@ -496,16 +496,15 @@ xmlCopyString(const void *id, char *buffer, size_t buflen)
     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)
@@ -513,10 +512,10 @@ xmlCopyString(const void *id, char *buffer, size_t 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;
@@ -556,23 +555,26 @@ xmlNodeGetString(const void *id, const char *path)
 
     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
         {
@@ -594,30 +596,29 @@ xmlNodeCopyString(const void *id, const char *path, char *buffer, size_t buflen)
     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)
         {
@@ -1299,42 +1300,10 @@ static const char *__xml_error_str[XML_MAX_ERROR] =
 };
 #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);
@@ -1347,36 +1316,37 @@ __xmlNodeGetPath(const char *start, size_t *len, char **name, size_t *nlen)
 
     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
@@ -1594,13 +1564,6 @@ __xmlNodeGet(const char *start, size_t *len, char **name, size_t *rlen, size_t *
                     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;