;
;This script is a very rudimentary dialing directory. It reads
;lines from TELNO.TXT, which can be anywhere in the set PATH.
;
:main
	unattended 1
	jmp enter
;
;This is the main search loop. Its as close to the start of the file
;so that it will run as fast as possible; the JMP instructions are
;very slow because they search the file from the beginning! The IF
;instruction compares the given string in &1 against the contents 
;of the shift register, &S.
;
:search
	fread
	jerror not-found
	if "&1" dial
	jmp search
;
;Set the baud rate and dial the number found. If it comes back
;connected, execute the signon script for this number, if any.
;
:dial
	fclose
	message "Name:&1  Phone:&2  Speed:&3"
	&b= &3
	call dial "&2"
	jerror end
	&s= &4
	if "" end
	call "&4" "&5" "&6"
	jmp end
;
;Check for the presence of the dialing directory, then ask for
;the name of the system to call. The name of the system to call
;is left in the Shift Register, &S. Entering a blank name ends
;the script execution.
;
:enter
	fclose
	fopen "telno.txt"
	jerror badfile
	input "Call who? [*=browse >=display]"
	&s= &1
	if "" end
	if "*" browse
	if ">" list
	jmp search
;
;Browse through the directory, ask Y or N at each number, if Y, dial it
;immediately.
;
:browse
	fread
	jerror enter
	ask "This one?  Name:&1  Phone:&2  Speed:&3"
	jerror dial
	jmp browse
;
;Can't find the directory file; ask to create a new one. No means
;just abort the script.
;
:badfile
	ask "No dialing directory TELNO.TXT; create a new one"
	jerror nf0
	jmp end
;
;Name not found; ask if we should add it to the directory. If not,
;go back and ask the "dial who" question again.
;
:not-found
	ask "&s isn't in the directory, want to add it?"
	jerror nf1
	jmp enter
:nf0
	fnew "telno.txt"
:nf1
	input "NAME  NUMBER  SPEED                "
	ask "OK?  Name:\"&1\" Phone:\"&2\" Speed:\"&3\""
	jerror nf2
	jmp nf1
:nf2
	push &1
	push &2
	push &3
:nf2a
	input "SCRIPT TO USE AND ANY ARGUMENTS (name, etc)    "
	ask "OK?  Script:\"&1\"  ARG1:\"&2\"  ARG2:\"&3\""
	jerror nf3
	jmp nf2a
:nf3
	&4= &1
	&5= &2
	&6= &3

	pop &3
	pop &2
	pop &1

	fwrite
	jmp enter
:end
	fclose
