home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOOL_INC.ZIP / INPUT.INC < prev    next >
Encoding:
Text File  |  1988-01-29  |  2.3 KB  |  123 lines

  1.  
  2. (*
  3.  * input.inc - library for local input and display
  4.  *             used when compiling parts of ProDOOR as local
  5.  *             (command-line) utilities.
  6.  *
  7.  * (C) 1987 Samuel H. Smith
  8.  *
  9.  *   procedure disp(msg:  longstring);
  10.  *   procedure newline;
  11.  *   procedure displn(msg:  longstring);
  12.  *   procedure input(var line:  longstring;
  13.  *                   maxlen:    integer);
  14.  *
  15.  *)
  16.  
  17. var
  18.    linenum: integer;
  19.  
  20. {$IFDEF TRACEIO}
  21. var
  22.    tracefd: text;
  23. const
  24.    traceopen: boolean = false;
  25. {$ENDIF}
  26.  
  27.  
  28. (* ------------------------------------------------------------ *)
  29. procedure disp(msg:  longstring);
  30. begin
  31.    write(output,msg);
  32.  
  33. {$IFDEF TRACEIO}
  34.    if not traceopen then
  35.    begin
  36.       assign(tracefd,'trace.out');
  37.       rewrite(tracefd);
  38.       traceopen := true;
  39.    end;
  40.  
  41.    write(tracefd,msg);
  42. {$ENDIF}
  43.  
  44. end;
  45.  
  46.  
  47. procedure newline;
  48. begin
  49.    flush(output);
  50.    disp(^M^J);
  51.    inc(linenum);
  52. end;
  53.  
  54. procedure displn(msg:  longstring);
  55. begin
  56.    disp(msg);
  57.    newline;
  58. end;
  59.  
  60.  
  61. (* ------------------------------------------------------------ *)
  62. procedure input(var line:  longstring;
  63.                 maxlen:    integer);
  64. var
  65.    c:     char;
  66.  
  67. begin
  68.    linenum := 1;
  69.    line := '';
  70.  
  71.    repeat
  72.       flush(output);
  73.       c := readkey;
  74.  
  75.       case c of
  76.          ' '..#126:
  77.             if maxlen = 0 then
  78.             begin
  79.                line := c;
  80.                disp(c);
  81.                c := ^M;    {automatic CR}
  82.             end
  83.             else
  84.  
  85.             if length(line) < maxlen then
  86.             begin
  87.                if (wherex > 78) then
  88.                   newline;
  89.  
  90.                CONCAT_CHAR(line,c);
  91.                disp(c);
  92.             end
  93.             else
  94.                disp(^G^X^H' '^H);
  95.  
  96.          ^H,#127:
  97.             if length(line) > 0 then
  98.             begin
  99.                dec(line[0]);
  100.                disp(^H' '^H);
  101.             end
  102.             else
  103.                disp(^G);
  104.  
  105.          ^M:   ;
  106.  
  107.          ^C:   begin
  108.                    displn('^C');
  109.                    halt(99);
  110.                end;
  111.  
  112.         else            {echo ^X with invalid inputs; might stop
  113.                          an external protocol driver that is stuck}
  114.            disp(^X^H' '^H);
  115.  
  116.       end;
  117.  
  118.    until (c = ^M);
  119.  
  120. end;
  121.  
  122.  
  123.