      INTEGER IN,TEXT,WORDS,SWORDS
      INTEGER MKTEMP,OPEN
      INTEGER MISSP0
      INTEGER MKTABL
      INTEGER STATE(4),INCLU0,VERBO0
      INTEGER GFNARG
      INTEGER FNAME(180)
      INTEGER A$BUF(200)
      INTEGER MEMAA0(32767)
      COMMON /DS$MEM/MEMAA0
      INTEGER PARSCL
      INTEGER AAAAA0(15)
      INTEGER AAAAB0
      INTEGER AAAAC0
      DATA AAAAA0/246,188,230,190,230,188,230,190,238,188,233,231,238,19
     *0,0/
      IF((PARSCL(AAAAA0,A$BUF).NE.-3))GOTO 10000
        CALL ERROR('Usage:  spell [-{v|f}] {file}.')
10000 IF((A$BUF(246-225+1).EQ.0))GOTO 10001
        VERBO0=1
        GOTO 10002
10001   VERBO0=0
10002 IF((A$BUF(230-225+1).EQ.0))GOTO 10003
        INCLU0=1
        GOTO 10004
10003   INCLU0=0
10004 TEXT=MKTEMP(3)
      IF((TEXT.NE.-3))GOTO 10005
        CALL ERROR('can''t create temporary file.')
10005 STATE(1)=1
10006   AAAAB0=GFNARG(FNAME,STATE)
        GOTO 10007
10008     GOTO 10009
10010     CALL PRINT(-15,'*s:  can''t open*n.',FNAME)
        GOTO 10011
10012     IN=OPEN(FNAME,1)
          IF((IN.NE.-3))GOTO 10013
            CALL PRINT(-15,'*s:  can''t open*n.',FNAME)
            GOTO 10014
10013       CALL FCOPY(IN,TEXT)
            CALL CLOSE(IN)
10014   GOTO 10011
10007   AAAAC0=AAAAB0+4
        GOTO(10010,10012,10008),AAAAC0
10011 CONTINUE
      GOTO 10006
10009 WORDS=MKTEMP(3)
      IF((WORDS.NE.-3))GOTO 10015
        CALL ERROR('can''t open temporary file.')
10015 CALL REWIND(TEXT)
      CALL SEPAR0(TEXT,WORDS,INCLU0)
      SWORDS=MKTEMP(3)
      IF((SWORDS.NE.-3))GOTO 10016
        CALL ERROR('can''t open temporary file.')
10016 CALL REWIND(WORDS)
      CALL SORT(WORDS,SWORDS)
      CALL RMTEMP(WORDS)
      CALL REWIND(SWORDS)
      CALL DSINIT(32767)
      MISSP0=MKTABL(0)
      CALL FINDM0(SWORDS,MISSP0)
      IF((VERBO0.NE.1))GOTO 10017
        CALL REWIND(TEXT)
        CALL HIGHL0(TEXT,MISSP0,-11,INCLU0)
        GOTO 10018
10017   CALL REPOR0(MISSP0,-11,INCLU0)
10018 CALL RMTEMP(TEXT)
      CALL RMTEMP(SWORDS)
      CALL SWT
      END
      SUBROUTINE SEPAR0(TEXT,WORDS,IFC)
      INTEGER TEXT,WORDS
      INTEGER IFC
      INTEGER LINE(102),WORD(102)
      INTEGER I,FIRST,LAST
      INTEGER GETWO0,GETLIN
10019 IF((GETLIN(LINE,TEXT).EQ.-1))GOTO 10020
        IF((IFC.NE.0))GOTO 10021
        IF((LINE(1).NE.174))GOTO 10021
          GOTO 10019
10021   I=1
10022   IF((GETWO0(WORD,LINE,I,FIRST,LAST).EQ.-1))GOTO 10023
          CALL PUTLIN(WORD,WORDS)
          CALL PUTCH(138,WORDS)
        GOTO 10022
10023 GOTO 10019
10020 RETURN
      END
      INTEGER FUNCTION GETWO0(WORD,LINE,I,FIRST,LAST)
      INTEGER WORD(102),LINE(102)
      INTEGER I,FIRST,LAST
      INTEGER J
10024   CONTINUE
10025     IF((LINE(I).NE.0))GOTO 10026
            GETWO0=-1
            RETURN
10026     IF((193.GT.LINE(I)))GOTO 10029
          IF((LINE(I).GT.218))GOTO 10029
          GOTO 10028
10029     IF((225.GT.LINE(I)))GOTO 10030
          IF((LINE(I).GT.250))GOTO 10030
          GOTO 10028
10030     GOTO 10027
10028       GOTO 10031
10027     I=I+(1)
        GOTO 10025
10031   J=1
        FIRST=I
10032   IF((LINE(I).EQ.167))GOTO 10034
        IF((193.GT.LINE(I)))GOTO 10035
        IF((LINE(I).GT.218))GOTO 10035
        GOTO 10034
10035   IF((225.GT.LINE(I)))GOTO 10036
        IF((LINE(I).GT.250))GOTO 10036
        GOTO 10034
10036   GOTO 10033
10034     WORD(J)=LINE(I)
          IF((193.GT.WORD(J)))GOTO 10037
          IF((WORD(J).GT.218))GOTO 10037
            WORD(J)=WORD(J)-193+225
10037     J=J+(1)
          I=I+(1)
        GOTO 10032
10033   IF((WORD(J-1).NE.167))GOTO 10038
          J=J-(1)
          LAST=I-2
          GOTO 10039
10038     LAST=I-1
10039   WORD(J)=0
      IF((J.LE.1))GOTO 10024
      GETWO0=J-1
      RETURN
      END
      SUBROUTINE FINDM0(SWORDS,MISSP0)
      INTEGER SWORDS
      INTEGER MISSP0
      INTEGER WORD(102),DWORD(102)
      INTEGER DICTI0
      INTEGER OPEN
      INTEGER I
      INTEGER STRCMP,GETLIN
      INTEGER LENGTH
      INTEGER AAAAD0(13)
      INTEGER AAAAE0
      DATA AAAAD0/189,228,233,227,244,233,239,238,225,242,249,189,0/
      DICTI0=OPEN(AAAAD0,1)
      IF((DICTI0.NE.-3))GOTO 10040
        CALL ERROR('=dictionary=:  can''t open.')
10040 IF((GETLIN(DWORD,DICTI0).NE.-1))GOTO 10041
        CALL ERROR('dictionary is empty!.')
10041 IF((GETLIN(WORD,SWORDS).NE.-1))GOTO 10042
        RETURN
10042 CONTINUE
10043   I=LENGTH(WORD)
        IF((WORD(I-2).NE.167))GOTO 10044
        IF((WORD(I-1).NE.243))GOTO 10044
          I=I-(2)
          WORD(I)=138
          WORD(I+1)=0
10044   AAAAE0=STRCMP(WORD,DWORD)
        GOTO 10045
10046     I=1
          GOTO 10049
10047     I=I+(1)
10049     IF((WORD(I).EQ.138))GOTO 10048
          GOTO 10047
10048     WORD(I)=0
          CALL ENTER(WORD,0,MISSP0)
          IF((GETLIN(WORD,SWORDS).NE.-1))GOTO 10050
            GOTO 10051
10050   GOTO 10052
10053     IF((GETLIN(WORD,SWORDS).NE.-1))GOTO 10054
            GOTO 10051
10054   GOTO 10052
10055     IF((GETLIN(DWORD,DICTI0).NE.-1))GOTO 10056
10057         I=1
              GOTO 10060
10058         I=I+(1)
10060         IF((WORD(I).EQ.138))GOTO 10059
              GOTO 10058
10059         WORD(I)=0
              CALL ENTER(WORD,0,MISSP0)
            IF((GETLIN(WORD,SWORDS).NE.-1))GOTO 10057
            GOTO 10051
10056   GOTO 10052
10045   GOTO(10046,10053,10055),AAAAE0
10052 CONTINUE
      GOTO 10043
10051 CALL CLOSE(DICTI0)
      RETURN
      END
      SUBROUTINE HIGHL0(TEXT,MISSP0,OUT,IFC)
      INTEGER TEXT,OUT
      INTEGER MISSP0
      INTEGER IFC
      INTEGER JUNK,I,FIRST,LAST,J,LIMIT
      INTEGER GETWO0,LOOKUP,GETLIN
      INTEGER LINE(102),WORD(102),HIGHM0(102)
      DO 10061 J=1,102
        HIGHM0(J)=160
10061 CONTINUE
10062 CONTINUE
10063 IF((GETLIN(LINE,TEXT).EQ.-1))GOTO 10064
        CALL PUTCH(160,OUT)
        CALL PUTLIN(LINE,OUT)
        IF((IFC.NE.0))GOTO 10065
        IF((LINE(1).NE.174))GOTO 10065
          GOTO 10063
10065   LIMIT=0
        I=1
10066   IF((GETWO0(WORD,LINE,I,FIRST,LAST).EQ.-1))GOTO 10067
          IF((LOOKUP(WORD,JUNK,MISSP0).NE.1))GOTO 10068
            DO 10069 J=FIRST,LAST
              HIGHM0(J)=LINE(J)
10069       CONTINUE
10070       LIMIT=LAST
10068   GOTO 10066
10067   IF((LIMIT.LE.0))GOTO 10071
          HIGHM0(LIMIT+1)=138
          HIGHM0(LIMIT+2)=0
          CALL PUTCH(171,OUT)
          CALL PUTLIN(HIGHM0,OUT)
          J=1
          GOTO 10074
10072     J=J+(1)
10074     IF((J.GT.LIMIT+2))GOTO 10073
            HIGHM0(J)=160
          GOTO 10072
10073   CONTINUE
10071 GOTO 10063
10064 RETURN
      END
      SUBROUTINE REPOR0(MISSP0,OUT,IFC)
      INTEGER MISSP0
      INTEGER OUT
      INTEGER IFC
      INTEGER POSN
      INTEGER JUNK
      INTEGER SCTABL
      INTEGER EXPAND,NEWWO0,OPEN
      INTEGER WORD(102)
      INTEGER NEWST0(102)
      LOGICAL SAVEB0
      INTEGER AAAAF0(12)
      DATA AAAAF0/189,238,229,247,223,247,239,242,228,243,189,0/
      SAVEB0=(EXPAND(AAAAF0,NEWST0,102).NE.-3)
      IF((.NOT.SAVEB0))GOTO 10075
        NEWWO0=OPEN(NEWST0,3)
        IF((NEWWO0.NE.-3))GOTO 10076
          SAVEB0=.FALSE.
          GOTO 10077
10076     CALL WIND(NEWWO0)
10077 CONTINUE
10075 POSN=0
10078 IF((SCTABL(MISSP0,WORD,JUNK,POSN).EQ.-1))GOTO 10079
        CALL PUTLIN(WORD,OUT)
        CALL PUTCH(138,OUT)
        IF((.NOT.SAVEB0))GOTO 10080
          CALL PUTLIN(WORD,NEWWO0)
          CALL PUTCH(138,NEWWO0)
10080 GOTO 10078
10079 RETURN
      END
      SUBROUTINE SORT(IFD,OFD)
      INTEGER IFD,OFD
      INTEGER LINBUF(32767)
      INTEGER INFIL(7),LINPTR(4096),NLINES,HIGH,LIM,LOW,T
      INTEGER GTEXT
      INTEGER OUTFD
      INTEGER MAKFIL
      HIGH=0
10081   T=GTEXT(LINPTR,NLINES,LINBUF,IFD)
        CALL QUICK(LINPTR,NLINES,LINBUF)
        IF((T.NE.-1))GOTO 10083
        IF((HIGH.GT.0))GOTO 10083
        GOTO 10082
10083     HIGH=HIGH+(1)
          OUTFD=MAKFIL(HIGH)
          CALL PTEXT(LINPTR,NLINES,LINBUF,OUTFD)
          CALL CLOSE(OUTFD)
10082 CONTINUE
      IF((T.NE.-1))GOTO 10081
      IF((HIGH.NE.0))GOTO 10084
        CALL PTEXT(LINPTR,NLINES,LINBUF,OFD)
        CALL REWIND(OFD)
        RETURN
10084 LOW=1
      GOTO 10087
10085 LOW=LOW+(7)
10087 IF((LOW.GE.HIGH))GOTO 10086
        LIM=MIN0(LOW+7-1,HIGH)
        CALL GOPEN(INFIL,LOW,LIM)
        IF((LIM.LT.HIGH))GOTO 10088
          CALL MERGE(INFIL,LIM-LOW+1,OFD)
          GOTO 10089
10088     HIGH=HIGH+(1)
          OUTFD=MAKFIL(HIGH)
          CALL MERGE(INFIL,LIM-LOW+1,OUTFD)
          CALL CLOSE(OUTFD)
10089   CALL GREMOV(INFIL,LOW,LIM)
      GOTO 10085
10086 CALL REWIND(OFD)
      RETURN
      END
      SUBROUTINE GNAME(N,NAME)
      INTEGER N
      INTEGER NAME(30)
      INTEGER AAAAG0(17)
      DATA AAAAG0/189,244,229,237,240,189,175,243,240,189,240,233,228,18
     *9,170,233,0/
      CALL ENCODE(NAME,30,AAAAG0,N)
      RETURN
      END
      INTEGER FUNCTION MAKFIL(N)
      INTEGER N
      INTEGER NAME(30)
      INTEGER CREATE
      CALL GNAME(N,NAME)
      MAKFIL=CREATE(NAME,3)
      IF((MAKFIL.NE.-3))GOTO 10090
        CALL CANT(NAME)
10090 RETURN
      END
      SUBROUTINE GOPEN(INFIL,LOW,LIM)
      INTEGER INFIL(7)
      INTEGER LOW,LIM
      INTEGER NAME(30)
      INTEGER I
      INTEGER OPEN
      I=1
      GOTO 10093
10091 I=I+(1)
10093 IF((I.GT.LIM-LOW+1))GOTO 10092
        CALL GNAME(LOW+I-1,NAME)
        INFIL(I)=OPEN(NAME,1)
        IF((INFIL(I).NE.-3))GOTO 10094
          CALL CANT(NAME)
10094 GOTO 10091
10092 RETURN
      END
      SUBROUTINE GREMOV(INFIL,LOW,LIM)
      INTEGER INFIL(7)
      INTEGER LOW,LIM
      INTEGER NAME(30)
      INTEGER I
      I=1
      GOTO 10097
10095 I=I+(1)
10097 IF((I.GT.LIM-LOW+1))GOTO 10096
        CALL CLOSE(INFIL(I))
        CALL GNAME(LOW+I-1,NAME)
        CALL REMOVE(NAME)
      GOTO 10095
10096 RETURN
      END
      SUBROUTINE MERGE(INFIL,NFILES,OUTFIL)
      INTEGER INFIL(7),OUTFIL
      INTEGER NFILES
      INTEGER LINBUF(900)
      INTEGER GETLIN
      INTEGER I,INF,LBP,LP1,NF,LINPTR(7)
      LBP=1
      NF=0
      I=1
      GOTO 10100
10098 I=I+(1)
10100 IF((I.GT.NFILES))GOTO 10099
        IF((GETLIN(LINBUF(LBP),INFIL(I)).EQ.-1))GOTO 10101
          NF=NF+(1)
          LINPTR(NF)=LBP
          LBP=LBP+(102)
10101 GOTO 10098
10099 CALL QUICK(LINPTR,NF,LINBUF)
10102 IF((NF.LE.0))GOTO 10103
        LP1=LINPTR(1)
        CALL PUTLIN(LINBUF(LP1),OUTFIL)
        INF=LP1/102+1
        IF((GETLIN(LINBUF(LP1),INFIL(INF)).NE.-1))GOTO 10104
          LINPTR(1)=LINPTR(NF)
          NF=NF-(1)
10104   CALL REHEAP(LINPTR,NF,LINBUF)
      GOTO 10102
10103 RETURN
      END
      SUBROUTINE REHEAP(LINPTR,NF,LINBUF)
      INTEGER LINPTR(1),NF
      INTEGER LINBUF(32767)
      INTEGER I,J
      INTEGER COMPA0
      I=1
      GOTO 10107
10105 I=J
10107 IF((2*I.GT.NF))GOTO 10106
        J=2*I
        IF((J.GE.NF))GOTO 10108
          IF((COMPA0(LINPTR(J),LINPTR(J+1),LINBUF).LE.0))GOTO 10109
            J=J+(1)
10109   CONTINUE
10108   IF((COMPA0(LINPTR(I),LINPTR(J),LINBUF).GT.0))GOTO 10110
          GOTO 10106
10110   CALL EXCHAN(LINPTR(I),LINPTR(J),LINBUF)
      GOTO 10105
10106 RETURN
      END
      INTEGER FUNCTION GTEXT(LINPTR,NLINES,LINBUF,INFILE)
      INTEGER LINPTR(4096),NLINES
      INTEGER LINBUF(32767)
      INTEGER INFILE
      INTEGER LBP,LEN
      INTEGER GETLIN
      NLINES=0
      LBP=1
10111   LEN=GETLIN(LINBUF(LBP),INFILE)
        IF((LEN.NE.-1))GOTO 10112
          GOTO 10113
10112   NLINES=NLINES+(1)
        LINPTR(NLINES)=LBP
        LBP=LBP+(LEN+1)
      IF((LBP.GE.32767-102))GOTO 10114
      IF((NLINES.GE.4096))GOTO 10114
      GOTO 10111
10114 CONTINUE
10113 GTEXT=LEN
      RETURN
      END
      SUBROUTINE PTEXT(LINPTR,NLINES,LINBUF,OUTFIL)
      INTEGER LINPTR(4096),NLINES
      INTEGER LINBUF(32767)
      INTEGER OUTFIL
      INTEGER I,J
      I=1
      GOTO 10117
10115 I=I+(1)
10117 IF((I.GT.NLINES))GOTO 10116
        J=LINPTR(I)
        CALL PUTLIN(LINBUF(J),OUTFIL)
      GOTO 10115
10116 RETURN
      END
      INTEGER FUNCTION COMPA0(LP1,LP2,LINBUF)
      INTEGER LP1,LP2
      INTEGER LINBUF(1)
      INTEGER C1,C2,UC1,UC2
      INTEGER MAPUP
      INTEGER I,J
      I=LP1
      J=LP2
10118   C1=LINBUF(I)
        C2=LINBUF(J)
        IF((C1.EQ.C2))GOTO 10119
          GOTO 10120
10119   IF((C1.NE.0))GOTO 10121
          COMPA0=0
          RETURN
10121   I=I+(1)
        J=J+(1)
      GOTO 10118
10120 UC1=MAPUP(C1)
      UC2=MAPUP(C2)
      GOTO 10122
10123   COMPA0=-1
      GOTO 10124
10125   COMPA0=+1
      GOTO 10124
10126   COMPA0=-1
      GOTO 10124
10122 IF((UC1.LT.UC2))GOTO 10123
      IF((UC1.GT.UC2))GOTO 10125
      IF((225.GT.C1))GOTO 10127
      IF((C1.GT.250))GOTO 10127
      GOTO 10126
10127 CONTINUE
        COMPA0=+1
10124 RETURN
      END
      SUBROUTINE EXCHAN(LP1,LP2,LINBUF)
      INTEGER LP1,LP2
      INTEGER LINBUF(1)
      INTEGER K
      K=LP1
      LP1=LP2
      LP2=K
      RETURN
      END
      SUBROUTINE QUICK(LINPTR,NLINES,LINBUF)
      INTEGER LINPTR(1),NLINES
      INTEGER LINBUF(1)
      INTEGER I,J,LV(12),P,PIVLIN,UV(12)
      INTEGER COMPA0
      LV(1)=1
      UV(1)=NLINES
      P=1
10128 IF((P.LE.0))GOTO 10129
        IF((LV(P).LT.UV(P)))GOTO 10130
          P=P-(1)
          GOTO 10131
10130     I=LV(P)-1
          J=UV(P)
          PIVLIN=LINPTR(J)
10132     IF((I.GE.J))GOTO 10133
            I=I+(1)
            GOTO 10136
10134       I=I+(1)
10136       IF((COMPA0(LINPTR(I),PIVLIN,LINBUF).GE.0))GOTO 10135
            GOTO 10134
10135       J=J-(1)
            GOTO 10139
10137       J=J-(1)
10139       IF((J.LE.I))GOTO 10138
              IF((COMPA0(LINPTR(J),PIVLIN,LINBUF).GT.0))GOTO 10140
                GOTO 10138
10140       GOTO 10137
10138       IF((I.GE.J))GOTO 10141
              CALL EXCHAN(LINPTR(I),LINPTR(J),LINBUF)
10141     GOTO 10132
10133     J=UV(P)
          CALL EXCHAN(LINPTR(I),LINPTR(J),LINBUF)
          IF((I-LV(P).GE.UV(P)-I))GOTO 10142
            LV(P+1)=LV(P)
            UV(P+1)=I-1
            LV(P)=I+1
            GOTO 10143
10142       LV(P+1)=I+1
            UV(P+1)=UV(P)
            UV(P)=I-1
10143     P=P+(1)
10131 GOTO 10128
10129 RETURN
      END
C ---- Long Name Map ----
C highlightmisspellings          highl0
C misspellings                   missp0
C compare                        compa0
C includefmtcommands             inclu0
C newstuff                       newst0
C verbose                        verbo0
C reportmisspellings             repor0
C newwords                       newwo0
C Mem                            memaa0
C getword                        getwo0
C savebadwords                   saveb0
C separate                       separ0
C findmisspellings               findm0
C dictionary                     dicti0
C highlighter                    highm0
