+#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
+static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
+{
+ char *s = buf; /* start of the word */
+ char *p = s + strlen(buf); /* end of the word */
+
+ buf += n_max_chars; /* past buffer's end */
+
+ while (1) {
+ int c = getchar();
+ if (c == EOF) {
+ if (p == s)
+ goto ret;
+ c = '\0';
+ }
+ *p++ = c;
+ if (c == '\0') { /* NUL or EOF detected */
+ /* A full word is loaded */
+ store_param(s);
+ dbg_msg("args[]:'%s'", s);
+ s = p;
+ n_max_arg--;
+ if (n_max_arg == 0) {
+ goto ret;
+ }
+ }
+ if (p == buf) {
+ goto ret;
+ }
+ }
+ ret:
+ *p = '\0';
+ /* store_param(NULL) - caller will do it */
+ dbg_msg("return:'%s'", s);
+ return s;
+}
+#endif /* FEATURE_XARGS_SUPPORT_ZERO_TERM */
+
+#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
+/*
+ * Used if -I<repl> was specified.
+ * In this mode, words aren't appended to PROG ARGS.
+ * Instead, entire input line is read, then <repl> string
+ * in every PROG and ARG is replaced with the line:
+ * echo -e "ho ho\nhi" | xargs -I_ cmd __ _
+ * results in "cmd 'ho hoho ho' 'ho ho'"; "cmd 'hihi' 'hi'".
+ * -n MAX_ARGS seems to be ignored.
+ * Tested with GNU findutils 4.5.10.
+ */
+//FIXME: n_max_chars is not handled the same way as in GNU findutils.
+//FIXME: quoting is not implemented.
+static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg UNUSED_PARAM, char *buf)
+{
+ int i;
+ char *end, *p;
+
+ /* Free strings from last invocation, if any */
+ for (i = 0; G.args && G.args[i]; i++)
+ if (G.args[i] != G.argv[i])
+ free(G.args[i]);
+
+ end = buf + n_max_chars;
+ p = buf;
+
+ while (1) {
+ int c = getchar();
+ if (c == EOF || c == G.eol_ch) {
+ if (p == buf)
+ goto ret; /* empty line */
+ c = '\0';
+ }
+ *p++ = c;
+ if (c == '\0') { /* EOL or EOF detected */
+ i = 0;
+ while (G.argv[i]) {
+ char *arg = G.argv[i];
+ int count = count_strstr(arg, G.repl_str);
+ if (count != 0)
+ arg = xmalloc_substitute_string(arg, count, G.repl_str, buf);
+ store_param(arg);
+ dbg_msg("args[]:'%s'", arg);
+ i++;
+ }
+ p = buf;
+ goto ret;
+ }
+ if (p == end) {
+ goto ret;
+ }
+ }
+ ret:
+ *p = '\0';
+ /* store_param(NULL) - caller will do it */
+ dbg_msg("return:'%s'", buf);
+ return buf;
+}
+#endif