grep.c (210578) | grep.c (210622) |
---|---|
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> | 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 210578 2010-07-29 00:11:14Z gabor $"); | 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", | 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 --color option", | 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", | 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*/ "unknown --binary-files option", 70/* 9*/ "Binary file %s matches\n", 71/*10*/ "%s (BSD grep) %s\n", | 69/* 8*/ "Binary file %s matches\n", 70/* 9*/ "%s (BSD grep) %s\n", |
72}; 73 74/* Flags passed to regcomp() and regexec() */ 75int cflags = 0; 76int eflags = REG_STARTEND; 77 78/* Shortcut for matching all cases like empty regex */ 79bool matchall; --- 360 unchanged lines hidden (view full) --- 440 case 'c': 441 cflag = true; 442 break; 443 case 'D': 444 if (strcasecmp(optarg, "skip") == 0) 445 devbehave = DEV_SKIP; 446 else if (strcasecmp(optarg, "read") == 0) 447 devbehave = DEV_READ; | 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; |
448 else { 449 errno = EINVAL; 450 err(2, NULL); 451 } | 447 else 448 errx(2, getstr(3), "--devices"); |
452 break; 453 case 'd': 454 if (strcasecmp("recurse", optarg) == 0) { 455 Hflag = true; 456 dirbehave = DIR_RECURSE; 457 } else if (strcasecmp("skip", optarg) == 0) 458 dirbehave = DIR_SKIP; 459 else if (strcasecmp("read", optarg) == 0) 460 dirbehave = DIR_READ; | 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; |
461 else { 462 errno = EINVAL; 463 err(2, NULL); 464 } | 458 else 459 errx(2, getstr(3), "--directories"); |
465 break; 466 case 'E': 467 grepbehave = GREP_EXTENDED; 468 break; 469 case 'e': 470 add_pattern(optarg, strlen(optarg)); 471 needpattern = 0; 472 break; --- 74 unchanged lines hidden (view full) --- 547 case 'U': 548 binbehave = BINFILE_BIN; 549 break; 550 case 'u': 551 case MMAP_OPT: 552 /* noop, compatibility */ 553 break; 554 case 'V': | 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': |
555 printf(getstr(10), __progname, VERSION); | 550 printf(getstr(9), __progname, VERSION); |
556 exit(0); 557 case 'v': 558 vflag = true; 559 break; 560 case 'w': 561 wflag = true; 562 break; 563 case 'x': --- 5 unchanged lines hidden (view full) --- 569 case BIN_OPT: 570 if (strcasecmp("binary", optarg) == 0) 571 binbehave = BINFILE_BIN; 572 else if (strcasecmp("without-match", optarg) == 0) 573 binbehave = BINFILE_SKIP; 574 else if (strcasecmp("text", optarg) == 0) 575 binbehave = BINFILE_TEXT; 576 else | 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 |
577 errx(2, "%s", getstr(8)); | 572 errx(2, getstr(3), "--binary-files"); |
578 break; 579 case COLOR_OPT: 580 color = NULL; 581 if (optarg == NULL || strcasecmp("auto", optarg) == 0 || 582 strcasecmp("tty", optarg) == 0 || 583 strcasecmp("if-tty", optarg) == 0) { 584 char *term; 585 586 term = getenv("TERM"); 587 if (isatty(STDOUT_FILENO) && term != NULL && 588 strcasecmp(term, "dumb") != 0) 589 color = init_color("01;31"); 590 } else if (strcasecmp("always", optarg) == 0 || 591 strcasecmp("yes", optarg) == 0 || 592 strcasecmp("force", optarg) == 0) { 593 color = init_color("01;31"); 594 } else if (strcasecmp("never", optarg) != 0 && 595 strcasecmp("none", optarg) != 0 && 596 strcasecmp("no", optarg) != 0) | 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) |
597 errx(2, "%s", getstr(3)); | 592 errx(2, getstr(3), "--color"); |
598 break; 599 case LABEL_OPT: 600 label = optarg; 601 break; 602 case LINEBUF_OPT: 603 lbflag = true; 604 break; 605 case NULL_OPT: --- 102 unchanged lines hidden --- | 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 --- |