-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport
More file actions
executable file
·59 lines (59 loc) · 1.13 KB
/
import
File metadata and controls
executable file
·59 lines (59 loc) · 1.13 KB
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
#!/bin/sh
if [ -z "$1" ] || [ -n "$3" ]; then
echo "usage: import BLOCK [TITLE]" >&2
exit 1
fi
awk -vb=$1 -vtitle=$2 '
function padl(str) {
for(i = 64 - length(str); i > 0; --i) str = str " "
return str
}
function mkhdr() {
hdr = padl(substr("\\ " title " (" n ") Load Save Snarf Paste Prev Next Abort Doc", 1, 64))
}
function emit() {
printf("%d ", b)
printf("%s%s%s%s", hdr, empty, bl, empty) >b
close b
bl = ""
r = 0
++b
++n
mkhdr()
}
function trim(s) {
p = match(s, "[ \n\t]+$")
if(p != 0) return substr(s, 1, RSTART)
return s
}
BEGIN {
bl = ""
r = 0
ln = n = 1
mkhdr()
empty = padl("")
}
{
s = trim($0)
if(s == "") {
bl = bl empty
if(r++ >= 35) emit()
++ln
next
}
while(s != "") {
h = trim(substr(s, 1, 64))
t = substr(s, 65)
if(length(t) && length(h) == 64 && substr(t, 1, 1) != " ") {
printf("line too long: %d: %s\n", ln, $0);
exit(1)
}
bl = bl padl(h)
if(r++ >= 35) emit()
s = t
}
++ln
}
END {
if(bl != "") emit()
}' -