PROCEDURE PCE_LINED ! ! This is a very basic line mode editor for TPU ! on_error [TPU$_STRNOTFOUND]: message ("String not found "); position (ml); [TPU$_INVNUMSTR]: message ("Unrecognized command - enter A,B,D,E,F,I,L,N,P,Q,T,or U "); [OTHERWISE]: endon_error; input_file := get_info (command_line, "file_name"); main_buffer := create_buffer ("main", input_file); position (beginning_of (main_buffer)); loop ! continuously loop until exit/abort if mark (none) <> end_of (current_buffer) then message (current_line); else message ("[End of file]"); endif; cmd := read_line ("*"); if cmd = "" then cmd_char := "N"; ! default to next line cmd else cmd_char := substr (cmd, 1, 1); change_case (cmd_char, upper); endif; case cmd_char from "A" to "Z" ["T"]: ! Top of buffer position (beginning_of (current_buffer)); ["B"]: ! Bottom of buffer position (end_of (current_buffer)); move_vertical (-1); ["N"]: ! Next line if mark (none) <> end_of (current_buffer) then move_horizontal (-current_offset); move_vertical (1); endif; ["P"]: ! Previous line move_horizontal (-current_offset); move_vertical (-1); ["I"]: ! Insert line if mark (none) <> end_of (current_buffer) then split_line; endif; copy_text (substr (cmd, 2, length (cmd))); ["D"]: ! Delete line erased := erase_line; ["U"]: ! UNDelete line copy_text (erased); split_line; ["F"]: ! Find a string this_string := substr (cmd, 2, length (cmd)); edit (this_string, trim); ml := mark (none); this_range := search (this_string, forward, no_exact); if this_range <> 0 then position (this_range); move_horizontal (-current_offset); endif; ["L"]: ! List to end of buffer this_string := substr (cmd, 2, length (cmd)); edit (this_string, trim); if length (this_string) > 0 then this_line_number := int (this_string); ml := mark (none); counter := 0; loop message (current_line); move_vertical (1); counter := counter + 1; exitif mark (none) = end_of (current_buffer); exitif counter > this_line_number; endloop; position (ml); else ml := mark (none); loop message (current_line); move_vertical (1); exitif mark (none) = end_of (current_buffer); endloop; position (ml); endif; ["E"]: ! Exit exit; ["A"]: ! Abort quit; ["Q"]: ! Quit, same as abort quit; [INRANGE, OUTRANGE]: ! anything else, assume line # this_string := cmd; edit (this_string, trim); this_line_number := int (this_string); line (this_line_number); endcase; endloop; ENDPROCEDURE; PROCEDURE LINE (LINE_PARAMETER) ! Go to start of a certain line in the current buffer, or optionally to ! the line in a certain procedure local the_line, last_line, start_mark, end_mark; on_error [TPU$_CONTROLC]: [TPU$_ENDOFBUF]: [OTHERWISE]: return; endon_error; the_line := line_parameter; start_mark := beginning_of (current_buffer); end_mark := end_of (current_buffer); if the_line <= 0 then the_line := 1; endif; last_line := get_info (current_buffer, "record_count"); ! do NOT include eob_text if last_line = 0 then message ("ERROR -- Buffer empty"); return; endif; position (get_info (start_mark, "record_number") + the_line - 1); if mark (none) > end_mark then position (end_mark); endif; return; ENDPROCEDURE; pce_lined;