C SUBROUTINE TTYINI
C COPYRIGHT (C) 1983 GLENN EVERHART
C PERMISSION IS GIVEN TO ANYONE TO USE, DISTRIBUTE, OR COPY THIS
C PROGRAM FREELY BUT NOT TO SELL IT COMMERICALLY.
C
C Modifications Record:
C =====================
C	13-Feb-87 Chris Doran, Sira
C CJD1	Get automatic setup of wrap and no edit working for V4, declaring
C	  an exit handler to reset them no matter how PCC terminates.
C	Also do some simplifications to the coding (lose redundant work vars).
C
	SUBROUTINE TTYINI
C PERFORM INITS ON UNIT 5. NORMALLY EITHER DO NOTHING OR
C REPLACE WITH SOMETHING THAT WORKS FOR YOUR SYSTEM. TYPICAL
C ACTIONS:
C  SET THE TERMINAL NOT TO WRAP AROUND
C  ATTACH TERMINAL SO TYPE-AHEAD WORKS
C  SET UP TERMINAL TO MUNGE AROUND THE ESCAPE SEQUENCES TO ALLOW
C  SPECIAL FUNCTION AND/OR ARROW KEYS TO WORK.
C VMS VERSION ... HIGHLY SYSTEM DEPENDENT...
	INTEGER*4 TTCHAN,STAT,SYS$ASSIGN,SYS$QIOW
	InTEgeR*2 IOSB(4)
	LOGICAL*1 AKP(2)
	InTEgeR*4 IOLVL,IOFG2,IGOLD
	COMMON/IOLVL/IOLVL,IGOLD,IOFG2
	INTEGER*4 MODEBF(3),DESBLK(5),TERMBF(3),SYS$DCLEXH		!CJD1
	EXTERNAL TTYRES							!CJD1
	INCLUDE '($IODEF)'
	INCLUDE '($TTDEF)'
	INCLUDE '($TT2DEF)'						!CJD1
	COMMON /TTCHN/TTCHAN
	COMMON/OLDTER/TERMBF						!CJD1
	DATA AKP/27,'='/
	DATA DESBLK(3)/1/						!CJD1
	STAT=SYS$ASSIGN('TT',TTCHAN,,)
	STAT=SYS$QIOW(,%VAL(TTCHAN),%VAL(IO$_SENSEMODE),IOSB,,,		!CJD1
     ;		TERMBF,%VAL(12),,,,)					!CJD1
	MODEBF(1)=TERMBF(1)						!CJD1
C SET TERMINAL		/ESCAPE				/NOWRAP		!CJD1
	MODEBF(2)=(TERMBF(2).OR.TT$M_ESCAPE).AND.(.NOT.TT$M_WRAP)	!CJD1
C					/NOLINE_EDIT			!CJD1
	MODEBF(3)=TERMBF(3).AND.(.NOT.TT2$M_EDITING)			!CJD1
C TURN ON DESIRED CHARACTERISTICS (REALLY NEED THE ESCAPE CHARAC.
C BADLY...)
	STAT=SYS$QIOW(,%VAL(TTCHAN),%VAL(IO$_SETMODE),IOSB,,,		!CJD1
     ;			MODEBF,%VAL(12),,,,)				!CJD1
C Queue a change back on exit						!CJD1
	DESBLK(2)=%LOC(TTYRES)						!CJD1
	DESBLK(4)=%LOC(STAT)						!CJD1
	STAT=SYS$DCLEXH(DESBLK)						!CJD1
C NOW HAVING SET THE TERMINAL UP, GET BACK OUTTA HERE...
C FIRST SET AUXILIARY KEYPAD MODE UP ON UNIT 6 THOUGH.
	WRITE(6,2000)AKP
2000	FORMAT(2A1)
	RETURN
	END
C
C SUBROUTINE GETTTL(LINE)
C READ IN A TERMINAL LINE ON VAX...
C VMS VERSION. FOR STANDARD VANILLA VERSION COMMENT
C OUT ALL BUT THE FORTRAN READ AND UNCOMMENT THAT...
	SUBROUTINE GETTTL(LINE)
	LOGICAL*1 LINE(132)
C
C
C ****++++ VMS SPECIFIC BELOW
	INTEGER*4 TTCHAN,STAT,SYS$ASSIGN,SYS$QIOW
	InTEgeR*2 IOSB(4)
	INTEGER*4 MODEBF(3)						!CJD1
	INCLUDE '($IODEF)'
	INCLUDE '($TTDEF)'
	COMMON /TTCHN/TTCHAN
	DO 1 N1=1,132
1	LINE(N1)=0
C NOTE TTCHAN IS SET UP IN TTYINI ABOVE
C CHANGE CODE TO READ-VIRTUAL-BLOCK
	STAT=SYS$QIOW(,%VAL(TTCHAN),%VAL(IO$_READVBLK),IOSB,,,		!CJD1
     ;			LINE,%VAL(132),,,,)				!CJD1
C THAT OUGHT TO PULL EVERYTHING IN...
C SINCE WE ZERO THE BUFFER INITIALLY, FORGET THE COUNT. IT ONLY
C MATTERS IF BUFFER NEEDS TO BE CLEARED PAST IT...
C ****++++ VMS SPECIFIC ABOVE
C
C
C DUMMY CODE FOR FORTRAN READ...
C *********
C  **** HERE IS THE SECTION OF CODE YOU NEED FOR NON-VMS-SPECIFIC VERSION
C	READ(5,1000)LINE
C1000	FORMAT(132A1)
C *********
	RETURN
	END
C									!CJD1
C									!CJD1
C TTYRES is called on exit to put the terminal back the way we found it	!CJD1
C -- especially line editing mode, and normal keypad.			!CJD1
	SUBROUTINE TTYRES(COND)						!CJD1
	InTEgeR*2 IOSB(4)						!CJD1
	INTEGER*4 TTCHAN,STAT,SYS$QIOW,TERMBF(3),COND			!CJD1
	LOGICAL*1 NOAKP(4)						!CJD1
	COMMON/OLDTER/TERMBF						!CJD1
	INCLUDE '($IODEF)'						!CJD1
	COMMON /TTCHN/TTCHAN						!CJD1
	DATA NOAKP/27,'>',27,'\'/					!CJD1
	STAT=SYS$QIOW(,%VAL(TTCHAN),%VAL(IO$_SETMODE),IOSB,,,		!CJD1
     ;		TERMBF,%VAL(12),,,,)					!CJD1
C Clear auxiliary keypad mode (& VT52 hold screen) on TTCHAN		!CJD1
	STAT=SYS$QIOW(,%VAL(TTCHAN),%VAL(IO$_WRITEVBLK),IOSB,,,		!CJD1
     ;		NOAKP,%VAL(4),,,,)					!CJD1
	RETURN								!CJD1
	END								!CJD1
