From e3e85aa183546e9ef18842fc244fdb53ba813c04 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 10:45:52 +0200 Subject: [PATCH] csv: add new sub-format for tabulator separated values --- lib/formats/csv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/formats/csv.c b/lib/formats/csv.c index a63a5141e..57832c0ba 100644 --- a/lib/formats/csv.c +++ b/lib/formats/csv.c @@ -178,8 +178,8 @@ void csv_header(struct io *io) fprintf(f, "%c", io->delimiter); } -static struct plugin p = { - .name = "csv", +static struct plugin p1 = { + .name = "tsv", .description = "Tabulator-separated values", .type = PLUGIN_TYPE_FORMAT, .format = { @@ -187,8 +187,24 @@ static struct plugin p = { .sscan = csv_sscan, .header = csv_header, .size = 0, - .flags = IO_NEWLINES + .flags = IO_NEWLINES, + .separator = '\t' } }; -REGISTER_PLUGIN(&p); +static struct plugin p2 = { + .name = "csv", + .description = "Comma-separated values", + .type = PLUGIN_TYPE_FORMAT, + .format = { + .sprint = csv_sprint, + .sscan = csv_sscan, + .header = csv_header, + .size = 0, + .flags = IO_NEWLINES, + .separator = ',' + } +}; + +REGISTER_PLUGIN(&p1); +REGISTER_PLUGIN(&p2);