static void scanfile(Scanner input, String filename, Pattern pattern) { int numLines = 1; while (input.hasNextLine()) { String line = input.nextLine(); boolean matches = pattern.matcher(line).find(); if (matches && !options.reverse_match) { messages.exit_status = messages.EXIT_SUCCESS; if (options.filename_only) { out.printf(filename + "\n"); return; } else if (options.number_lines) { out.printf(numLines + ": " + "%s:%s%n", filename, line); } else { out.printf("%s:%s%n", filename, line); } } else if (!matches && options.reverse_match) { if (options.number_lines) { out.printf(numLines + ": " + "%s:%s%n", filename, line); } else { out.printf("%s:%s%n", filename, line); } messages.exit_status = messages.EXIT_SUCCESS; } numLines++; } }
static void compileRegex(String[] args) { int i; if (optionsPresent) { i = 1; } else { i = 0; } options.regex = args[i]; try { if (options.insensitive) { options.pattern = Pattern.compile(options.regex, Pattern.CASE_INSENSITIVE); } else { options.pattern = Pattern.compile(options.regex); } } catch (PatternSyntaxException e) { messages.die(e.getMessage()); } }