      SUBROUTINE MAIN
      LOGICAL*1 BUF(400)
      INTEGER GETARG, OPEN, GETLIN
      INTEGER I, INT
      I=1
23000 IF(.NOT.(GETARG(I,BUF,400).NE.-1))GOTO 23002
      IF(.NOT.(BUF(1) .EQ. 63 .AND. BUF(2) .EQ. 0))GOTO 23003
      CALL ERROR (23Husage:  kwic [file...].)
23003 CONTINUE
      IF(.NOT.(BUF(1) .EQ. 45 .AND. BUF(2) .EQ. 0))GOTO 23005
      INT = 1
      GOTO 23006
23005 CONTINUE
      INT = OPEN(BUF,1)
      IF(.NOT.(INT .EQ. -3))GOTO 23007
      CALL CANT(BUF)
23007 CONTINUE
23006 CONTINUE
23009 IF(.NOT.(GETLIN(BUF,INT) .NE. -1))GOTO 23010
      CALL PUTROT(BUF, 2)
      GOTO 23009
23010 CONTINUE
      IF(.NOT.(INT .NE. 1))GOTO 23011
      CALL CLOSE(INT)
23011 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(I.EQ.1))GOTO 23013
23015 IF(.NOT.(GETLIN(BUF,1) .NE. -1))GOTO 23016
      CALL PUTROT(BUF, 2)
      GOTO 23015
23016 CONTINUE
23013 CONTINUE
      RETURN
      END
      SUBROUTINE PUTROT (BUF, OUTFIL)
      LOGICAL*1 TYPE
      LOGICAL*1 BUF(100), T
      INTEGER I, OUTFIL
      I=1
23017 IF(.NOT.(BUF(I) .NE. 10))GOTO 23019
      T = TYPE(BUF(I))
      IF(.NOT.(T .EQ. 1 .OR. T .EQ. 2))GOTO 23020
      CALL ROTATE(BUF, I, OUTFIL)
      T = TYPE(BUF(I+1))
23022 IF(.NOT.(T.EQ.1 .OR. T.EQ.2))GOTO 23024
      I = I + 1
23023 T=TYPE(BUF(I+1))
      GOTO 23022
23024 CONTINUE
23020 CONTINUE
23018 I=I+1
      GOTO 23017
23019 CONTINUE
      RETURN
      END
      SUBROUTINE ROTATE(BUF, N, OUTFIL)
      LOGICAL*1 BUF(100)
      INTEGER I, N, OUTFIL
      I=N
23025 IF(.NOT.(BUF(I) .NE. 10))GOTO 23027
      CALL PUTCH(BUF(I), OUTFIL)
23026 I=I+1
      GOTO 23025
23027 CONTINUE
      CALL PUTCH(36, OUTFIL)
      I=1
23028 IF(.NOT.(I.LT.N))GOTO 23030
      CALL PUTCH(BUF(I), OUTFIL)
23029 I=I+1
      GOTO 23028
23030 CONTINUE
      CALL PUTCH(10, OUTFIL)
      RETURN
      END
