summaryrefslogtreecommitdiff
path: root/xml2tsv.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2020-01-04 01:31:40 +0000
committerKatolaZ <katolaz@freaknet.org>2020-01-04 01:31:40 +0000
commitd1d29f3306ef651796d171c8d406b14fc74778ca (patch)
treeb02317e164150aac05a5b4134c3eb8c3f3d2a056 /xml2tsv.c
parent171b4c872cde8fea8cd6ddc0bc5df3e3bb5c3dcb (diff)
quote newline and tabs; set separator and attribute assign chars
Diffstat (limited to 'xml2tsv.c')
-rw-r--r--xml2tsv.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/xml2tsv.c b/xml2tsv.c
index dbd0d9a..ad2083e 100644
--- a/xml2tsv.c
+++ b/xml2tsv.c
@@ -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