;<MFEXEC>SPLCOR.MAC;11    28-JUN-79 15:39:02    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;10    21-JUN-79 14:26:34    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;8    21-JUN-79 14:19:54    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;7    21-JUN-79 14:12:28    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;6    21-JUN-79 14:03:36    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;6    21-JUN-79 14:01:51    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;5    21-JUN-79 12:31:46    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;4    21-JUN-79 12:20:12    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;3    21-JUN-79 12:16:37    EDIT BY WEISSMAN
;<MFEXEC>SPLCOR.MAC;2    21-JUN-79 11:41:38    EDIT BY WEISSMAN
	TITLE	SPLCOR
	SUBTTL	AUSTIN HENDERSON, JUNE 1976

	INTERN	SPLCOR

	SEARCH XSTG


INTERN .CORRECT
EXTERN CONF
.CORRECT:
	NOISE	(spelling errors)
	CONFIRM
	TLNE	Z,F1		; "NO CORRECT"?
	TDZA	A,A		; YES
	SETO	A,		; NO
	MOVEM	A,DOCORR
	RET
; Spelling corrector coded for the EXEC

;1/ pointer to typed string
;2/ pointer to table of correct entries
;	wd 0: count of entries
;	wd i: [bits,,routine],,[ASCIZ/string/]
;	PUSHJ	P,SPLCOR
;+1 always
; 1,2/ as on call
; 3/ index to entry chosen (0 implies no entry was close)
;
; saves all AC's.

P=17

SPLCOR:	MOVEM	17,SAVD17	;save registers
	HRRZI	17,REGS
	BLT	17,REGS+16
	MOVE	17,SAVD17
	MOVEM	2,TBL
	SETZ	14,	;spread input string
	MOVEI	16,TCHARS
SPLCR3:	ILDB	15,1
	JUMPE	15,SPLCR4
	ADDI	14,1
	ADDI	16,1
	MOVEM	15,(16)
	JRST	SPLCR3
SPLCR4:	MOVEM	14,TCHARS
	MOVE	10,(2)	;count of entries in table
	SETZ	11,
	SETZM	RES
	MOVEI	16,^D100
	MOVEM	16,SLNGTH
	SETZM	SCORE
SPLCLP:	SOJL	10,SPLCR1
	ADDI	11,1
	AOS	16,TBL	;location of entry
	MOVE	1,(16)	;entry
;eliminate non-applicable entry
	HLRZ 2,1
	MOVE 2,(2)
	TLNE 2,INVIS
	 JRST	SPLCLP
	HRLI	1,440700	;string pointer to correct string
	PUSHJ	P,SPLSCR	;score string against this entry
	JRST	SPLCLP	;not close
	CAMGE	1,SCORE	;1/score 2/length of entry string
	JRST	SPLCLP	;score<SCORE
	CAME	1,SCORE
	JRST	SPLCR2
	CAML	2,SLNGTH
	JRST	SPLCLP	;score=SCORE & length ge SLNGTH
SPLCR2:	MOVEM	1,SCORE	;this is the best entry yet
	MOVEM	2,SLNGTH
	MOVEM	11,RES
	JRST	SPLCLP
SPLCR1:	HRLZI	17,REGS	;restore registers
	BLT	17,16
	MOVE	17,SAVD17
	MOVE	3,RES
	POPJ	P,


;1/ input string pointer
;2/ command string pointer (correct)
;	PUSHJ	P,SPLSCR	scorer clobbers all registers xcpt 10,11,17
;+1 not close
;+2 close
; 1/ score (70 to 100; 100 is best)
; 2/ length of command string

TI=3
CI=4
T=5
C=6

SPLSCR:	SETZM	N	;initialization
	SETZM	NTRANS
	SETZM	DOUBLD
	SETZM	TN1
	SETZM	TN2
	SETZM	CN1
	SETZM	CN2
	SETZM	OLDT
	MOVEI	TI,1
	MOVEI	CI,1
	MOVEM	CI,SAVDCI
	SETZ	14,	;spread command string
	MOVEI	16,CCHARS
SPLS01:	ILDB	15,1
	JUMPE	15,SPLS02
	ADDI	14,1
	ADDI	16,1
	MOVEM	15,(16)
	JRST	SPLS01
SPLS02:	MOVEM	14,CCHARS	;count
SPLSLP:	MOVE	T,TCHARS(TI)
	MOVE	C,CCHARS(CI)
	SETZM	CNEXT
	CAMN	CI,SAVDCI
	SETOM	CNEXT
	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KIPE	TN2
	JRST	SPLSFA
	MOVE	16,TI
	SUB	16,DOUBLD
	MOVEM	16,TN2
	MOVEM	T,TS2
SPLS31:	ADDI	TI,1
	MOVEM	T,OLDT
	JRST	SPLSLP
;end of loop
SPLS03:	SKIPG	CN1
	JRST	SPLS32
	MOVE	16,CN1
	CAMN	16,TN1
	JRST	SPLS33
	CAME	16,TN2
	JRST	SPLS32
SPLS33:	SOS	N
SPLS32:	SKIPG	CN2
	JRST	SPLS34
	MOVE	16,CN2
	CAMN	16,TN1
	JRST	SPLS35
	CAME	16,TN2
	JRST	SPLS34
SPLS35:	SOS	N
SPLS34:	SKIPG	CN1
	JRST	SPLS36
	AOS	N
	SKIPLE	CN2
	AOS	N
SPLS36:	SKIPG	TN1
	JRST	SPLS37
	AOS	N
	SKIPLE	TN2
	AOS	N
SPLS37:	SKIPG	16,N
	JRST	SPLS38
	ADD	16,NTRANS
	MOVEM	16,N
SPLS38:	MOVE	T,TCHARS
	CAMLE	T,TI
	MOVE	T,TI	;effective length of typed string
	MOVE	C,CCHARS
	CAMLE	C,CI
	MOVE	C,CI	;effective length of correct string
	MOVE	16,T
	SUB	16,DOUBLD
	ADD	16,C	;b
	MOVE	1,16
	MOVE	15,N
	LSH	15,1
	SUB	1,15
	IMULI	1,^D100
	IDIV	1,16	;sc
	CAIGE	1,^D70
	JRST	SPLSFA
	MOVE	2,CCHARS
	AOS	(P)
SPLSFA:	POPJ	P,


;1/ a typed character
;2/ a correct character
;	PUSHJ	P,SPLSIM	;checks for similarity
;+1 not similar
;+2 similar

SPLSIM:	CAME	1,2
	JRST	SPLS50
SPLS51:	AOS	(P)
	POPJ	P,
SPLS50:	MOVE	7,SPLTBL(2)
	HLRZ	2,7
	CAMN	1,2
	JRST	SPLS51
	HRRZ	2,7
	CAMN	1,2
	JRST	SPLS51
	POPJ	P,

;declarations

;  x,,y   ;z :: you might have meant x or y when you typed z
SPLTBL:	^D-1,,^D-1	;^D0
	^D-1,,^D-1	;^D1
	^D-1,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D-1	;^D64
	^D97,,^D-1	;^D65
	^D98,,^D-1	;^D66
	^D99,,^D-1	;^D67
	^D100,,^D-1	;^D68
	^D101,,^D-1	;^D69
	^D102,,^D-1	;^D70
	^D103,,^D-1	;^D71
	^D104,,^D-1	;^D72
	^D105,,^D-1	;^D73
	^D106,,^D-1	;^D74
	^D107,,^D-1	;^D75
	^D108,,^D-1	;^D76
	^D109,,^D-1	;^D77
	^D110,,^D-1	;^D78
	^D111,,^D-1	;^D79
	^D112,,^D-1	;^D80
	^D113,,^D-1	;^D81
	^D114,,^D-1	;^D82
	^D115,,^D-1	;^D83
	^D116,,^D-1	;^D84
	^D117,,^D-1	;^D85
	^D118,,^D-1	;^D86
	^D119,,^D-1	;^D87
	^D120,,^D-1	;^D88
	^D121,,^D-1	;^D89
	^D122,,^D-1	;^D90
	^D123,,^D-1	;^D91
	^D124,,^D-1	;^D92
	^D125,,^D-1	;^D93
	^D126,,^D-1	;^D94
	^D48,,^D-1	;^D95
	^D64,,^D-1	;^D96
	^D65,,^D-1	;^D97
	^D66,,^D-1	;^D98
	^D67,,^D-1	;^D99
	^D68,,^D-1	;^D100
	^D69,,^D-1	;^D101
	^D70,,^D-1	;^D102
	^D71,,^D-1	;^D103
	^D72,,^D-1	;^D104
	^D73,,^D-1	;^D105
	^D74,,^D-1	;^D106
	^D75,,^D-1	;^D107
	^D76,,^D-1	;^D108
	^D77,,^D-1	;^D109
	^D78,,^D-1	;^D110
	^D79,,^D-1	;^D111
	^D80,,^D-1	;^D112
	^D81,,^D-1	;^D113
	^D82,,^D-1	;^D114
	^D83,,^D-1	;^D115
	^D84,,^D-1	;^D116
	^D85,,^D-1	;^D117
	^D86,,^D-1	;^D118
	^D87,,^D-1	;^D119
	^D88,,^D-1	;^D120
	^D89,,^D-1	;^D121
	^D90,,^D-1	;^D122
	^D91,,^D-1	;^D123
	^D92,,^D-1	;^D124
	^D93,,^D-1	;^D125
	^D94,,^D-1	;^D126
	^D-1,,^D-1 	;^D127

	END
