diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-04-02 18:39:37 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-04-02 18:39:37 +0000 |
commit | f4bfae6870ffdad1537fb6dd1d9c4731d979962f (patch) | |
tree | 0ae6bfd0fbf5b09c71b04bf6a17fd24c37358737 | |
parent | ed7a53c457ad60d773ccac910ed20c8d9931fb54 (diff) |
Implement --line-buffered
ok millert@ tedu@
-rw-r--r-- | usr.bin/grep/grep.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 6c82ef40891..6980d68cafa 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.26 2004/02/04 18:38:52 millert Exp $ */ +/* $OpenBSD: grep.c,v 1.27 2004/04/02 18:39:36 otto Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -82,13 +82,15 @@ int sflag; /* -s: silent mode (ignore errors) */ int vflag; /* -v: only show non-matching lines */ int wflag; /* -w: pattern must start and end on word boundaries */ int xflag; /* -x: pattern must match entire line */ +int lbflag; /* --line-buffered */ int binbehave = BIN_FILE_BIN; enum { BIN_OPT = CHAR_MAX + 1, HELP_OPT, - MMAP_OPT + MMAP_OPT, + LINEBUF_OPT }; /* Housekeeping */ @@ -109,7 +111,7 @@ usage(void) #else "usage: %s [-AB num] [-CEFGHILPRSUVZabchilnoqsvwx]\n" #endif - "\t[--context[=num]] [--binary-files=value]\n" + "\t[--context[=num]] [--binary-files=value] [--line-buffered]\n" "\t[-e pattern] [-f file] [pattern] [file ...]\n", __progname); exit(2); } @@ -125,6 +127,7 @@ struct option long_options[] = {"binary-files", required_argument, NULL, BIN_OPT}, {"help", no_argument, NULL, HELP_OPT}, {"mmap", no_argument, NULL, MMAP_OPT}, + {"line-buffered", no_argument, NULL, LINEBUF_OPT}, {"after-context", required_argument, NULL, 'A'}, {"before-context", required_argument, NULL, 'B'}, {"context", optional_argument, NULL, 'C'}, @@ -421,6 +424,9 @@ main(int argc, char *argv[]) case MMAP_OPT: /* default, compatibility */ break; + case LINEBUF_OPT: + lbflag = 1; + break; case HELP_OPT: default: usage(); @@ -458,6 +464,9 @@ main(int argc, char *argv[]) } } } + + if (lbflag) + setlinebuf(stdout); if ((argc == 0 || argc == 1) && !oflag) hflag = 1; |