Trailing-Edge
-
PDP-10 Archives
-
decuslib10-08
-
43,50512/tablel.b36
There are no other files named tablel.b36 in the archive.
MODULE TABLELOOK=
!Search a command table
BEGIN
!
! Conditionals
!
COMPILETIME FTKLUDGE=1;
!
! Table of Contents
!
FORWARD ROUTINE
TABLELOOK, !Find an entry in a dispatch table
CMD_ENTRY_CHECK;
!
! REQUIRE & LIBRARY Declarations
!
LIBRARY 'MACS';
!
! Version
!
THIS_IS[TABLELOOK] VERSION [1] EDIT [3] DATE[8,MAY,78]
!
! Literals & FIELD defs
!
LITERAL CMD_NOT_FOUND=0, CMD_AMBIGUOUS=1;
FIELD CMD_FIELDS=
SET
CMD_TEXT_ADDR=[0,18,18,0], !Addr of ASCIZ string to match
CMD_VALUE=[0,0,18,0] !Value of command (usually routine addr)
TES;
!
! Routines
!
GLOBAL ROUTINE TABLELOOK(TBL,STR)=
!Routine to find an entry in TBL for which STR is a unique abbreviation
!Arguments:
!TBL: A command table (TOPS-20 format)
!STR: Address of an ASCIZ string
!Returns:
! Address of entry in table if found uniquely, or
! 0 if entry is not found
! 1 if entry is ambiguous
BEGIN
LOCAL TPTR, !Byte pointer to command we are checking
CMDIMAX; !Addr of last entry in command table
CMDIMAX=.(.TBL)<18,18>;
%IF FTKLUDGE
%THEN IF .CMDIMAX EQL 0
THEN CMDIMAX=..TBL;
%FI
CMDIMAX=.CMDIMAX+.TBL;
INCR CMDI FROM (.TBL+1) TO .CMDIMAX DO
BEGIN
LOCAL TC, !Character from table
SC; !Character from user's string
CMD_ENTRY_CHECK(.STR,.CMDI,TC,SC); !See if there is a match
IF .SC EQL 0 THEN !An abbreviation?
BEGIN
IF .TC EQL 0 THEN RETURN .CMDI; !Win if we read the whole table string
IF .CMDI EQL .CMDIMAX THEN RETURN .CMDI; !No ambig check off end
CMD_ENTRY_CHECK(.STR,.CMDI+1,TC,SC);
IF ((.SC EQL 0) OR (.TC EQL 0)) THEN RETURN CMD_AMBIGUOUS;
!More than one match
RETURN .CMDI
END
END;
RETURN CMD_NOT_FOUND; !Not in the table at all
END;
ROUTINE CMD_ENTRY_CHECK(CMD,ADDR,TC,SC)=
!Local routine to scan a single entry in the table
BEGIN
MAP ADDR: REF BLOCK FIELD(CMD_FIELDS);
LOCAL TPTR; !Pointer to table entry
LOCAL SPTR; !Pointer to user's string
SPTR=CH$PTR(.CMD);
TPTR=CH$PTR(.ADDR[CMD_TEXT_ADDR]);
WHILE ((.SC=CH$RCHAR_A(SPTR)) EQL (.TC=CH$RCHAR_A(TPTR))) DO
(IF ..TC EQL 0 THEN RETURN)
END;
END ELUDOM