!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!  TPU procedures to insert fill-string supplied by the user at the
!  beginning or at the end of every line for the rest of the current
!  buffer.
!  Useful (together with FILELIST) in creating COM files by cut-and-paste.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


PROCEDURE	pre_fill

LOCAL	pre_fill_string ,
        now_position    ,
        end_position    ,
        work_range      ;

if ( eve$x_select_position = 0 )  then
        end_position  :=  end_of ( current_buffer ) ;
else
        now_position  :=  mark ( NONE ) ;
        if now_position < eve$x_select_position then
            end_position  :=  eve$x_select_position ;
        else
            position ( eve$x_select_position ) ;
            end_position  :=  now_position ;
        endif ;
endif ;


if  (eve$prompt_string ( ''  ,
		pre_fill_string  ,
		"Enter string to be inserted:  " ,
	     	"no string entered; no insertion performed" ) )
	then
	loop
		position ( search ( line_begin , reverse ) ) ;
		exitif ( mark ( NONE )  >=  end_position ) ;
		copy_text ( pre_fill_string ) ;
		move_vertical ( 1 ) ;

	endloop ;
endif ;

return ;

ENDPROCEDURE





PROCEDURE	cjc_post_fill

LOCAL	post_fill_string ,
        now_position ,
        end_position ,
        work_range ;

if ( eve$x_select_position = 0 )  then
        end_position  :=  end_of ( current_buffer ) ;
else
        now_position  :=  mark ( NONE ) ;
        if now_position < eve$x_select_position then
            end_position  :=  eve$x_select_position ;
        else
            position ( eve$x_select_position ) ;
            end_position  :=  now_position ;
        endif ;
endif ;

if  (eve$prompt_string ( ''  ,
		post_fill_string  ,
		"Enter string to be inserted:  " ,
	     	"no string entered; no insertion performed" ) )
	then
	loop
		position ( search ( LINE_END , FORWARD ) ) ;
		exitif ( mark ( NONE )  >=  end_position ) ;
		copy_text ( post_fill_string ) ;
		move_vertical ( 1 ) ;
		position ( search ( LINE_BEGIN , REVERSE ) ) ;

	endloop ;
endif ;

return ;

ENDPROCEDURE




