added hooks for sort
[oweals/busybox.git] / tee.c
diff --git a/tee.c b/tee.c
index fe444fcc4a66b6708b7cf6cb088d7c96b698ffc9..8d1ca6efd49e7dd21467ecca03776df384ad5258 100644 (file)
--- a/tee.c
+++ b/tee.c
@@ -3,7 +3,7 @@
  *
  *
  * Copyright (C) 1999 by Lineo, inc.
- * Written by John Beppu <beppu@line.com>
+ * Written by John Beppu <beppu@lineo.com>
  *
  * 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
  *
  */
 
+#include "internal.h"
 #include <stdio.h>
-#include <stdlib.h>
+
+static const char tee_usage[] =
+    "tee [OPTION]... [FILE]...\n\n"
+    "Copy standard input to each FILE, and also to standard output.\n\n"
+    "Options:\n"
+    "\t-a\tappend to the given FILEs, do not overwrite\n"
+#if 0
+    "\t-i\tignore interrupt signals\n"
+#endif
+    ;
+
 
 /* FileList _______________________________________________________________ */
 
@@ -32,27 +43,6 @@ static int  FL_end;
 
 typedef void (FL_Function)(FILE *file, char c);
     
-/* initialize FileList */
-static void
-FL_init()
-{
-    FL_end = 0;
-    FileList[0] = stdout;
-}
-
-/* add a file to FileList */
-static int
-FL_add(const char *filename, char *opt_open)
-{
-    FILE    *file;
-
-    file = fopen(filename, opt_open);
-    if (!file) { return 0; };
-    if (FL_end < FL_MAX) {
-       FileList[++FL_end] = file;
-    }
-    return 1;
-}
 
 /* apply a function to everything in FileList */
 static void
@@ -64,8 +54,6 @@ FL_apply(FL_Function *f, char c)
     }
 }
 
-/* ________________________________________________________________________ */
-
 /* FL_Function for writing to files*/
 static void
 tee_fwrite(FILE *file, char c)
@@ -80,21 +68,7 @@ tee_fclose(FILE *file, char c)
     fclose(file);
 }
 
-/* help message */
-static void
-tee_usage()
-{
-    fprintf (
-       stdout,
-       "%s\n%s\n%s\n%s\n%s\n",
-       "Usage: tee [OPTION]... [FILE]...",
-       "Copy standard input to each FILE, and also to standard output.\n",
-       "  -a,    append to the given FILEs, do not overwrite",
-       "  -i,    ignore interrupt signals",
-       "  -h,    this help message"
-    );
-    exit(1);
-}
+/* ________________________________________________________________________ */
 
 /* BusyBoxed tee(1) */
 int
@@ -104,6 +78,7 @@ tee_main(int argc, char **argv)
     char    c;
     char    opt;
     char    opt_fopen[2] = "w";
+    FILE    *file;
 
     /* parse argv[] */
     for (i = 1; i < argc; i++) {
@@ -113,15 +88,13 @@ tee_main(int argc, char **argv)
                case 'a':
                    opt_fopen[0] = 'a';
                    break;
+#if 0
                case 'i':
-                   fprintf(stderr, "ingore interrupt not implemented\n");
-                   break;
-               case 'h':
-                   tee_usage();
+                   fprintf(stderr, "ignore interrupt not implemented\n");
                    break;
+#endif
                default:
-                   fprintf(stderr, "tee: invalid option -- %c\n", opt);
-                   tee_usage();
+                   usage(tee_usage);
            }
        } else {
            break;
@@ -129,9 +102,15 @@ tee_main(int argc, char **argv)
     }
 
     /* init FILE pointers */
-    FL_init();
+    FL_end = 0;
+    FileList[0] = stdout;
     for ( ; i < argc; i++) {
-       FL_add(argv[i], opt_fopen);
+       /* add a file to FileList */
+       file = fopen(argv[i], opt_fopen);
+       if (!file) { continue; }
+       if (FL_end < FL_MAX) {
+           FileList[++FL_end] = file;
+       }
     }
 
     /* read and redirect */
@@ -144,4 +123,4 @@ tee_main(int argc, char **argv)
     exit(0);
 }
 
-/* $Id: tee.c,v 1.1 1999/12/10 05:27:16 beppu Exp $ */
+/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */