support for comments to ignore lines
authorJonas Jelten <jj@sft.mx>
Mon, 19 Jan 2015 03:28:24 +0000 (04:28 +0100)
committerJonas Jelten <jj@sft.mx>
Mon, 19 Jan 2015 03:28:24 +0000 (04:28 +0100)
use # as first character in a line to skip this line
from the slides.

example
sent.c

diff --git a/example b/example
index 06271163cf2d8a999c830812a58c49d44ac930a1..6aa415a39f5470786a2319cad638f9516227f8fe 100644 (file)
--- a/example
+++ b/example
@@ -7,5 +7,6 @@ no bloat
 how?
 sent FILENAME
 one slide per line
+# comments
  @FILE.png
 thanks / questions?
diff --git a/sent.c b/sent.c
index f089393759f2f1a22ae65d523f8df0b728249472..0e3f757d960961c21712e2b25d707c9be6fcc5dc 100644 (file)
--- a/sent.c
+++ b/sent.c
@@ -440,19 +440,22 @@ void load(FILE *fp)
 {
        static size_t size = 0;
        char buf[BUFSIZ], *p;
-       size_t i;
+       size_t i = slidecount;
 
        /* read each line from stdin and add it to the item list */
-       for (i = slidecount; fgets(buf, sizeof(buf), fp); i++) {
+       while (fgets(buf, sizeof(buf), fp)) {
                if ((i+1) * sizeof(*slides) >= size)
                        if (!(slides = realloc(slides, (size += BUFSIZ))))
                                eprintf("cannot realloc %u bytes:", size);
+               if (*buf == '#')
+                       continue;
                if ((p = strchr(buf, '\n')))
                        *p = '\0';
                if (!(slides[i].text = strdup(buf)))
                        eprintf("cannot strdup %u bytes:", strlen(buf)+1);
                if (slides[i].text[0] == '@')
                        slides[i].img = pngopen(slides[i].text + 1);
+               i++;
        }
        if (slides)
                slides[i].text = NULL;