# .autocis - xc script to visit CIS automagically.
# This file uses 4-character tabstops.
# It will log in, visit CIS Mail (if mail is waiting), then the
#  PRACTICE and UNIX Fora, uploading any prepared files, downloading
#  all new messages, and capture them into three separate files.

# The following assumption is made about your CIS interactions:
#  You are in "expert" mode in MAIL.
#  You are in Command mode in all Fora.
#  You have opted for continuous reading in all Fora.
#  You have set your Prompt Char set to '^H' --backspace-- in all Fora.
#	This last is VERY critical to the properly trigger the WAITFORs

# This script will call another script, .temp_opt, to set Forum options
# for only the current login

tty "on"		# echo to the tty while script is running (default anyways)
debug "on"		# capture in debug.log providing file pre-exists
set proto 7e	# CIS is happier
set bps 2400
set cis off		# don't trigger on any stray ENQ character
set xoff on		# set XON/XOFF signalling

#  if linked; then  # this alternate routine calls a
#	call .cisdial	# sub-script with the dialing information
#  endif

if ! linked; then dial "7662080"; endif	# dial this number
while ! waitfor "CONNECT" 52			# give modem 52 secs to say "CONNECT"
	do
		redial
	done

pause 2						# let network catch up
transmit "^C"				# First thing to send CIS
pause 3						# let network catch up

debug "off"					# so as not to display the password
# Now send CIS one string with PPN, first service to go to, and password
transmit "72160,1341/go:mail\\beige*screw^M"
debug "on"

if waitfor "CompuServe Mail^M" 8			# we already asked to GO MAIL
then if ! waitfor "No messages pending" 4	# unless nothing waiting, then
	 set cfile "email"						# use this capture file
		capture "on"						# open it
		file echo `date`					# time stamp it
		transmit "rec all^M"				# ask to read everything
		while ! waitfor "Mail!"				#  until this string appears
			do; done						#  script does nothing
		transmit "del all^M"				# remove msgs from CIS mbox
		capture "off"						# close the capture file
	fi
else
	beep							# beep if we never get to CISMail
endif

set cfile "pra"						# new capture file
transmit "g practice^M"				# new Forum
waitfor "moment please..."			# "Welcome" should follow this
capture "on"						# start appending to 'pra'
if waitfor "forum !^H" 60			# prompt with a backspace
then
	call ".temp_opt"				# set Forum options for this session.
	assign Upload eq `ls rp 2>/dev/null`
	if Upload eq "praR"				# is there a 'praR' file
	then	capture "off"			# then turn off capturing
		type "praR"					# transmit the 'praR' file
		transmit "^M"				# this extra newline will trigger
		while ! waitfor "% choice required"	# this response after the upload
			do; done
		shell "mv praR /usr/tmp/praR$$"	# rename the 'praR' file
		capture "on"				# start capturing again
	fi
	transmit "rea new^M^M"			# read all new messages
	while ! waitfor "% choice required"
		do; done
	capture "off"
else
	beep							# beep if Forum closed, or you get bumped
fi

set cfile "uni"						# same stuff in another Forum
transmit "g unixforum^M"
waitfor "moment please..."
capture "on"
if waitfor "forum !^h" 60
then
	call ".temp_opt"			
	assign Upload eq `ls ru 2>/dev/null`
	if Upload eq "uniR"
	then	capture "off"
		type "uniR"
		transmit "^M"
		while ! waitfor "% choice required"
			do; done
		shell "mv uniR /usr/tmp/uniR$$"
		capture "on"
	fi
	transmit "rea new^M^M"
	while ! waitfor "% choice required"
		do; done
	capture "off"
else
	beep
fi

transmit "off^M"
quit
