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

unix.superglobalmegacorp.com

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