home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1599 < prev    next >
Internet Message Format  |  1990-12-28  |  4KB

  1. From: david@WUBIOS.WUSTL.EDU (David J. Camp)
  2. Newsgroups: alt.sources
  3. Subject: [comp.laser-printers] Input Filter to Solve PostScript Protocol Bug
  4. Message-ID: <1990Jul18.200428.5809@math.lsa.umich.edu>
  5. Date: 18 Jul 90 20:04:28 GMT
  6.  
  7. Archive-name: igixon/04-Jul-90
  8. Original-posting-by: david@WUBIOS.WUSTL.EDU (David J. Camp)
  9. Original-subject: Input Filter to Solve PostScript Protocol Bug
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.laser-printers.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. /*
  16. After receiving a QMS-810/Turbo, we learned that there is an error in
  17. the xon/xoff protocol that causes data to be lost.  The explanation that
  18. we have heard is that the printer sends xoff, but fails to send xon.
  19. When the wait timeout expires, it dumps the job and sends xon.
  20.  
  21. The following is a Unix input filter that circumvents this bug.  
  22.  
  23. Please report problems directly to me, since I am way behing in reading
  24. mailing lists.  -David-
  25.  
  26. /* igixon.c -- input filter that accomodates erroneous flow control */
  27. /*
  28. Internet: david%wubios@wugate.wustl.edu     ^      Mr. David J. Camp
  29. uucp: ...!uunet!wugate!wubios!david       < * >    Box 8067, Biostatistics
  30. Washington University (314) 36-23635        v      660 South Euclid Avenue
  31. "Depend on God, who has dominion."                 Saint Louis, MO 63110
  32. */
  33.  
  34. #define TIMEOUTSEC 280L /* Note printer wait timeout must be 300 */
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <sys/types.h>
  39. #include <sys/timeb.h>
  40. #include <sys/time.h>
  41.  
  42. #ifndef TTYNAME
  43. *** ERROR use -DTTYNAME=\"/dev/tty??\"
  44. #endif
  45.  
  46. char * ttyname ();
  47.  
  48. void main (argc, argv)
  49. int argc;
  50. char * argv [];
  51.  
  52. {
  53. int c;
  54. long readfds;
  55. struct timeval timeout;
  56. time_t the_time;
  57. int x,y;
  58. FILE * outfile;
  59. char * tty_name;
  60. FILE * console;
  61.  
  62. nice (4);
  63. console = popen ("/usr/ucb/logger -p daemon.notice -f -", "w");
  64. if (console != NULL)
  65.     setbuf (console, NULL);
  66. #ifdef VERBOSE
  67. if (console != NULL)
  68.     fprintf (console, "igixon tty=%s\n", TTYNAME);
  69. #endif
  70. if (NULL == (outfile = freopen (TTYNAME, "r+", stdout)))
  71.     {
  72.     if (console != NULL)
  73.         fprintf (console, "Cannot access port.\n");
  74.     exit (3);
  75.     }
  76. setbuf (outfile, NULL);
  77. system ("/usr/bin/stty 9600 raw -ixon -ixoff -parity ignpar istrip clocal -crtscts tabs -icanon -cstopb -opost -echo -echoe");
  78. c = fgetc (stdin);
  79. while (!feof (stdin))
  80.     {
  81.     timeout.tv_sec = 0L;
  82.     timeout.tv_usec = 0L;
  83.     readfds = (1 << fileno (outfile));
  84.     while (select (fileno(outfile) + 1, &readfds, NULL, NULL, &timeout))
  85.         {
  86.         clearerr (outfile);
  87.         x = fgetc (outfile);
  88.         if (console != NULL && (x >= 040 || x == 012))
  89.             fprintf (console, "%c", x);
  90.         if (x == 023)
  91.             {
  92.             the_time = time (NULL) + TIMEOUTSEC;
  93.             timeout.tv_sec = TIMEOUTSEC;
  94.             timeout.tv_usec = 0L;
  95.             readfds = 1 << fileno (outfile);
  96.             while (select (fileno (outfile) + 1, &readfds, NULL, NULL, &timeout))
  97.                 {
  98.                 clearerr (outfile);
  99.         y = fgetc (outfile);
  100.                 if (console != NULL && (x >= 040 || x == 012))
  101.                     fprintf (console, "%c", y);
  102.                 if (y == 021)
  103.                     break;
  104.                 else
  105.                     {
  106.                     timeout.tv_sec = the_time - time (NULL);
  107.                     timeout.tv_usec = 0L;
  108.                     if (timeout.tv_sec < 0L)
  109.                         break;
  110.                     }
  111.                 }
  112.             }
  113.         timeout.tv_sec = 0L;
  114.         timeout.tv_usec = 0L;
  115.         readfds = 1 << fileno (outfile);
  116.         }
  117.     fputc (c, outfile);
  118.     c = fgetc (stdin);
  119.     }
  120. fprintf (outfile, " \n\004");
  121. outputwait (fileno(outfile));
  122. }
  123.  
  124. #include <sgtty.h>
  125.  
  126. outputwait(fd)
  127. int fd;
  128.  
  129. {
  130. int outchars;
  131.  
  132. while(ioctl(fd, TIOCOUTQ, &outchars) == 0 && outchars > 0)
  133.     {
  134.     sleep(1);
  135.     }
  136. }
  137.