**** NS.CMD - COMMAND FILE TO PROMPT FOR AND FIND A PERSON BY NAME. ****
**** version 1.0

STORE T TO TRUE
STORE 0 TO CHOICE

**** MAIN LOOP OF SUBROUTINE. 
*	LOOP UNTIL HE CHOOSES ONE OF THE NAMES DISPLAYED OR SAYS HE 
*	WANTS TO QUIT.

DO WHILE TRUE	

	*** ASK FOR LAST NAME

  	STORE "                         " TO LNAME
	@ 22,0
	@ 23,0
	@ 22,0 SAY 'ENTER ALL OR PART OF LAST NAME OF PERSON TO FIND (Q=>QUIT)' GET LNAME PICTURE '!!!!!!!!!!!!!!!!!!!!!!!!!'
	READ

	IF TRIM(LNAME) = "Q" .OR. $(LNAME,1,1)=" "
		STORE F TO TRUE
	ENDIF
	SET INDEX TO NAME
	STORE T TO FIRST

	**** LOOP2 OF SUBROUTINE

	DO WHILE TRIM(LNAME) <> "Q" .AND. $(LNAME,1,1)<>" "

  		STORE "               " TO FNAME
		@ 23,0 SAY 'ENTER A FIRST NAME TOO IF YOU WANT' GET FNAME PICTURE '!!!!!!!!!!!!!!!'
		READ
	
		** BUILD THE LOOKUP KEY. FILE KEY IS : LAST:NAME + FIRST:NAME. 
		*	NOTE THAT THE LAST NAME IS PADDED WITH SPACES TO A LENGTH OF 25.

 		IF $(FNAME,1,1) = " "
			STORE TRIM(LNAME) TO NAMEKEY
		ELSE 
			STORE LNAME+TRIM(FNAME) TO NAMEKEY
		ENDIF

		STORE 1 TO MAX
		STORE 99 TO CHOICE


		**** LOOP3 OF SUBROUTINE.
		*	IT DISPLAYS THE NAMES OF PEOPLE WHO MATCH THE NAME HE GAVE.
		*	AND ALLOWS THE USER TO SELECT THE ONE HE WANTS TO DISPLAY.

		DO WHILE MAX

			STORE 0 TO MAX
			ERASE
			SET INTENSITY OFF

			**** LOOP4 OF SUBROUTINE.
			* IT FILLS UP THE SCREEN WITH PEOPLE WHOSE NAME MATCHES THE ONE
			* HE GAVE.

			DO WHILE CHOICE = 99


				IF FIRST
					STORE F TO FIRST
					FIND &NAMEKEY
				ELSE
					SKIP
				ENDIF

    				IF #<>0 .AND. (.NOT. EOF) .AND. NAMEKEY=$(!(LAST:NAME+FIRST:NAME),1,LEN(NAMEKEY))
     					STORE MAX+1 TO MAX
     					IF MAX>9
      						STORE STR(MAX,2) TO MAXS
    	 				ELSE
      						STORE STR(MAX,1) TO MAXS
     					ENDIF
					STORE REF:NO TO REF&MAXS
					@ &MAXS,0 SAY MAXS+" "+TRIM(LAST:NAME)+', '+TRIM(FIRST:NAME)+" b: "+$(STR(BIRTH:DATE,8),1,4)+" ref= "+REF:NO
				ELSE
					STORE 0 TO CHOICE
				ENDIF
		
				IF MAX = 20
					STORE 0 TO CHOICE
				ENDIF 	
	
			ENDDO

			SET INTENSITY ON				
			
			IF MAX
				STORE -1 TO CHOICE
				DO WHILE (CHOICE<0 .OR. CHOICE>MAX) .AND. CHOICE<>99
					@ 22,0 SAY 'SELECT A PERSON (0=QUIT, 99=CONTINUE DISPLAYING)' GET CHOICE PICTURE '99'  
					READ
				ENDDO
				IF CHOICE <> 0 .AND. CHOICE <> 99
					STORE 0 TO MAX
					STORE "Q" TO LNAME
					STORE F TO TRUE
				ELSE
					IF CHOICE=0
						STORE 0 TO MAX
					ELSE
						ERASE
					ENDIF
				ENDIF
			ENDIF


		ENDDO

	STORE "Q" TO LNAME

	ENDDO

ENDDO

**** DISPLAY EITHER THE PERSON HE CHOSE OR OR LAST PERSON DISPLAYED BEFORE HE
*	SELECTED OPTION N IF AFTER ALL HE DIDN'T CHOOSE ANYONE.

SET INDEX TO REF,FATHER,MOTHER,NAME
ERASE
IF CHOICE > 0 .AND. CHOICE <> 99
	IF CHOICE>9
		STORE STR(CHOICE,2) TO CHOICES
	ELSE
		STORE STR(CHOICE,1) TO CHOICES
	ENDIF	
	STORE REF&CHOICES TO M1
	STORE M1 TO CURPER
	DO EXPLORE1	
ELSE
	IF VAL(CURPER) <> 0
		DO EXPLORE1
	ENDIF
ENDIF
*** LOOP TO RELEASE MEMORY VARIBLES. ***
STORE 1 TO MAX
DO WHILE MAX<21
	IF MAX<10
		STORE STR(MAX,1) TO MAXS
	ELSE
		STORE STR(MAX,2) TO MAXS
	ENDIF
	RELEASE REF&MAXS
	STORE MAX+1 TO MAX
ENDDO

RETURN  