From f8a4c4a534e695e8d04aec6dcc5c6d6a4ab879dd Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Mon, 25 Jul 2022 22:11:40 +0500 Subject: [PATCH] Refactor deplist --- Makefile | 4 ++-- deptable/insert.awk | 20 ++++++++++++++++++++ deptable/insert.sh | 21 --------------------- deptable/list.awk | 4 +++- deptable/markdown.sed | 16 ++++++++++++++++ deptable/markdown.sh | 7 ------- deptable/roff.sed | 16 ++++++++++++++++ deptable/roff.sh | 11 ----------- 8 files changed, 57 insertions(+), 42 deletions(-) create mode 100755 deptable/insert.awk delete mode 100755 deptable/insert.sh create mode 100755 deptable/markdown.sed delete mode 100755 deptable/markdown.sh create mode 100755 deptable/roff.sed delete mode 100755 deptable/roff.sh diff --git a/Makefile b/Makefile index 0a56a82..2f4adde 100644 --- a/Makefile +++ b/Makefile @@ -41,8 +41,8 @@ clean: $(MAKE) -C embed clean docs: README.md doc/ctpv.1 - deptable/list.awk $(PRE) | deptable/markdown.sh | deptable/insert.sh README.md - deptable/list.awk $(PRE) | deptable/roff.sh | deptable/insert.sh doc/ctpv.1 + deptable/list.awk $(PRE) | deptable/markdown.sed | deptable/insert.awk README.md + deptable/list.awk $(PRE) | deptable/roff.sed | deptable/insert.awk doc/ctpv.1 ctpv: $(OBJ) $(CC) -o $@ $+ $(LDFLAGS) diff --git a/deptable/insert.awk b/deptable/insert.awk new file mode 100755 index 0000000..2aa3bbf --- /dev/null +++ b/deptable/insert.awk @@ -0,0 +1,20 @@ +#!/usr/bin/gawk -f + +@include "inplace" + +BEGIN { + while ((getline line < "-") > 0) + input = input line "\n" + close("-") +} + +/TABLEEND/ { + table = 0 + printf "%s", input +} + +!table + +/TABLESTART/ { + table = 1 +} diff --git a/deptable/insert.sh b/deptable/insert.sh deleted file mode 100755 index 4615042..0000000 --- a/deptable/insert.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -set -e - -tmp="$(mktemp XXXXXX)" -table="$(mktemp XXXXXX)" -trap 'rm "$table"' EXIT - -cat > "$table" - -sed " - /TABLESTART/,/TABLEEND/ { - /TABLESTART/ { - r $table - b - } - /TABLEEND/!d - } -" "$1" > "$tmp" - -mv -- "$tmp" "$1" diff --git a/deptable/list.awk b/deptable/list.awk index 33e6c17..276aeb5 100755 --- a/deptable/list.awk +++ b/deptable/list.awk @@ -38,5 +38,7 @@ BEGIN { process_file(ARGV[i]) for (t in types) - printf "%s\t%s\n", t, join(types[t], " ") + s = s sprintf("%s\t%s\n", t, join(types[t], " ")) + + printf "%s", s | "sort" } diff --git a/deptable/markdown.sed b/deptable/markdown.sed new file mode 100755 index 0000000..539366d --- /dev/null +++ b/deptable/markdown.sed @@ -0,0 +1,16 @@ +#!/bin/sed -f + +# Add header +1i\ +| File types | Programs |\ +| ---- | ---- | + +# Format rows +s/ /` `/g +s/\t/ | `/ +s/^/| / +s/$/` |/ + +# Add a newline at the end +$a\ + diff --git a/deptable/markdown.sh b/deptable/markdown.sh deleted file mode 100755 index 4671645..0000000 --- a/deptable/markdown.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -echo "| File types | Programs |" -echo "| ---- | ---- |" - -sort | sed 's/ /` `/g; s/^/| /; s/\t/ | `/; s/$/` |/' -echo diff --git a/deptable/roff.sed b/deptable/roff.sed new file mode 100755 index 0000000..7e37fec --- /dev/null +++ b/deptable/roff.sed @@ -0,0 +1,16 @@ +#!/bin/sed -f + +# Add header +1i\ +.TS\ +allbox;\ +lb lb\ +l li .\ +File type\tPrograms + +# Format rows +s/\t/&T{\n/; s/$/\nT}/ + +# Add footer +$a\ +.TE diff --git a/deptable/roff.sh b/deptable/roff.sh deleted file mode 100755 index 1932836..0000000 --- a/deptable/roff.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -echo '.TS' -echo 'allbox;' -echo 'lb lb' -echo 'l li .' - -printf '%s\t%s\n' 'File type' 'Programs' -sort | sed 's/\t/&T{\n/; s/$/\nT}/' - -echo '.TE'