diff options
author | KatolaZ <katolaz@freaknet.org> | 2020-01-12 19:15:56 +0000 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2020-01-12 19:15:56 +0000 |
commit | 1e797ce6bffc927a69bc38828b5158dbb68b5950 (patch) | |
tree | c60d96f56ca6ef136ef83c72c61e6f46ad5a1f42 /xml2tsv.c | |
parent | 77a22b4fd5d8f6c9f64245788e5726de78f8c30e (diff) |
avoid unnecessary fields due to data after tags
Avoid to include more fields than needed in a record when there is
some data (e.g., spaces) after the end of a tag
Diffstat (limited to 'xml2tsv.c')
-rw-r--r-- | xml2tsv.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -19,6 +19,10 @@ #include "xml.h" #include "config.h" + +#define FALSE 0 +#define TRUE 1 + /* tag stack */ typedef struct { @@ -104,7 +108,7 @@ void print_cur_str(FILE *f, tstack_t *t){ /* global variables */ tstack_t st; - +char emitsep; /* xml callbacks */ @@ -174,12 +178,17 @@ xmlcommentend(XMLParser *x) void xmldata(XMLParser *x, const char *d, size_t dl) { + if (strcspn(d, " \t\n") && emitsep){ + printf("%c", SEP); + emitsep = FALSE; + } quote_print(stdout, d); } void xmldataend(XMLParser *x) { + emitsep = FALSE; } void @@ -197,7 +206,7 @@ xmldataentity(XMLParser *x, const char *d, size_t dl) void xmldatastart(XMLParser *x) { - printf("%c", SEP); + emitsep = TRUE; } void @@ -239,6 +248,7 @@ int main(void) { stack_init(&st); + emitsep = FALSE; XMLParser x = { 0 }; x.xmlattr = xmlattr; |