home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / laserjet-printcap / hpf.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.6 KB  |  113 lines

  1. #include "stdio.h"
  2. #include <signal.h>
  3.  
  4. int nomap = 0, is_of = 1;
  5.  
  6. main(ac, av)
  7. int ac;
  8. char **av;
  9. {
  10.     while(ac > 1 && av[1][0] == '-')
  11.     {
  12.     switch(av[1][1])
  13.     {
  14.         case 'c':
  15.         nomap = 1;
  16.         break;
  17.         case 'n': case 'h':
  18.         is_of = 0;
  19.         break;
  20.         default: break;
  21.     }
  22.     ac--;
  23.     av++;
  24.     }
  25.  
  26.     lzinit();
  27.     hpcat();
  28.     exit(0);
  29. }
  30.  
  31. #include <sgtty.h> 
  32.  
  33. lzinit()
  34. {
  35.     struct sgttyb nbuf;
  36.     unsigned long lbits;
  37.  
  38.     setbuf(stdout, NULL);
  39.     /* Work around to by-pass bug in terminal driver and force LITOUT */
  40.     lbits = LMDMBUF|LLITOUT;
  41.     ioctl(fileno(stdout), TIOCLSET, &lbits);
  42.     ioctl(fileno(stdout), TIOCGETP, &nbuf);
  43.     nbuf.sg_flags &= ~(ECHO|XTABS|CRMOD);  /* While we're at it, set the mode */
  44.     ioctl(fileno(stdout), TIOCSETP, &nbuf);
  45.  
  46.     fputs("\033&k3G", stdout);    /* Set device to sane mode    */
  47. }
  48.  
  49. hpcat()
  50. {
  51.     register int c, cnt = 0;
  52.  
  53.     while((c = getchar()) != EOF)
  54.     {
  55.  
  56.     if(c == '\t')
  57.     {
  58.         do {
  59.         delay();
  60.         putchar(' ');
  61.         cnt++;
  62.         } while(cnt%8 != 0);
  63.     }
  64.     else if(is_of && c == '\031')
  65.     {
  66.         if(getchar() == '\001') kill(getpid(), SIGSTOP);
  67.     }
  68.     else
  69.     {
  70.         delay();
  71.         putchar(c);
  72.         if(c == '\f' || c == '\n') 
  73.         {
  74.         cnt = 0;
  75.         }
  76.         else cnt++;
  77.     }
  78.     }
  79. }
  80.  
  81. #include <sys/time.h> 
  82.  
  83. struct timeval tm = {0, 1500};
  84.  
  85. delay()
  86. {
  87.     select(0, 0, 0, 0, &tm);
  88. }
  89.  
  90. /*    Old version, hope to use again later
  91. #include <sys/time.h> 
  92. #include <signal.h>
  93.  
  94. int wakeup;
  95.  
  96. void nullfunc(){
  97.     wakeup = 1;
  98. }
  99.  
  100. struct itimerval tm = {{0, 0}, {0, 1500}};
  101.  
  102. delay()
  103. {
  104.  
  105.     void nullfunc();
  106.  
  107.     signal(SIGALRM, nullfunc);
  108.     wakeup = 0;
  109.     if(setitimer(ITIMER_REAL, &tm, NULL)) exit(1);
  110.     while(wakeup == 0) sigpause(0);
  111. }
  112. */
  113.