! 17 Oct 91 - setup.cmd
!
! Devan R. Green
!
! 2/9/91   Original version
! 2/18/91  BTOS TERMnet
! 2/28/91  exitdisc
! 3/3/91   f13 - f16 support for function key combinations
! 3/4/91   if termsys line is blank, default that setting only
! 3/8/91   termsys order changed.
! 3/8/91   add termtype command (SuperDOS only)
! 3/25/91  if termsys is corrupt - default all
! 4/3/91   change for MSWin and X - added revmap, altkeys, extend, scaling
! 4/10/91  added set dimdim
! 5/7/91   added telnet: and rlogin: for nib-gn
! 6/27/91  fix nul: connect option for -gn
! 8/5/91   frozen for dos 6.2.2
! 10/17/91 added telnete: for unix colsolidated product, pty: for U3
!          new U3 part code = old NU3, NI3, NX3 combined.
!          frozen for unix 6.2.2
! 02/19/92 Added netspec 'tc' to list of available UNIX network releases
!	         Fixed problem with revdim only saving as REVERSE. (SGS) 
! 04/08/92 Fixed two non-U3 bugs:  scou3 not being dimensioned
!                                  communications sub-menu not appearing
!

! add quotes to a string

proc quote
	setv $1 '"'+trim($1)+'"'
endproc quote

! remove quotes from a string

proc unquote
	if right($1,1)='"'
		setv $1 left($1,len($1)-1)
	endi
	if left($1,1)='"'
		setv $1 right($1,len($1)-1)
	endi
endproc unquote

! change "on(off)" to "yes(no)"

proc on2yes
	if $1 = 'on'
		setv $1 'YES'
	else
		setv $1 'NO'
	endi
endproc on2yes

! change "yes(no)" to "on(off)"

proc yes2on
	if $1 = 'YES'
		setv $1 'on'
	else
		setv $1 'off'
	endi
endproc yes2on

! procedure to clear a 3 line window

proc clrwindow
	at 0,0 "                                 "
	at 1,0 "                                 "
	at 2,0 "                                 "
endproc clrwindow

! change "color" strings to "number" strings

proc col2num
	setv var '$1'
	setv color '$2'
	switch
		case color = 'BLACK'
			setv $(var) '0'
		case color = 'BLUE'
			setv $(var) '1'
		case color = 'GREEN'
			setv $(var) '2'
		case color = 'CYAN'
			setv $(var) '3'
		case color = 'RED'
			setv $(var) '4'
		case color = 'MAGENTA'
			setv $(var) '5'
		case color = 'BROWN'
			setv $(var) '6'
		case color = 'WHITE'
			setv $(var) '7'
		case color = 'GREY'
			setv $(var) '8'
		case color = 'LTBLUE'
			setv $(var) '9'
		case color = 'LTGREEN'
			setv $(var) '10'
		case color = 'LTCYAN'
			setv $(var) '11'
		case color = 'LTRED'
			setv $(var) '12'
		case color = 'LTMAGENTA'
			setv $(var) '13'
		case color = 'YELLOW'
			setv $(var) '14'
		case color = 'LTWHITE'
			setv $(var) '15'
	endswitch
endproc col2num

!  change "number" strings to "color" strings

proc num2col
	setv var '$1'
	setv number '$2'
	switch
		case number = '0'
			setv $(var) 'BLACK'
		case number = '1'
			setv $(var) 'BLUE'
		case number = '2'
			setv $(var) 'GREEN'
		case number = '3'
			setv $(var) 'CYAN'
		case number = '4'
			setv $(var) 'RED'
		case number = '5'
			setv $(var) 'MAGENTA'
		case number = '6'
			setv $(var) 'BROWN'
		case number = '7'
			setv $(var) 'WHITE'
		case number = '8'
			setv $(var) 'GREY'
		case number = '9'
			setv $(var) 'LTBLUE'
		case number = '10'
			setv $(var) 'LTGREEN'
		case number = '11'
			setv $(var) 'LTCYAN'
		case number = '12'
			setv $(var) 'LTRED'
		case number = '13'
			setv $(var) 'LTMAGENTA'
		case number = '14'
			setv $(var) 'YELLOW'
		case number = '15'
			setv $(var) 'LTWHITE'
	endswitch
endproc num2col

! set all default values 
! set comments to invalid values (to make termsys checking work)

proc setdef
setv zrem1 ''
setv zrem2 ''
setv zrem3 ''
setv zrem4 ''
setv zrem5 ''
setv zrem7 ''
setv zrem9 ''
setv zrem10 ''
setv zrem11 ''
setv zrem12 ''
setv zport '"NUL:"'
setv zbaud '9600'
setv zparity 'none'
setv zwordlen '8'
setv zstopbit '1'
setv zlockf '"'+_lockfile+'"'
setv zlockt '5400'
setv znetport ''
setv znetvt '""'
setv znetdiag '""'
setv zvidcard 'graphics'
setv zvidout 'ram'
setv zvidblink 'nobios'
setv zvidund 'none'
setv zkeyb 'int9'
setv zescloop '120'
setv zxonxoff '17,19'
setv zeofopen 'off'
setv zconsxon 'off'
setv zprot1 'xon'
if opsys()>1 and opsys()<8
	setv zcolnum '8'
else
	setv zcolnum '16'
endi
if iw
	setv zmenu 'csf1 menu'
	setv zhelp 'csf2 help'
	setv zgold 'csf3 gold'
	setv zshell 'csf4 shell'
	setv zcapt 'csf5 capture'
	setv zprint 'csf6 print'
	setv zcompose 'csf9 compose'
else
	setv zmenu 'f1 menu'
	setv zhelp 'f2 help'
	setv zgold 'f3 gold'
	setv zshell 'f4 shell'
	setv zcapt 'f5 capture'
	setv zprint 'f6 print'
	setv zcompose 'f9 compose'
endi
setv zcmd '"\^E" cmd'
setv zabort '"\^C" abort'
setv zbreak '"\^B" break'
setv zsright 'c-right scrright'
setv zsleft 'c-left scrleft'
setv zslup 'c-up scrlineup'
setv zsldn 'c-down scrlinedn'
setv zspup 'c-pgup scrpageup'
setv zspdn 'c-pgdn scrpagedn'
setv zscan 'altk scanmode'
setv znews 'af10 newsess'
setv znexts 'f10 nextsess'
setv zgotos 'cf10 gotosess'
setv zdiscs 'sf10 discsess'
setv zmode 'full'
setv zcharset 'american'
setv zpages '1'
setv zscrback '200'
setv zaddlf 'off'
setv zaddcr 'off'
setv zwrap 'on'
setv zmaskpar 'off'
setv zrevdim 'off'
setv ztabex 'off'
setv znoscroll 'off'
setv zturnchar '"\\r"'
setv zemul 'scoansi'
if iw
	setv zcoldef '14,1'
	setv zcolrev '1,14'
	setv zcolbold '-1'
	setv zcolund '-1'
	setv zcolblink '2,4'
else
	setv zcoldef '14,1'
	setv zcolrev '-1'
	setv zcolbold '-1'
	setv zcolund '-1'
	setv zcolblink '-1'
endif
setv zprinter 'disk pr#.fil overwrite flush'
setv zcapture 'disk capt#.fil append flush'
setv zprot2 'ascii'
setv zmodem 'HAYES'
setv zredial '3'
setv zddtr 'on'
setv zexitdtr 'on'
setv zdtimeout '60'
setv zdinit '"ATV1E0M1Q0S7=60\\r"'
setv zdprefix '"ATDT"'
setv zdsuffix '"\\r"'
setv zdoffhook '"ATA\\r"'
setv zdesc '"+++"'
setv zdans '"ATS0=1\\r"'
setv zdhangup '"ATHZ\\r\\r"'
setv zdok '"OK\\r\\n"'
setv zdring '"RING\\r\\n"'
setv zdconnect '"CONNECT"'
setv zcdelay '0'
setv zxprot 'termcrc'
setv zretries '10'
setv zrestart '3'
setv zcompress 'on'
setv zxferstat 'on'
setv zesc8bit 'off'
setv zaddeof 'off'
setv ztoupper 'off'
setv zwildsize '3584'
setv zldelay '0'
setv zlchar '"\\n"'
setv zitime '0'
setv zhtime '11'
setv zrtime '20'
setv zstime '10'
setv zlogfile 'term.log overwrite'
setv zlog 'off'
if opsys()=0
	setv zedit 'EDIT'
elseif opsys()=1
	setv zedit 'edlin'
elseif opsys()=9 | opsys()=11
	setv zedit 'EDIT'
elseif opsys()=8
	setv zedit 'edit'
else
	setv zedit 'vi'
endi
setv zflags '""'
setv zwru '""'
setv zwruchar '"\^E"'
setv zkermeol '_kermiteol "\\r"'
if opsys() = 11
	setv ztxwindow '_txwindow 1024'
else
	setv ztxwindow '_txwindow 0'
endi
setv ztxblk '_txblksize 0'
setv zrcvsync '_rcvsync 0'
setv zkermecho 'off'
setv zaltchk 'off'
setv zcom1base '0x3f8,4'
setv zcom2base '0x2f8,3'
setv zcom3base '0x3e8,4'
setv zcom4base '0x2e8,3'
setv zcom5base '0x2e8,4'
setv zcom6base '0x2e0,3'
setv zblock 'off'
setv zdo 'noscript'
setv zbsdel 'on'
setv zexitdisc 'off'
setv zterm 'WYSE50'
setv zrevmap 'on'
setv zaltkeys 'off'
setv zextwin 'off'
setv zscale 'off'
setv zdimdim 'off'
setv zjump '10'
endproc setdef


! display the Communications sub-menu

proc comm
	at clear
	do @unquotes
	if netspec != 'no'
	! network options - netspec & opsys
		if opsys() = 1
			if netspec = 'gn'
				menu 3 close
				attr $(title)
				menu 3 open "Network Options",1,0
				attr default
				menu 3 entry "Serial Ports","INT 14","NETBIOS","MS Networks","Excelan Telapi","Locus PCI","Intel Opennet","Retix OSI","SCO Xenixnet","Atlantix Coconet","SCO Asyncnet","Ungermann Bass","RS232 BIOS","Beame & Whiteside","Null Connect"
				wopen 2,0,21,19,57
				wselect 0
				attr $(title)
				at 0,30 "[TERM 6.2 Setup Utility - Communications]"
				attr default
				wselect 2
				at 2,12 "Current connection: "+zport+znode
				setvar menu3 menu(3,0)
				if menu3 = 1
					if iw
						setv netlist '"COM1:","COM2:","COM3:","COM4:"'
					else
						setv netlist '"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:"'
					endi
				elseif menu3 = 2
					setv netlist '"INT14:"'
				elseif menu3 = 3
					setv netlist '"NETBIOS:"'
				elseif menu3 = 4
					setv netlist '"MSNET:"'
				elseif menu3 = 5
					setv netlist '"TELAPI:","TELAPIB:","TELAPIN:"'
				elseif menu3 = 6
					setv netlist '"PCI:"'
				elseif menu3 = 7
					setv netlist '"OPENNET:"'
				elseif menu3 = 8
					setv netlist '"OPENNETB:"'
				elseif menu3 = 9 | menu3 = 10 | menu3 = 11
					setv netlist '"XENIXNET:"'
				elseif menu3 = 12
					setv netlist '"UB:","UB0:","UB1:","UB2:"'
				elseif menu3 = 13
					setv netlist '"BIOS1:","BIOS2:","BIOS3:","BIOS4:","BIOS5:","BIOS6:","BIOS7:"'
				elseif menu3 = 14
					setv netlist '"TELNET:","RLOGIN:"'
				elseif menu3 = 15
					setv netlist '"NUL:"'
				elseif menu3 = 0
					menu 3 close
					wclose 2
					return
				else
					setv netlist '"'+zport+'"'
				endi
				do @helpline
				wselect 2
				at 2,0 "                                                "
				at clear
				attr default
				if menu3 = 1 | menu3 = 15
					at 2,0 "            Communications Port: " get zport list $(netlist)
					at 4,0 "                      Baud Rate: " get zbaud list "1200","2400","4800","9600","19200","38400","57600","115200","300"
					at 6,0 "                         Parity: " get zparity list "NONE","EVEN","ODD","MARK","SPACE"
					at 8,0 "                     Wordlength: " get zwordlen list "8","7","6","5"
					at 10,0 "                       Stopbits: " get zstopbit list "1","2"
				elseif menu3 = 3 | menu3 = 4
					at 2,1 "          Network connection: " get zport list $(netlist)
					at 4,1 "                   Node Name: " get znode len 24
					at 6,1 "         Network port number: " get znetport len 4
					at 8,1 "Virtual Terminal Server name: " get znetvt len 10
					at 10,1 "  Network handshaking string: " get znetdiag len 24
					at 12,1 " Exit TERM on Network Session Disconnect: " get zexitdist list "NO","YES"
				else
					at 2,1 "          Network connection: " get zport list $(netlist)
					if menu3 = 2 | menu3 = 13
						at 4,1 "         Node Name/Baud Rate: " get znode len 24
					else
						at 4,1 "                   Node Name: " get znode len 24
					endi
					at 6,1 " Exit TERM on Network Session Disconnect: " get zexitdist list "NO","YES"
				endi
				at read
				setv ret _retval
				if ret = 0
					setv saved false
				endi
				wclose 2
				wclose 3
				menu 3 close
			else
				do @helpline
				wopen 2,4,0,9,78
				wselect 0
				attr $(title)
				at 4,19 "[TERM 6.2 Setup Utility - Communications]"
				attr default
				wselect 2
				if netspec = 'fs'
					at 2,17 "         Communications port: " get zport list "TELNET:","RLOGIN:"
				elseif netspec = 'fr'
					at 2,17 "         Communications port: " get zport list "ATLANTIS:","TELAPI:"
				elseif netspec = 'm1'
					at 2,17 "         Communications port: " get zport list "ATLANTIS:","COM1:"
				else
					at 2,17 "         Communications port: " get zport len 20
				endi
				at 3,17 "                   Node Name: " get znode len 20
				at 5,6 "Exit TERM on Network Session Disconnect: " get zexitdisc list "NO","YES"
				at read
				setv ret _retval
				if ret = 0
					setv saved false
				endi
				wclose 2
				wclose 3
			endi
		else
			if netspec = 'u3' | netspec = 'tc'
				menu 3 close
				attr $(title)
				menu 3 open "Connections",5,3
				attr default
				if scou3 | netspec = 'tc'
					menu 3 entry "Async","Telnet:","Telnete:","Rlogin:","Pty:"
				else
					menu 3 entry "Async","Telnet:","Telnete:","Rlogin:"
				endi
				if toupper(zport)="TELNET:"
					setv menu3 menu(3,2)
				elseif toupper(zport)="TELNETE:"
					setv menu3 menu(3,3)
				elseif toupper(zport)="RLOGIN:"
					setv menu3 menu(3,4)
				elseif (scou3 & toupper(zport)="PTY:")
					setv menu3 menu(3,5)
				else
					setv menu3 menu(3,1)
				endi
				setv ret menu3
				if ret = 0
					do @quotes
					return
				endi
				menu 3 close
				do @helpline
				if menu3=2|menu3=3|menu3=4|menu3=5
					wopen 2,4,0,9,78
				else
					wopen 2,4,0,11,78
				endi
				wselect 0
				attr $(title)
				at 4,19 "[TERM 6.2 Setup Utility - Communications]"
				attr default
				wselect 2
				if menu3=2|menu3=3|menu3=4|menu3=5
					if menu3=3
						setv zport 'telnete:'
					elseif menu3=4
						setv zport 'rlogin:'
					elseif menu3=5
						setv zport 'pty:'
					else
						setv zport 'telnet:'
					endi
					at 1,15 "         Communications port: " get zport len 20
					at 3,15 "                   Node Name: " get znode len 20
					at 5,16 "Exit TERM on Network Session Disconnect: " get zexitdisc list "NO","YES"
				else
					if zport = "telnet:" | zport = "telnete:" | zport = "rlogin:" | zport = "pty:"
						setv zasport ""
					else
						setv zasport zport
					endif
					at 1,15 "    Communications port: " get zasport len 36
					at 2,15 "              Baud Rate: " get zbaud list "1200","2400","4800","9600","19200","38400","56700","115200","300"
					at 3,15 "                 Parity: " get zparity list "NONE","EVEN","ODD","MARK","SPACE"
					at 4,15 "             Wordlength: " get zwordlen list "8","7","6","5"
					at 5,15 "               Stopbits: " get zstopbit list "1","2"
					if opsys()>1 and opsys()<8
						at 6,12 "   UUCP lockfile format: " get zlockf len 38
						at 7,9 " UUCP lockfiles are considered valid up to " get zlockt len 5
						at 7,58 "seconds"
					endi
				endi
				at read
				setv ret _retval
				if ret = 0
					setv saved false
				endi
				wclose 2
				wclose 3
			else
				do @helpline
				wopen 2,4,0,9,78
				wselect 0
				attr $(title)
				at 4,19 "[TERM 6.2 Setup Utility - Communications]"
				attr default
				wselect 2
				if opsys()=8
					at 1,17 "         Communications port: " get zport list "TELNET:","TELNETB","TCPCONFIG:","RLOGIN:"
				elseif netspec = 'tc'
					at 1,17 "         Communications port: " get zport list "TELNET:","RLOGIN:","PTY:"
				elseif netspec = 'u3'
					at 1,17 "         Communications port: " get zport $(netlist)
				else
					at 1,17 "         Communications port: " get zport len 20
				endi
				at 3,17 "                   Node Name: " get znode len 20
				at 5,6 "Exit TERM on Network Session Disconnect: " get zexitdisc list "NO","YES"
				at read
				setv ret _retval
				if ret = 0
					setv saved false
				endi
				wclose 2
				wclose 3
			endi
		endif
	else
		! async options - opsys
		do @helpline
		wopen 2,0,0,19,78
		wselect 0
		attr $(title)
		at 0,19 "[TERM 6.2 Setup Utility - Communications]"
		attr default
		wselect 2
		if opsys()=1
			if iw
				at 2,15 "    Communications port: " get zport list "COM1:","COM2:","COM3:","COM4:","NUL:"
			else
				at 2,15 "    Communications port: " get zport list "COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","NUL:"
			endi
		elseif opsys()=8
			at 2,15 "    Communications port: " get zport list "[Comm]A","[Comm]B","[Comm]C","[Comm]D","NUL:"
		elseif opsys()=9
			at 2,15 "    Communications port: " get zport list "Modem:","Printer:"
		elseif opsys()=11
			at 2,15 "    Communications port: " get zport list "1:","2:","3:","4:","5:","6:","7:","8:","9:","10:","11:","12:","13:","14:","15:","16:","17:","18:","19:","20:","NUL:"
		else
			at 2,15 "    Communications port: " get zport len 36
		endi
		at 4,15 "              Baud Rate: " get zbaud list "1200","2400","4800","9600","19200","38400","57600","115200","300"
		at 6,15 "                 Parity: " get zparity list "NONE","EVEN","ODD","MARK","SPACE"
		at 8,15 "             Wordlength: " get zwordlen list "8","7","6","5"
		at 10,15 "               Stopbits: " get zstopbit list "1","2"
		if opsys()>1 and opsys()<8
			at 12,12 "   UUCP lockfile format: " get zlockf len 38
			at 14,9 " UUCP lockfiles are considered valid up to " get zlockt len 5
			at 14,58 "seconds"
		endi
		at read
		setv ret _retval
		if ret = 0
			setv saved false
		endi
		wclose 2
		wclose 3
	endi	
	do @quotes
endproc comm

!  change quoted strings and prepare them for proc comm

proc unquotes
	do @unquote zport
	if pos(':',zport,1) != 0
		setv znode trim(right(zport,len(zport)-pos(':',zport,1)))
		setv zport trim(left(zport,pos(':',zport,1)))
	else
		setv znode ''
		setv zport trim(zport)
	endi
	setv zasport ""
	setv zparity toupper(zparity)
	if trim(znetport) = '0'
		setv znetport ''
	endi
	do @unquote zlockf
	do @unquote znetvt
	do @unquote znetdiag
	do @on2yes zexitdisc
endproc unquotes

!    quote strings from proc comm and prepare them for .termsys

proc quotes
	if zport = "telnet:" | zport = "telnete:" | zport = "rlogin:" | zport = "pty:"
		setv zport trim(zport)+trim(znode)
	endif
	if zasport != ""
		setv zport zasport
	endif
	do @quote zport
	setv zparity tolower(zparity)
	if trim(znetport) = ''
		setv znetport '0'
	endi
	do @quote zlockf
	do @quote znetvt
	do @quote znetdiag
	do @yes2on zexitdisc
	setv zlockt trim(zlockt)
endproc quotes


! display the Hardware sub-menu

proc hardware
	at clear
	do @helpline
	setv vidcust false
	if left(zvidcard,4) = 'cust'
		setv zvidcardo zvidcard
		setv zvidcard 'CUSTOM'
		setv vidcust true
	else
		setv zvidcard toupper(zvidcard)
	endi
	setv zvidout toupper(zvidout)
	setv zvidblink toupper(zvidblink)
	setv zvidund toupper(zvidund)
	setv zkeyb toupper(zkeyb)
	setv zxon left(zxonxoff,pos(',',zxonxoff,1)-1)
	setv zxoff right(zxonxoff,len(zxonxoff)-pos(',',zxonxoff,1))	
	do @on2yes zeofopen
	do @on2yes zconsxon
	setv zescloop trim(zescloop)
	if zprot1 = 'etx'
		setv zprot1 'ETX/ACK'
	elseif zprot1 = 'rts'
		setv zprot1 'RTS/CTS'
	else
		setv zprot1 'XON/XOFF'
	endi
	setv zterm trim(zterm)
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - Hardware]"
	attr default
	wselect 2
	if opsys()=1 & !iw
		if vidcust
			at 1,15 "Video Method for 132 column: " get zvidcard list "CUSTOM","NONE","GRAPHICS","AHEAD","ATI1","ATI2","EVEREX","PARADISE","TECMAR","TSENG","VIDEO7"
			at 2,2 "(See Advanced Options for customization)"
		else
			at 1,15 "Video Method for 132 column: " get zvidcard list "NONE","GRAPHICS","AHEAD","ATI1","ATI2","EVEREX","PARADISE","TECMAR","TSENG","VIDEO7"
		endi
		at 3,17 "             Video Output: " get zvidout list "RAM","SNOW","INT10","BDOS","GRAPHICS"
		at 5,17 "              Video Blink: " get zvidblink list "NOBIOS","BIOS"
		at 7,17 "          Video Underline: " get zvidund list "NONE","PORT","FONT"
		at 9,17 "                 Keyboard: " get zkeyb list "BIOS","EXTBIOS","INT9","INT9N"
		setv p1 9
		setv p2 17
		setv p3 2
		setv p4 4
		setv p5 6
		setv p6 7
	elseif iw | opsys() = 8 | opsys() = 0
		setv p1 3
		setv p2 17
		setv p3 0
		setv p4 2
		setv p5 4
		setv p6 6
	else
		at 1,10 " Time to wait between ESC and sequence: " get zescloop len 4
		at 1,54 "/1000 seconds"
		at 3,10 "        Terminal requires flow control: " get zconsxon list "NO","YES"
		at 5,10 "        Use alternate port open (AT&T): " get zeofopen list "NO","YES"
		setv p1 5
		setv p2 23
		setv p3 2
		setv p4 4
		setv p5 6
		setv p6 8
		if opsys() = 11
			at 7,23   "            Terminal Type: " get zterm len 10
			setv p1 7
		endi
	endi
	if !iw | opsys() != 8 | opsys() != 0
		at p1+p3,p2 "  Number of colors to use: " get zcolnum list "8","4","2","16"
	endif
	at p1+p4,p2 "       Emulation Protocol: " get zprot1 list "XON/XOFF","RTS/CTS","ETX/ACK"
	at p1+p5,p2 "        XON decimal value: " get zxon len 3
	at p1+p6,p2 "       XOFF decimal value: " get zxoff len 3
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	if left(zvidcard,4) = 'CUST'
		setv zvidcard zvidcardo
	else
		setv zvidcard tolower(zvidcard)
	endi
	setv zvidout tolower(zvidout)
	setv zvidblink tolower(zvidblink)
	setv zvidund tolower(zvidund)
	setv zkeyb tolower(zkeyb)
	if trim(zxon) = ''
		setv zxon 17
	elseif trim(zxoff) = ''
		setv zxoff 19
	endi
	setv zxonxoff trim(zxon)+','+trim(zxoff)
	setv zescloop trim(zescloop)
	do @yes2on zeofopen
	do @yes2on zconsxon
	if zprot1 = 'ETX/ACK'
		setv zprot1 'etx'
	elseif zprot1 = 'RTS/CTS'
		setv zprot1 'rts'
	else
		setv zprot1 'xon'
	endi
	setv zterm trim(zterm)
endproc hardware


! display the Keyboard sub-menu

proc key
	at clear
	do @helpline
	setv zmenu left(zmenu,len(zmenu)-5)
	setv zhelp left(zhelp,len(zhelp)-5)
	setv zgold left(zgold,len(zgold)-5)
	setv zshell left(zshell,len(zshell)-6)
	setv zcapt left(zcapt,len(zcapt)-8)
	setv zprint left(zprint,len(zprint)-6)
	setv zcompose left(zcompose,len(zcompose)-8)
	setv zcmd left(zcmd,len(zcmd)-4)
	setv zabort left(zabort,len(zabort)-6)
	setv zbreak left(zbreak,len(zbreak)-6)
	setv zsright left(zsright,len(zsright)-9)
	setv zsleft left(zsleft,len(zsleft)-8)
	setv zslup left(zslup,len(zslup)-10)
	setv zsldn left(zsldn,len(zsldn)-10)
	setv zspup left(zspup,len(zspup)-10)
	setv zspdn left(zspdn,len(zspdn)-10)
	setv zscan left(zscan,len(zscan)-9)
	setv znews left(znews,len(znews)-8)
	setv znexts left(znexts,len(znexts)-9)
	setv zgotos left(zgotos,len(zgotos)-9)
	setv zdiscs left(zdiscs,len(zdiscs)-9)
	do @keyset
	if zaltkeys = 'off'
		setv zaltkeys 'MS WINDOWS'
	else
		setv zaltkeys 'TERM'
	endi
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - Keyboard]"
	attr default
	wselect 2
	if opsys() = 11 | opsys() > 1 and opsys() < 8
		setv p1 18
		setv p2 18
	else
		setv p1 6
		setv p2 42
	endi
	if iw
		at 2,p1 "        Help System: " get zhelp len 10
		at 3,p1 "Gold (Passthru) key: " get zgold len 10
		at 4,p1 "Data Capture Toggle: " get zcapt len 10
		at 5,p1 "       Print Screen: " get zprint len 10
		at 6,p1 "  VT220 Compose Key: " get zcompose len 10
		at 7,p1 "   Command Line Key: " get zcmd len 10
		at 8,p1 "          Abort Key: " get zabort len 10
		at 9,p1 "          Break Key: " get zbreak len 10
	else
		at 1,p1 "          Main Menu: " get zmenu len 10
		at 2,p1 "        Help System: " get zhelp len 10
		at 3,p1 "Gold (Passthru) key: " get zgold len 10
		at 4,p1 "       Shell Escape: " get zshell len 10
		at 5,p1 "Data Capture Toggle: " get zcapt len 10
		at 6,p1 "       Print Screen: " get zprint len 10
		at 7,p1 "  VT220 Compose Key: " get zcompose len 10
		at 8,p1 "   Command Line Key: " get zcmd len 10
		at 9,p1 "          Abort Key: " get zabort len 10
		at 10,p1 "          Break Key: " get zbreak len 10
	endi
	if opsys() < 2 | opsys() > 7 and opsys() != 11
		at 2,p2 "   Scan Mode Toggle: " get zscan len 10
		at 3,p2 "   Open New Session: " get znews len 10
		at 4,p2 "       Next Session: " get znexts len 10
		at 5,p2 "      Go To Session: " get zgotos len 10
		at 6,p2 " Disconnect Session: " get zdiscs len 10
		at 7,p2 "Screen Scroll Right: " get zsright len 10
		at 8,p2 " Screen Scroll Left: " get zsleft len 10
	endi
	if opsys() < 2 | opsys() > 7
		if iw 
			at 11,18 "   Screen Scroll Back (line): " get zslup len 10
			at 12,18 "Screen Scroll Forward (line): " get zsldn len 10
			at 13,18 "   Screen Scroll Back (page): " get zspup len 10
			at 14,18 "Screen Scroll Forward (page): " get zspdn len 10
			at 15,18 "        Alt-Keys are used by: " get zaltkeys list "MS WINDOWS","TERM"
		else
			at 12,18 "   Screen Scroll Back (line): " get zslup len 10
			at 13,18 "Screen Scroll Forward (line): " get zsldn len 10
			at 14,18 "   Screen Scroll Back (page): " get zspup len 10
			at 15,18 "Screen Scroll Forward (page): " get zspdn len 10
		endif
	else
		at 12,9 "   Screen Scroll Back (page): " get zspup len 10
		at 13,9 "Screen Scroll Forward (page): " get zspdn len 10
	endi
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	do @keyreset
	do @keynone zmenu
	do @keynone zhelp
	do @keynone zgold
	do @keynone zshell
	do @keynone zcapt
	do @keynone zprint
	do @keynone zcompose
	do @keynone zcmd
	do @keynone zabort
	do @keynone zbreak
	do @keynone zsright
	do @keynone zsleft
	do @keynone zslup
	do @keynone zsldn
	do @keynone zspup
	do @keynone zspdn
	do @keynone zscan
	do @keynone znews
	do @keynone znexts
	do @keynone zgotos
	do @keynone zdiscs
	setv zmenu trim(zmenu)+' menu'
	setv zhelp trim(zhelp)+' help'
	setv zgold trim(zgold)+' gold'
	setv zshell trim(zshell)+' shell'
	setv zcapt trim(zcapt)+' capture'
	setv zprint trim(zprint)+' print'
	setv zcompose trim(zcompose)+' compose'
	setv zcmd trim(zcmd)+' cmd'
	setv zabort trim(zabort)+' abort'
	setv zbreak trim(zbreak)+' break'
	setv zsright trim(zsright)+' scrright'
	setv zsleft trim(zsleft)+' scrleft'
	setv zslup trim(zslup)+' scrlineup'
	setv zsldn trim(zsldn)+' scrlinedn'
	setv zspup trim(zspup)+' scrpageup'
	setv zspdn trim(zspdn)+' scrpagedn'
	setv zscan trim(zscan)+' scanmode'
	setv znews trim(znews)+' newsess'
	setv znexts trim(znexts)+' nextsess'
	setv zgotos trim(zgotos)+' gotosess'
	setv zdiscs trim(zdiscs)+' discsess'
	if zaltkeys = 'MS WINDOWS'
		setv zaltkeys 'off'
	else
		setv zaltkeys 'on'
	endi
endproc key


! display the Terminal sub-menu

proc term
	at clear
	do @helpline
	if zemul = 'vt220-8' & pos('wang2110',zdo,1) != 0
		setv zemul 'WANG2110'
	elseif zemul = 'tv950' & pos('ibm3270',zdo,1) != 0
		setv zemul 'IBM3270'
	elseif zemul = 'ib3101' and zblock = 'off'
		setv zemul 'IBM 3101 Line'
	elseif zemul = 'ib3101' and zblock = 'on'
		setv zemul 'IBM 3101 Block'
	elseif zemul = 'wyse50' and zblock = 'off'
		setv zemul 'WYSE50 Line'
	elseif zemul = 'wyse50 and zblock = 'on'
		setv zemul 'WYSE50 Block'
	elseif zemul = 'adm1'
		setv zemul 'ADM-1'
	else
		setv zemul toupper(zemul)
		setv zblock 'off'
	endi
	setv zmode toupper(zmode)
	setv zcharset toupper(zcharset)
	setv zwrap toupper(zwrap)
	do @on2yes zaddlf
	do @on2yes zaddcr
	if zrevdim = 'on'
		setv zrevdim  'DIM'
	else
		setv zrevdim  'REVERSE'
	endi
	do @on2yes zmaskpar
	do @on2yes ztabex
	do @on2yes zbsdel
	if znoscroll = 'on'
		setv znoscroll 'NO'
	else
		setv znoscroll 'YES'
	endi
	setv zturnchar trim(zturnchar)
	do @unquote zturnchar
	setv zrevmap toupper(zrevmap)
	setv zdimdim toupper(zdimdim)
	setv zjump trim(zjump)
	if zextwin = 'on'
		setv zfeature 'Extensible Windows'
	elseif zscale = 'on'
		setv zfeature 'Scalable Fonts'
	else
		setv zfeature 'None'
	endi
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - Terminal]"
	attr default
	wselect 2
	if opsys()=8
		at 1,8 "      Emulation: " get zemul list "VT100","VT220-7","VT220-8","SCOANSI","WYSE60","WYSE50 Line","WYSE50 Block","VT102","VT52","TV912","TV925","TV950","ANSI","IBM 3101 Line","IBM 3101 Block","ADM-1","WANG2110","IBM3270","TTY"
	else
		at 1,8 "      Emulation: " get zemul list "VT100","VT220-7","VT220-8","SCOANSI","WYSE60","PCTERM","WYSE50 Line","WYSE50 Block","VT102","VT52","TV912","TV925","TV950","ANSI","IBM 3101 Line","IBM 3101 Block","ADM-1","WANG2110","IBM3270","TTY"
	endi
	at 2,8 "    Duplex Mode: " get zmode list "FULL","HALF","MNEMONIC","CONTROL","TALK","DUMP"
	at 3,8 "   Screen Pages: " get zpages list "1","2","3","4","5","6"
	at 4,7 "Scrollback Buffer " get zscrback len 3
	if isx | iw
		at 5,7 "  Reverse Screen: " get zrevmap list "ON","OFF"
	endi
	at 4,28 " lines"
	at 1,40 "         Add Linefeeds: " get zaddlf list "YES","NO"
	at 2,40 "  Add Carriage Returns: " get zaddcr list "YES","NO"
	at 3,40 "      End of Line Wrap: " get zwrap list "ON","OFF"
	at 4,40 "Allow screen scrolling: " get znoscroll list "YES","NO"
	if isx | iw
		at 5,40 " Lines for Jump Scroll: " get zjump len 2
	endi
	at 7,10 "VT220-7 National Character Replacement Set: " get zcharset list "AMERICAN","BRITISH","DUTCH","FINNISH","FRENCH","CANADIAN","GERMAN","ITALIAN","DANISH","NORWEGIAN","PORTUGEUSE","SPANISH","SWEDISH","SWISS"
	at 8,10 "    Display Wyse 50 protected attribute as: " get zrevdim list "REVERSE","DIM"
	at 9,10 "             IBM 3101 Turnaround character: " get zturnchar len 4
	at 10,10 "            * Ignore Graphics / Parity bit: " get zmaskpar list "YES","NO"
	at 11,10 "           Expand Tab characters to spaces: " get ztabex list "YES","NO"
	at 12,10 "              VT220 Backspace sends Delete: " get zbsdel list "YES","NO"
	if opsys() = 1 | opsys() = 8
		at 13,10 "         Display Dim/Normal as Normal/Bold: " get zdimdim list "OFF","ON"
		if iw
			at 14,10 "                    Windows Feature to use: " get zfeature list "Extensible Windows","Scalable Fonts", "None"
		endi
	endi
	attr bold
	at 10,22 "*"
	at 15,5 "* This setting ignored in SCO Ansi, VT220-8, Wyse 60 and PCTERM"
	attr default
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	setv zdo 'noscript'
	if zemul = 'IBM 3101 Line'
		setv zemul 'ib3101'
		setv zblock 'off'
	elseif zemul = 'IBM 3101 Block'
		setv zemul 'ib3101'
		setv zblock 'on'
	elseif zemul = 'WYSE50 Line'
		setv zemul 'wyse50'
		setv zblock 'off'
	elseif zemul = 'WYSE50 Block'
		setv zemul 'wyse50'
		setv zblock 'on'
	elseif zemul = 'ADM-1'
		setv zemul 'adm1'
	elseif zemul = 'WANG2110'
		setv zemul 'vt220-8'
		setv zdo 'wang2110'
	elseif zemul = 'IBM3270'
		setv zemul 'tv950'
		setv zdo 'ibm3270'
	else
		setv zemul tolower(zemul)
		setv zblock 'off'
	endi
	setv zmode tolower(zmode)
	setv zcharset tolower(zcharset)
	setv zwrap tolower(zwrap)
	do @yes2on zaddlf
	do @yes2on zaddcr
	do @yes2on zmaskpar
	if zrevdim = 'DIM'
		setv zrevdim 'on'
	else
		setv zrevdim 'off'
	endi
	do @yes2on ztabex
	do @yes2on zbsdel
	if znoscroll = 'NO'
		setv znoscroll 'on'
	else
		setv znoscroll 'off'
	endi
	do @quote zturnchar
	setv zrevmap tolower(zrevmap)
	setv zdimdim tolower(zdimdim)
	setv zjump trim(zjump)
	if zfeature = 'Extensible Windows'
		setv zextwin 'on'
		setv zscale 'off'
	elseif zfeature = 'Scalable Fonts'
		setv zextwin 'off'
		setv zscale 'on'
	else
		setv zextwin 'off'
		setv zscale 'off'
	endi
endproc term


! display the Colors sub-menu

proc color
	at clear
	do @helpline
	setv zcoldef1 left(zcoldef,pos(',',zcoldef,1)-1)
	setv zcoldef2 right(zcoldef,len(zcoldef)-pos(',',zcoldef,1))
	do @num2col zcoldef1 $(zcoldef1)
	do @num2col zcoldef2 $(zcoldef2)	
	if pos(',',zcolrev,1) != 0
		setv zcolrev1 left(zcolrev,pos(',',zcolrev,1)-1)
		setv zcolrev2 right(zcolrev,len(zcolrev)-pos(',',zcolrev,1))
		do @num2col zcolrev1 $(zcolrev1)
		do @num2col zcolrev2 $(zcolrev2)	
	else
		setv zcolrev1 'DEFAULT'
		setv zcolrev2 'DEFAULT'
	endi
	if pos(',',zcolbold,1) != 0
		setv zcolbold1 left(zcolbold,pos(',',zcolbold,1)-1)
		setv zcolbold2 right(zcolbold,len(zcolbold)-pos(',',zcolbold,1))
		do @num2col zcolbold1 $(zcolbold1)
		do @num2col zcolbold2 $(zcolbold2)
	else
		setv zcolbold1 'DEFAULT'
		setv zcolbold2 'DEFAULT'
	endi
	if pos(',',zcolund,1) != 0
		setv zcolund1 left(zcolund,pos(',',zcolund,1)-1)
		setv zcolund2 right(zcolund,len(zcolund)-pos(',',zcolund,1))
		do @num2col zcolund1 $(zcolund1)
		do @num2col zcolund2 $(zcolund2)
	else
		setv zcolund1 'DEFAULT'
		setv zcolund2 'DEFAULT'
	endi
	if pos(',',zcolblink,1) != 0
		setv zcolblink1 left(zcolblink,pos(',',zcolblink,1)-1)
		setv zcolblink2 right(zcolblink,len(zcolblink)-pos(',',zcolblink,1))
		do @num2col zcolblink1 $(zcolblink1)
		do @num2col zcolblink2 $(zcolblink2)
	else
		setv zcolblink1 'DEFAULT'
		setv zcolblink2 'DEFAULT'
	endi
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,23 "[TERM 6.2 Setup Utility - Colors]"
	attr default
	wselect 2
	at 1,10 "      Display default colors as   " get zcoldef1 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE"
	if iw
		at 1,53 " on " get zcoldef2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE"
	else
		at 1,53 " on " get zcoldef2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE"
	endi
	at 3,10 "  Display reverse characters as   " get zcolrev1 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	if iw
		at 3,53 " on " get zcolrev2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	else
		at 3,53 " on " get zcolrev2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","DEFAULT"
	endi
	at 5,10 "     Display bold characters as   " get zcolbold1 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	if iw
		at 5,53 " on " get zcolbold2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	else
		at 5,53 " on " get zcolbold2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","DEFAULT"
	endi
	at 7,10 "Display underline characters as   " get zcolund1 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	if iw
		at 7,53 " on " get zcolund2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	else
		at 7,53 " on " get zcolund2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","DEFAULT"
	endi
	if !iw
		at 9,10 "    Display blink characters as   " get zcolblink1 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
		at 9,53 " on " get zcolblink2 list "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN","WHITE","GREY","LTBLUE","LTGREEN","LTCYAN","LTRED","LTMAGENTA","YELLOW","LTWHITE","DEFAULT"
	endi
	attr bold
	at 11,15 "NOTE:  Using DEFAULT as the foreground setting"
	at 12,22 "ignores the background color setting."
	if opsys()>1 and opsys()<8
	at 14,1 "You must have the bce/be entry in your terminfo/termcap for color to work."
	endi
	at 16,8 "Color changes will not have an effect on monochrome monitors."
!	at 11,0 "               NOTE:  Using DEFAULT as the foreground setting "
!	at 12,0 "                      ignores the background color setting."
!	at 16,0 "        Color changes will not have an effect on monochrome monitors."
	attr default
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	do @col2num zcoldef1 $(zcoldef1)
	do @col2num zcoldef2 $(zcoldef2)
	setv zcoldef zcoldef1+','+zcoldef2
	if zcolrev1 = 'DEFAULT'
		setv zcolrev '-1'
	else
		do @col2num zcolrev1 $(zcolrev1)
		do @col2num zcolrev2 $(zcolrev2)
		setv zcolrev zcolrev1+','+zcolrev2
	endi
	if zcolbold1 = 'DEFAULT'
		setv zcolbold '-1'
	else
		do @col2num zcolbold1 $(zcolbold1)
		do @col2num zcolbold2 $(zcolbold2)
		setv zcolbold zcolbold1+','+zcolbold2
	endi
	if zcolblink1 = 'DEFAULT'
		setv zcolblink '-1'
	else
		do @col2num zcolblink1 $(zcolblink1)
		do @col2num zcolblink2 $(zcolblink2)
		setv zcolblink zcolblink1+','+zcolblink2
	endi
	if zcolund1 = 'DEFAULT'
		setv zcolund '-1'
	else
		do @col2num zcolund1 $(zcolund1)
		do @col2num zcolund2 $(zcolund2)
		setv zcolund zcolund1+','+zcolund2
	endi
endproc color


! display the Capture sub-menu

proc capt
	at clear
	do @helpline
	setv cmode toupper(left(zcapture,pos(' ',zcapture,1)-1))
	setv cfile left(right(zcapture,len(zcapture)-pos(' ',zcapture,1)),pos(' ',right(zcapture,len(zcapture)-pos(' ',zcapture,1)),1)-1)
	if pos('overwrite',zcapture,1) != 0
		setv cover 'OVERWRITE'
	elseif pos('append',zcapture,1) != 0
		setv cover 'APPEND'
	else
		setv cover 'ASK'
	endi
	if pos('flush',zcapture,1) != 0
		setv cflush 'YES'
	else
		setv cflush 'NO'
	endi
	setv zprot2 toupper(zprot2)
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - Capture]"
	attr default
	wselect 2
	at 3,13 "         Device or File name: " get cfile len 30
	if opsys()>1 and opsys()<8
		at 5,13 "                Capture Mode: " get cmode list "DEVICE","DISK","SPOOL","TERMINAL"
	elseif opsys()=8
		at 5,13 "                Capture Mode: " get cmode list "DEVICE","DISK"
	else
		at 5,13 "                Capture Mode: " get cmode list "DEVICE","DISK","SPOOL"
	endi
	at 7,13 "      Action on Capture File: " get cover list "OVERWRITE","APPEND","ASK"
	at 9,13 "       Flush Commline buffer: " get cflush list "YES","NO"
	at 11,13 "            Capture protocol: " get zprot2 list "ASCII","BINARY"
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	setv zcapture tolower(cmode)+' '+trim(cfile)
	if cover = 'OVERWRITE'
		setv zcapture zcapture+' overwrite'
	elseif cover = 'APPEND'
		setv zcapture zcapture+' append'
	endi
	if cflush = 'YES'
		setv zcapture zcapture+' flush'
	endi
	setv zprot2 tolower(zprot2)
endproc capt	


! display the Printer sub-menu

proc prn
	at clear
	do @helpline
	setv pmode toupper(left(zprinter,pos(' ',zprinter,1)-1))
	setv pfile trim(right(zprinter,len(zprinter)-pos(' ',zprinter,1)))
	setv nppos 0
	repeat
		setv ppos nppos
		setv nppos pos(' ', pfile, ppos+1)
	until nppos = 0 or nppos > ppos+1
	if ppos > 0
		setv pfile right (pfile, len(pfile) - ppos)
	endi
	if pos('"',pfile,1) = 1
		setv ppos pos('"',pfile,2)
		setv pfile midstr (pfile, 2, ppos-2)
	else
		setv ppos pos(' ',pfile,1)
		if ppos = 0
			setv ppos len(pfile)
		else

			setv pfile left (pfile, ppos-1)
		endi
	endi
	setv ppos ppos+1
	if pos('overwrite',zprinter,ppos) != 0
		setv pover 'OVERWRITE'
	elseif pos('append',zprinter,ppos) != 0
		setv pover 'APPEND'
	else
		setv pover 'ASK'
	endi
	if pos('flush',zprinter,ppos) != 0
		setv pflush 'YES'
	else
		setv pflush 'NO'
	endi
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - Printer]"
	attr default
	wselect 2
	at 3,13 "         Device or File name: " get pfile len 30
	if opsys()>1 and opsys()<8
		at 5,13 "                Printer Mode: " get pmode list "DEVICE","DISK","SPOOL","TERMINAL","CAPTURE","NONE"
	elseif opsys()=8
		at 5,13 "                Printer Mode: " get pmode list "DEVICE","DISK","CAPTURE","NONE"
	else
		at 5,13 "                Printer Mode: " get pmode list "DEVICE","DISK","SPOOL","CAPTURE","NONE"
	endi
	at 7,13 "      Action on Printer File: " get pover list "OVERWRITE","APPEND","ASK"
	at 9,13 "       Flush Commline buffer: " get pflush list "YES","NO"
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	do @quote pfile
	setv zprinter tolower(pmode)+' '+trim(pfile)
	if pover = 'OVERWRITE'
		setv zprinter zprinter+' overwrite'
	elseif pover = 'APPEND'
		setv zprinter zprinter+' append'
	endi
	if pflush = 'YES'
		setv zprinter zprinter+' flush'
	endi
endproc prn	


! display the Modem sub-menu

proc modem
	at clear
	do @helpline
	do @on2yes zddtr
	do @on2yes zexitdtr	
	do @unquote zdinit
	do @unquote zdprefix
	do @unquote zdsuffix
	do @unquote zdoffhook
	do @unquote zdesc
	do @unquote zdans
	do @unquote zdhangup
	do @unquote zdok
	do @unquote zdring
	do @unquote zdconnect
	setv count 0
	repeat
		if zmodem = '$(dialfile[count])'
			setv zmodem '$(dialname[count])'
		endi
		setv count count+1
	until count = 20
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,23 "[TERM 6.2 Setup Utility - Modem]"
	attr default
	wselect 2
	if opsys()=1
		at 1,6 "       Modem type: " get zmodem list $(mdmlist)
		at 2,6 "  Redial Attempts: " get zredial len 2
		at 3,6 "No answer timeout: " get zdtimeout len 3
		at 3,29 "seconds"
		at 2,38 "   Drop DTR on hangup: " get zddtr list "YES","NO"
		at 3,38 "Drop DTR on TERM quit: " get zexitdtr list "YES","NO"
	else
		at 1,21 "       Modem type: " get zmodem list $(mdmlist)
		at 2,21 "  Redial Attempts: " get zredial len 2
		at 3,21 "No answer timeout: " get zdtimeout len 3
		at 3,44 "seconds"
	endi
	attr $(title)
	at 5,6 "Hayes modem dialer settings (valid only when Modem type is Hayes)"
	attr default
	at 6,10 " Modem initialization string: " get zdinit len 30
	at 7,10 "      Dialing command prefix: " get zdprefix len 30
	at 8,10 "      Dialing command suffix: " get zdsuffix len 30
	at 9,10 "        Force modem off hook: " get zdoffhook len 30
	at 10,10 "    Force modem command mode: " get zdesc len 30
	at 11,10 "        Pickup phone on ring: " get zdans len 30
	at 12,10 "        Modem hangup command: " get zdhangup len 30
	at 13,10 " Valid command return string: " get zdok len 30
	at 14,10 "   Modem response to ringing: " get zdring len 30
	at 15,10 "Modem response to connection: " get zdconnect len 30
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	do @yes2on zddtr
	do @yes2on zexitdtr
	setv zredial trim(zredial)
	setv zdtimeout trim(zdtimeout)
	do @quote zdinit
	do @quote zdprefix
	do @quote zdsuffix
	do @quote zdoffhook
	do @quote zdesc
	do @quote zdans
	do @quote zdhangup
	do @quote zdok
	do @quote zdring
	do @quote zdconnect
	setv count 0
	repeat
		if zmodem = '$(dialname[count])'
			setv zmodem '$(dialfile[count])'
		endi
		setv count count+1
	until count = 20
endproc modem


! display the File Transfer sub-menu

proc file
	at clear
	do @helpline
	setv zxprot toupper(zxprot)
	setv zcompress toupper(zcompress)
	do @unquote zlchar
	do @on2yes zxferstat
	do @on2yes zesc8bit
	do @on2yes zaddeof
	do @on2yes ztoupper
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,19 "[TERM 6.2 Setup Utility - File Transfer]"
	attr default
	wselect 2
	at 0,5 "                                Transfer protocol: " get zxprot list "TERMCRC","WTERMCRC","XMODEM","ZMODEM","MODEM7","KERMIT","YMODEM","OLDTERM","TERM5"
	at 1,5 "                  Maximum consecutive bad packets: " get zretries len 4
	at 2,5 "         Maximum restarts (TERMCRC/WTERMCRC only): " get zrestart len 3
	at 3,5 "                                 Data compression: " get zcompress list "ON","OFF"
	at 4,5 "              Display File Transfer Status Screen: " get zxferstat list "YES","NO"
	at 5,5 "       Use 7-bit protocol (for 7-bit connections): " get zesc8bit list "NO","YES"
	at 6,5 "Memory allocation for wildcard filename expansion: " get zwildsize len 4
	at 6,61 "bytes"
	at 7,5 "        * Length of time before handshake timeout: " get zhtime len 3
	at 7,59 " seconds"
	at 8,5 "           * Length of time before sender timeout: " get zstime len 3
	at 8,59 " seconds"
	at 9,5 "         * Length of time before receiver timeout: " get zrtime len 3
	at 9,59 " seconds"
	at 10,5 "                   Convert filenames to uppercase: " get ztoupper list "NO","YES"
	if opsys()=1
		at 11,5 "                       Add EOF character to files: " get zaddeof list "NO","YES"
	endi
	attr $(title)
	at 12,6 "USEND / LSEND Options"
	attr default
	at 13,5 "      * Number of seconds to wait for acknowledge: " get zitime len 3
	at 14,5 "                       Line acknowledge character: " get zlchar len 4
	at 15,5 "                Length of delay between each line: " get zldelay len 4
	at 15,60 "/1000 seconds"
	attr bold
	at 7,13 "*"
	at 8,16 "*"
	at 9,14 "*"
	at 13,11 "*"
	at 16,14 "* A setting of 0 indicates no timeout will occur"
	attr default
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	setv zxprot tolower(zxprot)
	setv zcompress tolower(zcompress)
	do @quote zlchar
	do @yes2on zxferstat
	do @yes2on zesc8bit
	do @yes2on zaddeof
	do @yes2on ztoupper
endproc file


! display the General sub-menu

proc general
	at clear
	do @helpline
	if pos('overwrite',zlogfile,1) != 0
		setv lfile left(zlogfile,pos('overwrite',zlogfile,1)-1)
		setv lover 'OVERWRITE'
	else
		setv lfile zlogfile
		setv lover 'APPEND'
	endi
	do @on2yes zlog
	do @unquote zflags
	do @unquote zwru
	do @unquote zwruchar
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,22 "[TERM 6.2 Setup Utility - General]"
	attr default
	wselect 2
	at 2,15 "Log file transfer activity: " get zlog list "NO","YES"
	at 4,15 "             Log file name: " get lfile len 30
	at 6,15 "        Action on log file: " get lover list "APPEND","OVERWRITE"
	if !iw
		at 8,15 "  Command to invoke editor: " get zedit len 20
		at 10,15 "     Default startup flags: " get zflags len 20
		at 12,15 "     Who-are-you character: " get zwruchar len 2
		at 14,15 "   Response to Who-are-you: " get zwru len 20
	else
		at 8,15 "     Default startup flags: " get zflags len 20
		at 10,15 "     Who-are-you character: " get zwruchar len 2
		at 12,15 "   Response to Who-are-you: " get zwru len 20
	endif
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	if lover = 'OVERWRITE'
		setv zlogfile lfile+' overwrite'
	else
		setv zlogfile lfile
	endi
	do @yes2on zlog
	do @quote zflags
	do @quote zwru
	do @quote zwruchar
endproc general


! display the Advanced Options sub-menu

proc advanced
	at clear
	do @helpline
	setv zkermeol right(zkermeol,len(zkermeol)-pos(' ',zkermeol,1))
	do @unquote zkermeol
	setv ztxwindow right(ztxwindow,len(ztxwindow)-10)
	setv ztxblk right(ztxblk,len(ztxblk)-11)
	setv zrcvsync right(zrcvsync,len(zrcvsync)-9)
	do @on2yes zkermecho
	do @on2yes zaltchk	
	setv vidcust false
	if left(zvidcard,4) = 'cust'
		setv vidcust true
		setv ovidcard zvidcard
		setv zvidcard right(zvidcard,len(zvidcard)-pos(',',zvidcard,1))
		setv zvidcust1 left(zvidcard,len(zvidcard)-pos(',',zvidcard,1))
		setv zvidcust2 right(zvidcard,len(zvidcard)-pos(',',zvidcard,1))
	else
		setv zvidcust1 '0'
		setv zvidcust2 '0'
	endi
	setv addr1 left(zcom1base,pos(',',zcom1base,1)-1)
	setv intr1 right(zcom1base,len(zcom1base)-pos(',',zcom1base,1))
	setv addr2 left(zcom2base,pos(',',zcom2base,1)-1)
	setv intr2 right(zcom2base,len(zcom2base)-pos(',',zcom2base,1))
	setv addr3 left(zcom3base,pos(',',zcom3base,1)-1)
	setv intr3 right(zcom3base,len(zcom3base)-pos(',',zcom3base,1))
	setv addr4 left(zcom4base,pos(',',zcom4base,1)-1)
	setv intr4 right(zcom4base,len(zcom4base)-pos(',',zcom4base,1))
	setv addr5 left(zcom5base,pos(',',zcom5base,1)-1)
	setv intr5 right(zcom5base,len(zcom5base)-pos(',',zcom5base,1))
	setv addr6 left(zcom6base,pos(',',zcom6base,1)-1)
	setv intr6 right(zcom6base,len(zcom6base)-pos(',',zcom6base,1))
	wopen 2,0,0,19,78
	wselect 0
	attr $(title)
	at 0,18 "[TERM 6.2 Setup Utility - Advanced Options]"
	attr default
	wselect 2
	setv p 1
	if opsys()=1
		setv i 1
	else
		setv i 2
	endi
	at p,6 "                   Kermit end-of-line character: " get zkermeol len 2
	setv p p+i
	at p,6 "                  Use alternate Kermit checksum: " get zaltchk list "NO","YES"
	setv p p+i
	at p,0 " Echo received characters during Kermit file transfer: " get zkermecho list "NO","YES"
	setv p p+i
	at p,6 "* Maximum window size during WTERMCRC transfers: " get ztxwindow len 6
	attr bold
	at p,6 "*"
	attr default
	setv p p+i
	at p,6 "                         * WTERMCRC packet size: " get ztxblk len 5
	attr bold
	at p,31 "*"
	attr default
	setv p p+i
	at p,6 "              * Synchronize received files every " get zrcvsync len 6 
	at p,62 "bytes"
	attr bold
	at p,20 "*"
	attr default
	setv p p+1
	attr bold
	at p,14 "* A value of 0 will select the default settings"
	attr default
	if opsys()=1 & !iw
		setv p p+2
		at p,14 "         Video 132 column INT10 ax,bx: " get zvidcust1 len 2
		at p,55 "," get zvidcust2 len 2
		setv p p+i
		attr bold
		at p,7 "              (Selecting 0,0 disables this feature)"
		attr default
		setv p p+i
		at p,9 "   COM1 settings:  Address = " get addr1 len 6
		at p,45 "Interupt (IRQ) = " get intr1 list "0","1","2","3","4","5","6","7"
		setv p p+i
		at p,9 "   COM2 settings:  Address = " get addr2 len 6
		at p,45 "Interupt (IRQ) = " get intr2 list "0","1","2","3","4","5","6","7"
		setv p p+i
		at p,9 "   COM3 settings:  Address = " get addr3 len 6
		at p,45 "Interupt (IRQ) = " get intr3 list "0","1","2","3","4","5","6","7"
		setv p p+i
		at p,9 "   COM4 settings:  Address = " get addr4 len 6
		at p,45 "Interupt (IRQ) = " get intr4 list "0","1","2","3","4","5","6","7"
		setv p p+i
		at p,9 "   COM5 settings:  Address = " get addr5 len 6
		at p,45 "Interupt (IRQ) = " get intr5 list "0","1","2","3","4","5","6","7"
		setv p p+i
		at p,9 "   COM6 settings:  Address = " get addr6 len 6
		at p,45 "Interupt (IRQ) = " get intr6 list "0","1","2","3","4","5","6","7"
		setv p p+i
	endi
	at read
	setv ret _retval
	if ret = 0
		setv saved false
	endi
	wclose 2
	wclose 3
	do @quote zkermeol
	setv zkermeol '_kermiteol '+zkermeol
	if ( opsys() = 11 ) & ( trim(ztxwindow) = '0' )
		setv ztxwindow '_txwindow 1024'
	else
		setv ztxwindow '_txwindow '+trim(ztxwindow)
	endi
	setv ztxblk '_txblksize '+trim(ztxblk)
	setv zrcvsync '_rcvsync '+trim(zrcvsync)
	do @yes2on zkermecho
	do @yes2on zaltchk
	if trim(zvidcust1) != '0' & trim(zvidcust2) != '0'
		setv zvidcard 'custom,'+trim(zvidcust1)+','+trim(zvidcust2)
	else
		if vidcust
			setv zvidcard ovidcard
		endi
	endi
	setv zcom1base trim(addr1)+','+intr1
	setv zcom2base trim(addr2)+','+intr2
	setv zcom3base trim(addr3)+','+intr3
	setv zcom4base trim(addr4)+','+intr4
	setv zcom5base trim(addr5)+','+intr5
	setv zcom6base trim(addr6)+','+intr6
endproc advanced


! display the accompanying help box on bottom of screen (for sub-menu's)

proc helpline
	wopen 3,19,0,5,78
	wselect 3
	if iw
		setv hp1 3
		setv hp2 18
	else
		setv hp1 4
		setv hp2 19
	endif
	attr dim
	at 0,hp1 "<SPACEBAR>"
	at 1,hp1 "<CURSOR KEYS>"
	at 2,hp1 "<ESC>"
	attr default
	at 0,hp2 "Next value in field"
	at 1,hp2 "Move between fields"
	if iw
		at 2,hp2 "Return to Main Menu                  Return to Main Menu"
	else
		at 2,hp2 "Return to Main Menu               Return to Main Menu"
	endif
	attr dim
	if iw
		at 0,40 "      <CTRL-Y>"
		at 1,40 "<Double Click>"
		at 2,40 "  or  <CTRL-E>"
	else
		at 0,44 "<CTRL-Y>"
		at 1,44 "<CTRL-E>"
	endif
	attr default
	if iw
		at 0,55 "Clear field"
		at 1,55 "Save settings and"
	else
		at 0,53 "Clear field"
		at 1,53 "Save settings and"
	endi
endproc helpline

! set variable to "none" if it is blank

proc keynone
	if trim($1) = ''
		setv $1 'none'
	endi
endproc keynone

! set all keys to echo their own key names

proc keyset
keyboard int9		! install DOS keyboard driver
!setkey up 'up'
!setkey down 'down'
!setkey right 'right'
!setkey left 'left'
setkey home 'home'
setkey kp0 'kp0'
setkey kp1 'kp1'
setkey kp2 'kp2'
setkey kp3 'kp3'
setkey kp4 'kp4'
setkey kp5 'kp5'
setkey kp6 'kp6'
setkey kp7 'kp7'
setkey kp8 'kp8'
setkey kp9 'kp9'
setkey kp- 'kp-'
setkey kp, 'kp,'
setkey kp. 'kp.'
setkey kpr 'kpr'
setkey c-bs 'c-bs'
setkey c-enter 'c-enter'
setkey c-esc 'c-esc'
setkey c-kp- 'c-kp-'
setkey c-kp+ 'c-kp+'
setkey c-kp* 'c-kp*'
setkey c-kpenter 'c-kpenter'
setkey c-five 'c-kpfive'
setkey kp* 'kp*'
setkey kp+ 'kp+'
setkey kp/ 'kp/'
setkey five 'kpfive'
setkey scrlock 'scrlock'
!setkey bs 'bs'
setkey pgdn 'pgdn'
setkey c-pgdn 'c-pgdn'
setkey pgup 'pgup'
setkey c-pgup 'c-pgup'
setkey c-home 'c-home'
setkey end 'end'
setkey c-end 'c-end'
setkey ins 'ins'
setkey c-ins 'c-ins'
!setkey del 'del'
setkey c-del 'c-del'
setkey c-right 'c-left'
setkey c-left 'c-left'
setkey c-up 'c-up'
setkey c-down 'c-down'
setkey tab 'tab'
setkey c-tab 'c-tab'
setkey s-tab 's-tab'
setkey backtab 'backtab'
setkey print 'print'	! %9		c-prtsc or c-kp*
setkey f1 'f1'
setkey f2 'f2'
setkey f3 'f3'
setkey f4 'f4'
setkey f5 'f5'
setkey f6 'f6'
setkey f7 'f7'
setkey f8 'f8'
setkey f9 'f9'
setkey f10 'f10'
setkey f11 'f11'
setkey f12 'f12'
setkey f13 'f13'
setkey f14 'f14'
setkey f15 'f15'
setkey f16 'f16'
setkey sf1 'sf1'
setkey sf2 'sf2'
setkey sf3 'sf3'
setkey sf4 'sf4'
setkey sf5 'sf5'
setkey sf6 'sf6'
setkey sf7 'sf7'
setkey sf8 'sf8'
setkey sf9 'sf9'
setkey sf10 'sf10'
setkey sf11 'sf11'
setkey sf12 'sf12'
setkey sf13 'sf13'
setkey sf14 'sf14'
setkey sf15 'sf15'
setkey sf16 'sf16'
setkey cf1 'cf1'
setkey cf2 'cf2'
setkey cf3 'cf3'
setkey cf4 'cf4'
setkey cf5 'cf5'
setkey cf6 'cf6'
setkey cf7 'cf7'
setkey cf8 'cf8'
setkey cf9 'cf9'
setkey cf10 'cf10'
setkey cf11 'cf11'
setkey cf12 'cf12'
setkey cf13 'cf13'
setkey cf14 'cf14'
setkey cf15 'cf15'
setkey cf16 'cf16'
setkey af1 'af1'
setkey af2 'af2'
setkey af3 'af3'
setkey af4 'af4'
setkey af5 'af5'
setkey af6 'af6'
setkey af7 'af7'
setkey af8 'af8'
setkey af9 'af9'
setkey af10 'af10'
setkey af11 'af11'
setkey af12 'af12'
setkey af13 'af13'
setkey af14 'af14'
setkey af15 'af15'
setkey af16 'af16'
setkey csf1 'csf1'
setkey csf2 'csf2'
setkey csf3 'csf3'
setkey csf4 'csf4'
setkey csf5 'csf5'
setkey csf6 'csf6'
setkey csf7 'csf7'
setkey csf8 'csf8'
setkey csf9 'csf9'
setkey csf10 'csf10'
setkey csf11 'csf11'
setkey csf12 'csf12'
setkey csf13 'csf13'
setkey csf14 'csf14'
setkey csf15 'csf15'
setkey csf16 'csf16'
setkey alt0 'alt0'
setkey alt1 'alt1'
setkey alt2 'alt2'
setkey alt3 'alt3'
setkey alt4 'alt4'
setkey alt5 'alt5'
setkey alt6 'alt6'
setkey alt7 'alt7'
setkey alt8 'alt8'
setkey alt9 'alt9'
setkey alt- 'alt-'
setkey alt= 'alt='
setkey alta 'alta'
setkey altb 'altb'
setkey altc 'altc'
setkey altd 'altd'
setkey alte 'alte'
setkey altf 'altf'
setkey altg 'altg'
setkey alth 'alth'
setkey alti 'alti'
setkey altj 'altj'
setkey altk 'altk'
setkey altl 'altl'
setkey altm 'altm'
setkey altn 'altn'
setkey alto 'alto'
setkey altp 'altp'
setkey altq 'altq'
setkey alts 'alts'
setkey altt 'altt'
setkey altu 'altu'
setkey altv 'altv'
setkey altw 'altw'
setkey altx 'altx'
setkey alty 'alty'
setkey altz 'altz'
!keyboard int9n		! numlock driver
!setkey numlock 'numlock'
endproc keyset

! reset all setkey settings

proc keyreset
keyboard int9		! install DOS keyboard driver
setkey home reset
setkey kp0 reset
setkey kp1 reset
setkey kp2 reset
setkey kp3 reset
setkey kp4 reset
setkey kp5 reset
setkey kp6 reset
setkey kp7 reset
setkey kp8 reset
setkey kp9 reset
setkey kp- reset
setkey kp, reset
setkey kp. reset
setkey kpr reset
setkey c-bs reset
setkey c-enter reset
setkey c-esc reset
setkey c-kp- reset
setkey c-kp+ reset
setkey c-kp* reset
setkey c-kpenter reset
setkey c-five reset
setkey kp* reset
setkey kp+ reset
setkey kp/ reset
setkey five reset
setkey scrlock reset
setkey pgdn reset
setkey c-pgdn reset
setkey pgup reset
setkey c-pgup reset
setkey c-home reset
setkey end reset
setkey c-end reset
setkey ins reset
setkey c-ins reset
setkey del reset
setkey c-del reset
setkey c-right reset
setkey c-left reset
setkey c-up reset
setkey c-down reset
setkey tab reset
setkey c-tab reset
setkey s-tab reset
setkey backtab reset
setkey print reset
setkey f1 reset
setkey f2 reset
setkey f3 reset
setkey f4 reset
setkey f5 reset
setkey f6 reset
setkey f7 reset
setkey f8 reset
setkey f9 reset
setkey f10 reset
setkey f11  reset
setkey f12 reset
setkey f13 reset
setkey f14 reset
setkey f15 reset
setkey f16 reset
setkey sf1 reset
setkey sf2 reset
setkey sf3 reset
setkey sf4 reset
setkey sf5 reset
setkey sf6 reset
setkey sf7 reset
setkey sf8 reset
setkey sf9 reset
setkey sf10 reset
setkey sf11 reset
setkey sf12 reset
setkey sf13 reset
setkey sf14 reset
setkey sf15 reset
setkey sf16 reset
setkey cf1 reset
setkey cf2 reset
setkey cf3 reset
setkey cf4 reset
setkey cf5 reset
setkey cf6 reset
setkey cf7 reset
setkey cf8 reset
setkey cf9 reset
setkey cf10 reset
setkey cf11 reset
setkey cf12 reset
setkey cf13 reset
setkey cf14 reset
setkey cf15 reset
setkey cf16 reset
setkey af1 reset
setkey af2 reset
setkey af3 reset
setkey af4 reset
setkey af5 reset
setkey af6 reset
setkey af7 reset
setkey af8 reset
setkey af9 reset
setkey af10 reset
setkey af11 reset
setkey af12 reset
setkey af13 reset
setkey af14 reset
setkey af15 reset
setkey af16 reset
setkey csf1 reset
setkey csf2 reset
setkey csf3 reset
setkey csf4 reset
setkey csf5 reset
setkey csf6 reset
setkey csf7 reset
setkey csf8 reset
setkey csf9 reset
setkey csf10 reset
setkey csf11 reset
setkey csf12 reset
setkey csf13 reset
setkey csf14 reset
setkey csf15 reset
setkey csf16 reset
setkey alt0 reset
setkey alt1 reset
setkey alt2 reset
setkey alt3 reset
setkey alt4 reset
setkey alt5 reset
setkey alt6 reset
setkey alt7 reset
setkey alt8 reset
setkey alt9 reset
setkey alt- reset
setkey alt= reset
setkey alta reset
setkey altb reset
setkey altc reset
setkey altd reset
setkey alte reset
setkey altf reset
setkey altg reset
setkey alth reset
setkey alti reset
setkey altj reset
setkey altk reset
setkey altl reset
setkey altm reset
setkey altn reset
setkey alto reset
setkey altp reset
setkey altq reset
setkey alts reset
setkey altt reset
setkey altu reset
setkey altv reset
setkey altw reset
setkey altx reset
setkey alty reset
setkey altz reset
!keyboard int9n		! numlock driver
!setkey numlock 'numlock'
endproc keyreset

! save current settings in .termsys

proc save
	wopen 4,7,sp,6,30
	wselect 4
	at 0,0 "     Saving setup file:"
	setvar disp_ts "["+tsfile+"]"
	setvar len_ts (28-(len(disp_ts)))/2
	if len_ts < 1
		setvar len_ts 0
		setvar disp_ts "[.." + right(disp_ts,25)
	endif
	at 1,len_ts disp_ts
	fseek 2,0
	fwriteln 2,'! Do NOT modify, add or delete lines between these markers: ******************'
	fwriteln 2,'! Communications Options'
	fwriteln 2,'portlist        '+zport
	fwriteln 2,'baud            '+zbaud
	fwriteln 2,'parity          '+zparity
	fwriteln 2,'wordlen         '+zwordlen
	fwriteln 2,'stopbits        '+zstopbit
	at 2,10 " 5% done"
	if opsys()>1 and opsys()<8
		fwriteln 2,'lockfile        '+zlockf
		fwriteln 2,'locktime        '+zlockt
	else
		fwriteln 2,'!lockfile       '+zlockf
		fwriteln 2,'!locktime       '+zlockt
	endi
	if ((toupper(zport) = '"MSNET:"' | toupper(zport) = '"NETBIOS:"') & opsys()=1)
		if trim(znetport) != ''
			fwriteln 2,'netport         '+znetport
		else
			fwriteln 2,'!netport        0'
		endi
		if trim(znetvt) != '""'
			fwriteln 2,'netvtname       '+znetvt
		else
			fwriteln 2,'!netvtname      '+znetvt
		endi
		if trim(znetdiag) != '""'
			fwriteln 2,'netdialog       '+znetdiag
		else
			fwriteln 2,'!netdialog      '+znetdiag
		endi
	else
		fwriteln 2,'!netport        '+znetport
		fwriteln 2,'!netvtname      '+znetvt
		fwriteln 2,'!netdialog      '+znetdiag
	endi
  fwriteln 2,'! Hardware Options'
	at 2,10 "10% done"
	if opsys()=1 & !iw
		fwriteln 2,'vidcard         '+zvidcard
		fwriteln 2,'vidout          '+zvidout
		fwriteln 2,'vidblink        '+zvidblink
		fwriteln 2,'vidunder        '+zvidund
		fwriteln 2,'keyboard        '+zkeyb
		fwriteln 2,'!setv _escloop  '+zescloop
		at 2,10 "15% done"
		fwriteln 2,'xonxoff         '+zxonxoff
		fwriteln 2,'!set eofopen    '+zeofopen
		fwriteln 2,'!set consxon    '+zconsxon
	elseif opsys()>1 and opsys()<8
		fwriteln 2,'!vidcard        '+zvidcard
		fwriteln 2,'!vidout         '+zvidout
		fwriteln 2,'!vidblink       '+zvidblink
		fwriteln 2,'!vidunder       '+zvidund
		fwriteln 2,'!keyboard       '+zkeyb
		fwriteln 2,'setv _escloop   '+zescloop
		at 2,10 "15% done"
		fwriteln 2,'xonxoff         '+zxonxoff
		fwriteln 2,'set eofopen     '+zeofopen
		fwriteln 2,'set consxon     '+zconsxon
	else
		fwriteln 2,'!vidcard        '+zvidcard
		fwriteln 2,'!vidout         '+zvidout
		fwriteln 2,'!vidblink       '+zvidblink
		fwriteln 2,'!vidunder       '+zvidund
		fwriteln 2,'!keyboard       '+zkeyb
		fwriteln 2,'!setv _escloop  '+zescloop
		at 2,10 "15% done"
		fwriteln 2,'xonxoff         '+zxonxoff
		fwriteln 2,'!set eofopen    '+zeofopen
		fwriteln 2,'!set consxon    '+zconsxon
	endi
	fwriteln 2,'protocol        '+zprot1
	if ( opsys()>1 and opsys()<8 and zcolnum = '8' ) | iw
		fwriteln 2,'!color number   '+zcolnum
	else
		fwriteln 2,'color number    '+zcolnum
	endi
	fwriteln 2,'! Keyboard Options'
	at 2,10 "20% done"
	if iw
		fwriteln 2,'!setkey         '+zmenu
	else
		fwriteln 2,'setkey          '+zmenu
	endi
	fwriteln 2,'setkey          '+zhelp
	fwriteln 2,'setkey          '+zgold
	if iw
		fwriteln 2,'!setkey         '+zshell
	else
		fwriteln 2,'setkey          '+zshell
	endi
	fwriteln 2,'setkey          '+zcapt
	fwriteln 2,'setkey          '+zprint
	at 2,10 "25% done"
	fwriteln 2,'setkey          '+zcompose
	fwriteln 2,'setkey          '+zcmd
	fwriteln 2,'setkey          '+zabort
	fwriteln 2,'setkey          '+zbreak
	fwriteln 2,'setkey          '+zsright
	fwriteln 2,'setkey          '+zsleft
	at 2,10 "30% done"
	fwriteln 2,'setkey          '+zslup
	fwriteln 2,'setkey          '+zsldn
	fwriteln 2,'setkey          '+zspup
	fwriteln 2,'setkey          '+zspdn
	fwriteln 2,'setkey          '+zscan
	fwriteln 2,'setkey          '+znews
	at 2,10 "35% done"
	fwriteln 2,'setkey          '+znexts
	fwriteln 2,'setkey          '+zgotos
	fwriteln 2,'setkey          '+zdiscs
	fwriteln 2,'! Terminal Options'
	fwriteln 2,'mode            '+zmode
	at 2,10 "40% done"
	fwriteln 2,'charset         '+zcharset
	fwriteln 2,'pages           '+zpages
	fwriteln 2,'scrollback      '+zscrback
	fwriteln 2,'addlf           '+zaddlf
	fwriteln 2,'addcr           '+zaddcr
	fwriteln 2,'set wrap        '+zwrap
	at 2,10 "50% done"
	fwriteln 2,'set maskpar     '+zmaskpar
	fwriteln 2,'set revdim      '+zrevdim
	fwriteln 2,'set tabex       '+ztabex
	fwriteln 2,'set noscroll    '+znoscroll
	fwriteln 2,'setv _turnchar  '+zturnchar
	fwriteln 2,'emulate         '+zemul
	fwriteln 2,'! Color Options'
	fwriteln 2,'color default   '+zcoldef
	at 2,10 "55% done"
	fwriteln 2,'color reverse   '+zcolrev
	if iw
		fwriteln 2,'!color bold     '+zcolbold
	else
		fwriteln 2,'color bold      '+zcolbold
	endi
	fwriteln 2,'color underline '+zcolund
	if iw
		fwriteln 2,'!color blink    '+zcolblink
	else
		fwriteln 2,'color blink     '+zcolblink
	endi
	fwriteln 2,'! Capture / Printer Options'
	fwriteln 2,'printer         '+zprinter
	at 2,10 "60% done"
	fwriteln 2,'capture         '+zcapture
	fwriteln 2,'protocol        '+zprot2
	fwriteln 2,'! Modem Options'
	fwriteln 2,'modem           '+zmodem
	fwriteln 2,'redial          '+zredial
	if opsys()=1
		fwriteln 2,'set ddtr        '+zddtr
		at 2,10 "65% done"
		fwriteln 2,'set exitdtr     '+zexitdtr
	else
		fwriteln 2,'!set ddtr       '+zddtr
		at 2,10 "65% done"
		fwriteln 2,'!set exitdtr    '+zexitdtr
	endi
	fwriteln 2,'dtimeout        '+zdtimeout
	fwriteln 2,'dinit           '+zdinit
	fwriteln 2,'dprefix         '+zdprefix
	fwriteln 2,'dsuffix         '+zdsuffix
	fwriteln 2,'doffhook        '+zdoffhook
	at 2,10 "70% done"
	fwriteln 2,'descape         '+zdesc
	fwriteln 2,'dautoans        '+zdans
	fwriteln 2,'dhangup         '+zdhangup
	fwriteln 2,'dokstr          '+zdok
	fwriteln 2,'dringstr        '+zdring
	fwriteln 2,'dconnect        '+zdconnect
	at 2,10 "75% done"
	fwriteln 2,'cdelay          '+zcdelay
	fwriteln 2,'! File Transfer Options'
	fwriteln 2,'xprot           '+zxprot
	fwriteln 2,'retries         '+zretries
	fwriteln 2,'restart         '+zrestart
	fwriteln 2,'set compress    '+zcompress
	at 2,10 "80% done"
	fwriteln 2,'set xferstat    '+zxferstat
	fwriteln 2,'set esc8bit     '+zesc8bit
	if opsys()=1
		fwriteln 2,'set addeof      '+zaddeof
	else
		fwriteln 2,'!set addeof     '+zaddeof
	endi
	fwriteln 2,'set toupper     '+ztoupper
	if zwildsize = '3584' | zwildsize = '0'
		fwriteln 2,'wildsize        '+zwildsize
	else
		fwriteln 2,'!wildsize       '+zwildsize
	endi
	fwriteln 2,'ldelay          '+zldelay
	at 2,10 "85% done"
	fwriteln 2,'lchar           '+zlchar
	if zitime = '0'
		fwriteln 2,'!itime          '+zitime
	else
		fwriteln 2,'itime           '+zitime
	endi
	if zhtime = '11'
		fwriteln 2,'!htime          '+zhtime
	else
		fwriteln 2,'htime           '+zhtime
	endi
	if zrtime = '10'	
		fwriteln 2,'!rtime          '+zrtime
	else
		fwriteln 2,'rtime           '+zrtime
	endi
	if zstime = '60'
		fwriteln 2,'!stime          '+zstime
	else
		fwriteln 2,'stime           '+zstime
	endi
	fwriteln 2,'! General Options'
	at 2,10 "90% done"
	if zlog = 'on'
		fwriteln 2,'logfile         '+zlogfile
	else
		fwriteln 2,'!logfile        '+zlogfile
	endi
	fwriteln 2,'set log         '+zlog
	if iw
		fwriteln 2,'!editor         '+zedit
	else
		fwriteln 2,'editor          '+zedit
	endi	
	fwriteln 2,'flags           '+zflags
	fwriteln 2,'wru             '+zwru
	fwriteln 2,'wruchar         '+zwruchar
	at 2,10 "95% done"
	fwriteln 2,'! Advanced Options'
	fwriteln 2,'setv            '+zkermeol
	if ztxwindow = '_txwindow 0'
		fwriteln 2,'!setv           '+ztxwindow
	else
		fwriteln 2,'setv            '+ztxwindow
	endi
	if ztxblk = '_txblksize 0'
		fwriteln 2,'!setv           '+ztxblk
	else
		fwriteln 2,'setv            '+ztxblk
	endi
	if zrcvsync = '_rcvsync 0'
		fwriteln 2,'!setv           '+zrcvsync
	else
		fwriteln 2,'setv            '+zrcvsync
	endi
	fwriteln 2,'set kermecho    '+zkermecho
	fwriteln 2,'set altchk      '+zaltchk
	if opsys()=1
		if toupper(zcom1base) != '0X3F8,4'
			fwriteln 2,'combase       1,'+zcom1base
		else
			fwriteln 2,'!combase      1,'+zcom1base
		endi
		if toupper(zcom2base) != '0X2F8,3'
			fwriteln 2,'combase       2,'+zcom2base
		else
			fwriteln 2,'!combase      2,'+zcom2base
		endi
		if toupper(zcom3base) != '0X3E8,4'
			fwriteln 2,'combase       3,'+zcom3base
		else
			fwriteln 2,'!combase      3,'+zcom3base
		endi
		if toupper(zcom4base) != '0X2E8,3'
			fwriteln 2,'combase       4,'+zcom4base
		else
			fwriteln 2,'!combase      4,'+zcom4base
		endi
		if toupper(zcom5base) != '0X2E8,4'
			fwriteln 2,'combase       5,'+zcom5base
		else
			fwriteln 2,'!combase      5,'+zcom5base
		endi
		if toupper(zcom6base) != '0X2E0,3'
			fwriteln 2,'combase       6,'+zcom6base
		else
			fwriteln 2,'!combase      6,'+zcom6base
		endi
	else
		fwriteln 2,'!combase      1,'+zcom1base
		fwriteln 2,'!combase      2,'+zcom2base
		fwriteln 2,'!combase      3,'+zcom3base
		fwriteln 2,'!combase      4,'+zcom4base
		fwriteln 2,'!combase      5,'+zcom5base
		fwriteln 2,'!combase      6,'+zcom6base
	endi
	if ((zemul = 'wyse50' | zemul = 'ib3101') & zblock = 'on')
		fwriteln 2,'set block       '+zblock
	else
		fwriteln 2,'!set block      '+zblock
	endi
	if zdo != 'noscript'
		fwriteln 2,'do              '+zdo
	else
		fwriteln 2,'!do             '+zdo
	endi
	fwriteln 2,'set bsdel       '+zbsdel
	fwriteln 2,'set exitdisc    '+zexitdisc
	if opsys() = 11
		if zterm = ''
			fwriteln 2,'!termtype       WYSE50'
		else
			fwriteln 2,'termtype        '+zterm
		endi
	else
		fwriteln 2,'!termtype       WYSE50'
	endi
	if isx | iw
		fwriteln 2,'set revmap      '+zrevmap
	else
		fwriteln 2,'!set revmap     '+zrevmap
	endi
	if iw
		fwriteln 2,'set altkeys     '+zaltkeys
		fwriteln 2,'set extend      '+zextwin
		fwriteln 2,'set scaling     '+zscale
	else
		fwriteln 2,'!set altkeys    '+zaltkeys
		fwriteln 2,'!set extend     '+zextwin
		fwriteln 2,'!set scaling    '+zscale
	endi
	if opsys() = 1 | opsys() = 8
		fwriteln 2,'set dimdim      '+zdimdim
	else
		fwriteln 2,'!set dimdim     '+zdimdim
	endi
	if isx | iw
		fwriteln 2,'jumpscroll      '+zjump
	else
		fwriteln 2,'!jumpscroll     '+zjump
	endi
	fwriteln 2,'! Do NOT add or delete lines above this marker: ******************************'
	if !tsmade
		fseek 1,tsfilepos
		repeat
			if !feof(1)
				freadln 1,x
				if x != ''
					fwriteln 2,x
				endi
			endi
		until feof(1)
	endi
	at 2,9 "100% done"
	at 3,2 ""
	pause Hit any key to continue
	wclose 4
endproc save

!====================================================================== 
! Begin actual setup process - main
!======================================================================

emulate vt100
release *

! get TERM version for compatibility of setup.cmd

noerr setv v _version
cls
! remove trailing blanks and newlines
setv xx pos("\r",v,1)
if xx != 0
	setv v left(v,xx-1)
endi
setv v trim(v)

setv iw false
setv isx false
setv typ 'IB'
setv vnum '6.2'

setv partcode midstr(v,len(v)-4,2)
if partcode = 'IW'
	setv iw true
endif

! What type of TERM? 

setv typ right(v,2)
if typ = 'FT' | typ = 'SP'
	setv netspec 'fs'
elseif typ = 'IW'
	setv netspec 'no'
	setv iw true
elseif typ = 'GN'
	setv netspec 'gn'
elseif typ = 'FR' | typ = 'M1' | typ = 'FU'
	setv netspec tolower(typ)
elseif typ = 'LA' | typ = 'TC' | typ = 'OP' | typ = 'RP' | typ = 'RO' | typ = 'S4' | typ = 'I6' | typ = 'H8' | typ = 'M8'
	setv netspec 'tc'
elseif typ = 'U3' | typ = 'I3' | typ = 'X3'
	setv netspec 'u3'
else
	setv netspec 'no'
endi

! new unix 6.2.2 consolidation
setv xx pos("SCO UNIX",v,1)
if xx != 0
	setv scou3 true
else
	setv scou3 false
endi

if toupper( midstr(v,len(v)-5,1) ) = 'X'
	setv isx true
else
	setv isx false
endi

! What is the version number?
setv vnumstart pos(" v",v,1)
setv vnum midstr(v,vnumstart+1,7)
setv vnum trim(vnum)
if vnum = '6.1.0' | vnum = '1.0.4e'
	setv ver 0
elseif vnum = '6.1.2' | vnum = '6.1.3'
	setv ver 1
elseif vnum = '1.0.5'
	setv ver 1
elseif vnum = '6.2'
! this should always be the case.
	setv ver 2
else
	setv ver 2
endi
cls

if ( opsys()=1 & !iw ) | isx
	color default 14,1	
	color reverse -1
	color dim 15,1
	color bold 15,1
	setv title 'dim'
elseif !iw
	setv title 'underline'
	!set revmap off
	color default 15,0
else
	setv title 'underline'
endi

setv net false
setv curdir false
setv termd trim( getenv( "TERMDIR"))
if right( termd, 1) != '/' | right( termd, 1) != '\\'
	setv termd termd+'/'
endi
if exists("./exists.txt")
	noerr erase ./exists.tst
endi
if exists("/usr/term/exists.tst")
	noerr erase /usr/term/exists.tst
endi
if exists( termd+"exists.tst")
	noerr erase $(termd)exists.tst
endi

fcreate 9,"./exists.tst"
fwriteln 9,"Temporary file to test for current dir for TERM software."
fclose 9
if exists( termd+"exists.tst") | exists("/usr/term/exists.tst")
	setv curdir true
endi
erase ./exists.tst
cls


if opsys()=0
! VMS:
	setv dwhere gethomedir()
	setv tsfile dwhere+"term.sys"
	setv tmsfile dwhere+"term.tmp"
	setv tbsfile dwhere+"term.bak"
	setv rcfile dwhere+"term.rc"
	setv rcbfile dwhere+"term.rcb"

elseif opsys()=9
! MAC:
	setv dwhere ""
	setv tsfile dwhere+"term.sys"
	setv tmsfile dwhere+"term.tmp"
	setv tbsfile dwhere+"term.bak"
	setv rcfile dwhere+"term.rc"
	setv rcbfile dwhere+"term.rcb"

elseif opsys()=1
! DOS:
	setv td trim(getenv("TERMDIR"))
	if exists("./term.sys")
		setv dwhere "./"
	elseif trim(td) != "" & isdir(td)
		setv dwhere trim(td)
	elseif isdir("/usr/term")
		setv dwhere "/usr/term/"
	else
		setv dwhere "./"
	endi
	if trim(td) != "" & isdir(td)
		setv rcwhere trim(td)
	elseif isdir("/usr/term")
		setv rcwhere "/usr/term/"
	else
		setv rcwhere "./"
	endi
	if right(rcwhere,1) != '/'
		setv rcwhere rcwhere+'/'
	endi
	if right(dwhere,1) != '/'
		setv dwhere dwhere+'/'
	endi
	setv tsfile  dwhere+"term.sys"
	setv tmsfile dwhere+"term.tmp"
	setv tbsfile dwhere+"term.bak"
	setv rcfile  rcwhere+"term.rc"
	setv rcbfile rcwhere+"term.rcb"

elseif opsys()=11
! SuperDOS
	setv td trim(getenv("TERMDIR"))
	if exists("term.sys")
		setv dwhere ""
	elseif trim(td) != "" & isdir(td)
		setv dwhere trim(td)
		if right(dwhere,1) != ':'
			setv dwhere "$(dwhere):"
		endi
	elseif isdir("5:0")
		setv dwhere "5:0:"
	else
		setv dwhere ""
	endi
	if trim(td) != "" & isdir(td)
		setv rcwhere trim(td)
		if right(rcwhere,1) != ':'
			setv rcwhere "$(rcwhere):"
		endi
	elseif isdir("5:0")
		setv rcwhere "5:0:"
	else
		setv rcwhere ""
	endi
	setv tsfile  dwhere+"term.sys"
	setv tmsfile dwhere+"term.tmp"
	setv tbsfile dwhere+"term.bak"
	setv rcfile  rcwhere+"term.rc"
	setv rcbfile rcwhere+"term.rcb"

elseif opsys()=8
! BTOS:
	setv td "[Sys]<term>"
	if exists("term.sys")
		setv dwhere ""
	elseif isdir(td)
		setv dwhere td
	else
		setv dwhere ""
	endi
	if isdir(td)
		setv rcwhere td
	else
		setv rcwhere ""
	endi
	setv tsfile  dwhere+"term.sys"
	setv tmsfile dwhere+"term.tmp"
	setv tbsfile dwhere+"term.bak"
	setv rcfile  rcwhere+"term.rc"
	setv rcbfile rcwhere+"term.rcb"

elseif opsys()>1 and opsys()<8
! UNIX: Also Xenix and everthing else
	if exists("./.termsys") and !curdir
		setv dwhere "./"
	else
		menu 2 close
		menu 2 open "TERM Version 6.2 Setup",2,24
		menu 2 entry "System wide defaults","Current Users defaults","Exit to System"
		repeat
			setv menu2 menu(2,0)
		until menu2 >= 1 and menu2 <= 3
		menu 2 close
		at 0,0 "\r"
		if menu2=3
			at 21,0
			? 
			return 1
		endi
		if menu2=2
			setv dwhere gethomedir()
			if dwhere=""
				cls
				! initial window
				wopen 5,2,20,5,35
				wselect 0
				at 2,25 "[TERM Version 6.2 Setup]"
				wselect 5
				at 0,0 "  Unable to find home directory"
				at 1,0 "        for current user"
				at 2,0 "           Quitting..."
				wselect 0
				at 10,0 ""
				return 1
			endi
		else
			setv dwhere getenv("TERMDIR")
			if dwhere=""
				setv dwhere "/usr/term/"
			endi
		endi
	endi

	setv td trim(getenv("TERMDIR"))
	if td != "" & isdir(td)
		setv rcwhere td
	elseif isdir("/usr/term")
		setv rcwhere "/usr/term/"
	else
		setv rcwhere "./"
	endi
	if right(rcwhere,1) != "/"
		setv rcwhere rcwhere+"/"
	endi
	if right(dwhere,1) != "/"
		setv dwhere dwhere+"/"
	endi
	setv tsfile dwhere+".termsys"
	setv tmsfile dwhere+".termtmp"
	setv tbsfile dwhere+".termbak"
	setv rcfile rcwhere+".termrc"
	setv rcbfile rcwhere+".termrcb"
	setv twhere rcwhere

else
	! initial window
	wopen 5,2,20,5,35
	wselect 0
	at 2,26 "[TERM Version 6.2 Setup]"
	wselect 5
	at 0,0 "  Setup not modified to work with"
	at 1,0 "        Operating System: $(opsys())"
	at 2,0 "           Quitting..."
	wselect 0	
	at 10,0 ""
	return 1
endi

! initial window
wopen 5,2,20,5,35
wselect 0
at 2,25 "[TERM Version 6.2 Setup]"
wselect 5
at 0,5 "  TERM Version $(vnum)  "
at 1,5 "      Format: $(typ)"

if !exists(tsfile)
	setv tsmade true
	iferror fcreate 1,tsfile
		do @clrwindow
		at 0,0 "  Cannot open TERM's setup file:"
		at 1,0 "  "+tsfile
		at 2,0 "  File exists or no access."
		wselect 0
		at 10,1 ""
		return
	endi
else
	setv tsmade false
	iferror fopen 1,tsfile
		do @clrwindow
		at 0,0 "  Cannot create TERM's setup file:"
		at 1,0 "  "+tsfile
		at 2,0 "  File exists or on access. "
		wselect 0
		at 10,0 ""
		return
	endi
endi

iferror fcreate 2,tmsfile	! output file
	do @clrwindow
	at 0,0 "  Cannot create termporary file:"
	at 1,0 "  "+tsfile
	at 2,0 "  File exists or no access. "
	wselect 0
	at 10,0 ""
	return
endi

! the order of occurance in this list MUST be reflected in the order in which
! the file is written out later.  Note that this list is what allows both
! the "fielding" of record via columns, and, as a result, fast read time.

dimstr zv 160
setv zv[0] 'zrem1'
setv zv[1] 'zrem2'
setv zv[2] 'zport'
setv zv[3] 'zbaud'
setv zv[4] 'zparity'
setv zv[5] 'zwordlen'
setv zv[6] 'zstopbit'
setv zv[7] 'zlockf'
setv zv[8] 'zlockt'
setv zv[9] 'znetport' 
setv zv[10] 'znetvt'
setv zv[11] 'znetdiag'
setv zv[12] 'zrem3'
setv zv[13] 'zvidcard'
setv zv[14] 'zvidout'
setv zv[15] 'zvidblink'
setv zv[16] 'zvidund'
setv zv[17] 'zkeyb'
setv zv[18] 'zescloop'
setv zv[19] 'zxonxoff'
setv zv[20] 'zeofopen'
setv zv[21] 'zconsxon'
setv zv[22] 'zprot1'
setv zv[23] 'zcolnum'
setv zv[24] 'zrem4'
setv zv[25] 'zmenu'
setv zv[26] 'zhelp'
setv zv[27] 'zgold'
setv zv[28] 'zshell'
setv zv[29] 'zcapt'
setv zv[30] 'zprint'
setv zv[31] 'zcompose'
setv zv[32] 'zcmd'
setv zv[33] 'zabort'
setv zv[34] 'zbreak'
setv zv[35] 'zsright'
setv zv[36] 'zsleft'
setv zv[37] 'zslup'
setv zv[38] 'zsldn'
setv zv[39] 'zspup'
setv zv[40] 'zspdn'
setv zv[41] 'zscan'
setv zv[42] 'znews'
setv zv[43] 'znexts'
setv zv[44] 'zgotos'
setv zv[45] 'zdiscs'
setv zv[46] 'zrem5'
setv zv[47] 'zmode'
setv zv[48] 'zcharset'
setv zv[49] 'zpages'
setv zv[50] 'zscrback'
setv zv[51] 'zaddlf'
setv zv[52] 'zaddcr'
setv zv[53] 'zwrap'
setv zv[54] 'zmaskpar'
setv zv[55] 'zrevdim'
setv zv[56] 'ztabex'
setv zv[57] 'znoscroll'
setv zv[58] 'zturnchar'
setv zv[59] 'zemul'
setv zv[60] 'zrem6'
setv zv[61] 'zcoldef'
setv zv[62] 'zcolrev'
setv zv[63] 'zcolbold'
setv zv[64] 'zcolund'
setv zv[65] 'zcolblink'
setv zv[66] 'zrem7'
setv zv[67] 'zprinter'
setv zv[68] 'zcapture'
setv zv[69] 'zprot2'
setv zv[70] 'zrem8'
setv zv[71] 'zmodem'
setv zv[72] 'zredial'
setv zv[73] 'zddtr'
setv zv[74] 'zexitdtr'
setv zv[75] 'zdtimeout'
setv zv[76] 'zdinit'
setv zv[77] 'zdprefix'
setv zv[78] 'zdsuffix'
setv zv[79] 'zdoffhook'
setv zv[80] 'zdesc'
setv zv[81] 'zdans'
setv zv[82] 'zdhangup'
setv zv[83] 'zdok'
setv zv[84] 'zdring'
setv zv[85] 'zdconnect'
setv zv[86] 'zcdelay'
setv zv[87] 'zrem9'
setv zv[88] 'zxprot'
setv zv[89] 'zretries'
setv zv[90] 'zrestart'
setv zv[91] 'zcompress'
setv zv[92] 'zxferstat'
setv zv[93] 'zesc8bit'
setv zv[94] 'zaddeof'
setv zv[95] 'ztoupper'
setv zv[96] 'zwildsize'
setv zv[97] 'zldelay'
setv zv[98] 'zlchar'
setv zv[99] 'zitime'
setv zv[100] 'zhtime'
setv zv[101] 'zrtime'
setv zv[102] 'zstime'
setv zv[103] 'zrem10'
setv zv[104] 'zlogfile'
setv zv[105] 'zlog'
setv zv[106] 'zedit'
setv zv[107] 'zflags'
setv zv[108] 'zwru'
setv zv[109] 'zwruchar'
setv zv[110] 'zrem11'
setv zv[111] 'zkermeol'
setv zv[112] 'ztxwindow'
setv zv[113] 'ztxblk'
setv zv[114] 'zrcvsync'
setv zv[115] 'zkermecho'
setv zv[116] 'zaltchk'
setv zv[117] 'zcom1base'
setv zv[118] 'zcom2base'
setv zv[119] 'zcom3base'
setv zv[120] 'zcom4base'
setv zv[121] 'zcom5base'
setv zv[122] 'zcom6base'
setv zv[123] 'zblock'
setv zv[124] 'zdo'
setv zv[125] 'zbsdel'
setv zv[126] 'zexitdisc'
setv zv[127] 'zterm'
setv zv[128] 'zrevmap'
setv zv[129] 'zaltkeys'
setv zv[130] 'zextwin'
setv zv[131] 'zscale'
setv zv[132] 'zdimdim'
setv zv[133] 'zjump'
setv zv[134] 'zrem12'

do @setdef

! read in term.sys

setv n 0
setv badtsfile false
do @clrwindow
if !tsmade
	at 0,0 "     Reading old setup file:"
	setvar disp_ts "["+tsfile+"]"
	setvar len_ts (32-(len(disp_ts)))/2
	if len_ts < 1
		setvar len_ts 0
		setvar disp_ts "[.." + right(disp_ts,29)
	endif
	at 1,len_ts disp_ts
	at 2,4 "        1 % done"
	repeat
		if !feof(1)
			freadln 1,x		! throws away cr's
			if trim(x) = ''
				! no empty lines
				setv badtsfile true
			else
				setv $(zv[n]) trim( midstr(x,17,80))
			endi
			setv n n+1
		endi
		setv per (n)/2
		at 2,12 "$(per)"
	until feof( 1) | n=135
	setv tsfilepos ftell(1)
else
	at 0,0 "    Creating new setup file:"
	setvar disp_ts "["+tsfile+"]"
	setvar len_ts (32-(len(disp_ts)))/2
	if len_ts < 1
		setvar len_ts 0
		setvar disp_ts "[.." + right(disp_ts,29)
	endif
	at 1,len_ts disp_ts
	at 2,12 "25% done"
	wait 1
endi
at 2,12 "75"
setv per 75

! get modem dialer list

dimstr dialname 20
dimstr dialfile 20
setv count 0
for file in ($(twhere)mdm*.cmd) do
	setv count count+1
	if count <= 20
		fopen count+2,'$(file)'
		freadln count+2,nameline
		setv namestart pos("&>>","$(nameline)",1)
		setv nameend pos("<<","$(nameline)",1)
		setv fnamestart pos("mdm","$(file)",1)
		setv fnamelen len("$(file)")
		if namestart != 0
			setv dialfile[count-1] midstr("$(file)",fnamestart,fnamelen)
			setv dialname[count-1] midstr("$(nameline)",namestart+3,nameend-namestart-3)
			if len(dialname[count-1]) > 20
				setv dialname[count-1] left(dialname[count-1],20)
			endi
		endi
		fclose count+2
	endi
	setv per per+1
	at 2,12 "$(per)"
endfor

setv mdmlist "\'HAYES\'"
setv count 0
setv toolong false
repeat
	if dialname[count] != ''
		setv omdmlist mdmlist
		setv mdmlist mdmlist+',\'$(dialname[count])\''
		if len("$(mdmlist)") >= 255
			setv mdmlist omdmlist
			setv toolong true
		endi
	endi
	setv count count+1
until count = 20 | toolong
at 2,11 "100"
wait 1

! do user interaction after all timetaking tasks
! to check for invalid/corrupted termsys file, check the comments

if !tsmade
	if (zrem1 != ' add or delete lines between these markers: ******************') | (zrem12 != 'delete lines above this marker: ******************************')
		setv badtsfile true
	elseif (zrem2 != ' Options') | (zrem3 != 'ns') | (zrem4 != 'ns') | (zrem5 != 'ns') | (zrem7 != 'ter Options') | (zrem9 != 'Options') | (zrem10 != 's') | (zrem11 != 'ns')
		setv badtsfile true
	endi
endi

if badtsfile
	do @clrwindow
	at 0,0 "   Setup file seems corrupted"
	setvar disp_ts "["+tsfile+"]"
	setvar len_ts (32-(len(disp_ts)))/2
	if len_ts < 1
		setvar len_ts 0
		setvar disp_ts "[.." + right(disp_ts,29)
	endif
	at 1,len_ts disp_ts
	at 2,0 "  Continue with defaults(y/n)?"
	repeat
	setv rsp toupper( chrin())
	until ( rsp = 'Y' | rsp = 'N' )
	if rsp!="Y"
		wclose 5
		cls
		? "\r\n\r\nYou may want to delete "+tsfile+" and then regenerate it"
		? "by running this program.  This will uncorrupt the file."
		return
	endi
		? rsp;
		! if termsys seemed corrupted, default all to avoid indexing problems.
		do @setdef
endi

wclose 5
release zv
cls
menu 1 close
menu 1 open "  Setup Options ",2,2
menu 1 entry "Communications","Hardware","Keyboard","Terminal","cOlors","captUre","Printer","Modem settings","File transfer","General","Advanced options","Save settings","Return to TERM","Exit to system"
cls

! welcome screen

if opsys()=1
	attr dim
endi
at 2,26 "This  setup  utility will allow you to quickly  and"
at 3,26 "easily configure TERM to your specific needs.  Your"
at 4,26 "selections here will become the default  parameters"
at 5,26 "whenever you start TERM."
at 7,26 "If you need to modify the factory default settings,"
at 8,26 "select  the  menu  option  requiring change and set"
at 9,26 "your  parameters.   If you are not sure of  what  a"
at 10,26 "parameter controls,  see your  TERM  documentation."
at 12,26 "After  you  have  made  your  changes,  select  the"
at 13,26 "'Save Settings'  option  to save them.   To  return"
at 14,26 "to TERM with the new settings,  select the  'Return"
at 15,26 "to TERM'  option.  To exit to the operating system,"
at 16,26 "select the  'Exit to System'  option."
if iw
	at 19,2 "Single mouse button click or cursor keys highlight option"
	at 20,2 "Double click, capitalized letter or enter selects option"
else
	at 19,2 "Cursor keys highlight option"
	at 20,2 "Captalized letter or Enter selects option"
endif
attr default

setv done false
setv saved true 
setv written false
setv vidcust false
setv sp 30
repeat
setv ret false
setv menu1 menu(1,0)
switch
	case menu1=1
		menu 1 off
		do @comm
	case menu1=2
		menu 1 off
		do @hardware
	case menu1=3
		menu 1 off
		do @key
	case menu1=4
		menu 1 off
		do @term
	case menu1=5
		menu 1 off
		do @color
	case menu1=6
		menu 1 off
		do @capt
	case menu1=7
		menu 1 off
		do @prn
	case menu1=8
		menu 1 off
		do @modem
	case menu1=9
		menu 1 off
		do @file
	case menu1=10
		menu 1 off
		do @general
	case menu1=11
		menu 1 off
		do @advanced
	case menu1=12
		setv sp 30
		do @save
		setv saved true
		setv written true
	case menu1=13
		menu 1 off
		setv ret true
	default
		menu 1 off
	endswitch
until menu1 > 12

cls
if !saved
	? "\r\r\n               Settings not saved!  Save before exiting (y/n)? ";
	repeat
		setv rsp toupper( chrin())
	until ( rsp = 'Y' | rsp = 'N' )
	? rsp;
	if rsp = "Y"
		setv sp 25
		do @save
		setv saved true
		setv written true
	else
	? "\r\n                          Settings left unchanged."	
	endi
endi

if written
	fclose 1
	fclose 2
	if exists(tsfile)
		noerr rename $tsfile $tbsfile overwrite
	endi
	noerr rename $tmsfile $tsfile
else
	fclose 1
	fclose 2
	erase $tmsfile
	if tsmade
		erase $tsfile
	endi
endi
	
! remove startup message

if exists(rcfile)
	fopen 3,rcfile
	freadln 3,rcline1
	fclose 3
	if pos('Startup TERM.RC',rcline1,1) != 0
        noerr rename $rcfile $rcbfile
	endi
endi

if ret
	do $(tsfile)
	menu 1 close
	menu 2 close
	menu 3 close
	release *
	return
else
	quit
endi
