From 302088dbb8f0eb6bca0c3d97bb2066bad3d5d4c5 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sun, 5 Jan 2020 06:54:03 +0000 Subject: remove control chars --- xml2tsv.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/xml2tsv.c b/xml2tsv.c index 9ad033b..635ae37 100644 --- a/xml2tsv.c +++ b/xml2tsv.c @@ -14,6 +14,7 @@ #include #include +#include #include "xml.h" #include "config.h" @@ -58,26 +59,37 @@ void stack_init(tstack_t *t){ /* utility functions */ +/* quote_print: quote \\, \n, \t, and strip other ctrl chars */ void quote_print(FILE *f, const char *s){ const char *tmp = s; size_t len; + int i; while (*tmp != '\0'){ len = strcspn(tmp, "\\\n\t"); - fwrite(tmp, 1, len, f); - tmp += len; - if (*tmp == '\n'){ - if (len > 0){ - fprintf(f, "\\n"); + for(i=0; i 0){ + fprintf(f, "\\n"); + } + tmp ++; + break; + case '\t': + fprintf(f, "\\t"); + tmp ++; + break; + case '\r': + fprintf(f, "\\r"); + tmp ++; + break; + case '\\': + fprintf(f, "\\\\"); + tmp ++; + break; } } } -- cgit v1.2.3