Annotation of researchv10dc/cmd/omovie/stills.awk, revision 1.1.1.1

1.1       root        1: BEGIN {
                      2:   # develop is set from first argument of form develop=filename
                      3: 
                      4:   fillstring = "; line from GL.n  to GL.s; line from GL.e  to GL.w "\
                      5:                "; line from GL.ne to GL.sw; line from GL.nw to GL.se"
                      6:   set(textname, "small s medium m big b bigbig B")
                      7:   set(linename, "solid s fat f fatfat F")
                      8:   set(justtr, "l ljust r rjust a above b below")
                      9:   set(linetr, "o dotted a dashed"); linetr["s"] = linetr["f"] = linetr["F"] = ""
                     10:   set(arrowtr, "< <- > -> x <->"); arrowtr["-"] = ""
                     11:   set(convert, "dot \\s+3.\\s-3 bullet \\s-3\\(bu\\s+3 "\
                     12:        "times \\s-3\\(mu\\s+3 circle \\s-3\\(ob\\s+3")
                     13:   instills = 0
                     14: }
                     15: 
                     16: instills == 0        { if ($1 == ".begin" && /^\.begin[ \t]+stills/) {
                     17:                                instills = 1; startstills()
                     18:                        } else print
                     19:                        next
                     20:                      }
                     21: /^\.end/             { instills = 0; endstills(); next }
                     22: END                  { if (instills) fatal("eof inside begin/end") }
                     23: 
                     24:                      { inputline = $0; sub(/\#.*$/, "") }
                     25: /^[ \t]*$/           { next }
                     26: $1 == "view"          { viewnum[$2] = viewct++
                     27:                        if (NF <= 2) text = $2
                     28:                        else {  text = rest(3)
                     29:                                if (text ~ /^"/) {
                     30:                                    if (text !~ /"$/) text = substr(text,2)
                     31:                                    else text=substr(text,2,length(text)-2)
                     32:                                }
                     33:                        }
                     34:                        inviewtitle[$2] = text
                     35:                        next
                     36:                      }
                     37: $1 == "print"         {        sawprint = 1
                     38:                        if ($2 == "all") printglobal = 1
                     39:                        else if ($2 == "final") printfinal = 1
                     40:                        else { # print <clickname> ...
                     41:                                if ($3 == "all") { # print <clickname> all
                     42:                                        allnamearr[$2] = 1
                     43:                                } else { # print <clickname> v1 v2 ...
                     44:                                        if (!($2 in snamenum))
                     45:                                                snamenum[$2] = snamenumct++
                     46:                                        for (i = 3; i <= NF; i++)
                     47:                                            printsome[snamenum[$2] "." $i]=1
                     48:                                }
                     49:                        }
                     50:                        next
                     51:                      }
                     52: /./                  { # parameter assignments
                     53:                        n = $2; sub(/^\+/, "", n); n = 0 + n
                     54:                        if      ($1 == "file")          infile = $2
                     55:                        else if ($1 == "across")        across = n
                     56:                        else if ($1 == "down")          down = n
                     57:                        else if ($1 == "margin")        margin = n
                     58:                        else if ($1 == "frameht")       frameht = n
                     59:                        else if ($1 == "framewid")      framewid = n
                     60:                        else if ($1 in textname)        textinc[textname[$1]] = n
                     61:                        else if ($1 in linename)        lineinc[linename[$1]] = n
                     62:                        else if ($1 ~ /^times?$/) {
                     63:                                wanttime = 1;  if ($2 == "invis") wanttime = 0
                     64:                        } else if ($1 ~ /^frames?$/) {
                     65:                                wantframe = 1; if ($2 == "invis") wantframe = 0
                     66:                        } else warn("unrecognized command")
                     67:                        next 
                     68:                      }
                     69: 
                     70: function rest(f,  s, i) { # rest of $0, starting at $f
                     71:        if (NF <= f) return $f
                     72:        s = $0
                     73:        sub(/^[ \t]+/, "", s)
                     74:        for (i = 1; i < f; i++)
                     75:                sub(/^[^ \t]+[ \t]+/, "", s)
                     76:        return s
                     77: }
                     78: 
                     79: function dump(time,  i, gtype, vnum, x1, x2, y1, y2,
                     80:                opts, text, delta, btype) {
                     81:        btype = ""; if (wantframe == 0) btype = " invis"
                     82:        if (goacross == 0) { # time goes down the page, views go across
                     83:                if (colcnt >= colmax) {
                     84:                        delta = .1; if (wanttime) delta += .8
                     85:                        print "A0: box invis wid 0 ht 0 with .sw at A0.sw + ("\
                     86:                                viewct*framewid + delta " , 0)"
                     87:                        print "B0: box invis wid 0 ht 0 with .sw at A0.sw"
                     88:                        colcnt = 0
                     89:                }
                     90:                print "B0: box" btype " wid framewid ht frameht with .n at B0.s"
                     91:                for (i = 1; i < viewct; i++)
                     92:                        print "B" i ":  box" btype\
                     93:                            " wid framewid ht frameht with .w at B" i-1 ".e"
                     94:                if (colcnt == 0)
                     95:                        for (i = 0; i < viewct; i++)
                     96:                                if (viewtitle[i] != "")
                     97:                                        print "\"" viewtitle[i] "\" at B"\
                     98:                                                viewbase[i] ".n + (0, .1)"
                     99:                if (wanttime)
                    100:                        print "\"" time "\" ljust at B" viewct-1 ".e + (.1,0)"
                    101:        } else { # time goes across the page, views go down
                    102:                if (colcnt >= colmax) {
                    103:                        delta = .1; if (wanttime) delta += .3
                    104:                        print "A0: box invis wid 0 ht 0 with .c at A0.c - (0,"\
                    105:                                viewct*frameht + delta ")"
                    106:                        print "B0: box invis wid 0 ht 0 with .c at A0.c"
                    107:                        colcnt = 0
                    108:                }
                    109:                print "B0: box" btype " wid framewid ht frameht with .w at B0.e"
                    110:                for (i = 1; i < viewct; i++)
                    111:                        print "B" i ":  box" btype\
                    112:                            " wid framewid ht frameht with .n at B" i-1 ".s"
                    113:                if (colcnt == 0)
                    114:                        for (i = 0; i < viewct; i++)
                    115:                                if (viewtitle[i] != "")
                    116:                                        print "\"" viewtitle[i] "\" rjust at B"\
                    117:                                                viewbase[i] ".w - (.1, 0)"
                    118:                if (wanttime)
                    119:                        print "\"" time "\" at B" viewct-1 ".s + (0,-.15)"
                    120:        }
                    121:        colcnt++
                    122:        for (i = 1; i <= slotcnt; i++)
                    123:                if (slot[i] != "") {
                    124:                        if (slot[i] ~ /^g\t/) slot[i] = makepic(slot[i])
                    125:                        print slot[i]
                    126:                }
                    127:        for (i = 1; i <= staticcnt; i++)
                    128:                print static[i]
                    129: }
                    130: 
                    131: function pos(x, y) {
                    132:        return sprintf("B%d.sw+(%.3g,%.3g)", basenum,\
                    133:                framexfac*(frameborder+x), frameyfac*(frameborder+y))
                    134: }
                    135: 
                    136: function makepic(istring,    fields, gtype, vnum, pstring, just,
                    137:                        x1, x2, y1, y2, opts, text, i, t, linemode, arrow,
                    138:                        inc, ss, es) { # convert int file string to pic
                    139:        fields = split(istring, f, "\t")
                    140:        gtype=f[3]; vnum=f[4]; opts=f[5]; x1=f[6]; y1=f[7]
                    141:        basenum = viewbase[vnum]
                    142:        if (gtype == "l") { # line
                    143:                x2 = f[8]; y2 = f[9]
                    144:                linemode = substr(opts,1,1) # solid,fat,fatfat,dotted,dashed
                    145:                arrow = substr(opts,2,1) # -,->,<-, <->
                    146:                pstring = "line " linetr[linemode] " " arrowtr[arrow]\
                    147:                          " from " pos(x1, y1) " to " pos(x2, y2)
                    148:                if (linemode != "f" && linemode != "F") linemode = "s"
                    149:                inc = lineinc[linemode]
                    150:                if (inc != 0) {
                    151:                        if (inc < 0) { ss = inc; es = "+" 0-inc }
                    152:                        else         { ss = "+" inc; es = "-" inc }
                    153:                        pstring = ".ps " ss "\n" pstring "\n.ps " es
                    154:                }
                    155:        } else if (gtype == "b") { # box
                    156:                x2 = f[8]; y2 = f[9]
                    157:                if (x1 > x2) { t = x1; x1 = x2; x2 = t }
                    158:                if (y1 > y2) { t = y1; y1 = y2; y2 = t }
                    159:                pstring = "GL: box with .sw at " pos(x1,y1)\
                    160:                                " ht "  (y2-y1)*frameyfac\
                    161:                                " wid " (x2-x1)*framexfac
                    162:                if (substr(opts,1,1) == "f") pstring = pstring fillstring
                    163:        } else if (gtype == "c") { # circle
                    164:                pstring = "GL: circle radius " framexfac*f[8]\
                    165:                        " at " pos(x1, y1)
                    166:                if (substr(opts,1,1) == "f") pstring = pstring fillstring
                    167:        } else if (gtype == "t") { # text
                    168:                if (fields == 8) text = f[8]
                    169:                for (i = 9; i <= fields; i++) text = text "\t" f[i]
                    170:                if (text in convert) text = convert[text]
                    171:                just = justtr[substr(opts,1,1)]
                    172:                pstring = "\"" text "\" " just " at " pos(x1, y1)
                    173:                inc = textinc[substr(opts,2,1)]
                    174:                if (inc != 0) {
                    175:                        if (inc < 0) { ss = inc; es = "+" 0-inc }
                    176:                        else         { ss = "+" inc; es = "-" inc }
                    177:                        pstring = ".ps " ss "\n" pstring "\n.ps " es
                    178:                }
                    179:        } else warn("int file bug: illegal modifier after g")
                    180:        return pstring
                    181: }
                    182: 
                    183: function warn(s) {
                    184:        print "stills warning: " s >"/dev/tty"
                    185:        print "  near input line " NR ": " inputline >"/dev/tty"
                    186: }
                    187: function fatal(s) {
                    188:        print "stills fatal error: " s >"/dev/tty"
                    189:        print "  near input line " NR ": " inputline >"/dev/tty"
                    190:        exit
                    191: }
                    192: 
                    193: function startstills() {
                    194:        set(textinc, "s -2 m 0 b 3 B 8")
                    195:        set(lineinc, "s 0 f 3 F 8")
                    196:        infile = ""; sawprint = 0
                    197:        frameht = 1.5; framewid = 1.5; margin = 0.05
                    198:        wanttime = wantframe = 1 
                    199:        printglobal = printfinal = 0
                    200:        across = 0; down = -1
                    201:        clear(allnamearr)
                    202:        clear(allnumarr)
                    203:        clear(clickname)
                    204:        clear(inviewtitle)
                    205:        clear(printsome)
                    206:        clear(slot)     ; slotcnt = 0
                    207:        clear(somenum)
                    208:        clear(snamenum) ; snamenumct = 0        
                    209:        clear(static)   ; staticcnt = 0
                    210:        clear(timectr)
                    211:        clear(viewactive)
                    212:        clear(viewtitle)
                    213:        clear(viewnum)  ; viewct = 0    
                    214:        print ".PS"
                    215:        print "A0: B0: box invis wid 0 ht 0"
                    216: }
                    217: 
                    218: function clear(a, i) {
                    219:        for (i in a) delete a[i]
                    220: }
                    221: function set(a, s,  i, n, q) {
                    222:        n = split(s, q)
                    223:        for (i = 1; i < n; i += 2)
                    224:                a[q[i]] = q[i+1]
                    225: }
                    226: 
                    227: function endstills() {
                    228: if (sawprint = 0) warn("no print statements")
                    229: if (viewct == 0) viewglobal = 1
                    230: if (down < 0) {
                    231:        goacross = 1; colmax = across; ratio = 6/framewid
                    232: } else {
                    233:        goacross = 0; colmax = down; ratio = 8/frameht
                    234: }
                    235: if (colmax <= 0) colmax = int(ratio)
                    236: inputrange = 10000                     # 0..9999
                    237: frameborder = inputrange * margin      # border of whitespace
                    238: framexfac = framewid/(inputrange + 2*frameborder)
                    239: frameyfac =  frameht/(inputrange + 2*frameborder)
                    240: print "frameht  = " frameht
                    241: print "framewid = " framewid
                    242: if (infile == "") fatal("missing script file name")
                    243: if (infile !~ /\.s$/) fatal("script file name must end in .s")
                    244: system(develop " " infile)
                    245: sub(".s$", ".i", infile)
                    246: OFMT = "%.3g"
                    247: FS = "\t"
                    248: while ((getline <infile) > 0) {
                    249:        if ($1 == "g") {
                    250:                if (viewactive[$4]) {
                    251:                        snum = $2
                    252:                        if (snum > slotcnt) slotcnt = snum
                    253:                        if (snum != 0) slot[snum] = $0
                    254:                        else static[++staticcnt] = makepic($0)
                    255:                }
                    256:        } else if ($1 == "e") { # erase
                    257:                if (viewactive[$4]) slot[$2] = ""
                    258:        } else if ($1 == "c") { # click
                    259:                ++timectr[$2]
                    260:                if (printglobal || allnumarr[$2] ||
                    261:                          (somenum[$2] "." timectr[$2] in printsome))
                    262:                        dump(clickname[$2] ": " timectr[$2])
                    263:        } else if ($1 == "#") { # comment -- ignore it
                    264:        } else if ($1 == "b") { # blank the current view by enclosed erases
                    265:        } else if ($1 == "d") { # define
                    266:                if ($2 == "c") { # click
                    267:                        clickname[$3] = $4
                    268:                        allnumarr[$3] = 0
                    269:                        if ($4 in allnamearr) allnumarr[$3] = 1
                    270:                        somenum[$3] = -1
                    271:                        if ($4 in snamenum) somenum[$3] = snamenum[$4]
                    272:                } else if ($2 == "v") { # view
                    273:                        viewactive[$3] = 0
                    274:                        if ($4 in viewnum) {
                    275:                                viewactive[$3] = 1
                    276:                                viewbase[$3] = viewnum[$4]
                    277:                                viewtitle[$3] = inviewtitle[$4]
                    278:                        } else if (viewglobal) {
                    279:                                viewactive[$3] = 1
                    280:                                viewbase[$3] = viewct++
                    281:                                viewtitle[$3] = $4
                    282:                        }
                    283:                } else if ($2 == "p") { # ``pragmas'' -- check here?
                    284:                } else warn("int file bug: illegal modifier following d")
                    285:        } else warn("int file bug: unrecognized command")
                    286: }
                    287: close(infile)
                    288: if (printfinal) dump("final")
                    289: print ".PE"
                    290: FS = " "
                    291: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.