-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathMANUAL2man
executable file
·88 lines (70 loc) · 1.86 KB
/
MANUAL2man
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
#
# MANUAL2man : MANUAL ディレクトリ以下のテキスト・ファイルを man の形式に変換する。
# : written by 柳 日向 ([email protected]; 2023/03/19)
#
version="Sat Mar 18 15:55:31 JST 2023"
edition=1
case "${1:-}" in
--version|--help)
cat >&2 <<-EOF
Usage : $(basename "$0")
Version : ${version}
Edition : ${edition}
EOF
exit 1
esac
version="$("$1" --version 2>&1 | fpad _ 3 | selr 1 Version | self 3/NF | xargs -I{} date -d "{}" +%Y%m%d)"
awk -vname="$1" -vsection=1 \
-vversion_date="$(dayslash --output 'yyyy-mm-dd' 1 <<< "${version}" | LANG=C xargs -I{} date -d{} +"%d %b %Y")" \
-vversion="${version}" -vspace="$(echo -ne '\r\xe2\x80\x89')" '
/^(- ?)+$/ { next }
NR == 1 {
print ".TH ", "Tukubai", section, "\"" version_date "\"", "\"usp Tukubai\"", "\"Tukubai コマンド マニュアル\"";
next;
}
match($0, /^(<(.+)>(.*)|([^(]+)).+)$/, title) {
gsub(/[<>]/, "", title[1]);
gsub(")", " ", title[1]);
print ".SH", title[1];
if (title[3] != "") {
printf " " title[2];
}
next;
}
/^\s*$/ {
source = 0;
}
/^\$/ {
print "";
source = 1;
}
match($0, /^# ([0-9]{8}) (.+)$/, matches) {
# 余談が開始したとき。
if (digression != 1) {
print "";
print ".SH", "履歴";
}
digression = 1
print " " substr(matches[1], 0, 4) "年" substr(matches[1], 5, 2) "月" substr(matches[1], 7, 2) "日 " matches[2];
next;
}
/^ {8}/ {
print;
print ".br";
next;
}
{
gsub(/\\t/, " ", $0);
gsub(/\\/, "\x5c", $0);
$0 = gensub(/([^!-~] +)([!-~]+) +([^!-~])/, "\\1" space "\\2" space "\\3", "", $0);
if (source) {
print " " $0;
next;
}
gsub(/\\/, "\\\x5c");
gsub(/<[^!][^>]+[^-]> *\n/, "\n.I \\0\\n", $0);
gsub(/ /, "\\ ", $0);
print $0;
print ".br";
}'