+ /* compile the regular expression
+ * we're not going to mess with sub-expressions, and we need to
+ * treat newlines right. */
+ reflags = REG_NOSUB | REG_NEWLINE;
+ if (ignore_case)
+ reflags |= REG_ICASE;
+ xregcomp(®ex, argv[optind], reflags);
+
+ /* argv[(optind+1)..(argc-1)] should be names of file to grep through. If
+ * there is more than one file to grep, we will print the filenames */
+ if ((argc-1) - (optind+1) > 0)
+ print_filename++;
+
+ /* If no files were specified, or '-' was specified, take input from
+ * stdin. Otherwise, we grep through all the files specified. */
+ if (argv[optind+1] == NULL || (strcmp(argv[optind+1], "-") == 0)) {
+ grep_file(stdin);
+ } else {
+ int i;
+ FILE *file;
+ for (i = optind + 1; i < argc; i++) {
+ cur_file = argv[i];
+ file = fopen(cur_file, "r");
+ if (file == NULL) {
+ if (!suppress_err_msgs)
+ errorMsg("%s: %s\n", cur_file, strerror(errno));
+ } else {
+ grep_file(file);
+ fclose(file);
+ }
+ }
+ }