Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6725 siemargl 1
/*---------------------------------------------------------------------------
2
 
3
   zapigrep.cmd  (ye olde REXX procedure for OS/2)
4
 
5
   Script to search members of a zipfile for a string and print the names of
6
   any such members (and, optionally, the matching text).
7
 
8
   This is the zipgrep.cmd program completely rewritten to take advantage
9
   of the REXX API.  Among the improvements are:
10
        egrep no longer needed.  All work done by API and this script.
11
	Added option switches.
12
 
13
   Be aware, however, that this script does not support regular expressions
14
   as zipgrep does.
15
 
16
  ---------------------------------------------------------------------------*/
17
 
18
PARSE ARG args
19
 
20
nocase = 0
21
word = 0
22
text = 0
23
 
24
DO WHILE Left(args,1) == '-' | Left(args,1) == '/'
25
   PARSE VAR args option args
26
   option = Translate(SubStr(option,2))
27
   DO WHILE option \= ''
28
      oneopt = Left(option,1)
29
      option = SubStr(option,2)
30
      SELECT
31
       WHEN oneopt == 'W' THEN
32
	  word = 1
33
       WHEN oneopt == 'I' THEN
34
	  nocase = 1
35
       WHEN oneopt == 'T' THEN
36
	  text = 1
37
       OTHERWISE NOP
38
      END
39
   END
40
END
41
 
42
PARSE VAR args string zipfile members
43
 
44
IF (string == '') THEN DO
45
   SAY 'usage:  zipgrep [-i][-t][-w] search_string zipfile [members...]'
46
   SAY '   Displays the names of zipfile members containing a given string.'
47
   SAY '   By default it displays filenames only of members containing an'
48
   SAY '   exact match of the string.  Options are:'"0a"x
49
   SAY '	-i  Ignore case'
50
   SAY '	-t  Display matching lines'
51
   SAY '	-w  Match words only'
52
   EXIT 1
53
END
54
string = Strip(string,'b','"')
55
IF nocase THEN string = Translate(string)
56
 
57
CALL RxFuncAdd 'UZLoadFuncs', 'UNZIP32', 'UZLoadFuncs'
58
CALL UZLoadFuncs
59
 
60
CALL UZUnZipToStem zipfile, 'file.', members
61
 
62
DO i = 1 TO file.0
63
   ptr = file.i
64
   file = file.ptr
65
   IF nocase THEN file = Translate(file)
66
   IF word THEN DO
67
      wp = WordPos(string,file)
68
      IF wp>0 THEN
69
	 scan = WordIndex(file,wp)
70
      ELSE
71
         scan = 0
72
   END
73
   ELSE
74
      scan = Pos(string,file)
75
   IF scan \= 0 THEN DO
76
      SAY file.i':'
77
      IF text THEN DO
78
	 DO WHILE scan > 0
79
	    from = LastPos('0a'x,file,scan)+1
80
	    to = Pos('0a'x,file,scan)
81
	    IF to = 0 THEN to = Length(file.ptr)
82
	    oneline = Strip(SubStr(file.ptr,from,to-from),'T','0a'x)
83
	    SAY Strip(oneline,'T','0d'x)
84
	    IF word THEN DO
85
	       wp = WordPos(string,file,wp+1)
86
	       IF wp>0 THEN
87
		  scan = WordIndex(file,wp)
88
	       ELSE
89
		  scan = 0
90
	    END
91
	    ELSE
92
	       scan = Pos(string,file,scan+1)
93
	 END
94
      END
95
   END
96
END
97
 
98
EXIT 0