avoid unnecessary fields due to data after tags - xml2tsv - a simple xml-to-tsv converter, based on xmlparser
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 1e797ce6bffc927a69bc38828b5158dbb68b5950
(DIR) parent 77a22b4fd5d8f6c9f64245788e5726de78f8c30e
(HTM) Author: KatolaZ <katolaz@freaknet.org>
Date: Sun, 12 Jan 2020 19:15:56 +0000
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:
M xml2tsv.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/xml2tsv.c b/xml2tsv.c
@@ -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;