!----------------------------------------------------------------------------
!  server.cmd ---- 6.2.5  Copyright 1989-1994 Century Software Inc.
!                                                                    
!                                                                    
!  server.cmd is a file transfer interface menu for those calling
!    into this computer from other sites.  It allows transfer of files
!    using xmodem, ymodem, zmodem, or kermit, along with Century 
!    Software's own TermCRC and WTermCRC transfer protocols.  Files
!    are automatically converted between Unix and Dos (and VMS and
!    Mac) formats, if necessary.
!                                                                    
!  To run, from a remote login execute:
!	term -x server
!             
!  Optionally, create a login specifically for those needing to 
!    transfer files to this site, and include the above line in
!    that user's .profile file.
!
!  2/94 v6.2 General re-write, added zmodem, x-1K, and options menu
!  9/91 v6.2 Enhanced to run from command line
!  2/91 v6.2 Allow multiple file transfer, also made help 'nice'
!
!  Notes:
!		Unformatted receives
!			<CR><LF> pairs may not be handled exactly as you expect
!			them to be.  Incoming <CR>'s are translated to <LF>'s
!			and incoming <LF>'s ignored on Unix, opposite on DOS.
!			this allows correct line termination on all operating
!			systems.
!		Unformatted sends 
!			All unformatted sends are sent delimited by the line
!			terminators <CR> and <LF>
!		File conversion
!			Except on unformatted stuff (where it's rather kinda
!			automatic), text file conversion must be asked for to
!			occur.  In addition, options only effect files which
!			are received; conversion can only be done by a file's
!			receiver logically anyway, but this can be overlooked
!			and cause strange-looking files.  To guarantee the
!			results, use TERM on the receiving end.
!
!		Common problem resolutions, uncomment the line needed:
!
!		for 7 bit connections (wtermcrc & zmodem transfers only)
!set esc8bit on
!
!		for alternate kermit checksum
!set altchk on
!
!		for a larger memory slot for wildcard filename expansion
!wildsize 8196
!
!		To increase or decrease TERM's timeouts for file transfers
!		Current settings are defaults.
!		htime is the initial handshake timeout
setvar  h_time 30
htime $(h_time)
!
!		rtime is the receive packet timeout
rtime 5
!
!		stime is the send packet timeout
stime 5
!		retries is the number of packet retries
retries 6
!
on abort
	xmit "\r\naborted...\r\n"
	quit
endon

if opsys() > 1
	ignore input "\n"
	trans input "\r" "\n"
endif

! "clear" screen
proc clr
	xmit "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
endproc clr

!
! Name:       waitkey
! Purpose:    Give a "hit any key to continue" message and wait for a key...
! Parameters: string - allows for personal prompt 
!
proc waitkey
	setvar prompt '$1'
	setvar key_in '\r'
	xmit "\r\n       Hit any key to continue$(prompt)"
	setvar key_in chr(asc(comin())&127)
	xmit "\r\n\r\n"
endproc

!
! Name:       getfname
! Purpose:    get a filename from, and echo it out to, the com port
! Parameters: 0, 1, 2, or 3
!             0 - receive filename required
!             1 - receive filename or filenames required
!             2 - send filename or filenames required
!             3 - send filename required
!
proc getfname
	setvar option $1
	repeat			! until flname is correct
		if option < 4
			xmit "\r\n       Use forward slashes (/) not backslashes (\\) to designate pathnames.\r\n"
		else
			setvar option (option&3)
		endif
		if option = 0
			xmit "\r\n       What is the name of the destination file? "
			xmit "\r\n        "
		elseif option = 1
			xmit "\r\n       What is the name of the destination directory (or file)? "
			xmit "\r\n        "
		elseif option = 2
			xmit "\r\n       What is the name of the file(s) to send (wildcards ok)? "
			xmit "\r\n        "
		elseif option = 3
			xmit "\r\n       What is the name of the file to send? "
			xmit "\r\n        "
		endif
		do @echoin flname T F
		if flname=""
			return
		elseif exists(flname)
			if option = 0 | option = 1
				xmit "\r\n       That file already exists... overwrite? (Y/N) "
				repeat
					setvar x toupper(chr(asc(comin())&127))
					if x!="Y" & x!="N"
						xmit "\007"
					endif
				until (x="Y") | (x="N")
				if x="N"
					xmit "No\r\n"
					wait 1
					setvar okname false
				else
					xmit "Yes\r\n"
					wait 1
					setvar okname true
				endif
			else
		    	setvar okname true
		    endif
		else
			setvar okname true
		endif
	until okname
endproc

!
! Name:       echoin
! Purpose:    Input character string until return executed up to 78 chars,
!             Echo or don't them back down the line ---- allow editing:
!             <DEL> or <BS> backs up one char.
! Parameters: variable to be set, boolean: t=echo, boolean: t=toupper
!
proc echoin
	setvar inval ""
	repeat
		setvar incr chr(asc(comin())&127)
		if $3
			setvar incr toupper(incr)
		endif
		if incr="\010" | incr="\177"
			if len(inval)>0
				if $2
					xmit "\010 \010"
				endif
				setvar inval left(inval,len(inval)-1)
			else
				xmit "\007"
			endif
		elseif incr>=" " & incr<"\177"
 			if incr="\\"
 				setvar incr "/"
 			endif
			if len(inval)<60
				setvar inval inval+incr
				if $2
					xmit "$(incr)"
				endif
			else
				xmit "\007"
			endif
		elseif incr!="\r"
			xmit "\007"
		endif
	until incr="\r"
	setvar $1 inval
endproc

!
! Name:       help 
! Purpose:    duh!?
! Parameters: none
!
proc help
repeat
	setvar help 0
	do @clr
	xmit "                  ________________________________________\r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  I would like an explanation on...     |\r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  [h]  How to use TERM server           |\r\n"
	xmit "                 |  [p]  Common Problems, Troubleshooting |\r\n"
	xmit "                 |  [t]  TERMCRC protocol                 |\r\n"
	xmit "                 |  [w]  WTERMCRC and Zmodem protocols    |\r\n"
	xmit "                 |  [x]  Xmodem protocol                  |\r\n"
	xmit "                 |  [c]  Xmodem-CRC protocol              |\r\n"
!	xmit "                 |  [1]  Xmodem-1K protocol               |\r\n"
	xmit "                 |  [y]  Ymodem protocol                  |\r\n"
	xmit "                 |  [k]  Kermit protocol                  |\r\n"
	xmit "                 |  [u]  Unformatted file transfers       |\r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  [a]  All help screens                 |\r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  [q]  Quit to Main Menu                |\r\n"
	xmit "                 |________________________________________|\r\n"
	xmit "\r\n\r\n                           Enter Your Selection:"
	flush
	setvar okval false
	repeat
	setvar cval toupper(chr(asc(comin())&127))
	setvar okval true
	switch
		case cval = 'A'
			setvar help 0
		case cval = 'H'
			setvar help 1
		case cval = 'P'
			setvar help 2
		case cval = 'T'
			setvar help 3
		case cval = 'W'
			setvar help 4
		case cval = 'K'
			setvar help 5
		case cval = 'X'
			setvar help 6
		case cval = 'C'
			setvar help 7
!		case cval = '1'
!			setvar help 8
		case cval = 'Y'
			setvar help 9
		case cval = 'U'
			setvar help 11
		case cval = 'Q'
			setvar help 12
		default
			setvar okval false
	endswitch
		if !okval
			xmit "\007"
		endif
	until okval
xmit "\r\n\r\n"
if help = 0 | help = 1
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                   How to use TERM server                     |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Using the TERM server script is very easy.  First, you select|\r\n"
	xmit "      | the protocol you wish to do file transfers with.  If you are |\r\n"
	xmit "      | not sure which protocol to use, the next few help screens    |\r\n"
	xmit "      | will explain the menu choices.  After you have chosen a      |\r\n"
	xmit "      | protocol, TERM server will ask you which direction you wish  |\r\n"
	xmit "      | to transfer files.  If you are going to send files to TERM   |\r\n"
	xmit "      | server (me) choose 'Upload.'  If you want TERM server (me)   |\r\n"
	xmit "      | to send you files, choose 'Download.'  If you have chosen    |\r\n"
	xmit "      | the wrong protocol by mistake, choose 'Neither' to return to |\r\n"
	xmit "      | the main menu.  After specifying the direction of the file   |\r\n"
	xmit "      | transfer, you are then asked for directory or file names. If |\r\n"
	xmit "      | you are uploading, you are asked for the directory or        |\r\n"
	xmit "      | filename you wish the uploaded file(s) to go into.  If you   |\r\n"
	xmit "      | are downloading, you are asked for the filename(s) to        |\r\n"
	xmit "      | download.  After telling TERM server this information, you   |\r\n"
	xmit "      | will have approximately 30 seconds to start the file transfer|\r\n"
	xmit "      | on your side.  To avoid having to redo this procedure, you   |\r\n"
	xmit "      | should have the steps to start your communications package   |\r\n"
	xmit "      | file transfer readily available.                             |\r\n"
	xmit "      |______________________________________________________________|"
	do @waitkey " or q to return to the main menu."
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 2)
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                 If you're having problems                    |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | If you are getting CRC or checksum errors, you may be using  |\r\n"
	xmit "      | the wrong protocol.  Usually this problem will occur if you  |\r\n"
	xmit "      | are using Xmodem-CRC and have chosen Xmodem or vice-versa.   |\r\n"
	xmit "      | Another cause of CRC errors in xmodem and other file transfer|\r\n"
	xmit "      | protocols is flow control.  This can be RTS/CTS, XON/XOFF, or|\r\n"
	xmit "      | MNP. If possible, turn off flow control.  Flow control occurs|\r\n"
	xmit "      | in modems and multiport cards.  Find the manual on your modem|\r\n"
	xmit "      | and/or multiport card, and turn off XON/XOFF and MNP.  This  |\r\n"
	xmit "      | helps increase file transfer efficency, especially with      |\r\n"
	xmit "      | TERMCRC and WTERMCRC.                                        |\r\n"
	xmit "      | You may have file transfer problems if you are connected over|\r\n"
	xmit "      | a 7-bit line.  Many protocols (include TERMCRC and WTERMCRC) |\r\n"
	xmit "      | use all 8 bits in the file transfer.  To tell TERM to use the|\r\n"
	xmit "      | protocols correctly over a 7-bit line, you must edit the     |\r\n"
	xmit "      | server.cmd script (usually in /usr/term) and uncomment the   |\r\n"
	xmit "      | line '!set esc8bit on' by removing the '!'.                  |\r\n"
	do @waitkey " or q to return to the main menu."
	if toupper(key_in) = 'Q'
		return
	endif
	xmit "      | Some kermit protocols use an alternate checksum.  To use     |\r\n"
	xmit "      | this for TERM's kermit, you must uncomment the line          |\r\n"
	xmit "      | '!set altchk on' by removing the '!'.                        |\r\n"
	xmit "      | If you are using wildcard filenames for a large number of    |\r\n"
	xmit "      | files, you may need to increase TERM's memory expansion size |\r\n"
	xmit "      | for wildcard filenames.  You can do this by uncomment the    |\r\n"
	xmit "      | line '!wildsize 3584' by removing the '!'.  The default in   |\r\n"
	xmit "      | TERM is 3584, you will need to increase the number.          |\r\n"
	xmit "      | If everything seems to be setup correctly, and the file      |\r\n"
	xmit "      | transfer seems to be aborting, it may be a timeout setting.  |\r\n"
	xmit "      | You can change TERM's timeouts by uncommenting the line      |\r\n"
	xmit "      | '!htime 30' or '!rtime 20' or '!stime 10' whichever seems    |\r\n"
	xmit "      | appropriate.                                                 |\r\n"
	xmit "      | Another major cause of transfer aborting is permissions.     |\r\n"
	xmit "      | You must have permissions to read the file(s) and directory  |\r\n"
	xmit "      | to be able to transfer them.                                 |\r\n"
	xmit "      | Also, make sure the file(s) exists!                          |\r\n"
	xmit "      | These lines are near the top of the server.cmd file for easy |\r\n"
	xmit "      | reference.  If you uncomment or change one, please change it |\r\n"
	xmit "      | back, or make a note of it for the next TERM server user.    |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey " or q to return to the main menu."
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 5)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                       [k] - Kermit                           |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Do file transfer using kermit protocol.  If your program     |\r\n"
	xmit "      | uses kermit protocol, use this option.  Kermit is a 7-bit    |\r\n"
	xmit "      | transfer protocol developed by Columbia University.  Most    |\r\n"
	xmit "      | programs that use kermit are named kermit. If the program    |\r\n"
	xmit "      | you are using is named kermit or it transfers it's files     |\r\n"
	xmit "      | using kermit protocol, use this option.                      |\r\n"
	xmit "      |______________________________________________________________|\r\n"
		do @waitkey " or q to return to the main menu."
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 6)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                    [x] - Xmodem Checksum                     |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Do file transfers using xmodem protocol.  If your program    |\r\n"
	xmit "      | uses xmodem protocol checksum error checking then use this   |\r\n"
	xmit "      | option.  Xmodem is an 8 bit protocol.                        |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey " or q to return to the main menu."
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 7)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [c] - Xmodem CRC                        |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Do file transfers using xmodem protocol.  If your program    |\r\n"
	xmit "      | uses xmodem protocol CRC error checking then use this option.|\r\n"
	xmit "      | This Xmodem is also an 8 bit protocol.                       |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 8)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [1] - Xmodem-1K                         |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | While TERM does not overtly support Xmodem-1K, it can be     |\r\n"
	xmit "      | fooled into accepting an Xmodem-1k upload.  To do this,      |\r\n"
	xmit "      | choose a Ymodem upload and enter the filename.  Then use      |\r\n"
	xmit "      | your local com package to send the file via xmodem-1X.       |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 9)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                        [y] - Ymodem                          |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Do file transfers using the Ymodem protocol.  This protocol  |\r\n"
	xmit "      | provides full support of the Ymodem specification, which     |\r\n"
	xmit "      | includes *.* (wildcards) batch file transfers, and 1024      |\r\n"
	xmit "      | byte packets.                                                |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 3)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [t] - TERMCRC                           |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Do file transfers using new TERMCRC protocol. For fast error |\r\n"
	xmit "      | checked transfers of any type of file, use this option.      |\r\n"
	xmit "      | TERMCRC protocol will automatically convert text and source  |\r\n"
	xmit "      | files for immediate use coming from MS-DOS, Xenix, CP/M, and |\r\n"
	xmit "      | any other operating system to this operating system, if      |\r\n"
	xmit "      | needed. This means you can send up all your source files and |\r\n"
	xmit "      | recompile your programs with little or no modification,      |\r\n"
	xmit "      | saving many hours in an editor 'fixing' the ends of lines.   |\r\n"
	xmit "      | TERMCRC protocol also allows you to transfer binary image    |\r\n"
	xmit "      | files with no additional work on your part once they've been |\r\n"
	xmit "      | moved... for example if you had an Altos 886 or 2086 and you |\r\n"
	xmit "      | wanted to use one of your programs on an IBM AT which was    |\r\n"
	xmit "      | running SCO Xenix or IBM UNIX, you could use the TERMCRC     |\r\n"
	xmit "      | protocol, and in most cases the progam would run without     |\r\n"
	xmit "      | recompiling!  TERMCRC also supports compression to increase  |\r\n"
	xmit "      | the efficiency of your file transfer.                        |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 4)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                 [w] - WTERMCRC and Zmodem                    |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | WTERMCRC and Zmodem file transfers both use TERMs Server     |\r\n"
	xmit "      | abilities to transfer files.  When choosing either of thest  |\r\n"
	xmit "      | options, the Server is started up.  From this point you may  |\r\n"
	xmit "      | use your local TERM system to initiate WTERMCRC uploads      |\r\n"
	xmit "      | and/or downloads.  You may also use your local TERM or       |\r\n"
	xmit "      | other com packages' Zmodem to initiate uploads and/or         |\r\n"
	xmit "      | downloads.                                                   |\r\n"

	xmit "      | When a file transfer is complete, Server is still active.    |\r\n"
	xmit "      | You may at this point transfer more files or exit Server.    |\r\n"
	xmit "      | To exit the Server, hit Ctrl-X 5 times.                      |\r\n"
	xmit "      | These two file transfer protocols have advantages of being   |\r\n"
	xmit "      | able to transfer over networks, and being able to transfer   |\r\n"
	xmit "      | multiple packets without having wo wait for each packet's    |\r\n"
	xmit "      | confirmation.  WTERMCRC always supports data compression,    |\r\n"
	xmit "      | TERM's Zmodem always does, other com packages Zmodems may.   |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
if (help = 0 | help = 11)
	do @clr
	xmit "       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |              [u] - Unformatted File Transfers                |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      | Transfer files without a protocol.  If you are talking to    |\r\n"
	xmit "      | a modem, such as the RACAL/VADIC 9600, an error checked      |\r\n"
	xmit "      | network, or you for some reason do not want to do error      |\r\n"
	xmit "      | checking, you use this option.  While the first two cases    |\r\n"
	xmit "      | let the hardware do the error checking for you, it is not    |\r\n"
	xmit "      | noticibly faster (and in some cases slower) than using an    |\r\n"
	xmit "      | errorchecked protocol on top... In any case, if you use an   |\r\n"
	xmit "      | errorchecked protocol too, you are just that much more       |\r\n"
	xmit "      | likely to not have any errors.  The important part is that   |\r\n"
	xmit "      | it lets you send and receive files even if the other computer|\r\n"
	xmit "      | HAS NO COMMUNICATION SOFTWARE!  While it is not recommended  |\r\n"
	xmit "      | for binary files, on most computer systems you can call up   |\r\n"
	xmit "      | and copy from the console (the place you are logged into) to |\r\n"
	xmit "      | a file... also you can display a file to the screen and save |\r\n"
	xmit "      | it that way.  If you wanted to do one of these things, or if |\r\n"
	xmit "      | you wanted to hook a printer up and print from one machine   |\r\n"
	xmit "      | to a file on another machine, this is the option to use.     |\r\n"
	xmit "      |______________________________________________________________|\r\n"
	do @waitkey ' or q to return to the main menu.'
	if toupper(key_in) = 'Q'
		return
	endif
endif
	if help = 12
 		return
	endif
	xmit "\r\n\r\n\r\n"
until false
endproc help

!
! Name:       fsend
! Purpose:    send file(s) loop
! Parameters: 0 or 1
!             0 - non multiple file transfer protocol - use for loop
!             1 - multiple file transfer protocol - use single send line
!
proc fsend
	setvar option $1
	setvar err 0
	if option = 1
		wait 3
		iferror send $(flname)
			setvar err err+1
		endif
	else
		for file in ($(flname)) do
			iferror send $(file)
				setvar err err+1
			endif
			if err > 3
				return
			endif
		endfor
	endif
endproc fsend

!
! Name:       sendget
! Purpose:    transfer a file with preselected or no protocol
! Parameters:	0 or 1
!             1 - use send, rcv  
!             0 - use usend, capture
!
proc sendget
  xmit "\r\n       Upload to TERM server, Download to you, Neither (U/D/N)? "
	repeat
		setvar x toupper(chr(asc(comin())&127))
		if x="\r"
			setvar x "N"
		endif
		if x!="U" & x!="D" & x!="N"
			xmit "\007"
		endif
	until (x="U") | (x="D") | (x="N")
	switch
	case x="D"
		xmit "\r\n                               D O W N L O A D\r\n"
		if multiple
			do @getfname 2
		else
			do @getfname 3
		endif
		if flname=""
			do @canceled
			return
		endif
		xmit "\r\n       Your machine must do file conversion if needed\r\n"
		xmit "       You have $(h_time) seconds to begin receiving...\r\n"
		if $1=0
			if multiple
				do @fsend 1
			else
				do @fsend 0
			endif
			if err > 0
				xmit "\r\n       Errors occured - file(s) not sent properly\r\n"
				do @waitkey ''
				return
			endif
		else
			wait $(h_time)		! wait then send
			addcr on
			iferror usend $flname
				addcr off
				xmit "       Error: file not sent properly\r\n"
				xmit "       Make sure file exists!\r\n"
				do @waitkey
				return
			endif
			addcr off
			do @waitkey
		endif
		xmit "       Transmission complete.\r\n\r\n"
		do @waitkey
	case x="U"
		xmit "\r\n                                 U P L O A D\r\n"
		if multiple
			do @getfname 1
		else
			do @getfname 0
		endif
		if flname=""
			do @canceled
			return
		endif
		xmit "\r\n       You have $(h_time) seconds to begin sending...\r\n"
		if $1=0
			! (c) to do automatic file conversion if needed.
			iferror rcv $flname(c)
				xmit "       Error: file not received!\r\n"
				xmit "       Send within time window,\r\n"
				xmit "       Make sure you have write permission,\r\n"
				xmit "       Make sure the directory specification is valid.\r\n"
				do @waitkey
				return
			endif
		else
			xmit "       Type \^D (control-D) when done\r\n"
			capture file $flname[o]
			capture on
			dwait "^D",$(h_time)
			if _timeout
				xmit "\r\n       $(h_time) seconds quiet... timed out\007\r\n"
				wait 1
				do @waitkey
				return
			endif
! WARNING: places ^D in last line (incomplete end of line)
			capture close
		endif
		xmit "       File received.\r\n\r\n"
		do @waitkey
	default			! neither
		xmit "\r\n                                N E I T H E R\r\n"
		do @waitkey
		return
	endswitch
endproc sendget


proc canceled
	xmit "\r\n                               << CANCELLED >>\r\n"
	do @waitkey ''
endproc canceled

setvar noquit "$1"

!
! main control loop
!
cls
repeat
do @clr
	xprot termcrc
	setvar multiple false
	xmit "\r\n\r\n\r\n\r\n"
	xmit "                  _T_E_R_M__S_e_r_v_e_r__M_o_d_e__M_e_n_u_ \r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  [t]  TERMCRC protocol file transfers  |\r\n"
	xmit "                 | *[w]  WTERMCRC protocol file transfers |\r\n"
	xmit "                 |  [x]  Xmodem [checksum] file transfers |\r\n"
	xmit "                 |  [c]  Xmodem-CRC file transfers        |\r\n"
	xmit "                 |  [y]  Ymodem file transfers            |\r\n"
	xmit "                 | *[z]  Zmodem file transfers            |\r\n"
	xmit "                 |  [k]  Kermit file transfers            |\r\n"
	xmit "                 |  [u]  Unformatted file transfers       |\r\n"
	xmit "                 |                                        |\r\n"
	xmit "                 |  [?]  Help - How to, Troubleshooting   |\r\n"
	xmit "                 |              Protocol explanation      |\r\n"
	xmit "                 |  [r]  Redraw Menu                      |\r\n"
	xmit "                 |  [q]  Quit TERM server                 |\r\n"
	xmit "                 |________________________________________|\r\n"
	xmit "                      * - Fastest Transfers Available\r\n"
	xmit "\r\n\r\n"
	xmit "                           Enter Your Selection: "
	flush
	setvar okval false
	repeat
		setvar cval toupper(chr(asc(comin())&127))
		setvar okval true
		switch
		case cval="?" | cval="H"
			xmit "\r\n                         [?] - Help with TERM server\r\n"
			wait 1
			do @help
		case cval="T"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [t] - TERMCRC                           |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot termcrc
			xmit "\r\nTERMCRC Server mode begins now.\r\n"
			xmit "You may initiate file transfers in either direction.\r\n"
			xmit "Hit <Ctrl-C> to exit server mode.\r\n\n"
			set control on
			terminal "^C"
		case cval="W"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [w] - WTERMCRC                          |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot wtermcrc
			xmit "\r\nWTERMCRC Server mode begins when you see 'OK'.\r\n"
			xmit "You may initiate file transfers in either direction.\r\n"
			xmit "Hit \^X\^X\^X\^X\^X (5 Ctrl-X's) to exit server mode.\r\n\n"
			server .
		case cval="K"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                       [k] - Kermit                           |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot kermit
			setvar multiple true
			do @sendget 0
		case cval="X"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                        [x] - Xmodem                          |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot xmodem
			setvar multiple false
			do @sendget 0
		case cval="C"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                      [c] - Xmodem CRC                        |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot xmodem-crc
			setvar multiple false
			do @sendget 0
		case cval="Y"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                        [y] - Ymodem                          |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot ymodem
			setvar multiple true
			do @sendget 0
		case cval="Z"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |                       [z] - ZMODEM                           |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			xprot zmodem
			xmit "\r\nZMODEM Server mode begins when you see 'OK'.\r\n"
			xmit "You may initiate file transfers in either direction.\r\n"
			xmit "Hit \^X\^X\^X\^X\^X (5 Ctrl-X's) to exit server mode.\r\n\n"
			server .
		case cval="U"
	xmit "\r\n       ______________________________________________________________\r\n"
	xmit "      |                                                              |\r\n"
	xmit "      |              [u] - Unformatted File Transfers                |\r\n"
	xmit "      |______________________________________________________________|\r\n"
			wait 1
			setvar multiple false
			do @sendget 1
		case cval="R"
			xmit "\r\n                           [r] - Redraw Main Menu\r\n"
			wait 1
		case cval="Q"
			xmit "\r\n                           [q] - Quit TERM server\r\n"
			xmit "\r\n"
			wait 1
			if noquit="NOQUIT"
				return
			else
				quit
			endif
		default
			setvar okval false
		endswitch
		if !okval
			xmit "\007"
		endif
	until okval
until false

