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
|
awk ' # format
# Input: sort key (tab) string (tab) numlist
# Output: troff format, commands interpreted
BEGIN { FS = "\t"
s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz "
# set upper["a"] = "A"
for (i = 1; i <= 27; i++) upper[substr(s,i+27,1)] = substr(s,i,1)
# set lower["a"] = lower["A"] ="a"
for (i = 1; i <= 27; i++) {
lower[substr(s,i,1)] = substr(s,i+27,1)
lower[substr(s,i+27,1)] = substr(s,i+27,1)
}
}
{ # mark change between letters with .YY
# find first non-punctuation char
for (i = 1; (c = substr($1,i,1)) != ""; i++)
if (c ~ /[a-zA-Z0-9 ]/)
break
this = c
if (!(this in lower)) lower[this] = " "
this = lower[this]
if (this != last) # && this != " ")
print ".YY", this, upper[last=this]
quoted = 0
# interpret font change language
if ($2 ~ /^ /) # different macro, to avoid bad breaks in hier
print ".ZZ"
else
print ".XX"
if (NF == 3)
$0 = $2 "," " " $3 # discard sort key, leave term .. numlist
else
$0 = $2
if ($0 ~ /%/) {
quoted = 1
gsub(/%%/, "QQ0QQ", $0)
gsub(/%\[/, "QQ1QQ", $0)
gsub(/%\]/, "QQ2QQ", $0)
gsub(/%\{/, "QQ3QQ", $0)
gsub(/%\}/, "QQ4QQ", $0)
gsub(/%~/, "QQ5QQ", $0)
}
gsub(/%e/, "\\e", $0) # %e -> \e
gsub(/~/, " ", $0) # unpaddable spaces go away at last
if (gsub(/\[/, "\\\\&\\f(CW", $0))
gsub(/\]/, "\\fP", $0)
if (gsub(/\{/, "\\f2", $0))
gsub(/\}/, "\\fP", $0)
if (quoted) {
gsub(/%/, "", $0)
gsub(/QQ0QQ/, "%", $0)
gsub(/QQ1QQ/, "[", $0)
gsub(/QQ2QQ/, "]", $0)
gsub(/QQ3QQ/, "{", $0)
gsub(/QQ4QQ/, "}", $0)
gsub(/QQ5QQ/, "~", $0)
}
printf "\\&%s\n", $0
}
' $*
|