! EVE$EXTRAS.TPU 1-MAR-1993 08:04 Page 1 module eve$extras ident "V03-013" ! ! COPYRIGHT © 1987,1993 BY ! DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS ! ALL RIGHTS RESERVED ! ! THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED ! ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE ! INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER ! COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY ! OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY ! TRANSFERRED. ! ! THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE ! AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT ! CORPORATION. ! ! DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS ! SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL. ! !++ ! FACILITY: ! DECTPU - Text Processing Utility ! EVE - Extensible Versatile Editor ! ! ABSTRACT: ! This is the source program for the EVE interface extra functions. ! ! ENVIRONMENT: ! OpenVMS VAX, OpenVMS AXP, RISC/ULTRIX ! !Author: Bill Robinson (among others) ! ! CREATION DATE: 29-Jan-1987 ! ! MODIFIED BY: ! !-- !++ ! Table of Contents ! ! EVE$EXTRAS.TPU ! 1-MAR-1993 08:04 ! ! Procedure name Page Description ! -------------- ---- ------------ ! ! eve_spell 2 Run SPELLing corrector over text ! eve$$spell 3 Actually invoke spell checker !-- ! EVE$EXTRAS.TPU Page 2 procedure eve_spell ! Run SPELLing corrector over text (;spell_args) ! VMS qualifiers (Ultrix options) for spell command local ok_to_ask, ok_to_write, text_ptr; on_error [OTHERWISE]: endon_error; if current_window = eve$command_window then eve$message (EVE$_CANTCMDWINDOW); eve$learn_abort; return (FALSE); endif; if not eve$declare_intention (eve$k_action_spell) then return (FALSE); endif; text_ptr := eve$selection (FALSE,,, eve$x_select_remove_flag,, TRUE); if text_ptr = 0 then text_ptr := current_buffer; endif; ! eve$x_spell_flag description ! -------------------- ----------- ! unspecified (default) ask if want to write modified buffer ! true don't ask, write out modified buffer ! false don't ask, don't write modified buffer if get_info (current_buffer, "modified") and (not eve$x_ultrix_active) then if eve$x_spell_flag = tpu$k_unspecified then ok_to_ask := TRUE; ok_to_write := TRUE; else if eve$x_spell_flag then ok_to_write := TRUE; endif; endif; if ok_to_ask then if eve$insist_y_n (fao (message_text (EVE$_SPELLPROMPT, tpu$k_message_text), get_info (current_buffer, "name"))) then ok_to_write := TRUE; else ok_to_write := FALSE; endif; endif; if ok_to_write then if not eve$write_file (current_buffer, "", 0) then return (FALSE); endif; endif; endif; eve$message (EVE$_INVOKINGSPELL); if eve$$spell (text_ptr, spell_args) then if eve$x_ultrix_active then eve$message (EVE$_SPELLDONEULT); else eve$message (EVE$_SPELLDONE, eve$k_success, get_info (eve$$x_spell_save_buffer, "name")); endif; return (TRUE); else return (FALSE); ! already did learn_abort endif; endprocedure; ! eve_spell ! EVE$EXTRAS.TPU Page 3 procedure eve$$spell ! Actually invoke spell checker (text_ptr, ! range or buffer to be spelled spell_args) ! VMS qualifiers (Ultrix options) for spell command local local_text, text_buffer, is_empty, start_mark, spell_options, end_mark, the_file, the_file1, the_position, is_range, is_box, is_offset, original_success, status, saved_box_flag, this_buffer, this_window, spell_window, saved_window, saved_mark; on_error [TPU$_CONTROLC]: eve$$restore_position (saved_window, saved_mark); eve$x_box_select_flag := saved_box_flag; eve$$release_scratch_buffer; set (SUCCESS, original_success); eve$learn_abort; abort; [TPU$_CREATEFAIL]: set (SCREEN_UPDATE, ON); %if eve$x_option_decwindows %then eve$popup_message (message_text (EVE$_CANTCREASPELL, 1)); %else eve$message (EVE$_CANTCREASPELL); %endif set (SUCCESS, original_success); eve$learn_abort; return (FALSE); [OTHERWISE]: eve$$restore_position (saved_window, saved_mark); eve$x_box_select_flag := saved_box_flag; eve$$release_scratch_buffer; set (SUCCESS, original_success); endon_error; saved_window := current_window; saved_mark := mark (FREE_CURSOR); saved_box_flag := eve$x_box_select_flag; original_success := SET (SUCCESS, OFF); local_text := text_ptr; if (get_info (spell_args, "type") = STRING) then spell_options := spell_args; else spell_options := ""; endif; if not eve$$reserve_scratch_buffer then eve$message (EVE$_ILLSCRATCHRES); eve$learn_abort; return (FALSE); endif; status := FALSE; if not eve$x_ultrix_active then ! first see if DECspell is installed (assume SYS$SYSTEM:LNGSPLCOR.EXE) eve$reset_file_search; ! Negate earlier file_search with same name. if file_search ("LNGSPLCOR", "SYS$SYSTEM:.EXE") = "" then eve$message (EVE$_NODECSPELL); eve$learn_abort; eve$$release_scratch_buffer; set (SUCCESS, original_success); return (status); endif; endif; ! See if it's a buffer or range or box selection if get_info (local_text, "type") = BUFFER then ! entire buffer text_buffer := local_text; else if get_info (local_text, "type") = ARRAY then ! box selection is_box := TRUE; text_buffer := get_info (local_text {0}, "buffer"); else ! standard selection if get_info (local_text, "type") = RANGE then ! box selection is_range := TRUE; text_buffer := get_info (local_text, "buffer"); else ! bad selection? eve$message (EVE$_EVEINTERROR); eve$learn_abort; return (status); endif; endif; endif; if not eve$x_ultrix_active then ! Don't spell an unmodifable buffer on VMS where correction is done. if not get_info (text_buffer, "modifiable") then eve$message (EVE$_BUFUNMODIFIABLE, 0, get_info (current_buffer, "name")); eve$learn_abort; return (status); endif; endif; ! Create spell buffer and process if get_info (eve$$spell_buffer, "type") <> BUFFER then if eve$$x_buf_str_spell = tpu$k_unspecified then eve$$x_buf_str_spell := "SPELL"; endif; eve$$spell_buffer := eve$init_buffer (eve$$x_buf_str_spell, "", FALSE); ! not permanent endif; if (get_info (eve$$x_spell_process, "type") = UNSPECIFIED) or (eve$$x_spell_process = 0) then if eve$x_ultrix_active then eve$$x_spell_process := create_process (eve$$spell_buffer); else eve$$x_spell_process := create_process (eve$$spell_buffer, "set noon"); ! disregard user symbol send ("delete:==delete", eve$$x_spell_process); send ("create:==create", eve$$x_spell_process); endif; endif; the_file := str (get_info (eve$$x_spell_process, "pid")) + ".tmp"; if eve$x_ultrix_active then ! Ultrix: write to the_file, redirect spell output to the_file1. the_file1 := the_file + ".1"; else the_file := "sys$scratch:" + the_file; endif; ! insure we do complete lines (otherwise single words selected in the middle of ! a line get read_file'd onto previous line, too nasty to prevent) if is_range then start_mark := beginning_of (local_text); end_mark := end_of (local_text); if get_info (start_mark, "offset") > 0 then position (start_mark); position (LINE_BEGIN); start_mark := mark (NONE); endif; if get_info (end_mark, "offset") > 0 then position (end_mark); position (LINE_END); end_mark := mark (NONE); endif; local_text := create_range (start_mark, end_mark, NONE); endif; erase (eve$$x_scratch_buffer); erase (eve$$x_spell_save_buffer); ! Copy the text to the $SPELL$ buffer. (saves text on VMS) if is_box then ! A box selection. eve$x_box_select_flag := TRUE; eve$$store_remove (eve$$x_spell_save_buffer, ! buffer to copy to FALSE, ! don't delete it FALSE, ! no messages local_text); ! text to copy eve$x_box_select_flag := saved_box_flag; the_position := beginning_of (local_text {1}); else ! An entire buffer or a standard selection. the_position := beginning_of (local_text); position (eve$$x_spell_save_buffer); copy_text (local_text); endif; ! write out temp file, then check it, then read in results position (eve$$x_scratch_buffer); write_file (eve$$x_spell_save_buffer, the_file); if eve$x_ultrix_active then ! % spell -d hlist infile > outfile send ("/usr/bin/spell " + spell_options + " " + the_file + " > " + the_file1, eve$$x_spell_process); read_file (the_file1); else if eve$x_decwindows_active then ! When running decwindows, send ("CREATE/TERMINAL=DECTERM/WAIT" + "/WINDOW_ATTRIBUTES=(ROWS=24,columns=80,Initial_state=window," + 'title="DECSpell",Icon_name="DECSpell") ' + " SPELL " + spell_options + " " + the_file + "/output=" + the_file, eve$$x_spell_process); else spawn ("spell " + spell_options + " " + the_file + "/output=" + the_file); endif; read_file (the_file); endif; position (the_position); if get_info (eve$$x_scratch_buffer, "record_count") = 0 then ! something went wrong if eve$x_ultrix_active then eve$message (EVE$_NOSPELLTEXTULT); erase (eve$$x_spell_save_buffer); ! show no text if it's mapped else eve$message (EVE$_NOSPELLTEXT); endif; else if eve$x_ultrix_active then ! Split windows like SHELL command, show mispellings in other window. this_buffer := current_buffer; if this_buffer = eve$$x_spell_save_buffer then spell_window := current_window; else if eve$x_number_of_windows = 1 then eve_split_window (2); this_window := eve$top_window; spell_window := current_window; map (spell_window, eve$$x_spell_save_buffer); else this_window := current_window; spell_window := eve$get_mapped_window (eve$$x_spell_save_buffer); if spell_window = 0 then ! insure the spell_window is opposite the current_window spell_window := eve$bottom_window; if spell_window = this_window then spell_window := eve$top_window; endif; endif; map (spell_window, eve$$x_spell_save_buffer); endif; endif; eve$set_status_line (spell_window); erase (eve$$x_spell_save_buffer); position (eve$$x_spell_save_buffer); copy_text (eve$$x_scratch_buffer); position (BUFFER_BEGIN); if this_buffer <> eve$$x_spell_save_buffer then position (this_window); endif; status := TRUE; else if is_box then ! Cut the box (using eve$x_box_pad_flag + buffer mode) erase (eve$$x_spell_save_buffer); eve$$box_cut (local_text, eve$$x_spell_save_buffer, TRUE, ! delete the box FALSE); ! no messages ! Paste the corrected text (using eve$x_box_pad_flag + buffer mode) eve$$box_paste (eve$$x_scratch_buffer); status := TRUE; else erase (local_text); if get_info (current_buffer, "record_count") = 0 then ! either spell'd w/no range, or range covered entire buffer is_empty := TRUE; split_line; else if (the_position <> beginning_of (current_buffer)) then ! put marker @eol before line where corrected text is put move_horizontal (-1); the_position := mark (NONE); move_horizontal (1); is_offset := 1; endif; endif; eve$insert_text (eve$$x_scratch_buffer); position (the_position); if is_offset ! position to start of corrected text then move_horizontal (1); else position (beginning_of (current_buffer)); if is_empty then ! erase temporary modification erase_line; endif; endif; status := TRUE; endif; endif; endif; eve$$release_scratch_buffer; if eve$x_ultrix_active then send ("/bin/rm " + the_file + " " + the_file1, eve$$x_spell_process); else send ("$ delete " + the_file + ";*", eve$$x_spell_process); endif; set (SUCCESS, original_success); if not status then eve$learn_abort; endif; return (status); endprocedure ! eve$$spell ! EVE$EXTRAS.TPU Page 4 ! Module initialization code ! Global process varibles eve$$x_spell_process := 0; ! subprocess used by SPELL command endmodule; ! EVE$EXTRAS.TPU Page 5 variable eve$x_spell_flag; eve$$require ("eve$core"); ! Build dependencies