Annotation of researchv10dc/vol2/index/tools/theadings.awk, revision 1.1

1.1     ! root        1: BEGIN  {
        !             2:        longest = 0
        !             3:        overf = 0
        !             4:        i = 1
        !             5:        }
        !             6: /^%/   {
        !             7:        total += length($0)+1
        !             8:        next
        !             9:        }
        !            10: /\\def/        {
        !            11:        total += length($0)+1
        !            12:        next
        !            13:        }
        !            14: /\\title/      {
        !            15:        place[i] = total
        !            16:        total += length($0) + 1
        !            17:        gettitl($0)
        !            18:        text[i] = title
        !            19:        hsize += length(title)+1
        !            20:        i++
        !            21:        l = length(title)
        !            22:        if(longest < l+1)
        !            23:                longest = l + 1
        !            24:        if(l > 23){
        !            25:                while(l>=23){
        !            26:                        overf++;
        !            27:                        l -= 23
        !            28:                }
        !            29:        }
        !            30:        next
        !            31:        }
        !            32: /\\([Ss]ection|sub.*section|newsection|chapter)[^a-zA-Z]/      {
        !            33:        place[i] = total
        !            34:        if($0 ~ /{/ && $0 ~ /}/){
        !            35:                line=$0
        !            36:                op=gsub("{","",line)
        !            37:                cl=gsub("}","",line)
        !            38:                n=index($0,"{") +1
        !            39:                if(op == cl && cl>1){
        !            40:                        sub("}","")
        !            41:                        sub(/{\\tt/,"")
        !            42:                }
        !            43:                heading = substr($0, n, index($0,"}")-n)
        !            44:        }
        !            45:        else if($0 ~ /{/){
        !            46:                total += length($0) + 1
        !            47:                nlines = 0
        !            48:                n=index($0, "{")
        !            49:                heading = substr($0, n+1, length($0)-n)
        !            50:                while(getline ){
        !            51:                        if(nlines++ > 3){
        !            52:                                print "too many lines in heading:" heading |"cat 1>&2"
        !            53:                                break
        !            54:                        }
        !            55:                        total += length($0) +1
        !            56:                        if($0 ~ /}/){
        !            57:                                heading = heading " " substr($0, 1, index($0,"}")-1)
        !            58:                                break
        !            59:                        }
        !            60:                        else
        !            61:                                heading = heading " " $0
        !            62:                }
        !            63:        }
        !            64:        total += length($0) +1
        !            65:        text[i] = heading
        !            66:        hsize += length(heading)+1
        !            67:        l = length(heading)
        !            68:        if(longest < l+1)
        !            69:                longest = l + 1
        !            70:        if(l > 23){
        !            71:                while(l>=23){
        !            72:                        overf++;
        !            73:                        l -= 23
        !            74:                }
        !            75:        }
        !            76:        heading = ""
        !            77:        i++
        !            78:        next
        !            79:        }
        !            80: /.*/   {
        !            81:        total += length($0) + 1
        !            82:        }
        !            83: END    {
        !            84:        if(i > 1){
        !            85: #              print hsize, longest, i-1, overf
        !            86:                for(n=1;n<i;n++){
        !            87: #                      print place[n]
        !            88:                        print text[n]
        !            89:                }
        !            90:        }
        !            91:        }
        !            92: function gettitl(A){
        !            93:        if(A ~ "%"){
        !            94:                split(A,z,"%")
        !            95:                a=z[1]
        !            96:        }
        !            97:        else a=A
        !            98:        if(a ~ /\\thanks/){
        !            99:                if(a ~ /}/)
        !           100:                        sub(/\\thanks{.*}/," ",a)
        !           101:                else{
        !           102:                        thanks=1
        !           103:                        sub(/\\thanks.*/, " ",a)
        !           104:                }
        !           105:        }
        !           106:        left=gsub(/{/," ",a)
        !           107:        right = gsub(/}/," ",a)
        !           108:        if(thanks)left += 1
        !           109:        if(a ~ /\\[a-z][a-z]* /)gsub(/\\[a-z][a-z]* /," ",a)
        !           110:        if(a ~ /\\[^a-z]/)gsub(/\\[^a-z]/," ",a)
        !           111:        title = a
        !           112:        while(left != right){
        !           113:                if((getline)<1){print "ran out of file"
        !           114:                        exit
        !           115:                }
        !           116:                total += length($0) +1
        !           117:                if($0 ~ "%"){
        !           118:                        split($0,z,"%")
        !           119:                        if(length(z[1]) == 0)continue
        !           120:                        a = z[1]
        !           121:                }
        !           122:                else a = $0
        !           123:                if(thanks){
        !           124:                        if(a ~ /}/){
        !           125:                                thanks=0
        !           126:                                right += 1
        !           127:                                sub(/}/,"XXX",a)
        !           128:                                sub(/.*XXX/," ",a)
        !           129:                        }
        !           130:                        else continue
        !           131:                }
        !           132:                if(a ~ /\\thanks/){
        !           133:                        b=a
        !           134:                        left += gsub(/{/," ",b)
        !           135:                        right += gsub(/}/," ",b)
        !           136:                        if(index(/}/,a)){
        !           137:                                gsub(/\\thanks.*}/," ",a)
        !           138:                                title = title " " a
        !           139:                                continue
        !           140:                        }
        !           141:                        thanks=1
        !           142:                        continue
        !           143:                }
        !           144:                left+=gsub(/{/," ",a)
        !           145:                right += gsub(/}/," ",a)
        !           146:                if(a ~ /\\[a-z][a-z]* /)gsub(/\\[a-z][a-z]* /," ",a)
        !           147:                if(a ~ /\\[^a-z]/)gsub(/\\[^a-z]/," ",a)
        !           148:                title = title " " a
        !           149:        }
        !           150:        gsub(/[ ][ ]*/," ",title)
        !           151:        sub(/^ /,"", title)
        !           152: }

unix.superglobalmegacorp.com

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