home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ptest.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  72 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5.  
  6. int printon = 0, lstclosed = 1 ;
  7. FILE * lst = NULL ;
  8. char * printfile = NULL ;
  9.  
  10. void
  11. printeron() {
  12.     if (printon)            /* It's already on. */
  13.       return;
  14.     if (lstclosed || !lst) {        /* Open printer device */
  15.         if (!printfile)        /* If printer not redirected */
  16.           lst = fopen("prn", "w");    /* open the PRN device */
  17.         else /* otherwise */
  18.           lst = fopen(printfile, "ab"); /* open the file in append mode. */
  19.     }
  20.     if (lst) {                /* Open OK? */
  21.         lstclosed = 0;        /* So not closed */
  22.         printon = 1;            /* and printer is on. */
  23.     }
  24. }
  25.  
  26. void
  27. printeroff() {                /* Turn off printer */
  28.     if (!printon)            /* It's already off. */
  29.       return;
  30.     if (lst && !lstclosed)
  31.     {
  32.         fclose(lst);
  33.     }
  34.     lstclosed = 1;
  35.     printon = 0;
  36. }
  37.  
  38.  
  39. int main( int argc, char * argv[] ) 
  40. {
  41.     if ( argc > 2 )
  42.     {
  43.         printf( "Usage: %s [<printer_device>]\n",argv[0] ) ;
  44.         return(1);
  45.     }
  46.  
  47.     if ( argc == 2 )
  48.       printfile = argv[1] ;
  49.  
  50.     printf( "Opening Printer %s\n", printfile ? printfile : "prn") ;
  51.     printeron();
  52.     if ( lst )
  53.     {
  54.         int i,j,k=1;
  55.         printf("Printer Open - Testing\n");
  56.         for ( i=1; i<50 ; i++ )
  57.         {
  58.             for ( j=1 ; j<80 ; j++ )
  59.               fprintf(lst,"%d",k%10);
  60.             fprintf(lst,"\n");
  61.         }
  62.         printeroff();
  63.         printf("Printer Closed\n");
  64.     }
  65.     else
  66.     {
  67.         printf("Unable to Open Printer: %s\n", strerror(errno));
  68.         return(2);
  69.     }
  70.     return(0);
  71. }
  72.