Refactor deplist

This commit is contained in:
Nikita Ivanov 2022-07-25 22:11:40 +05:00
parent fda170aa19
commit f8a4c4a534
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
8 changed files with 57 additions and 42 deletions

View File

@ -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)

20
deptable/insert.awk Executable file
View File

@ -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
}

View File

@ -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"

View File

@ -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"
}

16
deptable/markdown.sed Executable file
View File

@ -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\

View File

@ -1,7 +0,0 @@
#!/bin/sh
echo "| File types | Programs |"
echo "| ---- | ---- |"
sort | sed 's/ /` `/g; s/^/| /; s/\t/ | `/; s/$/` |/'
echo

16
deptable/roff.sed Executable file
View File

@ -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

View File

@ -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'