Adding line numbers to errors. - libical - A simple ical library.
       
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit eff7e5e44fa69bcfcd092b77560153e36bdfc5bf
 (DIR) parent bccaa1ea3b33f47b4be6de3745635d5378ab4016
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sat,  2 Feb 2013 16:02:20 +0100
       
       Adding line numbers to errors.
       
       Diffstat:
         ical.c                              |      12 +++++++++---
       
       1 file changed, 9 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/ical.c b/ical.c
       @@ -207,7 +207,7 @@ vitems_read(int fd)
                vitemprop_t *itemprop;
                char *filebuf, *rp, *p, *sepp, *paramsp, buf[1024], *pbuf, *line,
                     *oline;
       -        int len, state, blen;
       +        int len, state, blen, lnum;
        
                filebuf = readtoeoffd(fd, &len);
                if (filebuf == NULL)
       @@ -220,6 +220,7 @@ vitems_read(int fd)
                rp = filebuf;
                p = filebuf;
                line = NULL;
       +        lnum = 0;
                for (;;) {
                        if (line != NULL)
                                free(line);
       @@ -231,6 +232,8 @@ vitems_read(int fd)
                                break;
        
                        for (; (rp = sgets(buf, sizeof(buf)-1, &p));) {
       +                        lnum++;
       +
                                blen = strlen(buf);
                                if (buf[blen-1] == '\r') {
                                        buf[blen-1] = '\0';
       @@ -262,9 +265,12 @@ vitems_read(int fd)
                        if (line == NULL)
                                break;
        
       +                if (strlen(line) == 0)
       +                        continue;
       +
                        sepp = strchr(line, ':');
                        if (sepp == NULL)
       -                        die("Syntax error.\n");
       +                        die("No ':' separator. (line: %d)\n", lnum);
        
                        sepp[0] = '\0';
                        sepp++;
       @@ -286,7 +292,7 @@ vitems_read(int fd)
                                        state = STATE_VCALEND;
                                } else {
                                        if (item == NULL)
       -                                        die("item == NULL\n");
       +                                        die("item == NULL (line: %d)\n", lnum);
                                        vitems_additem(items, item);
                                        item = NULL;
                                }