From 9d71da175ace4a0efae0449d8667ed4dba585e90 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 21 Oct 2022 13:58:15 +0200 Subject: [PATCH] colorize: make it compatible with BSD awk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the following error seen on MacOS: /usr/bin/awk: syntax error at source line 22 source file header_pattern = >>> @ <<< /^[A-Z][[:alnum:]-]+:/ The @ character in front of regular expressions to pre-compile them seems not in the POSIX specification. Replace them with regular strings and call match() instead of the ~ operator. Also, adjust the url_pattern expression for BSD awk which explicitly states: The awk utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”) specification, except awk does not support {n,m} pattern matching. Use [[:lower:]]+ instead of [a-z]{2,6}. Tested with: GNU Awk 5.1.1 awk version 20121220 (FreeBSD) Link: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html Fixes: https://todo.sr.ht/~rjarry/aerc/96 Signed-off-by: Robin Jarry Acked-by: Koni Marti --- filters/colorize | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/filters/colorize b/filters/colorize index 77f2603..da3aac3 100755 --- a/filters/colorize +++ b/filters/colorize @@ -23,9 +23,9 @@ BEGIN { in_headers = 0 in_body = 0 # patterns - header_pattern = @/^[A-Z][[:alnum:]-]+:/ - url_pattern = @/[a-z]{2,6}:\/\/[[:graph:]]+|(mailto:)?[[:alnum:]_\+\.~\/-]*[[:alnum:]_]@[[:lower:]][[:alnum:]\.-]*[[:lower:]]/ - meta_pattern = @/^(diff --git|(new|deleted) file|similarity index|(rename|copy) (to|from)|index|---|\+\+\+) / + header_pattern = "^[A-Z][[:alnum:]-]+:" + url_pattern = "[[:lower:]]+://[[:graph:]]+|(mailto:)?[[:alnum:]_\\+\\.~/-]*[[:alnum:]_]@[[:lower:]][[:alnum:]\\.-]*[[:lower:]]" + meta_pattern = "^(diff --git|(new|deleted) file|similarity index|(rename|copy) (to|from)|index|---|\\+\\+\\+) " } function color_quote(line) { level = 0 @@ -50,7 +50,7 @@ function color_quote(line) { } else { color = quote_x } - if (line ~ meta_pattern) { + if (match(line, meta_pattern)) { return color quotes bold line reset } else if (line ~ /^\+/) { return color quotes diff_add line reset @@ -71,7 +71,7 @@ function color_quote(line) { $0 = signature $0 reset } else if ($0 ~ /^@@ /) { gsub(/^@@[^@]+@@/, diff_chunk "&" reset) - } else if ($0 ~ meta_pattern) { + } else if (match($0, meta_pattern)) { $0 = diff_meta $0 reset } else if ($0 ~ /^\+/) { $0 = diff_add $0 reset @@ -117,7 +117,7 @@ function color_quote(line) { } else if ($0 ~ /^-- ?$/) { in_signature = 1 $0 = signature $0 reset - } else if ($0 ~ header_pattern) { + } else if (match($0, header_pattern)) { in_headers = 1 sub(header_pattern, header "&" reset) gsub(url_pattern, url "&" reset)