tldm-universe/Ardent/UV/BP/GET.TOKEN.B
2024-09-09 17:51:08 -04:00

158 lines
6.0 KiB
Brainfuck
Executable File

Subroutine GET.TOKEN.B(delay.interval, sequential.delay.time, es.delay,
alpha.size, mat alpha.strings, mat alpha.codes,
escape.code, mnemo.code, unknown.code,
mnemo.count, menu.mnemonic,
left.over, input.code, mnemos)
$INCLUDE UNIVERSE.INCLUDE TERMINFO
******************************************************************************
*
* Routine TO pull token off the type-ahead buffer
*
* Module %M% Version %I% Date %H%
*
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
* This is unpublished proprietary source code of Ardent Software Inc.
* The copyright notice above does not evidence any actual or intENDed
* publication of such source code.
*
*******************************************************************************
*
* Maintenence log - insert most recent change descriptions at top
*
* Date.... GTAR# WHO Description.........................................
* 10/14/98 23801 SAP Change copyrights.
* 05/13/91 8345 DTM Changed print to tprint
* 02/10/91 7673 DTM Changed the logic in program
* 08/29/90 7393 DPB Turned cursor off insead of putting it at 0,0
* 08/24/90 7393 DPB Fixed bug with escape.code problems.
* 6/28/90 7236 DSC New Cataloged routine
*
*******************************************************************************
*****************************************************************************
* This subroutine takes input characters, finds first token. Also IF the token
* is a Mnemonic, THEN it notes its associated field number.
* If the type-ahead buffer is empty, this routine waits FOR at least one
* character, but takes characters until time out.
*****************************************************************************
*****************************************************************************
* Arguments TO the function are:
* delay.interval - The length in milliseconds of naps TO take
* while waiting FOR timeouts
*
* sequential.delay.time - The length of nap TO take beFORe
* assuming a complete keystroke has been received
*
* es.delay - The length of nap TO take beFORe
* assuming an escape (special) character has been
* received
*
* alpha.size - The size of the the alphabet vectors
*
* alpha.strings - Vector of tokens that are TO be recognized
* This vector must be stored in decreasing size,
* and length of longest string is in element 0
*
* alpha.codes - Value TO be associated with each token
*
* escape.code - The number of element which is TO be treated
* specially. The string FOR this element must be
* of length 1. TypiCALLy this is a character which
* is a token when it appears alone, but which may
* start other strings. In most cases this will be
* the character ESCAPE (char 27).
*
* mnemo.code - The code TO be returned IF a mnemonic is found
*
* unknown.code - The code TO be returned IF no match is found
*
* mnemo.count - The number of mnemonics TO be accepted
*
* menu.mnemonic - Dynamic array of single letters which are
* tokens. There must be exactly mnemo.count mnemonics
* provided.
*
* left.over - Characters which were taken off the type-ahead
* buffer but not allocated TO any token yet. This
* is both input and output.
*
* input.code - The matching element code of alpha.codes which
* corresponds TO the token found, or mnemo.code or
* unknown.code.
*
* mnemos - The number the mnemonic that matched, or the
* character which matched nothing.
*
*****************************************************************************
id = "%W%"
*****************************************************************************
* This is a complicated problem. An Escape is defined as an Escape
* followed by nothing else. For how long? That is a halting problem.
* Due TO network propagation delays, must allow at least es.delay.
* An Escape-sequence is an Escape followed by certain valid combinations
* in that same 2 seconds. Any other series of characters followed by a
* shorter delay (sequential.delay.time) is TO be analyzed,
* and is either valid or invalid.
*****************************************************************************
*****************************************************************************
* No left-over characters. Wait FOR at least one character, and
* accept as many as are in type-ahead buffer already (up TO the
* maximum size sequence)
*****************************************************************************
IF left.over = "" THEN
TPRINT @(0,0):CURSOR.INVISIBLE ;* Put the cursor in this normal place
CALL *GET.TA.BUF.B(1,alpha.strings(0),0,0,new.in)
in.buff = new.in
END
ELSE in.buff = left.over
up.in.buff=UPCASE(in.buff[1,1])
FOR i = 1 TO mnemo.count
IF up.in.buff = menu.mnemonic<i> THEN
input.code = mnemo.code
mnemos = i
GOTO got.a.single.char.token
END
NEXT i
*****************************************************************************
* Could this be an Escape character?
*****************************************************************************
mnemos=in.buff[1,1]
flag=0
FOR i = 1 TO alpha.size
IF alpha.strings(i)#"" THEN
IF in.buff[1,1] = alpha.strings(i)[1,1] THEN
in.len=LEN(in.buff)
al.len=LEN(alpha.strings(i))
IF in.len < al.len AND flag#1 THEN
TPRINT @(0,0):CURSOR.INVISIBLE
CALL *GET.TA.BUF.B(0,al.len-in.len,delay.interval,es.delay,new.in)
in.buff:=new.in
flag=1
END
IF in.buff[1,al.len] = alpha.strings(i) THEN
left.over=in.buff[1+al.len,999]
IF i=escape.code AND left.over # "" THEN GOTO is.illegal
input.code=alpha.codes(i)
GOTO got.a.token
END
END
END
NEXT i
*****************************************************************************
* Illegal character was received...
*****************************************************************************
is.illegal:
input.code = unknown.code
got.a.single.char.token:
left.over = in.buff[2,999] ;* TO END of string and beyond
got.a.token:
TPRINT @(0,0):CURSOR.VISIBLE:CURSOR.NORMAL
RETURN