/*
 *  Send a text file(s) to my SUN workstations, using 'ex' or 'vi', since
 *  my zmodem uploading is broken.
 *
 *  written by Jonathan Springer
 *
 *  Filenames are stripped and stored in the current directory on the SUNs
 *
 *  Note that your xprASCII.library must be set up with large enough delays
 *  between lines and/or characters that it doesn't overwhelm the receiving
 *  system.
 */

OPTIONS RESULTS

TIMEOUT 10

IF ~show('L', "rexxarplib.library") THEN DO
    SAY 'Trying to find ''rexxarplib.library'''
    IF ~addlib("rexxarplib.library", 0, -30, 0) THEN EXIT
    SAY 'Found it'
    END

/*  Set up your system prompt here  */
sysprompt = 'screech.springjp> '

/*  Not used, since it breaks on single files :(
REQUESTFILE TITLE '"Select Files to UpType"' MULTI STEM Files
*/

/*  Find out where TERM is  */
GETATTR term.screen
TermScreen = result

GetFile(,,,,'Select File(s) to UpType', TermScreen,'MULTISELECT',Files)

IF Files.0 = 0 THEN EXIT

/*  Get the files to be sent	*/

SAY 'Parsing file list.'

DO i = 1 TO Files.0 /*	Use DO i=0 to Files.COUNT-1 with REQUESTFILE	*/

    nummatches = FileList(Files.i, SubFiles, 'F', 'E')
    IF nummatches = 0 THEN iterate i

    DO j = 1 to nummatches

	/*  Isolate the file name   */
	FileList(SubFiles.j, DumbStem, 'F', 'N')
	partfile = DumbStem.1
	SAY partfile

	drop DumbStem

	/*  Send them	*/

	DELAY 2
	SEND '\r'                       /*  Set things in motion.   */

	WAIT sysprompt
	DELAY 1
	SEND 'ls\r'

	TIMEOUT 2
	WAIT partfile
	IF rc = 0 THEN DO
	    TIMEOUT 10
	    WAIT sysprompt
	    ITERATE j			/*  File exists 	    */
	    END
	TIMEOUT 10

	DELAY 1
	SEND '\r'
	WAIT sysprompt
	DELAY 1
	SEND 'vi ' partfile '\r'        /*  Start up the editor     */

	DELAY 2
	SEND ':set noautoindent\r'      /*  Just in case :)         */
	DELAY 1

	SEND 'i'                        /*  Insert mode...          */

	DELAY 1

	SENDFILE MODE ASCII NAMES SubFiles.j

	DELAY 1

	SEND '\e'                       /*  Escape Insert mode      */
	DELAY 1

	SEND 'ZZ'                       /*  And exit vi.            */

	END
    END

    /*	That's all folks.   */
