!++ ! FILENAME: TEXT_FORMAT.TPU ! FUNCTION: This file contains procedures for simple text formatting. ! AUTHOR: Steven K. Shapiro, (C) Copyright SKS Enterprises, Austin TX. ! All Rights Reserved. ! ! The format, structure and contents of this file are the sole ! property of Steven K. Shapiro and are copyrighted to SKS ! Enterprises, Austin Texas. ! ! The information may be freely distributed, used and modified ! provided that the information in this header block is not ! changed, altered, disturbed or modified in any way. ! ! DATE: 25-AUG-1987 Original. ! HISTORY: current. ! CONTENTS: ! eve_toggle_justify ! eve_justify ! eve_compress_par ! eve_fix_crlfs ! eve_insreq ! !23456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H !-- !*----------------------------------------------------------------------------*! procedure text_format_module_ident local file_date, module_vers; file_date := "-<( 30-NOV-1988 14:44:37.09 )>-"; module_vers := substr(file_date,5,2) + substr(file_date,8,3) + substr(file_date,14,2) + substr(file_date,17,5) ; return module_vers; endprocedure; !*----------------------------------------------------------------------------*! ! Toggle between different fill types, ragged or justified. ! procedure eve_toggle_justify ! set(informational,off); if eve_global_justify = 1 then evedt_key ("eve_fill_paragraph", key_name("J",shift_key),"fill"," "); eve_global_justify := 0; message("Text will be filled within margins WITH ragged edges."); else evedt_key ("eve_justify", key_name("J",shift_key),"justify"," "); eve_global_justify := 1; message("Text will be justified within margins with NO ragged edges."); endif; set(informational,on); ! endprocedure; !*----------------------------------------------------------------------------*! ! ! Fill a paragraph and go back and eliminate the ragged edges. ! procedure eve_justify local this_position, ! Marker for current cursor position start_paragraph, ! Marker for start of current paragraph stop_paragraph, ! Marker for end of current paragraph cur_right_margin, cur_left_margin, delta_margin, cur_line, next_line, len_line, par_stat, io_mode, ! Mode of Insert / Overstrike fill_range; ! Range for current paragraph ! Compress the paragraph first. eve_compress_par; ! Can't fill an empty buffer - avoid additional checks later on if beginning_of (current_buffer) = end_of (current_buffer) then message ("Nothing to fill"); return; endif; this_position := mark (none); ! Find beginning and end of paragraph ! If on a blank line do preceding paragraph move_horizontal (- current_offset); loop exitif mark (none) = beginning_of (current_buffer); move_vertical (-1); if eve$paragraph_break then move_vertical (1); exitif 1; endif; endloop; start_paragraph := mark (none); position (this_position); move_horizontal (- current_offset); loop exitif mark (none) = end_of (current_buffer); exitif eve$paragraph_break; move_vertical (1); endloop; if start_paragraph = mark (none) then message ("Nothing to fill"); position (this_position); else move_horizontal (-1); stop_paragraph := mark (none); ! Now fill the paragraph fill_range := create_range (start_paragraph, stop_paragraph, none); fill (fill_range, eve$x_fill_separators); position (stop_paragraph); eve$show_first_line; endif; ! ! justify within margins, no ragged lines ! position (start_paragraph); io_mode := get_info (current_buffer, "mode"); set (insert, current_buffer); cur_right_margin := get_info (current_buffer, "right_margin"); cur_left_margin := get_info (current_buffer, "left_margin"); delta_margin := cur_right_margin - cur_left_margin + 1; ! do each line of the paragraph set(informational,off); loop exitif eve$paragraph_break; cur_line := current_line; edit(cur_line,COMPRESS); edit(cur_line,TRIM); len_line := length(cur_line); ! add spaces between words loop exitif len_line >= delta_margin; move_vertical (1); par_stat := eve$paragraph_break; move_vertical (-1); exitif par_stat; eve_move_by_word; exitif eve$paragraph_break; copy_text (' '); len_line := length(current_line); endloop; move_horizontal (- current_offset); move_vertical (1); endloop; set (io_mode, current_buffer); set(informational,on); endprocedure; !*----------------------------------------------------------------------------*! ! ! Compress and trim all spaces from a paragraph. procedure eve_compress_par local start_paragraph, ! Marker for start of current paragraph io_mode, this_mark, cur_line; ! Can't fill an empty buffer - avoid additional checks later on if beginning_of (current_buffer) = end_of (current_buffer) then message ("Nothing to fill"); return; endif; ! Find beginning and end of paragraph ! If on a blank line do preceding paragraph io_mode := get_info (current_buffer, "mode"); set (insert, current_buffer); move_horizontal (- current_offset); loop exitif mark (none) = beginning_of (current_buffer); move_vertical (-1); if eve$paragraph_break then this_mark := mark(free_cursor); ! Mark where we found the break. move_vertical (1); exitif 1; endif; endloop; start_paragraph := mark (none); move_horizontal (- current_offset); ! compress paragraph within margins loop exitif eve$paragraph_break; cur_line := erase_line; edit(cur_line,COMPRESS,OFF); edit(cur_line,TRIM,OFF); copy_text ( cur_line ); split_line; move_horizontal (- current_offset); endloop; set (io_mode, current_buffer); set(informational,on); position (this_mark); ! Move back to paragraph break move_vertical(1); ! Next line which is start of paragraph endprocedure; !*----------------------------------------------------------------------------*! procedure eve_fix_crlfs ! This procedure will turn CRLFs into line breaks and remove leading s and ! trailing s. This is particularly useful when editing DSR files. LOCAL the_range; on_error if (ERROR <> tpu$_STRNOTFOUND) then message("Error (" + str(ERROR) + ") at line " + str(ERROR_LINE)); return; endif; endon_error; ! message("Trimmimg CRLF's from buffer..."); ! First remove the CRLFs. If they are not at the EOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(13)+ascii(10), FORWARD); exitif (the_range = 0); erase(the_range); position(beginning_of(the_range)); if (current_character <> "") then split_line; endif; endloop; ! ! Next remove naked LFs. If they are not at the EOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(10), FORWARD); exitif (the_range = 0); erase(the_range); position(beginning_of(the_range)); if (current_character <> "") then split_line; endif; endloop; ! ! Finally, remove naked CRs. If they are not at the BOL, add a line break. ! position(beginning_of(current_buffer)); loop the_range := search(ascii(13), FORWARD); exitif (the_range = 0); position(end_of(the_range)); if (current_offset <> 0) then split_line; endif; erase(the_range); endloop; message("CRLF's trimmed from buffer..."); endprocedure !*----------------------------------------------------------------------------*! ! procedure eve_insreq ! ! Insert the file specified by a DSR .REQUIRE ! local found_range, include_file_name, ! Local copy of include_file_parameter started_at_bof, ! True if current position at start of file include_position, ! Marker for where cursor should end up temp_file_name, ! First file name string - from file_parse file_search_result, ! Latest string returned by file_search start_filename, end_filename, file_range, start_of_buffer; on_error if error = tpu$_strnotfound then message ("No more .REQUIRE strings found."); return; endif; if error = tpu$_parsefail then message (fao ("Don't understand file name: !AS", include_file_name)); return; endif; endon_error; message("BEGIN INSREQ"); ! loop for all .REQUIRE strings loop found_range := search(".req",forward); exitif found_range = 0; ! get filename from string position(found_range); eve_move_by_word; start_filename := mark (none); eve_end_of_line; stop_filename := mark (none); ! comment out the .REQUIRE statement in the text. position(found_range); copy_text(".! "); file_range := create_range (start_filename, stop_filename, none); include_file_name := substr(file_range,1,length(file_range)); ! eliminate embedded tabs and spaces from filename edit(include_file_name,collapse,off); ! extract filename from within the quotes include_file_name := substr(include_file_name,2,length(include_file_name)-2); ! message ("last filename =>"+include_file_name+"<"); ! move down a line so we don't keep getting the same .req on each loop ! position(found_range); ! eve_end_of_line; move_vertical(1); ! insert the file named in the .REQUIRE statement if eve$check_bad_window then message ("Cursor has been moved to a text window; try command again"); return; endif; if mark (none) = beginning_of (current_buffer) then started_at_bof := 1; else started_at_bof := 0; endif; if started_at_bof then include_position := mark (none); else move_horizontal (-1); include_position := mark (none); move_horizontal (1); endif; ! Initialize to null string and protect against earlier file_search ! with same file name. temp_file_name := file_search (eve$kt_null); temp_file_name := file_parse (include_file_name); erase (eve$choice_buffer); loop ! message("inside loop"); file_search_result := file_search (include_file_name); exitif file_search_result = eve$kt_null; eve$add_choice (file_search_result); temp_file_name := file_search_result; endloop; case get_info (eve$choice_buffer, eve$kt_record_count) from 0 to 1 [0] : message (fao ("Could not include file: !AS", include_file_name)); [1] : read_file (temp_file_name); if started_at_bof then position (beginning_of (current_buffer)); else ! position (include_position); ! move_horizontal (1); position(found_range); eve_end_of_line; ! move_vertical (1); endif; [outrange] : eve$display_choices (fao ("Ambiguous file name: !AS", include_file_name)); endcase; exitif end_of (current_buffer); endloop; endprocedure;