aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/dformat
blob: f14b584146e0d02cf411e49a09232302a8bccda3 (plain)
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
awk '
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"
        n = split(s, x)
        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.9" }
                }
                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
                }
                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]+$/, "")
                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]+/, ""); gsub(/[ \t]+$/, ""); 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 "
                if (boxname != "") printf "  %s:", boxname
                printf "  BoxB: box %s %s ht %g wid %g with .w at BoxB.e\n",
                        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") }
' $*