Can someone explain to me why xargs(1) does not support using newline
as a separators, when that is one of the most common unix separators?

I'm pasting one potential approach to the end of this message. There's
a few issues that might be stalling points:

(*) which command line option to be used (this gets into potential
conflicts with other versions).

(*) how to handle (or not handle) escape characters (my feeling is
that escaping newline characters would be a bad thing when using
newline as a separator).

(*) code neatness and style issues.

But, anyways, given the problems that arise from xargs space handling
being "too smart", and given how often spaces get included in file and
directory names, it seems like newline separated records should have
been a no-brainer back like 20 years ago, if not earlier. So
presumably someone has at some point squashed efforts to fix this.

So, I guess I might be looking for the reasons. Does anyone know?

Thanks,

-- 
Raul

--- xargs.c.orig        2017-10-13 14:13:16.000000000 -0400
+++ xargs.c        2017-10-13 14:13:17.000000000 -0400
@@ -65,7 +65,7 @@
 static char **av, **bxp, **ep, **endxp, **xp;
 static char *argp, *bbp, *ebp, *inpline, *p, *replstr;
 static const char *eofstr;
-static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
+static int count, insingle, indouble, oflag, pflag, tflag, Rflag,
rval, zflag, lflag;
 static int cnt, Iflag, jfound, Lflag, wasquoted, xflag, runeof = 1;
 static int curprocs, maxprocs;
 static size_t inpsize;
@@ -174,6 +174,9 @@
                 case '0':
                         zflag = 1;
                         break;
+                case '/':
+                        lflag = 1;
+                        break;
                 case '?':
                 default:
                         usage();
@@ -262,7 +265,7 @@
                 if (insingle || indouble)
                         goto addch;
                 hasblank = 1;
-                if (zflag)
+                if (zflag || (lflag  && '\n'==ch))
                         goto addch;
                 goto arg2;
         }
@@ -282,6 +285,8 @@
                         goto arg2;
                 goto addch;
         case '\n':
+                if (lflag)
+                        goto arg2;
                 hasblank = 1;
                 if (hadblank == 0)
                         count++;
@@ -360,19 +365,19 @@
                 wasquoted = 0;
                 break;
         case '\'':
-                if (indouble || zflag)
+                if (indouble || zflag || lflag)
                         goto addch;
                 insingle = !insingle;
                 wasquoted = 1;
                 break;
         case '"':
-                if (insingle || zflag)
+                if (insingle || zflag || lflag)
                         goto addch;
                 indouble = !indouble;
                 wasquoted = 1;
                 break;
         case '\\':
-                if (zflag)
+                if (zflag || lflag)
                         goto addch;
                 /* Backslash escapes anything, is escaped by quotes. */
                 if (!insingle && !indouble && (ch = getchar()) == EOF)

Reply via email to