home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / LIB / RAWREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-09  |  2.8 KB  |  156 lines

  1. /* rawread - read in raw mode and perform special processing
  2.  
  3.     Copyright (c) 1984 by JMI Software Consultants, Inc.
  4. */
  5. #include "acom.h"
  6. #include "host.h"
  7. #include "rrd.h"
  8. #define BUFSIZE 512
  9.  
  10.  
  11. IMPORT RR rdc;
  12. LOCAL TEXT rawbuf[BUFSIZE] = {0}; /* raw data resides here */
  13. LOCAL TEXT *s = rawbuf;             /* pointer to next character in rawbuf */
  14. LOCAL TEXT *eob = rawbuf;         /* pointer past last character in rawbuf */
  15. LOCAL TEXT stdecho[2] = {0};     /* buffer for echoing input character */
  16. LOCAL BOOL backslash = NO;
  17.  
  18. INT rawread(fd, buf, len, mode)
  19.     INT fd;         /* file descriptor */
  20.     TEXT *buf;     /* pointer to a buffer where input data will be put */
  21.     INT len;     /* maximum number of characters to be input */
  22.     BITS mode;     /* special processing modes (see rrd.h) */
  23.     {
  24.     FAST TEXT c, *t;
  25.     FAST INT l;
  26.     INT n;
  27.     BOOL skip;
  28.     TEXT *echo;
  29.     REGVAL ri, ro;
  30.  
  31.     t = buf;
  32.     l = 0;
  33.     FOREVER
  34.         {
  35.         skip = NO;
  36.         if (s >= eob)
  37.             {
  38.             ri.dx = 0x00ff;
  39.             ri.ax = 0x0600;
  40.             if (!(mode & RR_WAIT))
  41.                 {
  42.                 if (kbhit() == 0)
  43.                     break;
  44.                 intdos(&ri, &ro);
  45.                 }
  46.             else
  47.  
  48.                 FOREVER
  49.                     {
  50.                     if (kbhit() != 0)
  51.                         {
  52.                         intdos(&ri, &ro);
  53.                         break;
  54.                         }
  55.                     }
  56.             s = rawbuf;
  57.             n = 0;
  58.             rawbuf[n++] = ro.ax & 0x00ff;
  59.             while (n <= BUFSIZE)
  60.                 {
  61.                 if (kbhit() == 0)
  62.                     break;
  63.                 intdos(&ri, &ro);
  64.                 rawbuf[n++] = ro.ax & 0x00ff;
  65.                     }
  66.             eob = rawbuf + n;
  67.             }
  68.         c = *s++;
  69.         if (mode & RR_7BIT)
  70.             c &= 0x7f;
  71.         if (mode & RR_CRMOD && c == '\r')
  72.             c = '\n';
  73.         if (mode & RR_UCASE)
  74.             c = toupper(c);
  75.         if (mode & RR_LCASE)
  76.             c = tolower(c);
  77.         stdecho[0] = c;
  78.         echo = stdecho;
  79.         if (c == '\n')
  80.             echo = "\r\n";
  81.         if (mode & RR_ERASE && c == rdc.rr_erase)
  82.             {
  83.             echo = "\b \b";
  84.             if (!backslash)
  85.                 {
  86.                 skip = YES;
  87.                 if (--t < buf)
  88.                     {
  89.                     ++t;
  90.                     echo = "";
  91.                     }
  92.                 else
  93.                     --l;
  94.                 }
  95.             }
  96.         if (mode & RR_KILL && c == rdc.rr_kill)
  97.             {
  98.             if (!backslash)
  99.                 {
  100.                 skip = YES;
  101.                 t = buf;
  102.                 l = 0;
  103.                 }
  104.             echo = "\r\n";
  105.             }
  106.         if (mode & RR_NECR && (c == '\r' || c == '\n'))
  107.             echo = "";
  108.         if (mode & RR_INTR && c == rdc.rr_intr)
  109.             {
  110.             exit();
  111.             break;
  112.             }
  113.         if (mode & RR_QUIT && c == rdc.rr_quit)
  114.             {
  115.             exit();
  116.             break;
  117.             }
  118.         if (mode & RR_EOT && c == rdc.rr_eot)
  119.             {
  120.             l = 0;
  121.             break;
  122.             }
  123.         if (mode & RR_BSLSH && c == '\\')
  124.             {
  125.             backslash = YES;
  126.             continue;
  127.             }
  128.         if (mode & RR_ECHO)
  129.             {
  130.             if (backslash)
  131.                 write(1, "\\", 1);
  132.             write(1, echo, strlen(echo));
  133.             }
  134.         if (backslash)
  135.             {
  136.             *t++ = '\\';
  137.             if (++l >= len)
  138.                 {
  139.                 --s;
  140.                 break;
  141.                 }
  142.             backslash = NO;
  143.             }
  144.         if (!skip)
  145.             {
  146.             *t++ = c;
  147.             ++l;
  148.             }
  149.         if (mode & RR_LINE && c == '\n')
  150.             break;
  151.         if (l >= len)
  152.             break;
  153.         }
  154.     return (l);
  155.     }
  156.