home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / GROFFSRC / SRC / SPOOLER / PRINTPS.C < prev   
Encoding:
C/C++ Source or Header  |  1994-01-03  |  998 b   |  49 lines

  1. #include <stdlib.h>
  2. #include <io.h>
  3. #include <fcntl.h>
  4.  
  5. #define DEVICE "lpt1"  /* default */
  6.  
  7. void printps(int input, char *out)
  8. {
  9.   char buf[1024];
  10.   int output, bytes;
  11.  
  12.   if ( (output = open(out, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666)) == -1 )
  13.     return;
  14.  
  15.   while ( (bytes = read(input, buf, sizeof(buf))) > 0 )
  16.     if ( write(output, buf, bytes) == -1 )
  17.       break;
  18.     
  19.   close(output);
  20. }
  21.  
  22. void main(int argc, char **argv)
  23. {
  24.   char *dev = getenv("PS_DEVICE");
  25.   int arg, file;
  26.  
  27.   if ( argc == 1 )
  28.     if ( isatty(0) )
  29.     {
  30.       printf("\nUsage: %s [file ...]"
  31.              "\n   or: command | %s\n", argv[0], argv[0]);
  32.       exit(1);
  33.     }
  34.     else
  35.     {
  36.       setmode(0, O_BINARY);
  37.       printps(0, dev ? dev : DEVICE);
  38.     }
  39.   else
  40.     for ( arg = 1; arg < argc; arg++ )
  41.       if ( (file = open(argv[arg], O_RDONLY | O_BINARY)) != -1 )
  42.       {
  43.         printps(file, dev ? dev : DEVICE);
  44.         close(file);
  45.       }
  46.   
  47.   exit(0);
  48. }
  49.