From 11fefcda40d5c7d0a674441486cbac61a3ba6fc7 Mon Sep 17 00:00:00 2001 From: kevans Date: Wed, 16 Aug 2017 00:47:53 +0000 Subject: bsdgrep: add -z/--null-data support and update NLS catalogs accordingly MFC r317049: bsdgrep: add -z/--null-data support -z treats input and output data as sequences of lines terminated by a zero byte instead of a newline. This brings it more in line with GNU grep and brings us closer to passing the current tests with BSD grep. MFC r317679: bsdgrep: correct nls usage data after r317049 r317049 added -z/--null-data to BSD grep but missed the update to nls catalogs. Approved by: emaste (mentor, blanket MFC) Relnotes: yes --- usr.bin/grep/file.c | 7 ++++--- usr.bin/grep/grep.1 | 9 ++++++--- usr.bin/grep/grep.c | 10 ++++++++-- usr.bin/grep/grep.h | 1 + usr.bin/grep/nls/C.msg | 2 +- usr.bin/grep/nls/es_ES.ISO8859-1.msg | 2 +- usr.bin/grep/nls/gl_ES.ISO8859-1.msg | 2 +- usr.bin/grep/nls/hu_HU.ISO8859-2.msg | 2 +- usr.bin/grep/nls/ja_JP.SJIS.msg | 2 +- usr.bin/grep/nls/ja_JP.UTF-8.msg | 2 +- usr.bin/grep/nls/ja_JP.eucJP.msg | 2 +- usr.bin/grep/nls/pt_BR.ISO8859-1.msg | 2 +- usr.bin/grep/nls/ru_RU.KOI8-R.msg | 2 +- usr.bin/grep/nls/uk_UA.UTF-8.msg | 2 +- usr.bin/grep/nls/zh_CN.UTF-8.msg | 2 +- usr.bin/grep/util.c | 4 ++-- 16 files changed, 32 insertions(+), 21 deletions(-) (limited to 'usr.bin/grep') diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c index 34831f1..7ed34d9 100644 --- a/usr.bin/grep/file.c +++ b/usr.bin/grep/file.c @@ -197,7 +197,7 @@ grep_fgetln(struct file *f, size_t *lenp) } /* Look for a newline in the remaining part of the buffer */ - if ((p = memchr(bufpos, '\n', bufrem)) != NULL) { + if ((p = memchr(bufpos, fileeol, bufrem)) != NULL) { ++p; /* advance over newline */ ret = bufpos; len = p - bufpos; @@ -219,7 +219,7 @@ grep_fgetln(struct file *f, size_t *lenp) if (bufrem == 0) /* EOF: return partial line */ break; - if ((p = memchr(bufpos, '\n', bufrem)) == NULL && + if ((p = memchr(bufpos, fileeol, bufrem)) == NULL && filebehave != FILE_MMAP) continue; if (p == NULL) { @@ -322,7 +322,8 @@ grep_open(const char *path) goto error2; /* Check for binary stuff, if necessary */ - if (binbehave != BINFILE_TEXT && memchr(bufpos, '\0', bufrem) != NULL) + if (binbehave != BINFILE_TEXT && fileeol != '\0' && + memchr(bufpos, '\0', bufrem) != NULL) f->binary = true; return (f); diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1 index f06cfaa..f790ce1 100644 --- a/usr.bin/grep/grep.1 +++ b/usr.bin/grep/grep.1 @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd July 28, 2010 +.Dd April 17, 2017 .Dt GREP 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Sh SYNOPSIS .Nm grep .Bk -words -.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ +.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZz .Op Fl A Ar num .Op Fl B Ar num .Op Fl C Ns Op Ar num @@ -378,7 +378,10 @@ expression are considered to be matching lines. Equivalent to .Fl i . Obsoleted. -.It Fl Z , Fl z , Fl Fl decompress +.It Fl z , Fl Fl null-data +Treat input and output data as sequences of lines terminated by a +zero-byte instead of a newline. +.It Fl Z , Fl Fl decompress Force .Nm grep to behave as diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index fe8c778..190322c 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -67,7 +67,7 @@ const char *errstr[] = { /* 1*/ "(standard input)", /* 2*/ "cannot read bzip2 compressed file", /* 3*/ "unknown %s option", -/* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n", +/* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n", /* 5*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", /* 6*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", /* 7*/ "\t[--null] [pattern] [file ...]\n", @@ -110,6 +110,7 @@ bool lflag; /* -l: only show names of files with matches */ bool mflag; /* -m x: stop reading the files after x matches */ long long mcount; /* count for -m */ long long mlimit; /* requested value for -m */ +char fileeol; /* indicator for eol */ bool nflag; /* -n: show line numbers in front of matching lines */ bool oflag; /* -o: print only matching part */ bool qflag; /* -q: quiet mode (don't output anything) */ @@ -166,7 +167,7 @@ usage(void) exit(2); } -static const char *optstr = "0123456789A:B:C:D:EFGHIJMLOPSRUVZabcd:e:f:hilm:nopqrsuvwxXy"; +static const char *optstr = "0123456789A:B:C:D:EFGHIJMLOPSRUVZabcd:e:f:hilm:nopqrsuvwxXyz"; static const struct option long_options[] = { @@ -216,6 +217,7 @@ static const struct option long_options[] = {"word-regexp", no_argument, NULL, 'w'}, {"line-regexp", no_argument, NULL, 'x'}, {"xz", no_argument, NULL, 'X'}, + {"null-data", no_argument, NULL, 'z'}, {"decompress", no_argument, NULL, 'Z'}, {NULL, no_argument, NULL, 0} }; @@ -385,6 +387,7 @@ main(int argc, char *argv[]) newarg = 1; prevoptind = 1; needpattern = 1; + fileeol = '\n'; eopts = getenv("GREP_OPTIONS"); @@ -606,6 +609,9 @@ main(int argc, char *argv[]) case 'X': filebehave = FILE_XZ; break; + case 'z': + fileeol = '\0'; + break; case 'Z': filebehave = FILE_GZIP; break; diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h index 5613d39..c82e6bb 100644 --- a/usr.bin/grep/grep.h +++ b/usr.bin/grep/grep.h @@ -116,6 +116,7 @@ extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag; extern unsigned long long Aflag, Bflag; extern long long mcount; extern long long mlimit; +extern char fileeol; extern char *label; extern const char *color; extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave; diff --git a/usr.bin/grep/nls/C.msg b/usr.bin/grep/nls/C.msg index 6327b27..d8a3f08 100644 --- a/usr.bin/grep/nls/C.msg +++ b/usr.bin/grep/nls/C.msg @@ -5,7 +5,7 @@ $quote " 1 "(standard input)" 2 "cannot read bzip2 compressed file" 3 "unknown %s option" -4 "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" +4 "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n" 5 "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n" 6 "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n" 7 "\t[--null] [pattern] [file ...]\n" diff --git a/usr.bin/grep/nls/es_ES.ISO8859-1.msg b/usr.bin/grep/nls/es_ES.ISO8859-1.msg index 208e91d..8a08079 100644 --- a/usr.bin/grep/nls/es_ES.ISO8859-1.msg +++ b/usr.bin/grep/nls/es_ES.ISO8859-1.msg @@ -5,7 +5,7 @@ $quote " 1 "(entrada estndar)" 2 "no se puede leer el fichero comprimido bzip2" 3 "opcin desconocida de %s" -4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A no] [-B no] [-C[no]]\n" +4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A no] [-B no] [-C[no]]\n" 5 "\t[-e pauta] [-f fichero] [--binary-files=valor] [--color=cuando]\n" 6 "\t[--context[=no]] [--directories=accin] [--label] [--line-buffered]\n" 7 "\t[--null] [pauta] [fichero ...]\n" diff --git a/usr.bin/grep/nls/gl_ES.ISO8859-1.msg b/usr.bin/grep/nls/gl_ES.ISO8859-1.msg index 9f3915a..f89532f 100644 --- a/usr.bin/grep/nls/gl_ES.ISO8859-1.msg +++ b/usr.bin/grep/nls/gl_ES.ISO8859-1.msg @@ -5,7 +5,7 @@ $quote " 1 "(entrada estndar)" 2 "non se pode ler o ficheiro comprimido bzip2" 3 "opcin descoecida de %s" -4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A no] [-B no] [-C[no]]\n" +4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A no] [-B no] [-C[no]]\n" 5 "\t[-e pauta] [-f ficheiro] [--binary-files=valor] [--color=cando]\n" 6 "\t[--context[=no]] [--directories=accin] [--label] [--line-buffered]\n" 7 "\t[--null] [pauta] [ficheiro ...]\n" diff --git a/usr.bin/grep/nls/hu_HU.ISO8859-2.msg b/usr.bin/grep/nls/hu_HU.ISO8859-2.msg index 6d3c1c9..9c8aafd 100644 --- a/usr.bin/grep/nls/hu_HU.ISO8859-2.msg +++ b/usr.bin/grep/nls/hu_HU.ISO8859-2.msg @@ -5,7 +5,7 @@ $quote " 1 "(szabvnyos bemenet)" 2 "bzip2 tmrtett fjl nem olvashat" 3 "ismeretlen %s opci" -4 "hasznlat: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A szm] [-B szm] [-C[szm]]\n" +4 "hasznlat: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A szm] [-B szm] [-C[szm]]\n" 5 "\t[-e minta] [-f fjl] [--binary-files=rtk] [--color=mikor]\n" 6 "\t[--context[=szm]] [--directories=mvelet] [--label] [--line-buffered]\n" 7 "\t[--null] [minta] [fjl ...]\n" diff --git a/usr.bin/grep/nls/ja_JP.SJIS.msg b/usr.bin/grep/nls/ja_JP.SJIS.msg index d18edd5..da0677e 100644 --- a/usr.bin/grep/nls/ja_JP.SJIS.msg +++ b/usr.bin/grep/nls/ja_JP.SJIS.msg @@ -5,7 +5,7 @@ $quote " 1 "(W)" 2 "bzip2 kt@CǂݍނƂł܂" 3 "%s IvV̎wlɌ肪܂" -4 "g: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A ] [-B ] [-C[]]\n" +4 "g: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A ] [-B ] [-C[]]\n" 5 "\t[-e p^[] [-f t@C] [--binary-files=l] [--color=l]\n" 6 "\t[--context[=]] [--directories=] [--label] [--line-buffered]\n" 7 "\t[--null] [p^[] [t@C ...]\n" diff --git a/usr.bin/grep/nls/ja_JP.UTF-8.msg b/usr.bin/grep/nls/ja_JP.UTF-8.msg index 84c6f45..e842b25 100644 --- a/usr.bin/grep/nls/ja_JP.UTF-8.msg +++ b/usr.bin/grep/nls/ja_JP.UTF-8.msg @@ -5,7 +5,7 @@ $quote " 1 "(標準入力)" 2 "bzip2 圧縮ファイルを読み込むことができません" 3 "%s オプションの指定値に誤りがあります" -4 "使い方: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A 数字] [-B 数字] [-C[数字]]\n" +4 "使い方: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A 数字] [-B 数字] [-C[数字]]\n" 5 "\t[-e パターン] [-f ファイル名] [--binary-files=値] [--color=値]\n" 6 "\t[--context[=数字]] [--directories=動作] [--label] [--line-buffered]\n" 7 "\t[--null] [パターン] [ファイル名 ...]\n" diff --git a/usr.bin/grep/nls/ja_JP.eucJP.msg b/usr.bin/grep/nls/ja_JP.eucJP.msg index e778c5f..922b25a 100644 --- a/usr.bin/grep/nls/ja_JP.eucJP.msg +++ b/usr.bin/grep/nls/ja_JP.eucJP.msg @@ -5,7 +5,7 @@ $quote " 1 "(ɸ)" 2 "bzip2 ̥եɤ߹ळȤǤޤ" 3 "%s ץλͤ˸꤬ޤ" -4 "Ȥ: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A ] [-B ] [-C[]]\n" +4 "Ȥ: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A ] [-B ] [-C[]]\n" 5 "\t[-e ѥ] [-f ե̾] [--binary-files=] [--color=]\n" 6 "\t[--context[=]] [--directories=ư] [--label] [--line-buffered]\n" 7 "\t[--null] [ѥ] [ե̾ ...]\n" diff --git a/usr.bin/grep/nls/pt_BR.ISO8859-1.msg b/usr.bin/grep/nls/pt_BR.ISO8859-1.msg index 79c026e..c049fde 100644 --- a/usr.bin/grep/nls/pt_BR.ISO8859-1.msg +++ b/usr.bin/grep/nls/pt_BR.ISO8859-1.msg @@ -5,7 +5,7 @@ $quote " 1 "(entrada padro)" 2 "no se posso ler o fichero comprimido bzip2" 3 "opco no conhecida de %s" -4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" +4 "uso: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n" 5 "\t[-e padro] [-f arquivo] [--binary-files=valor] [--color=quando]\n" 6 "\t[--context[=num]] [--directories=ao] [--label] [--line-buffered]\n" 7 "\t[--null] [padro] [arquivo ...]\n" diff --git a/usr.bin/grep/nls/ru_RU.KOI8-R.msg b/usr.bin/grep/nls/ru_RU.KOI8-R.msg index 6880d51..d6d308f 100644 --- a/usr.bin/grep/nls/ru_RU.KOI8-R.msg +++ b/usr.bin/grep/nls/ru_RU.KOI8-R.msg @@ -5,7 +5,7 @@ $quote " 1 "( )" 2 " bzip2 " 3 " %s" -4 ": %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A ] [-B ] [-C[]]\n" +4 ": %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A ] [-B ] [-C[]]\n" 5 "\t[-e ] [-f ] [--binary-files=] [--color=]\n" 6 "\t[--context[=]] [--directories=] [--label] [--line-buffered]\n" 7 "\t[--null] [] [ ...]\n" diff --git a/usr.bin/grep/nls/uk_UA.UTF-8.msg b/usr.bin/grep/nls/uk_UA.UTF-8.msg index 4492d31..e601ca2 100644 --- a/usr.bin/grep/nls/uk_UA.UTF-8.msg +++ b/usr.bin/grep/nls/uk_UA.UTF-8.msg @@ -4,7 +4,7 @@ $quote " 1 "(стандартний ввід)" 2 "не можу прочитати стиснутий bzip2 файл" 3 "невiдома опція %s" -4 "використання: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A чис] [-B чис] [-C[чис]]\n" +4 "використання: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A чис] [-B чис] [-C[чис]]\n" 5 "\t[-e шаблон] [-f файл] [--binary-files=значення] [--color=коли]\n" 6 "\t[--context[=чис] [--directories=дія] [--label] [--line-buffered]\n" 7 "\t[--null] [шаблон] [файл ...]\n" diff --git a/usr.bin/grep/nls/zh_CN.UTF-8.msg b/usr.bin/grep/nls/zh_CN.UTF-8.msg index d5cd0c2..921ff4b 100644 --- a/usr.bin/grep/nls/zh_CN.UTF-8.msg +++ b/usr.bin/grep/nls/zh_CN.UTF-8.msg @@ -5,7 +5,7 @@ $quote " 1 "(标准输入)" 2 "读取 bzip2 压缩文件时出错" 3 "选项 %s 无法识别" -4 "用法: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A 行数] [-B 行数] [-C[行数]]\n" +4 "用法: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A 行数] [-B 行数] [-C[行数]]\n" 5 "\t[-e 模式] [-f 文件] [--binary-files=值] [--color=何时]\n" 6 "\t[--context[=行数]] [--directories=动作] [--label] [--line-buffered]\n" 7 "\t[--null] [模式] [文件名 ...]\n" diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 46b1dd8..4ab7b06 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -216,7 +216,7 @@ procfile(const char *fn) else break; } - if (ln.len > 0 && ln.dat[ln.len - 1] == '\n') + if (ln.len > 0 && ln.dat[ln.len - 1] == fileeol) --ln.len; ln.line_no++; @@ -525,6 +525,6 @@ printline(struct str *line, int sep, regmatch_t *matches, int m) } } else { fwrite(line->dat, line->len, 1, stdout); - putchar('\n'); + putchar(fileeol); } } -- cgit v1.1