Mercurial > hg > toybox
changeset 423:2a2b483a4cf9
Implement xargs -E.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 02 Feb 2012 07:44:04 -0600 |
parents | 82d70cff7357 |
children | 85a5e01e7ad8 |
files | toys/xargs.c |
diffstat | 1 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/xargs.c Thu Feb 02 07:42:31 2012 -0600 +++ b/toys/xargs.c Thu Feb 02 07:44:04 2012 -0600 @@ -26,7 +26,7 @@ #-x Exit if can't fit everything in one command #-r Don't run command with empty input #-L Max number of lines of input per command - #-E stop at line matching string + -E stop at line matching string */ #include "toys.h" @@ -35,7 +35,7 @@ long max_bytes; long max_entries; long L; - char *E; + char *eofstr; char *I; long entries, bytes; @@ -44,18 +44,13 @@ #define TT this.xargs -// According to man execv(5), the actual ARGS_MAX for linux is 128k (131072) -// meaning the theoretical maximum arguments (each one char) is 65536... but -// we can just use toybuf (1024 pointer on 32 bit, 512 on 64 bit). - -#define ACTUAL_ARGS_MAX 131072 - // If out==NULL count TT.bytes and TT.entries, stopping at max. // Otherwise, fill out out[] // Returning NULL means need more data. +// Returning char * means hit data limits, start of data left over // Returning 1 means hit data limits, but consumed all data -// Returning char * means hit data limits, start of data left over +// Returning 2 means hit -E eofstr static char *handle_entries(char *data, char **entry) { @@ -82,6 +77,11 @@ if (!*s || isspace(*s)) break; s++; } + if (TT.eofstr) { + int len = s-save; + if (len == strlen(TT.eofstr) && !strncmp(save, TT.eofstr, len)) + return (char *)2; + } if (entry) entry[TT.entries] = save; ++TT.entries; } @@ -139,7 +139,8 @@ // Count data used data = handle_entries(data, NULL); if (!data) continue; - if (data == (char *)1) data = 0; + if (data == (char *)2) done++; + if ((long)data <= 2) data = 0; else data = xstrdup(data); break;