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.2 by greg, Wed Jun 1 00:29:40 2011 UTC vs.
Revision 2.8 by greg, Thu Apr 2 16:40:32 2015 UTC

# Line 38 | Line 38 | static const char RCSid[] = "$Id$";
38   #include <sys/stat.h>
39   #include "ezxml.h"
40  
41 + #ifdef _WIN32
42 + #include <io.h>
43 + #define read            _read
44 + #define open            _open
45 + #define close           _close  
46 + #endif
47 +
48   #define EZXML_WS   "\t\r\n "  /* whitespace */
49   #define EZXML_ERRL 128        /* maximum error string length */
50  
# Line 67 | 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 143 | Line 158 | ezxml_t ezxml_err(ezxml_root_t root, char *s, const ch
158      char *t, fmt[EZXML_ERRL];
159      
160      for (t = root->s; t < s; t++) if (*t == '\n') line++;
161 <    snprintf(fmt, EZXML_ERRL, "[error near line %d]: %s", line, err);
161 >    sprintf(fmt, "[error near line %d]: %s", line, err);
162  
163      va_start(ap, err);
164      vsnprintf(root->err, EZXML_ERRL, fmt, ap);
# Line 163 | Line 178 | char *ezxml_decode(char *s, char **ent, char t)
178      char *e, *r = s, *m = s;
179      long b, c, d, l;
180  
181 <    for (; *s; s++) { /* normalize line endings */
182 <        while (*s == '\r') {
183 <            *(s++) = '\n';
184 <            if (*s == '\n') memmove(s, (s + 1), strlen(s));
185 <        }
186 <    }
181 >    for (; *s; s++)     /* normalize line endings */
182 >        if (*s == '\r') {
183 >            char *s2 = s+1;
184 >            do {
185 >                while (*s2 == '\r')
186 >                    ++s2;
187 >                *s++ = *s2;
188 >            } while (*s2++);
189 >            break;
190 >        }
191      
192      for (s = r; ; ) {
193          while (*s && *s != '&' && (*s != '%' || t != '%') && !isspace(*s)) s++;
# Line 363 | Line 382 | short ezxml_internal_dtd(ezxml_root_t root, char *s, s
382              if (*(s = t + strcspn(t, EZXML_WS ">")) == '>') continue;
383              else *s = '\0'; /* null terminate tag name */
384              for (i = 0; root->attr[i] && strcmp(n, root->attr[i][0]); i++);
385 <
386 <            while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
385 >            ++s;
386 >            while (*(n = s + strspn(s, EZXML_WS)) && *n != '>') {
387                  if (*(s = n + strcspn(n, EZXML_WS))) *s = '\0'; /* attr name */
388                  else { ezxml_err(root, t, "malformed <!ATTLIST"); break; }
389  
# Line 405 | Line 424 | short ezxml_internal_dtd(ezxml_root_t root, char *s, s
424                  root->attr[i][j + 1] = (v) ? ezxml_decode(v, root->ent, *c)
425                                             : NULL;
426                  root->attr[i][j] = n; /* attribute name  */
427 +                ++s;
428              }
429          }
430          else if (! strncmp(s, "<!--", 4)) s = strstr(s + 4, "-->"); /* comments */
# Line 910 | 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