Ok, first off, I appreciate your having taken time to respond.
Especially given the bug I had in my suggested patch.

That said... two things I am missing here:

(1) How do I get access to that normal tooling from the shell command
line without xargs?

(2) Given that POSIX is an incomplete specification, why is POSIX the
issue here?

That said, note also that I am partially motivated by having seen a
lot of xargs -0 deprecated warnings over the years, but I am also
motivated by my desire to use grep or other filters in front of xargs.

Thanks,

-- 
Raul

On Fri, Oct 13, 2017 at 2:34 PM, Theo de Raadt <dera...@openbsd.org> wrote:
>> 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?
>
> Because then you don't need xargs, normal tooling seperates each line
> into a seperate argv entry regardless of other spacing.
>
> You are proposing an incompatible extension to a POSIX defined
> utility.  Meaning if someone uses this in a script, it won't work on
> other systems.
>
> Not everything in unix is perfect.
>
>> 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