! ABEL_SORT.TPU ! ! Table of Contents as of 27-Mar-1988 ! ! Procedure name Page Description ! -------------- ---- ----------- ! ! eve$sort_buffer 1 Eveplus' old sort call ! abl$extended_sort_buffer 2 Sorts a buffer with system sort ! eve_sort 3 Sort things ! Page 1 procedure eve$sort_buffer(sort_buffer) ! Eveplus' old sort call ! EvePlus' old routine replaced by call to system sort; this procedure ! keeps other routines from having to be changed ! ! Parameters: ! sort_buffer buffer buffer to sort ! ! Globals: ! abl$sort_ascending integer can be used to indicate ascending order ! abl$sort_descending integer can be used to indicate descending order ! ! Source: ! Eveplus abl$extended_sort_buffer(sort_buffer,0,0,abl$sort_ascending); ! above calling parameters: buffer, position, length, order endprocedure ! Page 2 procedure abl$extended_sort_buffer ! Sorts a buffer with system sort (sort_buffer,sort_position,sort_length,sort_order) ! Interface to the calluser's VMS callable sort. ! ! Parameters: ! sort_buffer buffer buffer to sort ! sort_position integer start of key to sort with ! sort_length integer length of key to sort with ! sort_order integer 0 for ascending, 1 for descending ! ! Globals: ! abl$sort_ascending integer can be used to indicate ascending order ! abl$sort_descending integer can be used to indicate descending order ! abl$sort_max_line_length integer longest line that we can pass back and ! forth to calluser ! ! Source: ! Eva2 local dummy, ! holds result of call_user call line, ! current line passing to sort starting_position; ! user's starting position on_error dummy := call_user(abl$cu_end_sort,''); erase_line; position(beginning_of(sort_buffer)); erase_line; eve$trim_buffer(current_buffer); position(starting_position); return 1; endon_error ! Set up for sort starting_position:=mark(none); position(beginning_of(sort_buffer)); dummy := call_user(abl$cu_init_sort,""); !inits all key info to zero if sort_order <> 0 then dummy := call_user(abl$cu_sort_order,str(sort_order)) endif; if sort_position <> 0 then dummy := call_user(abl$cu_sort_position,str(sort_position)) endif; if sort_length <> 0 then dummy := call_user(abl$cu_sort_length,str(sort_length)) endif; dummy := call_user(abl$cu_begin_sort,""); ! Pass records to sort loop exitif mark(none) = end_of(sort_buffer); line := current_line; if length(line) > abl$sort_max_line_length then message(fao("Could not sort; line !SL is !SL characters long; " + "exceeds !SL character limit", eve$what_line, length(line), abl$sort_max_line_length)); position(starting_position); dummy := call_user(abl$cu_end_sort,''); return 0; endif; dummy := call_user(abl$cu_release_rec,current_line); move_vertical(1); endloop; ! Sort dummy := call_user(abl$cu_sort_merge,""); erase(sort_buffer); ! Retrieve sorted records loop split_line; line := call_user(abl$cu_return_rec,""); copy_text(line); endloop; endprocedure ! Page 3 procedure eve_sort ! Sort things ($sort_type,$buffer_to_sort) ! Sort the specified thing ! ! Parameters: ! $sort_type string "buffer", "select_range", "block" ! $buffer_to_sort string name of buffer to sort if buffer sort ! ! Qualifiers: ! /position integer character number for start of key ! /length integer length of key ! /order string "ascending" or "descending" ! /reset boolean reset select range when done ! ! Source: ! Eva2, Eveplus local original_buffer, ! user's buffer when we were invoked sort_type, ! "buffer", "select_range", "block" sort_range, ! if select active, holds range sort_order_string, ! ascending or descending string sort_order, ! ascending or descending value starting_position, ! user's starting position sort_range_start, ! marker for beginning of sort range block_line_length, ! length of a line in the block sort_buffer; ! buffer pointer ! ! Initializations ! original_buffer := current_buffer; starting_position := mark(none); buffer_to_sort := $buffer_to_sort; edit(buffer_to_sort,trim,upper); ! ! Determine sort type ! if not abl$prompt_word("/buffer/select_range/block",$sort_type,sort_type, "Sort what (buffer, select_range, block) [] ? ","Aborted...") then return 0 endif; ! ! Process /order qualifier ! if not abl$prompt_word("/ascending/descending",abl$q_order,sort_order_string, "Sort order (ascending, descending) [ascending] ? ","") then sort_order_string := "ascending" endif; ! if sort_order_string = "ascending" then sort_order := abl$sort_ascending else sort_order := abl$sort_descending endif; ! ! Pre-sort processing for each sort type ! if sort_type = "buffer" then if buffer_to_sort = "" then sort_buffer := current_buffer; else sort_buffer := eveplus_find_buffer (buffer_to_sort); if sort_buffer = 0 then message("Buffer "+buffer_to_sort+ " not found"); return 0; endif; endif; endif; ! if sort_type = "select_range" then if eve$x_select_position = 0 then message("Use Select before using Sort Select_range"); return 0; endif; if get_info (eve$x_select_position, "buffer") <> current_buffer then message("Select range active but not in this buffer; aborting"); return 0; endif; ! ! Get all of each line with in the selected range ! sort_range:=select_range; position(beginning_of(sort_range)); move_horizontal(-current_offset); sort_range_start := mark(none); position(end_of(sort_range)); position(search(line_end,forward)); sort_range := create_range(sort_range_start,mark(none),none); ! ! Move selected text to paste buffer ! erase(paste_buffer); position(paste_buffer); move_text(sort_range); sort_buffer := paste_buffer; endif; ! if sort_type = "block" then if abl$x_block_select_position = 0 then message("Use Block Select before using Sort Block"); return 0; endif; if get_info (abl$x_block_select_position, "buffer") <> current_buffer then message("Block Select active but not in this buffer; aborting"); return 0; endif; ! ! Get the block in the paste buffer ! abl$do("eve_block_remove","abl$q_log := 0"); sort_buffer := paste_buffer; position(beginning_of(paste_buffer)); block_line_length := length(current_line); position(original_buffer); endif; ! ! Perform sort and trim buffer of added trailing blanks ! if not abl$extended_sort_buffer (sort_buffer,abl$q_position,abl$q_length,sort_order) then message("Error occured during sort"); return 0; endif; eve$trim_buffer(sort_buffer); ! ! Post-sort processing for each sort type ! if sort_type = "select_range" then position(starting_position); copy_text(paste_buffer); if abl$q_reset then eve$x_select_position := 0 endif; endif; ! if sort_type = "block" then position(beginning_of(paste_buffer)); loop exitif mark(none) = end_of(paste_buffer); position(search(line_end,forward)); copy_text(substr(eve$x_spaces,1, block_line_length - length(current_line))); move_horizontal(-current_offset); move_vertical(1); endloop; position(original_buffer); abl$do("eve_block_insert_here","abl$q_log := 0"); if abl$q_reset then abl$x_block_select_position := 0 endif; endif; message("Sorted"); endprocedure