home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ARCTV26B.ZIP / CINPUT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-01-04  |  1.9 KB  |  113 lines

  1.  
  2. {$i prodef.inc}
  3.  
  4. unit CInput;
  5.  
  6. interface
  7.  
  8. Uses
  9.   Dos,
  10.   MiniCrt,
  11.   Tools;
  12.  
  13. var
  14.    linenum: integer;
  15.  
  16. procedure disp(msg:  longstring);
  17. procedure newline;
  18. procedure displn(msg:  longstring);
  19. procedure input(var line:  longstring;
  20.                 maxlen:    integer);
  21.  
  22.  
  23. implementation
  24.  
  25. var
  26.    stdout: text;
  27.  
  28.  
  29. (* ------------------------------------------------------------ *)
  30. procedure disp(msg:  longstring);
  31. begin
  32.    write(stdout,msg);
  33. end;
  34.  
  35. procedure newline;
  36. begin
  37.    flush(stdout);
  38.    disp(^M^J);
  39.    inc(linenum);
  40. end;
  41.  
  42. procedure displn(msg:  longstring);
  43. begin
  44.    disp(msg);
  45.    newline;
  46. end;
  47.  
  48.  
  49. (* ------------------------------------------------------------ *)
  50. procedure input(var line:  longstring;
  51.                 maxlen:    integer);
  52. var
  53.    c:     char;
  54.  
  55. begin
  56.    linenum := 1;
  57.    line := '';
  58.  
  59.    repeat
  60.       flush(stdout);
  61.       c := readkey;
  62.  
  63.       case c of
  64.          ' '..#126:
  65.             if maxlen = 0 then
  66.             begin
  67.                line := c;
  68.                disp(c);
  69.                c := ^M;    {automatic CR}
  70.             end
  71.             else
  72.  
  73.             if LEN(line) < maxlen then
  74.             begin
  75.                if (wherex > 78) then
  76.                   newline;
  77.  
  78.                CONCAT_CHAR(line,c);
  79.                disp(c);
  80.             end
  81.             else
  82.                disp(^G^X^H' '^H);
  83.  
  84.          ^H,#127:
  85.             if LEN(line) > 0 then
  86.             begin
  87.                dec(line[0]);
  88.                disp(^H' '^H);
  89.             end
  90.             else
  91.                disp(^G);
  92.  
  93.          ^M:   ;
  94.  
  95.          ^C:   halt(88);
  96.  
  97.         else            {echo ^X with invalid inputs; might stop
  98.                          an external protocol driver that is stuck}
  99.            disp(^X^H' '^H);
  100.  
  101.       end;
  102.  
  103.    until (c = ^M);
  104.  
  105. end;
  106.  
  107.  
  108. begin
  109.    assign(stdout,'');
  110.    rewrite(stdout);
  111. end.
  112.  
  113.