	PROGRAM SORT
	BYTE A$(80), B$(80), C$(80), D$(80)
	BYTE ARAY$(8), ARAY(40,100,1)

	CALL DEFD$(A$)
	CALL DEFD$(B$)
	CALL DEFD$(C$)
	CALL DEFD$(D$)
	CALL DEFT$(ARAY$,ARAY,40,100,1)

	CALL CMD$(A$)
	I2=MATCH$(A$,'#@',1)
	IF(I2.GT.80)I2=0

	WRITE(5,10)
	WRITE(5,30)
	WRITE(5,40)
	WRITE(5,50)
	WRITE(5,10)
	WRITE(5,60)
	WRITE(5,10)
10	FORMAT(1X)
20	FORMAT(1X,80A1)
30	FORMAT(1X,12X'The SORT Bit (tm)  -  Version 1.01')
40	FORMAT(1X,12X'Copyright (C) 1980   Key Bits Inc.')
50	FORMAT(1X,12X'January, 1980   -   Miami, FL, USA')
60	FORMAT(1X,25X,'using')
	CALL VER$(B$)
	I=LEN$(B$)
	WRITE(5,10)
	WRITE(5,20) (B$(J),J=1,I)
	WRITE(5,10)

70	CONTINUE
	K=1
	III=NFORM$(B$,A$,K)
	J=MATCH$(A$,'=@',3)

	J=J+1
	J2=LEN$(A$)
	J3=J2-J+1
	CALL RIGHT$(D$,A$,J3)
	I=LOOK$(D$)
	IF(I.GT.-1)GO TO 90
	WRITE(5,80)
80	FORMAT(1X,'*** FILE NOT FOUND ***')
	GO TO 200


90	CONTINUE
	J=NFORM$(C$,A$,J)
	CALL OPEN(6,C$,III)
	CALL OPEN(7,B$,J)

	DO 110 LINES=1,100
	READ(6,100,END=120) A$
100	FORMAT(80A1)
	CALL STRIP$(A$)
	CALL MAKE$(ARAY$,LINES,1,A$)
110	CONTINUE

120	CONTINUE
	LINES=LINES-1


130	N=LINES
	M=N
140	M=M/2
	IF (M.EQ.0) GO TO 230
	K=N-M
	J=1
150	I=J
160	L=I+M
	ISIZE=IDEN$(ARAY$,I,1,ARAY$,L,1)
170	IF (ISIZE.GT.0) GO TO 190
180	J=J+1
	IF (J.GT.K) GO TO 140
	GO TO 150
190	CALL SWAP$(ARAY$,I,1,ARAY$,L,1)
	I=I-M
	IF (I.LT.1) GO TO 180
	GO TO 160

200	CONTINUE
	WRITE(5,210)
210	FORMAT(1X,'REENTER FILE NAMES - ')
	READ(5,220)A$
220	FORMAT(80A1)
	CALL STRIP$(A$)
	CALL UPPER$(A$)
	I=MATCH$(A$,'END@',1)
	IF(I.GT.0)GO TO 270
	GO TO 70

230	CONTINUE

240	DO 260 I=1,LINES
	CALL MAKE$(A$,ARAY$,I,1)
	J=LEN$(A$)
	WRITE(7,250) (A$(K),K=1,J)
250	FORMAT(1X,80A1)
260	CONTINUE

	ENDFILE 6
	ENDFILE 7

270	CONTINUE
	WRITE(5,10)
	WRITE(5,280)
280	FORMAT(1X,12X,'        Goodbye . . .')
	WRITE(5,10)
	WRITE(5,10)

	IF(I2.GT.0)GO TO 290
	GO TO 310

290	CONTINUE
	CALL CHAIN$('DEMO.COM@')
	WRITE(5,300)
300	FORMAT(1X,'*** DEMO.COM NOT FOUND - RETURNED TO SYSTEM ***@')

310	CONTINUE
	END
