From 63739502acefd23e2f5307921c7e88db1e5d5f34 Mon Sep 17 00:00:00 2001 From: Sekulum Forka Date: Sun, 9 Apr 2023 22:50:45 +0200 Subject: [PATCH 1/2] mcom: remove needless invocations of awk Fixes #238. --- mcom | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mcom b/mcom index 397cb5f..9db1255 100755 --- a/mcom +++ b/mcom @@ -276,7 +276,7 @@ fi commajoin | sed 's/^/Cc: /' printf '%s' "$hdrs" | mhdr -M -h bcc - | commajoin | sed 's/^/Bcc: /' - printf '%s\n' "$hdrs" | awk '{ print }' | + printf '%s\n' "$hdrs" | msed "/to/d; /cc/d; /bcc/d; /body/d" - } | msed "/cc/a//; /bcc/a//; /subject/a//; /from/a/$default_from/" - | sed '/^$/d' msgid @@ -298,7 +298,7 @@ fi printf '%s' "$hdrs" | mhdr -M -h bcc - | commajoin | sed 's/^/Bcc: /' COLUMNS=10000 mscan -f 'Subject: Fwd: [%f] %s' "$@" 2>/dev/null | sed 1q - printf '%s\n' "$hdrs" | awk '{ print }' | + printf '%s\n' "$hdrs" | msed "/to/d; /cc/d; /bcc/d" - } | msed "/cc/a//; /bcc/a//; /from/a/$default_from/" - | sed '/^$/d' msgid @@ -335,7 +335,7 @@ fi commajoin | sed 's/^/Resent-To: /' printf '%s' "$hdrs" | mhdr -M -h resent-cc - | commajoin | sed 's/^/Resent-Cc: /' - printf '%s\n' "$hdrs" | awk '{ print }' | + printf '%s\n' "$hdrs" | msed "/resent-to/d; /resent-cc/d" - } | msed "/resent-to/a//; /resent-from/a/$default_from/" - | sed '/^$/d' @@ -368,11 +368,11 @@ fi notmine |grep -Fv -e "$to" | ouniq |commajoin)" printf 'Bcc: \n' - printf '%s\n' "$hdrs" | awk '{ print }' | + printf '%s\n' "$hdrs" | msed "/body/d" - fi | sed '/^$/d' printf 'Subject: Re: %s\n' "$(COLUMNS=10000 mscan -f '%S' "$1")" - if ! printf '%s\n' "$hdrs" | awk '{ print }' | + if ! printf '%s\n' "$hdrs" | mhdr -h from: - >/dev/null; then addr=$(maddr -a -h delivered-to:to:cc:bcc: "$1" | replyfrom | head -n1) [ -n "$addr" ] && from=$(maddr -h reply-from "$MBLAZE/profile" | grep -Fi "<$addr>" | head -n1) From e8eacb19578b7a59e4d673497329b7a7befaeed1 Mon Sep 17 00:00:00 2001 From: Sekulum Forka Date: Mon, 10 Apr 2023 10:15:21 +0200 Subject: [PATCH 2/2] msed: replace while loops with c string functions --- msed.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/msed.c b/msed.c index c545278..ce94cb9 100644 --- a/msed.c +++ b/msed.c @@ -114,24 +114,19 @@ sed(char *file) if (!v) continue; v++; - while (*v && (*v == ' ' || *v == '\t')) - v++; + v += strspn(v, " \t"); v = strdup(v); char *e = expr; while (*e) { - while (*e && - (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';')) - e++; - *headersel = 0; + e += strspn(e, " \t\n;"); if (*e == '/') { e++; char *s = e; // parse_headers, sets headersel - while (*e && *e != '/') - e++; + e = strchr(e, '/'); snprintf(headersel, sizeof headersel, "^(%.*s)*:", (int)(e-s), s); for (s = headersel; *s && *(s+1); s++) @@ -167,8 +162,7 @@ sed(char *file) fprintf(stderr, "msed: unterminated a command\n"); exit(1); } - while (*e && *e != sep) - e++; + e = strchr(e, sep); if (*e == sep) e++; if (!(*e == ' ' || *e == ';' || *e == '\n' || !*e)) { @@ -179,22 +173,18 @@ sed(char *file) case 'c': sep = *++e; s = ++e; - while (*e && *e != sep) - e++; + e = strchr(e, sep); free(v); v = strndup(s, e-s); break; case 's': sep = *++e; s = ++e; - while (*e && *e != sep) - e++; + e = strchr(e, sep); char *t = ++e; - while (*e && *e != sep) - e++; + e = strchr(e, sep); char *u = ++e; - while (*e == 'd' || *e == 'g' || *e == 'i') - e++; + e += strspn(e, "dgi"); if (!(*e == ' ' || *e == ';' || *e == '\n' || !*e)) { fprintf(stderr, "msed: unterminated s command\n"); @@ -226,8 +216,7 @@ sed(char *file) exit(1); } } - while (*e && *e != ';' && *e != '\n') - e++; + e += strcspn(e, ";\n"); } if (v) { printhdr(h, 0); @@ -241,17 +230,14 @@ sed(char *file) char *hs, *he; char *e = expr; while (*e) { - while (*e && - (*e == ' ' || *e == '\t' || *e == '\n' || *e == ';')) - e++; + e += strspn(e, " \t\n;"); hs = he = 0; if (*e == '/') { e++; hs = e; // parse_headers, sets headersel - while (*e && *e != '/') - e++; + e = strchr(e, '/'); he = e; if (*e) e++; @@ -281,8 +267,7 @@ sed(char *file) exit(1); } s = ++e; - while (*e && *e != sep) - e++; + e = strchr(e, sep); v = strndup(s, e-s); } @@ -305,8 +290,7 @@ sed(char *file) // ignore here; break; } - while (*e && *e != ';' && *e != '\n') - e++; + e += strcspn(e, ";\n"); } printf("\n");