Java Reference
In-Depth Information
*/
public
public class
class
JGrep
JGrep
{
private
private static
final
String USAGE
=
"Usage: JGrep pattern [-chilrsnv][-f pattfile][filename...]"
;
/** The pattern we're looking for */
protected
static final
protected
Pattern pattern
;
/** The matcher for this pattern */
protected
protected
Matcher matcher
;
private
private
boolean
boolean
debug
;
/** Are we to only count lines, instead of printing? */
protected
protected static
static
boolean
boolean
countOnly
=
false
false
;
/** Are we to ignore case? */
protected
protected static
false
;
/** Are we to suppress printing of filenames? */
protected
static
boolean
boolean
ignoreCase
=
false
protected static
false
;
/** Are we to only list names of files that match? */
protected
static
boolean
boolean
dontPrintFileName
=
false
protected static
false
;
/** are we to print line numbers? */
protected
static
boolean
boolean
listOnly
=
false
protected static
false
;
/** Are we to be silent about errors? */
protected
static
boolean
boolean
numbered
=
false
protected static
false
;
/** are we to print only lines that DONT match? */
protected
static
boolean
boolean
silent
=
false
protected static
false
;
/** Are we to process arguments recursively if directories? */
protected
static
boolean
boolean
inVert
=
false
protected static
static
boolean
boolean
recursive
=
false
false
;
/** Construct a Grep object for the pattern, and run it
* on all input files listed in argv.
* Be aware that a few of the command-line options are not
* acted upon in this version - left as an exercise for the reader!
*/
public
public static
static
void
void
main
(
String
[]
argv
) {
iif
(
argv
.
length
<
1
) {
System
.
err
.
println
(
USAGE
);
System
.
exit
(
1
);
}
String patt
=
null
null
;
GetOpt go
=
new
new
GetOpt
(
"cf:hilnrRsv"
);
char
char
c
;
while
while
((
c
=
go
.
getopt
(
argv
)) !=
0
) {
switch
switch
(
c
) {
case
case
'c'
:
countOnly
=
true
true
;