diff options
author | Robin Jarry <robin@jarry.cc> | 2023-01-17 14:33:09 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-26 00:20:45 +0100 |
commit | 3191ee171c435a43912264b131340af66fea8112 (patch) | |
tree | 2a68c5c4a3b9975d102cb379171548e7a8937da5 /filters/test.sh | |
parent | a8b6693f7e7bdcc8b73c3fa0baa0ef5f51993dc7 (diff) | |
download | aerc-3191ee171c435a43912264b131340af66fea8112.tar.gz |
filters: rewrite wrap in c
This utility introduced in commit c9524d265793 ("filters: add wrap
utility written in go") allows to reflow text to view emails that have
very long lines without breaking quotes, lists and indentation.
For such a simple task, go produces a binary that is 2.0M bytes on disk.
After stripping debugging symbols, it can be reduced to 1.2M bytes. All
of this for 267 lines of source code. This is a bit ridiculous, provided
people may load this binary into memory multiple times per minute. This
tool is a small side-project that seems not suitable for golang.
Rewrite it in C. It now only depends on a POSIX libc to run. It is safe
to assume that there is one available on all *NIX systems in the world
of 2023. The resulting binary is now 27K bytes (15K after stripping).
To build it, a C compiler and libc headers are required. These should
most likely be available since they are dependencies of the go compiler
toolchain.
I have tested compilation (with clang-analyzer and gcc -fanalyzer) and
basic operation on FreeBSD, Fedora (glibc) and Alpine (musl libc). More
tests would probably be required on MacOSX and older Linux distros.
I also added test vectors to give some confidence that this works as
expected.
Update CI with aggressive gcc hardening flags and to run these tests
with valgrind --leak-check=full.
Command line options are unchanged:
usage: wrap [-h] [-w INT] [-r] [-l INT] [-f FILE]
Wrap text without messing up email quotes.
options:
-h show this help message
-w INT preferred wrap margin (default 80)
-r reflow all paragraphs even if no trailing space
-l INT minimum percentage of letters in a line to be considered
a paragaph
-f FILE read from filename (default stdin)
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Maxwell G <gotmax@e.email>
Diffstat (limited to 'filters/test.sh')
-rwxr-xr-x | filters/test.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/filters/test.sh b/filters/test.sh new file mode 100755 index 00000000..65a1d4d3 --- /dev/null +++ b/filters/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +set -e + +here=$(dirname $0) +fail=0 + +for vec in $here/vectors/*.in; do + tool=$(basename $vec | sed 's/-.*//') + expected=${vec%%.in}.expected + tmp=$(mktemp) + if ! $FILTERS_TEST_PREFIX $here/../$tool -f $vec > $tmp; then + fail=1 + fi + if diff -u "$expected" "$tmp"; then + echo "ok $tool < $vec > $tmp" + else + echo "error $tool < $vec > $tmp" + fail=1 + fi + rm -f -- "$tmp" +done + +exit $fail |