diff options
author | KatolaZ <katolaz@freaknet.org> | 2020-01-04 01:31:40 +0000 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2020-01-04 01:31:40 +0000 |
commit | d1d29f3306ef651796d171c8d406b14fc74778ca (patch) | |
tree | b02317e164150aac05a5b4134c3eb8c3f3d2a056 | |
parent | 171b4c872cde8fea8cd6ddc0bc5df3e3bb5c3dcb (diff) |
quote newline and tabs; set separator and attribute assign chars
-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 |