| 170 |
|
char *e, *r = s, *m = s; |
| 171 |
|
long b, c, d, l; |
| 172 |
|
|
| 173 |
< |
for (; *s; s++) { /* normalize line endings */ |
| 174 |
< |
while (*s == '\r') { |
| 175 |
< |
*(s++) = '\n'; |
| 176 |
< |
if (*s == '\n') memmove(s, (s + 1), strlen(s)); |
| 177 |
< |
} |
| 178 |
< |
} |
| 173 |
> |
for (; *s; s++) /* normalize line endings */ |
| 174 |
> |
if (*s == '\r') { |
| 175 |
> |
char *s2 = s+1; |
| 176 |
> |
do { |
| 177 |
> |
while (*s2 == '\r') |
| 178 |
> |
++s2; |
| 179 |
> |
*s++ = *s2; |
| 180 |
> |
} while (*s2++); |
| 181 |
> |
break; |
| 182 |
> |
} |
| 183 |
|
|
| 184 |
|
for (s = r; ; ) { |
| 185 |
|
while (*s && *s != '&' && (*s != '%' || t != '%') && !isspace(*s)) s++; |
| 374 |
|
if (*(s = t + strcspn(t, EZXML_WS ">")) == '>') continue; |
| 375 |
|
else *s = '\0'; /* null terminate tag name */ |
| 376 |
|
for (i = 0; root->attr[i] && strcmp(n, root->attr[i][0]); i++); |
| 377 |
< |
|
| 378 |
< |
while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') { |
| 377 |
> |
++s; |
| 378 |
> |
while (*(n = s + strspn(s, EZXML_WS)) && *n != '>') { |
| 379 |
|
if (*(s = n + strcspn(n, EZXML_WS))) *s = '\0'; /* attr name */ |
| 380 |
|
else { ezxml_err(root, t, "malformed <!ATTLIST"); break; } |
| 381 |
|
|
| 416 |
|
root->attr[i][j + 1] = (v) ? ezxml_decode(v, root->ent, *c) |
| 417 |
|
: NULL; |
| 418 |
|
root->attr[i][j] = n; /* attribute name */ |
| 419 |
+ |
++s; |
| 420 |
|
} |
| 421 |
|
} |
| 422 |
|
else if (! strncmp(s, "<!--", 4)) s = strstr(s + 4, "-->"); /* comments */ |
| 922 |
|
ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt) |
| 923 |
|
{ |
| 924 |
|
if (! xml) return NULL; |
| 925 |
+ |
if (txt == xml->txt) return xml; |
| 926 |
|
if (xml->flags & EZXML_TXTM) free(xml->txt); /* existing txt was malloced */ |
| 927 |
|
xml->flags &= ~EZXML_TXTM; |
| 928 |
|
xml->txt = (char *)txt; |
| 929 |
|
return xml; |
| 930 |
+ |
} |
| 931 |
+ |
|
| 932 |
+ |
/* add text to the current character content, allocating memory as needed (GW) */ |
| 933 |
+ |
ezxml_t ezxml_add_txt(ezxml_t xml, const char *txt) |
| 934 |
+ |
{ |
| 935 |
+ |
int len; |
| 936 |
+ |
if (! xml) return NULL; |
| 937 |
+ |
if (!*txt) return xml; |
| 938 |
+ |
len = strlen(xml->txt) + strlen(txt) + 1; |
| 939 |
+ |
if (xml->flags & EZXML_TXTM) { |
| 940 |
+ |
xml->txt = (char *)realloc(xml->txt, len); |
| 941 |
+ |
} else { |
| 942 |
+ |
xml->txt = strcpy((char *)malloc(len), xml->txt); |
| 943 |
+ |
xml->flags |= EZXML_TXTM; |
| 944 |
+ |
} |
| 945 |
+ |
strcat(xml->txt, txt); |
| 946 |
+ |
return xml; |
| 947 |
|
} |
| 948 |
|
|
| 949 |
|
/* Sets the given tag attribute or adds a new attribute if not found. A value */ |