diff options
Diffstat (limited to 'xml2tsv.c')
-rw-r--r-- | xml2tsv.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -19,7 +19,8 @@ #define STR_MAX 128 #define DEPTH_MAX 50 - +#define SEP '\t' +#define SATTR '=' /* tag stack */ @@ -65,11 +66,19 @@ void print_no_cr(FILE *f, const char *s){ const char *tmp = s; size_t len; while (*tmp != '\0'){ - len = strcspn(tmp, "\n"); + len = strcspn(tmp, "\n\t"); fwrite(tmp, 1, len, f); tmp += len; - if (tmp[len] == '\n') - tmp++; + if (*tmp == '\n'){ + if (len > 0){ + fprintf(f, "\\n"); + } + tmp ++; + } + else if (*tmp == '\t'){ + fprintf(f, "\\t"); + tmp ++; + } } } @@ -115,13 +124,13 @@ xmlattrend(XMLParser *x, const char *t, size_t tl, const char *a, size_t al) void xmlattrstart(XMLParser *x, const char *t, size_t tl, const char *a, size_t al) { - printf("\t%s=", a); + printf("%c%s%c", SEP, a, SATTR); } void xmlcdatastart(XMLParser *x) { - printf("\t"); + printf("%c", SEP); } void @@ -176,7 +185,7 @@ xmldataentity(XMLParser *x, const char *d, size_t dl) void xmldatastart(XMLParser *x) { - printf("\t"); + printf("%c", SEP); } void |