home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / sysutl / tools.lbr / LIST.CZ / LIST.C
Encoding:
C/C++ Source or Header  |  1987-08-07  |  1.5 KB  |  111 lines

  1. #include <bdscio.h>
  2.  
  3. /* This program lists files to the printer. Wildcards and
  4.    argument lists are supported.
  5. */
  6.  
  7. int kill;
  8.  
  9. main(argc,argv)
  10.  
  11. int argc;
  12. char *argv[];
  13. {
  14. int i;
  15.     kill = FALSE;
  16.     if (argc < 2)
  17.     {
  18.         printf("Usage:  list <arglist> \n");
  19.         exit(1);
  20.     }
  21.     else
  22.     {
  23.         expand(&argc,&argv);
  24.         for ( i = 1; i < argc; i++) 
  25.         {
  26.             if(kill) break;
  27.             lst(argv[i]);
  28.         }
  29.     }
  30.     feed();
  31. }
  32.  
  33.  
  34. /* Subroutine to display a file on the printer. The argument
  35.    must not be a wildcard name.
  36. */
  37. lst(name)
  38.  
  39. char *name;
  40. {
  41. char ibuf[BUFSIZ], line[MAXLINE];
  42. int pagecnt, linecnt;
  43.  
  44.     if(openr(name,ibuf) == ERROR)
  45.         return;
  46.  
  47. /* Set up printer tab stops */
  48.  
  49.     settabs();
  50.  
  51. /* Begin page loop */
  52.  
  53.     kill = abort();    
  54.     pagecnt = 1;
  55.     while(fgets(line,ibuf) && !kill)
  56.     {
  57.         fprintf(2,"\t%s\t\t\t\t\t\t\tPAGE %d\n\n",
  58.                         name,pagecnt);
  59.         fprintf(2,"\t%s",line);
  60.         linecnt = 1;
  61.  
  62.         /* Begin line loop */
  63.  
  64.         while((fgets(line,ibuf)) && !kill)
  65.         {
  66.             kill = abort();
  67.             fprintf(2,"\t%s",line);
  68.             if(++linecnt >= 55) break;
  69.         }
  70.         pagecnt++;
  71.         feed();
  72.     }
  73.     fclose(ibuf);
  74. }
  75.  
  76. list(c)
  77. char c;
  78. {
  79.     putc(c,2);
  80. }
  81.  
  82. feed()
  83.  
  84. #define FF 0x0c
  85. {
  86.     list(FF);
  87. }
  88.  
  89. settabs()
  90. {
  91. int n;
  92. #define ESC 0x1b
  93.  
  94.     list(ESC);
  95.     list('D');
  96.     for( n = 4 ; n < 81 ; n = n + 8)
  97.         list(n);
  98.     list(0);
  99. }
  100.  
  101. abort()
  102. {
  103. int c;
  104.  
  105.     c = bdos(6, 0xff);
  106.     if (c == 3)
  107.         return(TRUE);
  108.     else
  109.         return(FALSE);
  110. }
  111.