Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Aug 2017 00:47:53 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r322560 - in stable/11/usr.bin/grep: . nls
Message-ID:  <201708160047.v7G0lrwM037998@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Aug 16 00:47:53 2017
New Revision: 322560
URL: https://svnweb.freebsd.org/changeset/base/322560

Log:
  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

Modified:
  stable/11/usr.bin/grep/file.c
  stable/11/usr.bin/grep/grep.1
  stable/11/usr.bin/grep/grep.c
  stable/11/usr.bin/grep/grep.h
  stable/11/usr.bin/grep/nls/C.msg
  stable/11/usr.bin/grep/nls/es_ES.ISO8859-1.msg
  stable/11/usr.bin/grep/nls/gl_ES.ISO8859-1.msg
  stable/11/usr.bin/grep/nls/hu_HU.ISO8859-2.msg
  stable/11/usr.bin/grep/nls/ja_JP.SJIS.msg
  stable/11/usr.bin/grep/nls/ja_JP.UTF-8.msg
  stable/11/usr.bin/grep/nls/ja_JP.eucJP.msg
  stable/11/usr.bin/grep/nls/pt_BR.ISO8859-1.msg
  stable/11/usr.bin/grep/nls/ru_RU.KOI8-R.msg
  stable/11/usr.bin/grep/nls/uk_UA.UTF-8.msg
  stable/11/usr.bin/grep/nls/zh_CN.UTF-8.msg
  stable/11/usr.bin/grep/util.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/grep/file.c
==============================================================================
--- stable/11/usr.bin/grep/file.c	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/file.c	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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);

Modified: stable/11/usr.bin/grep/grep.1
==============================================================================
--- stable/11/usr.bin/grep/grep.1	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/grep.1	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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

Modified: stable/11/usr.bin/grep/grep.c
==============================================================================
--- stable/11/usr.bin/grep/grep.c	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/grep.c	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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 mat
 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");
 
@@ -605,6 +608,9 @@ main(int argc, char *argv[])
 			break;
 		case 'X':
 			filebehave = FILE_XZ;
+			break;
+		case 'z':
+			fileeol = '\0';
 			break;
 		case 'Z':
 			filebehave = FILE_GZIP;

Modified: stable/11/usr.bin/grep/grep.h
==============================================================================
--- stable/11/usr.bin/grep/grep.h	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/grep.h	Wed Aug 16 00:47:53 2017	(r322560)
@@ -116,6 +116,7 @@ extern bool	 dexclude, dinclude, fexclude, finclude, l
 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;

Modified: stable/11/usr.bin/grep/nls/C.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/C.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/C.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/es_ES.ISO8859-1.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/es_ES.ISO8859-1.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/es_ES.ISO8859-1.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/gl_ES.ISO8859-1.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/gl_ES.ISO8859-1.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/gl_ES.ISO8859-1.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/hu_HU.ISO8859-2.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/hu_HU.ISO8859-2.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/hu_HU.ISO8859-2.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/ja_JP.SJIS.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/ja_JP.SJIS.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/ja_JP.SJIS.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/ja_JP.UTF-8.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/ja_JP.UTF-8.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/ja_JP.UTF-8.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/ja_JP.eucJP.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/ja_JP.eucJP.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/ja_JP.eucJP.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/pt_BR.ISO8859-1.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/pt_BR.ISO8859-1.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/pt_BR.ISO8859-1.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/ru_RU.KOI8-R.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/ru_RU.KOI8-R.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/ru_RU.KOI8-R.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/uk_UA.UTF-8.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/uk_UA.UTF-8.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/uk_UA.UTF-8.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/nls/zh_CN.UTF-8.msg
==============================================================================
--- stable/11/usr.bin/grep/nls/zh_CN.UTF-8.msg	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/nls/zh_CN.UTF-8.msg	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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"

Modified: stable/11/usr.bin/grep/util.c
==============================================================================
--- stable/11/usr.bin/grep/util.c	Wed Aug 16 00:42:51 2017	(r322559)
+++ stable/11/usr.bin/grep/util.c	Wed Aug 16 00:47:53 2017	(r322560)
@@ -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 *match
 		}
 	} else {
 		fwrite(line->dat, line->len, 1, stdout);
-		putchar('\n');
+		putchar(fileeol);
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708160047.v7G0lrwM037998>