svn commit: r322560 - in stable/11/usr.bin/grep: . nls

Kyle Evans kevans at FreeBSD.org
Wed Aug 16 00:47:55 UTC 2017


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 estándar)"
 2 "no se puede leer el fichero comprimido bzip2"
 3 "opción 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=acción] [--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 estándar)"
 2 "non se pode ler o ficheiro comprimido bzip2"
 3 "opción descoñecida 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=acción] [--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 "(szabványos bemenet)"
 2 "bzip2 tömörített fájl nem olvasható"
 3 "ismeretlen %s opció"
-4 "használat: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A szám] [-B szám] [-C[szám]]\n"
+4 "használat: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A szám] [-B szám] [-C[szám]]\n"
 5 "\t[-e minta] [-f fájl] [--binary-files=érték] [--color=mikor]\n"
 6 "\t[--context[=szám]] [--directories=mûvelet] [--label] [--line-buffered]\n"
 7 "\t[--null] [minta] [fájl ...]\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 ˆ³kƒtƒ@ƒCƒ‹‚ð“ǂݍž‚Þ‚±‚Æ‚ª‚Å‚«‚Ü‚¹‚ñ"
 3 "%s ƒIƒvƒVƒ‡ƒ“‚ÌŽw’è’l‚ÉŒë‚肪‚ ‚è‚Ü‚·"
-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 padrão)"
 2 "não se posso ler o fichero comprimido bzip2"
 3 "opcão não 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 padrão] [-f arquivo] [--binary-files=valor] [--color=quando]\n"
 6 "\t[--context[=num]] [--directories=ação] [--label] [--line-buffered]\n"
 7 "\t[--null] [padrão] [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);
 	}
 }


More information about the svn-src-all mailing list