home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols100 / vol144 / tr1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-13  |  1.4 KB  |  61 lines

  1. #include <bdscio.h>
  2. #include "sqcom.h"
  3. #include "sq.h"
  4.  
  5. /* First translation - encoding of repeated characters
  6.  * The code is byte for byte pass through except that
  7.  * DLE is encoded as DLE, zero and repeated byte values
  8.  * are encoded as value, DLE, count for count >= 3.
  9.  */
  10.  
  11. init_ncr()    /*initialize getcnr() */
  12. {
  13.     state = NOHIST;
  14. }
  15.  
  16. int
  17. getcnr(iob)
  18. struct _buf *iob;
  19. {
  20.     switch(state) {
  21.     case NOHIST:
  22.         /* No relevant history */
  23.         state = SENTCHAR;
  24.         return lastchar = getc_crc(iob);   
  25.     case SENTCHAR:
  26.         /* Lastchar is set, need lookahead */
  27.         switch(lastchar) {
  28.         case DLE:
  29.             state = NOHIST;
  30.             return 0;    /* indicates DLE was the data */
  31.         case EOF:
  32.             return EOF;
  33.         default:
  34.             for(likect = 1; (newchar = getc_crc(iob)) == lastchar && likect < 255; ++likect)
  35.                 ;
  36.             switch(likect) {
  37.             case 1:
  38.                 return lastchar = newchar;
  39.             case 2:
  40.                 /* just pass through */
  41.                 state = SENDNEWC;
  42.                 return lastchar;
  43.             default:
  44.                 state = SENDCNT;
  45.                 return DLE;
  46.             }
  47.         }
  48.     case SENDNEWC:
  49.         /* Previous sequence complete, newchar set */
  50.         state = SENTCHAR;
  51.         return lastchar = newchar;
  52.     case SENDCNT:
  53.         /* Sent DLE for repeat sequence, send count */
  54.         state = SENDNEWC;
  55.         return likect;
  56.     default:
  57.         puts("Bug - bad state\n");
  58.         exit(1);
  59.     }
  60. }
  61.