;;;-*-Midas-*-

TITLE INSTALL

;SUGGESTIONS FOR FUTURE IMPROVEMENTS
; USE REMINDERS TO GET STUFF SENT WHEN A HOST IS DOWN
; OPERATE NET DIRECTLY INSTEAD OF THROUGH MLDEV

A=1
B=2
C=3
D=4
E=5
T=6
TT=7
H=10
I=11
J=12
Q=13
R=14
P=17

TYIC==1
TYOC==2
INCH==3
OUCH==4
ERRC==5

PDL:	-20,,.
	BLOCK 20

JCLBUF:	BLOCK 20
JCLP:	440700,,JCLBUF
FILEP:	0		;AOBJN POINTER TO INPUT FILE
FDATE:	0		;FILE DATE

IAOBJN:	-NITSS,,0

ITSS:	;; Use these if .GETSYS doesn't support ITSNMS
	IRPS ITS,,[AI,MC,MX]
	SIXBIT /ITS/
	TERMIN
NITSS==:.-ITSS
	BLOCK 9
MXITSS==:.-ITSS

WRITO:	BLOCK MXITSS

DEFDEV:	0	;DEFAULT FILE FROM DDT
DEFSNM:	0
DEFFN1:	0
DEFFN2:	0

DEV:	0	;ACTUAL FILE
SNM:	0
FN1:	0
FN2:	0

fbits:	0	;status work from FILBLK call

GRTRP:	0	;-1 IF GREATER THAN OR LESS THAN USED

GO:	MOVE P,PDL
	.OPEN TYIC,[.UAI,,'TTY]
	 .LOSE %LSFIL
	.OPEN TYOC,[.UAO,,'TTY]
	 .LOSE %LSFIL
	MOVE T,[-<MXITSS+1>,,ITSS]	; Ask for 1 more than we actually
	MOVE TT,[SIXBIT /ITSNMS/]	;  have room for.
	.GETSYS T,
	 JRST GETJCL
	SKIPL T			; We hit the jackpot!  More ITS machines that
	 .LOSE			;  I ever dreamed possible!
	MOVNI T,-ITSS(T)
	HRLZM T,IAOBJN
GETJCL:	.BREAK 12,[..RJCL,,JCLBUF]
	.BREAK 12,[..RPFILE,,DEFDEV]
NEWWRD:	SETZ A,
	MOVE B,[440600,,A]
NEWCHR:	ILDB TT,JCLP
	CAIN TT,^Q
	 JRST QUOTCH
	CAIN TT,":
	 JRST SETDEV
	CAIN TT,";
	 JRST SETSNM
	CAIG TT,40
	 JRST DELIM
	CAIL TT,"a
	 CAILE TT,"z
	  SUBI TT,40
	TLNE B,770000
DEPOT:	 IDPB TT,B
	JRST NEWCHR

QUOTCH:	ILDB TT,JCLP
	CAIL TT,"a
	 CAILE TT,"z
	  SUBI TT,40
	JRST DEPOT

SETDEV:	MOVEM A,DEV
	JRST NEWWRD

SETSNM:	MOVEM A,SNM
	JRST NEWWRD

DELIM:	JUMPE A,DELIM1
	SKIPE FN1
	 MOVEM A,FN2
	SKIPN FN1
	 MOVEM A,FN1
DELIM1:	CAIN TT,40
	 JRST NEWWRD
	CAIE TT,33
	 JRST WRTALL
NEWHOS:	SETZ A,
	MOVE B,[440600,,A]
NEWCHH:	ILDB TT,JCLP
	CAIL TT,"A
	 CAILE TT,"z
	  JRST HOSDEL
	CAIL TT,"a
	 SUBI TT,"a-"A
	CAILE TT,"Z
	 JRST HOSDEL
	SUBI TT,40
	TLNE B,770000
	 IDPB TT,B
	JRST NEWCHH

HOSDEL:	MOVE B,IAOBJN
HOSDL1:	CAMN A,ITSS(B)
	 SETOM WRITO(B)
	AOBJN B,HOSDL1
	CAIL TT,40
	 JRST NEWHOS
	JRST JCLOVR

WRTALL:	MOVE B,IAOBJN
WRTAL1:	SETOM WRITO(B)
	AOBJN B,WRTAL1

JCLOVR:	MOVSI B,-4
JCLOV1:	MOVE A,DEFDEV(B)
	SKIPN DEV(B)
	 MOVEM A,DEV(B)
	AOBJN B,JCLOV1
	.CALL [	SETZ
		SIXBIT/OPEN/
		[.BAI,,INCH]
		DEV
		FN1
		FN2
		SETZ SNM ]
	 JRST FNF
	.CALL [	SETZ
		'RFNAME
		MOVEI INCH
		MOVEM A
		MOVEM B
		SETZM E ]
	 .LOSE %LSFIL
	.CALL [	SETZ
		'FILBLK
		MOVEI INCH
		movem fbits ? movem fbits	;only want 3rd value
		SETZM fbits ]
	 .LOSE %LSFIL
	CAMN A,[SIXBIT/DSK/]
	 .CALL [SETZ
		'SSTATU
		REPEAT 5,MOVEM B
		SETZM A ]
	  JFCL
	MOVE B,IAOBJN
JCLOV2:	CAMN A,ITSS(B)
	 SETZM WRITO(B)	;DON'T WRITE TO SAME MACHINE AS READING FROM
	AOBJN B,JCLOV2
	MOVE A,FN2
	CAME A,[SIXBIT/</]
	 CAMN A,[SIXBIT/>/]
	  JRST GRTR
	MOVE A,FN1
	CAME A,[SIXBIT/</]
	 CAMN A,[SIXBIT/>/]
	  JRST GRTR
	JRST ASK

GRTR:	SETOM GRTRP
	MOVEM E,FN2
ASK:	MOVEI TT,[ASCIZ/Write /]
	PUSHJ P,ASZW
	PUSHJ P,FILW
	MOVEI TT,[ASCIZ/to /]
	SETO A,
	MOVE B,IAOBJN
ASK1:	SKIPN WRITO(B)
	 JRST ASK2
	PUSHJ P,ASZW
	MOVE TT,ITSS(B)
	PUSHJ P,SIXW
	MOVEI TT,[ASCIZ/, /]
	SETZ A,
ASK2:	AOBJN B,ASK1
	JUMPE A,ASK3
	MOVEI TT,[ASCIZ/to noplace?????
/]
	PUSHJ P,ASZW
	.BREAK 16,160000

ASK3:	.IOT TYOC,["?]
	PUSHJ P,YORN
	 .BREAK 16,060000
	JRST READIN

YORN:	.IOT TYIC,TT
	PUSHJ P,CRLF
	CAIL TT,"a
	 SUBI TT,"a-"A
	CAIN TT,"Y
	 JRST POPJ1
	CAIN TT,"N
	 JRST CPOPJ
	MOVEI TT,[ASCIZ/Y or N please - /]
	PUSHJ P,ASZW
	JRST YORN

POPJ1:	AOS (P)
CPOPJ:	POPJ P,

FILW:	IRPS NM,DEL,[DEV:SNM;FN1 FN2 ]
	 MOVE TT,NM
	 PUSHJ P,SIXW
	 .IOT TYOC,["DEL]
	 TERMIN
	POPJ P,

ASZW:	HRLI TT,440700
ASZW1:	ILDB T,TT
	JUMPE T,CPOPJ
	.IOT TYOC,T
	JRST ASZW1

CRLF:	.IOT TYOC,[15]
	.IOT TYOC,[12]
	POPJ P,

SIXW:	SETZ T,
	LSHC T,6
	ADDI T,40
	.IOT TYOC,T
	JUMPN TT,SIXW
	POPJ P,

FNF:	PUSHJ P,FILW
	.OPEN ERRC,[.UAI,,'ERR ? 1 ? 0]
	 .LOSE %LSFIL
FNF1:	.IOT ERRC,A
	CAIGE A,40
	 JRST FNF2
	.IOT TYOC,A
	JRST FNF1

FNF2:	PUSHJ P,CRLF
	.BREAK 16,060000

READIN:	.CALL [	SETZ
		'RFDATE
		MOVEI INCH
		SETZM FDATE ]
	 .LOSE %LSFIL
	.CALL [	SETZ
		'FILLEN
		MOVEI INCH
		SETZM A ]
	 .LOSE %LSFIL
	MOVEI B,BUFFER-1(A)	;LAST WD NEEDED
	LSH B,-10.		;LAST PG NEEDED
	.CORE 1(B)
	 JRST [	MOVEI TT,[ASCIZ/No Core available./]
		PUSHJ P,ASZW
		JRST FNF2 ]
	.VALUE [ASCIZ/:PROCEED /]
	HRLOI A,-1(A)
	EQVI A,BUFFER
	MOVEM A,FILEP
	.IOT INCH,A		;GET FILE
	.CLOSE INCH,
	MOVE B,IAOBJN
WROUT:	SKIPN WRITO(B)
	 JRST WROUT9
	SKIPN GRTRP
	 JRST WROUT1
	.CALL [	SETZ
		SIXBIT/OPEN/
		JFFO A		;SIGH
		[.BAI,,INCH]
		ITSS(B)
		FN1
		FN2
		SETZ SNM ]
	 JFCL
	.CLOSE INCH,
	CAIE A,%ENSFL
	 CAIN A,%EBDLK
	  JRST WROUT1
	PUSH P,DEV
	MOVE C,ITSS(B)
	MOVEM C,DEV
	PUSHJ P,FILW
	POP P,DEV
	SKIPN A
	 MOVEI A,%EEXFL
	.CALL [	SETZ
		SIXBIT/OPEN/
		[.UAI,,ERRC]
		['ERR,,]
		MOVEI 4
		SETZ A ]
	 .VALUE
WROUT2:	.IOT ERRC,A
	CAIGE A,40
	 JRST WROUT3
	.IOT TYOC,A
	JRST WROUT2

WROUT3:	.CLOSE ERRC,
	MOVEI TT,[ASCIZ/; write it anyway?/]
	PUSHJ P,ASZW
	PUSHJ P,YORN
	 JRST WROUT9
WROUT1:	.CALL [	SETZ
		SIXBIT/OPEN/
		[.BAO,,OUCH]
		ITSS(B)
		[SIXBIT/_INSL_/]
		[SIXBIT/OUTPUT/]
		SETZ SNM ]
	  Jrst [Movei TT,[Asciz /îCan't write to /]
		Pushj P,ASZW
		Move TT,ITSS(B)
		Pushj P,SIXW
		Movei TT,[Asciz / -- Continue? /]
		Pushj P,ASZW
		Pushj P,YorN
		  Jrst Done
		Jrst WROUT9]
	MOVE A,FILEP
	.IOT OUCH,A
	.CALL [	SETZ
		'SFDATE
		MOVEI OUCH
		SETZ FDATE ]
	 .LOSE %LSFIL
	.CALL [	SETZ
		SIXBIT/RENMWO/
		MOVEI OUCH
		FN1
		SETZ FN2 ]
	 .LOSE %LSFIL
	;;; make "$" flag on dest match same on source
	ldb a,[230100,,fbits]
	.call [setz ? 'sreapb ? 1000,,ouch ? setz a]
	 .lose %lsfil
	.CLOSE OUCH,
WROUT9:	AOBJN B,WROUT
Done:	.BREAK 16,160000

VARIABLES
CONSTANTS
BUFFER:

END GO
