home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 09print / pr_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.2 KB  |  57 lines

  1. /*
  2.  *    pr_file -- process each filename or standard input
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <local\std.h>
  9. #include "print.h"
  10.  
  11. int
  12. pr_file(pname, ac, av)
  13. char *pname;
  14. int ac;
  15. char **av;
  16. {
  17.     int ch, errcount = 0;
  18.     FILE *fin, *fout;
  19.     extern PRINT pcnf;
  20.  
  21.     extern void fatal(char *, char *, int);
  22.     extern int pr_cpy(FILE *, FILE *, char *);
  23.  
  24.     /* open output stream only if not already open */
  25.     if (*pcnf.p_dest == '\0' || strcmp(pcnf.p_dest, "CON") == 0)
  26.         fout = stdout;
  27.     else if (strcmp(pcnf.p_dest, "PRN") == 0)
  28.         fout = stdprn;
  29.     else if (strcmp(pcnf.p_dest, "AUX") == 0)
  30.         fout = stdaux;
  31.     else
  32.         if ((fout = fopen(pcnf.p_dest, "w")) == NULL)
  33.             fatal(pname, "Error open destination stream", 1);
  34.  
  35.     /* prepare input stream */
  36.     if (ac == 0)
  37.         pr_cpy(stdin, fout, "");
  38.     else {
  39.         for (; ac > 0; --ac, ++av) {
  40.             if ((fin = fopen(*av, "r")) == NULL) {
  41.                 fprintf(stderr, "%s: Error opening %s",
  42.                     pname, *av);
  43.                 continue;
  44.             }
  45.             if (pr_cpy(fin, fout, *av) == -1) {
  46.                 fprintf(stderr, "%s: Cannot stat %s",
  47.                     pname, *av);
  48.                 continue;
  49.             }
  50.             if (fclose(fin) == EOF)
  51.                 fatal(pname, "Error closing input file", 2);
  52.         }
  53.     }
  54.  
  55.     return (errcount);
  56. }
  57.