From 1a1d36f59624cdd0be6b131d4e9fb56bc772e3b5 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 29 Apr 2020 17:07:39 -0400 Subject: Highlight diff/index/---/+++ lines of patches as well --- html.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/html.c b/html.c index 850e070..ee9e966 100644 --- a/html.c +++ b/html.c @@ -14,8 +14,9 @@ * along with this program. If not, see . */ -#include +#include #include +#include #include #include #include @@ -225,11 +226,7 @@ static int htmlMarkupURLs(FILE *file, char *buf) { static regex_t regex; if (!regex.re_nsub) { int error = regcomp(®ex, Pattern, REG_EXTENDED); - if (error) { - char buf[256]; - regerror(error, ®ex, buf, sizeof(buf)); - errx(EX_SOFTWARE, "%s: %s", buf, Pattern); - } + assert(!error); } int error; @@ -281,15 +278,21 @@ static int htmlMarkup(FILE *file, const char *content) { patch = false; } - if (patch && !strncmp(buf, "@@", 2)) { + static const char *Pattern = "^(diff|index|---|[+]{3}|@@) "; + static regex_t regex; + if (!regex.re_nsub) { + error = regcomp(®ex, Pattern, REG_EXTENDED); + assert(!error); + } + if (patch && !regexec(®ex, buf, 0, NULL, 0)) { error = templateRender( file, TEMPLATE([line]), vars, escapeXML ); - } else if (patch && buf[0] == '-' && strncmp(buf, "---", 3)) { + } else if (patch && buf[0] == '-' && strcmp(buf, "---")) { error = templateRender( file, TEMPLATE([line]), vars, escapeXML ); - } else if (patch && buf[0] == '+' && strncmp(buf, "+++", 3)) { + } else if (patch && buf[0] == '+') { error = templateRender( file, TEMPLATE([line]), vars, escapeXML ); -- cgit 1.4.1