Annotation of researchv10no/cmd/docsubmit/tex.awk, revision 1.1.1.1

1.1       root        1: BEGIN  {
                      2:        if(texinp != "")
                      3:                ninputs = split(texinp, texinputs, ":")
                      4:        else {
                      5:                ninputs = 1
                      6:                texinputs[1] = "."
                      7:        }
                      8:        idef=0
                      9:        }
                     10: /\\newcommand/ {
                     11:        ckdef(0, $0, 1)
                     12:        next
                     13:        }
                     14: /\\def[^a-z]/  {
                     15:        ckdef(0, $0, 0)
                     16:        next
                     17:        }
                     18: /\\(input|include)[{ ]/        {
                     19:        getfile()
                     20:        next
                     21:        }
                     22: /\\bibliography[{ ]/   {
                     23:        n = substr($0, index($0,"{")+1, index($0,"}")-index($0,"{")-1)
                     24:        if(n ~ ","){
                     25:                num=split(n, b, ",")
                     26:                for(i=1;i<=num;i++)
                     27:                        system("cp " b[i] ".bbl " dir)
                     28:                        close("cp " b[i] ".bbl " dir)
                     29:        }
                     30:        else{
                     31:                system("cp " n ".bbl " dir)
                     32:                close("cp " n ".bbl " dir)
                     33:        }
                     34:        }
                     35: /^\\includepicture/    {
                     36:        n=index($0,"{")+1
                     37:        fname=substr($0,n,index($0,"}")-n)
                     38:        system ("cp " fname ".t " dir )
                     39:        close ("cp " fname ".t " dir )
                     40:        system ("cp " fname ".tex " dir )
                     41:        close ("cp " fname ".tex " dir )
                     42:        }
                     43: /\\special/    {
                     44:        getpost($0)
                     45:        next
                     46:        }
                     47: /\\/   {
                     48:        isdef($0)
                     49:        next
                     50:        }
                     51: /.*/   {
                     52:        print $0
                     53:        }
                     54: function getfile(      saveline, n, bname, tname, j, name, flag){
                     55:        saveline = $0
                     56:        if($0 ~ /\\input/)n = index($0,"\\input")+7
                     57:        else n=index($0,"\\include")+9
                     58:        bname = substr($0,n)
                     59:        gsub(/^[ {]*/,"",bname)
                     60:        gsub(/[ }].*/,"",bname)
                     61:        gsub(/[ }]$/,"",bname)
                     62:        tname = bname ".tex"
                     63:        for(j=1; j<= ninputs; j++){
                     64:                name = texinputs[j] "/" tname
                     65:                if((getline <name) >=0)break
                     66:                name = texinputs[j] "/" bname
                     67:                if((getline <name) >=0)break
                     68:                name = ""
                     69:        }
                     70:        if(name == ""){
                     71:                print "cannot open file " bname " or " tname | "cat 1>&2"
                     72:                return
                     73:        }
                     74:        if(name ~ /\/usr\/lib\/tex\/macros/){
                     75:                print saveline
                     76:                return
                     77:        }
                     78:        flag=0
                     79:        while(1){
                     80:                if(flag)if((getline <name)<1)break
                     81:                flag=1
                     82:                if($0 ~ /\\newcommand/){
                     83:                        ckdef(name, $0, 1)
                     84:                        continue
                     85:                }
                     86:                if($0 ~ /\\def[^a-z]/){
                     87:                        ckdef(name, $0, 0)
                     88:                        continue
                     89:                }
                     90:                if($0 ~ /\\(input|include)[{ ]/){
                     91:                        getfile()
                     92:                }
                     93:                else if($0 ~ /\\special/)getpost($0)
                     94:                else if($0 ~ /\\/){
                     95:                        isdef($0)
                     96:                }
                     97:                else print $0
                     98:        }
                     99:        close(name)
                    100: }
                    101: function getpost(str){
                    102:        if(str ~ /psfile/){
                    103:                n=substr(str,index(str,"psfile"))
                    104:                if(n ~ / /)sub(/ .*/, "", n)
                    105:                if(n ~ /\=/)sub(/.*=/, "", n)
                    106:                if(n ~ /,$/)sub(/,/, "", n)
                    107:                if(n ~ /,.*/)sub(/,.*/, "", n)
                    108:                system( "cp " n " " dir)
                    109:                close( "cp " n " " dir)
                    110:                if(n ~ /\//){
                    111:                        num = split(n, xa, /\//)
                    112:                        sub(n, xa[num], str)
                    113:                }
                    114:                print str
                    115:        }
                    116:        else print str
                    117:        }
                    118: function ckdef(file, first,new){
                    119:        print first
                    120:        if(new){
                    121:                n=index(first,"{")+1
                    122:                name=substr(first,n,index(first,"}")-n)
                    123:                name = "\\" name
                    124:                n=index(first,"[")+1
                    125:                if(n > 1)
                    126:                        args=substr(first,n,index(first,"]")-n)+0
                    127:                else args=0
                    128:        }
                    129:        else {
                    130:                sub(/\\def\\/,"")
                    131:                savs = first
                    132:                if(first ~ /^[A-Za-z]/){
                    133:                        abc=first
                    134:                        sub(/[^A-Za-z]/,"{",abc)
                    135:                        name = "\\\\" substr(first,0,index(abc,"{")-1)
                    136:                }
                    137:                else name = "\\\\" substr(first,0,1)
                    138:                if(savs ~ /#/){
                    139:                        if(savs ~ "{")gsub(/{.*/, "",savs)
                    140:                        n=split(savs, z, "#")
                    141:                        args = n-1
                    142:                }
                    143:                else args=0
                    144:                xdef=1
                    145:        }
                    146:        if(first ~ "%"){
                    147:                n=split(first, z, "%")
                    148:                save = z[1]
                    149:                left=gsub(/{/,":",z[1])
                    150:                right=gsub(/}/,";",z[1])
                    151:        }
                    152:        else{
                    153:                save = $0
                    154:                left=gsub(/{/,":")
                    155:                right=gsub(/}/,";")
                    156:        }
                    157:        psav = isav = 0 
                    158:        if($0 ~ /special/){
                    159:                getpattern(file, save)
                    160:                psav++
                    161:        }
                    162:        while(left != right || (left == 1 && !xdef)){
                    163:                if(file== 0){
                    164:                        if((getline) <1){
                    165:                                print "ran out of file in newcommand"|"cat 1>&2"
                    166:                                exit
                    167:                        }
                    168:                }
                    169:                else if((getline<file) < 1){
                    170:                                print "ran out of file in newcommand"|"cat 1>&2"
                    171:                                exit
                    172:                        }
                    173:                save=$0
                    174:                left +=gsub(/{/,":")
                    175:                right+=gsub(/}/,";")
                    176:                if($0 ~ /special/){
                    177:                        getpattern(file, save)
                    178:                        psav++
                    179:                }
                    180:                if($0 ~ /(input|include)/){
                    181:                        getpattern(file, save)
                    182:                        isav++
                    183:                }
                    184:                else print save
                    185:        }
                    186:        if(psav||isav){
                    187:                argct[idef] = args
                    188:                if(psave)post[idef] = psav
                    189:                else inp[idef]=isav
                    190:                def[idef++] = name
                    191:        }
                    192: 
                    193: }
                    194: function getpattern(file, command){
                    195:        save = command
                    196:        if(command ~ /psfile/){
                    197:                n=substr(command, index(command, "psfile"))
                    198:                sub(/.*=[ \t]*/,"",n)
                    199:                sub(/}*$/,"",n)
                    200:                sub(/ .*/,"",n)
                    201:                ckargs(n,save)
                    202:        }
                    203:        if(command ~ /(input|include)/){
                    204:                if(command ~ /\\input/)n = index(command,"\\input")+7
                    205:                else n=index(command,"\\include")+9
                    206:                bname = substr(command,n)
                    207:                gsub(/^[ ]*/,"",bname)
                    208:                gsub(/[ }].*/,"",bname)
                    209:                gsub(/[ }]$/,"",bname)
                    210:                ckargs(bname,save)
                    211:        }
                    212: }
                    213: function ckargs(pat,command){
                    214:        if(pat ~ /#/)
                    215:                num = substr(pat,index(pat,"#")+1,1)
                    216:        else num = 0
                    217:        pattern[idef,num] = pat
                    218:        if(command ~ /\//){
                    219:                num = split(pat, xa, /\//)
                    220:                sub(n, xa[num], command)
                    221:        }
                    222:        print command
                    223: }
                    224: function cpfile(name, pat){
                    225:        if(name ~ "}")
                    226:                sub(/}.*/,"", name)
                    227:        sub(/#./,name,pat)
                    228:        system("cp " pat " " dir)
                    229:        close("cp " pat " " dir)
                    230:        if(name ~ /\//){
                    231:                num = split(name, xa, /\//)
                    232:                sub(name, xa[num],string)
                    233:        }
                    234: }
                    235: function isdef(string, i, gotarg, a, x, j, l, r){
                    236:        if(idef){
                    237:                for(i=0;i<idef;i++){
                    238:                        if(string !~ def[i])continue
                    239:                        if((i,0) in pattern){
                    240:                                system("cp " pattern[idef,0] " " dir)
                    241:                                close("cp " pattern[idef,0] " " dir)
                    242:                                break
                    243:                        }
                    244:                        gotarg=0
                    245:                        a=string
                    246:                        while(gotarg<argct[i]){
                    247:                                x=0
                    248:                                if(j=index(a,"{")){
                    249:                                        x++
                    250:                                        a = substr(a,j+1)
                    251:                                        if((i,gotarg+1) in pattern)
                    252:                                                cpfile(a, pattern[i,gotarg+1])
                    253:                                        while(x){
                    254:                                                l=index(a,"{")
                    255:                                                r=index(a,"}")
                    256:                                                if(!l && !r){
                    257:                                                        getline
                    258:                                                        string = string "\n" $0
                    259:                                                        a=$0
                    260:                                                        continue
                    261:                                                }
                    262:                                                if(l<r && l>0){
                    263:                                                        x++
                    264:                                                        a=substr(a,l+1)
                    265:                                                }
                    266:                                                else{
                    267:                                                        a=substr(a,r+1)
                    268:                                                        x--
                    269:                                                }
                    270:                                        }
                    271:                                        gotarg++
                    272:                                }
                    273:                                else {
                    274:                                        getline
                    275:                                        string = string "\n" $0
                    276:                                        a = $0
                    277:                                }
                    278:                        }
                    279:                        break
                    280:                }
                    281:        }
                    282:        print string
                    283: }

unix.superglobalmegacorp.com

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