| 40 |
|
|
| 41 |
|
#ifdef _WIN32 |
| 42 |
|
#include <io.h> |
| 43 |
– |
#define snprintf printf_s |
| 43 |
|
#define read _read |
| 44 |
|
#define open _open |
| 45 |
|
#define close _close |
| 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) |
| 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); |
| 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++; |
| 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 |
|
|
| 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 */ |
| 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 */ |