      SUBROUTINE MAIN
      INTEGER I, STATUS, UNIT
      INTEGER GETARG, EQUAL, OPEN
      LOGICAL*1 FILE(40)
      LOGICAL*1 MINUST(2)
      DATA MINUST(1)/45/,MINUST(2)/0/
      CALL QUERY(37Husage:  spell [-ddictname] [file] ...)
      CALL LODIDX
      I = 1
23000 CONTINUE
      STATUS = GETARG(I, FILE, 40)
      IF (.NOT.(STATUS .EQ. -1))GOTO 23003
      IF (.NOT.(I .GT. 1))GOTO 23005
      GOTO 23002
23005 CONTINUE
      UNIT = 1
23006 CONTINUE
      GOTO 23004
23003 CONTINUE
      IF (.NOT.(EQUAL(FILE, MINUST) .EQ. 1))GOTO 23007
      UNIT = 1
      GOTO 23008
23007 CONTINUE
      UNIT = OPEN(FILE, 1)
      IF (.NOT.(UNIT .EQ. -3))GOTO 23009
      CALL CANT(FILE)
23009 CONTINUE
23008 CONTINUE
23004 CONTINUE
      CALL DOSPEL(UNIT)
      IF (.NOT.(UNIT .NE. 1))GOTO 23011
      CALL CLOSE(UNIT)
23011 CONTINUE
      I = I + 1
23001 GOTO 23000
23002 CONTINUE
      RETURN
      END
      INTEGER FUNCTION ALPHAN(C)
      LOGICAL*1 C, T
      LOGICAL*1 TYPE
      T = TYPE(C)
      IF (.NOT.(T .EQ. 1 .OR. T .EQ. 2))GOTO 23013
      ALPHAN=(1)
      RETURN
23013 CONTINUE
      ALPHAN=(0)
      RETURN
23014 CONTINUE
      END
      INTEGER FUNCTION BINSRC(WORD)
      LOGICAL*1 WORD(100)
      INTEGER FIRST, LAST, I, M, C
      INTEGER STRCMP
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      M = STRPTR(NLINES)
      IF (.NOT.(STRCMP(WORD, CHARAY(M)) .GT. 0))GOTO 23015
      BINSRC=(NLINES)
      RETURN
23015 CONTINUE
      M = STRPTR(1)
      IF (.NOT.(STRCMP(WORD, CHARAY(M)) .LT. 0))GOTO 23017
      BINSRC=(1)
      RETURN
23017 CONTINUE
      FIRST = 1
      LAST = NLINES
23019 IF (.NOT.((LAST - FIRST) .GT. 1))GOTO 23020
      I = (FIRST + LAST) / 2
      M = STRPTR(I)
      C = STRCMP(WORD, CHARAY(M))
      IF (.NOT.(C .EQ. 1))GOTO 23021
      FIRST = I
      GOTO 23022
23021 CONTINUE
      IF (.NOT.(C .EQ. 0))GOTO 23023
      LAST = I
      FIRST = I
      GOTO 23024
23023 CONTINUE
      LAST = I
23024 CONTINUE
23022 CONTINUE
      GOTO 23019
23020 CONTINUE
      BINSRC=(FIRST)
      RETURN
      END
      SUBROUTINE DOSPEL(UNIT)
      INTEGER I, M, N, IFERR, J, START, UNIT
      INTEGER GETLIN, FINDWD, GTWORD
      LOGICAL*1 BUF(512), WORD(512), ERRBUF(512)
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      N=GETLIN(BUF,UNIT)
23025 IF (.NOT.(N .NE. -1))GOTO 23027
      CALL PUTLIN(BUF, 2)
      J=1
23028 IF (.NOT.(BUF(J) .NE. 0))GOTO 23030
      IF (.NOT.(BUF(J) .EQ. 9))GOTO 23031
      ERRBUF(J) = 9
      GOTO 23032
23031 CONTINUE
      IF (.NOT.(BUF(J) .EQ. 10))GOTO 23033
      ERRBUF(J) = 10
      GOTO 23034
23033 CONTINUE
      ERRBUF(J) = 32
23034 CONTINUE
23032 CONTINUE
23029 J=J+1
      GOTO 23028
23030 CONTINUE
      ERRBUF(J) = 0
      I = 1
      IFERR = 0
23035 IF (.NOT.(GTWORD(BUF, I, WORD, START) .GT. 0))GOTO 23036
      CALL FOLD(WORD)
      IF (.NOT.(FINDWD(WORD) .EQ. 0))GOTO 23037
      IFERR = 1
      J=START
23039 IF (.NOT.(J .LT. I))GOTO 23041
      ERRBUF(J) = 42
23040 J=J+1
      GOTO 23039
23041 CONTINUE
23037 CONTINUE
      GOTO 23035
23036 CONTINUE
      IF (.NOT.(IFERR .EQ. 1))GOTO 23042
      CALL PUTLIN(ERRBUF, 2)
23042 CONTINUE
23026 N=GETLIN(BUF,UNIT)
      GOTO 23025
23027 CONTINUE
      RETURN
      END
      INTEGER FUNCTION FINDWD(WORD)
      LOGICAL*1 WORD(100)
      INTEGER I, JUNK, N
      INTEGER GETLIN, BINSRC, STRCMP, EQUAL, WDLOOK, OKWORD
      LOGICAL*1 BUF(512)
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      IF (.NOT.(OKWORD(WORD) .EQ. 1))GOTO 23044
      FINDWD=(1)
      RETURN
23044 CONTINUE
      IF (.NOT.(WDLOOK(WORD) .EQ. 1))GOTO 23046
      FINDWD=(0)
      RETURN
23046 CONTINUE
      I = BINSRC(WORD)
      CALL SEEK(LINPTR(I), DUNIT)
      N=GETLIN(BUF,DUNIT)
23048 IF (.NOT.(N .NE. -1))GOTO 23050
      BUF(N) = 0
      IF (.NOT.(STRCMP(WORD, BUF) .LE. 0))GOTO 23051
      GOTO 23050
23051 CONTINUE
23049 N=GETLIN(BUF,DUNIT)
      GOTO 23048
23050 CONTINUE
      IF (.NOT.(N .EQ. -1))GOTO 23053
      BUF(1) = 0
23053 CONTINUE
      IF (.NOT.(EQUAL(WORD, BUF) .EQ. 0))GOTO 23055
      CALL WDSTAL(WORD)
      FINDWD = 0
      GOTO 23056
23055 CONTINUE
      FINDWD = 1
23056 CONTINUE
      RETURN
      END
      SUBROUTINE GTROOT(ROOT)
      LOGICAL*1 ROOT(40)
      INTEGER I, FOUND
      INTEGER GETARG
      LOGICAL*1 DICT(5)
      DATA DICT(1)/100/,DICT(2)/105/,DICT(3)/99/,DICT(4)/116/,DICT(5)/0/
      FOUND = 0
      I=1
23057 IF (.NOT.(GETARG(I, ROOT, 40) .NE. -1))GOTO 23059
      IF (.NOT.(ROOT(1) .EQ. 45 .AND. (ROOT(2) .EQ. 100 .OR. ROOT(2) .EQ
     *. 68)))GOTO 23060
      CALL SCOPY(ROOT, 3, ROOT, 1)
      CALL DELARG(I)
      FOUND = 1
      GOTO 23059
23060 CONTINUE
23058 I=I+1
      GOTO 23057
23059 CONTINUE
      IF (.NOT.(FOUND .EQ. 0))GOTO 23062
      CALL STRCPY(DICT, ROOT)
23062 CONTINUE
      RETURN
      END
      INTEGER FUNCTION GTWORD(BUF, I, WORD, START)
      INTEGER I, START, J
      LOGICAL*1 BUF(100), WORD(100)
      INTEGER ALPHAN, LENGTH
23064 IF (.NOT.(ALPHAN(BUF(I)) .EQ. 0))GOTO 23065
      IF (.NOT.(BUF(I) .EQ. 0))GOTO 23066
      GOTO 23065
23066 CONTINUE
      I = I + 1
23067 CONTINUE
      GOTO 23064
23065 CONTINUE
      START = I
      J=1
23068 IF (.NOT.(ALPHAN(BUF(I)) .EQ. 1))GOTO 23070
      WORD(J) = BUF(I)
      I = I + 1
23069 J=J+1
      GOTO 23068
23070 CONTINUE
      WORD(J) = 0
      GTWORD=(LENGTH(WORD))
      RETURN
      END
      SUBROUTINE LODIDX
      LOGICAL*1 FILE(40), BUF(512), ROOT(40), SPATH(120)
      INTEGER INT, N, M, I, JUNK
      INTEGER OPEN, GETLIN, INDEXS, LOCCOM
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      LOGICAL*1 SUFFIX(3)
      LOGICAL*1 SRCSUF(3)
      DATA SUFFIX(1)/100/,SUFFIX(2)/120/,SUFFIX(3)/0/
      DATA SRCSUF(1)/0/,SRCSUF(2)/10/,SRCSUF(3)/0/
      CALL GTROOT(ROOT)
      CALL CONCAT(ROOT, SUFFIX, BUF)
      CALL IMPATH(SPATH)
      IF (.NOT.(LOCCOM(BUF, SPATH, SRCSUF, FILE) .NE. 12))GOTO 23071
      CALL CANT(BUF)
23071 CONTINUE
      INT = OPEN(FILE, 1)
      IF (.NOT.(INT .NE. -3))GOTO 23073
      M = 1
      N=1
23075 IF (.NOT.(GETLIN(BUF, INT) .NE. -1))GOTO 23077
      I = 1
23078 IF (.NOT.(BUF(I) .NE. 32))GOTO 23079
      I = I + 1
      GOTO 23078
23079 CONTINUE
      JUNK = M + I
      IF (.NOT.(N .GT. 1800 .OR. JUNK .GT. 18000))GOTO 23080
      CALL ERROR(48HDictionary index too large for internal storage!)
23080 CONTINUE
      STRPTR(N) = M
      BUF(I) = 0
      I = I + 1
      CALL STCOPY(BUF, 1, CHARAY, M)
      M = M + 1
      CALL CTOPTR(BUF, I, LINPTR(N))
23076 N=N+1
      GOTO 23075
23077 CONTINUE
      NLINES = N - 1
      FREEP = N
      FREEC = M
      CALL CLOSE(INT)
      GOTO 23074
23073 CONTINUE
      CALL CANT(FILE)
23074 CONTINUE
      I = INDEXS(FILE, SUFFIX)
      FILE(I) = 0
      DUNIT = OPEN(FILE, 1)
      IF (.NOT.(DUNIT .EQ. -3))GOTO 23082
      CALL CANT(FILE)
23082 CONTINUE
      RETURN
      END
      INTEGER FUNCTION OKWORD(WORD)
      LOGICAL*1 WORD(100)
      INTEGER TYPE, EQUAL
      LOGICAL*1 A(2)
      LOGICAL*1 I(2)
      DATA A(1)/97/,A(2)/0/
      DATA I(1)/105/,I(2)/0/
      OKWORD = 0
      IF (.NOT.(TYPE(WORD(1)) .EQ. 2))GOTO 23084
      OKWORD = 1
      GOTO 23085
23084 CONTINUE
      IF (.NOT.(EQUAL(WORD, A) .EQ. 1))GOTO 23086
      OKWORD = 1
      GOTO 23087
23086 CONTINUE
      IF (.NOT.(EQUAL(WORD, I) .EQ. 1))GOTO 23088
      OKWORD = 1
23088 CONTINUE
23087 CONTINUE
23085 CONTINUE
      RETURN
      END
      INTEGER FUNCTION WDLOOK(WORD)
      LOGICAL*1 WORD(100)
      INTEGER I, J
      INTEGER EQUAL
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      I=NLINES+1
23090 IF (.NOT.(I .LT. FREEP))GOTO 23092
      J = STRPTR(I)
      IF (.NOT.(EQUAL(WORD, CHARAY(J)) .EQ. 1))GOTO 23093
      WDLOOK=(1)
      RETURN
23093 CONTINUE
23091 I=I+1
      GOTO 23090
23092 CONTINUE
      WDLOOK=(0)
      RETURN
      END
      SUBROUTINE WDSTAL(WORD)
      LOGICAL*1 WORD(100)
      INTEGER I
      INTEGER LENGTH
      COMMON / CSPELL / NLINES, DUNIT, FREEP, FREEC, STRPTR(1800), LINPT
     *R(1800), CHARAY(18000)
      INTEGER NLINES
      INTEGER DUNIT
      INTEGER FREEP
      INTEGER FREEC
      INTEGER STRPTR
      INTEGER*4 LINPTR
      LOGICAL*1 CHARAY
      IF (.NOT.(FREEP .LE. 1800))GOTO 23095
      I = FREEC + LENGTH(WORD)
      IF (.NOT.(I .LE. 18000))GOTO 23097
      STRPTR(FREEP) = FREEC
      FREEP = FREEP + 1
      CALL STCOPY(WORD, 1, CHARAY, FREEC)
      FREEC = FREEC + 1
23097 CONTINUE
23095 CONTINUE
      RETURN
      END
