C EXTENSIVE REVISION BY LAWSON PIERCE 27 MAR 1982
C TABS EXPANDED, PAGING OPTIONS, DRIVE OPTIONS, &
C TITLE MODS ADDED.
C FORM FEEDS RETAINED ON ONE OPTION
C M80  .PRN FILE EDITOR  VERSION 1.2  6/29/78
C. 
C THIS PROGRAM EDITS THE  .PRN FILE PRODUCED BY THE M80
C ASSEMBLER AND WRITES TO THE LST: DEVICE.  THE OUTPUT
C IS NARROW ENOUGH TO FIT ON 8.5" PAPER.
C ADAPTED FROM CMUG 026 ,EDITM.FOR BY R. C. MINNICK, BOX 306
C   OURAY, COLORADO 81427
C$
	PROGRAM EDITM
	EXTERNAL OPEN
	LOGICAL A(128),D(25)
	CALL PNAME(D,NFLAG)
	J=0
	IFLAG=0
	NDFLAG=0
	READ(6,30,END=1000)A
	CALL TABS(A)
	DO 300 I=1,25
	A(I+55)=D(I)
300	CONTINUE
	WRITE(2,37)(A(I),I=2,80)
37	FORMAT(' ',80A1)
	READ(6,30,END=1000)A
	WRITE(2,36)
36	FORMAT('0')
C.
200	READ(6,30,END=1000)A
30	FORMAT(128A1)
	CALL TABS(A)
C.
	IF (J.GT.0) GO TO 45
	  DO 40 I=1,128
	  IF (A(I).EQ.12) J=I
	  IF (A(I).EQ.12) CALL OPTION (I,NFLAG,NDFLAG,A,D)
	  IF (NDFLAG.EQ.1) GOTO 1000
40	  CONTINUE
	IF (J.EQ.0) GO TO 47
C IFLAG=END RECOGNIZED
	IF (A(J-3).NE.69) GO TO 47
	IF (A(J-2).NE.78) GO TO 47
	IF (A(J-1).NE.68) GO TO 47
	IFLAG=1
47	IF (J.NE.0) J=5
C FIND ACTUAL LINE LENGTH & CALL IT L
45	L=128
C
	DO 50 I=0,127
C		IF A(I) IS NOT A CR OR BLANK, GET OUT OF LOOP
	IF (A(-1*I+128).NE.13.AND.A(-1*I+128).NE.32) GO TO 60
C		ELSE DECR END OF LINE COUNT
	L=L-1
50	CONTINUE
C.
C INCR L TO PICKUP CR AT END OF LINE
60	IF (L.LT.128) L=L+1
	J=J-1
	IF (J.LT.0) J=0
	IF (IFLAG.EQ.0) WRITE(2,35)(A(I),I=1,20),(A(I),I=32,L)
	IF (IFLAG.EQ.1) WRITE(2,35)(A(I),I=1,L)
35	FORMAT('+',2X,128A1)
	GO TO 200
C.
1000	ENDFILE 6
	END
C$
C SETUP FILE NAME
	SUBROUTINE PNAME(D,NFLAG)
	LOGICAL B(11),D(25),DUM(12)
	DO 2 I=1,25
2	D(I)=' '
C.
C INSERT DATE OF COMPILE OR PRINT
	WRITE (1,5)
	READ (1,20) (D(I),I=17,25)
5	FORMAT(1H0,'COMPILE OR PRINT DATE ? .. 01 JAN 82 ..')
	WRITE(1,10)
10	FORMAT(' FILE NAME: ')
	READ(1,20) DUM
20	FORMAT(12A1)
	IFLAG=0
	B(1)=DUM(1)
	DO 25 I=2,8
		B(I)=DUM(I)
		IF (B(I).EQ.46) IFLAG=1
		IF (IFLAG.EQ.1) B(I)=32
25		IF (B(I).EQ.13) B(I)=32
26	B(9)='P'
	B(10)='R'
	B(11)='N'
	WRITE (1,600)
600	FORMAT (1H0,'POSITION PAPER 7 LINES FROM TOP OF PAGE')
	WRITE (1,28)
28	FORMAT (1H0,'DRIVE PRN FILE IS ON ? A=1, B=2 ...')
	READ (1,602) IDRIVE
	WRITE (1,29)
29	FORMAT (1H ,'PAGING OPTION, 0=NONE, 1=MACRO',
     1		' HEADINGS ... ')
	READ (1,602) NFLAG
602	FORMAT (15I5)
	J=3
C
	CALL OPEN(6,B,IDRIVE)
C
C MAKEUP NAME AND DATE LABEL
		DO 200 I=1,8
		IF (B(I).EQ.32) GOTO 200
		J=J+1
		D(J)=B(I)
200		CONTINUE
		J=J+1
		D(J)=46
		DO 210 I=9,11
		J=J+1
		D(J)=B(I)
210		CONTINUE
C
	RETURN
	END
C
C SUBROUTINE TO EXPAND TABS
C
	SUBROUTINE TABS(A)
	LOGICAL A(128),E(128)
		DO 50 I=1,128
		E(I)=32
50		CONTINUE
	N=0
	DO 100 K=1,80,8
	DO 200 I=1,8
	N=N+1
	M=K+I-1
	IF (A(M).EQ.9) GOTO 105
	E(N)=A(M)
	GOTO 200
105	CONTINUE
		DO 110 J=I,8
		E(N)=32
		N=N+1
110		CONTINUE
200	CONTINUE
100	CONTINUE
		DO 300 I=1,128
		A(I)=E(I)
300		CONTINUE
	RETURN
	END
C
C SUBROUTINE FOR PAGING CONTROL
C
	SUBROUTINE OPTION(I,NFLAG,NDFLAG,A,D)
	LOGICAL A(128),D(25)
	IF (NFLAG.NE.1) GOTO 100
C
C IF HERE WE WANT MACRO TITLE ON EACH PAGE
C
	IF (I.GT.100) GOTO 301
	DO 300 K=3,25
	KK=I+K+55
	A(KK)=D(K)
300	CONTINUE
C
301	WRITE (2,37) (A(K),K=1,24),(A(K),K=30,85)
	READ (6,30,END=1000) A
	RETURN
1000	NDFLAG=1
	RETURN
C
C FOR NOW, RETURN
C
C READ NEXT 2 RECORDS AND IGNORE, USE THIRD
100	DO 110 K=1,3
	READ (6,30,END=1000) A
110	CONTINUE
	RETURN
37	FORMAT (' ',80A1)
30	FORMAT (128A1)
	END
