Add support to handle possible EOF without previous \n or \r\n - 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 d8177ac6bcc6201a347f094e2128370f107b78ad
 (DIR) parent 477d355c259932e82ee1d6b659d895ec7f188e00
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Wed, 26 Jun 2019 01:23:11 
       
       Add support to handle possible EOF without previous \n or \r\n
       
       Diffstat:
        TODO.txt   |  1 -
        csvtofsv.c |  8 +++++++-
        2 files changed, 7 insertions(+), 2 deletions(-)
       ---
       diff -r 477d355c2599 -r d8177ac6bcc6 TODO.txt
       --- a/TODO.txt  Wed Jun 26 01:21:39 2019 +0200
       +++ b/TODO.txt  Wed Jun 26 01:23:11 2019 +0200
       @@ -1,5 +1,4 @@
        Possible known todo and parsing mistakes:
        
        - `\r' should be always ignored
       -- Trailing EOF without a `\n' or `\r\n' is not gracefully handled
        - Add more tests and recheck RFC 4180
       diff -r 477d355c2599 -r d8177ac6bcc6 csvtofsv.c
       --- a/csvtofsv.c        Wed Jun 26 01:21:39 2019 +0200
       +++ b/csvtofsv.c        Wed Jun 26 01:23:11 2019 +0200
       @@ -35,12 +35,14 @@
        int
        main(int argc, char *argv[])
        {
       -       int c, nc;
       +       int c, nc, pc;
               bool first, quoted;
        
               first = true;
               quoted = false;
       +       pc = '\0';
               while ((c = getchar()) != EOF) {
       +               pc = c;
                       switch (c) {
                       case '"':
                               if (first) {
       @@ -49,6 +51,7 @@
                               } else if (!quoted) {
                                       putchar(c);
                               } else if ((nc = getchar()) != EOF) {
       +                               pc = nc;
                                       if (nc == '"') {
                                               putchar('"');
                                       } else if (nc == ',') {
       @@ -95,5 +98,8 @@
                       }
               }
        
       +       if (pc != '\0' && pc != '\n')
       +               putchar(RS);
       +
               return 0;
        }