File: grep

package info (click to toggle)
epic5 3.0.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: ansic: 75,810; makefile: 648; ruby: 227; python: 215; sh: 78; perl: 13
file content (69 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; };

#
# grep 1.0 -- adds [e]grep support to the client, neat
# Author --  wd@anduril.org White_Dragon Chip Norkus
# Any deviation from the original is Jeremy Nelson's fault.
#
# Contributed to the EPIC project by Phoengold, on Fri, 14 Apr 2000.
#
# Usage: /grep [-w #] <text>
#	 /egrep [-w #] <text>
# Performs a text search on the lastlog of the current/specified window
#
# At the most basic level, /grep searches the lastlog of your current window
# for the specified text.  with the -w option you can specify the window
# whose lastlog you want to use. A regular expression of any sort can be
# used, as well.
#

alias grep 
{
	^local win,exp,re,i,x,l,s.,l.;

	if (![$0]) {
		echo Usage: /grep [-w #] <text>;
		return;
	};
        
	@ win = 1;
        
        if ([$0] == [-w]) {
                if (![$2])
                        return;
                @ win = [$1];
                @ exp = [$2-];
        } else {
                @ exp = [$*];
        };
        
        if (!winlevel($win))
		assign -win;

        @ re = regcomp($exp);
        
        ### grep here, and save the lines
        @ i = getset(LASTLOG);
        @ x = 0;
	while (i) 
	{
		@ l = line($i $win);
                if (!regexec($re $l)) {
                        @ s[$x] = l;
                        @ l[$x] = i;
                        @ x++;
                };
                @ i--;
        };
        @ regfree($re);
        
	echo ------------------ Results of grep: ----------------------;
	@ i = 0;
        while (i < x) {
                xecho -nolog $[4]l[$i]: $s[$i];
                @ i++;
        };
	echo ------------------------ End -----------------------------;
};

#WhiteDragon'Y2K