Deleted Added
sdiff udiff text old ( 210578 ) new ( 210622 )
full compact
1/* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */
2
3/*-
4 * Copyright (c) 1999 James Howard and Dag-Erling Co�dan Sm�rgrav
5 * Copyright (C) 2008-2009 Gabor Kovesdan <gabor@FreeBSD.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/usr.bin/grep/grep.c 210622 2010-07-29 18:02:57Z gabor $");
32
33#include <sys/stat.h>
34#include <sys/types.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <errno.h>
39#include <getopt.h>

--- 16 unchanged lines hidden (view full) ---

56/*
57 * Default messags to use when NLS is disabled or no catalogue
58 * is found.
59 */
60const char *errstr[] = {
61 "",
62/* 1*/ "(standard input)",
63/* 2*/ "cannot read bzip2 compressed file",
64/* 3*/ "unknown %s option",
65/* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n",
66/* 5*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n",
67/* 6*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n",
68/* 7*/ "\t[--null] [pattern] [file ...]\n",
69/* 8*/ "Binary file %s matches\n",
70/* 9*/ "%s (BSD grep) %s\n",
71};
72
73/* Flags passed to regcomp() and regexec() */
74int cflags = 0;
75int eflags = REG_STARTEND;
76
77/* Shortcut for matching all cases like empty regex */
78bool matchall;

--- 360 unchanged lines hidden (view full) ---

439 case 'c':
440 cflag = true;
441 break;
442 case 'D':
443 if (strcasecmp(optarg, "skip") == 0)
444 devbehave = DEV_SKIP;
445 else if (strcasecmp(optarg, "read") == 0)
446 devbehave = DEV_READ;
447 else
448 errx(2, getstr(3), "--devices");
449 break;
450 case 'd':
451 if (strcasecmp("recurse", optarg) == 0) {
452 Hflag = true;
453 dirbehave = DIR_RECURSE;
454 } else if (strcasecmp("skip", optarg) == 0)
455 dirbehave = DIR_SKIP;
456 else if (strcasecmp("read", optarg) == 0)
457 dirbehave = DIR_READ;
458 else
459 errx(2, getstr(3), "--directories");
460 break;
461 case 'E':
462 grepbehave = GREP_EXTENDED;
463 break;
464 case 'e':
465 add_pattern(optarg, strlen(optarg));
466 needpattern = 0;
467 break;

--- 74 unchanged lines hidden (view full) ---

542 case 'U':
543 binbehave = BINFILE_BIN;
544 break;
545 case 'u':
546 case MMAP_OPT:
547 /* noop, compatibility */
548 break;
549 case 'V':
550 printf(getstr(9), __progname, VERSION);
551 exit(0);
552 case 'v':
553 vflag = true;
554 break;
555 case 'w':
556 wflag = true;
557 break;
558 case 'x':

--- 5 unchanged lines hidden (view full) ---

564 case BIN_OPT:
565 if (strcasecmp("binary", optarg) == 0)
566 binbehave = BINFILE_BIN;
567 else if (strcasecmp("without-match", optarg) == 0)
568 binbehave = BINFILE_SKIP;
569 else if (strcasecmp("text", optarg) == 0)
570 binbehave = BINFILE_TEXT;
571 else
572 errx(2, getstr(3), "--binary-files");
573 break;
574 case COLOR_OPT:
575 color = NULL;
576 if (optarg == NULL || strcasecmp("auto", optarg) == 0 ||
577 strcasecmp("tty", optarg) == 0 ||
578 strcasecmp("if-tty", optarg) == 0) {
579 char *term;
580
581 term = getenv("TERM");
582 if (isatty(STDOUT_FILENO) && term != NULL &&
583 strcasecmp(term, "dumb") != 0)
584 color = init_color("01;31");
585 } else if (strcasecmp("always", optarg) == 0 ||
586 strcasecmp("yes", optarg) == 0 ||
587 strcasecmp("force", optarg) == 0) {
588 color = init_color("01;31");
589 } else if (strcasecmp("never", optarg) != 0 &&
590 strcasecmp("none", optarg) != 0 &&
591 strcasecmp("no", optarg) != 0)
592 errx(2, getstr(3), "--color");
593 break;
594 case LABEL_OPT:
595 label = optarg;
596 break;
597 case LINEBUF_OPT:
598 lbflag = true;
599 break;
600 case NULL_OPT:

--- 102 unchanged lines hidden ---