Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-05 - 43,50337/23/menu.sim
There is 1 other file named menu.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-A/-Q/-I/-D);
    ! The MENU procedure is designed to be used in validity checks
    ! at MENU-like command requests.
    !
    ! The MENU procedure will check for nonambiguous
    ! correspondance between T and the text array TABLE elements.
    ! (Note that an exact match will allways be accepted, even if it is a
    ! substring of another table element.) The table must contain
    ! upper case letters only with no trailing blanks. The input
    ! may have lower case letters.
    ! If no match is found, I will return 0.
    ! If T is ambiguous, I returns -1 else
    ! the table matching index will be returned.
    ! An example:
    !
    ! BEGIN   TEXT ARRAY menu[1:5];
    !     INTEGER index;
    !     BOOLEAN ok;
    !     TEXT t;
    !
    !     menu[1]:- Copy("STOP");
    !     menu[2]:- Copy("START");
    !     menu[3]:- Copy("END");
    !     menu[4]:- Copy("ENDURE");
    !     menu[5]:- Copy("EXIT");
    !
    !     t:- <... input ...>;
    !     ok:= menu(t,index,menu,5);
    !
    ! OK will become TRUE if T is equal to
    !
    ! START	(INDEX =  2)
    ! start	(INDEX =  2)
    ! Sta	(INDEX =  2)
    ! sto	(INDEX =  1)
    ! enD	(INDEX =  3)
    ! endure	(INDEX =  4)
    ! endu	(INDEX =  4)
    !
    ! and FALSE for
    !
    ! S		(INDEX = -1)
    ! ST	(INDEX = -1)
    ! x		(INDEX =  0)
    ! e		(INDEX = -1)
    ! en	(INDEX = -1)
    ;
    EXTERNAL TEXT PROCEDURE upcase;
    BOOLEAN PROCEDURE menu(t,i,table,n);
    NAME i;   TEXT t;   TEXT ARRAY table;   INTEGER i,n;
    BEGIN   TEXT u;   INTEGER j,k,hit;

	! Checking the array index bounds: ;
	OPTIONS(/A);   u:- table[1];   u:- table[n];;   OPTIONS(/-A);
	u:- upcase(t.Strip);

	FOR j:= 1 STEP 1 UNTIL n DO
	IF u = table[j] THEN
	BEGIN   hit:= 1;   k:= j;   GO TO ready  END ELSE
	IF u.Length < table[j].Length THEN
	BEGIN
		IF u = table[j].Sub(1,u.Length) THEN
		BEGIN   k:= j;   hit:= hit + 1   END
	END;

	ready:
	menu:= hit = 1;
	i:= IF hit = 1 THEN k ELSE Sign(-hit)

    END of menu;