|
|
1.1 ! root 1: BEGIN { ! 2: monkdel = "\(\)\[\]<>{\}\"\"\'\'\`\'" ! 3: longest = 0 ! 4: overf = 0 ! 5: i = 1 ! 6: havetitle=0 ! 7: } ! 8: /^\|title[^a-z_]/ { ! 9: place[i] = total ! 10: total += length($0) + 1 ! 11: if(havetitle)next ! 12: gettitl($0) ! 13: text[i] = title ! 14: hsize += length(title)+1 ! 15: i++ ! 16: l = length(title) ! 17: if(longest < l+1) ! 18: longest = l + 1 ! 19: if(l > 23){ ! 20: while(l>=23){ ! 21: overf++; ! 22: l -= 23 ! 23: } ! 24: } ! 25: havetitle=1 ! 26: next ! 27: } ! 28: /\|(section|subsection|subsubsection|unnumbered_section|unnumbered_subsection)/ { ! 29: place[i] = total ! 30: save=$0 ! 31: heading = "" ! 32: rdelim=getdel() ! 33: if(pldelim == prdelim)getequal() ! 34: else getpair() ! 35: total += length(save) +1 ! 36: text[i] = heading ! 37: hsize += length(heading)+1 ! 38: l = length(heading) ! 39: if(longest < l+1) ! 40: longest = l + 1 ! 41: if(l > 23){ ! 42: while(l>=23){ ! 43: overf++; ! 44: l -= 23 ! 45: } ! 46: } ! 47: heading = "" ! 48: i++ ! 49: next ! 50: } ! 51: /.*/ { ! 52: total += length($0) + 1 ! 53: } ! 54: END { ! 55: if(i > 1){ ! 56: # print hsize, longest, i-1, overf ! 57: for(n=1;n<i;n++){ ! 58: # print place[n] ! 59: print text[n] ! 60: } ! 61: } ! 62: } ! 63: function gettitl( rdelim,n,m,junk){ ! 64: rdelim = getdel() ! 65: title=$0 ! 66: n=gsub(ldelim,"") ! 67: junk=$0 ! 68: m=gsub(rdelim,"",junk) ! 69: if($0 !~ rdelim || n != m-1){ ! 70: while(getline > 0){ ! 71: total += length($0) +1 ! 72: title=title " " $0 ! 73: n=sub(ldelim,"") ! 74: if($0 ~ rdelim && n == 0)break ! 75: } ! 76: } ! 77: title=substr(title,1,length(title)-1) ! 78: } ! 79: function getdel(){ ! 80: if($0 !~ /^\|/ && $0 ~ /..*\|/)sub(/^..*\|/,"\|") ! 81: sub(/\|[a-z_ \t]*/,"") ! 82: pldelim = substr($0, 0, 1) ! 83: sub(/./,"") ! 84: b = substr(monkdel,index(monkdel,pldelim)+1,1) ! 85: prdelim = b ! 86: ldelim = "\\" pldelim ! 87: return("\\" b) ! 88: } ! 89: function getpair(){ ! 90: lsave=$0 ! 91: n = xn = gsub(ldelim,":") ! 92: ind = index(lsave,pldelim) ! 93: m = xm = gsub(rdelim,":") ! 94: imd = index(lsave,prdelim) ! 95: if(m>0 && n+1 == m){ ! 96: heading = substr(lsave, 1, index(lsave,prdelim)-1) ! 97: return ! 98: } ! 99: total += length(save) + 1 ! 100: nlines = 0 ! 101: heading = $0 ! 102: while(getline ){ ! 103: save=$0 ! 104: if(nlines++ > 3){ ! 105: print "too many lines in heading:" heading |"cat 1>&2" ! 106: break ! 107: } ! 108: lsave=$0 ! 109: n=gsub(ldelim,"X") ! 110: xn += n ! 111: ind = index(lsave,pldelim) ! 112: m=gsub(rdelim,"Z") ! 113: xm += m ! 114: imd = index(lsave,prdelim) ! 115: if(m>0 && xn+1 == xm){ ! 116: if(ind > imd && n+1 == m){ ! 117: if(heading == "") ! 118: heading=substr(lsave, 1, index(lsave,prdelim)-1) ! 119: else ! 120: heading=heading " " substr(lsave,1,index(lsave,prdelim)-1) ! 121: } ! 122: else{ ! 123: new=getind() ! 124: if(heading == "")heading=substr(lsave, 1,new-1) ! 125: else heading = heading " " substr(lsave, 1,new-1) ! 126: } ! 127: break ! 128: } ! 129: else{ ! 130: total += length(lsave) +1 ! 131: if(heading == "")heading = lsave ! 132: else heading = heading " " lsave ! 133: } ! 134: } ! 135: } ! 136: function getind(){ ! 137: split($0,foo,"Z") ! 138: sum=0 ! 139: for(j=1;j<=m;j++) ! 140: sum += length(foo[j])+1 ! 141: return(sum) ! 142: } ! 143: function getequal(){ ! 144: cmd= "\\|[a-zA-Z_]*" prdelim ! 145: lsave=$0 ! 146: n = xn = gsub(ldelim,":") ! 147: if(n==1){ ! 148: heading = substr(lsave, 1, index(lsave,prdelim)-1) ! 149: return ! 150: } ! 151: total += length(save) + 1 ! 152: heading = $0 ! 153: while(getline){ ! 154: save=lsave=$0 ! 155: ind=0 ! 156: if($0 ~ cmd){ ! 157: while($0 ~ cmd) ! 158: ind=getcmd() ! 159: } ! 160: nind=index($0,pldelim) ! 161: n=gsub(ldelim,":") ! 162: xn += n ! 163: if(xn == 1){ ! 164: if(heading == "")heading=substr(save,1,nind+ind-1) ! 165: else heading=heading " " substr(save,1,nind+ind-1) ! 166: break ! 167: } ! 168: else{ ! 169: total += length(lsave) +1 ! 170: if(heading == "")heading = lsave ! 171: else heading = heading " " lsave ! 172: } ! 173: } ! 174: } ! 175: function getcmd( i,nsv,sum){ ! 176: sum=length($0) ! 177: sub(cmd,"") ! 178: i=sub(ldelim,"") ! 179: sum=sum-length($0) ! 180: if(!i){ ! 181: total += length(lsave) +1 ! 182: if(heading == "")heading = lsave ! 183: else heading = heading " " lsave ! 184: getline ! 185: save=lsave=$0 ! 186: sub(ldelim,"") ! 187: } ! 188: return(sum) ! 189: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.