]> git.mxchange.org Git - flightgear.git/blobdiff - utils/xmlgrep/xmlgrep.c
Merge branch 'ehofman/version'
[flightgear.git] / utils / xmlgrep / xmlgrep.c
index 688fb66818eeb95691fabbc91092b7c75f717e22..23577b0c8d2415a25343817e413c1dcd33836cf1 100644 (file)
@@ -5,12 +5,13 @@
 #include <string.h>
 #ifndef _MSC_VER
 # include <strings.h>
+# include <unistd.h>   /* read */
 #else
 # define strncasecmp strnicmp
 # include <stdlib.h>
+# include <io.h>
 #endif
 #include <assert.h>
-#include <unistd.h>    /* read */
 #include <sys/stat.h>  /* fstat */
 #include <fcntl.h>     /* open */
 
@@ -121,6 +122,7 @@ parse_option(char **args, int n, int max)
     {
         if (arg == 0) SHOW_NOVAL(opt);
         alen = strlen(arg)+1;
+        if (_root) free(_root);
         _root = malloc(alen);
         memcpy(_root, arg, alen);
         return 2;
@@ -129,6 +131,7 @@ parse_option(char **args, int n, int max)
     {
         if (arg == 0) SHOW_NOVAL(opt);
         alen = strlen(arg)+1;
+        if (_element) free(_element);
         _element = malloc(alen);
         memcpy(_element, arg, alen);
         return 2;
@@ -137,6 +140,7 @@ parse_option(char **args, int n, int max)
     {
         if (arg == 0) SHOW_NOVAL(opt);
         alen = strlen(arg)+1;
+        if (_value) free(_value);
         _value = malloc(alen);
         memcpy(_value, arg, alen);
         return 2;
@@ -145,6 +149,7 @@ parse_option(char **args, int n, int max)
     {
         if (arg == 0) SHOW_NOVAL(opt);
         alen = strlen(arg)+1;
+        if (_print) free(_print);
         _print = malloc(alen);
         memcpy(_print, arg, alen);
         return 2;
@@ -153,6 +158,7 @@ parse_option(char **args, int n, int max)
     {
         if (arg == 0) SHOW_NOVAL(opt);
         alen = strlen(arg)+1;
+        if (_attribute) free(_attribute);
         _attribute = malloc(alen);
         memcpy(_attribute, arg, alen);
         return 2;
@@ -207,17 +213,23 @@ void walk_the_tree(size_t num, void *xid, char *tree)
             {
                 if (xmlNodeGetPos(xid, xmid, _print, i) != 0)
                 {
-                    char value[STRING_LEN];
+                    char *value;
 
-                    xmlCopyString(xmid, (char *)&value, STRING_LEN);
-                    if (_value && _attribute)
+                    value = xmlGetString(xmid);
+                    if (_value && _attribute && value)
                     {
+#if 1
+                       char *a = xmlAttributeGetString(xmid, _attribute);
+                       if (a && !strcmp(a, _value))
+#else
                        if (!xmlAttributeCompareString(xmid, _attribute, _value))
+#endif
                        {
                           printf("%s: <%s %s=\"%s\">%s</%s>\n",
                                  _filenames[num], _print, _attribute, _value,
                                                   value, _print);
                        }
+                       if (value) free(value);
                     }
                     else
                     {