      SUBROUTINE MAIN
      LOGICAL*1 BUF(400)
      INTEGER GETARG, OPEN, CTOI
      INTEGER I, INT, WIDTH, J, N
      DATA WIDTH /80/
      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 (25Husage: unrot [-n] [file].)
23003 CONTINUE
      IF(.NOT.(BUF(1) .EQ. 45 .AND. BUF(2) .NE. 0))GOTO 23005
      J = 2
      N = CTOI(BUF,J)
      IF(.NOT.(N .GT. 0))GOTO 23007
      WIDTH = N
23007 CONTINUE
      GOTO 23001
23005 CONTINUE
      IF(.NOT.(BUF(1) .EQ. 45))GOTO 23009
      INT = 1
      GOTO 23010
23009 CONTINUE
      INT = OPEN(BUF, 1)
      IF(.NOT.(INT .EQ. -3))GOTO 23011
      CALL CANT(BUF)
23011 CONTINUE
23010 CONTINUE
23006 CONTINUE
      CALL NROT (INT, WIDTH)
      IF(.NOT.(INT .NE. 1))GOTO 23013
      CALL CLOSE(INT)
23013 CONTINUE
23001 I=I+1
      GOTO 23000
23002 CONTINUE
      IF(.NOT.(I.EQ.1))GOTO 23015
      CALL NROT (1, WIDTH)
23015 CONTINUE
      RETURN
      END
      SUBROUTINE NROT(INT, WIDTH)
      LOGICAL*1 INBUF(400), OUTBUF(400)
      INTEGER GETLIN, INDEX
      INTEGER INT, I, J, WIDTH, MIDDLE
      MIDDLE = MAX0(WIDTH/2, 1)
23017 IF(.NOT.(GETLIN(INBUF, INT) .NE. -1))GOTO 23018
      I=1
23019 IF(.NOT.(I.LT.WIDTH))GOTO 23021
      OUTBUF(I) = 32
23020 I=I+1
      GOTO 23019
23021 CONTINUE
      J = MIDDLE
      I=1
23022 IF(.NOT.(INBUF(I).NE.36 .AND. INBUF(I).NE.10))GOTO 23024
      J = J + 1
      IF(.NOT.(I.GT.1 .AND. INBUF(I-1) .EQ. 32))GOTO 23025
      IF(.NOT.(NEXTJ(+1,INBUF,I,J) .GE. WIDTH - 1))GOTO 23027
      J = 1
23027 CONTINUE
23025 CONTINUE
      IF(.NOT.(J .GE. WIDTH - 1))GOTO 23029
      J = 1
23029 CONTINUE
      OUTBUF(J) = INBUF(I)
23023 I=I+1
      GOTO 23022
23024 CONTINUE
      IF(.NOT.(INBUF(I) .EQ. 36))GOTO 23031
      J = MIDDLE
      I=INDEX(INBUF,10)-1
23033 IF(.NOT.(I.GT.0))GOTO 23035
      IF(.NOT.(INBUF(I) .EQ. 36))GOTO 23036
      GOTO 23035
23036 CONTINUE
      J = J -1
      IF(.NOT.(INBUF(I+1) .EQ. 32))GOTO 23038
      IF(.NOT.(NEXTJ(-1,INBUF,I,J) .LE. 0))GOTO 23040
      J = WIDTH - 2
23040 CONTINUE
23038 CONTINUE
      IF(.NOT.(J .LE. 0))GOTO 23042
      J = WIDTH - 2
23042 CONTINUE
      OUTBUF(J) = INBUF(I)
23034 I=I-1
      GOTO 23033
23035 CONTINUE
23031 CONTINUE
      I=WIDTH-2
23044 IF(.NOT.(I .GT. 0))GOTO 23046
      IF(.NOT.(OUTBUF(I) .NE. 32))GOTO 23047
      GOTO 23046
23047 CONTINUE
23045 I=I-1
      GOTO 23044
23046 CONTINUE
      OUTBUF(I+1) = 10
      OUTBUF(I+2) = 0
      CALL PUTLIN(OUTBUF, 2)
      GOTO 23017
23018 CONTINUE
      RETURN
      END
      INTEGER FUNCTION NEXTJ(INCMNT,BUF,I,J)
      LOGICAL*1 BUF(100)
      INTEGER INCMNT, I, J, K
      NEXTJ = J
      K=I
23049 IF(.NOT.(K.GT.0))GOTO 23051
      IF(.NOT.(BUF(K) .EQ. 32 .OR. BUF(K) .EQ. 36 .OR. BUF(K) .EQ. 10))G
     *OTO 23052
      GOTO 23051
23052 CONTINUE
      NEXTJ = NEXTJ + INCMNT
23050 K = K + INCMNT
      GOTO 23049
23051 CONTINUE
      RETURN
      END
