! ! SPELL_CHECK.TPU ! ! Author: Dilip Jain ! Schwitzer Div., Household Mfg., Inc. ! P.O. Box 80-B ! Indianapolis, IN 46206 ! ! Procedure to check if the next string of alphabetic characters (word) in the ! current buffer is in a dictionary file (a la spelling check). If the word is ! not in the dictionary it is either misspelt in which case the procedure gives ! user the option to replace the misspelt word with a user entered correct word; ! or the word is spelt correctly (in which case the procedure gives the user the ! option to add that word to a dictionary). ! PROCEDURE dictionary(return_code) ! LOCAL w_mark_1, w_mark_2, w_range, w_string_1, w_string_2, w_string_3, ans, out_str, out_nbr, password; ! ! Search for a string of alphabetic characters ! w_range := SEARCH(sch$edt_word_pattern,FORWARD,NO_EXACT); IF w_range = 0 THEN return_code := 0; RETURN; ENDIF; w_string_1 := SUBSTR(w_range,1,LENGTH(w_range)); w_string_2 := w_string_1; CHANGE_CASE(w_string_2,UPPER); ! ! Pass the string of characters to the FORTRAN program for checking. ! out_str := CALL_USER(1,w_string_2); out_nbr := INT(out_str); ! ! Take action for words not found. ! CASE out_nbr FROM 1 TO 9 [1]: ! ! The character string was not in the dictionary; Highlight the character ! string under consideration; Give Error message ! POSITION(BEGINNING_OF(w_range)); w_mark_1 := MARK(NONE); POSITION(END_OF (w_range)); w_mark_2 := MARK(NONE); w_range := CREATE_RANGE(w_mark_1,w_mark_2,REVERSE); UPDATE(CURRENT_WINDOW); MESSAGE('Word "'+w_string_1+'" not found in the dictionary!'); ! ! Give user the option to ignore the error message, correct the word, or ! add the word to the dictionary. ! ans := READ_LINE( 'Press C)orrect; Add to U)ser, S)ystem Dictionary; I)gnore; Q)uit; ',1); CHANGE_CASE(ans,UPPER); ! CASE ans FROM 'C' TO 'U' ! ! User wants to add the word to the SYSTEM dictionary ! ['S'] : IF sch$edt_spell_sysusr = 0 THEN password := READ_LINE('Password: '); CHANGE_CASE(password,UPPER); IF password = sch$edt_spell_paswrd THEN sch$edt_spell_sysusr := 1; out_str := CALL_USER(2,w_string_2); out_nbr := INT(out_str); ELSE ans := READ_LINE('Wrong password; Press a key: ',1); ENDIF; ELSE out_str := CALL_USER(2,w_string_2); out_nbr := INT(out_str); ENDIF; ! ! User wants to add the word to the USER dictionary ! ['U'] : out_str := CALL_USER(4,w_string_2); out_nbr := INT(out_str); ! ! User wants to ignore the word. So add it to the WORDS TO IGNORE list ! ['I'] : out_str := CALL_USER(6,w_string_2); out_nbr := INT(out_str); ! ! User wants to correct the wrong word. Prompt for the correct spelling. ! ['C'] : w_string_3 := READ_LINE('Enter correct spelling for "'+w_string_1+'": '); ERASE(w_range); COPY_TEXT(w_string_3); ! ! User wants to quit checking the errors. ! ['Q'] : return_code := 0; RETURN; ENDCASE; [6]: ans := READ_LINE('Can''t access SYSTEM dictionary; Please inform the '+ 'SYSTEM MANAGER; Press a key ',1); return_code := 0; RETURN; ! [7]: ans := READ_LINE('Can''t access YOUR dictionary; Please inform the '+ 'SYSTEM MANAGER; Press a key ',1); return_code := 0; RETURN; ! ENDCASE; ! ! Move to the character next to the current string of characters. ! POSITION(END_OF(w_range)); MOVE_HORIZONTAL(1); ! ENDPROCEDURE; ! ! Author: Dilip Jain ! Schwitzer Div., Household Mfg., Inc. ! P.O. Box 80-B ! Indianapolis, IN 46206 ! ! Procedure to check for and if wrong, correct the spelling of all the ! alphabetic strings of characters (words) in the current buffer. ! PROCEDURE spell_check ! LOCAL mark_1,return_code; ! return_code := 1; ! SET(TIMER,ON,'Checking ...'); ! mark_1 := MARK(NONE); POSITION(BEGINNING_OF(CURRENT_BUFFER)); LOOP EXITIF MARK(NONE) = END_OF(CURRENT_BUFFER); EXITIF return_code = 0; dictionary(return_code); ENDLOOP; POSITION(mark_1); MESSAGE('Finished Checking Spellings ...'); ! SET(TIMER,OFF); ! ENDPROCEDURE;