tdefine some run-time options, change some options - webdump - [FORK] git://git.codemadness.org/webdump
 (HTM) git clone git://git.z3bra.org/webdump.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 46afcf5acd4771e10f93530cd4108a14dc416564
 (DIR) parent 553dfc4b2c06d714579eba44fbdf812520477a51
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Thu, 21 Nov 2019 00:18:22 +0100
       
       define some run-time options, change some options
       
       Diffstat:
         M TODO                                |      13 +++++++++++++
         M webdump.c                           |      34 ++++++++++++++++++-------------
       
       2 files changed, 33 insertions(+), 14 deletions(-)
       ---
 (DIR) diff --git a/TODO b/TODO
       t@@ -1,3 +1,16 @@
       +- add -w flag for line-wrapping?
       +
       +
       +http://git.z3bra.org/webdump/log.html
       +
       +
       +? skip <br/> in empty table cell.
       +
       +- import more named entities.
       +
       +- suppress repeated newlines somewhat?
       +
       +
        <div>
        <span>test</span>
        
 (DIR) diff --git a/webdump.c b/webdump.c
       t@@ -28,10 +28,12 @@ struct uri {
                char port[6];     /* numeric port */
        };
        
       -static int termwidth = 72;
       -
       -//#define LINKREFS
       +/* options */
       +static int allowesc     = 0;  /* alloc ANSI escape codes */
       +static int showlinkrefs = 0;  /* show link references at the bottom */
       +static int termwidth    = 72; /* terminal width */
        
       +#define LINKREFS
        #ifdef LINKREFS
        /* linked-list of link references */
        struct linkref {
       t@@ -265,7 +267,7 @@ printc(int c)
                        }
                }
        
       -#if 0
       +#if 1
                /* DEBUG: soft line-wrapping on white-space and certain characters like ',' */
                /* TODO: better line-wrapping */
                if (strchr(" \n\t", c) && ncharsline >= termwidth)
       t@@ -606,7 +608,8 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort)
                        }
                }
        
       -        if (cur->tag.displaytype & (DisplayBold | DisplayItalic | DisplayUnderline))
       +        if (allowesc &&
       +            cur->tag.displaytype & (DisplayBold | DisplayItalic | DisplayUnderline))
                        fputs("\033[0m", stdout); /* reset */
        
                /* specific tag handling */
       t@@ -642,7 +645,7 @@ xmltagstartparsed(XMLParser *p, const char *t, size_t tl, int isshort)
        
        #ifdef LINKREFS
                /* show links as reference at the bottom */
       -        if (src[0]) {
       +        if (showlinkrefs && src[0]) {
                        char absurl[1024];
                        if (absuri(absurl, sizeof(absurl), src, basehref) != -1) {
                                if (!links_head)
       t@@ -660,8 +663,8 @@ xmltagstartparsed(XMLParser *p, const char *t, size_t tl, int isshort)
                                }
        
                        }
       +                src[0] = '\0';
                }
       -        src[0] = '\0';
        #endif
        
        #if 0
       t@@ -712,12 +715,14 @@ xmltagstartparsed(XMLParser *p, const char *t, size_t tl, int isshort)
                        }
                }
        
       -        if (cur->tag.displaytype & DisplayBold)
       -                fputs("\033[1m", stdout);
       -        if (cur->tag.displaytype & DisplayItalic)
       -                fputs("\033[3m", stdout);
       -        if (cur->tag.displaytype & DisplayUnderline)
       -                fputs("\033[4m", stdout);
       +        if (allowesc) {
       +                if (cur->tag.displaytype & DisplayBold)
       +                        fputs("\033[1m", stdout);
       +                if (cur->tag.displaytype & DisplayItalic)
       +                        fputs("\033[3m", stdout);
       +                if (cur->tag.displaytype & DisplayUnderline)
       +                        fputs("\033[4m", stdout);
       +        }
        
                /* specific tag handling */
                if (!strcasecmp(t, "hr")) { /* ruler */
       t@@ -775,7 +780,8 @@ main(int argc, char **argv)
                xml_parse(&parser);
        
        #ifdef LINKREFS
       -        printlinkrefs();
       +        if (showlinkrefs)
       +                printlinkrefs();
        #endif
                putchar('\n');