!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! TPU procedures to do global search-and-replace either on the entire ! current buffer , or on multiple files whose names are entered sequentially ! from the keyboard until the user gives a RETURN response to the filename ! prompt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PROCEDURE cjc_global_search_replace LOCAL target_str , replace_str , target_range , replace_count , work_range ; ON_ERROR if ( ERROR = TPU$_STRNOTFOUND ) then message ( fao ( 'Complete !ul replacement!%s', replace_count ) ) ; endif ; return; ENDON_ERROR; replace_count := 0; eve$prompt_string ( "" , target_str , "String to be replaced: " , "No string entered." ) ; if ( target_str = eve$kt_null ) then return endif ; eve$prompt_string ( "" , replace_str , "String to be replaced: " , "" ) ; if ( eve$x_select_position = 0 ) then end_position := end_of ( current_buffer ) ; else work_range := select_range ; position ( beginning_of ( work_range ) ) ; end_position := end_of ( work_range ) ; endif ; loop target_range := search ( target_str, forward ) ; exitif ( beginning_of ( target_range ) >= end_position ) ; erase ( target_range ) ; position ( end_of ( target_range ) ) ; copy_text ( replace_str ) ; replace_count := replace_count + 1; endloop; message ( fao ( 'Complete !ul replacement!%s', replace_count ) ) ; ENDPROCEDURE ; PROCEDURE cjc_multi_search_replace LOCAL input_file , target_range , target_str , replace_str , this_position , this_buffer , work_buffer , work_buf_name ; ON_ERROR ! must deal with DEC TPU's mistaken handling as an error of ! SEARCH: "string not found" if ( ERROR = TPU$_DUPBUFNAME ) then if ( eve$prompt_string ( "" , work_buf_name , "buffer " + work_buf_name + " already exists. " + "Enter new name: " , "No string entered -- returning" ) ) then work_buffer := create_buffer ( work_buf_name , input_file ) ; else return ( 0 ) ; endif ; else if ( ERROR <> TPU$_STRNOTFOUND ) then message ( 'FATAL ERROR in substitution-process' ) ; map ( this_window , this_buffer ) ; position ( this_position ) ; return ( 1 ) ; endif ; endif ; ENDON_ERROR ; if ( 0 = eve$prompt_string ( "" , target_str , "String to be replaced (RET to quit): " , "No string entered." ) ) then return ; endif ; eve$prompt_string ( "" , replace_str , "String to replace it with: " , "" ) ; this_position := mark ( NONE ) ; this_buffer := current_buffer ; this_window := eve$x_this_window ; work_buf_name := 'M_S_R_work_buffer' ; loop exitif ( 0 = eve$prompt_string ( "" , input_file , "Input file (RET to quit): " , "Edit session completed." ) ) ; work_buffer := create_buffer ( work_buf_name , input_file ) ; position ( beginning_of ( work_buffer ) ) ; set ( OUTPUT_FILE , work_buffer , input_file ) ; replace_count := 0 ; loop target_range := search ( target_str, forward ) ; exitif ( target_range = 0 ) ; erase ( target_range ) ; position ( end_of ( target_range ) ) ; copy_text ( replace_str ) ; replace_count := replace_count + 1; endloop ; message ( fao ( 'Complete !ul replacement!%s', replace_count ) ) ; write_file ( work_buffer ) ; delete ( work_buffer ) ; endloop ; map ( this_window , this_buffer ) ; position ( this_position ) ; ENDPROCEDURE ;