aboutsummaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-10-21 13:58:15 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-23 20:51:02 +0200
commit9d71da175ace4a0efae0449d8667ed4dba585e90 (patch)
tree42f0f1c80abaab8d9c642e451fecf44f55e55221 /filters
parent8e37d16a32ee89260e9dbf7bd04c0e91e135cfbe (diff)
downloadaerc-9d71da175ace4a0efae0449d8667ed4dba585e90.tar.gz
colorize: make it compatible with BSD awk
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 <robin@jarry.cc> Acked-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'filters')
-rwxr-xr-xfilters/colorize12
1 files changed, 6 insertions, 6 deletions
diff --git a/filters/colorize b/filters/colorize
index 77f26035..da3aac3f 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)