More troff bits; if you want them elsewhere, feel free to repo copy them.
This commit is contained in:
parent
a7eb134e87
commit
aa83d77271
22 changed files with 670 additions and 1 deletions
35
src/cmd/index/range.collapse
Normal file
35
src/cmd/index/range.collapse
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
awk ' # range.collapse
|
||||
# Input: lines of form: string (tab) ["b"|"e"|"a"] (tab) number
|
||||
# Output: lines of form: string (tab) num [(space) num]
|
||||
# In sequence of lines with same value of string:
|
||||
# b line and following e line are combined into single line:
|
||||
# string (tab) num num
|
||||
# a line disappears if between paired b and e
|
||||
# a line otherwise becomes single line:
|
||||
# string (tab) num
|
||||
|
||||
function error(s) {
|
||||
print "range.collapse: " s " near pp " rlo "-" rhi | "cat 1>&2"
|
||||
}
|
||||
function printoldrange() {
|
||||
if (range == 1) { error("no %end for " term); rhi = "XXX" }
|
||||
if (NR > 1) {
|
||||
if (rlo == rhi)
|
||||
print term, rlo
|
||||
else
|
||||
print term, (rlo " " rhi)
|
||||
}
|
||||
rlo = rhi = $3 # bounds of current range
|
||||
}
|
||||
|
||||
BEGIN { FS = OFS = "\t" }
|
||||
$1 != term { printoldrange(); term = $1; range = 0 }
|
||||
$2 == "e" { if (range == 1) { range = 0; rhi = $3 }
|
||||
else { printoldrange(); error("no %begin for " term); rlo = "XXX" }
|
||||
next
|
||||
}
|
||||
$3 <= rhi + 1 { rhi = $3}
|
||||
$3 > rhi + 1 { if (range == 0) printoldrange() }
|
||||
$2 == "b" { if (range == 1) error("multiple %begin for " term); range = 1 }
|
||||
END { if (NR == 1) NR = 2; printoldrange() }
|
||||
' $*
|
||||
Loading…
Add table
Add a link
Reference in a new issue