package org.jboss.fresh.shell.commands;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.shell.AbstractExecutable;
import java.io.PrintWriter;
/**
* @author boky
* @created 2003.4.9 19:38:38
* @version 1.0
*/
public class GrepExecutable extends AbstractExecutable {
private static final String VERSION = "1.0";
private void printHelp(PrintWriter out) {
out.println("Usage: grep [OPTION]... PATTERN [FILES...]");
out.println("Search for PATTERN on standard input.");
out.println("Example: cat main.c | grep -i 'hello world'");
out.println("");
out.println("Regexp selection and interpretation:");
out.println(" -E, -J, -P, --regexp The given patern is a Java regular expression");
out.println(" -f, --file=FILE obtain PATTERN from FILE");
out.println(" -i, --ignore-case ignore case distinctions");
out.println(" -w, --word-regexp force PATTERN to match only whole words");
out.println(" -x, --line-regexp force PATTERN to match only whole lines");
out.println(" -z, --null-data a data line ends in 0 byte, not newline");
out.println("");
out.println("Miscellaneous:");
out.println(" -s, --no-messages suppress error messages");
out.println(" -v, --invert-match select non-matching lines");
out.println(" -V, --version print version information and exit");
out.println(" -h, --help display this help and exit");
out.println("");
out.println("Output control:");
out.println(" -m, --max-count=NUM stop after NUM matches");
out.println(" -b, --byte-offset print the byte offset with output lines");
out.println(" -n, --line-number print line number with output lines");
out.println(" --line-buffered flush output on every line");
out.println(" -o, --only-matching show only the part of a line matching PATTERN");
out.println(" -q, --quiet, --silent suppress all normal output");
out.println(" --binary-files=TYPE assume that binary files are TYPE");
out.println(" TYPE is 'binary', 'text', or 'without-match'");
out.println(" -a, --text equivalent to --binary-files=text");
out.println(" -I equivalent to --binary-files=without-match");
out.println(" -c, --count only print a count of matching lines");
out.println(" -Z, --null print 0 byte after FILE name");
out.println("");
out.println("Context control:");
out.println(" -B, --before-context=NUM print NUM lines of leading context");
out.println(" -A, --after-context=NUM print NUM lines of trailing context");
out.println(" -C, --context=NUM print NUM lines of output context");
out.println(" -U, --binary do not strip CR characters at EOL (MSDOS)");
out.println(" -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS)");
out.println("");
}
protected void process(String exepath, String[] args) throws Exception {
PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
String[] invalidSwitches = getInvalidSwitches(args, "EJPfiwxzsvVhmbnoqaIcZBACUu", new String[]
{"regexp", "file", "ignore-case", "word-regexp", "line-regexp", "null-data", "no-messages",
"invert-match", "version", "help", "max-count", "byte-offset", "line-number",
"line-buffered", "only-matching", "quiet", "silent", "binary-files", "text," +
"count", "null", "before-context", "after-context", "binary", "unix-byte-offsets"});
if (helpRequested() || (invalidSwitches.length > 0)) {
printHelp(out);
return;
}
if (isSwitchActive(args, "V", "version")) {
out.println("grep (CP2 grep), version: " + VERSION);
out.println("");
return;
}
out.print("Not yet implemented.");
}
}