|
|
1.1 root 1: # I-TRFIL(1)
2: #
3: # Icon trace filter
4: #
5: # Allan J. Anderson
6: #
7: # Last modified 7/10/83
8: #
9:
10: global buffer, ylist, nlist, yylist, priorlines, followlines
11:
12: procedure main(a)
13: local s, n, i
14: initial {
15: ylist := []
16: nlist := []
17: yylist := []
18: buffer := []
19: priorlines := followlines := 0
20: }
21: every s := !a do
22: if s[1+:2] == ("-c" | "-C") then {
23: if n := integer(s[3:0] | a[i + 1]) then {
24: if n = 0 then priorlines := followlines := 0
25: else if n < 0 then priorlines := abs(n)
26: else if n > 0 then followlines := n
27: }
28: }
29: else if s[1] == "+" then
30: if *s <= 1 then next
31: else put(ylist,s[2:0])
32: else if s[1] == "^" then
33: if *s <= 1 then next
34: else put(nlist,s[2:0])
35: else if s[1] == "!" then
36: if *s <= 1 then next
37: else put(yylist,s[2:0])
38: else if not integer(s) then stop(
39: "usage: trfil +includestring ^excludestring !keepstring -cn <infile")
40: while trfil(read())
41: end # main
42:
43: procedure trfil(line)
44: if *buffer > priorlines then get(buffer)
45: put(buffer,line)
46: if (*ylist = 0) | find(!ylist,line) then delcheck(line)
47: return
48: end
49:
50: procedure delcheck(line)
51: local n
52: if find(!nlist,line) then
53: if not find(!yylist,line) then return
54: every write(get(buffer))
55: n := followlines
56: while n > 0 do {
57: if find(!ylist,line) & (not find(!nlist,line)) then
58: n := followlines
59: else n -:= 1
60: if *buffer < priorlines then put(buffer,line)
61: write(line)
62: if *buffer >= priorlines then get(buffer,line)
63: line := read()
64: }
65: if (priorlines > 0 | followlines > 0) then write("\t")
66: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.