Initial commit - csvtofsv - Convert CSV to FSV (`fs' (0x1c) as FS and `rs' (0x1e) as RS)
 (HTM) hg clone https://bitbucket.org/iamleot/csvtofsv
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset fe779850f664a14c83dd752e6f64cb81a4a19ef6
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Tue, 25 Jun 2019 10:48:52 
       
       Initial commit
       
       Diffstat:
        csvtofsv.c |  63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        t/01.csv   |   2 +
        t/01.fsv   |   1 +
        t/02.csv   |   8 +++++++
        t/02.fsv   |   2 +
        5 files changed, 76 insertions(+), 0 deletions(-)
       ---
       diff -r 000000000000 -r fe779850f664 csvtofsv.c
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/csvtofsv.c        Tue Jun 25 10:48:52 2019 +0200
       @@ -0,0 +1,63 @@
       +#include <stdbool.h>
       +#include <stdio.h>
       +
       +#define        FS      034
       +#define        RS      036
       +
       +int
       +main(int argc, char *argv[])
       +{
       +       int c, nc;
       +       bool first, quoted;
       +
       +       first = true;
       +       quoted = false;
       +       while ((c = getchar()) != EOF) {
       +               switch (c) {
       +               case '"':
       +                       if (first) {
       +                               quoted = true;
       +                               first = false;
       +                       } else if ((nc = getchar()) != EOF) {
       +                               if (quoted && nc == '"') {
       +                                       putchar('"');
       +                               } else if (quoted && nc == ',') {
       +                                       putchar(FS);
       +                                       first = true;
       +                                       quoted = false;
       +                               } else if (quoted && nc == '\n') {
       +                                       putchar(RS);
       +                                       first = true;
       +                                       quoted = false;
       +                               } else {
       +                                       ungetc(nc, stdin);
       +                               }
       +                       }
       +                       break;
       +               case ',':
       +                       if (quoted) {
       +                               putchar(',');
       +                       } else {
       +                               putchar(FS);
       +                               first = true;
       +                       }
       +                       break;
       +               case '\n':
       +                       if (quoted) {
       +                               putchar('\n');
       +                       } else {
       +                               putchar(RS);
       +                               first = true;
       +                       }
       +                       break;
       +               case '\r':
       +                       /* ignore */
       +                       break;
       +               default:
       +                       putchar(c);
       +                       break;
       +               }
       +       }
       +
       +       return 0;
       +}
       diff -r 000000000000 -r fe779850f664 t/01.csv
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/t/01.csv  Tue Jun 25 10:48:52 2019 +0200
       @@ -0,0 +1,2 @@
       +1,2,3,4
       +one,two,three,four
       diff -r 000000000000 -r fe779850f664 t/01.fsv
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/t/01.fsv  Tue Jun 25 10:48:52 2019 +0200
       @@ -0,0 +1,1 @@
       +1
       2
       3
       4
       one
       two
       three
       four
       
       \ No newline at end of file
       diff -r 000000000000 -r fe779850f664 t/02.csv
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/t/02.csv  Tue Jun 25 10:48:52 2019 +0200
       @@ -0,0 +1,8 @@
       +"",,
       +empty,empty,empty
       +" ","  ","
       +"
       +space,tab,newline
       +"quoted text","""really "" quoted""",not quoted
       +"""",",",",,"
       +quote,comma,two commas
       diff -r 000000000000 -r fe779850f664 t/02.fsv
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/t/02.fsv  Tue Jun 25 10:48:52 2019 +0200
       @@ -0,0 +1,2 @@
       +
       
       
       empty
       empty
       empty
        
               
       
       +
       space
       tab
       newline
       quoted text
       "really " quoted"
       not quoted
       "
       ,
       ,,
       quote
       comma
       two commas
       
       \ No newline at end of file