aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/index/range.collapse
diff options
context:
space:
mode:
authorwkj <devnull@localhost>2004-05-17 03:22:35 +0000
committerwkj <devnull@localhost>2004-05-17 03:22:35 +0000
commitaa83d77271f0d2be72067058f78abd1780f3b69e (patch)
tree14a24e73abb43ad0b7340a1623e077a733b0be33 /src/cmd/index/range.collapse
parenta7eb134e8717c2ea831066891314cf74fa4a6ad3 (diff)
downloadplan9port-aa83d77271f0d2be72067058f78abd1780f3b69e.tar.gz
plan9port-aa83d77271f0d2be72067058f78abd1780f3b69e.tar.bz2
plan9port-aa83d77271f0d2be72067058f78abd1780f3b69e.zip
More troff bits; if you want them elsewhere, feel free to repo copy them.
Diffstat (limited to 'src/cmd/index/range.collapse')
-rw-r--r--src/cmd/index/range.collapse35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cmd/index/range.collapse b/src/cmd/index/range.collapse
new file mode 100644
index 00000000..9119cea6
--- /dev/null
+++ b/src/cmd/index/range.collapse
@@ -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() }
+' $*