]> err.no Git - moreutils/commitdiff
er yeah, let's check in the right stuff
authorjoeyh <joeyh>
Thu, 16 Mar 2006 17:08:29 +0000 (17:08 +0000)
committerjoeyh <joeyh>
Thu, 16 Mar 2006 17:08:29 +0000 (17:08 +0000)
pee [deleted file]
pee.c [new file with mode: 0644]
pee.docbook [new file with mode: 0644]

diff --git a/pee b/pee
deleted file mode 100755 (executable)
index b4874b7..0000000
Binary files a/pee and /dev/null differ
diff --git a/pee.c b/pee.c
new file mode 100644 (file)
index 0000000..35ad37d
--- /dev/null
+++ b/pee.c
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+/* Licensed under the GPL
+ * Copyright (c) Miek Gieben, 2006
+ */
+
+/* like tee(1), but then connect to other programs using
+ * pipes _and_ output to standard output
+ */
+
+void
+close_pipes(FILE **p, size_t i) 
+{
+       size_t j;
+       for (j = 0; j < i; j++) 
+               pclose(p[j]);
+}
+
+int
+main(int argc, char **argv) {
+       size_t i, r;
+       FILE **pipes;
+       char buf[BUFSIZ];
+
+       pipes = malloc(((argc - 1) * sizeof *pipes));
+       if (!pipes) 
+               exit(EXIT_FAILURE);
+
+       for (i = 1; i < argc; i++) {
+               pipes[i - 1] = popen(argv[i], "w");
+               if (!pipes[i - 1]) {
+                       fprintf(stderr, "Can not open pipe to '%s\'\n", argv[i]);
+                       close_pipes(pipes, i);
+
+                       exit(EXIT_FAILURE);
+               }
+       }
+       argc--;
+       
+       while(!feof(stdin) && (!ferror(stdin))) {
+               r = fread(buf, sizeof(char), BUFSIZ, stdin);
+               for(i = 0; i < argc; i++) {
+                       if (fwrite(buf, sizeof(char), r, pipes[i]) != r) {
+                               fprintf(stderr, "Write error to `%s\'\n", argv[i + 1]);
+                               close_pipes(pipes, i);
+                               exit(EXIT_FAILURE);
+                       }
+                       fwrite(buf, sizeof(char), r, stdout);
+               }
+       }
+       close_pipes(pipes, argc);
+
+       exit(EXIT_SUCCESS);
+}
diff --git a/pee.docbook b/pee.docbook
new file mode 100644 (file)
index 0000000..970dc81
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+
+Copyright 2006 Joey Hess <joey@kitenet.net>
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+-->
+
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN"
+"file:///usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd"
+[]>
+
+<refentry>
+       <refentryinfo>
+               <address>
+                       <email>joey@kitenet.net</email>
+               </address>
+               <author>
+                       <firstname>Joey</firstname>
+                       <surname>Hess</surname>
+               </author>
+               <date>2006-03-14</date>
+       </refentryinfo>
+
+       <refmeta>
+               <refentrytitle>pee</refentrytitle>
+               <manvolnum>1</manvolnum>
+       </refmeta>
+
+       <refnamediv>
+               <refname>pee</refname> 
+               <refpurpose>tee standard input to pipes</refpurpose>
+       </refnamediv>
+
+       <refsynopsisdiv>
+               <cmdsynopsis>
+                       <command>pee</command>
+                       <group choice="opt">
+                               <arg rep="repeat"><replaceable>"command"</replaceable></arg>
+                       </group>
+               </cmdsynopsis>
+       </refsynopsisdiv>
+       
+       <refsect1>
+               <title>DESCRIPTION</title>
+               
+               <para><command>pee</command> is like <command>tee</command>
+               but for pipes. Each command is run and standard input is
+               copied into it, as well as being sent to stdout.</para>
+               
+       </refsect1>
+       
+       <refsect1>
+               <title>SEE ALSO</title>
+               
+               <para>
+                       <citerefentry>
+                               <refentrytitle>tee</refentrytitle><manvolnum>1</manvolnum>
+                       </citerefentry>
+               </para>
+               
+       </refsect1>
+</refentry>