From mteterin@250-217.customer.cloud9.net  Fri Sep 19 14:36:59 2003
Return-Path: <mteterin@250-217.customer.cloud9.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DCA7D16A4BF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Sep 2003 14:36:59 -0700 (PDT)
Received: from corbulon.video-collage.com (corbulon.video-collage.com [64.35.99.179])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1D6F943FE5
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Sep 2003 14:36:58 -0700 (PDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from 250-217.customer.cloud9.net (250-217.customer.cloud9.net [168.100.250.217])
	by corbulon.video-collage.com (8.12.10/8.12.10) with ESMTP id h8JLao7Q024576
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Sep 2003 17:36:55 -0400 (EDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: from 250-217.customer.cloud9.net (mteterin@localhost [127.0.0.1])
	by 250-217.customer.cloud9.net (8.12.9/8.12.9) with ESMTP id h8JLbtjB061222
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Sep 2003 17:38:00 -0400 (EDT)
	(envelope-from mteterin@250-217.customer.cloud9.net)
Received: (from mteterin@localhost)
	by 250-217.customer.cloud9.net (8.12.9/8.12.9/Submit) id h8JLbsIs061221;
	Fri, 19 Sep 2003 17:37:54 -0400 (EDT)
	(envelope-from mteterin)
Message-Id: <200309192137.h8JLbsIs061221@250-217.customer.cloud9.net>
Date: Fri, 19 Sep 2003 17:37:54 -0400 (EDT)
From: Mikhail Teterin <mi@aldan.algebra.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: a new option for xargs(1) -- only treat \n as separators
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         57024
>Category:       bin
>Synopsis:       a new option for xargs(1) -- only treat \n as separators
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 19 14:40:13 PDT 2003
>Closed-Date:    Wed Dec 07 12:25:56 GMT 2005
>Last-Modified:  Wed Dec 07 12:25:56 GMT 2005
>Originator:     Mikhail Teterin
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
Virtual Estates, Inc.
>Environment:
System: FreeBSD mi.us.murex.com 5.1-CURRENT FreeBSD 5.1-CURRENT #5: Wed Sep 10 16:35:59 EDT 2003 root@mi.us.murex.com:/misha/obj/misha/src/sys/Misha-g i386

>Description:

	While the -0 option provides the ultimate solution for handling
	unusual characters in file-names, it requires cooperation from
	the input generator (such as find(1)).

	Sometimes, the potential input for xargs(1) is generated by a
	non-cooperating utility, which does not have the find(1) -print0
	equivalent. Output of ``tar -t'' is one example.

	The '\n' character, however, happens very rarely in the filenames.
	It would be of great convenience to be able to specify it as the
	only separator, for it does not require modifications to the input.

		find .... | xargs -N ...

	will work as good as

		find .... -print0 | xargs -0 ...

	as long as there are no filenames with embedded \n.

>How-To-Repeat:

		tar -t some.tar | xargs ls -l

	would break if the archive has files with tabs or spaces in
	their names. While modifying tar is an option, the proposed
	new flag will solve the problem for almost everybody:

		tar -t some.tar | xargs -N ls -l

>Fix:

	This would be another non-standard option and the patch
	below documents it as such.

Index: xargs.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/xargs/xargs.1,v
retrieving revision 1.30
diff -U2 -r1.30 xargs.1
--- xargs.1	21 May 2003 21:07:28 -0000	1.30
+++ xargs.1	19 Sep 2003 21:33:31 -0000
@@ -46,5 +46,5 @@
 .Sh SYNOPSIS
 .Nm
-.Op Fl 0opt
+.Op Fl 0Nopt
 .Op Fl E Ar eofstr
 .Oo
@@ -99,4 +99,11 @@
 function in
 .Xr find 1 .
+.It Fl N
+Change
+.Nm
+to only treat newlines as separators. This is not as comprehensive as the
+.Fl 0
+option above, but can be useful if the input contains one argument per line
+as is often the case.
 .It Fl E Ar eofstr
 Use
@@ -295,5 +302,5 @@
 compliant.
 The
-.Fl J , o , P
+.Fl J , N, o , P
 and
 .Fl R
Index: xargs.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/xargs/xargs.c,v
retrieving revision 1.54
diff -U2 -r1.54 xargs.c
--- xargs.c	13 Jun 2003 17:05:41 -0000	1.54
+++ xargs.c	19 Sep 2003 21:33:31 -0000
@@ -81,5 +81,5 @@
 static const char *eofstr;
 static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
-static int cnt, Iflag, jfound, Lflag, wasquoted, xflag;
+static int cnt, Iflag, jfound, Lflag, Nflag, wasquoted, xflag;
 static int curprocs, maxprocs;
 
@@ -125,5 +125,5 @@
 	}
 	maxprocs = 1;
-	while ((ch = getopt(argc, argv, "0E:I:J:L:n:oP:pR:s:tx")) != -1)
+	while ((ch = getopt(argc, argv, "0NE:I:J:L:n:oP:pR:s:tx")) != -1)
 		switch(ch) {
 		case 'E':
@@ -176,4 +176,7 @@
 			zflag = 1;
 			break;
+		case 'N':
+			Nflag = 1;
+			break;
 		case '?':
 		default:
@@ -183,4 +186,6 @@
 	argv += optind;
 
+	if (zflag && Nflag)
+		errx(1, "-0 and -N are mutually exclusive");
 	if (!Iflag && Rflag)
 		usage();
@@ -269,5 +274,5 @@
 	case '\t':
 		/* Quotes escape tabs and spaces. */
-		if (insingle || indouble || zflag)
+		if (insingle || indouble || zflag || Nflag)
 			goto addch;
 		goto arg2;
@@ -353,5 +358,5 @@
 		break;
 	case '\'':
-		if (indouble || zflag)
+		if (indouble || zflag || Nflag)
 			goto addch;
 		insingle = !insingle;
@@ -359,5 +364,5 @@
 		break;
 	case '"':
-		if (insingle || zflag)
+		if (insingle || zflag || Nflag)
 			goto addch;
 		indouble = !indouble;
@@ -365,5 +370,5 @@
 		break;
 	case '\\':
-		if (zflag)
+		if (zflag || Nflag)
 			goto addch;
 		/* Backslash escapes anything, is escaped by quotes. */
@@ -600,5 +605,5 @@
 {
 	fprintf(stderr,
-"usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
+"usage: xargs [-0Nopt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n"
 "             [-L number] [-n number [-x]] [-P maxprocs] [-s size]\n"
 "             [utility [argument ...]]\n");
>Release-Note:
>Audit-Trail:

From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: freebsd-gnats-submit@FreeBSD.org, mi@aldan.algebra.com
Cc:  
Subject: Re: bin/57024: a new option for xargs(1) -- only treat \n as separators
Date: Sat, 20 Sep 2003 05:49:36 +0200

 How about:
   tar -t some.tar | tr '\n' '\000' | xargs -0 ls -l
 
 

From: Garance A Drosehn <gad@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, mi@aldan.algebra.com
Cc:  
Subject: Re: bin/57024: a new option for xargs(1) -- only treat \n as
 separators
Date: Sat, 26 Feb 2005 20:35:19 -0500

 I suspect this PR should be closed.  Not only is there the
 very-workable solution from Oliver, but 'xargs -L <num>' is
 pretty close to what the original PR is asking for.
 
 It may not be obvious from  description in the man page, but
 when you request -L you're saying (among other things) that
 you want *lines* of input.  Therefore it switches to using
 just '\n' as the delimiter for arguments.
 
 (the reason I'm not closing the PR myself is that I haven't
 yet checked the 'xargs' on other OS's to see if our 'xargs'
 has implemented -L in the same way that their versions do.
 I might close come back and close the PR at some later date).
 
 -- 
 Garance Alistair Drosehn     =      gad@gilead.netel.rpi.edu
 Senior Systems Programmer               or   gad@FreeBSD.org
 Rensselaer Polytechnic Institute;             Troy, NY;  USA
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Wed Dec 7 12:25:55 GMT 2005 
State-Changed-Why:  
xargs -L1 is POSIX-compliant and will do what you want 

http://www.freebsd.org/cgi/query-pr.cgi?pr=57024 
>Unformatted:
