ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ezxml.c
(Generate patch)

Comparing ray/src/common/ezxml.c (file contents):
Revision 2.6 by greg, Sun Oct 26 17:35:53 2014 UTC vs.
Revision 2.8 by greg, Thu Apr 2 16:40:32 2015 UTC

# Line 74 | Line 74 | ezxml_t ezxml_child(ezxml_t xml, const char *name)
74      return xml;
75   }
76  
77 + /* returns the given tag's character content or empty string if none */
78 + char *ezxml_txt(ezxml_t xml)
79 + {
80 +        if (xml == NULL)
81 +                return "";
82 +        return xml->txt;
83 + }
84 +
85   /* returns the Nth tag with the same name in the same subsection or NULL if not */
86   /* found */
87   ezxml_t ezxml_idx(ezxml_t xml, int idx)
# Line 922 | Line 930 | ezxml_t ezxml_add_child(ezxml_t xml, const char *name,
930   ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt)
931   {
932      if (! xml) return NULL;
933 +    if (txt == xml->txt) return xml;
934      if (xml->flags & EZXML_TXTM) free(xml->txt); /* existing txt was malloced */
935      xml->flags &= ~EZXML_TXTM;
936      xml->txt = (char *)txt;
937      return xml;
938 + }
939 +
940 + /* add text to the current character content, allocating memory as needed (GW) */
941 + ezxml_t ezxml_add_txt(ezxml_t xml, const char *txt)
942 + {
943 +        int     len;
944 +        if (! xml) return NULL;
945 +        if (!*txt) return xml;
946 +        len = strlen(xml->txt) + strlen(txt) + 1;
947 +        if (xml->flags & EZXML_TXTM) {
948 +                xml->txt = (char *)realloc(xml->txt, len);
949 +        } else {
950 +                xml->txt = strcpy((char *)malloc(len), xml->txt);
951 +                xml->flags |= EZXML_TXTM;
952 +        }
953 +        strcat(xml->txt, txt);
954 +        return xml;
955   }
956  
957   /* Sets the given tag attribute or adds a new attribute if not found. A value */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines