home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 171_01 / print.c < prev    next >
Text File  |  1983-10-30  |  3KB  |  133 lines

  1. /* ---------------------------------------------------    */
  2. /*    PRINT - Print a file with header to the printer */
  3. /*        M. Burton    04 July 1983        */
  4. /*    Written in Computer Innovations C86        */
  5. /* ---------------------------------------------------    */
  6. /*        Syntax:                 */
  7. /*                            */
  8. /*    PRINT filename.typ - Print a file with line    */
  9. /*                numbers.        */
  10. /*    PRINT filename.typ /N - Print a file without    */
  11. /*                line numbers.        */
  12. /* ---------------------------------------------------    */
  13.  
  14. #include "stdio.h"
  15.  
  16. struct regval        /* Register structure for INT    */
  17. {
  18.     int ax,bx,cx,dx,si,di,ds,es;
  19. }
  20. struct regval srv, rrv, trv, brv;
  21. int mo, dy, yr;
  22. int hr, mn, sc, hn;
  23.  
  24. main(argc,argv)
  25.     int argc;    /* Number of args in cmd line    */
  26.     char *argv[];    /* Args in cmd line        */
  27. {
  28.     int *fd;    /* File stream pointer        */
  29.     int *cd;    /* Printer stream pointer    */
  30.     char *sp;    /* filename.typ pointer     */
  31.     int c;        /* Loop variable        */
  32.     int lineno=1;    /* Line counter         */
  33.     int pline=1;    /* Line on page counter     */
  34.     int page=1;    /* Page counter         */
  35.     char s[232];    /* Line buffer            */
  36.  
  37.     srv.ax = (0x2c << 8);
  38.     sysint(0x21,&srv,&brv); /* Get the time     */
  39.  
  40.     if (argc == 1)
  41.     {
  42.         printf("Proper syntax: PRINT filename.typ </N>\007\n");
  43.         goto abort;
  44.     }
  45.  
  46.     sp = argv[1];
  47.     while ((*sp = toupper(*sp)) != EOS) sp++;
  48.     fd = fopen(argv[1],"r");
  49.     if (fd == 0)
  50.     {
  51.         printf("%s not found\007\n",argv[1]);
  52.         goto abort;
  53.     }
  54.  
  55.     cd = fopen("PRN:","w");
  56.     if (cd == 0)
  57.     {
  58.         printf("Printer offline\007\n");
  59.         goto abort;
  60.     }
  61.  
  62.     c = 1;
  63.     prthdr(page,cd,argv[1]);
  64.     while (c != EOS)
  65.     {
  66.         pline = 1;
  67.         while (pline < 57)
  68.         {
  69.             c = fgets(s,232,fd);
  70.             if (c == EOS) goto quit;
  71.             if (argc == 3)
  72.             {
  73.                 if (strncmp(argv[2],"/n",2) == 0 || strncmp(argv[2],"/N",2) == 0)
  74.                 {
  75.                     fprintf(cd,"%s",s);
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 fprintf(cd,"%7u  %s",lineno,s);
  81.             }
  82.             lineno++;
  83.             pline++;
  84.         }
  85.         page++;
  86.         fprintf(cd,"\n\014");
  87.         prthdr(page,cd,argv[1]);
  88.     }
  89. quit:
  90.     fprintf(cd,"  \n\014");
  91.     srv.ax = (0x2c << 8);
  92.     sysint(0x21,&srv,&trv);     /* Get end time */
  93.     hr = (trv.cx >> 8) - (brv.cx >> 8);
  94.     if((mn = (trv.cx & 0xff) - (brv.cx & 0xff)) < 0)
  95.     {
  96.         hr--;
  97.         mn = mn + 60;
  98.     }
  99.     if((sc = (trv.dx >> 8) - (brv.dx >> 8)) < 0)
  100.     {
  101.         mn--;
  102.         sc = sc + 60;
  103.         if (mn < 0)
  104.         {
  105.             hr--;
  106.             mn = mn + 60;
  107.         }
  108.     }
  109.     printf("Finished printing '%s';",argv[1]);
  110.     printf("%5u lines,%5u pages.\n",--lineno,page);
  111.     printf("Total print time %02u:%02u:%02u\n",hr,mn,sc);
  112.     fclose(fd);
  113.     fclose(cd);
  114. abort:    ;        /* Dummy line            */
  115. }
  116.  
  117. prthdr(p,cc,aa)     /* Print the page header    */
  118.     int p, cc, *aa;
  119. {
  120.     srv.ax = (0x2a << 8);
  121.     sysint(0x21,&srv,&rrv);
  122.     mo = (rrv.dx >> 8);
  123.     dy = (rrv.dx & 0xff);
  124.     yr = rrv.cx;
  125.     srv.ax = (0x2c << 8);
  126.     sysint(0x21,&srv,&trv);
  127.     hr = (trv.cx >> 8);
  128.     mn = (trv.cx & 0xff);
  129.     sc = (trv.dx >> 8);
  130.     hn = (trv.dx & 0xff);
  131.     fprintf(cc,"Listing of %s     %02u-%02u-%4u     %02u:%02u:%02u.%02u                   Page %3u\n",aa,mo,dy,yr,hr,mn,sc,hn,p);
  132. }
  133.