summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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