home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1699 / iffil.c next >
C/C++ Source or Header  |  1990-12-28  |  2KB  |  83 lines

  1. /*
  2.     iffil, a printcap filter to print on the HP LaserJet Series II
  3.  
  4.     Written by Brian Utterback
  5.     December 1987
  6.  
  7. */
  8.  
  9. #include <stdio.h>
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     int c,atoi();
  15.     int contr,width,length;
  16.     int nlines=0,npages=2;
  17.     FILE *fopen(), *fp;
  18.     char *cp,*indent;
  19.     char *logi,*host,*actf;
  20.  
  21.     while (--argc) {
  22.         if (*(cp = *++argv) == '-' ) {
  23.             switch (cp[1]) {
  24.             case 'w':
  25.                 width = atoi(&cp[2]);
  26.                 break;
  27.  
  28.             case 'l':
  29.                 length = atoi(&cp[2]);
  30.                 break;
  31.  
  32.             case 'c':
  33.                 contr++;
  34.                 break;
  35.  
  36.             case 'i':
  37.                 indent = &cp[2];
  38.                 break;
  39.  
  40.             case 'n':
  41.                 logi = argv[1];
  42.                 break;
  43.  
  44.             case 'h':
  45.                 host = argv[1];
  46.                 actf = argv[2];
  47.                 break;
  48.             }
  49.         }
  50.     };
  51.  
  52.  
  53.  
  54.     printf("\033E");        /* Reset the printer */
  55.     printf("\033&k3G");        /* cr || nl -> cr+nl */
  56.     if ( length == 78 )          /* Legal paper       */
  57.         printf("\033&l3a2H");    /* Hand feed         */
  58.     if ( length == 45 )  {        /* Landscape         */
  59.         if (width == 136 || width == 226 )
  60.             printf("\033&l3a2H"); /* Legal again */
  61.         printf("\033&l1O");     /* set to Landscape  */
  62.     };
  63.     if (width == 132 || width == 176 || width == 226 )
  64.         printf("\033(s16.66H");    /* Compressed print  */
  65.     printf("\033&a%sL",indent);    /* Indented         */
  66.     while ( (c = getchar()) != EOF) {
  67.         if ( c == '\n' || c == '\r' ) nlines++;
  68.         if ( c == '\f' || nlines > length) {
  69.             nlines = 0;
  70.             npages++;
  71.         };
  72.         putchar(c);
  73.     };
  74.     if (access(actf, 02) >= 0 && (fp = fopen(actf,"a")) != NULL ) {
  75.         fprintf(fp,"%7.2f\t%s:%s\n",(float)npages,host,logi);
  76.         fclose(fp);
  77.     } else {
  78.         fprintf(stderr,
  79.             "iffil: Can't open %s\n", actf);
  80.         exit(1);
  81.     };
  82. }
  83.