home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PASCAL / CONSOLE.ZIP / CONSOLE.DOC next >
Encoding:
Text File  |  1989-10-19  |  10.1 KB  |  237 lines

  1. PROCEDURE
  2.  
  3.         console         (string input with Wordstar editing)
  4.         
  5. USAGE
  6.  
  7.         To obtain a string of characters from the console in any arbitrary
  8.         length up to a maximum of 80 characters.  Provides ability to set
  9.         the maximum length acceptable (for field length control), and to
  10.         return upline, downline, ^Q and escape responses by the operator
  11.         for customized reaction if needed.
  12.         
  13. FUNCTION
  14.  
  15.         Full line-oriented editing features are supported with Wordstar
  16.         compatible command characters.
  17.         
  18.         The following control characters are recognized:
  19.         
  20.                 ^A = backward by words (curser positioned at first
  21.                      letter).
  22.                 ^S = backspace one character.
  23.                 ^D = forespace one character.
  24.                 ^F = forward by words (curser positioned at first
  25.                      letter).
  26.                 ^G = single character delete.
  27.                 ^V = single (blank) character inserted. (NOTE: non-
  28.                      standard from Wordstar response -- see below.)
  29.                tab = non-destructive forward move of 5 characters.
  30.         left arrow = same as ^S.
  31.        right arrow = same as ^D.
  32.            rub-del = destructive overwriting backspace.
  33.          backspace = backspace.
  34.               <CR> = terminate input.  Not echoed to the screen.  Curser
  35.                      will remain where it was when carriage return made.
  36.             escape = terminate input (quit requested).
  37.                 ^Q = terminate input (quit requested, possibly program
  38.                      abort requested).
  39.                 ^J = terminate input (up arrow requested).
  40.                 ^K = terminate input (down arrow requested).
  41.                 ^E = terminate input (Wordstar up line requested).
  42.                 ^X = terminate input (Wordstar down line requested).
  43.             
  44.         RETURNED VALUES:
  45.            On return from a call to console, your CHAR variable will
  46.            have one of five possible values:
  47.                ^J (CHR(10)) -- down arrow requested.
  48.                ^K (CHR(11)) -- up arrow requested.
  49.               <cr>(CHR(13)) -- normal return
  50.                ^Q (CHR(17)) -- control-Q entered.
  51.               esc (CHR(27)) -- escape entered.
  52.               
  53.            The value of outch on entry to procedure console is ignored.
  54.            
  55.            The integer variable "position" will point to the current
  56.            position in the string array at the time one of the five
  57.            terminating characters was entered (if the curser was at
  58.            the end of the edit line, then "position" will equal
  59.            length(editline)+1).  On entry to console, "position" is an
  60.            index into the string and determines where in the string
  61.            console believes itself to be upon entry.  Thus you may
  62.            control the starting position, if desired.  Naturally,
  63.            you must handle cursor on-screen positioning to conform
  64.            to the position value you are sending to console.  If console
  65.            is given a position value which is GREATER than the current
  66.            length of the string it is to edit (as supplied to it in
  67.            the "charcount" parameter), console will move the curser
  68.            back on the line to reach the ending position as defined
  69.            by charcount.  For example, if you send it a charcount of
  70.            10, but a position value of 15, console will assume that
  71.            the cursor is at column 15 and will move back four spaces
  72.            to conform with the defined end of string.  The curser will
  73.            be positioned at column 11 (the growing end of the edit
  74.            line), where columns are always counted 1..length(string).
  75.            
  76.            The edited string is returned in your string variable.
  77.            
  78.  
  79. EXAMPLE
  80.  
  81.  
  82.     PROGRAM demo(INPUT, OUTPUT);
  83.  
  84.     CONST
  85.       maxlength = 80; {max of string}       maxbuf = 2;
  86.            lf  = $0A; {linefeed}
  87.            bel  = 7;  {buzzer}                 nul = 0;  {harmless character}
  88.  
  89.  
  90.     VAR
  91.       bufptr, index  : INTEGER; {used to access str[bufptr, index]}
  92.       str : ARRAY[0..maxbuf] OF STRING;         up, ch : CHAR;
  93.       dummy, upvalue : INTEGER;
  94.  
  95.  
  96.     EXTERNAL PROCEDURE console(VAR outch : CHAR; VAR str : STRING;
  97.                             VAR position : INTEGER; charcount, len : INTEGER);
  98.  
  99.  
  100.     EXTERNAL FUNCTION @BDOS(func : INTEGER; parm : WORD) : INTEGER;
  101.  
  102.     {this will be used only to output a linefeed to the terminal, since
  103.      MT+ uses linefeeds for eoln indicators, it can't be written with
  104.      write(chr(lf)) statements. }
  105.  
  106.  
  107.     BEGIN {main}
  108.  
  109.       {*********************** INITIALIZATION *************************}
  110.       index := 1;    {we want to start by pointing to first character.}
  111.                       
  112.       FOR bufptr := 0 TO maxbuf DO
  113.          str[bufptr] := '';   {initialize all strings to nul lengths}
  114.          
  115.       bufptr := 0;  {to start at first field's string}
  116.       
  117.       WRITE('Please enter decimal value of your "up" character:');
  118.       READLN(upvalue);
  119.       up := CHR(upvalue);     {up arrow values vary with terminal type}
  120.       {****************************************************************}
  121.  
  122.       WRITELN;
  123.       WRITELN('Type CNTRL-Q to ABORT;     ESCAPE when FINISHED.');
  124.       WRITELN;
  125.       WRITELN('First  field:');
  126.       WRITELN('Second field:');
  127.       WRITE('Final  field: ',up,up);     {and wind up on original line}
  128.  
  129.       REPEAT
  130.         IF (ORD(ch)=11) THEN            {they asked for up arrow}
  131.  
  132.             IF bufptr > 0 THEN          {there's room to rise}
  133.                BEGIN
  134.                  WRITE(up);
  135.                  bufptr := PRED(bufptr) {and move edit up one, too}
  136.                END
  137.             ELSE WRITE(CHR(bel))        {warn them they've hit the roof}
  138.  
  139.         ELSE IF (ORD(ch)=10) OR (ORD(ch)=13) THEN    {down requested}
  140.  
  141.             IF bufptr < maxbuf THEN     {there's room to go down}
  142.               BEGIN
  143.                 dummy := @BDOS(2, WRD(lf)); {have cp/m put a linefeed}
  144.  
  145.                 {The above circuitous call is necessary to defeat MT+'s
  146.                  use of linefeeds as end of line indicators which
  147.                  makes it impossible to just write(chr(lf)). }
  148.  
  149.                 bufptr := SUCC(bufptr)
  150.               END
  151.             ELSE WRITE(CHR(bel)); {we hit the floor!}
  152.  
  153. {--> }  console(ch, str[bufptr], index, LENGTH(str[bufptr]), maxlength);
  154.  
  155.      UNTIL (ORD(ch)=27) OR (ORD(ch)=17); {escape or control-Q}
  156.  
  157.      FOR dummy := bufptr TO maxbuf + 2 DO
  158.          WRITELN;            {be sure we're two lines below data fields}
  159.  
  160.      IF (ORD(ch)=17) THEN    {they typed a ^Q to bomb out}
  161.        WRITELN('Abort requested via ^Q.')
  162.      ELSE
  163.        WRITELN('Data accepted.');
  164.    END. {main}
  165.  
  166.       A .COM file of this demo program is included in the console
  167.    library for you to try out.  Naturally, the code above is considerably
  168.    junked up by the necessity for avoiding direct curser addressing.  By
  169.    including in your standard libarary of terminal handlers a function
  170.    such as
  171.               FUNCTION at(row, column : INTEGER) : CHAR;
  172.    things are made much simpler because bufptr can be used in a single
  173.    line-addressing statement to move to the appropriate line, i.e.
  174.          WRITE(at(bufptr, index + offset);
  175.    which will handle all the necessary messy details of being where
  176.    we say we are.
  177.  
  178.  
  179. QUIRKS
  180.  
  181.         RETURN is non-standard in that
  182.                 1) It may be hit at ANY point in the line and the
  183.                    entire line is accepted and returned.  This follows
  184.                    the Wordstar philosophy of "what you see is what
  185.                    you get."  Therefore, unwanted characters behind
  186.                    the curser must be deleted via ^G before return
  187.                    is pressed.
  188.                 2) It is not echoed to the screen, so unless the
  189.                    calling program does something about it, you
  190.                    remain exactly where you were on the screen when
  191.                    return was entered.
  192.   
  193.        ^T is not supported.  This is Wordstar's word delete command.
  194.           All deletion must be done one character at a time with ^G
  195.           or the rub-delete key.
  196.  
  197.        ^F is non-standard (in the context of Wordstar).  Rather than
  198.           being a toggle on/off, it merely inserts ONE blank space
  199.           at the current curser position.  To insert multiple characters,
  200.           ^F must be pressed as many times as needed to create space.
  201.           Following that action, the new material may be typed into the
  202.           "hole" created.
  203.           
  204. FINAL NOTES
  205.  
  206.        The console.erl file included in the console.lbr file has been
  207.    compiled for 8080 code only, and hence is not optimized for Z-80
  208.    operation (a minimal difference in this case).
  209.    
  210.        I have not tried this, but MT+ claims that such .erl files can be
  211.    invoked from machine language routines.  Parameters are passed on the
  212.    stack using a 16-bit word for each parameter.  Top of stack is the
  213.    return address.
  214.        In this case you would:
  215.           PUSH (address of outch);
  216.           PUSH (address of str);
  217.           PUSH (address of position);
  218.           PUSH charcount;
  219.           PUSH len;
  220.           PUSH return-address;
  221.           CALL console;
  222.        The only other thing to beware of is that MT+ defines a string
  223.    as str[0] = length byte (0..255), str[1..length] = character array
  224.    so your string would have to match this format.
  225.        I'm pretty sure the stack would be cleaned up upon return since
  226.    a machine language routine called from Pascal has to do its own house-
  227.    cleaning before return, so I assume Pascal returns the favor.
  228.  
  229.        Let me know of any problems, if found.
  230.  
  231.    
  232.                         Patrick Wallace
  233.                         628 North Blvd.
  234.                         Baton Rouge, La. 70802
  235.  
  236.  ee¬âeDURE
  237. en ;N#à3 ■#G£$