-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdformat.awk
185 lines (164 loc) · 3.64 KB
/
dformat.awk
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#! /bin/awk -f
# mailto:[email protected]
function error(s)
{
print("dformat error: " s " near input line " NR) | "cat 1>&2"
}
BEGIN {
s = "recht 0.3 addrht 0.055 recspread 0.15 "
s = s "charwid 0.07 textht 0.167 addrdelta 4 "
s = s "bitwid 0.125 linedisp 0.04 addr both "
s = s "fill off linethrutext 1 "
s = s "shaded off"
n = split(s, x, FS)
for (i = 1; i <= n - 1; i += 2) oparm[x[i]] = parm[x[i]] = x[i + 1]
}
inlang == 0 {
if ($0 !~ /^\.begin[ \t]/ || $2 != "dformat") {
print
} else {
inlang = 1
print ".PS"
boxacnt = 0
if (firstpic != 1) {
firstpic = 1
print "fillval = 0.1"
}
}
next
}
/^\.end/ {
inlang = 0
print ".PE"
next
}
$1 == "style" {
if (! ($2 in parm)) {
error("unrecognized name: " $2)
} else if ($3 == "reset") {
t = oparm[$2]
oparm[$2] = parm[$2]
parm[$2] = t
} else {
oparm[$2] = parm[$2]
parm[$2] = $3
#error("set shaded to: " $3)
}
next
}
$1 == "pic" {
$1 = ""
print $0
next
}
/^[^ \t]/ {
printf "BoxA: box invis ht %g wid 0", parm["recht"]
if (boxacnt++) {
printf " with .n at BoxA.s - (0, %g)",
parm["recspread"] + maxdy * parm["textht"]
}
printf "\n"
maxdy = sumboxlen = 0
gsub(/[ \t]+$/, "", $0)
if ($0 != "noname") {
printf " \"%s \" rjust at BoxA.w\n", $0
printf " box invis with .e at BoxA.w ht 0 wid %g\n",
parm["charwid"] * (length($0) + 3)
}
printf " BoxB: box invis ht %g wid 0 at BoxA\n", parm["recht"]
next
}
/./ {
boxname = ""
if ($1 ~ /:$/) {
boxname = substr($1, 1, length($1) - 1)
$1 = ""
$0 = " " $0
}
range = $1
$1 = ""
gsub(/^[ \t]+/, "", $0)
gsub(/[ \t]+$/, "", $0)
text = $0
n = split(range, x, "-")
rlo = x[1]
rhi = (n >= 2) ? x[2] : rlo
cwid = (rhi >= rlo) ? rhi - rlo + 1 : rlo - rhi + 1
rwid = (n >= 3) ? (0 + x[3]) : cwid
btype = x[4]
if (btype !~ /^(dot|dash|invis)/) {
btype = "solid"
}
textlen = parm["charwid"] * length(text)
boxlen = parm["bitwid"] * rwid
dy = 0
if (textlen > boxlen) {
# set dy, the channel for this text
chan[maxdy + 1] = -999
for (dy = 1; chan[dy] + textlen > sumboxlen; dy++);
if (dy > maxdy) {
maxdy = dy
}
if (parm["linethrutext"] == 0) {
for (k = 1; k <= dy; k++) {
chan[k] = sumboxlen + boxlen
}
} else {
chan[dy] = sumboxlen
}
}
sumboxlen += boxlen
fill = ""
if (parm["fill"] == "on") {
fill = " fill "
}
shaded = ""
if (parm["shaded"] != "off") {
shaded = " shaded "
shaded = shaded "\"" parm["shaded"] "\" "
}
if (boxname != "") {
printf " %s:", boxname
}
printf " BoxB: box %s %s %s ht %g wid %g with .w at BoxB.e\n",
shaded, fill, btype, parm["recht"], boxlen
if (dy == 0) {
printf " \"%s\" at BoxB.c\n", text
} else {
if (rwid < 2) {
start = "BoxB.s"
} else {
start = "BoxB.se - (" parm["linedisp"] ",0)"
}
printf " line from %s down %g\n", start, dy * parm["textht"]
printf " \"%s\\|\" at last line .s rjust\n", text
printf " box invis with .e at last line .s ht 0 wid %g\n",
textlen
}
if (parm["addr"] ~ /^(left|right|both)$/) {
dp = int(parm["addrdelta"]) # Delta Point size
if (dp < 0 || dp > 9) {
error("bad addrdelta value: " dp)
}
dah = parm["addrht"] # Delta Addr Height
pb = parm["addr"] # Parameter for Bits
if (rlo == rhi) {
printf " \"\\s-%d%s\\s+%d\" at BoxB.s + (0,%g)\n",
dp, rlo, dp, dah
} else {
if (pb == "left" || pb == "both") {
printf "\t\"\\|\\s-%d%s\\s+%d\" ljust at BoxB.sw + (0,%g)\n",
dp, rlo, dp, dah
}
if (pb == "right" || pb == "both") {
printf "\t\"\\s-%d%s\\s+%d\\|\" rjust at BoxB.se + (0,%g)\n",
dp, rhi, dp, dah
}
}
}
}
END {
if (inlang) {
error("eof inside begin/end")
}
}