home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-05-03 | 621.2 KB | 14,129 lines |
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --hconv
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ HCONV
-
- --
- --
- -- Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with Text_IO ;
-
- with Direct_IO ;
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
- use basic_io_system ;
-
- with crt_customization ;
- use crt_customization ;
-
- with crt_windows ;
- use crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- package help_convert is
-
- subtype data_file_name is ascii_text_file_name ;
-
- procedure DEFINE_HELP_FILE(SOURCE_FILE : in ASCII_TEXT_FILE_NAME ;
- DESTINATION_FILE: in DATA_FILE_NAME );
- -- This tool processes a help file in ASCII format to a format allowing
- -- fast access to each of the various help screens. It is for use by
- -- the systems's manager to modify user help information to his
- -- particular audience.
-
- private
-
- block_size : constant integer := 256 ; -- cannot be changed!
- subtype block_index is integer range 0 .. block_size - 1 ;
- type block_of_data is array ( block_index
- range 0 .. block_size - 1 ) of character ;
- type type_help_text_array is
- record
- block_number : integer ;
- data : block_of_data ;
- end record ;
-
- help_text_array : type_help_text_array ;
-
- end help_convert ;
-
- package body help_convert is
-
- package help_file_io is new direct_io ( type_help_text_array ) ;
- -- unvalidated telesoft ada does not allow arrays, only records...
-
- procedure DEFINE_HELP_FILE(SOURCE_FILE : in ASCII_TEXT_FILE_NAME ;
- DESTINATION_FILE: in DATA_FILE_NAME ) is
- -- This tool processes a help file in ASCII format to a format allowing
- -- fast access to each of the various help screens. It is for use by
- -- the systems's manager to modify user help information to his
- -- particular audience.
-
- maximum_help_topics : constant integer := 40 ;
- subtype help_topic_index_number is INTEGER
- range 1 .. maximum_help_topics ;
- subtype topic_name_type is string ( 1 .. 28 ) ;
- blank_topic_name : constant topic_name_type
- := " " ;
- type help_topic_description is
- record
- block_number : INTEGER range 0 .. 32000 := 0 ;
- place : block_index := 0 ;
- help_code : CHARACTER := ascii.nul ;
- topic_name : topic_name_type := blank_topic_name ;
- end record ;
- type some_entries is array ( help_topic_index_number )
- of help_topic_description ;
-
- help_description_array : some_entries ;
- first_text_block_in_file : constant integer := 6 ;
-
- next_character_position_within_block : INTEGER ;
- current_help_topic_number : INTEGER ;
- Input_String_Length : INTEGER ;
- Input_Line : pstring ;
-
- Put_Block_Error : EXCEPTION ;
-
- Help_Input_Text_File : text_IO.FILE_TYPE ;
- Help_Data_File : help_file_io.FILE_TYPE ;
- Next_Output_Block : help_file_io.POSITIVE_COUNT ;
- master_window : window_pointer ;
- requested_source_file : ascii_text_file_name ;
- requested_destination_file: data_file_name ;
-
- procedure get_input_file_name is
- ok : boolean ;
- begin
- if source_file = no_file then
- ok := false ;
- else
- ok_to_read( source_file , requested_source_file , ok ) ;
- end if ;
- if not ok then
- -- we need to read in another file name
- -- here on no input file name or file does not exist.
- if source_file /= no_file then
- error( " File """ & string_library.compress(source_file)
- & """ does not exist." ,
- not_fatal_error , operator_wait , short_beep ) ;
- end if ;
- loop
- clear_end_of_screen( master_window , 5 , 1 ) ;
- goto_line_column ( master_window , 5 , 1 ) ;
- crt_windows.put(
- " Enter Help Input File Name ( or <return> to abort ) => ") ;
- requested_source_file :=
- get_input_filename_or_return ;
- if requested_source_file = no_file then
- ok := true ;
- elsif requested_source_file( 1 ) = ascii.esc then
- -- an error, the file name did not exist
- error(" File Name """ & compress(requested_source_file
- ( 2 .. requested_source_file'length ) )
- & """ is invalid." ,
- not_fatal_error , operator_wait , short_beep ) ;
- elsif not file_exists ( requested_source_file ) then
- -- an error, the file name did not exist
- error(" File """ & compress(requested_source_file
- ( 2 .. requested_source_file'length ) )
- & """ does not exist." ,
- not_fatal_error , operator_wait , short_beep ) ;
- else
- ok := true ; -- because it does not exist...
- end if ;
- -- need to set the default environment
- exit when ok ;
- end loop ;
- end if ;
- end get_input_file_name ;
-
- function get_yes_no return boolean is
- begin -- get_yes_no
- return char_or_abort( 'N' , 'Y' , 'N' ) = 'Y' ;
- end get_yes_no ;
-
- procedure get_output_file_name is
- done : boolean ;
- begin -- get_output_file_name
- requested_destination_file := destination_file ;
- loop
- if requested_destination_file( 1 ) = ascii.esc then
- -- an error, the file name did not exist
- error(" File """ & compress(requested_destination_file
- ( 2 .. requested_destination_file'length ) )
- & """ is an invalid name." ,
- not_fatal_error , operator_wait , short_beep ) ;
- done := false ;
- elsif file_exists ( requested_destination_file ) then
- -- we must confirm that they want to save it
- crt_windows.put( ascii.cr ) ;
- crt_windows.put( ascii.cr ) ;
- crt_windows.put(" File """ & compress(requested_destination_file)
- & """ already exists. ");
- crt_windows.put( ascii.cr ) ;
- crt_windows.put( ascii.cr ) ;
- crt_windows.put(" Delete """ & compress( requested_destination_file )
- & """ and continue (Y/N) ? ");
- done := get_yes_no ; -- if they say "Y", then we will just leave.
- -- when it comes time to writing, we will automatically rename
- -- otherwise, if they say no, then re-ask the question for a
- -- file name
- else
- done := requested_destination_file /= no_file ;
- end if ;
- exit when done ;
- -- here when we are not done... must get a new file name
- clear_end_of_screen( master_window , 13 , 1 ) ;
- goto_line_column ( master_window , 13 , 1 ) ;
- crt_windows.put(
- " Enter Help Output File Name ( or <return> to abort ) => ") ;
- requested_destination_file :=
- get_output_filename_or_return (".hlp");
- if requested_destination_file = no_file then
- requested_source_file := no_file ;
- done := true ;
- end if ;
- -- need to set the default environment
- exit when done ;
- end loop ;
- end get_output_file_name ;
-
- procedure open_for_write( file_handle : in out help_file_io.file_type ;
- file_name : in out data_file_name ;
- successfull : out boolean ) is
- -- Open the file setting the handle
- begin -- open_for_write
- if help_file_io.is_open(file_handle) then
- help_file_io.close(file_handle);
- end if ;
- help_file_io.create(file_handle,help_file_io.inout_file,
- no_blanks(file_name));
- successfull := true ;
- exception
- when others => successfull := false ;
- end open_for_write ;
-
- procedure initialize is
- -- set up the files for help definition
- ok : boolean ;
- final_name : ascii_text_file_name ;
- had_old_file : boolean ;
- begin -- initialize
- master_window := create_window ( 1 , basic_io_system.total_crt_col ,
- 1 , basic_io_system.total_crt_line ,
- true , 1 ) ;
- -- Create a screen window
- -- Make the window the entire screen, with a 1 line status area
- -- at the top of the window
- set_current_window ( master_window ) ;
- clear_prompt( master_window ) ;
- clear_window( master_window ) ;
- get_input_file_name ;
- if requested_source_file /= no_file then
- get_output_file_name ;
- if requested_destination_file /= no_file then
- -- we can open the files...
- open_for_read( Help_Input_Text_File , requested_source_file , ok ) ;
- if not ok then
- -- we have a fatal error....
- error(" Program Error: No File """
- & compress(requested_source_file) & """." ,
- fatal_error , operator_wait , short_beep ) ;
- else
- -- we are ready to try to open for output...
- open_for_write( Help_Data_File , requested_destination_file , ok);
- if not ok then
- -- we have a fatal error....
- error(" Program Error: Out File """
- & compress(requested_destination_file) & """." ,
- fatal_error , operator_wait , short_beep ) ;
- else
- -- ok, both files are opened...
- for blockn in 1 .. first_text_block_in_file loop
- help_file_io.write(Help_Data_File , help_text_array ,
- help_file_io.positive_count(blockn));
- -- just puts those blocks in as place holders.
- end loop ;
-
- Next_Output_Block := help_file_io.positive_count(
- first_text_block_in_file ) ;
- -- this is the block our data should go into
- next_character_position_within_block := 0 ;
- -- this is the position our data goes into
- current_help_topic_number := 1 ;
- -- This is the next key to fill
- end if ;
- end if ;
- end if ;
- end if ;
- end initialize ;
-
- Procedure DELETE ( str : in out pstring ; start , len : in integer ) is
- str_length : integer ;
- begin
- str_length := length ( str ) ;
- if start + len <= str_length then
- for i in start+len .. str_length loop
- str.data(i-len) := str.data(i) ;
- end loop ;
- set_length( str , str_length - len ) ;
- else
- set_length( str , start - 1 ) ;
- end if ;
- end ;
-
- procedure GET_LINE is -- get the next input line in//
- in_line : string ( 1 .. 255 ) ;
- begin -- GET_LINE
- text_io.get_line ( Help_Input_Text_File ,
- in_line , Input_String_Length ) ;
- Input_Line := string_to_pstring ( In_Line ( 1 .. Input_String_Length ));
- end GET_LINE ;
-
- procedure PUT_BLOCK is
- -- We have filled a block, now we need to put it to the disk//
- begin -- PUT_BLOCK
- help_text_array.block_number := integer(next_output_block) ;
- help_file_io.write ( Help_Data_File , help_text_array ,
- Next_Output_Block ) ;
- Next_Output_Block := Next_Output_Block + 1 ;
- next_character_position_within_block := 0 ;
- exception
- when others => raise Put_Block_Error ;
- end PUT_BLOCK ;
-
- procedure Move_Data_To_Help_Area is -- move a line to the output block//
- TMP : INTEGER ;
- begin -- Move_Data_To_Help_Area
- -- we want to add the current Input_Line to help_text_array...
- -- next_character_position_within_block is where the data should go. Put a <cr><lf>
- -- after any line which is not length(0). Increment Next_Output_Block
- -- if we overflow this block.//
- if length( Input_Line ) = 0 then
- help_text_array.data(
- next_character_position_within_block ) := ascii.nul ;
- next_character_position_within_block :=
- next_character_position_within_block + 1 ;
- if next_character_position_within_block = block_size then
- PUT_BLOCK ;
- end if ;
- else
- TMP := 1 ; -- this is the next character to move
- -- over//
- while ( TMP <= length ( Input_Line ) ) loop -- move the line over//
- help_text_array.data( next_character_position_within_block )
- := Input_Line.data( TMP ) ;
- TMP := TMP + 1 ;
- next_character_position_within_block :=
- next_character_position_within_block + 1 ;
- if next_character_position_within_block = block_size then
- PUT_BLOCK ;
- end if ;
- end loop ; -- Now, We Need the <cr><lf>//
- help_text_array.data( next_character_position_within_block ) :=
- ascii.cr ;
- next_character_position_within_block :=
- next_character_position_within_block + 1 ;
- if next_character_position_within_block = block_size then
- PUT_BLOCK ;
- end if ;
- end if ;
- end Move_Data_To_Help_Area ;
-
- procedure SHOWNUM ( B1 , P1 , B2
- , P2 : in INTEGER ) is
- I1 ,
- I2 : INTEGER ;
- begin -- SHOWNUM
- I1 := ( B1 * block_size ) + P1 ;
- I2 := ( B2 * block_size ) + P2 ;
- basic_io_system.put( I2 - I1 , 5 ) ;
- end SHOWNUM ;
-
- procedure DOWORK is
- ind : integer ;
- begin -- DOWORK
- GET_LINE ; -- get rid of the environment//
- while ( length ( input_line ) < 5 )
- or else ( Input_Line.data( 1 ) = '?' )
- or else ( Input_Line.data( 1 ) = '-' )
- loop
- GET_LINE ;
- end loop ;
- crt_windows.put ( ascii.cr ) ;
- crt_windows.put ( ascii.cr ) ;
- while Input_Line.data( 1 ) /= '*' loop
- -- we work until we hit a * as the
- -- first character//
- -- fill in key information//
- help_description_array( current_help_topic_number )
- .block_number := integer(Next_Output_Block) ;
- help_description_array( current_help_topic_number )
- .PLACE := next_character_position_within_block ;
- help_description_array( current_help_topic_number )
- .help_code := Input_Line.data( 1 ) ;
- delete ( Input_Line , 1 , 3 ) ; -- line was 'A) Auto Indent....
- -- Now is 'Auto Indent...//
- if length( input_line ) > topic_name_type'length then
- crt_windows.put( " Error... Index Line Too Long..." ) ;
- crt_windows.put( Input_Line ) ;
- crt_windows.put ( ascii.cr ) ;
- while ( Length ( Input_Line ) > topic_name_type'length ) loop
- DELETE ( Input_Line , topic_name_type'length + 1 , 1 ) ;
- end loop ;
- end if ;
- ind := 1 ;
- while Length ( Input_Line ) < topic_name_type'length loop
- Input_Line := Input_Line & " " ;
- end loop ;
- help_description_array( current_help_topic_number )
- .topic_name := Input_Line.data( 1 .. length(input_line)) ;
- -- Show progress...//
- basic_io_system.put( " " ) ;
- basic_io_system.put( current_help_topic_number , 2 ) ;
- basic_io_system.put( " " ) ;
- basic_io_system.put( help_description_array( current_help_topic_number )
- .block_number , 3 ) ;
- basic_io_system.put( " " ) ;
- basic_io_system.put( help_description_array( current_help_topic_number )
- .PLACE , 3 ) ;
- basic_io_system.put( " " ) ;
- basic_io_system.put( help_description_array( current_help_topic_number )
- .help_code ) ;
- basic_io_system.put( " """ ) ;
- basic_io_system.put( help_description_array( current_help_topic_number )
- .topic_name ) ;
- basic_io_system.put( '"' ) ;
- -- Now, do the lines of data//
- GET_LINE ;
- while Input_Line.data( 1 ) /= '*' loop -- process a line//
- Move_Data_To_Help_Area ; -- get the next line//
- GET_LINE ;
- end loop ; -- Put The End On//
- set_length ( Input_Line , 0 ) ;
- Move_Data_To_Help_Area ; -- Now, show final statistics//
- SHOWNUM ( help_description_array( current_help_topic_number )
- .block_number ,
- help_description_array( current_help_topic_number )
- .PLACE ,
- integer(Next_Output_Block) ,
- next_character_position_within_block ) ;
- crt_windows.put ( ascii.cr ) ; -- Now, prepare for the next one...//
- current_help_topic_number := current_help_topic_number + 1 ;
- if current_help_topic_number > maximum_help_topics then
- basic_io_system.put( " Error...To Many Keys.... " ) ;
- crt_windows.put ( ascii.cr ) ;
- end if ;
- GET_LINE ; -- get in the next index line//
- end loop ;
- put_block ;
- end DOWORK ;
-
- procedure FINISHUP is
- type code_array_type is array ( 0 ..
- ( ( first_text_block_in_file - 1 ) * block_size ) - 1 )
- of character ;
- code_array : code_array_type ;
-
- procedure convert_from_entry_to_text ( t : in help_topic_description;
- ot_place : in integer ) is
- begin
- -- we must move t data over into code_array starting at ot_place
- code_array ( ot_place + 00 ) := character'val(t.block_number / 64 );
- code_array ( ot_place + 01 ) := character'val(
- ( ( t.block_number mod 64 ) * 2 )
- + ( t.place / 128 ) ); -- lowest bit
- code_array ( ot_place + 02 ) := character'val( t.place mod 128 ) ;
- code_array ( ot_place + 03 ) := t.help_code ;
- for posn in 1 .. 28 loop
- code_array ( ot_place + 3 + posn ) := t.topic_name ( posn ) ;
- end loop ;
- end convert_from_entry_to_text ;
-
- begin -- FINISHUP
- for topic in 1 .. maximum_help_topics loop
- -- we must convert it over
- convert_from_entry_to_text ( help_description_array( topic ) ,
- (topic-1)*32 ) ;
- end loop ;
- for blockn in 1 .. first_text_block_in_file - 1 loop
- for posn in 0 .. block_size - 1 loop
- help_text_array.data(posn) := code_array ( (blockn-1) * block_size
- + posn );
- end loop ;
- next_output_block := help_file_io.positive_count( blockn ) ;
- put_block ;
- end loop ;
- help_file_io.close ( Help_Data_File ) ;
- end ;
-
- procedure err( s : string ) is
- c : extended_character ;
-
- begin
- crt_windows.put ( ascii.cr );
- crt_windows.put ( ascii.cr );
- text_io.put_line( "Exception: " & s ) ;
- crt_windows.put ( ascii.cr );
- crt_windows.put ( ascii.cr );
- text_io.put ( " Type <space> to continue.... ");
- c := basic_io_system.get_transparent ;
- end err ;
-
- procedure pause is
- c : extended_character ;
- begin
- crt_windows.put ( ascii.cr );
- text_io.put ( " Type <space> to continue.... ");
- c := basic_io_system.get_transparent ;
- end pause ;
-
- begin -- define_help_file
- initialize ;
- if requested_destination_file /= no_file
- and then requested_source_file /= no_file then
- -- ok, we have a source and destination
- dowork ;
- finishup ;
- pause ;
- end if ;
- exception
- when Put_Block_Error => error( "Encountered Put_Block Error " ,
- fatal_error , operator_wait , short_beep );
- -- when user_abort => null ;
- when constraint_error => err("Constraint Error");
- when numeric_error => err("Numeric Error");
- when program_error => err("Program Error");
- when storage_error => err("Storage Error");
- when tasking_error => err("Tasking Error");
- when others => err("Unknown Error");
- end define_help_file ;
-
- begin -- help_convert ;
- null ; -- no initialization needed
- -- to use, do the following two lines...
- -- define_help_file( no_file , no_file ) ;
- -- crt.do_crt ( crt.program_termination ) ;
- end help_convert ;
-
- --$$$- HCONV
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --runh.TXT;compile]hconv
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ runh
-
- with crt_customization ;
- use crt_customization ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with help_convert ;
- use help_convert ;
-
- Procedure RunH is
-
- begin -- RunH ;
- define_help_file( no_file , no_file ) ;
- crt.do_crt ( crt.program_termination ) ;
- end RunH ;
-
- --$$$- runh
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editglob
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITGLOB
-
- -- File 008
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Globals Written 29 Nov 84 - RSCymbalski
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ;
- use text_io ;
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with crt_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- package editor_globals is
-
- subtype an_editor_command is crt_customization.
- editor_customization.crt_editor_command ;
-
- -- type crt_editor_command is ( up_command , down_command ,
-
- -- Now, we define the logical window sizing
-
- MAX_LINE_NUMBER : constant INTEGER := INTEGER'LAST ;
- MAX_COLUMN_NUMBER : constant INTEGER := 512 ;
-
- subtype LINE_NUMBER is INTEGER range 0 .. MAX_LINE_NUMBER ;
- subtype COLUMN_POSITION is INTEGER range 0 .. MAX_COLUMN_NUMBER ;
- -- 0 in either signifies no set position
-
- -- Now, information for buffer lines
-
- Max_leading_spaces : constant integer := 254 ;
-
- subtype extended_character is basic_io_system.extended_character ;
-
- subtype type_text_length is integer range 0 .. max_column_number ;
- subtype type_leading_spaces is integer range 0 .. max_leading_spaces ;
- type data_array_type is array ( type_text_length
- range 1 .. MAX_COLUMN_NUMBER )
- of extended_character ;
- type type_text_line is
- record
- data : data_array_type ;
- leading_spaces : type_leading_spaces ;
- data_length : type_text_length ;
- end record ;
-
- Max_line_length : constant integer := 255 ;
- -- Actual max number of text characters on a line
- subtype type_line_length is integer range 0 .. max_line_length ;
- Max_Bytes_In_Line : constant integer := Max_Line_Length + 3 ;
- -- A line in the buffer has max_line_length characters
- -- and three control characters
- Screen_Size : constant integer :=
- basic_io_system.max_screen_lines * max_bytes_in_line ;
- standard_open_area : constant integer := screen_size ;
- -- A standard working open area should be equivalent to
- -- a screen of data
- Minimum_Open_Area : constant integer := Max_Bytes_In_Line * 2 ;
- -- Whenever we are working, we must have two lines of
- -- room around us.
- max_buffer_size : constant integer := Screen_Size * 3 +
- standard_open_area ;
- -- The buffer must be able to handle a screen of data,
- -- bracketed by a screen on each side, and with the
- -- standard open area following ;
-
- subtype type_buffer_position is integer range 0 .. max_buffer_size ;
-
- type SCREEN_ATTRIBUTE_TYPE is ( NO_SCREEN_ATTRIBUTE , INVERSE_VIDEO ) ;
- type SCREEN_POSITION is
- record
- LINE : basic_io_system.a_screen_line_number := 0 ;
- COLUMN : basic_io_system.a_screen_column_number := 0 ;
- end record ;
-
- type COPY_MODE is ( INSERT , OVERSTRIKE ) ;
-
- type real_editor_buffer ; -- To be defined Later
-
- type an_editor_buffer is access real_editor_buffer ;
- NO_BUFFER : Constant an_editor_buffer := null ;
-
- current_buffer : an_editor_buffer:= no_buffer ;
-
- type cursor_position is
- record
- buffer_position : type_buffer_position := 0 ;
- file_line_number: line_number := 0 ;
- line_start : type_buffer_position := 0 ;
- column_offset : column_position := 0 ;
- end record ;
-
- cursor_nowhere : constant cursor_position := ( 0 , 0 , 0 , 0 ) ;
-
- type TEXT_POSITION is
- record
- LINE : LINE_NUMBER := 0 ;
- COLUMN : COLUMN_POSITION := 0 ;
- SCREEN_ATTRIBUTE : SCREEN_ATTRIBUTE_TYPE := NO_SCREEN_ATTRIBUTE ;
- WHICH_BUFFER : an_editor_buffer := no_buffer ;
- end record ;
-
- NO_SET_LOCATION : TEXT_POSITION := ( 0 , 0 , NO_SCREEN_ATTRIBUTE ,
- NO_BUFFER ) ;
-
- type TEXT_RANGE is
- record
- LO_POSITION ,
- HI_POSITION : TEXT_POSITION ;
- ATTRIBUTE : SCREEN_ATTRIBUTE_TYPE := NO_SCREEN_ATTRIBUTE ;
- end record ;
-
- type marker_item ;
- type MARKER_pointer is access marker_item ;
- type marker_item is
- record
- DATA : TEXT_POSITION ;
- PRIOR_item ,
- NEXT_item : MARKER_pointer ;
- end record ;
- NO_MARKER : constant MARKER_pointer := null ;
-
- subtype status_line_type is pstring ;
-
- -- The following is used to generate statistics on the user's efficiency
-
- time_in : basic_io_system.timer ;
- time_out: basic_io_system.timer ;
- keystrokes : integer ;
-
- -- Now, a number of buffer items
-
- Max_Buffer_Number : constant Integer := 10 ;
- subtype A_Buffer_Number is Integer range 0 .. Max_Buffer_Number ;
-
- buffer_list : array ( a_buffer_number range 1 .. max_buffer_number )
- of an_editor_buffer := ( 1 .. max_buffer_number
- => no_buffer ) ;
-
- type each_position is record
- data : extended_character ;
- attr : screen_attribute_type ;
- end record ;
-
- type T_BUFFER is array ( type_buffer_position
- range 0 .. max_buffer_size
- ) of each_position ;
-
- -- The following is the description of the text I/O items
- subtype text_file_type is text_io.file_type ;
-
- -- The following is the description of the block I/O items
- -- BLOCK_SIZE : constant integer := 1024 ;
- BLOCK_SIZE : constant integer := 512 ;
- -- The programmer must guarantee that
- -- block_size is greater than max_bytes_in_line
- -- This is a requirement of return_forward and
- -- backward line, so that we cannot get confused
- BLOCK_MINUS : constant integer := block_size - 1 ;
- subtype block_offset is integer range 0 .. block_minus ;
- type BLOCK is array ( block_offset
- range 0 .. block_minus
- ) of each_position;
-
- blank_file_name : constant ascii_text_file_name := no_file ;
-
- max_markers : constant integer := 10 ;
- subtype marker_number is integer range 0 .. max_markers ;
- subtype valid_marker_number is marker_number range 1 .. max_markers ;
- subtype STR10 is string ( 1 .. 10 ) ;
- blank_marker : constant str10 := " " ;
- type markers_array_content is
- record
- name : str10 ;
- location : marker_pointer := no_marker ;
- end record ;
- type MARKERS_ARRAY is
- array ( valid_marker_number
- range 1 .. max_markers ) of markers_array_content ;
-
- type TABTYPES is ( TNONE , TNORMAL , TNUMBER ) ;
- type a_tab_line is array ( column_position ) of TABTYPES ;
-
- type HEADER is
- record
- FILENAME : ascii_text_file_name ; -- the file name//
- marker_count : marker_number ; --The count of valid markers//
- markers : MARKERS_ARRAY ;
- AUTOINDENT : BOOLEAN ; -- Environment stuff follows//
- break_char : character ;
- CHECKCASE : BOOLEAN ;
- ENABLE_CMDS : BOOLEAN ;
- FILLING : BOOLEAN ;
- HYPHENATE : BOOLEAN ;
- JUSTIFY : BOOLEAN ;
- save_envirn : BOOLEAN ;
- TOKDEF : BOOLEAN ;
- wordprocess : BOOLEAN ;
- LMARGIN : column_position ;
- RMARGIN : column_position ;
- PARAMARGIN : column_position ;
- CREATED : basic_io_system.timer ;
- LAST_USED : basic_io_system.timer ;
- first_five ,
- last_five : string ( 1 .. 5 ) ;
- tabline : a_tab_line ;
- end record ;
-
- -- The following is the description of the text buffer
-
- type real_editor_buffer is
- record
- buffer_number : a_buffer_number ;
- -- This number is assigned when a
- -- new buffer is allocated.
- window : crt_windows.window_pointer ;
- -- which window to work
- -- now, text buffer information
- e_buf : t_buffer ;
- -- This is where the actual text of a
- -- buffer resides....
- bufcount : type_buffer_position ;
- -- Number of valid characters in the
- -- E_buf
- fixed_cursor : cursor_position := cursor_nowhere ;
- floating_cursor : cursor_position := cursor_nowhere ;
- moving_cursor : cursor_position := cursor_nowhere ;
- top_screen_cursor : cursor_position := cursor_nowhere ;
- next_screen_cursor : cursor_position := cursor_nowhere ;
-
- INPUTFILE : text_file_type ;
- -- where we read text from
- still_reading_input_file : boolean ;
- input_file_name : ascii_text_file_name ;
- copy_file_name : ascii_text_file_name ;
- output_file_name : ascii_text_file_name ;
- -- TOPFILE ,
- -- BOTFILE : BLOCKFILE ; -- storage areas for text
- PRESTOPBLOCK : INTEGER ;
- PRESBOTBLOCK : INTEGER ;
- prior_buffer ,
- following_buffer : an_editor_buffer ;
-
- PAGEZERO : HEADER ;
- NAME : STRING( 1 .. 10 ) ;
- MODE : COPY_MODE ;
- open_buffer_area : boolean ;
- first_open_position : type_buffer_position ;
- last_open_position : type_buffer_position ;
-
- last_marked_position : marker_pointer := no_marker ;
- end record ;
-
- type topush is ( thetop , thebot ) ;
-
- need_prompt : boolean ; -- do we need to put the main prompt up ?
-
- subtype a_repeat_factor is integer ;
- infinity : constant a_repeat_factor:= a_repeat_factor'last ;
- current_repeat_factor : a_repeat_factor := 0 ;
- current_command : an_editor_command :=
- crt_customization.editor_customization.illegal_command ;
-
- -- Text Buffer Layout Description...
- --
- -- The text buffer has a very special format. If corrupted, it
- -- can become impossible for the editor to recover. Therefore,
- -- text buffer manipulation should NOT be attempted by any routines
- -- other than those currently sitting in the buffer package.
- --
- -- The text buffer is an array ( 1 .. max_buffer_size ) which
- -- contains the following when initialized:
- --
- -- <255> Buffer Start Flag
- -- <0><0><0> Line Length / No Leading Spaces / Line Length
- -- <255> Buffer End Flag
- --
- -- If a single space is added, the buffer changes to the following:
- --
- -- <255> Buffer Start Flag
- -- <0><1><0> Line Length / 1 Leading Space / Line Length
- -- <255> Buffer End Flag
- --
- -- If a single character X is added, the buffer changes to the following:
- --
- -- <255> Buffer Start Flag
- -- <1><0>X<1> Line Length / No Leading Spaces /X/ Line Length
- -- <255> Buffer End Flag
- --
- -- If the text lines "Line 1<cr> Line 2<cr> Line 3<cr> is inserted
- -- then the buffer will look as follows:
- --
- -- <255> Buffer Start Flag
- -- <6><0>Line 1<6>
- -- <6><2>Line 2<6>
- -- <6><4>Line 3<6>
- -- <0><0><0>
- -- <255> Buffer End Flag
- --
- --
- -- Note that the max line length of 254 is real, because the 255 code
- -- is used to signify the beginning and end of the buffer.
- -- Also note that the line length does NOT include the leading
- -- spaces.
-
- -- The Text area can be pictured as follows
- --
- -- <Prior Editing Buffer> Pointed to by prior_buffer_number
- -- <Top File> Blocks of text saved on disk
- -- <E_buf> Text which can be manipulated
- -- <Bottom File> Blocks of text saved on disk
- -- <Input File> Input Text not yet read
- -- <Following Editing Buffer> Pointed to by following_buffer_number
- --
-
- end editor_globals ;
-
- package body editor_globals is
-
- begin
- -- EDITGLOB by SAIC/Clearwater Editor Globals 22 Jan 85
- --
- null ;
- basic_io_system.put(" Maximum bytes taken up by one line in buffer => ");
- basic_io_system.put(max_bytes_in_line);
- basic_io_system.put_line;
- basic_io_system.put(" Maximum Screen Size => ");
- basic_io_system.put(screen_size);
- basic_io_system.put_line;
- basic_io_system.put(" Standard Open Area when adding to buffer => ");
- basic_io_system.put(Standard_Open_Area);
- basic_io_system.put_line;
- basic_io_system.put(" Minimum Open Area When working => ");
- basic_io_system.put(Minimum_Open_Area);
- basic_io_system.put_line;
- basic_io_system.put(" Maximum Characters In Buffer => ");
- basic_io_system.put(max_buffer_size);
- basic_io_system.put_line;
- end editor_globals ;
-
- --$$$- EDITGLOB
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --ewindows
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EWINDOWS
-
- --
- -- File 009
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Window Manager Routines Written 19 Dec 84 - Robert S. Cymbalski
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ;
-
- with string_library ;
- use string_library ;
-
- with crt_windows ;
- use crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- package edit_windows is
-
- subtype window_line_number is crt_windows.window_line_number ;
- subtype window_column_number is crt_windows.window_column_number;
- -- integer because we don't know the limits on columns over
-
- procedure clear_window ( which_buffer : in an_editor_buffer ) ;
- -- Clear the entire window of all text
-
- procedure clear_prompt ( which_buffer : in an_editor_buffer ) ;
- -- Clear the prompt line(s) of a window
-
- procedure Clear_Line ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ) ;
- -- Clear the Line Specified
-
- procedure Clear_End_Of_Line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) ;
- -- Clear the Line Specified, from line,column to end of line
-
- procedure Clear_Prompt_End_Of_Line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number) ;
- -- Clear the Prompt Line Specified, from line,column to end of line
-
- procedure Clear_End_Of_Screen( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) ;
- -- Clear from Line, Column to the end of the window
-
- procedure goto_line_column ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) ;
- -- Move to the specified line and column within a window. Note that
- -- the first column and line are numbered #1. A Window area is
- -- exclusive of any prompt area
-
- procedure goto_Prompt_line_column ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) ;
- -- Move to the specified line and column within a window's Prompt
- -- area. Note that the first column and line are numbered #1.
-
- procedure set_prompt ( which_buffer : in an_editor_buffer ;
- which_prompt_line : in integer ;
- prompt_line : in string ) ;
- -- Set the prompt line as specified
-
- procedure set_prompt ( which_buffer : in an_editor_buffer ;
- which_prompt_line : in integer ;
- prompt_line : in pstring ) ;
- -- Set the prompt line as specified
-
- procedure save_prompt_temporarily ;
- -- save the prompt area because an error message will be written
-
- procedure restore_prompt_after_temporary_save ;
- -- and restore the prompt area after that error message
-
- Function Lowest_Column_Number ( which_buffer : in an_editor_buffer )
- return window_column_number ;
- -- Return the lowest column number available on the window
-
- Function Highest_Column_Number ( which_buffer : in an_editor_buffer )
- return window_column_number ;
- -- Return the highest column number available on the window
-
- Function Window_Height ( which_buffer : in an_editor_buffer )
- return window_Line_number ;
- -- Return the number of text lines in this window
-
- procedure set_reverse ( do_reverse : boolean ) ;
- -- set current_window.next_will_be_reverse and do the
- -- appropriate crt command
-
- procedure set_reverse_if_necessary ( do_reverse : boolean ) ;
- -- set current_window.next_will_be_reverse and do the
- -- appropriate crt command only if we are not set correctly
-
- function current_reverse return boolean ;
- -- return the current setting of the reverse flag
-
- procedure put( c : character ) ;
- -- puts a character into the current window. We only recognize
- -- ' ' .. tilde and ascii.cr. Ascii.cr moves to the first column
- -- of the next line
-
- procedure put( s : string ) ;
- -- puts out a string of all printable characters
-
- procedure put( s : pstring ) ;
- -- puts out a pstring of all printable characters
-
- procedure put( num : integer ; len : integer ) ;
- -- put out the number within the len indicated
-
- procedure put( char_posn : in each_position ) ;
- -- put out the character at this position, and set any attributes
- -- as required
-
- procedure put_line ;
- -- start a new line within the window
-
- procedure put_line( s : string ) ;
- -- output the string and then start a new line in the window
-
- procedure put_line( s : pstring ) ;
- -- output the string and then start a new line in the window
-
- -- function current_position return text_position ;
- -- return the line/column/and buffer for the current position
-
- Procedure SHIFT ( SHIFT_BUFFER : in out an_editor_buffer ;
- SHIFT_AMOUNT : in INTEGER ) ;
- -- *** change which relative character position on the line will be
- -- displayed in column 1 on the screen. Applies to any buffer
- -- mapped to the window.
-
- procedure store_shift ;
- -- store the shift amount for later because the current screen needs
- -- a shift of zero
-
- procedure restore_shift ;
- -- restore the old shift amount ;
-
- Procedure MAP_WINDOW ( WINDOW_NAME : in WINDOW_POINTER ;
- BUFFER_NAME : in out an_editor_buffer ) ;
- -- *** uses window_name as the viewing area for buffer_name, where
- -- the viewing area was previously defined with create_window
-
- Procedure REFRESH_SCREEN ;
- -- *** redraw screen to represent the current editing context
- -- requests a mandatory redraw of every line of every window
- -- which is mapped to the screen
-
- Procedure UPDATE_WINDOW ( which_buffer : in out an_editor_buffer ) ;
- -- *** update screen to reflect the current internal state of the
- -- buffer which the window_to_update is associated with
-
- Procedure UNMAP_WINDOW ( which_buffer : in out an_editor_buffer ) ;
- -- *** disassociate window_to_unmap from its buffer ; erase window from
- -- the screen but do not remove it from the available windows list
-
- function current_window return window_pointer ;
-
- function no_window return window_pointer ;
-
- procedure scroll_up_entire_window (
- number_of_lines_to_scroll : window_line_number ) ;
-
- procedure scroll_down_entire_window (
- number_of_lines_to_scroll : window_line_number ) ;
-
- end edit_windows ;
-
- package body edit_windows is
-
- old_shift_amount : integer := 0 ;
-
- procedure clear_window ( which_buffer : in an_editor_buffer ) is
- -- Clear the entire window of all text
- begin -- clear_window
- clear_window( which_buffer.window ) ;
- end clear_window ;
-
- procedure clear_prompt ( which_buffer : in an_editor_buffer ) is
- -- Clear the prompt line(s) of a window
- begin -- clear_prompt
- if which_buffer.window = crt_windows.no_window then
- error(" Program Error: Clear Prompt On Null Window " ,
- fatal_error , operator_wait , short_beep ) ;
- end if;
- clear_prompt(which_buffer.window) ;
- end clear_prompt ;
-
- procedure Clear_Line ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ) is
- -- Clear the Line Specified
- begin -- Clear_Line
- clear_line(which_buffer.window , line) ;
- end Clear_Line ;
-
- procedure Clear_End_Of_Line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) is
- -- Clear the Line Specified, from line,column to end of line
- begin -- Clear_End_Of_Line
- clear_end_of_line(which_buffer.window , line , column) ;
- end Clear_End_Of_Line ;
-
- procedure Clear_Prompt_End_Of_Line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) is
- -- Clear the Prompt Line Specified, from line,column to end of line
- begin -- Clear_Prompt_End_Of_Line
- clear_prompt_end_of_line(which_buffer.window , line , column) ;
- end Clear_Prompt_End_Of_Line ;
-
- procedure Clear_End_Of_Screen( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) is
- -- Clear from Line, Column to the end of the window
- begin -- Clear_End_Of_Screen
- clear_end_of_screen(which_buffer.window , line , column) ;
- end Clear_End_Of_Screen ;
-
- procedure goto_line_column ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) is
- -- Move to the specified line and column within a window. Note that
- -- the first column and line are numbered #1. A Window area is
- -- exclusive of any prompt area
- begin -- GoTo_Line_Column
- goto_line_column(which_buffer.window , line , column) ;
- end GoTo_Line_Column ;
-
- procedure goto_Prompt_line_column ( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ) is
- -- Move to the specified line and column within a window's Prompt
- -- area. Note that the first column and line are numbered #1.
- begin -- goto_prompt_line_column
- goto_prompt_line_column( which_buffer.window , line , column ) ;
- end goto_prompt_line_column ;
-
- procedure set_prompt ( which_buffer : in an_editor_buffer ;
- which_prompt_line : in integer ;
- prompt_line : in string ) is
- -- Set the prompt line as specified
- begin -- Set_Prompt
- set_prompt(which_buffer.window , which_prompt_line , prompt_line) ;
- end Set_Prompt ;
-
- procedure set_prompt ( which_buffer : in an_editor_buffer ;
- which_prompt_line : in integer ;
- prompt_line : in pstring ) is
- -- Set the prompt line as specified
- begin -- Set_Prompt
- set_prompt(which_buffer.window , which_prompt_line , prompt_line) ;
- end Set_Prompt ;
-
- procedure save_prompt_temporarily is
- -- save the prompt area because an error message will be written
- begin -- save_prompt_temporarily
- crt_windows.save_prompt_temporarily ;
- end save_prompt_temporarily ;
-
- procedure restore_prompt_after_temporary_save is
- -- and restore the prompt area after that error message
- begin -- restore_prompt_after_temporary_save
- crt_windows.restore_prompt_after_temporary_save ;
- end restore_prompt_after_temporary_save ;
-
- Function Lowest_Column_Number ( which_buffer : in an_editor_buffer )
- return window_column_number is
- -- Return the Lowest column number available on the window
- begin -- Lowest_column_number
- return Lowest_column_number( which_buffer.window);
- end Lowest_column_number ;
-
- Function Highest_Column_Number ( which_buffer : in an_editor_buffer )
- return window_column_number is
- -- Return the highest column number available on the window
- begin -- highest_column_number
- return highest_column_number( which_buffer.window);
- end highest_column_number ;
-
- Function Window_Height ( which_buffer : in an_editor_buffer )
- return window_Line_number is
- -- Return the number of text lines in this window
- begin -- window_height
- return window_height(which_buffer.window);
- end window_height ;
-
- procedure set_reverse ( do_reverse : boolean ) is
- -- set current_window.next_will_be_reverse and do the
- -- appropriate crt command
- begin -- set_reverse
- crt_windows.set_reverse( do_reverse ) ;
- end set_reverse ;
-
- procedure set_reverse_if_necessary ( do_reverse : boolean ) is
- -- set current_window.next_will_be_reverse and do the
- -- appropriate crt command only if we are not set correctly
- begin -- set_reverse_if_necessary
- crt_windows.set_reverse_if_necessary( do_reverse ) ;
- end set_reverse_if_necessary ;
-
- function current_reverse return boolean is
- -- return the current setting of the reverse flag
- begin -- current_reverse
- return crt_windows.current_reverse ;
- end current_reverse ;
-
- procedure put( c : character ) is
- -- puts a character into the current window. We only recognize
- -- ' ' .. tilde and ascii.cr. Ascii.cr moves to the first column
- -- of the next line
- begin -- put
- crt_windows.put(c);
- end put ;
-
- procedure put( s : string ) is
- -- puts out a string of all printable characters
- begin -- put
- crt_windows.put(s);
- end put ;
-
- procedure put( s : pstring ) is
- -- puts out a pstring of all printable characters
- begin -- put
- crt_windows.put(s);
- end put ;
-
- procedure put( num : integer ; len : integer ) is
- -- put out the number within the len indicated
- begin -- put
- crt_windows.put(num,len);
- end put ;
-
- procedure put( char_posn : in each_position ) is
- -- put out the character at this position, and set any attributes
- -- as required
- begin -- put
- crt_windows.set_reverse_if_necessary( char_posn.attr = inverse_video ) ;
- crt_windows.put( character'val( char_posn.data ) ) ;
- end put ;
-
- procedure put_line is
- -- start a new line within the window
- begin -- put_line
- crt_windows.put(ascii.cr);
- end put_line ;
-
- procedure put_line( s : string ) is
- -- output the string and then start a new line in the window
- begin -- put_line
- crt_windows.put(s);
- crt_windows.put(ascii.cr);
- end put_line ;
-
- procedure put_line( s : pstring ) is
- -- output the string and then start a new line in the window
- begin -- put_line
- crt_windows.put(s);
- crt_windows.put(ascii.cr);
- end put_line ;
-
- -- function current_position return text_position is
- -- line : crt_windows.window_line_number ;
- -- col : crt_windows.window_column_number ;
- -- begin -- current_position
- -- line := crt_windows.current_line ;
- -- col := crt_windows.current_col ;
- -- return text_position'( line , col , no_screen_attribute , current_buffer);
- -- end current_position ;
-
- Procedure SHIFT ( SHIFT_BUFFER : in out an_editor_buffer ;
- SHIFT_AMOUNT : in INTEGER ) is
- -- *** change which relative character position on the line will be
- -- displayed in column 1 on the screen. Applies to any buffer
- -- mapped to the window.
- -- we do not let a call to this routine set a positive shift amount
- old_shift : integer ;
- begin -- shift
- old_shift := crt_windows.current_shift ;
- if old_shift + shift_amount > 0 then
- crt_windows.shift( shift_buffer.window , -old_shift ) ;
- else
- crt_windows.shift( shift_buffer.window , shift_amount ) ;
- end if ;
- end shift ;
-
- procedure store_shift is
- -- store the shift amount for later because the current screen needs
- -- a shift of zero
- begin -- store_shift
- old_shift_amount := crt_windows.current_shift ;
- crt_windows.shift( current_buffer.window , - old_shift_amount ) ;
- end store_shift ;
-
- procedure restore_shift is
- -- restore the old shift amount ;
- begin --restore_shift
- crt_windows.shift( current_buffer.window ,
- old_shift_amount - crt_windows.current_shift );
- end restore_shift ;
-
- Procedure MAP_WINDOW ( WINDOW_NAME : in WINDOW_POINTER ;
- BUFFER_NAME : in out an_editor_buffer ) is
- -- *** uses window_name as the viewing area for buffer_name, where
- -- the viewing area was previously defined with create_window
- begin -- map_window
- buffer_name.window := window_name ;
- current_buffer := buffer_name ;
- set_current_window ( window_name ) ;
- end map_window ;
-
- Procedure REFRESH_SCREEN is
- -- *** redraw screen to represent the current editing context
- -- requests a mandatory redraw of every line of every window
- -- which is mapped to the screen
- begin -- refresh_screen
- for buf in 1 .. max_buffer_number loop
- if buffer_list( buf ) /= null then
- redisplay( buffer_list ( buf ) . window ) ;
- end if ;
- end loop ;
- end refresh_screen ;
-
- Procedure UPDATE_WINDOW ( which_buffer : in out an_editor_buffer ) is
- -- *** update screen to reflect the current internal state of the
- -- buffer which the window_to_update is associated with
- begin -- update_window
- redisplay( which_buffer.window ) ;
- end update_window ;
-
- Procedure UNMAP_WINDOW ( which_buffer : in out an_editor_buffer ) is
- -- *** disassociate window_to_unmap from its buffer ; erase window from
- -- the screen but do not remove it from the available windows list
- begin -- unmap_window
- -- window_to_unmap.buffer := null ;
- -- if window_to_unmap = which_window then
- -- which_window := next_most_recent_which_window ;
- -- current_buffer := which_window.buffer ;
- -- cursor.buffer.line := which_window.current_row ;
- -- cursor.buffer.column := which_window.current_column ;
- -- end if ;
- -- remove window_to_unmap from the screen area
- -- return screen area to adjacent windows if original_length of adjacent
- -- windows warrants it
- if crt_windows.current_window = which_buffer.window then
- set_current_window( crt_windows.no_window ) ;
- end if ;
- dispose_window( which_buffer.window ) ;
- end unmap_window ;
-
- function current_window return window_pointer is
- begin -- current_window
- return crt_windows.current_window ;
- end current_window ;
-
- function no_window return window_pointer is
- begin -- no_window
- return crt_windows.no_window ;
- end no_window ;
-
- procedure scroll_up_entire_window (
- number_of_lines_to_scroll : window_line_number ) is
- begin -- scroll_up_entire_window
- crt_windows.scroll_up_entire_window( number_of_lines_to_scroll ) ;
- end scroll_up_entire_window ;
-
- procedure scroll_down_entire_window (
- number_of_lines_to_scroll : window_line_number ) is
- begin -- scroll_down_entire_window
- crt_windows.scroll_down_entire_window( number_of_lines_to_scroll ) ;
- end scroll_down_entire_window ;
-
- begin -- Edit_Windows
- -- EWINDOWS by SAIC/Clearwater Editor Window Management 22 Jan 85
- null ;
- end edit_windows ;
-
- --$$$- EWINDOWS
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --markers
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ MARKERS
-
- --
- -- File 011
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Marker Packages Written 26 Dec 84 - RSC
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with crt_customization ;
- use crt_customization ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- package markers is
-
- PACKAGE TEXT_POSITION_HANDLER is
-
- --
- -- Text Position Handler Written 12 Nov 84 - RSC
- -- revised 18 Dec 84 - RSC
- --
-
- Function "<" ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN ;
- -- is left position before the right position
-
- Function ">" ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN ;
- -- is left position after the right position
-
- Function LT ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN ;
- -- is left position before the right position
-
- Function GT ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN ;
- -- is left position after the right position
-
- Procedure NORMALIZE_RANGE ( A_RANGE : in out TEXT_RANGE ) ;
- -- make sure that the lo range is less than the
- -- high range
-
- end ;
-
- PACKAGE TEXT_POS_DOUBLE_LINKED_LIST is
-
- --
- -- Text Position List Handler Written 12 Nov 84 - RSC
- -- revised 03 Dec 84 - RSC
- --
-
- Function ALLOCATE_LIST_ITEM( WITH_NEW_VALUE : in TEXT_POSITION )
- return marker_pointer ;
- -- allocate a new item & set its data value to with_new_value
-
- Procedure DE_ALLOCATE_LIST_ITEM ( OLD_ITEM : in out marker_pointer ) ;
- -- de-allocate the old list item
-
- Function FIRST_IN_LIST return marker_pointer ;
- -- return the first item in the list
-
- Function LAST_IN_LIST return marker_pointer ;
- -- return the last item in the list
-
- Function NEXT_IN_LIST ( OLD_ITEM : in marker_pointer )
- return marker_pointer ;
- -- return next item from list
-
- Function PRIOR_IN_LIST ( OLD_ITEM : in marker_pointer )
- return marker_pointer ;
- -- return prior item from list
-
- end ;
-
- PACKAGE MARKER_MANAGER is
-
- --
- -- Marker Manager Written 12 Nov 84 - RSC
- -- revised 05 Dec 84 - RSC
- --
-
- -- use text_pos_double_linked_list ;
-
- -- this allocates space for markers & manages them
-
- -- don't allow any operations on markers except
- -- "=" & "=/".
-
- -- you can't do anything with a marker except
- -- 1) set it
- -- 2) check it's position
- -- 3) kill it
- -- 4) see if it specifies the same position as another
- -- marker ( line = line ; column = column )
- -- you can not assign it or anything ...
-
- Procedure NEW_MARKER ( A_NEW_MARKER : out marker_pointer ) ;
- -- allocate a new marker
-
- Procedure DISPOSE ( OLD_MARKER : in out marker_pointer ) ;
- -- de-allocate an old marker
-
- Procedure LOAD_MARKER ( MARKER_NAME : in out marker_pointer ;
- WITH_ADDRESS : in TEXT_POSITION ) ;
- -- set the value of that marker with the specified position
-
- Function MARKERS_POSITION ( THE_MARKER : in marker_pointer )
- return TEXT_POSITION ;
- -- returns specified position of the given marker
-
- Procedure MARK ( A_MARKER : in out marker_pointer ;
- WITH_ATTRIBUTE : in SCREEN_ATTRIBUTE_TYPE ) ;
- -- set the marker to have the specified attribute.
-
- Procedure UPDATE_MARKERS_FOR_ADDED_TEXT
- ( This_Buffer : in an_editor_buffer ;
- NEW_TEXT_RANGE : in out TEXT_RANGE ) ;
- -- update all marker positions because text was
- -- added between the range
-
- Procedure UPDATE_MARKERS_FOR_DELETED_TEXT
- ( This_Buffer : in an_editor_buffer ;
- OLD_TEXT_RANGE : in out TEXT_RANGE ) ;
- -- update all markers because the old text
- -- range was deleted
-
- Procedure CLEAR_MARKERS ( FROM_BUFFER : in an_editor_buffer ) ;
- -- Clear all markers which are in that buffer
-
- end ;
-
- end markers ;
-
- package body markers is
-
- PACKAGE body TEXT_POSITION_HANDLER is
-
- -- text position definitions
-
- Function "<" ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN is
- -- is left position before the right position
-
- begin
- -- Does not check to see if in same buffer
- if ( LEFT.LINE < RIGHT.LINE ) then
- return TRUE ;
- elsif ( LEFT.LINE > RIGHT.LINE ) then
- return FALSE ;
- else
- return ( LEFT.COLUMN < RIGHT.COLUMN ) ;
- end if ;
- end ;
-
- Function ">" (LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN is
- -- is left position before the right position
- begin
- -- Does not check to see if in same buffer
- return RIGHT < LEFT ;
- end ;
-
- Function LT ( LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN is
- -- is left position before the right position
-
- begin
- -- Does not check to see if in same buffer
- if ( LEFT.LINE < RIGHT.LINE ) then
- return TRUE ;
- elsif ( LEFT.LINE > RIGHT.LINE ) then
- return FALSE ;
- else
- return ( LEFT.COLUMN < RIGHT.COLUMN ) ;
- end if ;
- end ;
-
- Function GT (LEFT , RIGHT : TEXT_POSITION ) return BOOLEAN is
- -- is left position before the right position
- begin
- -- Does not check to see if in same buffer
- return RIGHT < LEFT ;
- end ;
-
- Procedure NORMALIZE_RANGE ( A_RANGE : in out TEXT_RANGE ) is
- -- make sure that the low range is less than the
- -- high range
- TEMP_POSITION : TEXT_POSITION ;
- begin
- -- Does not check to see if in same buffer
- if gt ( A_RANGE.LO_POSITION , A_RANGE.HI_POSITION ) then
- TEMP_POSITION := A_RANGE.LO_POSITION ;
- A_RANGE.LO_POSITION := A_RANGE.HI_POSITION ;
- A_RANGE.HI_POSITION := TEMP_POSITION ;
- end if ;
- end normalize_range ;
-
- Begin -- TEXT_POSITION_HANDLER
- -- TEXTPOS by SAIC/Clearwater Text Position Handler 21 Dec 84
- null ;
- End TEXT_POSITION_HANDLER ;
-
- use TEXT_POSITION_HANDLER ;
-
- PACKAGE body TEXT_POS_DOUBLE_LINKED_LIST is
-
- ITEM_LIST_HEAD : marker_pointer := null ;
- ITEM_LIST_TAIL : marker_pointer := null ;
-
- Function ALLOCATE_LIST_ITEM ( WITH_NEW_VALUE : in TEXT_POSITION )
- return marker_pointer is
- -- allocate a new item & set its data value to with_new_value
- AN_ITEM : marker_pointer ;
- begin
- AN_ITEM := NEW marker_item ;
- AN_ITEM.DATA := WITH_NEW_VALUE ;
- AN_ITEM.PRIOR_ITEM := ITEM_LIST_TAIL ;
- AN_ITEM.NEXT_ITEM := null ;
- if item_list_tail = null then
- -- a new list
- item_list_head := an_item ;
- item_list_tail := an_item ;
- else
- -- an old list
- ITEM_LIST_TAIL.NEXT_ITEM := AN_ITEM ;
- ITEM_LIST_TAIL := AN_ITEM ;
- end if;
- return AN_ITEM ;
- end ;
-
- Procedure DE_ALLOCATE_LIST_ITEM ( OLD_ITEM : in out marker_pointer ) is
- -- de-alloate the old list item
- begin
- if OLD_ITEM = null then
- null ; -- really an error ...
- else
- if OLD_ITEM = ITEM_LIST_HEAD then
- ITEM_LIST_HEAD := ITEM_LIST_HEAD.NEXT_ITEM ;
- end if ;
- if OLD_ITEM = ITEM_LIST_TAIL then
- ITEM_LIST_TAIL := ITEM_LIST_TAIL.PRIOR_ITEM ;
- end if ;
- -- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- -- *** release ( OLD_ITEM ) ; ***
- -- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- OLD_ITEM := null ;
- end if ;
- end ;
-
- Function FIRST_IN_LIST return marker_pointer is
- -- return first item in the list
- begin
- return ITEM_LIST_HEAD ;
- end ;
-
- Function LAST_IN_LIST return marker_pointer is
- -- return last item in the list
- begin
- return ITEM_LIST_TAIL ;
- end ;
-
- Function NEXT_IN_LIST ( OLD_ITEM : in marker_pointer )
- return marker_pointer is
- -- return next item from list
- begin
- return OLD_ITEM.NEXT_ITEM ;
- end ;
-
- Function PRIOR_IN_LIST ( OLD_ITEM : in marker_pointer )
- return marker_pointer is
- -- returns prior item from list
- begin
- return OLD_ITEM.PRIOR_ITEM ;
- end ;
-
- Begin -- DOUBLE_LINKED_LIST_PACKAGE
- -- All done automatically
- -- TEXTLIST by SAIC/Clearwater Text Position Linked List 18 Dec 84
- null ;
- end TEXT_POS_DOUBLE_LINKED_LIST ;
-
- use TEXT_POS_DOUBLE_LINKED_LIST ;
-
- PACKAGE body MARKER_MANAGER is
-
- Procedure NEW_MARKER ( A_NEW_MARKER : out marker_pointer ) is
- -- allocate a new marker
- Begin
- A_NEW_MARKER := ALLOCATE_LIST_ITEM ( NO_SET_LOCATION ) ;
- -- allocate a new marker & set its text_position
- -- to no location set yet
- End ;
-
- Procedure DISPOSE ( OLD_MARKER : in out marker_pointer ) is
- -- get rid of old marker
- Begin
- DE_ALLOCATE_LIST_ITEM ( OLD_MARKER ) ;
- End ;
-
- Procedure LOAD_MARKER ( MARKER_NAME : in out marker_pointer ;
- WITH_ADDRESS : in TEXT_POSITION ) is
- -- set marker value with the specified position
-
- Begin
- if marker_name /= NO_MARKER then
- NEW_MARKER ( marker_name ) ;
- end if ;
- MARKER_NAME.DATA := WITH_ADDRESS ;
- End ;
-
- Function MARKERS_POSITION ( THE_MARKER : in marker_pointer )
- return TEXT_POSITION is
- -- returns specified position for given marker
-
- Begin
- return THE_MARKER.DATA ;
- End ;
-
- Procedure MARK ( A_MARKER : in out marker_pointer ;
- WITH_ATTRIBUTE : in SCREEN_ATTRIBUTE_TYPE ) is
- -- set the marker to have the specified attribute.
- -- *** also change attribute if necessary !!! ***
- Begin
- if A_MARKER /= NO_MARKER then
- NEW_MARKER ( A_MARKER ) ;
- end if ;
- LOAD_MARKER( A_MARKER, text_position'(
- current_buffer.fixed_cursor.file_line_number ,
- current_buffer.fixed_cursor.column_offset ,
- with_attribute ,
- current_buffer) ) ;
- End ;
-
- Procedure UPDATE_MARKERS_FOR_ADDED_TEXT
- ( This_Buffer : in an_editor_buffer ;
- NEW_TEXT_RANGE : in out TEXT_RANGE ) is
- -- update all marker positions because text was
- -- added between the range
- A_MARKER : marker_pointer ;
- Begin
- A_MARKER := FIRST_IN_LIST ;
- WHILE A_MARKER /= null loop
- if a_marker.data.which_buffer = this_buffer then
- -- OK , we match the current buffer and can work.
- if gt ( NEW_TEXT_RANGE.LO_POSITION , A_MARKER.DATA ) then
- null ; -- marker not affected - marker before the added range
- else
- -- this marker is affected
- if A_MARKER.DATA.LINE = NEW_TEXT_RANGE.LO_POSITION.LINE then
- -- then text added to this line before this position,
- -- so the column is affected
- A_MARKER.DATA.COLUMN := A_MARKER.DATA.COLUMN -
- NEW_TEXT_RANGE.LO_POSITION.COLUMN +
- NEW_TEXT_RANGE.HI_POSITION.COLUMN ;
- else
- null ; -- column is not affected
- end if ;
- -- obtain new line number for the marker
- A_MARKER.DATA.LINE := A_MARKER.DATA.LINE -
- NEW_TEXT_RANGE.LO_POSITION.LINE +
- NEW_TEXT_RANGE.HI_POSITION.LINE ;
- end if ;
- end if ;
- -- get next marker to check
- A_MARKER := NEXT_IN_LIST ( A_MARKER ) ;
- end loop ;
- End UPDATE_MARKERS_FOR_ADDED_TEXT ;
-
- Procedure UPDATE_MARKERS_FOR_DELETED_TEXT
- ( This_Buffer : in an_editor_buffer ;
- OLD_TEXT_RANGE : in out TEXT_RANGE ) is
- -- update all markers because the old text
- -- range was deleted
- A_MARKER : marker_pointer ;
- Begin
- A_MARKER := FIRST_IN_LIST ;
- while A_MARKER /= null loop
- if a_marker.data.which_buffer = this_buffer then
- -- OK , we match the current buffer and can work.
- if gt ( OLD_TEXT_RANGE.LO_POSITION , A_MARKER.DATA ) then
- null ; -- marker not affected - marker before deleted range
- else
- -- this marker is affected
- if lt ( A_MARKER.DATA , OLD_TEXT_RANGE.HI_POSITION ) then
- -- marker inside deleted range
- -- set to position immediately before the deleted range
- A_MARKER.DATA := OLD_TEXT_RANGE.LO_POSITION ;
- else
- -- marker past deleted text
- if A_MARKER.DATA.LINE = OLD_TEXT_RANGE.HI_POSITION.LINE then
- -- text deleted in line before this position - column affected
- A_MARKER.DATA.COLUMN := A_MARKER.DATA.COLUMN -
- OLD_TEXT_RANGE.HI_POSITION.COLUMN +
- OLD_TEXT_RANGE.LO_POSITION.COLUMN ;
- else
- null ; -- column not affected
- end if ;
- -- obtain new line number for marker
- A_MARKER.DATA.LINE := A_MARKER.DATA.LINE -
- ( OLD_TEXT_RANGE.HI_POSITION.LINE -
- OLD_TEXT_RANGE.LO_POSITION.LINE ) ;
- end if ;
- end if ;
- end if ;
- -- obtain next marker to check
- A_MARKER := NEXT_IN_LIST ( A_MARKER ) ;
- end loop ;
- End UPDATE_MARKERS_FOR_DELETED_TEXT ;
-
- Procedure CLEAR_MARKERS ( FROM_BUFFER : in an_editor_buffer ) is
- -- clear all floating markers for lists
- -- +++ RULE : any marker MUST be disposed. When a buffer is
- -- closed .. it must have all markers cleared
- -- ( if applicable ).
- A_MARKER : marker_pointer ;
- TEMP_MARKER : marker_pointer ;
- Begin
- A_MARKER := FIRST_IN_LIST ;
- while A_MARKER /= null loop
- -- get next marker in list
- TEMP_MARKER := NEXT_IN_LIST ( A_MARKER ) ;
- if A_MARKER.DATA.WHICH_BUFFER = FROM_BUFFER then
- -- marker in given buffer, so dispose it.
- DISPOSE ( A_MARKER ) ;
- end if ;
- -- restore to next marker in the list
- A_MARKER := TEMP_MARKER ;
- end loop ;
- End CLEAR_MARKERS ;
-
- Begin -- MARKER_MANAGER ;
- -- MARKER by SAIC/Clearwater Marker Manager Package 18 Dec 84
- null ;
- End MARKER_MANAGER ;
-
- begin -- markers
- -- MARKERS by SAIC/Clearwater Marker Packages 26 Dec 84
- null ;
- end markers ;
-
- --$$$- MARKERS
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --envirnio
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ ENVIRNIO
-
- --
- -- File 012
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Environment Input/Output Routines Written 27 Dec 84 - Robert S. Cymbalski
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ;
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with markers ;
- use markers ;
- use marker_manager ;
-
- package environment_input_output is
-
- procedure convert_string_to_header ( input_string : in string ;
- env_code : in out integer ;
- which_header : in out header ;
- markers_buffer: in an_editor_buffer
- ); -- no_buffer ) ;
- -- Take the Input String as a new line read from a file
- -- The Environment Code is the Last Environment Line Read In
- -- and is zero for no lInes read in yet.
- -- If this line is an environment Line, then modify environment
- -- appropriately
- -- Update env_code to be the next sequential number, or else return
- -- it as -1 when this line was not processed because it was not part
- -- of an environment
-
- procedure convert_header_to_string ( environment : in header ;
- env_code : in out integer ;
- new_string : out pstring ) ;
- -- Take the environment specified, and output the line number
- -- corresponding to the env_code provided. Return the string of
- -- environment data in the string new_string. Update env_code to the
- -- next environment code
-
- function default_header return header ;
- -- Return the standard default header
-
- procedure users_default_header ( which_header : in out header );
- -- Return the user's default header if one exists, else the standard
-
- end environment_input_output ;
-
- package body environment_input_output is
-
- -- An editor environment is saved in the following format
-
- -- The environment ( if it exists ) starts on the very first line .
- -- at the first character position .
- -- The Environment data is contained in the character positions 6 .. 70
- -- Positions 1..5 and 71..75 have values which are constant over a
- -- specified environment, but which can change between files.
-
- -- Line 1 Format
- -- Columns 6.. 9 " 01 "
- -- Columns 10..21 "SAIC Editor "
- -- Columns 22..48 File Name of file when last saved (Possibly Truncated)
- -- Columns 49..57 " Created "
- -- Columns 58..69 YYMMDD:HH:MM
- -- Column 70 " "
-
- -- Line 2 Format
- -- Columns 6.. 9 " 02 "
- -- Columns 10..48 "A=b B=c C=b E=b F=b J=b S=b T=b W=b x=x"
- -- Columns 49..57 " Updated "
- -- Columns 58..69 YYMMDD:HH:MM
- -- Column 70 " "
-
- -- Line 3 Format
- -- Columns 6.. 9 " 03 "
- -- Columns 10..61 "Left = nnn Para = nnn Right = nnn Markers = nnn "
- -- Columns 62..69 " "
- -- Column 70 " "
-
- -- Line 4 Format
- -- Columns 6.. 9 " 04 "
- -- Columns 10..69 Code for Tabs in Positions 1 .. 180
- -- Column 70 " "
-
- -- Line 5 Format
- -- Columns 6.. 9 " 05 "
- -- Columns 10..69 Code for Tabs in Positions 181 .. 360
- -- Column 70 " "
-
- -- Line 6 Format
- -- Columns 6.. 9 " 06 "
- -- Columns 10..69 Code for Tabs in Positions 361 .. 512
- -- Column 70 " "
-
- -- Line 7 .. Markers + 6 ( if any ) Format
- -- Columns 6..9 " nn "
- -- Columns 10..19 Marker Name
- -- Columns 20..62 " Line Number = nnnnn Column Number = nnn "
- -- Columns 63..69 " "
- -- Column 70 " "
-
- -- Now, misc. routines
-
- function int_to_string_length( number : in integer ;
- length : in integer )
- return pstring is
- new_string : pstring ;
- begin
- new_string := int_to_str( number ) ;
- while string_library.length( new_string ) < length loop
- new_string := "0" & new_string ;
- end loop ;
- return new_string ;
- end;
-
- procedure convert_string_to_header ( input_string : in string ;
- env_code : in out integer;
- which_header : in out header ;
- markers_buffer: in an_editor_buffer
- ) is -- no_buffer ) is
- -- Take the Input String as a new line read from a file
- -- The Environment Code is the Last Environment Line Read In
- -- and is zero for no lines read in yet.
- -- If this line is an environment Line, then modify environment
- -- appropriately
- -- Update env_code to be the next sequential number, or else return
- -- it as -1 when this line was not processed because it was not part
- -- of an environment
-
- function ok_line_number return boolean is
- -- s(6..9) should be " nn " where nn is env_code + 1
- line_number_string : pstring ;
- begin
- line_number_string := int_to_string_length( env_code + 1 , 2 ) ;
- return ( input_string( 6 ) = ' ' )
- and ( input_string( 7..8 ) = line_number_string.data( 1 .. 2 ) )
- and ( input_string( 9 ) = ' ' ) ;
- end;
-
- procedure set_first_and_last_five_characters is
- begin
- which_header.first_five := input_string( 1 .. 5 ) ;
- which_header.last_five := input_string( 71 .. 75 ) ;
- end ;
-
- Function It_Matches_The_Last_Line return boolean is
- begin
- return ( which_header.first_five = input_string( 1.. 5 ) )
- and ( which_header.last_five = input_string( 71..75 ) ) ;
- end ;
-
- function s_to_i ( s : in string ) return integer is
- num : integer ;
- str : string ( 1 .. s'length ) ;
- -- because of problems with the wicat, only works to 32759
- begin
- str := s ;
- num := 0 ;
- for position in 1 .. str'length loop
- if str(position) in '0'..'9' then
- if num + 9 < integer'last / 10 then
- num := num * 10 + ( character'pos( str(position) )
- - character'pos('0') ) ;
- else
- return 0 ;
- end if;
- else
- return 0;
- end if;
- end loop;
- return num ;
- end;
-
- function to_date ( s : in string ) return basic_io_system.timer is
- -- Columns 1..12 YYMMDD:HH:MM
- i : integer ;
- year : basic_io_system.year_number ;
- month : basic_io_system.month_number ;
- day : basic_io_system.day_number ;
- weekday : basic_io_system.day_of_week_name;
- hour : basic_io_system.hour_number ;
- minute : basic_io_system.minute_number ;
- second : basic_io_system.second_number ;
- str : string ( 1 .. s'length ) ;
- dt : basic_io_system.timer ;
- begin
- str := s ;
- i := s_to_i ( str( 1 .. 2 ) ) ;
- if i > 84 then
- year := 1900 + i ;
- else
- year := 2000 + i ;
- end if ;
- i := s_to_i ( str( 3 .. 4 ) ) ;
- if i in basic_io_system.month_number then
- month := i ;
- else
- month := 10 ;
- end if ;
- i := s_to_i ( str( 5 .. 6 ) ) ;
- if i in basic_io_system.day_number then
- day := i ;
- else
- day := 4 ;
- end if ;
- weekday := basic_io_system.sunday ;
- i := s_to_i ( str( 8 .. 9 ) ) ;
- if i in basic_io_system.hour_number then
- hour := i ;
- else
- hour := 0 ;
- end if ;
- i :=s_to_i ( str(11 ..12 ) ) ;
- if i in basic_io_system.minute_number then
- minute := i ;
- else
- minute := 0 ;
- end if ;
- second := 0 ;
- dt := basic_io_system.time_of ( year , month , day , weekday ,
- hour , minute , second ) ;
- return dt ;
- end;
-
- procedure do_tabs ( tab_offset : integer ) is
- -- Columns 10..69 Code for Tabs in Positions 1 .. 180
- -- or 181 .. 360
- -- or 361 .. 512
- newpla ,
- whichtab ,
- presnum : integer ;
- filled : array ( 0 .. 5 ) of boolean ;
- tabpla : integer ;
- begin -- do_tabs
- newpla := 10 ; -- column to start with
- whichtab := 0 ;
- tabpla := tab_offset + 1 ;
- loop
- if whichtab = 0 then
- presnum := character'pos(input_string(newpla))-character'pos('@');
- if presnum < 0 then
- presnum := 0 ;
- end if ;
- for pla in reverse 0 .. 5 loop
- filled( pla ) := presnum mod 2 /= 0 ;
- presnum := presnum / 2 ;
- end loop ;
- end if ;
- if filled( whichtab ) then
- which_header.tabline( tabpla ) := tnormal ;
- elsif filled( whichtab + 1 ) then
- which_header.tabline( tabpla ) := tnumber ;
- else
- which_header.tabline( tabpla ) := tnone ;
- end if ;
- whichtab := whichtab + 2 ;
- if whichtab = 6 then
- whichtab := 0 ;
- newpla := newpla + 1 ;
- end if;
- tabpla := tabpla + 1 ;
- exit when ( tabpla > tab_offset + 180 )
- or else ( tabpla > column_position'last ) ;
- end loop ;
- end do_tabs ;
-
- procedure do_marker ( marker_num : integer ) is
- line_number : integer ;
- line_offset : integer ;
- mark : markers_array_content ;
- begin -- do_marker
- mark.name := input_string( 10 .. 19 ) ;
- line_number := s_to_i ( input_string( 35 .. 39 ) ) ;
- line_offset := s_to_i ( input_string( 59 .. 61 ) ) ;
- new_marker (mark.location);
- load_marker( mark.location , text_position'
- ( line_number , line_offset ,
- no_screen_attribute , markers_buffer) );
- which_header.markers(marker_num) := mark ;
- end do_marker ;
-
- function bool ( c : character ) return boolean is
- begin
- return ( c = 'T' ) or else ( c = 't' ) ;
- end ;
-
- begin -- convert_string_to_header
- -- What do we do?
- -- First, check to see if the line number is in position
- if input_string'length < 75 then
- -- not a real line
- env_code := -1 ;
- elsif not ok_line_number then
- env_code := ( -1 ) ;
- else
- if env_code = 0 then
- -- Check for a Special String
- if input_string ( 10 .. 21 ) = "SAIC Editor " then
- -- ok..
- -- we need to load the starting and ending codes
- set_first_and_last_five_characters ;
- else
- -- not ok
- env_code := -1;
- return ;
- end if;
- else
- if not it_matches_the_last_line then
- -- no good, not part of the environment
- env_code := -1;
- return ;
- end if ;
- end if;
- -- OK, here on a good line number and starting and ending characters
- env_code := env_code + 1 ;
- case env_code is
- when 1=>which_header.created:=to_date( input_string( 58..69 ));
- when 2=>which_header.autoindent := bool( input_string( 12 ) ) ;
- which_header.break_char := input_string( 16 ) ;
- which_header.checkcase := bool( input_string( 20 ) ) ;
- which_header.enable_cmds:= bool( input_string( 24 ) ) ;
- which_header.filling := bool( input_string( 28 ) ) ;
- which_header.justify := bool( input_string( 32 ) ) ;
- which_header.save_envirn:= bool( input_string( 36 ) ) ;
- which_header.Tokdef := bool( input_string( 40 ) ) ;
- which_header.WordProcess:= bool( input_string( 44 ) ) ;
- which_header.last_used:=to_date( input_string(58..69));
- when 3=>which_header.lmargin := s_to_i (
- input_string( 17 .. 19 ) ) ;
- which_header.paramargin := s_to_i (
- input_string( 29 .. 31 ) ) ;
- which_header.rmargin := s_to_i (
- input_string( 42 .. 44 ) ) ;
- which_header.marker_count:=s_to_i (
- input_string( 57 .. 59 ) ) ;
- if which_header.marker_count > max_markers then
- env_code := -1;
- end if ;
- when 4=>do_tabs ( 0 ) ;
- when 5=>do_tabs ( 180 ) ;
- when 6=>do_tabs ( 360 ) ;
- when others=>if env_code - 6 > which_header.marker_count then
- env_code := -1 ;
- else
- do_marker( env_code - 6 ) ;
- end if;
- end case;
- end if ;
- end convert_string_to_header ;
-
- procedure convert_header_to_string ( environment : in header ;
- env_code : in out integer ;
- new_string : out pstring ) is
- -- Take the environment specified, and output the line number
- -- corresponding to the env_code provided. Return the string of
- -- environment data in the string new_string. Update env_code to the
- -- next environment code
-
- outs : string ( 1 .. 75 ) := -- ( 1 .. 75 => ' ' ) ;
- " ";
- subtype str2 is string ( 1 .. 2 ) ;
- subtype str3 is string ( 1 .. 3 ) ;
- subtype str5 is string ( 1 .. 5 ) ;
-
- function to_str2( num : integer ) return str2 is
- s : pstring ;
- begin
- s := int_to_string_length ( num , 2 ) ;
- return s.data ( 1 .. 2 ) ;
- end;
-
- function to_str3( num : integer ) return str3 is
- s : pstring ;
- begin
- s := int_to_string_length ( num , 3 ) ;
- return s.data ( 1 .. 3 ) ;
- end;
-
- function to_str5( num : integer ) return str5 is
- s : pstring ;
- begin
- s := int_to_string_length ( num , 5 ) ;
- return s.data ( 1 .. 5 ) ;
- end;
-
- procedure set_line_number is
- -- Columns 6.. 9 " nn "
- begin
- outs ( 7 .. 8 ) := to_str2( env_code ) ;
- end;
-
- procedure do_line_1 is
- -- Line 1 Format
- -- Columns 6.. 9 " 01 "
- -- Columns 10..21 "SAIC Editor "
- -- Columns 22..48 File Name when last saved (Possibly Truncated)
- -- Columns 49..57 " Created "
- -- Columns 58..69 YYMMDD:HH:MM
- -- Column 70 " "
- begin -- do_line_1
- outs( 10 .. 21 ) := "SAIC Editor " ;
- if maximum_file_name_length < 27 then
- -- need to work something else out
- outs( 22 .. 21 + maximum_file_name_length ) :=
- editor_requested_output_file_name ;
- else
- outs( 22 .. 48 ) := editor_requested_output_file_name ( 1 .. 27 ) ;
- end if ;
- outs( 49 .. 57 ) := " Created " ;
- outs( 58 .. 69 ) := "YYMMDD:HH:MM" ;
- outs( 58 .. 59 ) := to_str2 ( environment.created.year mod 100 ) ;
- outs( 60 .. 61 ) := to_str2 ( environment.created.month ) ;
- outs( 62 .. 63 ) := to_str2 ( environment.created.day ) ;
- outs( 65 .. 66 ) := to_str2 ( environment.created.hour ) ;
- outs( 68 .. 69 ) := to_str2 ( environment.created.minute ) ;
- end do_line_1 ;
-
- procedure do_line_2 is
- -- Line 2 Format
- -- Columns 6.. 9 " 02 "
- -- Columns 10..48 "A=b B=c C=b E=b F=b J=b S=b T=b W=b x=x"
- -- Columns 49..57 " Updated "
- -- Columns 58..69 YYMMDD:HH:MM
- -- Column 70 " "
- new_time : basic_io_system.timer ;
-
- function bool ( b : in boolean ) return character is
- begin
- if b then
- return 'T' ;
- else
- return 'F' ;
- end if ;
- end bool ;
-
- begin -- do_line_2
- outs( 10 .. 48 ) := "A=b B=c C=b E=b F=b J=b S=b T=b W=b x=x" ;
- outs( 12 ) := bool ( environment.autoindent ) ;
- outs( 16 ) := environment.break_char ;
- outs( 20 ) := bool ( environment.checkcase ) ;
- outs( 24 ) := bool ( environment.enable_cmds) ;
- outs( 28 ) := bool ( environment.filling ) ;
- outs( 32 ) := bool ( environment.justify ) ;
- outs( 36 ) := bool ( environment.save_envirn) ;
- outs( 40 ) := bool ( environment.Tokdef ) ;
- outs( 44 ) := bool ( environment.WordProcess) ;
- new_time := basic_io_system.clock ;
- outs( 49 .. 57 ) := " Updated " ;
- outs( 58 .. 69 ) := "YYMMDD:HH:MM" ;
- outs( 58 .. 59 ) := to_str2 ( new_time.year mod 100 ) ;
- outs( 60 .. 61 ) := to_str2 ( new_time.month ) ;
- outs( 62 .. 63 ) := to_str2 ( new_time.day ) ;
- outs( 65 .. 66 ) := to_str2 ( new_time.hour ) ;
- outs( 68 .. 69 ) := to_str2 ( new_time.minute ) ;
- end do_line_2 ;
-
- procedure do_line_3 is
- -- Line 3 Format
- -- Columns 6.. 9 " 03 "
- -- Cols 10..61 "Left = nnn Para = nnn Right = nnn Markers = nnn "
- -- Columns 62..69 " "
- -- Column 70 " "
- begin -- do_line_3
- outs( 10 .. 61 ) :=
- "Left = nnn Para = nnn Right = nnn Markers = nnn " ;
- outs( 17 .. 19 ) := to_str3 ( environment.lmargin ) ;
- outs( 29 .. 31 ) := to_str3 ( environment.paramargin ) ;
- outs( 42 .. 44 ) := to_str3 ( environment.rmargin ) ;
- outs( 57 .. 59 ) := to_str3 ( environment.marker_count ) ;
- end do_line_3 ;
-
- procedure do_tabs ( tab_offset : integer ) is
- -- Columns 10..69 Code for Tabs in Positions 1 .. 180
- -- or 181 .. 360
- -- or 361 .. 512
- newpla ,
- whichtab ,
- presnum : integer ;
- add : array ( 0 .. 5 ) of integer ;
- tabpla : integer ;
- begin -- do_tabs
- add(0) := 32 ;
- add(1) := 16 ;
- add(2) := 8 ;
- add(3) := 4 ;
- add(4) := 2 ;
- add(5) := 1 ;
- newpla := 10 ; -- column to start with
- whichtab := 0 ;
- tabpla := tab_offset + 1 ;
- loop
- if whichtab = 0 then
- outs( newpla ) := '@' ;
- end if ;
- case environment.tabline( tabpla ) is
- when tnone => null ;
- when tnormal => outs(newpla) := character'val(
- character'pos( outs(newpla))
- + add(whichtab));
- when tnumber => outs(newpla) := character'val(
- character'pos( outs(newpla))
- + add(whichtab+1));
- end case ;
- whichtab := whichtab + 2 ;
- if whichtab = 6 then
- whichtab := 0 ;
- newpla := newpla + 1 ;
- end if;
- tabpla := tabpla + 1 ;
- exit when ( tabpla > tab_offset + 180 )
- or else ( tabpla > column_position'last ) ;
- end loop ;
- end do_tabs ;
-
- procedure do_line_4 is
- -- Line 4 Format
- -- Columns 6.. 9 " 04 "
- -- Columns 10..69 Code for Tabs in Positions 1 .. 180
- -- Column 70 " "
- begin -- do_line_4
- do_tabs( 0 ) ;
- end do_line_4 ;
-
- procedure do_line_5 is
- -- Line 5 Format
- -- Columns 6.. 9 " 05 "
- -- Columns 10..69 Code for Tabs in Positions 181 .. 360
- -- Column 70 " "
- begin -- do_line_5
- do_tabs(180);
- end do_line_5 ;
-
- procedure do_line_6 is
- -- Line 6 Format
- -- Columns 6.. 9 " 06 "
- -- Columns 10..69 Code for Tabs in Positions 361 .. 512
- -- Column 70 " "
- begin -- do_line_6
- do_tabs(360);
- end do_line_6 ;
-
- procedure do_markers ( marker_num : integer ) is
- -- Line 7 .. Markers + 6 ( if any ) Format
- -- Columns 6..9 " nn "
- -- Columns 10..19 Marker Name
- -- Columns 20..62 " Line Number = nnnnn Column Number = nnn "
- -- Columns 63..69 " "
- -- Column 70 " "
- begin -- do_markers
- outs ( 10 .. 19 ) := environment.markers( marker_num ).name ;
- outs ( 20 .. 62 ) := " Line Number = nnnnn Column Number = nnn " ;
- outs ( 35 .. 39 ) := to_str5(
- environment.markers( marker_num ).location
- .data.line);
- outs ( 59 .. 61 ) := to_str3(
- environment.markers( marker_num ).location
- .data.column);
- end do_markers ;
-
- begin -- convert_header_to_string
- -- we must take an input code and work it
- env_code := env_code + 1 ;
- if env_code - 6 > environment.marker_count then
- env_code := 0 ;
- else
- -- ok, we have to make a line
- outs( 1 .. 5 ) := environment.first_five ;
- for posn in 6 .. 70 loop
- outs( posn ) := ' ' ;
- end loop ;
- outs( 71 .. 75 ) := environment.last_five ;
- set_line_number ;
- case env_code is
- when 1 => do_line_1 ;
- when 2 => do_line_2 ;
- when 3 => do_line_3 ;
- when 4 => do_line_4 ;
- when 5 => do_line_5 ;
- when 6 => do_line_6 ;
- when others => do_markers( env_code - 6 ) ;
- end case;
- end if ;
- new_string := string_to_pstring( outs ) ;
- -- returns something, even if just blank
- end convert_header_to_string ;
-
- function default_header return header is
- working_header : header ;
-
- function cleared_tab_line return a_tab_line is
- working_tab_line : a_tab_line ;
- begin
- for position in 1 .. max_column_number loop
- if position mod 8 = 1 and then
- position > 1 then
- working_tab_line( position ) := tnormal ;
- else
- working_tab_line( position ) := tnone ;
- end if ;
- end loop ;
- return working_tab_line ;
- end cleared_tab_line ;
-
- begin -- default_header
- working_header.filename := blank_file_name ;
- working_header.marker_count := 0 ;
- working_header.autoindent := false ;
- working_header.break_char := '.' ;
- working_header.checkcase := false ;
- working_header.enable_cmds := false ;
- working_header.filling := false ;
- working_header.hyphenate := false ;
- working_header.justify := false ;
- working_header.save_envirn := false ;
- working_header.tokdef := false ;
- working_header.wordprocess := false ;
- working_header.lmargin := 0 ;
- working_header.rmargin := basic_io_system.total_crt_col - 2 ;
- working_header.paramargin := 0 ;
- working_header.created := basic_io_system.clock ;
- working_header.last_used := working_header.created ;
- working_header.first_five := "?????" ;
- working_header.last_five := "?????" ;
- working_header.tabline := cleared_tab_line ;
- return working_header ;
- end default_header ;
-
- procedure users_default_header ( which_header : in out header )
- is
- -- Return the user's default header if one exists, else the standard
- header_file : text_io.file_type ;
- input_string : string ( 1 .. 100 ) ;
- new_string_len : integer ;
- env_code : integer ;
- actual_file_name : ascii_text_file_name ;
- ok : boolean ;
- begin -- users_default_header
- which_header := default_header ;
- sok_to_read( default_environment_file_name , actual_file_name , ok ) ;
- if ok then
- -- OK , the user has specified a default environment
- open_for_read(header_file,actual_file_name,ok);
- if not ok then
- -- File not found, even though our own routine told us that it
- -- really exists.
- text_io.close(header_file);
- else
- -- OK!
- env_code := 0 ;
- loop
- text_io.get_line(header_file,input_string,new_string_len);
- exit when text_io.end_of_file(header_file);
- convert_string_to_header ( input_string( 1 .. new_string_len ) ,
- env_code , which_header , no_buffer );
- exit when ( env_code < 0 ) ;
- end loop ;
- text_io.close(header_file);
- end if ; -- we actually had a file out there
- end if ;
- which_header.created := basic_io_system.clock ;
- which_header.last_used := which_header.created ;
- end users_default_header ;
-
- begin -- environment_input_output
- -- ENVIRNIO by SAIC/Clearwater Environment Input/Output 27 Dec 84
- null ;
- end environment_input_output ;
-
- --$$$- ENVIRNIO
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --buffers
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ BUFFERS
-
- -- File 013
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ;
- with io_exceptions ;
- use io_exceptions ;
-
- with direct_io ;
-
- with string_library ;
- use string_library ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- -- with debugger ;
- -- use debugger ;
-
- with environment_input_output ;
- use environment_input_output ;
-
- with markers ;
- use markers ;
- use text_position_handler ;
- use marker_manager ;
-
- package buffer_package is
-
- package buffer_block_io is
-
- --
- -- Block I/O written to bypass problems with wicat
- -- Written 19 Dec 84 - RSCymbalski
- --
-
- procedure create ( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- successfull : out boolean ) ;
- -- open the file for input and output
-
- procedure close ( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- successfull : out boolean ) ;
- -- close the file
-
- procedure getblock( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- block_of_data: out block ;
- block_number : in integer ;
- successfull : out boolean ) ;
- -- read in a block of data from that file
-
- procedure putblock( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- block_of_data: in block ;
- block_number : in integer ;
- successfull : out boolean ) ;
- -- write a block of data from that file
-
- end buffer_block_io ;
-
- package buffer_general is
-
- procedure move_buffer_area_to_block( which_buffer : an_editor_buffer ;
- start_pos : type_buffer_position ;
- block_of_data: out block ) ;
- -- Move the buffer data starting at start_pos to the block of data
-
- procedure move_block_to_buffer_area( which_buffer:in out an_editor_buffer;
- block_of_data: in block ;
- start_pos : type_buffer_position);
- -- Move the block of data to the buffer at start pos
-
- procedure shift_buffer_area( which_buffer : in out an_editor_buffer;
- source : type_buffer_position ;
- destination : type_buffer_position ;
- length : type_buffer_position ) ;
- -- Shift data in the buffer from the source position to the
- -- destination position, and then continue for length positions
- -- If the destination is to the right of the source, then do it
- -- in the reverse direction!
-
- procedure adjust_cursors( which_buffer : in out an_editor_buffer ;
- amount_added : in integer ) ;
- -- adjust the (4) cursors within a buffer because we have added
- -- or subtracted the specified number of buffer positions.
- -- If any position becomes invalid, mark as line_start = 0
-
- procedure open_buffer( which_buffer : in out an_editor_buffer ;
- line_start : in type_buffer_position ;
- required_area: in integer ) ;
- -- Open an area in the buffer which will facilitate
- -- the addition of at least the required area of
- -- bytes. Start moving text from the line_start specified
-
- procedure close_buffer( which_buffer : in out an_editor_buffer ) ;
- -- Close up the opened area in the buffer
-
- procedure push_data( which_buffer : in out an_editor_buffer ;
- from : in topush ;
- successfull : out boolean ) ;
- -- Push information to thetop or thebot of the file
- -- return true if successfull
-
- procedure pop_data( which_buffer : in out an_editor_buffer ;
- from : in topush ;
- successfull : out boolean ) ;
- -- Pop information from thetop or thebot of the
- -- file, if any exists.
- -- return true if successfull
-
- procedure interpret_string ( in_string : in string ;
- leading_blanks : out type_leading_spaces ;
- first_character: out type_text_length ;
- last_character : out type_text_length ;
- length : out type_line_length ) ;
- -- Take the input string and interpret it by our rules
-
- procedure read_next_line ( which_buffer : in out an_editor_buffer ;
- env_code : in out integer ) ;
- -- Read the next line into an open buffer
- -- the env_code is a code to keep track of the environment
- -- when we are reading it.
-
- end buffer_general ;
-
- package buffer_lines is
-
- buffer_boundry : constant integer := 255 ;
-
- function Line_Length ( which_buffer : in an_editor_buffer ;
- starting_pos : in type_buffer_position )
- return type_line_length ;
- -- Return the line length of the line starting here
-
- function Num_Leading_Spaces ( which_buffer : in an_editor_buffer ;
- starting_pos : in type_buffer_position )
- return type_leading_spaces ;
- -- Return the leading spaces on the line starting here
-
- function num_leading_spaces( which_buffer : in an_editor_buffer ;
- a_cursor : in cursor_position )
- return type_leading_spaces ;
- -- Return leading spaces on the cursor line
-
- procedure get_line_info( which_buffer : in an_editor_buffer ;
- starting_position: in type_buffer_position ;
- leading_spaces : out type_leading_spaces ;
- first_text_position,
- last_text_position:out type_buffer_position ;
- length : out type_line_length );
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Note that this starting position
- -- is a pointer to the starting line length for the line.
- -- The number of leading spaces and pointers to the first
- -- and last characters on the line are returned. Also,
- -- the count of the number of characters is provided.
-
- procedure ot_line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ;
- first_text ,
- last_text : in type_buffer_position );
- -- The buffer is provided, as well as the line
- -- and column to start with when displaying text.
- -- the actual text exists from first_text to
- -- last_text in the buffer. Output it IF it fits
- -- within the current editor window.
-
- procedure ot_line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number;
- Line_Of_Text : in type_text_line ) ;
- -- The buffer is provided, as well as the line
- -- and column to start with when displaying text.
- -- the actual text exists in Line_Of_Text
- -- Output it IF it fits within the current editor window.
- -- Note that we will have to skip the first
- -- spaces (designated by leading_spaces) because they
- -- are already included in the starting screen position
-
- procedure get_text_line( which_buffer : in an_editor_buffer ;
- starting_position: in type_buffer_position ;
- Line_Of_Text : out type_text_line ) ;
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Note that this starting position
- -- is an entity which cannot be manipulated by the caller
- -- The number of leading spaces , the length of the text
- -- in the line, and the actual text line are returned.
-
- procedure show_line( which_buffer : in an_editor_buffer ;
- starting_position : in type_buffer_position ;
- line_number_within_file : in Line_Number ;
- move_to_starting_pos : in boolean := true );
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Also, the actual line number
- -- within the file is sent. This routine sends the text
- -- line to the screen.
-
- procedure show_line( which_buffer : in an_editor_buffer ;
- Line_Of_Text : in type_text_line ;
- line_Number_within_file : in Line_Number ;
- move_to_starting_pos : in boolean := true ) ;
- -- The buffer and the line of text to put on the screen
- -- are provided. Also, the actual line number within the
- -- file is sent. This routine sends the text
- -- line to the screen.
-
- procedure line_forward( which_buffer : in out an_editor_buffer ) ;
- -- The buffer and starting position of the current line
- -- are provided. Returns the starting position of the
- -- line immediately following the old line. If the new
- -- location is the same as the starting position, then
- -- movement was not possible.
- -- moves from fixed_cursor.linestart and sets moving_cursor
-
- procedure line_backward(which_buffer : in out an_editor_buffer ) ;
- -- The buffer and starting position of the current line
- -- are provided. Returns the starting position of the
- -- line immediately before the old line. If the new
- -- location is the same as the starting position, then
- -- movement was not possible.
- -- moves from fixed_cursor.linestart and sets moving_cursor
-
- procedure set_cursor_up_lines ( which_buffer : in out an_editor_buffer ;
- old_cursor : in cursor_position ;
- new_cursor : out cursor_position ;
- lines_up : integer ) ;
-
- procedure set_cursor_down_lines(which_buffer : in out an_editor_buffer ;
- old_cursor : in cursor_position ;
- new_cursor : out cursor_position ;
- lines_down : integer ) ;
-
- procedure put_cursor_on_line ( which_buffer : in out an_editor_buffer ;
- this_line : in window_line_number ) ;
-
- procedure memory_center ( which_buffer : in out an_editor_buffer ;
- new_line_number : in window_line_number := 0 ) ;
- -- center the buffer's cursor in memory so that we can place the
- -- cursor anywhere on the screen and feel safe that we will not run
- -- out of text in memory
-
- function cursor_off_screen ( which_buffer : in an_editor_buffer )
- return boolean ;
-
- end buffer_lines ;
-
- procedure re_initialize ( which_buffer : in out an_editor_buffer ) ;
- -- Do the initialization which is also done each time a buffer
- -- is re_loaded
-
- procedure initialize_buffer( which_buffer : out an_editor_buffer ;
- buffer_number: in a_buffer_number ) ;
- -- Initialize the buffer.
-
- procedure load_file( which_buffer : in out an_editor_buffer ;
- file_to_load : in ascii_text_file_name ) ;
- -- Load the named file into the buffer. We can assume
- -- an empty buffer in this case.
-
- procedure copy_file( which_buffer : in out an_editor_buffer ;
- file_to_copy : in ascii_text_file_name ;
- first_marker : in str10 ;
- last_marker : in str10 ) ;
- -- Copy the named file in at the current position in
- -- which buffer.
-
- procedure dispose_buffer( which_buffer : in out an_editor_buffer ) ;
- -- close a buffer because we are done with it
-
- end buffer_package ;
-
- package body buffer_package is
-
- package body buffer_block_io is
-
- package edit_block_io is new direct_io(block);
-
- type single_buffer_files is array ( topush ) of edit_block_io.file_type ;
-
- buffer_files : array ( a_buffer_number range
- 1 .. max_buffer_number )
- of single_buffer_files ;
-
- procedure create ( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- successfull : out boolean ) is
- -- open the file for input and output
- begin -- create
- edit_block_io.create( buffer_files( which_buffer.buffer_number )
- ( the_file ) ,
- edit_block_io.inout_file);
- successfull := true ;
- exception
- when others => successfull := false ;
- end create ;
-
- procedure close ( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- successfull : out boolean ) is
- -- close the temporary file
- begin -- close
- edit_block_io.close ( buffer_files( which_buffer.buffer_number )
- ( the_file ) ) ;
- successfull := true ;
- exception
- when others => successfull := false ;
- end close ;
-
- procedure getblock( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- block_of_data: out block ;
- block_number : in integer ;
- successfull : out boolean ) is
- -- read in a block of data from that file
- begin -- getblock
- edit_block_io.read( buffer_files( which_buffer.buffer_number )
- ( the_file ) ,
- block_of_data ,
- edit_block_io.positive_count(block_number)) ;
- successfull := true ;
- exception
- when others => successfull := false ;
- end getblock ;
-
- procedure putblock( which_buffer : in out an_editor_buffer ;
- the_file : in topush ;
- block_of_data: in block ;
- block_number : in integer ;
- successfull : out boolean ) is
- -- write a block of data from that file
- wicat_block : block := block_of_data ;
- begin -- putblock
- -- since this crazy wicat does not match the LRM, we must do a
- -- temp variable!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- edit_block_io.write(buffer_files( which_buffer.buffer_number )
- ( the_file ) ,
- wicat_block ,
- edit_block_io.positive_count(block_number)) ;
- successfull := true ;
- exception
- when others => successfull := false ;
- end putblock ;
-
- begin -- buffer_block_io
- -- BUFFBLOK by SAIC/Clearwater Buffer Block I/O 19 Dec 84
- null ;
- end buffer_block_io ;
-
- use buffer_block_io;
-
- package body buffer_general is
-
- procedure move_buffer_area_to_block( which_buffer : an_editor_buffer ;
- start_pos : type_buffer_position ;
- block_of_data: out block ) is
- -- Move the buffer data starting at start_pos to the block of data
- begin -- move_buffer_area_to_block
- for position in 0 .. block_minus loop
- block_of_data( position ) := which_buffer.e_buf( start_pos + position );
- end loop ;
- -- block_of_data ( 0 .. block_minus )
- -- := which_buffer.e_buf( start_pos .. start_pos + block_size - 1 ) ;
- end move_buffer_area_to_block ;
-
- procedure move_block_to_buffer_area( which_buffer:in out an_editor_buffer;
- block_of_data: in block ;
- start_pos :type_buffer_position) is
- -- Move the block of data to the buffer at start pos
- begin -- move_block_to_buffer_area
- for position in 0 .. block_minus loop
- which_buffer.e_buf( start_pos + position ):= block_of_data(position);
- end loop ;
- -- which_buffer.e_buf( start_pos .. start_pos + block_size - 1 )
- -- := block_of_data ( 0 .. block_minus ) ;
- end move_block_to_buffer_area ;
-
- procedure shift_buffer_area( which_buffer : in out an_editor_buffer;
- source : type_buffer_position ;
- destination : type_buffer_position ;
- length : type_buffer_position ) is
- -- Shift data in the buffer from the source position to the
- -- destination position, and then continue for length positions
- -- If the destination is to the right of the source, then do it
- -- in the reverse direction!
- begin -- shift_buffer_area
- if length > 0 then
- if source > destination then
- -- we are moving left
- for counter in 0 .. length - 1 loop
- which_buffer.e_buf( destination + counter )
- := which_buffer.e_buf( source + counter ) ;
- end loop ;
- else
- -- either a no-op if identical, or move right
- for counter in reverse 0 .. length - 1 loop
- which_buffer.e_buf( destination + counter )
- := which_buffer.e_buf( source + counter ) ;
- end loop ;
- end if ;
- end if ;
- end shift_buffer_area ;
-
- procedure adjust_cursors( which_buffer : in out an_editor_buffer ;
- amount_added : in integer ) is
- -- adjust the (4) cursors within a buffer because we have added
- -- or subtracted the specified number of buffer positions.
- -- If any position becomes invalid, mark as line_start = 0
- lowest_position : constant type_buffer_position := 1 ;
- highest_position : type_buffer_position ;
-
- procedure adjust ( cursor : in out cursor_position ) is
- new_position : integer ;
- begin
- cursor.buffer_position := 0 ;
- if cursor.line_start /= 0 then
- -- we only work it if it is not a zero....
- new_position := cursor.line_start + amount_added ;
- if ( new_position >= lowest_position )
- and then ( new_position <= highest_position ) then
- cursor.line_start := new_position ;
- else
- cursor.line_start := 0 ;
- end if ;
- end if ;
- end;
-
- begin -- adjust_cursors
- -- work with : which_buffer.fixed_cursor
- -- .floating_cursor
- -- .moving_cursor
- -- .top_screen_cursor
- -- .next_screen_cursor
- -- each has .buffer_position : type_buffer_position
- -- .file_line_number : line_number
- -- .line_start : type_buffer_position
- -- .column_offset : column_position
- --
- -- text_io.put("<");
- if which_buffer.open_buffer_area then
- -- we are only working within the first half of the buffer
- highest_position := which_buffer.first_open_position - 1;
- else
- highest_position := which_buffer.bufcount ;
- end if ;
- adjust( which_buffer.fixed_cursor ) ;
- adjust( which_buffer.floating_cursor ) ;
- adjust( which_buffer.moving_cursor ) ;
- adjust( which_buffer.top_screen_cursor ) ;
- adjust( which_buffer.next_screen_cursor ) ;
- -- if ( which_buffer.top_screen_cursor.line_start = 0 ) then
- -- which_buffer.next_screen_cursor.line_start := 0 ;
- -- end if ; -- just in case
- -- text_io.put(">");
- end adjust_cursors ;
-
- procedure open_buffer( which_buffer : in out an_editor_buffer ;
- line_start : in type_buffer_position ;
- required_area: in integer ) is
- -- Open an area in the buffer which will facilitate
- -- the addition of at least the required area of
- -- bytes. Start moving text from the line_start specified
- successfull : boolean := true ;
- positions_to_move : integer ;
- move_to : type_buffer_position ;
- final_line_start : type_buffer_position ;
- begin -- open_buffer
- -- The Physical Buffer is defined from 0 .. Max_Buffer_Size
- -- Actual Data resides in buffer from 1 .. which_buffer.bufcount
- -- 1st Step: Empty The buffer enough to make the required area open
- final_line_start := line_start ;
- loop
- exit when max_buffer_size - which_buffer.bufcount > required_area ;
- if final_line_start < which_buffer.bufcount - block_size then
- -- we want to push from the bottom
- push_data( which_buffer , thebot , successfull ) ;
- exit when not successfull ;
- else
- exit when final_line_start <= block_size ;
- push_data( which_buffer , thetop , successfull ) ;
- exit when not successfull ;
- final_line_start := final_line_start - block_size ;
- end if ;
- end loop ;
- -- 2nd Step: Open the buffer
- positions_to_move := which_buffer.bufcount - final_line_start + 1 ;
- move_to := max_buffer_size - positions_to_move + 1 ;
- shift_buffer_area( which_buffer , final_line_start , move_to ,
- positions_to_move ) ;
- -- 3rd Step: Set The actual values
- which_buffer.open_buffer_area := true ;
- which_buffer.first_open_position:= final_line_start ;
- which_buffer.last_open_position := move_to - 1 ;
- which_buffer.bufcount := max_buffer_size ;
- if not successfull then
- error("Unable To Correctly Read/Write Temporary Files.",
- not_fatal_error,operator_wait,medium_beep);
- end if ;
- end open_buffer ;
-
- procedure close_buffer( which_buffer : in out an_editor_buffer ) is
- -- Close up the opened area in the buffer
- positions_to_move : integer ;
- begin -- close_buffer
- positions_to_move := which_buffer.bufcount
- - which_buffer.last_open_position ;
- shift_buffer_area( which_buffer , which_buffer.last_open_position + 1 ,
- which_buffer.first_open_position ,
- positions_to_move ) ;
- which_buffer.open_buffer_area := false ;
- which_buffer.bufcount := which_buffer.first_open_position - 1
- + positions_to_move ;
- end close_buffer ;
-
- procedure push_data( which_buffer : in out an_editor_buffer ;
- from : in topush ;
- successfull : out boolean ) is
- -- Push information to thetop or thebot of the file
- -- return true if successfull
- last_move_position : type_buffer_position ;
- first_move_position: type_buffer_position ;
- positions_to_move : type_buffer_position ;
- block_of_data : block ;
- new_block : integer ;
- temp_successfull : boolean := false ;
- begin -- push_data
- successfull := false ;
- if from = thetop then
- -- text_io.put("[Push Top #");
-
- -- Push a block of text from the beginning of the text buffer onto
- -- a stack of blocks
- -- First, make sure we have room
- if which_buffer.open_buffer_area then
- -- we are pushing while the buffer is open.
- last_move_position := which_buffer.first_open_position - 1 ;
- -- That is the last character position to move after push
- else
- -- the buffer is not open
- last_move_position := which_buffer.bufcount ;
- end if ;
- if block_size <= last_move_position then
- -- we are here when the size of a block ( 1024 ) is less than
- -- the number of characters available to push so that
- -- we definitely have 1024 characters we are prepared to push
- new_block := which_buffer.prestopblock + 1 ;
- -- We increment to the next top block to write. We start with
- -- prestopblock set to 0, and the first written block is numbered
- -- #1
- move_buffer_area_to_block( which_buffer , 1 , block_of_data ) ;
-
- putblock( which_buffer , thetop , block_of_data , new_block ,
- temp_successfull );
- if temp_successfull then
- -- here if the block is put correctly...
- -- text_io.put(" ok ");
- which_buffer.prestopblock := new_block ;
- positions_to_move := last_move_position - block_size ;
- shift_buffer_area( which_buffer , block_size + 1 , 1 ,
- positions_to_move ) ;
- -- shifts within which_buffer, from block_size + 1 to
- -- position 1. Positions_to_move Positions
- if which_buffer.open_buffer_area then
- -- we are pushing while the buffer is open.
- -- last_move_position := which_buffer.first_open_position - 1 ;
- -- That is the last character position to move after push
- which_buffer.first_open_position
- := which_buffer.first_open_position - block_size ;
- else
- -- the buffer is not open
- -- last_move_position := which_buffer.bufcount
- which_buffer.bufcount := which_buffer.bufcount - block_size ;
- end if ;
- -- Now, is there anything else to do? Yes. We must reset the
- -- cursor offset.
- adjust_cursors( which_buffer , - block_size ) ;
- -- else -- cannot write block out
- end if;
- -- else -- don't have enough stuff to be able to push
- end if ; -- we had or did not have enough data to move
-
- else
-
- -- text_io.put("[Push Bot #");
- -- Push a block of text from the end of the text buffer onto
- -- a stack of blocks
- -- First, make sure we have room
- if which_buffer.open_buffer_area then
- -- we are pushing while the buffer is open.
- first_move_position := which_buffer.last_open_position + 1 ;
- -- That is the last character position to move after push
- else
- -- the buffer is not open
- first_move_position := 1 ;
- end if ;
- if block_size <= which_buffer.bufcount - first_move_position + 1 then
- -- we are here when the size of a block ( 1024 ) is less than
- -- the number of characters available to push so that
- -- we definitely have 1024 characters we are prepared to push
- new_block := which_buffer.presbotblock + 1 ;
- -- We increment to the next top block to write. We start with
- -- prestopblock set to 0, and the first written block is numbered
- -- #1
- move_buffer_area_to_block( which_buffer ,
- which_buffer.bufcount - block_size + 1 ,
- block_of_data ) ;
- putblock( which_buffer , thebot , block_of_data , new_block ,
- temp_successfull );
- if temp_successfull then
- -- here if the block is put correctly...
- -- text_io.put(" ok ");
- which_buffer.presbotblock := new_block ;
- if which_buffer.open_buffer_area then
- -- we are pushing while the buffer is open.
- which_buffer.last_open_position
- := which_buffer.last_open_position + block_size ;
- positions_to_move := which_buffer.bufcount
- - first_move_position + 1
- - block_size ;
- shift_buffer_area(which_buffer,first_move_position ,
- first_move_position + block_size,
- positions_to_move ) ;
- -- shifts within which_buffer, towards the end of the buffer
- else
- -- the buffer is not open
- -- first_move_position := which_buffer.bufcount
- which_buffer.bufcount := which_buffer.bufcount - block_size ;
- end if ;
- -- Now, is there anything else to do? Yes. We must reset the
- -- cursor offset.
- -- Since the cursor cannot be in the second part, skip it
- -- else -- cannot write block out
- end if;
- -- else -- don't have enough stuff to be able to push
- end if ; -- we had or did not have enough data to move
-
- end if ;
- -- text_io.put(" PushEnd]");
- successfull := temp_successfull ;
- end push_data ;
-
- procedure pop_data( which_buffer : in out an_editor_buffer ;
- from : in topush ;
- successfull : out boolean ) is
- -- Pop information from thetop or thebot of the
- -- file, if any exists.
- -- return true if successfull
- block_of_data : block ;
- highest_position : type_buffer_position ;
- need_to_push : boolean ;
- temp_successfull : boolean := false ;
-
- procedure read_new_data is
- garbage : integer := -1 ;
- begin -- read_new_data
- open_buffer( which_buffer , which_buffer.bufcount
- , block_size + max_bytes_in_line
- + max_bytes_in_line );
- -- open up the buffer and guarantee us that we will have room
- -- to read in an entire block ( and since it is not exact , we
- -- might have up to two extra lines
- -- we will end when open area is <= 2 * max_bytes_in_line
- loop
- read_next_line ( which_buffer , garbage ) ;
- exit when not which_buffer.still_reading_input_file ;
- exit when which_buffer.last_open_position
- - which_buffer.first_open_position + 1 <= max_bytes_in_line
- + max_bytes_in_line ;
- end loop ;
- close_buffer(which_buffer);
- end read_new_data ;
-
- begin -- pop_data
- if ( ( from = thetop ) and ( which_buffer.prestopblock > 0 ) )
- or ( ( from = thebot ) and ( ( which_buffer.presbotblock > 0 )
- or which_buffer.still_reading_input_file ) )
- then
- -- We are here and know that we must do something
- -- First, make some room if necessary
- -- put(" Pop The ");
- -- if from = thetop then
- -- put("TOP");
- -- else
- -- put("BOT");
- -- end if ;
- if which_buffer.open_buffer_area then
- -- we are only working within the first half of the buffer
- highest_position := which_buffer.first_open_position - 1;
- need_to_push := false ; -- if we opened buffer, must have planned
- -- for this call...
- else
- highest_position := which_buffer.bufcount ;
- need_to_push := highest_position + block_size > max_buffer_size ;
- end if ;
- if need_to_push then
- -- we need to push something.
- if from = thetop then
- push_data( which_buffer , thebot , temp_successfull ) ;
- else
- push_data( which_buffer , thetop , temp_successfull ) ;
- end if ;
- -- if temp_successfull then
- -- text_io.put("Psh");
- -- else
- -- text_io.put("NoPsh");
- -- end if ;
- if not temp_successfull then
- successfull := false ;
- return ;
- end if ;
- end if ;
- -- text_io.put("?");
- temp_successfull := true ;
- if from = thetop then
- -- must pop from the front of the file, and we know something is there
- -- we have put info out to the file, and it is waiting for us
- -- here with a block ready to be read and enough room to read it
- -- put( which_buffer.prestopblock , 4 ) ;
- getblock( which_buffer , thetop , block_of_data ,
- which_buffer.prestopblock , temp_successfull ) ;
- if temp_successfull then
- -- now, we actually have the block, too!
- which_buffer.prestopblock := which_buffer.prestopblock - 1 ;
- if which_buffer.open_buffer_area then
- -- we are only working within the first half of the buffer
- highest_position := which_buffer.first_open_position - 1;
- else
- highest_position := which_buffer.bufcount ;
- end if ;
- shift_buffer_area( which_buffer , 1 , block_size + 1 ,
- highest_position );
- if which_buffer.open_buffer_area then
- -- we are popping while the buffer is open.
- which_buffer.first_open_position
- := which_buffer.first_open_position + block_size ;
- else
- -- the buffer is not open
- which_buffer.bufcount := which_buffer.bufcount + block_size ;
- end if ;
- move_block_to_buffer_area ( which_buffer , block_of_data , 1 ) ;
- adjust_cursors( which_buffer , block_size ) ;
- -- else
- -- put(" HELP>>>>>>>>>>>>>");
- -- else -- not successfull getting block
- end if ; -- successfull in reading block ;
- -- we had a top block to read
- -- put("Done");
- else
- -- and from = thebot
- -- must pop from the end of the file
- if which_buffer.presbotblock > 0 then
- -- we have put info out to the file, and it is waiting for us
- -- here with a block ready to be read and enough room to read it
- getblock( which_buffer , thebot , block_of_data ,
- which_buffer.presbotblock , temp_successfull ) ;
- if temp_successfull then
- -- now, we actually have the block, too!
- which_buffer.presbotblock := which_buffer.presbotblock - 1 ;
- -- for now, we do not call pop_data when the buffer is open
- -- with a thebot parameter
- move_block_to_buffer_area ( which_buffer , block_of_data ,
- which_buffer.bufcount + 1 ) ;
- which_buffer.bufcount := which_buffer.bufcount + block_size ;
- end if ; -- successfull in reading block ;
- else
- -- here if we had no bottom block, but might be in the middle
- read_new_data ;
- end if ; -- working a still open input file
- end if ; -- reading from the bottom of the file
- else
- temp_successfull := true ; -- because we didn't need to do anything
- end if ; -- we had something out there to actually read
- -- text_io.put("EndPop");
- successfull := temp_successfull ;
- end pop_data ;
-
- procedure interpret_string ( in_string : in string ;
- leading_blanks : out type_leading_spaces ;
- first_character: out type_text_length ;
- last_character : out type_text_length ;
- length : out type_line_length ) is
- -- Take the input string and interpret it by our rules
- in_place : integer ;
- done : boolean ;
- blanks ,
- first_c ,
- last_c ,
- len : integer ;
- an_error : boolean ;
- temp_first_character : type_text_length ;
- temp_last_character : type_text_length ;
- temp_length : type_line_length ;
- begin -- interpret_string
- blanks := 0 ;
- in_place := 0 ;
- done := false ;
- an_error := false ;
- while ( in_place < in_string'length )
- and ( not done ) loop
- in_place := in_place + 1 ;
- case in_string(in_place) is
- when ' ' => blanks := blanks + 1 ;
- when ascii.dle => if in_place < in_string'length then
- in_place := in_place + 1 ;
- if in_string( in_place ) >= ' ' then
- blanks := blanks +
- character'pos( in_string(in_place) ) -
- character'pos( ' ' ) ;
- end if ;
- end if ;
- when ascii.ht => blanks := ( ( blanks / 8 )
- + 1 ) * 8 ;
- -- 0 .. 7 change to 8
- -- 8 ..15 change to 16
- when others => done := true ;
- end case ;
- end loop ;
- -- we are here with in_place set to the last character processed
- if in_place <= in_string'length then
- first_c := in_place ;
- last_c := in_string'length ;
- if done then
- len := last_c - in_place + 1 ;
- else
- len := 0 ;
- end if ;
- else
- first_c := 0 ;
- last_c := 0 ;
- len := 0 ;
- end if ;
- -- Finally, check for errors
- if blanks <= max_leading_spaces then
- leading_blanks := blanks ;
- else
- leading_blanks := max_leading_spaces ;
- an_error := true ;
- end if ;
- if len <= max_line_length then
- temp_length := len ;
- else
- temp_length := max_line_length ;
- an_error := true ;
- end if ;
- if first_c <= max_column_number then
- temp_first_character := first_c ;
- else
- temp_first_character := max_column_number ;
- an_error := true ;
- end if ;
- if last_c <= max_column_number then
- temp_last_character := last_c ;
- else
- temp_last_character := max_column_number ;
- an_error := true ;
- end if ;
- if an_error then
- -- might need to fix last_character
- if temp_last_character = max_column_number then
- temp_first_character := temp_last_character - temp_length + 1 ;
- elsif temp_first_character + temp_length > max_column_number then
- temp_last_character := max_column_number ;
- temp_first_character := temp_last_character - temp_length + 1 ;
- else
- temp_last_character := temp_first_character + temp_length - 1 ;
- end if ;
- error(" Input line has too many spaces or characters." ,
- not_fatal_error , operator_wait , short_beep ) ;
- end if ;
- first_character := temp_first_character ;
- last_character := temp_last_character ;
- length := temp_length ;
- end interpret_string ;
-
- procedure read_next_line ( which_buffer : in out an_editor_buffer ;
- env_code : in out integer ) is
- -- Read the next line into an open buffer
- input_string : string ( 1 .. max_column_number ) ;
- new_string_len : integer ;
- leading_blanks : type_leading_spaces ;
- first_char ,
- last_char : type_text_length ;
- length : type_line_length ;
- ln_start : type_buffer_position ;
- old_env_code : integer ;
- begin -- read_next_line
- text_io.get_line(which_buffer.inputfile,input_string,new_string_len);
- if ( not text_io.end_of_file(which_buffer.inputfile) )
- or else ( new_string_len > 0 ) then
- if env_code >= 0 then
- -- we must check for an environment line
- old_env_code := env_code ;
- if new_string_len > 0 then
- convert_string_to_header( input_string(1..new_string_len) ,
- env_code , which_buffer.pagezero ,
- which_buffer );
- if env_code > 0 then
- new_string_len := 0 ;
- end if ;
- else
- env_code := -1 ;
- end if ;
- if ( old_env_code = 0 ) and then ( env_code < 0 ) then
- -- no environment found, look for user's environment
- users_default_header(which_buffer.pagezero) ;
- end if ;
- end if ;
- if env_code < 0 then
- -- we must work the string because it was not an env string
- interpret_string(input_string(1..new_string_len),
- leading_blanks,first_char,
- last_char , length ) ;
- ln_start := which_buffer.first_open_position ;
- which_buffer.e_buf(ln_start).data := extended_character(length) ;
- which_buffer.e_buf(ln_start+1 ).data :=
- extended_character(leading_blanks) ;
- for place in 1 .. length loop
- which_buffer.e_buf(ln_start + 1 + place ).data :=
- extended_character(
- character'pos(input_string( first_char + place - 1 ) ));
- end loop ;
- which_buffer.e_buf(ln_start + length + 2 ).data :=
- extended_character(length) ;
- which_buffer.first_open_position
- := which_buffer.first_open_position + length + 3 ;
- for place in ln_start .. ln_start + length + 2 loop
- which_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- end if ;
- else
- -- empty line.....
- if env_code = 0 then
- -- empty file
- -- no data anywhere
- users_default_header(which_buffer.pagezero) ;
- env_code := -1 ;
- end if ;
- end if ;
- if text_io.end_of_file(which_buffer.inputfile) then
- if new_string_len = 0 then
- -- need to adjust the buffer
- -- end_of_file with no data on last line
- -- Put in blank line area for working then...
- -- which is <0><0><0>
- for posn in which_buffer.last_open_position - 2 ..
- which_buffer.last_open_position loop
- which_buffer.e_buf(posn) :=
- ( extended_character(0) , no_screen_attribute ) ;
- end loop ;
- which_buffer.last_open_position:=which_buffer.last_open_position - 3;
- end if ;
- which_buffer.still_reading_input_file := false ;
- text_io.close(which_buffer.inputfile);
- end if;
- exception
- when end_error => -- this is for a telesoft bug....
- for posn in which_buffer.last_open_position - 2 ..
- which_buffer.last_open_position loop
- which_buffer.e_buf(posn) :=
- ( extended_character(0) , no_screen_attribute ) ;
- end loop ;
- which_buffer.last_open_position
- := which_buffer.last_open_position - 3;
- which_buffer.still_reading_input_file := false ;
- text_io.close(which_buffer.inputfile);
- end read_next_line ;
-
- begin -- buffer_general
- -- BUFFERGN by SAIC/Clearwater General Buffer Routines 23 Jan 85
- null ;
- end buffer_general ;
-
- use buffer_general ;
-
- package body buffer_lines is
-
- -- Text Buffer Layout Description...
- --
- -- The text buffer has a very special format. If corrupted, it
- -- can become impossible for the editor to recover. Therefore,
- -- text buffer manipulation should NOT be attempted by any routines
- -- other than those currently sitting in the buffer package.
- --
- -- The text buffer is an array ( 1 .. max_buffer_size ) which
- -- contains the following when initialized:
- --
- -- <255> Buffer Start Flag
- -- <0><0><0> Line Length / No Leading Spaces / Line Length
- -- <255> Buffer End Flag
- --
- --
- -- <Prior Editing Buffer> Pointed to by prior_buffer_number
- -- <Top File> Blocks of text saved on disk
- -- <E_buf> Text which can be manipulated
- -- <Bottom File> Blocks of text saved on disk
- -- <Input File> Input Text not yet read
- -- <Following Editing Buffer> Pointed to by following_buffer_number
- --
-
- function Line_Length ( which_buffer : in an_editor_buffer ;
- starting_pos : in type_buffer_position )
- return type_line_length is
- -- Return the line length of the line starting here
- begin -- line_length
- return type_line_length( which_buffer.e_buf(starting_pos).data ) ;
- end line_length ;
-
- function Num_Leading_Spaces ( which_buffer : in an_editor_buffer ;
- starting_pos : in type_buffer_position )
- return type_leading_spaces is
- -- Return the leading spaces on the line starting here
- begin -- num_leading_spaces
- return type_leading_spaces( which_buffer.e_buf( starting_pos + 1 )
- .data ) ;
- end num_leading_spaces ;
-
- function num_leading_spaces( which_buffer : in an_editor_buffer ;
- a_cursor : in cursor_position )
- return type_leading_spaces is
- -- Return leading spaces on the cursor line
- begin -- num_leading_spaces
- return type_leading_spaces(which_buffer.e_buf(a_cursor.line_start + 1)
- .data );
- end num_leading_spaces ;
-
- procedure get_line_info( which_buffer : in an_editor_buffer ;
- starting_position: in type_buffer_position ;
- leading_spaces : out type_leading_spaces ;
- first_text_position,
- last_text_position:out type_buffer_position ;
- length : out Type_Line_Length ) is
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Note that this starting position
- -- is a pointer to the starting line length for the line.
- -- The number of leading spaces and pointers to the first
- -- and last characters on the line are returned. Also,
- -- the count of the number of characters is provided.
- temp_length : type_line_length ;
- begin
- temp_length := line_length(which_buffer,starting_position);
- -- the length of the current line is at the current position
- if temp_length = buffer_boundry then
- -- we are sitting at the starting or ending boundry
- leading_spaces := 0 ;
- first_text_position := 0 ;
- last_text_position := 0 ;
- length := 0 ;
- else
- leading_spaces := Num_leading_spaces(which_buffer,starting_position);
- first_text_position := starting_position + 2 ;
- last_text_position := starting_position + temp_length + 1 ;
- length := temp_length ;
- end if ;
- end get_line_info ;
-
- procedure ot_line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number ;
- first_text ,
- last_text : in type_buffer_position ) is
- -- The buffer is provided, as well as the line
- -- and column to start with when displaying text.
- -- the actual text exists from first_text to
- -- last_text in the buffer. Output it IF it fits
- -- within the current editor window.
- final_first_text: type_buffer_position ;
- final_last_text : type_buffer_position ;
- final_column : window_column_number ;
- last_possible_line : window_line_number := window_height(which_buffer);
- first_possible_col : window_column_number:=lowest_column_number
- (which_buffer);
- last_possible_col : window_column_number:=highest_column_number
- (which_buffer);
- begin
- if line > last_possible_line then
- null ; -- we are past the end of the window.
- elsif column > last_possible_col then
- -- we are past the right edge of the screen
- if line = 0 then
- -- we must be at the first text position on the last line
- goto_line_column ( which_buffer , last_possible_line ,
- last_possible_col ) ;
- else
- goto_line_column( which_buffer , line , last_possible_col ) ;
- end if ;
- set_reverse( which_buffer.e_buf( first_text ).attr = inverse_video ) ;
- put('!');
- else
- -- Now, check to skip leading characters if columns_over /= 0
- if column < first_possible_col then
- -- some leading text will have to go.
- final_first_text := first_text + first_possible_col - column ;
- final_column := first_possible_col ;
- if final_first_text > last_text then
- goto_line_column( which_buffer , line , first_possible_col ) ;
- put('!');
- return;
- end if;
- else
- final_first_text := first_text ;
- final_column := column ;
- end if ;
- -- Now check to truncate the line because it is too long.
- if ( line = last_possible_line )
- or ( line = 0 ) then
- -- line as zero means do whatever line we are on...
- last_possible_col := last_possible_col - 1 ;
- end if ;
- if final_column + last_text - final_first_text > last_possible_col then
- final_last_text := final_first_text + last_possible_col
- - final_column - 1 ;
- -- Minus 1 because we will put a '!' out there
- else
- final_last_text := last_text ;
- end if ;
- if line = 0 then
- goto_line_column( which_buffer , last_possible_line , final_column);
- else
- goto_line_column( which_buffer , line , final_column );
- end if ;
- for text_pos in final_first_text .. final_last_text loop
- put( which_buffer.e_buf( text_pos ) );
- end loop;
- if last_text /= final_last_text then
- put('!');
- end if;
- end if;
- end ot_line ;
-
- procedure ot_line( which_buffer : in an_editor_buffer ;
- line : in window_line_number ;
- column : in window_column_number;
- Line_Of_Text : in type_text_line ) is
- -- The buffer is provided, as well as the line
- -- and column to start with when displaying text.
- -- the actual text exists in Line_Of_Text
- -- Output it IF it fits within the current editor window.
- -- Note that we will have to skip the first
- -- spaces (designated by leading_spaces) because they
- -- are already included in the starting screen position
- first_text : type_text_length ;
- last_text : type_text_length ;
- final_last_text : type_text_length ;
- final_column : window_column_number ;
- begin -- ot_line
- set_reverse(false);
- if line > window_height(which_buffer) then
- null ; -- we are past the end of the window.
- elsif column > highest_column_number(which_buffer) then
- -- we are past the right edge of the screen
- if line = 0 then
- goto_line_column ( which_buffer , window_height(which_buffer),
- highest_column_number(which_buffer) ) ;
- else
- goto_line_column( which_buffer , line ,
- highest_column_number(which_buffer) ) ;
- end if ;
- put('!');
- else
- first_text := line_of_text.leading_spaces + 1 ;
- last_text := line_of_text.data_length ;
- -- Now, check to skip leading characters if columns_over /= 0
- if column < lowest_column_number(which_buffer) then
- -- some leading text will have to go.
- first_text := first_text
- + lowest_column_number(which_buffer) - column ;
- final_column := lowest_column_number(which_buffer) ;
- if first_text > last_text then
- return;
- end if;
- else
- final_column := column ;
- end if ;
- -- Now check to truncate the line because it is too long.
- if final_column + last_text - first_text
- > highest_column_number(which_buffer) then
- final_last_text := first_text + highest_column_number(which_buffer)
- - final_column - 1 ;
- -- Minus 1 because we will put a '!' out there
- else
- final_last_text := last_text ;
- end if ;
- if line = 0 then
- goto_line_column( which_buffer , window_height(which_buffer) ,
- final_column );
- else
- goto_line_column( which_buffer , line , final_column );
- end if ;
- for text_pos in first_text .. final_last_text loop
- put( character'val(line_of_text.data(text_pos)) ) ;
- end loop;
- if last_text /= final_last_text then
- put('!');
- end if;
- end if;
- end ot_line ;
-
- procedure get_text_line( which_buffer : in an_editor_buffer ;
- starting_position: in type_buffer_position ;
- Line_Of_Text : out type_text_line ) is
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Note that this starting position
- -- is an entity which cannot be manipulated by the caller
- -- The number of leading spaces , the length of the text
- -- in the line, and the actual text line are returned.
- -- Note that the line_of_text.data actually includes the
- -- leading_spaces leading spaces.
- spaces : type_leading_spaces ;
- length : type_line_length ;
- first_text_position,
- last_text_position : type_buffer_position ;
- temp_line_of_text : type_text_line ;
- begin
- length := line_length(which_buffer,starting_position);
- -- the length of the current line is at the current position
- if length = buffer_boundry then
- -- we are sitting at the starting or ending boundry
- temp_line_of_text.leading_spaces := 0 ;
- temp_line_of_text.data_length := 0 ;
- else
- spaces := num_leading_spaces(which_buffer,starting_position);
- temp_line_of_text.leading_spaces := spaces ;
- temp_line_of_text.data_length := length +
- temp_line_of_text.leading_spaces ;
- if spaces > 0 then
- for a_space in 1 .. spaces loop
- temp_line_of_text.data(a_space):=
- extended_character(character'pos(' ')) ;
- end loop ;
- end if ;
- if length > 0 then
- for character_pos in 1 .. length loop
- temp_line_of_text.data( spaces + character_pos )
- := which_buffer.e_buf( starting_position + 1 + character_pos )
- .data ;
- end loop ;
- end if;
- end if ;
- line_of_text := temp_line_of_text ;
- end get_text_line ;
-
- procedure show_line( which_buffer : in an_editor_buffer ;
- starting_position : in type_buffer_position ;
- line_number_within_file : in Line_Number ;
- move_to_starting_pos : in boolean := true ) is
- -- The buffer and a pointer to the current line's starting
- -- position are provided. Also, the actual line number
- -- within the file is sent. This routine sends the text
- -- line to the screen.
- spaces : type_leading_spaces ;
- first_text : type_buffer_position ;
- last_text : type_buffer_position ;
- length : Type_line_Length ;
- window_line : window_line_number ;
- begin
- get_line_info(which_buffer,starting_position,spaces,first_text,
- last_text,length);
- if first_text = 0 then -- No text
- return ; -- so we don't do anything.
- end if;
- -- We get here with spaces, first_text, and last_text set
- if move_to_starting_pos then
- window_line := line_number_within_file
- - which_buffer.top_screen_cursor.file_line_number + 1 ;
- ot_line(which_buffer,window_line, spaces + 1 ,first_text,last_text);
- else
- ot_line( which_buffer , 0 , spaces + 1 , first_text , last_text );
- end if ;
- end show_line ;
-
- procedure show_line( which_buffer : in an_editor_buffer ;
- Line_Of_Text : in type_text_line ;
- line_number_within_file : in Line_Number ;
- move_to_starting_pos : in boolean := true ) is
- -- The buffer and the line of text to put on the screen
- -- are provided. Also, the actual line number within the
- -- file is sent. This routine sends the text
- -- line to the screen.
- window_line : window_line_number ;
- begin
- if move_to_starting_pos then
- window_line := line_number_within_file
- - which_buffer.top_screen_cursor.file_line_number + 1 ;
- ot_line(which_buffer,window_line, 1 ,line_of_text);
- else
- ot_line( which_buffer , 0 , 1 , line_of_text );
- end if ;
- end show_line ;
-
- procedure line_forward( which_buffer : in out an_editor_buffer ) is
- -- The buffer and starting position of the current line
- -- are provided. Returns the starting position of the
- -- line immediately following the old line. If the new
- -- location is the same as the starting position, then
- -- movement was not possible.
- -- moves from fixed_cursor.linestart and sets moving_cursor
- ending_position : type_buffer_position ;
- successfull : boolean ;
- begin -- line_forward
- if which_buffer.open_buffer_area then
- -- we might hit the end of an open area....
- which_buffer.e_buf(which_buffer.first_open_position)
- := ( buffer_boundry , no_screen_attribute ) ;
- end if ;
- if which_buffer.fixed_cursor.line_start + max_bytes_in_line
- >= which_buffer.bufcount - max_bytes_in_line then
- -- used to subtract screen_size from bufcount (not maxbytes)
- -- If the possible starting position of the
- -- next line (which can be the current position
- -- plus the maximum number of bytes in a line)
- -- is closer to the end of the buffer than a
- -- screen size, then bump to the end
- pop_data( which_buffer , thebot , successfull ) ;
- -- Get data from bottom of file
- if not successfull then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- return ;
- end if ;
- end if ;
- ending_position :=
- which_buffer.fixed_cursor.line_start + line_length(
- which_buffer , which_buffer.fixed_cursor.line_start ) + 3 ;
- -- Move from the starting position, over the number
- -- of text bytes in this line, and then over the
- -- current and ending length bytes
- if which_buffer.e_buf(ending_position).data = buffer_boundry then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- else
- which_buffer.moving_cursor.line_start := ending_position ;
- which_buffer.moving_cursor.file_line_number :=
- which_buffer.fixed_cursor.file_line_number + 1 ;
- which_buffer.moving_cursor.buffer_position := 0 ;
- which_buffer.moving_cursor.column_offset := 0 ;
- end if;
- end line_forward ;
-
- procedure line_backward(which_buffer : in out an_editor_buffer ) is
- -- The buffer and starting position of the current line
- -- are provided. Returns the starting position of the
- -- line immediately before the old line. If the new
- -- location is the same as the starting position, then
- -- movement was not possible.
- -- moves from fixed_cursor.linestart and sets moving_cursor
- successfull : boolean ;
- a_position : type_buffer_position ;
- begin -- line_backward
- if which_buffer.fixed_cursor.line_start
- < max_bytes_in_line + max_bytes_in_line then
- -- screen_size + max_bytes_in_line then
- -- If the possible starting position of the
- -- next line (which can be the current position
- -- plus the maximum number of bytes in a line)
- -- is closer to the end of the buffer than a
- -- screen size, then bump to the end
- pop_data( which_buffer , thetop , successfull ) ;
- -- Get data from bottom of file
- if not successfull then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- return ;
- end if ;
- end if ;
- a_position := which_buffer.fixed_cursor.line_start ;
- if which_buffer.e_buf(a_position - 1 ).data = buffer_boundry then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- else
- which_buffer.moving_cursor.line_start := a_position
- - line_length( which_buffer , a_position-1 ) - 3 ;
- -- Move from the starting position, over the number
- -- of text bytes in the previous line, and then over
- -- the current and ending length bytes
- which_buffer.moving_cursor.file_line_number :=
- which_buffer.fixed_cursor.file_line_number - 1 ;
- which_buffer.moving_cursor.buffer_position := 0 ;
- which_buffer.moving_cursor.column_offset := 0 ;
- end if ;
- end line_backward ;
-
- function cursor_off_screen ( which_buffer : in an_editor_buffer )
- return boolean is
- begin -- cursor_off_screen
- if ( which_buffer.top_screen_cursor.line_start = 0 ) then
- -- or else ( which_buffer.next_screen_cursor.line_start = 0 ) then
- -- we have moved around too much to even find out where we are.
- -- must completely redraw screen
- return true ;
- -- This all depends upon having the right sized buffer!!!!
- elsif which_buffer.fixed_cursor.column_offset
- < lowest_column_number(which_buffer)
- or which_buffer.fixed_cursor.column_offset
- > highest_column_number(which_buffer) then
- return true ;
- elsif which_buffer.fixed_cursor.file_line_number
- < which_buffer.top_screen_cursor
- .file_line_number then
- return true ;
- elsif which_buffer.fixed_cursor.file_line_number
- >= -- which_buffer.next_screen_cursor
- -- .file_line_number then
- which_buffer.top_screen_cursor.file_line_number
- + window_height( which_buffer ) then
- return true ;
- else
- -- ok, here we just need to find out where we are and go there
- return false ;
- end if ;
- end cursor_off_screen ;
-
- procedure set_cursor_up_lines ( which_buffer : in out an_editor_buffer ;
- old_cursor : in cursor_position ;
- new_cursor : out cursor_position ;
- lines_up : integer ) is
- -- cannot change fixed_cursor, even if called to change fixed cursor
- number_of_lines_moved : integer ;
- begin -- set_cursor_up_lines
- number_of_lines_moved := 0 ;
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := old_cursor ;
- while number_of_lines_moved < lines_up loop
- -- we need to go backwards, and we know that we can without error
- line_backward(which_buffer);
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- number_of_lines_moved := number_of_lines_moved + 1 ;
- end loop ;
- new_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := which_buffer.floating_cursor ;
- end set_cursor_up_lines ;
-
- procedure set_cursor_down_lines(which_buffer : in out an_editor_buffer ;
- old_cursor : in cursor_position ;
- new_cursor : out cursor_position ;
- lines_down : integer ) is
- number_of_lines_moved : integer ;
- -- cannot change fixed_cursor, even if called to change fixed cursor
- begin -- set_cursor_down_lines
- number_of_lines_moved := 0 ;
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := old_cursor ;
- while number_of_lines_moved < lines_down loop
- -- we need to go backwards, and we know that we can without error
- line_forward(which_buffer);
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- number_of_lines_moved := number_of_lines_moved + 1 ;
- end loop ;
- new_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := which_buffer.floating_cursor ;
- end set_cursor_down_lines ;
-
- procedure put_cursor_on_line ( which_buffer : in out an_editor_buffer ;
- this_line : in window_line_number ) is
- -- set the first line position so as to make the cursor on
- -- the this_line line
- target_line_number : line_number ;
- begin -- put_cursor_on_line
- -- show_buffer( 'V' ) ;
- set_cursor_up_lines ( which_buffer , which_buffer.fixed_cursor ,
- which_buffer.top_screen_cursor ,
- this_line - 1 ) ;
- -- show_buffer( 'V' ) ;
- target_line_number := which_buffer.top_screen_cursor.file_line_number
- + window_height( which_buffer ) ;
- set_cursor_down_lines ( which_buffer,which_buffer.fixed_cursor ,
- which_buffer.next_screen_cursor,
- target_line_number -
- which_buffer.fixed_cursor .
- file_line_number ) ;
- if which_buffer.top_screen_cursor.file_line_number
- + window_height( which_buffer ) /= which_buffer.next_screen_cursor
- . file_line_number then
- which_buffer.next_screen_cursor.line_start := 0 ;
- which_buffer.next_screen_cursor.file_line_number :=
- which_buffer.next_screen_cursor.file_line_number + 1 ;
- -- above statement added 14 Mar 85
- end if ;
- -- show_buffer( 'V' ) ;
- end put_cursor_on_line ;
-
- procedure memory_center ( which_buffer : in out an_editor_buffer ;
- new_line_number : in window_line_number:=0) is
- -- center the buffer's cursor in memory so that we can place the
- -- cursor anywhere on the screen and feel safe that we will not run
- -- out of text in memory
- --
- -- We enter with cursor completely defined ( except buffer_position
- -- which can be 0 if it is not in the current line's
- -- text area.
- -- Also, first_window_line_position & first_window_line might not
- -- even be defined (if we have moved around a lot). In that case,
- -- first_window_line_position is 0 .
-
- -- This routine guarantees us that we can move one line in either
- -- direction off of the screen if there is any text there.
-
- moved_cursor : cursor_position ;
-
- count_backward : integer ;
-
- begin -- memory_center
- -- show_buffer('V');
- if which_buffer.fixed_cursor.line_start
- < screen_size + max_bytes_in_line then
- -- the +max bytes ensures that we have one extra line available
- -- we might have to do some work to make sure we can be at the
- -- last line on the screen
- set_cursor_up_lines ( which_buffer , which_buffer.fixed_cursor ,
- moved_cursor ,
- window_height( which_buffer ) ) ;
- count_backward := which_buffer.fixed_cursor.file_line_number
- - moved_cursor.file_line_number ;
- else
- count_backward := window_height( which_buffer ) ;
- -- to say that we have more than a window in that direction
- end if ;
- -- Now, we need to set top_screen_cursor & next_screen_cursor
- -- we might need to completely refigure the window position
- -- count_backward tells us how many lines we can move backwards
- -- if new_line_number is > 0 then it is telling us where to put it
- if new_line_number > 0 then
- -- new line number is the line number on the screen where the caller
- -- wants the cursor to end up
- if new_line_number > window_height( which_buffer ) then
- -- they tried to put us off the screen...
- if count_backward + 1 > window_height( which_buffer ) then
- put_cursor_on_line( which_buffer ,window_height ( which_buffer ) ) ;
- else
- put_cursor_on_line( which_buffer , count_backward + 1 ) ;
- end if ;
- elsif new_line_number > count_backward + 1 then
- -- by definition, count_backward + 1 must be less than
- -- the window_height, otherwise, the previous if would have
- -- caught it
- put_cursor_on_line( which_buffer , count_backward + 1 ) ;
- else
- put_cursor_on_line( which_buffer , new_line_number ) ;
- end if ;
- elsif which_buffer.top_screen_cursor.line_start = 0 then
- -- we have to refigure because we are lost
- if count_backward + 1 <= window_height( which_buffer ) then
- -- we are on the first screen....
- put_cursor_on_line(which_buffer,
- which_buffer.fixed_cursor.file_line_number ) ;
- -- elsif count_forward + 1 <= window_height( which_buffer ) then
- -- we are on the last screen....
- -- put_cursor_on_line( which_buffer,window_height ( which_buffer ) ) ;
- else
- -- we are on a middle screen
- put_cursor_on_line( which_buffer ,
- window_height ( which_buffer ) / 2 ) ;
- end if ;
- else
- -- we get here if we are off the screen but still
- -- know what the first window line position is
- null ; -- handled by the caller....
- end if ;
- -- show_buffer('V');
- end memory_center ;
-
- begin -- buffer_lines
- -- BUFFERMS by SAIC/Clearwater General Buffer Routines 24 Jan 85
- null ;
- end buffer_lines ;
-
- use buffer_lines ;
-
- procedure re_initialize ( which_buffer : in out an_editor_buffer ) is
- -- Do the initialization which is also done each time a buffer
- -- is re_loaded
- begin -- re_initialize
- which_buffer.e_buf(0).data := extended_character(buffer_boundry) ;
- which_buffer.e_buf(1).data := extended_character( 0) ;
- which_buffer.e_buf(2).data := extended_character( 0) ;
- which_buffer.e_buf(3).data := extended_character( 0) ;
- which_buffer.e_buf(4).data := extended_character(buffer_boundry) ;
- which_buffer.fixed_cursor.buffer_position := 0 ;
- which_buffer.fixed_cursor.file_line_number := 1 ;
- which_buffer.fixed_cursor.line_start := 1 ;
- which_buffer.fixed_cursor.column_offset := 0 ;
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- which_buffer.top_screen_cursor := which_buffer.fixed_cursor ;
- which_buffer.next_screen_cursor := which_buffer.fixed_cursor ;
- which_buffer.bufcount := 4 ;
- which_buffer.still_reading_input_file := false ;
- which_buffer.copy_file_name := blank_file_name ;
- which_buffer.output_file_name := blank_file_name ;
- which_buffer.prestopblock := 0 ;
- which_buffer.presbotblock := 0 ;
- -- Buffer does not need initialization
- which_buffer.pagezero := default_header ;
- which_buffer.open_buffer_area := false ;
- which_buffer.first_open_position := 0 ;
- which_buffer.last_open_position := 0 ;
- -- new_marker( which_buffer.saved_cursor ) ;
- new_marker( which_buffer.last_marked_position ) ;
- end re_initialize ;
-
- procedure initialize_buffer( which_buffer : out an_editor_buffer ;
- buffer_number: in a_buffer_number ) is
- -- Initialize the buffer.
- temp_which_buffer : an_editor_buffer ;
- successfull : boolean ;
- begin -- initialize_buffer
- temp_which_buffer := new real_editor_buffer ;
- temp_which_buffer.window := no_window ;
- temp_which_buffer.buffer_number := buffer_number ;
- create( temp_which_buffer , thetop , successfull ) ;
- if successfull then
- -- If we create any temporary files, we need to have buffer_list
- -- set so that an exception can generate a request to close
- -- any created files
- buffer_list(buffer_number) := temp_which_buffer ;
- create( temp_which_buffer , thebot , successfull ) ;
- if successfull then
- temp_which_buffer.input_file_name := blank_file_name ;
- temp_which_buffer.prior_buffer := null ;
- temp_which_buffer.following_buffer := null ;
- temp_which_buffer.name := "BufferName" ;
- temp_which_buffer.mode := insert ;
- if text_io.is_open(temp_which_buffer.inputfile) then
- text_io.close(temp_which_buffer.inputfile);
- end if ;
- re_initialize(temp_which_buffer);
- -- The buffer number is used to keep track of each buffer
- -- The (buffer_boundry) signifies the start of the real text area
- -- The (0) is the preceding Line Length
- -- The next (0) is the following Line Length
- -- The final (buffer_boundry) is the end of buffer signal
- -- We are at position 1, which is the start of line 1
- -- We are in line 1
- -- Line 1 starts at position 1
- -- We are not offset into the line yet
- -- We are at the left edge of our window
- -- The highest numbered extended_character in the e_buf is #3
- -- We do Not yet have any data from an input file
- end if ;
- end if ;
- if not successfull then
- -- we have a fatal error.
- error( "Unable To Open Temporary Editor Files.",
- fatal_error , operator_wait , long_beep ) ;
- end if ;
- which_buffer := temp_which_buffer ;
- end initialize_buffer ;
-
- procedure load_file( which_buffer : in out an_editor_buffer ;
- file_to_load : in ascii_text_file_name ) is
- -- Load the named file into the buffer. We can assume
- -- an empty buffer in this case.
- bytes_needed_for_load : constant integer := screen_size + screen_size ;
- -- we must load at least two screens of data
- input_string : string ( 1 .. max_column_number ) ;
- new_string_len : integer ;
- leading_blanks : type_leading_spaces ;
- first_char ,
- last_char : type_text_length ;
- length : type_text_length ;
- ln_start : type_buffer_position ;
- env_code ,
- old_env_code : integer ;
- ok : boolean ;
- file_loaded : ascii_text_file_name ;
- begin -- load_file
- file_loaded := file_to_load ;
- open_for_read(which_buffer.inputfile,file_loaded ,ok);
- if not ok then
- -- File not found, even though the caller assured us that it would
- -- really exist.
- error("Bad Input File Name.",
- not_fatal_error , operator_wait , medium_beep ) ;
- else
- -- OK!
- which_buffer.input_file_name := file_loaded ;
- re_initialize(which_buffer); -- reset as empty buffer
- which_buffer.still_reading_input_file := true ;
- open_buffer(which_buffer,which_buffer.fixed_cursor.line_start,
- bytes_needed_for_load );
- -- Open up a text area here so that we can insert the file
- -- Now, since we are reading a file, kill the empty line in buffer
- which_buffer.last_open_position := which_buffer.last_open_position + 3;
- env_code := 0 ; -- no environment lines read yet
- loop
- read_next_line( which_buffer , env_code ) ;
- exit when not which_buffer.still_reading_input_file
- or which_buffer.first_open_position + minimum_open_area
- > which_buffer.last_open_position ;
- end loop ;
- -- Data loaded
- close_buffer(which_buffer);
- memory_center ( which_buffer , 1 ) ; -- place the cursor on line 1
- -- Finally, fix the cursor position
- which_buffer.fixed_cursor.column_offset :=
- num_leading_spaces(which_buffer,which_buffer.fixed_cursor) + 1 ;
- which_buffer.moving_cursor.column_offset :=
- num_leading_spaces(which_buffer,which_buffer.moving_cursor) + 1 ;
- end if ; -- we actually had a file out there
- end load_file ;
-
- procedure copy_file( which_buffer : in out an_editor_buffer ;
- file_to_copy : in ascii_text_file_name ;
- first_marker : in str10 ;
- last_marker : in str10 ) is
- -- Copy the named file in at the current position in
- -- which buffer.
- bytes_needed_for_load : constant integer := screen_size + screen_size ;
- -- we must load at least two screens of data
- new_string_length : integer ;
- leading_blanks : type_leading_spaces ;
- first_char ,
- last_char : type_text_length ;
- length : type_line_length ;
- ln_start : type_buffer_position ;
- copy_string : string ( 1 .. max_column_number ) ;
- lines_added : integer ;
- original_line_number : integer ;
- copyfile : text_file_type ;
- successfull : boolean ;
- env_code ,
- old_env_code : integer ;
- copy_header : header ;
- ok : boolean ;
- file_copied : ascii_text_file_name ;
- first_line_to_move_in : integer := 1 ;
- last_line_to_move_in : integer := integer'last ;
- first_col_to_move_in : integer := 1 ;
- last_col_to_move_in : integer := integer'last ;
- current_line_reading : integer := 1 ;
-
- procedure adjust_markers ( start_line : line_number ;
- start_column : column_position ;
- end_line : line_number ;
- end_column : column_position ) is
- new_text_range : text_range ;
-
- begin -- adjust_markers
- new_text_range.lo_position := ( start_line , start_column ,
- no_screen_attribute , which_buffer ) ;
- new_text_range.hi_position := ( end_line , end_column ,
- no_screen_attribute , which_buffer ) ;
- new_text_range.attribute := no_screen_attribute ;
- update_markers_for_added_text( which_buffer , new_text_range ) ;
- end adjust_markers ;
-
- procedure merge_environment ( old_environment : in out header ;
- new_environment : in header ) is
- begin -- merge_environment
- -- Later we might want to merge in unique marker names
- null ;
- end merge_environment ;
-
- procedure empty_environment ( old_environment : in out header ) is
- begin -- empty_environment
- -- and then delete the old markers.....
- for posn in 1 .. old_environment.marker_count loop
- dispose( old_environment.markers( posn ) .location ) ;
- end loop ;
- end empty_environment ;
-
- function find_marker ( name : in str10 ) return marker_number is
- begin -- find_marker
- for posn in 1 .. copy_header.marker_count loop
- if name = copy_header.markers ( posn ) . name then
- return posn ;
- end if ;
- end loop ;
- return 0 ;
- end find_marker ;
-
- function work_environment return boolean is
- -- return true if we successfull moved past environment
- ok : boolean := true ;
- mark_place : integer ;
- begin -- work_environment
- env_code := 0 ; -- no environment lines read yet
- loop
- exit when text_io.end_of_file(copyfile);
- text_io.get_line(copyfile,copy_string,new_string_length);
- exit when text_io.end_of_file(copyfile) and new_string_length = 0 ;
- if env_code >= 0 then
- -- we must check for an environment line
- old_env_code := env_code ;
- if new_string_length > 0 then
- convert_string_to_header( copy_string(1..new_string_length),
- env_code, copy_header , no_buffer );
- else
- env_code := -1 ;
- end if ;
- if ( old_env_code = 0 ) and then ( env_code < 0 ) then
- -- no environment found, look for user's environment
- users_default_header(copy_header) ;
- end if ;
- end if ;
- exit when env_code < 0 ;
- end loop ;
- if env_code >= 0 then
- -- abnormal exit
- empty_environment(copy_header);
- return false ;
- else
- -- check markers....
- if first_marker = blank_marker then
- ok := true ;
- first_line_to_move_in := 1 ;
- first_col_to_move_in := 1 ;
- else
- -- must check a marker...
- mark_place := find_marker( first_marker ) ;
- if mark_place > 0 then
- ok := true ;
- first_line_to_move_in
- := copy_header.markers(mark_place).location.data.line ;
- first_col_to_move_in
- := copy_header.markers(mark_place).location.data.column ;
- else
- ok := false ;
- error("Marker """ & compress(first_marker)
- & """ does not exist in file." ,
- not_fatal_error , operator_wait , medium_beep ) ;
- end if ;
- end if ;
- if ok then
- if last_marker = blank_marker then
- last_line_to_move_in := integer'last ;
- last_col_to_move_in := integer'last ;
- else
- -- must check a marker...
- mark_place := find_marker( last_marker ) ;
- if mark_place > 0 then
- ok := true ;
- last_line_to_move_in
- := copy_header.markers(mark_place).location.data.line ;
- last_col_to_move_in
- := copy_header.markers(mark_place).location.data.column
- - 1 ;
- else
- ok := false ;
- error("Marker """ & compress(last_marker)
- & """ does not exist in file." ,
- not_fatal_error , operator_wait , medium_beep ) ;
- end if ;
- end if ;
- if ok then
- -- check for sequencing ..
- if ( first_line_to_move_in > last_line_to_move_in ) then
- ok := false ; -- lines out of order
- elsif first_line_to_move_in = last_line_to_move_in then
- ok := first_col_to_move_in <= last_col_to_move_in ;
- end if ;
- if not ok then
- error("Marker """ & compress(first_marker)
- & """ must precede """ & compress(last_marker) & """." ,
- not_fatal_error , operator_wait , medium_beep ) ;
- end if ;
- end if ;
- end if ;
- if ok then
- return true ;
- else
- empty_environment(copy_header);
- return false ;
- end if ;
- end if ;
- end work_environment ;
-
- procedure read_text is
- -- return true if we successfull moved past environment
- not_to_do : integer ;
- text_not_to_do : integer ;
- begin -- read_text
- open_buffer(which_buffer,which_buffer.fixed_cursor.line_start,
- bytes_needed_for_load );
- -- Open up a text area here so that we can insert the file
- current_line_reading := 1 ;
- loop
- ln_start := which_buffer.first_open_position ;
- if current_line_reading >= first_line_to_move_in then
- if new_string_length > 0 then
- interpret_string(copy_string(1..new_string_length),
- leading_blanks,first_char,
- last_char , length ) ;
- else
- leading_blanks := 0 ;
- length := 0 ;
- end if ;
- --
- -- Note: No matter what, we start this on a line start and end
- -- at the end of a line....
- --
- if current_line_reading = first_line_to_move_in then
- -- must adjust settings ...
- if first_col_to_move_in > leading_blanks + 1 then
- -- we don't want the leading blanks......
- not_to_do := first_col_to_move_in - leading_blanks - 1 ;
- text_not_to_do := not_to_do + leading_blanks ;
- leading_blanks := 0 ;
- if not_to_do >= length then
- first_char := 0 ;
- last_char := 0 ;
- length := 0 ;
- else
- first_char := first_char + not_to_do ;
- length := length - not_to_do ;
- if current_line_reading = last_line_to_move_in then
- -- must specially treat first_line = last_line
- last_col_to_move_in := last_col_to_move_in - text_not_to_do;
- end if ;
- end if ;
- else
- null ; -- if they have a marker set at start of line or
- -- within leading spaces or at first character,
- -- we move over all leading spaces...
- end if ;
- -- else do nothing...
- end if ;
- -- we stop here and check last line because it could both start
- -- and stop on the same line
- if current_line_reading = last_line_to_move_in then
- -- again, must adjust settings ...
- -- first, adjust last_col_to_move_in by the number of
- -- characters already deleted on this line
- exit when last_col_to_move_in <= leading_blanks ;
- -- exit if we don't want any part of this line.....
- -- we get here if we want part of this line....
- if last_col_to_move_in < leading_blanks + length then
- -- must get rid of a few characters
- not_to_do := leading_blanks + length
- - last_col_to_move_in ;
- length := length - not_to_do ;
- last_char := last_char - not_to_do ;
- end if ;
- end if ;
- which_buffer.e_buf(ln_start).data := extended_character(length) ;
- which_buffer.e_buf(ln_start+1 ).data :=
- extended_character(leading_blanks) ;
- if length > 0 then
- for place in 1 .. length loop
- which_buffer.e_buf(ln_start + 1 + place ).data :=
- extended_character(
- character'pos(copy_string( first_char + place - 1 ) ));
- end loop ;
- end if ;
- which_buffer.e_buf(ln_start + length + 2 ).data :=
- extended_character(length) ;
- which_buffer.first_open_position := ln_start + length + 3 ;
- lines_added := lines_added + 1 ;
- for place in ln_start .. ln_start + length + 2 loop
- which_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- if which_buffer.first_open_position + minimum_open_area
- > which_buffer.last_open_position then
- -- need to bump
- push_data(which_buffer,thetop,successfull);
- if not successfull then
- error("Unable To Read/Write Temporary Files.",
- not_fatal_error , operator_wait , medium_beep ) ;
- end if ;
- exit when not successfull ;
- end if;
- end if ;
- ln_start := which_buffer.first_open_position ;
- exit when text_io.end_of_file(copyfile);
- text_io.get_line(copyfile,copy_string,new_string_length);
- exit when text_io.end_of_file(copyfile) and new_string_length = 0 ;
- current_line_reading := current_line_reading + 1 ;
- exit when current_line_reading > last_line_to_move_in ;
- end loop ;
- -- Data loaded
- which_buffer.fixed_cursor := ( 0 , original_line_number + lines_added ,
- ln_start , 1 ) ;
- which_buffer.first_open_position := ln_start ;
- close_buffer(which_buffer);
- end read_text ;
-
- begin -- copy_file
- -- Later we might want to completely work with copy buffer
- file_copied := file_to_copy ;
- open_for_read(copyfile,file_copied ,ok);
- if not ok then
- error("Bad Copy File Name.",
- not_fatal_error , operator_wait , medium_beep ) ;
- return ;
- -- error. should not be able to get here
- end if ;
- if text_io.end_of_file(copyfile) then
- -- File not found, even though the caller assured us that it would
- -- really exist.
- text_io.close(copyfile);
- else
- -- OK!
- if work_environment then
- which_buffer.copy_file_name := file_copied ;
- original_line_number:= which_buffer.fixed_cursor.file_line_number ;
- lines_added := 0 ;
- read_text ;
- -- Now, adjust markers for lines_added from original_line_number
- adjust_markers(original_line_number,0,
- original_line_number + lines_added,0);
- merge_environment(which_buffer.pagezero,copy_header ) ;
- empty_environment(copy_header);
- end if ;
- text_io.close(copyfile);
- -- merge the new environment w/marker line offset
- -- specified
- -- Finally, fix the cursor position
- -- jump_to_position (which_buffer,original_line_number, 0);
- -- which_buffer.cursor.column_offset :=
- -- num_leading_spaces(which_buffer,which_buffer.cursor) + 1 ;
- end if ; -- we actually had a file out there
- end copy_file ;
-
- procedure dispose_buffer( which_buffer : in out an_editor_buffer ) is
- -- close a buffer because we are done with it
- successfull : boolean ;
- begin -- dispose_buffer
- for psh in topush'first .. topush'last loop
- close ( which_buffer , psh , successfull ) ;
- -- close the block file
- end loop ;
-
- -- and then get rid of its memory requirements....
-
- end dispose_buffer ;
-
- begin -- buffer_package
- -- BUFFERS by SAIC/Clearwater Buffer Package 17 Jan 85
- null ;
- end buffer_package ;
-
- --$$$- BUFFERS
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editmisc
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITMISC
-
- --
- -- File 016
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Ada Software Development Project Team
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with basic_io_system ;
-
- with text_io ;
-
- with direct_io ;
-
- with string_library ;
- use string_library ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_general ;
- use buffer_lines ;
-
- with markers ;
- use markers ;
- use text_position_handler ;
-
- package editor_misc is
-
- package copy_package is
-
- Procedure Copy_Text_To_Copy_Buffer(which_buffer: in out an_editor_buffer ;
- copy_range : text_range ;
- add_to_previous_copy : boolean :=false;
- delete_after_copy : boolean:=false ;
- adjust_markers : boolean := true ) ;
- -- copy the text within the range to the copy buffer
- -- then, optionally, delete the text......
-
- procedure Copy_Text_Back_From_Copy_Buffer ( which_buffer :
- in out an_editor_buffer ) ;
-
- procedure copy_debug ( c : character ) ;
-
- procedure terminate_copy_package ;
-
- end copy_package ;
-
- master_buffer : editor_globals.an_editor_buffer ;
- master_window : crt_windows.window_pointer ;
-
- procedure set_direction ( go_forward : boolean ) ;
- -- Set the direction arrow at the top left corner
-
- procedure set_repeat_prompt( is_show_repeat_on : boolean ;
- repeat_factor : a_repeat_factor ) ;
- -- If is_show_repeat_on, the set the repeat factor string
- -- as stated in repeat_factor. If it is -1, then set it
- -- as [Once].
-
- procedure prompt ( prompt_string : in string ) ;
- -- show the prompt string in the master buffer
-
- procedure show_screen( which_buffer : in out an_editor_buffer ) ;
- -- Given the current screen definition, show the entire
- -- screen within the current window.
-
- procedure show_screen( which_buffer : in out an_editor_buffer ;
- cursor : in out cursor_position ;
- Cursor_Line : in window_line_number ) ;
- -- Given the current screen definition, show the entire
- -- screen within the current window.
- -- The cursor is to be put on cursor_line if possible.
- -- Note: cursor might be found as both CURSOR and
- -- WHICH_BUFFER.fixed_CURSOR
-
- procedure show_cursor ;
- -- move the actual cursor to the position on the screen where the
- -- master buffer's logical cursor is
-
- procedure show_cursor ( which_buffer : in out an_editor_buffer ) ;
- -- Show the cursor on the screen. If necessary, push/pop
- -- data to make sure you have enough for the entire screen
-
- procedure jump_to_position ( which_buffer : in out an_editor_buffer ;
- to_line_number : in line_number ;
- to_column_number : in column_position ;
- show_new_position: in boolean := true ) ;
- -- Move the cursor and screen display to the specified
- -- position.
-
- function current_position return text_position ;
- -- return the line/column/and buffer for the current position
-
- function cursor_forward_line return boolean ;
- -- return true if we moved forward a line like we were asked
-
- function cursor_backward_line return boolean ;
- -- return true if we moved backward a line like we were asked
-
- procedure get_leading ( txt : in out type_text_line ;
- leading_spaces : out type_leading_spaces ;
- first_text_position,
- last_text_position:out type_text_length ;
- length : out type_line_length ) ;
- -- take a txt line and get facts necessary for insertion into
- -- the buffer. truncate any values necessary to force it to
- -- be a valid line...
-
- procedure get_next_command( Old_Repeat : in a_repeat_factor ;
- New_Repeat : out a_repeat_factor ;
- new_command : out an_editor_command ) ;
-
- allow_alternate_prompt_command : boolean := true ;
-
- private
-
- is_go_forward : boolean ;
- repeat_prompt : string_library.pstring ;
- last_repeat : integer ;
- prompt_line : string_library.pstring ;
-
- reverse_storage : boolean := false ;
-
- end editor_misc ;
-
- package body editor_misc is
-
- package body copy_package is
-
- package copy_block_io is new direct_io(block);
-
- type Type_Copy_Data is
- record
- Present_Copy_Block : Integer := 0 ;
- Present_Copy_Length : block_offset := 0 ;
- We_Have_Copy_Data : boolean := false ;
- The_Copy_Buffer : block;
- Copy_Started_At_Stuff_Start : boolean := false ;
- Copy_Ended_At_Line_End : boolean := false ;
- Copy_Ended_At_Stuff_Start : boolean := false ;
- Copy_File : copy_block_io.file_type ;
- end record ;
-
- Type Copy_Data_Pointer is access Type_Copy_Data ;
-
- The_Copy_Data : Copy_Data_Pointer ;
-
- Current_Copy_Data : Copy_Data_Pointer ;
-
- procedure copy_debug ( c : character ) is
-
- procedure show ( s : string ; b : boolean ) is
- begin
- put(s);
- if b then put_line("True"); else put_line("False"); end if ;
- end ;
-
- procedure show_insides( b : block ) is
- p1 : block_offset := 0 ;
- p2 : integer := current_copy_data.present_copy_length - 1 ;
- ln_start : integer ;
- ln_posn : block_offset ;
-
- procedure show_c ( val , len : integer ) is
- begin
- if val < 0 then
- basic_io_system.put(" XXX");
- elsif val < 32 then
- basic_io_system.put(val,len);
- elsif val < 127 then
- basic_io_system.put(" """);
- basic_io_system.put( character'val(val));
- elsif val <= 999 then
- basic_io_system.put(val,len);
- else
- basic_io_system.put(" XXX");
- end if ;
- end ;
-
- begin
- basic_io_system.put_line ;
- ln_start := p1 ;
- loop
- basic_io_system.put(ln_start,5);
- basic_io_system.put(" ");
- ln_posn := ln_start ;
- loop
- show_c( b(ln_posn).data , 4 ) ;
- ln_posn := ln_posn + 1 ;
- exit when ( ln_posn = ln_start + 16 ) or ( ln_posn > p2 ) ;
- end loop ;
- basic_io_system.put_line;
- ln_start := ln_start + 16 ;
- exit when ln_start > p2 ;
- end loop ;
- end;
-
- begin -- copy_debug
- case c is
- when 'X' => put_line(" ");
- put(" Present Copy Block => ");
- put( current_copy_data.present_copy_block , 3 ) ;
- put_line(" ");
- put(" Present Copy Leng => ");
- put( current_copy_data.Present_Copy_Length , 4 ) ;
- put_line(" ");
- show("Copy Available " , current_copy_data.We_Have_Copy_Data);
- show("Start StuffStart " , current_copy_data.Copy_Started_At_Stuff_Start);
- show("End Line End " , current_copy_data.Copy_Ended_At_Line_End );
- show("End StuffStart " , current_copy_data.Copy_Ended_At_Stuff_Start );
- when 'B' => show_insides( current_copy_data.The_Copy_Buffer ) ;
- when others => null ;
- end case ;
- end copy_debug ;
-
- procedure initialize_copy_package is
- begin -- initialize_copy_package
- copy_block_io.create(Current_Copy_Data.Copy_File,copy_block_io.inout_file);
- exception
- when others => error( "Unable To Open Temporary Copy File.",
- fatal_error,operator_wait , long_beep ) ;
- end initialize_copy_package ;
-
- procedure terminate_copy_package is
- begin -- terminate_copy_package
- copy_block_io.close ( Current_Copy_Data.Copy_File ) ;
- exception
- when others => null ;
- end terminate_copy_package ;
-
- procedure getblock( block_of_data: out block ;
- block_number : in integer ;
- successfull : out boolean ) is
- -- read in a block of data from that file
- begin -- getblock
- copy_block_io.read( Current_Copy_Data.Copy_File , block_of_data ,
- copy_block_io.positive_count(block_number)) ;
- successfull := true ;
- exception
- when others => successfull := false ;
- end getblock ;
-
- procedure putblock( block_of_data: in block ;
- block_number : in integer ;
- successfull : out boolean ) is
- -- write a block of data from that file
- wicat_block : block := block_of_data ;
- begin -- putblock
- copy_block_io.write(Current_Copy_Data.Copy_File , wicat_block ,
- copy_block_io.positive_count(block_number)) ;
- successfull := true ;
- exception
- when others => successfull := false ;
- end putblock ;
-
- Procedure Copy_Text_To_Copy_Buffer( which_buffer: in out an_editor_buffer ;
- copy_range : text_range ;
- add_to_previous_copy : boolean := false;
- delete_after_copy : boolean:=false ;
- adjust_markers : boolean := true ) is
- First_Pos ,
- Second_Pos : Text_Position ;
- Actual_Copy_Range : Text_Range ;
- Original_Location : Text_Position ;
- should_delete_extra_leading : boolean ;
- Original_Leading_Spaces : type_leading_spaces ;
- Fixed_Cursor_Line_Start : type_buffer_position ;
- Fixed_Cursor_Buffer_Position : type_buffer_position ;
- First_Line_Character_Position : type_buffer_position ;
- Last_Line_Character_Position : type_buffer_position ;
- Lines_Leading_Spaces : type_leading_spaces ;
- Lines_Last_Column : column_position ;
- Lines_Text_Length : type_line_length ;
- next_copy_position : block_offset :=
- Current_Copy_Data.Present_Copy_Length ;
- no_room_to_copy_text : exception ;
- -- now items for the deletion
- First_Deleted_Position : type_buffer_position := 1 ;
- Last_Deleted_Position : type_buffer_position := 0 ;
- -- the above two settings make it so that we know nothing is deleted
- orig_text : type_text_line ;
- orig_col : column_position ;
- orig_line_number : line_number ;
- type a_place is ( in_leading , at_stuff_start ,
- in_text , at_text_end , past_end_of_line ) ;
- left_place , right_place : a_place ;
-
- procedure new_block is
- successfull : boolean ;
- begin -- new_block
- Current_Copy_Data.Present_Copy_Block
- := Current_Copy_Data.Present_Copy_Block + 1 ;
- putblock( Current_Copy_Data.The_Copy_Buffer ,
- Current_Copy_Data.Present_Copy_Block , successfull ) ;
- if successfull then
- next_copy_position := 0 ;
- else
- -- error....
- error(" Unable To Copy Text To Disk..." ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- raise no_room_to_copy_text ;
- end if ;
- end new_block ;
-
- Procedure Add_Ch_To_Buffer
- ( C : in extended_character ) is
- -- add one extended character to buffer
- begin -- Add_Ch_To_Buffer
- Current_Copy_Data.The_Copy_Buffer( next_copy_position ).data := c ;
- if next_copy_position = block_minus then
- new_block ;
- else
- next_copy_position := next_copy_position + 1 ;
- end if ;
- end Add_Ch_To_Buffer ;
-
- Procedure Add_One_Character_To_Buffer ( C : in character ) is
- begin -- add_one_character_to_buffer
- Current_Copy_Data.The_Copy_Buffer( next_copy_position ).data :=
- extended_character( character'pos( c ) ) ;
- if next_copy_position = block_minus then
- new_block ;
- else
- next_copy_position := next_copy_position + 1 ;
- end if ;
- end add_one_character_to_buffer ;
-
- Function Backup_One_Character_From_Buffer return character is
- successfull : boolean ;
- next_extended : extended_character ;
- begin -- backup_one_character_from_buffer
- if next_copy_position = 0 then
- -- we need to be carefull.....
- if current_copy_data.present_copy_block = 0 then
- return ascii.nul ; -- can't back up any more
- else
- Current_Copy_Data.Present_Copy_Block
- := Current_Copy_Data.Present_Copy_Block - 1 ;
- getblock( Current_Copy_Data.The_Copy_Buffer ,
- Current_Copy_Data.Present_Copy_Block , successfull ) ;
- if successfull then
- next_copy_position := block_minus ;
- else
- -- error....
- error(" Unable To Add Copy Text To Disk..." ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- raise no_room_to_copy_text ;
- end if ;
- end if ;
- end if ;
- -- if we get this far... then we can read the next character ...
- next_copy_position := next_copy_position - 1 ;
- next_extended := Current_Copy_Data.The_Copy_Buffer(
- next_copy_position ).data ;
- if next_extended <= extended_character(character'pos(character'last))
- then
- return character'val( next_extended ) ;
- else
- return ascii.del ;
- end if ;
- end backup_one_character_from_buffer ;
-
- Procedure Fix_Fixed_Cursor is
- -- note the boundries of the current line for searching
- begin -- fix_fixed_cursor
- Fixed_Cursor_Line_Start := which_buffer.fixed_cursor.line_start ;
- Lines_Leading_Spaces := num_leading_spaces ( which_buffer ,
- fixed_cursor_line_start ) ;
- Lines_Text_Length := line_length( which_buffer ,
- fixed_cursor_line_start ) ;
- First_Line_Character_Position := Fixed_Cursor_Line_Start + 2 ;
- Last_Line_Character_Position := First_Line_Character_Position
- + Lines_Text_Length - 1 ;
- Lines_Last_Column := Lines_Leading_Spaces
- + Lines_Text_Length ;
- end fix_fixed_Cursor ;
-
- function is_at_stuff_start ( cursor : cursor_position ) return boolean is
- save_cursor : cursor_position := which_buffer.fixed_cursor ;
- return_value : boolean ;
- begin -- is_at_stuff_start
- which_buffer.fixed_cursor := cursor ;
- fix_fixed_cursor ;
- return_value := ( lines_text_length < 1 )
- or else ( cursor.column_offset <= lines_leading_spaces + 1 ) ;
- which_buffer.fixed_cursor := save_cursor ;
- fix_fixed_cursor ;
- return return_value ;
- end is_at_stuff_start ;
-
- function is_at_line_end ( cursor : cursor_position ) return boolean is
- save_cursor : cursor_position := which_buffer.fixed_cursor ;
- return_value : boolean ;
- begin -- is_at_line_end
- which_buffer.fixed_cursor := cursor ;
- fix_fixed_cursor ;
- return_value := ( lines_text_length < 1 )
- or else ( cursor.column_offset > lines_last_column ) ;
- which_buffer.fixed_cursor := save_cursor ;
- fix_fixed_cursor ;
- return return_value ;
- end is_at_line_end ;
-
- procedure copy_out_initialize is
- old_c : character ;
- begin -- copy_out_initialize
- -- first, make sure lo < hi
- Actual_Copy_Range := Copy_Range ;
- Normalize_Range( Actual_Copy_Range ) ;
- first_pos := actual_copy_range.lo_position ;
- second_pos := actual_copy_range.hi_position ;
- -- now, ready to work...
- need_prompt := true ;
- clear_prompt( which_buffer ) ;
- goto_prompt_line_column( which_buffer , 1 , 1 ) ;
- if add_to_previous_copy then
- put(" Adding text to list");
- else
- put(" Copying data");
- Current_Copy_Data.Present_Copy_Block := 0 ;
- Current_Copy_Data.Present_Copy_Length := 0 ;
- end if ;
- put(" for later C(opy from B(uffer ...");
- which_buffer.last_marked_position.data := first_pos ;
- -- the last was for the '=' command
- if delete_after_copy then
- -- when done, we must move to the first location remaining after
- -- we delete the range....which is the starting location
- Original_Location := First_Pos ;
- -- and, while we are here, we might as well take care of the
- -- markers..... because we are deleting text....
- if adjust_markers then
- markers.marker_manager.update_markers_for_deleted_text(
- which_buffer , actual_copy_range ) ;
- end if ;
- else
- -- remember where we have to move to...
- Original_Location := ( which_buffer.fixed_cursor.file_line_number ,
- which_buffer.fixed_cursor.column_offset ,
- no_screen_attribute ,
- which_buffer ) ;
- -- and, while we are here, we might as well take care of the
- -- markers..... because we added text.....
- if adjust_markers then
- markers.marker_manager.update_markers_for_added_text(
- which_buffer , actual_copy_range ) ;
- end if ;
- end if ;
- jump_to_position ( which_buffer , first_pos.line , first_pos.column ,
- false ) ;
- fix_fixed_cursor ;
- Original_Leading_Spaces := Lines_Leading_Spaces ;
- if first_pos.column = original_leading_spaces + 1 then
- -- they are at the first character of the line
- -- must back up first position .....
- should_delete_extra_leading := true ;
- else
- should_delete_extra_leading := false ;
- end if ;
- If add_to_previous_copy
- and then current_copy_data.we_have_copy_data then
- -- ok, we need to adjust any ending positions.....
- If is_at_stuff_start ( which_buffer.fixed_cursor ) then
- -- in this case, we might adjust some old information...
- if current_copy_data.copy_ended_at_stuff_start then
- -- back up to the <cr>.......
- loop
- old_c := backup_one_character_from_buffer ;
- exit when old_c = ascii.nul or old_c = ascii.cr ;
- end loop ;
- if old_c = ascii.cr then
- add_one_character_to_buffer ( ascii.cr ) ;
- end if ;
- else
- -- ended either at line end or in the middle...
- -- simply add a <cr> to the old buffer to nicely add on this
- -- new info..
- add_one_character_to_buffer( ascii.cr ) ;
- end if ;
- -- else, do nothing to the old area.....
- end if ;
- next_copy_position := Current_Copy_Data.Present_Copy_Length ;
- else
- -- set the copy start information
- Current_Copy_Data.Copy_Started_At_Stuff_Start
- := is_at_stuff_start ( which_buffer.fixed_cursor ) ;
- Current_Copy_Data.Present_Copy_Block := 0 ;
- Current_Copy_Data.Present_Copy_Length := 0 ;
- next_copy_position := 0 ;
- end if ;
- end copy_out_initialize ;
-
- Procedure Copy_Out_Finish is
- begin -- copy_out_finish
- Current_Copy_Data.We_Have_Copy_Data :=
- Current_Copy_Data.Present_Copy_Length > 0
- or else Current_Copy_Data.Present_Copy_Block > 0 ;
- Current_Copy_Data.Copy_Ended_At_Stuff_Start
- := is_at_stuff_start ( which_buffer.fixed_cursor ) ;
- Current_Copy_Data.Copy_Ended_At_Line_End
- := is_at_line_end ( which_buffer.fixed_cursor ) ;
- end copy_out_finish ;
-
- procedure add_this_line ( leading_spaces : type_leading_spaces ;
- first_pos : type_buffer_position;
- last_pos : type_buffer_position;
- ln_length : type_line_length ;
- add_return : boolean := true ) is
- remaining_length : integer := ln_length ;
- next_char : type_buffer_position := first_pos ;
- amount_moved : integer ;
- begin -- add_this_line
- if leading_spaces > 0 then
- add_one_character_to_buffer( ascii.dle ) ;
- Add_Ch_To_Buffer( extended_character ( leading_spaces ) ) ;
- end if ; -- end of leading spaces
- while remaining_length > 0 loop
- -- in case all does not fit in copy buffer....
- if next_copy_position + remaining_length <= block_minus then
- -- can move over in a block...
- for looper in 0 .. remaining_length - 1 loop
- Current_Copy_Data.The_Copy_Buffer( next_copy_position + looper )
- := which_buffer.e_buf( next_char + looper ) ;
- end loop ;
- if next_copy_position + remaining_length = block_minus then
- new_block ;
- else
- next_copy_position := next_copy_position + remaining_length ;
- end if ;
- remaining_length := 0 ;
- else
- -- must move some and then return...
- amount_moved := block_minus - next_copy_position ;
- -- actually, amount moved is one LESS than amount moved...
- for looper in 0 .. amount_moved loop
- Current_Copy_Data.The_Copy_Buffer( next_copy_position + looper )
- := which_buffer.e_buf( next_char + looper ) ;
- end loop ;
- new_block ;
- remaining_length := remaining_length - amount_moved - 1 ;
- next_char := next_char + amount_moved + 1 ;
- end if ;
- end loop ;
- if add_return then
- add_one_character_to_buffer( ascii.cr ) ;
- end if ; -- end of adding carriage return....
- end add_this_line ;
-
- procedure replace_current_text ( txt : in out type_text_line ) is
- lspaces : type_leading_spaces;
- tfirst , tlast : type_text_length;
- tlength : type_line_length;
- olength : type_line_length;
- lstart : type_buffer_position;
- old_nxtln ,
- new_nxtln : type_buffer_position;
- begin -- replace_current_text
- get_leading ( txt , lspaces , tfirst , tlast , tlength );
- lstart := which_buffer.fixed_cursor.line_start;
- olength := line_length( which_buffer , lstart );
- old_nxtln := lstart + olength + 3;
- new_nxtln := lstart + tlength + 3;
- shift_buffer_area ( which_buffer , old_nxtln , new_nxtln ,
- which_buffer.bufcount - old_nxtln + 1 );
- which_buffer.bufcount:=which_buffer.bufcount -olength +tlength;
- which_buffer.e_buf(lstart).data
- := extended_character(tlength);
- which_buffer.e_buf(lstart+1 ).data
- := extended_character(lspaces);
- for place in 1 .. tlength loop
- which_buffer.e_buf(lstart + 1 + place ).data :=
- txt.data(tfirst+place-1);
- end loop;
- which_buffer.e_buf(lstart + tlength + 2 ).data
- := extended_character(tlength);
- for place in lstart .. lstart + tlength + 2 loop
- which_buffer.e_buf(place).attr := no_screen_attribute;
- end loop;
- end replace_current_text;
-
- procedure determine_left_and_right ( l_col , r_col : column_position ) is
- -- type a_place is ( in_leading , at_stuff_start ,
- -- in_text , at_text_end , past_end_of_line ) ;
- -- left_place , right_place : a_place ;
- begin -- determine_left_and_right
- fix_fixed_cursor ;
- if l_col > lines_last_column then
- left_place := past_end_of_line ;
- right_place := past_end_of_line ;
- else
- if l_col < lines_leading_spaces + 1 then
- if lines_leading_spaces = 0 then
- left_place := past_end_of_line ;
- else
- left_place := in_leading ;
- end if ;
- elsif l_col = lines_leading_spaces + 1 then
- left_place := at_stuff_start ;
- elsif l_col < lines_last_column then
- left_place := in_text ;
- else
- left_place := at_text_end ;
- -- because the past_end_of_line is taken care of above...
- end if ;
- if r_col < lines_leading_spaces + 1 then
- if lines_leading_spaces = 0 then
- right_place := past_end_of_line ;
- else
- right_place := in_leading ;
- end if ;
- elsif r_col = lines_leading_spaces + 1 then
- right_place := at_stuff_start ;
- elsif r_col < lines_last_column then
- right_place := in_text ;
- elsif r_col = lines_last_column then
- right_place := at_text_end ;
- else
- right_place := past_end_of_line ;
- end if ;
- end if ;
- end determine_left_and_right ;
-
- procedure add_partial_line_to_copy_buffer( in_first_col , in_last_col
- : column_position ) is
- first_pos : type_buffer_position ;
- last_pos : type_buffer_position ;
- ln_length : type_line_length ;
- first_col : column_position := in_first_col ;
- last_col : column_position := in_last_col ;
- real_leading_spaces : type_leading_spaces ;
- txt_to_move : integer ;
- begin -- add_partial_line_to_copy_buffer
- determine_left_and_right ( in_first_col , in_last_col ) ;
- real_leading_spaces := lines_leading_spaces ;
- case left_place is
- when in_leading => first_pos := first_line_character_position ;
- lines_leading_spaces
- := lines_leading_spaces
- - first_col + 1 ;
- when at_stuff_start => first_pos := first_line_character_position ;
- -- lines_leading_spaces is already correct
- when in_text => first_pos := first_line_character_position
- + first_col
- - real_Leading_Spaces - 1 ;
- lines_leading_spaces := 0 ;
- when at_text_end => first_pos := last_line_character_position ;
- lines_leading_spaces := 0 ;
- when past_end_of_line => return ; -- nothing to do if past end
- -- on start position
- end case ;
- case right_place is
- when in_leading => last_pos := 0 ;
- if last_col - first_col + 1 >= 0 then
- lines_leading_spaces := last_col
- - first_col + 1 ;
- else
- lines_leading_spaces := 0 ;
- end if ;
- when at_stuff_start => last_pos := first_line_character_position ;
- when in_text => last_pos := first_line_character_position
- + last_col
- - real_Leading_Spaces - 1 ;
- when at_text_end
- | past_end_of_line => last_pos := last_line_character_position ;
- last_col := lines_last_column ;
- -- sometime later we might want to include trailing spaces, and
- -- then in that case we would break these into two cases.....
- end case ;
- if last_pos < first_pos then
- if lines_leading_spaces = 0 then
- return ;
- else
- ln_length := 0 ;
- end if ;
- else
- ln_length := last_pos - first_pos + 1 ;
- end if ;
- add_this_line ( lines_leading_spaces ,
- first_pos ,
- last_pos ,
- ln_length , false ) ;
- -- Now delete after copy
- If delete_after_copy then
- -- must get rid of deleted text....
- -- and only this text is being deleted...
- -- we have ORIG_TEXT and know to get rid of FIRST_COL .. LAST_COL
- -- and ORIG_TEXT.data_length
- txt_to_move := orig_text.data_length - last_col ;
- if txt_to_move > 0 then
- for pn in 1 .. txt_to_move loop
- orig_text.data( first_col + pn - 1 )
- := orig_text.data( last_col + pn ) ;
- end loop ;
- end if ;
- orig_text.data_length := orig_text.data_length
- - last_col + first_col - 1 ;
- replace_current_text ( orig_text ) ;
- end if ;
- end add_partial_line_to_copy_buffer ;
-
- procedure add_end_of_line_to_copy_buffer(
- in_first_col : in out column_position ) is
- first_col : column_position := in_first_col ;
- first_pos : type_buffer_position ;
- last_pos : type_buffer_position ;
- ln_length : type_line_length ;
- real_leading_spaces : type_leading_spaces ;
- begin -- add_end_of_line_to_copy_buffer
- determine_left_and_right ( in_first_col , column_position'last ) ;
- real_leading_spaces := lines_leading_spaces ;
- case left_place is
- when in_leading => first_pos := first_line_character_position ;
- lines_leading_spaces
- := lines_leading_spaces
- - first_col + 1 ;
- when at_stuff_start => first_pos := first_line_character_position ;
- -- lines_leading_spaces is already correct
- when in_text => first_pos := first_line_character_position
- + first_col
- - real_Leading_Spaces - 1 ;
- lines_leading_spaces := 0 ;
- when at_text_end => first_pos := last_line_character_position ;
- lines_leading_spaces := 0 ;
- when past_end_of_line => -- because past right end of line ...
- add_this_line ( 0 , 1 , 0 , 0 , true ) ;
- in_first_col := 0 ; -- signal no info
- return ;
- end case ;
- last_pos := last_line_character_position ;
- ln_length := last_pos - first_pos + 1 ;
- add_this_line ( lines_leading_spaces ,
- first_pos ,
- last_pos ,
- ln_length , true ) ;
- end add_end_of_line_to_copy_buffer ;
-
- procedure add_line_to_copy_buffer is
- -- add the line described by fixed_cursor to the copy buffer
- begin -- add_line_to_copy_buffer
- fix_fixed_cursor ;
- add_this_line ( lines_leading_spaces ,
- first_line_character_position ,
- last_line_character_position ,
- lines_text_length , true ) ;
- end add_line_to_copy_buffer ;
-
- procedure delete_chunk is
- positions_to_move : integer ;
- begin -- delete_chunk
- if delete_after_copy then
- -- delete first_deleted_position .. last_deleted_position ...
- if last_deleted_position > first_deleted_position then
- -- stuff has been deleted...
- positions_to_move := which_buffer.bufcount - last_deleted_position ;
- shift_buffer_area( which_buffer , last_deleted_position + 1 ,
- first_deleted_position ,
- positions_to_move ) ;
- which_buffer.bufcount := first_deleted_position - 1
- + positions_to_move ;
- which_buffer.fixed_cursor.line_start := first_deleted_position ;
- last_deleted_position := first_deleted_position - 1 ;
- end if ;
- end if ;
- end delete_chunk ;
-
- procedure add_start_of_line_to_copy_buffer( last_col:
- in out column_position ) is
- in_first_col : column_position := 1 ;
- in_last_col : column_position := last_col ;
- last_pos : type_buffer_position ;
- ln_length : type_line_length ;
- final_text : type_text_line ;
- txt_to_move : integer ;
- real_leading_spaces : type_leading_spaces ;
- begin -- add_start_of_line_to_copy_buffer
- determine_left_and_right ( in_first_col , in_last_col ) ;
- real_leading_spaces := lines_leading_spaces ;
- case right_place is
- when in_leading => last_pos := 0 ;
- ln_length:= 0 ;
- if last_col > 0 then
- lines_leading_spaces := last_col ;
- end if ;
- when at_stuff_start => last_pos := first_line_character_position ;
- when in_text => last_pos := first_line_character_position
- + last_col
- - real_Leading_Spaces - 1 ;
- when at_text_end
- | past_end_of_line => last_pos := last_line_character_position ;
- last_col := lines_last_column ;
- -- sometime later we might want to include trailing spaces, and
- -- then in that case we would break these into two cases.....
- end case ;
- if last_pos > 0 then
- ln_length := last_pos - first_line_character_position + 1 ;
- end if ;
- if last_col > 0 then
- add_this_line ( lines_leading_spaces ,
- first_line_character_position ,
- last_pos ,
- ln_length , false ) ;
- end if ;
- if should_delete_extra_leading
- -- means that the first line started at the beginning of a line
- and then lines_leading_spaces + 1 >= last_col then
- -- means that the last line ends at the beginning of a line
- if delete_after_copy then
- delete_chunk ;
- if not cursor_backward_line then
- -- should always be able to move back, otherwise, the first and
- -- last lines are not fixed correctly....
- error(" Possibly Fatal Program Error: 1 " ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- -- here, failed to delete the first line of the deletion....
- else
- fix_fixed_cursor ;
- first_deleted_position := which_buffer.fixed_cursor.line_start ;
- last_deleted_position := last_line_character_position + 1 ;
- delete_chunk ; -- gets rid of first line of deletion...
- end if ;
- which_buffer.fixed_cursor.file_line_number := orig_line_number ;
- original_location.column := 0 ;
- end if ;
- return ; -- because we don't need to do anything on a last line...
- end if ;
- If delete_after_copy then
- get_text_line( which_buffer , which_buffer.fixed_cursor.line_start ,
- final_text ) ;
- last_deleted_position := last_line_character_position + 1 ;
- delete_chunk ; -- got rid of that line.....
- -- now, merge first and last lines...
- -- go backward one line...
- if not cursor_backward_line then
- -- should always be able to move back, otherwise, the first and
- -- last lines are not fixed correctly....
- error(" Possibly Fatal Program Error: 1 " ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- -- here, the line where the deletion started is still in the
- -- buffer, but the entire line where the deletion stopped is
- -- lost forever.....
- else
- txt_to_move := final_text.data_length - last_col ;
- if txt_to_move > 0 then
- for pn in 1 .. txt_to_move loop
- orig_text.data( orig_text.data_length + pn )
- := final_text.data( last_col + pn ) ;
- end loop ;
- orig_text.data_length := orig_text.data_length + txt_to_move ;
- end if ;
- -- replace the first line no matter what....
- replace_current_text ( orig_text ) ;
- which_buffer.fixed_cursor.file_line_number := orig_line_number ;
- end if ;
- end if ; -- delete after copy
- end add_start_of_line_to_copy_buffer ;
-
- function special_cursor_forward_line ( FirstLn : boolean := false )
- return boolean is
- -- a merging of cursor_forward_line and line_forward for speed...
- ending_position : type_buffer_position ;
- successfull : boolean ;
- pn : type_buffer_position ;
- begin -- special_cursor_forward_line
- if which_buffer.fixed_cursor.line_start + max_bytes_in_line
- >= which_buffer.bufcount - max_bytes_in_line then
- delete_chunk ;
- pop_data( which_buffer , thebot , successfull ) ;
- first_deleted_position := which_buffer.fixed_cursor.line_start ;
- last_deleted_position := first_deleted_position - 1 ;
- if not successfull then
- return false ;
- else
- -- we are here because we have deleted the chunk of text from
- -- memory, and have at the same time managed to move forward
- -- a line if we deleted after the copy.........
- if delete_after_copy and ( not firstln ) then
- -- delete first_deleted_position .. last_deleted_position ...
- -- simply, find out if we are at the end of the buffer...
- -- here, we may need to put back the 0 0 0 ....
- if which_buffer.e_buf(first_deleted_position).data
- = buffer_boundry then
- -- we must put back the empty last line...
- pn := first_deleted_position ;
- -- The following copied from buffer package.....
- which_buffer.e_buf(pn ).data := extended_character( 0) ;
- which_buffer.e_buf(pn+1).data := extended_character( 0) ;
- which_buffer.e_buf(pn+2).data := extended_character( 0) ;
- which_buffer.e_buf(pn+3).data
- :=extended_character(buffer_boundry);
- which_buffer.bufcount := pn + 3 ;
- return false ;
- else
- which_buffer.fixed_cursor.file_line_number
- := which_buffer.fixed_cursor.file_line_number + 1 ;
- return true ;
- end if ;
- end if ;
- end if ;
- end if ;
- ending_position :=
- which_buffer.fixed_cursor.line_start + line_length(
- which_buffer , which_buffer.fixed_cursor.line_start ) + 3 ;
- if which_buffer.e_buf(ending_position).data = buffer_boundry then
- return false ;
- else
- which_buffer.moving_cursor.line_start := ending_position ;
- which_buffer.moving_cursor.file_line_number :=
- which_buffer.fixed_cursor.file_line_number + 1 ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- return true ;
- end if;
- end special_cursor_forward_line ;
-
- begin -- Copy_Text_To_Copy_Buffer
- copy_out_initialize;
- -- now, we need to move (and delete if asked) to second_pos
- orig_line_number := which_buffer.fixed_cursor.file_line_number ;
- get_text_line( which_buffer , which_buffer.fixed_cursor.line_start ,
- orig_text ) ;
- if first_pos.line = second_pos.line then
- -- only a partial line...
- add_partial_line_to_copy_buffer( first_pos.column, second_pos.column );
- else
- orig_col := which_buffer.fixed_cursor.column_offset ;
- add_end_of_line_to_copy_buffer( first_pos.column ) ;
- -- that sends back the first_pos.column which was worked on...
- if first_pos.column > 0 then
- -- zero means at end of line...
- orig_col := first_pos.column ;
- orig_text.data_length := orig_col - 1 ;
- end if ;
- -- note that the first line is not worked with....
- if special_cursor_forward_line ( true ) then
- first_deleted_position := which_buffer.fixed_cursor.line_start ;
- last_deleted_position := first_deleted_position - 1 ;
- loop
- exit when which_buffer.fixed_cursor.file_line_number
- = second_pos.line;
- add_line_to_copy_buffer ;
- if delete_after_copy then
- last_deleted_position := last_line_character_position + 1 ;
- end if ;
- exit when not special_cursor_forward_line ;
- end loop ;
- delete_chunk ;
- if which_buffer.fixed_cursor.file_line_number = second_pos.line then
- add_start_of_line_to_copy_buffer( second_pos.column ) ;
- -- which merges in the orig info.....
- end if ;
- end if ;
- end if ;
- Current_Copy_Data.Present_Copy_Length := next_copy_position ;
- which_buffer.fixed_cursor.buffer_position := 0 ;
- which_buffer.fixed_cursor.column_offset := 0 ;
- jump_to_position ( which_buffer , Original_Location.line ,
- Original_Location.column ,
- false ) ;
- copy_out_finish ;
- exception
- when no_room_to_copy_text =>
- Current_Copy_Data.Present_Copy_Length
- := next_copy_position ;
- which_buffer.fixed_cursor.buffer_position := 0 ;
- which_buffer.fixed_cursor.column_offset := 0 ;
- copy_out_finish ;
- end Copy_Text_To_Copy_Buffer ;
-
- procedure Copy_Text_Back_From_Copy_Buffer ( which_buffer :
- in out an_editor_buffer ) is
- orig_text : type_text_line ;
- orig_col : column_position ;
- orig_lead : column_position ;
- new_text : type_text_line ;
- cblock : block ;
- ok : boolean ;
- buffer_is_open : boolean := false ;
- failed_copy : boolean := false ;
- no_room_to_copy_text : exception ;
- last_out_char_was_dle : boolean := false ;
- orig_line_number : line_number ;
- copy_in_started_at_stuff_start : boolean ;
- delete_first_spaces : boolean ;
- delete_next_spaces : boolean ;
- actual_copy_range : text_range ;
-
- procedure open_for_copy is
- -- special open based upon first items in copy block
- nxt_line_start : type_buffer_position ;
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- begin -- open_for_copy
- orig_line_number := which_buffer.fixed_cursor.file_line_number ;
- get_text_line( which_buffer , which_buffer.fixed_cursor.line_start ,
- orig_text ) ;
- -- the following in case the col is past the right edge of text line
- for posn in orig_text.data_length + 1 .. max_column_number loop
- orig_text.data(posn) := extended_character(32); -- spaces...
- end loop ;
- orig_col := which_buffer.fixed_cursor.column_offset ;
- new_text := orig_text ;
- new_text.data_length := orig_col - 1 ;
- -- now, work on buffer
- get_leading( orig_text , leading , text_first , text_last , text_leng );
- orig_lead := leading ;
- nxt_line_start := which_buffer.fixed_cursor.line_start
- + text_leng + 3 ;
- open_buffer( which_buffer , nxt_line_start ,
- block_size + max_bytes_in_line ) ;
- -- and delete current line...
- which_buffer.first_open_position
- := which_buffer.fixed_cursor.line_start ;
- --
- buffer_is_open := true ;
- copy_in_started_at_stuff_start := text_leng = 0
- or else orig_col <= leading + 1 ;
- if Current_Copy_Data.Copy_Started_At_Stuff_Start then
- -- must check for deleting the line prior to this....
- delete_next_spaces := true ;
- if copy_in_started_at_stuff_start then
- -- here we should move back some spaces....
- new_text.data_length := 0 ;
- orig_col := 1 ;
- delete_first_spaces := false ;
- else
- -- we should skip the leading spaces because we are inside a line
- delete_first_spaces := true ;
- end if ;
- else
- delete_first_spaces := false ; -- we didn't start at a new line...
- end if ;
- end open_for_copy ;
-
- procedure replace_current_text ( also_save_this_many :
- integer := max_bytes_in_line + 2 ) is
- -- the two are to ensure that we have some empty space in the
- -- buffer on the last line.....
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- old_leng : type_line_length ;
- ln_start : type_buffer_position ;
- new_nxt_line : type_buffer_position ;
- successfull : boolean ;
- begin -- replace_current_text
- get_leading ( new_text, leading , text_first , text_last , text_leng ) ;
- ln_start := which_buffer.fixed_cursor.line_start ;
- if ln_start + text_leng + 3 + also_save_this_many
- >= which_buffer.last_open_position then
- -- need to push some data around.......
- -- we have to ensure that we have enough room for both this line
- -- and any final line which might be around.....
- which_buffer.first_open_position := ln_start ;
- if ln_start > block_size then
- push_data( which_buffer , thetop , successfull ) ;
- else
- push_data( which_buffer , thebot , successfull ) ;
- end if ;
- if not successfull then
- error( "Unable to Add Copy Text. No Temporary File Room.",
- not_fatal_error , operator_wait , short_beep ) ;
- raise no_room_to_copy_text ;
- else
- ln_start := which_buffer.fixed_cursor.line_start ;
- end if ;
- end if ;
- -- guaranteed to have some room available...
- new_nxt_line := ln_start + text_leng + 3 ;
- which_buffer.e_buf(ln_start).data
- := extended_character(text_leng) ;
- which_buffer.e_buf(ln_start+1 ).data
- := extended_character(leading) ;
- for place in 1 .. text_leng loop
- which_buffer.e_buf(ln_start + 1 + place ).data :=
- new_text.data(text_first+place-1) ;
- end loop ;
- which_buffer.e_buf(ln_start + text_leng + 2 ).data
- := extended_character(text_leng) ;
- for place in ln_start .. ln_start + text_leng + 2 loop
- which_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- which_buffer.fixed_cursor.line_start :=ln_start + text_leng + 3 ;
- which_buffer.fixed_cursor.file_line_number
- := which_buffer.fixed_cursor.file_line_number + 1 ;
- new_text.data_length := 0 ;
- which_buffer.first_open_position :=which_buffer.fixed_cursor.line_start;
- end replace_current_text ;
-
- procedure add_in_new_character ( c : extended_character ) is
- spaces_out : integer := 0 ;
- begin -- add_in_new_character
- if last_out_char_was_dle then
- -- this is a blank compression code
- if delete_first_spaces then
- -- here if we had an old set of spaces at the beginning of
- -- a copy ...
- delete_first_spaces := false ;
- else
- spaces_out := integer(c);
- loop
- exit when new_text.data_length = max_column_number ;
- exit when spaces_out < 1 ; -- in the case of <dle><0>....
- new_text.data_length := new_text.data_length + 1 ;
- new_text.data( new_text.data_length )
- := extended_character( character'pos( ' ' ) ) ;
- spaces_out := spaces_out - 1 ;
- end loop ;
- end if ;
- last_out_char_was_dle := false ;
- elsif c = extended_character( character'pos( ascii.cr ) ) then
- -- this is the end of a line.....
- delete_first_spaces := false ;
- replace_current_text ;
- elsif c = extended_character( character'pos( ascii.dle) ) then
- last_out_char_was_dle := true ;
- else
- -- just a normal output character ...
- delete_first_spaces := false ;
- if new_text.data_length < max_column_number then
- -- we can add a new character
- new_text.data_length := new_text.data_length + 1 ;
- new_text.data( new_text.data_length ) := c ;
- -- else we ignore.....might later give an error message
- end if ;
- end if ;
- end add_in_new_character ;
-
- procedure merge_block ( first_loc , last_loc : block_offset ) is
- begin -- merge_block
- -- merge in data from cblock...
- for posn in first_loc .. last_loc loop
- add_in_new_character( cblock( posn ).data ) ;
- -- note that any attributes are lost here......
- end loop ;
- end merge_block ;
-
- procedure close_for_copy is
- -- here, we must take New_Text.Data from 1 .. New_Text.Data_Length
- -- as the final line which is to be input.... To that, we must
- -- append Orig_Text.Data from Orig_Col .. Orig_Text.Data_Length
- -- however, if failed_copy....don't try to push it.....
- -- otherwise, we might try to raise no_room_to_copy_text....
- -- note that if we have not yet failed, then the replace...(0)
- -- cannot fail!!!
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- last_col : column_position ;
- begin -- close_for_copy
- last_out_char_was_dle := false ;
- -- that was done just in case...however, that should NEVER have been
- -- set to true when this close is called.......except possibly if
- -- an exception was raised....
- last_col := new_text.data_length ;
- if Current_Copy_Data.Copy_Started_At_Stuff_Start
- and then Current_Copy_Data.Copy_Ended_At_Stuff_Start
- and then copy_in_started_at_stuff_Start then
- -- we must insert the line without the ending leading spaces ...
- new_text.data_length := 0 ; -- eats the leading at the end...
- end if ;
- for posn in orig_col .. Orig_Text.Data_Length loop
- add_in_new_character( Orig_Text.Data(posn) ) ;
- end loop ;
- -- now, we must add in the new characters only if there is
- -- text there to do it to...
- get_leading ( new_text, leading , text_first , text_last , text_leng ) ;
- -- now, see what we should do..
- if text_leng = 0 then
- -- ok, there is nothing here to add in.....
- if orig_line_number = which_buffer.fixed_cursor.file_line_number then
- -- ok, if we just added spaces....then add them in...
- replace_current_text(0);
- else
- -- else, if we added at least a line, and now have nothing, throw
- -- the remainder away....
- -- last_col := 0 ;
- --
- -- that didn't seem right, here we just replace it...
- replace_current_text(0);
- end if ;
- else
- -- ok, there is something here to add in ...
- replace_current_text(0);
- end if ;
- which_buffer.first_open_position :=which_buffer.fixed_cursor.line_start;
- close_buffer( which_buffer ) ;
- actual_copy_range.lo_position := ( orig_line_number , orig_col ,
- no_screen_attribute , which_buffer );
- actual_copy_range.hi_position := ( which_buffer.fixed_cursor
- .file_line_number , last_col ,
- no_screen_attribute , which_buffer );
- markers.marker_manager.update_markers_for_added_text(
- which_buffer , actual_copy_range ) ;
- end close_for_copy ;
-
- procedure copy_in_finish is
- begin -- copy_in_finish
- -- must move to the correct location and show the screen
- which_buffer.fixed_cursor.buffer_position := 0 ;
- which_buffer.fixed_cursor.column_offset := 0 ;
- jump_to_position ( which_buffer , orig_line_number , orig_col , false );
- if copy_in_started_at_stuff_start then
- which_buffer.fixed_cursor.column_offset :=
- num_leading_spaces(which_buffer,
- which_buffer.fixed_cursor.line_start ) + 1 ;
- end if ;
- show_screen( which_buffer ) ;
- -- , which_buffer.fixed_cursor , orig_screen_line ) ;
- end copy_in_finish ;
-
- begin -- Copy_Text_Back_From_Copy_Buffer
- if not current_copy_data.we_have_copy_data then
- error(" No Copy Buffer Data... " ,
- not_fatal_error , operator_wait , short_beep ) ;
- else
- for block_number in 1 .. Current_Copy_Data.Present_Copy_Block loop
- getblock( cblock , block_number , ok ) ;
- if not ok then
- error(" Unable to correctly read temporary copy file. " ,
- not_fatal_error , operator_wait , short_beep ) ;
- return ;
- else
- if not buffer_is_open then
- open_for_copy ;
- end if ;
- merge_block ( 0 , block_offset'last ) ;
- end if ;
- end loop ;
- if Current_Copy_Data.Present_Copy_Length > 0 then
- if not buffer_is_open then
- open_for_copy ;
- end if ;
- cblock := Current_Copy_Data.The_Copy_Buffer ;
- merge_block( 0, Current_Copy_Data.Present_Copy_Length - 1 );
- end if ;
- if buffer_is_open then
- close_for_copy ;
- end if ;
- copy_in_finish ;
- end if ;
- exception
- when no_room_to_copy_text => failed_copy := true ;
- if buffer_is_open then
- close_for_copy ;
- end if ;
- copy_in_finish ;
- end Copy_Text_Back_From_Copy_Buffer ;
-
- begin -- copy_package
- The_Copy_Data := new Type_Copy_Data ;
- Current_Copy_Data := The_Copy_Data ;
- initialize_copy_package ;
- end copy_package ;
-
- procedure store_reverse ( new_reverse : boolean ) is
- begin -- store_reverse
- reverse_storage := current_reverse ;
- if reverse_storage /= new_reverse then
- set_reverse( new_reverse ) ;
- end if ;
- end store_reverse ;
-
- procedure restore_reverse is
- begin -- restore_reverse
- set_reverse_if_necessary ( reverse_storage ) ;
- end restore_reverse ;
-
- procedure set_direction ( go_forward : boolean ) is
- -- Set the direction arrow at the top left corner
- begin -- set_direction
- store_reverse ( false ) ;
- is_go_forward := go_forward ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- if go_forward then
- put('>');
- else
- put('<');
- end if ;
- restore_reverse ;
- show_cursor;
- end set_direction ;
-
- procedure show_repeat ( repeat_factor : a_repeat_factor ) is
- temp_string : string_library.pstring ;
- begin -- show_repeat
- last_repeat := repeat_factor ;
- if repeat_factor < 0 then
- -- code for once
- repeat_prompt := string_to_pstring("[ Once]");
- elsif repeat_factor = infinity then
- repeat_prompt := string_to_pstring("[Every]");
- else
- temp_string := int_to_str( repeat_factor ) ;
- while length(temp_string) < 5 loop
- temp_string := " " & temp_string ;
- end loop ;
- repeat_prompt := "[" & temp_string & "]" ;
- end if ;
- store_reverse ( false ) ;
- goto_prompt_line_column( master_buffer , 1 , 2 ) ;
- put(repeat_prompt);
- restore_reverse ;
- end show_repeat ;
-
- procedure set_repeat_prompt( is_show_repeat_on : boolean ;
- repeat_factor : a_repeat_factor ) is
- -- If is_show_repeat_on, the set the repeat factor string
- -- as stated in repeat_factor. If it is -1, then set it
- -- as [Once].
- begin -- set_repeat_prompt
- if not is_show_repeat_on then
- repeat_prompt := string_library.blank_line ;
- else
- -- we are showing the repeat factor
- show_repeat( repeat_factor ) ;
- show_cursor;
- end if ;
- end set_repeat_prompt ;
-
- procedure prompt ( prompt_string : in string ) is
- -- show the prompt string in the master buffer
- -- >[Every]
- -- 123456789
- line_posn : integer ;
- begin -- prompt
- prompt_line := string_library.string_to_pstring( prompt_string ) ;
- store_reverse ( false ) ;
- if repeat_prompt /= string_library.blank_line then
- line_posn := 9 ;
- else
- line_posn := 1 ;
- end if ;
- clear_prompt_end_of_line( master_buffer , 1 , line_posn ) ;
- goto_prompt_line_column ( master_buffer , 1 , line_posn ) ;
- for posn in 1 .. length( prompt_line ) loop
- if prompt_line.data(posn) = '{' then
- -- to reverse
- set_reverse(true);
- elsif prompt_line.data(posn) = '}' then
- -- from reverse
- set_reverse(false);
- else
- put( prompt_line.data(posn) );
- end if ;
- end loop ;
- restore_reverse ;
- end prompt ;
-
- procedure set_cursor( which_buffer : in out an_editor_buffer ;
- cursor : in out cursor_position ;
- linestart : in type_buffer_position ;
- line : in line_number ;
- col : in column_position ) is
- -- set the cursor within which_buffer at the specified line and col
- -- note that if the col is not within the text area, then the
- -- cursor's buffer_position is 0.
- -- if col is sent as 0 , then move to the first text position on line
- the_leading_spaces : type_leading_spaces ;
- target_col : column_position ;
- last_col : column_position ;
- begin -- set_cursor
- the_leading_spaces := num_leading_spaces(which_buffer,linestart);
- last_col := the_leading_spaces
- + line_length(which_buffer,linestart);
- if col = 0 then
- -- we want to go to the first text on line
- target_col := the_leading_spaces + 1 ;
- else
- target_col := col ;
- end if ;
- if target_col <= the_leading_spaces then
- cursor.buffer_position := 0 ; -- not specified
- elsif target_col > last_col then
- cursor.buffer_position := 0 ; -- Past right end
- else
- cursor.buffer_position := linestart + target_col
- - the_leading_spaces + 1 ;
- -- the + 1 is for skipping the <leading-spaces> position
- end if ;
- cursor.file_line_number:= line ;
- cursor.line_start := linestart ;
- cursor.column_offset := target_col;
- end set_cursor ;
-
- procedure just_show_screen( which_buffer : in out an_editor_buffer ) is
- -- Given the current screen definition, show the entire
- -- screen within the current window.
- -- only called when we know we are on the screen
- -- don't worry about cursor
- starting_position : type_buffer_position ;
- current_window_line ,
- last_window_line : window_line_number ;
- current_line_number : line_number ;
- begin -- just_show_screen
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := which_buffer.top_screen_cursor ;
- current_line_number := which_buffer.top_screen_cursor
- .file_line_number ;
- current_window_line := 1 ;
- last_window_line := window_height(which_buffer);
-
- clear_window( which_buffer ) ;
- loop
- starting_position := which_buffer.fixed_cursor.line_start ;
- show_line( which_buffer , starting_position , current_line_number ) ;
- line_forward( which_buffer );
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- current_line_number := current_line_number + 1 ;
- current_window_line := current_window_line + 1 ;
- exit when ( current_window_line > last_window_line ) ;
- end loop ;
- which_buffer.fixed_cursor := which_buffer.floating_cursor ;
- end just_show_screen ;
-
- procedure show_screen( which_buffer : in out an_editor_buffer ) is
- -- Given the current screen definition, show the entire
- -- screen within the current window.
- begin -- show_screen
- if not cursor_off_screen(which_buffer) then
- just_show_screen( which_buffer ) ;
- end if ;
- show_cursor(which_buffer);
- end show_screen ;
-
- procedure show_screen( which_buffer : in out an_editor_buffer ;
- cursor : in out cursor_position ;
- Cursor_Line : in window_line_number ) is
- -- Given the current screen definition, show the entire
- -- screen within the current window.
- -- The cursor is to be put on cursor_line if possible.
- -- Note: cursor might be found as both CURSOR and
- -- WHICH_BUFFER.fixed_CURSOR
- begin -- show_screen
- which_buffer.fixed_cursor := cursor ;
- memory_center( which_buffer , cursor_line ) ;
- if not cursor_off_screen(which_buffer) then
- just_show_screen( which_buffer ) ;
- -- else is caught in show_cursor...
- end if ;
- show_cursor( which_buffer ) ;
- cursor := which_buffer.fixed_cursor ;
- end show_screen ;
-
- procedure adjust_cursor_lines( which_buffer : in out an_editor_buffer ;
- number_of_lines : integer ) is
- old_position : type_buffer_position ;
- begin -- adjust_cursor_lines
- if number_of_lines > 0 then
- -- we are moving forward ;
- set_cursor_down_lines( which_buffer ,
- which_buffer.top_screen_cursor ,
- which_buffer.top_screen_cursor ,
- number_of_lines ) ;
- set_cursor_down_lines( which_buffer ,
- which_buffer.next_screen_cursor ,
- which_buffer.next_screen_cursor ,
- number_of_lines ) ;
- else
- set_cursor_up_lines ( which_buffer ,
- which_buffer.top_screen_cursor ,
- which_buffer.top_screen_cursor ,
- - number_of_lines ) ;
- set_cursor_down_lines( which_buffer ,
- which_buffer.top_screen_cursor ,
- which_buffer.next_screen_cursor ,
- window_height(which_buffer) ) ;
- end if ;
- end adjust_cursor_lines ;
-
- procedure scroll_up ( which_buffer : in out an_editor_buffer ;
- bottom_cursor: in cursor_position ;
- number_of_lines : integer ) is
- -- bottom_line is the start of the next line to output
- -- number_of_lines is the number to work with
- -- top_screen_cursor.line_start does not have to be set...
- old_line_number : line_number ;
- lines_moved : integer ;
- begin -- scroll_up
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- old_line_number := bottom_cursor.file_line_number ;
- which_buffer.fixed_cursor := bottom_cursor ;
- -- First, put out the new lines
- lines_moved := 0 ;
- scroll_up_entire_window( number_of_lines ) ;
- while lines_moved < number_of_lines loop
- goto_line_column( which_buffer , window_height(which_buffer)
- - number_of_lines + lines_moved + 1 ,
- lowest_column_number(which_buffer) ) ;
- show_line(which_buffer,which_buffer.fixed_cursor.line_start ,
- old_line_number ,false);
- line_forward( which_buffer ) ;
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- lines_moved := lines_moved + 1 ;
- old_line_number := old_line_number + 1 ;
- end loop ;
- -- adjust assumes a good starting location for top/next screen cursors
- which_buffer.fixed_cursor := which_buffer.floating_cursor ;
- adjust_cursor_lines( which_buffer , number_of_lines ) ;
- end scroll_up ;
-
- procedure show_cursor is
- -- move the actual cursor to the position on the screen where the
- -- master buffer's logical cursor is
- begin -- show_cursor
- show_cursor( master_buffer ) ;
- end show_cursor ;
-
- procedure show_cursor ( which_buffer : in out an_editor_buffer ) is
- -- Show the cursor on the screen. If necessary, push/pop
- -- data to make sure you have enough for the entire screen
- new_line : window_line_number ;
- new_col : window_column_number ;
- please_redo_screen : boolean := false ;
-
- procedure go_up_lines ( which_buffer : in out an_editor_buffer ;
- number_of_lines : integer ) is
- -- add the appropriate number of lines to the beginning of the
- -- screen .
- begin -- go_up_lines
- if please_redo_screen or else
- ( number_of_lines > window_height( which_buffer ) / 2 ) then
- -- just center the cursor
- memory_center ( which_buffer , window_height(which_buffer) / 2 ) ;
- -- Now that we have fixed it, show the screen
- just_show_screen( which_buffer ) ;
- please_redo_screen := false ;
- else
- -- we can add just a few????
- -- We might use insert if the crt has it........LATER!
- memory_center ( which_buffer , window_height(which_buffer) / 2 ) ;
- -- Now that we have fixed it, show the screen
- just_show_screen( which_buffer ) ;
- end if ;
- end go_up_lines ;
-
- procedure show_scroll ( which_buffer : in out an_editor_buffer ;
- first_line_to_show ,
- last_line_to_show : line_number ) is
- save_cursor : cursor_position ; -- because we know that no
- -- disk access can take place
- -- during this procedure
- begin -- show_scroll
- -- save the current status
- save_cursor := which_buffer.fixed_cursor ;
- -- then, scroll the screen
- scroll_up_entire_window( last_line_to_show - first_line_to_show + 1 ) ;
- -- and then, display the text
- -- find the first line to work
- if which_buffer.next_screen_cursor.line_start = 0 then
- -- need to do it differently
- set_cursor_down_lines( which_buffer ,
- which_buffer.top_screen_cursor ,
- which_buffer.moving_cursor ,
- first_line_to_show
- - which_buffer.top_screen_cursor
- .file_line_number ) ;
- else
- set_cursor_up_lines ( which_buffer ,
- which_buffer.next_screen_cursor ,
- which_buffer.moving_cursor ,
- which_buffer.next_screen_cursor.file_line_number
- - first_line_to_show ) ;
- end if ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- -- loop through, displaying the lines
- loop
- show_line(which_buffer,which_buffer.fixed_cursor.line_start,
- which_buffer.fixed_cursor.file_line_number ) ;
- line_forward( which_buffer ) ;
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- exit when which_buffer.fixed_cursor.file_line_number =
- which_buffer.next_screen_cursor.file_line_number ;
- end loop ;
- which_buffer.fixed_cursor := save_cursor ;
- end show_scroll ;
-
- procedure go_down_lines ( which_buffer : in out an_editor_buffer ;
- number_of_lines : integer ) is
- -- place the appropriate number of lines at the end of the screen
- next_line_on_screen : line_number ;
- begin -- go_down_lines
- if please_redo_screen or else
- ( number_of_lines > window_height ( which_buffer ) ) then
- -- we need to redraw the screen
- memory_center ( which_buffer , window_height ( which_buffer ) / 2 );
- just_show_screen( which_buffer ) ;
- please_redo_screen := false ;
- else
- -- just add lines
- next_line_on_screen := which_buffer.top_screen_cursor.file_line_number
- + window_height ( which_buffer ) ;
- -- show_buffer ( 'V' ) ;
- memory_center( which_buffer , window_height ( which_buffer ) ) ;
- -- show_buffer ( 'V' ) ;
- show_scroll ( which_buffer , next_line_on_screen ,
- which_buffer.fixed_cursor.file_line_number );
- -- show_buffer ( 'V' ) ;
- end if ;
- end go_down_lines ;
-
- begin -- show_cursor
- -- scroll as appropriate
- if not cursor_off_screen(which_buffer) then
- -- that also sets top_screen_cursor.line_start if necessary
- -- we get here with nothing to do..... still on screen
- null ; -- not off screen . nothing to do
- else
- -- First, we will check horizontal
- if which_buffer.fixed_cursor.column_offset
- < lowest_column_number(which_buffer) then
- -- the left screen position is protected by shift itself,
- -- so there is no need to worry about going too far in one
- -- direction
- shift( which_buffer , max ( 15 , lowest_column_number(which_buffer)
- - which_buffer.fixed_cursor.column_offset)
- + 5 ) ;
- -- Now that we have fixed it, show the screen
- please_redo_screen := true ;
- elsif which_buffer.fixed_cursor.column_offset
- > highest_column_number(which_buffer) then
- shift( which_buffer,-max(15 , which_buffer.fixed_cursor.column_offset
- - highest_column_number(which_buffer)
- + 5 ));
- -- Now that we have fixed it, show the screen
- please_redo_screen := true ;
- end if ;
- -- Now, check vertical
- if which_buffer.top_screen_cursor.line_start = 0 then
- -- must show everything from scratch...
- memory_center ( which_buffer , window_height(which_buffer) / 2 ) ;
- -- Now that we have fixed it, show the screen
- just_show_screen( which_buffer ) ;
- elsif which_buffer.fixed_cursor.file_line_number
- < which_buffer.top_screen_cursor.file_line_number then
- -- we have to add lines to the top of the screen
- go_up_lines( which_buffer ,
- which_buffer.top_screen_cursor.file_line_number
- - which_buffer.fixed_cursor.file_line_number ) ;
- elsif which_buffer.fixed_cursor.file_line_number
- > which_buffer.top_screen_cursor.file_line_number
- + window_height(which_buffer)
- - 1 then
- go_down_lines(which_buffer, which_buffer.fixed_cursor.file_line_number
- - which_buffer.top_screen_cursor.file_line_number
- - window_height(which_buffer) + 1 ) ;
- else
- -- we had horizontal but not vertical
- -- don't even need to check please_redo_screen...
- just_show_screen( which_buffer ) ;
- end if ;
- end if ;
- -- now place the cursor where it should be
- new_line := which_buffer.fixed_cursor.file_line_number
- - which_buffer.top_screen_cursor.file_line_number + 1 ;
- new_col := which_buffer.fixed_cursor.column_offset ;
- goto_line_column( which_buffer , new_line , new_col ) ;
- end show_cursor ;
-
- procedure jump_to_position ( which_buffer : in out an_editor_buffer ;
- to_line_number : in line_number ;
- to_column_number : in column_position ;
- show_new_position: in boolean := true ) is
- -- Move the cursor and screen display to the specified
- -- position.
- line : line_number ;
- target_column : column_position ;
- begin -- jump_to_position
- target_column := to_column_number ;
- line := which_buffer.fixed_cursor.file_line_number ;
- if to_line_number > line then
- -- We need to move forward
- loop
- line_forward(which_buffer);
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- -- end of file
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- line := line + 1 ;
- exit when line = to_line_number ; -- found line
- end loop ;
- -- Here on either found line or at end of file
- elsif to_line_number < line then
- -- We need to move backward
- loop
- line_backward(which_buffer);
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- -- end of file
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- line := line - 1 ;
- exit when line = to_line_number ; -- found line
- end loop ;
- -- Here on either found line or at end of file
- end if ;
- -- Now, we need to move to the specified offset
- -- Line is current file line number
- -- Offset is current line start
- if line /= to_line_number then
- target_column := 0 ; -- Just go to first char on line
- end if;
- -- show_buffer ( 'V' ) ;
- -- Target column is the column to go to. If = 0 , then go to
- -- the first text position on the line
- set_cursor(which_buffer,which_buffer.fixed_cursor,
- which_buffer.fixed_cursor.line_start ,
- which_buffer.fixed_cursor.file_line_number ,
- target_column);
- if line /= to_line_number then
- -- we really need to go to the last character on the line
- which_buffer.fixed_cursor.column_offset :=
- which_buffer.fixed_cursor.column_offset
- + line_length( which_buffer ,
- which_buffer.fixed_cursor.line_start ) ;
- which_buffer.fixed_cursor.buffer_position := 0 ;
- end if ;
- if show_new_position then
- show_screen ( which_buffer , which_buffer.fixed_cursor , 0 ) ;
- end if ;
- end jump_to_position ;
-
- function current_position return text_position is
- begin -- current_position
- return text_position'( current_buffer.fixed_cursor.file_line_number ,
- current_buffer.fixed_cursor.column_offset ,
- no_screen_attribute ,
- current_buffer);
- end current_position ;
-
- function cursor_forward_line return boolean is
- -- return true if we moved forward a line like we were asked
- begin -- cursor_forward_line
- line_forward( master_buffer ) ;
- if master_buffer.fixed_cursor = master_buffer.moving_cursor then
- -- we didn't move
- return false ;
- else
- -- we moved...
- master_buffer.fixed_cursor := master_buffer.moving_cursor ;
- return true ;
- end if ;
- end cursor_forward_line ;
-
- function cursor_backward_line return boolean is
- -- return true if we moved backward a line like we were asked
- begin -- cursor_backward_line
- line_backward( master_buffer ) ;
- if master_buffer.fixed_cursor = master_buffer.moving_cursor then
- -- we didn't move
- return false ;
- else
- -- we moved...
- master_buffer.fixed_cursor := master_buffer.moving_cursor ;
- return true ;
- end if ;
- end cursor_backward_line ;
-
- procedure get_leading ( txt : in out type_text_line ;
- leading_spaces : out type_leading_spaces ;
- first_text_position,
- last_text_position:out type_text_length ;
- length : out type_line_length ) is
- -- take a txt line and get facts necessary for insertion into
- -- the buffer. truncate any values necessary to force it to
- -- be a valid line...
- leading , text_first , text_last , text_leng : integer ;
- -- because we error check after assigning values
- begin -- get_leading
- text_first := 1 ;
- while ( text_first <= txt.data_length )
- and then ( txt.data(text_first) = extended_character(32) ) loop
- text_first := text_first + 1 ;
- end loop ;
- leading := text_first - 1 ;
- text_last := txt.data_length ;
- text_leng := text_last - text_first + 1 ;
- if text_leng > type_line_length'last then
- text_leng := type_line_length'last;
- text_last := text_first + text_leng - 1 ;
- end if ;
- if leading > type_leading_spaces'last then
- leading := type_leading_spaces'last ;
- end if ;
- txt.leading_spaces := leading ;
- leading_spaces := leading ;
- first_text_position := text_first ;
- last_text_position := text_last ;
- length := text_leng ;
- end get_leading ;
-
- procedure get_next_command( Old_Repeat : in a_repeat_factor ;
- New_Repeat : out a_repeat_factor ;
- new_command : out an_editor_command ) is
- main_prompt_on : boolean := true ;
- TmpCmd : an_editor_command ;
- redo_once : boolean ;
- Tmp_New_Repeat : a_repeat_factor ;
-
- procedure get_repeat_factor_and_command is
- n: INTEGER;
- overflow: BOOLEAN;
- ch : character ;
- new_num : integer ;
- begin
- crt_windows.get_character ( ch , TmpCmd ) ;
- case TmpCmd is
- when infinity_command =>
- set_repeat_prompt( true , infinity );
- Tmp_New_Repeat := infinity ;
- redo_once := true ;
- when digit_command =>
- overflow := false;
- n := 0 ;
- loop
- new_num := character'pos (ch)-character'pos ('0');
- if n > a_repeat_factor'last / 10 then
- overflow := true ;
- else
- n := n * 10 ;
- if a_repeat_factor'last - new_num - 1 < n then
- -- the -1 is because we use
- -- the 'last as infinity
- overflow := true ;
- else
- n := n + new_num ;
- set_repeat_prompt( true , n ) ;
- crt_windows.get_character( ch , TmpCmd ) ;
- end if ;
- end if ;
- exit when ( TmpCmd /= digit_command ) or overflow;
- end loop ;
- if overflow then
- error( " Repeat Factor Too Large " ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- set_repeat_prompt( true , -1 ) ;
- Tmp_New_Repeat := 1 ;
- TmpCmd := illegal_command ;
- else
- Tmp_New_Repeat := n ;
- end if;
- redo_once := true ;
- if TmpCmd = infinity_command then
- set_repeat_prompt( true , infinity );
- Tmp_New_Repeat := infinity ;
- end if ;
- when others => null ;
- end case ;
- end get_repeat_factor_and_command ;
-
- begin -- get_next_command
- redo_once := false ;
- if ( Old_Repeat /= 1 ) then
- set_repeat_prompt( true , -1 ) ;
- end if ;
- Tmp_New_Repeat := 1 ;
- loop
- if need_prompt then
- if main_prompt_on then
- set_repeat_prompt ( true , -1 ) ;
- prompt(main_command_prompt);
- else
- set_repeat_prompt ( true , -1 ) ;
- prompt(alternate_command_prompt);
- end if ;
- need_prompt:=false;
- show_cursor;
- end if ;
- get_repeat_factor_and_command ;
- if TmpCmd = show_other_prompt_command
- and then allow_alternate_prompt_command then
- main_prompt_on:=not main_prompt_on;
- need_prompt:=true;
- end if ;
- exit when (TmpCmd /= show_other_prompt_command)
- and (TmpCmd /= illegal_command)
- and (TmpCmd /= infinity_command) ;
- end loop ;
- need_prompt := (not main_prompt_on) or need_prompt ;
- -- we need to prompt later if we left it off....
- new_command := TmpCmd ;
- if redo_once and Tmp_New_Repeat = 1 then
- -- they typed 1 in by themselves, and now we really should
- -- redisplay once
- set_repeat_prompt( true , -1 ) ;
- end if ;
- New_Repeat := Tmp_New_Repeat ;
- end get_next_command ;
-
- begin -- editor_misc
- -- EDITMISC by SAIC/Clearwater Misc Editor Routines 22 Jan 85
- null ;
- end editor_misc ;
-
- --$$$- EDITMISC
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --debug
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ DEBUG
-
- with text_io ;
- use text_io ;
-
- --
- -- File 010
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Debug Routines Written Januaray 1985, Robert S. Cymbalski
- --
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
- use basic_io_system ;
-
- with crt_windows ;
- use crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- package debugger is
-
- procedure pause ;
-
- procedure show_buffer ( debug_opt : in character := ascii.nul ) ;
-
- end debugger ;
-
- package body debugger is
-
- procedure pause is
- c : character ;
- spec : an_editor_command ;
- begin -- pause
- basic_io_system.put(" Enter <space> to continue ");
- get_character( c , spec ) ;
- end pause ;
-
- procedure show_buffer ( debug_opt : in character := ascii.nul ) is
-
- users_opt : character ;
-
- procedure show_c ( val , len : integer ) is
- begin
- if val < 0 then
- -- impossible
- basic_io_system.put(" XXX");
- elsif val < 32 then
- -- control character
- -- basic_io_system.put(" ^");
- -- basic_io_system.put( character'val( val + 64 ) ) ;
- basic_io_system.put(val,len);
- elsif val < 127 then
- basic_io_system.put(" """);
- basic_io_system.put( character'val(val));
- elsif val <= 999 then
- basic_io_system.put(val,len);
- else
- basic_io_system.put(" XXX");
- end if ;
- end show_c ;
-
- procedure show_values ( b : in an_editor_buffer ) is
-
- procedure show_x ( c : in cursor_position ) is
- begin -- show_x
- basic_io_system.put( c.line_start , 5 ) ;
- basic_io_system.put(" [");
- basic_io_system.put( c.file_line_number , 5 ) ;
- basic_io_system.put(" /");
- basic_io_system.put( c.column_offset , 3 ) ;
- basic_io_system.put(" ] ");
- basic_io_system.put( c.buffer_position , 6 ) ;
- basic_io_system.put_line ;
- end show_x ;
-
- procedure ot ( s : string ; n : integer ) is
- begin
- text_io.put( s ) ;
- basic_io_system.put( n , 5 ) ;
- basic_io_system.put_line ;
- end ;
-
- begin
- basic_io_system.put_line;
- basic_io_system.put(" Buffer Num ");
- basic_io_system.put(b.buffer_number,2) ;
- basic_io_system.put_line;
- if b.still_reading_input_file then
- basic_io_system.put(" Reading Input File");
- else
- basic_io_system.put(" Done Reading Input File ");
- end if ;
- basic_io_system.put_line ;
- ot ( " Present Top Block " , b.prestopblock ) ;
- ot ( " Present Bot Block " , b.presbotblock ) ;
- -- ot ( " Present Cpy Block " , b.prescopyblock) ;
- -- ot ( " Present Cpy Leng " , b.prescopylen ) ;
- ot ( " Bufcount " , b.bufcount ) ;
- if b.open_buffer_area then
- ot ( " First Open Positn " , b.first_open_position);
- ot ( " Last Open Positin " , b.last_open_position);
- else
- ot ( " Buffer Closed " , 0 ) ;
- end if ;
- basic_io_system.put(" Top Cursor "); show_x( b.top_screen_cursor ) ;
- basic_io_system.put(" Nxt Cursor "); show_x( b.next_screen_cursor) ;
- basic_io_system.put(" Fxd Cursor "); show_x( b.fixed_cursor ) ;
- basic_io_system.put(" Mov Cursor "); show_x( b.moving_cursor ) ;
- basic_io_system.put(" Flt Cursor "); show_x( b.floating_cursor ) ;
- basic_io_system.put(" Buf Count "); basic_io_system.put( b.bufcount,5) ; basic_io_system.put_line;
- basic_io_system.put_line;
- end ;
-
- procedure show_insides( e : t_buffer ; start : type_buffer_position ;
- lowest , highest : type_buffer_position ) is
- do_length : integer := 320 ;
- p1 , p2 : type_buffer_position ;
- ln_start , ln_posn : type_buffer_position ;
- begin
- if start - do_length / 2 < lowest then
- p1 := lowest ;
- else
- p1 := start - do_length / 2 ;
- end if ;
- if p1 + do_length - 1 > highest then
- p2 := highest ;
- do_length := highest - lowest + 1 ;
- else
- p2 := p1 + do_length - 1 ;
- end if ;
- -- p1 is starting location
- -- p2 is stopping location
- -- do_length is number of positions to do
- basic_io_system.put(" Line Start At ");
- basic_io_system.put(start);
- basic_io_system.put_line;
- basic_io_system.put(" Lowest Is ");
- basic_io_system.put(lowest);
- basic_io_system.put(" Highest Is ");
- basic_io_system.put(highest);
- basic_io_system.put_line ;
- ln_start := p1 ;
- loop
- -- for each group of 16
- basic_io_system.put(ln_start,5);
- basic_io_system.put(" ");
- -- we are working with e.data() which is basic_io_system.extended_character
- ln_posn := ln_start ;
- loop
- show_c( e(ln_posn).data , 4 ) ;
- ln_posn := ln_posn + 1 ;
- exit when ( ln_posn = ln_start + 16 ) or ( ln_posn > p2 ) ;
- end loop ;
- basic_io_system.put_line;
- ln_start := ln_start + 16 ;
- exit when ln_start > p2 ;
- end loop ;
- end;
-
- procedure do_memory is
- type ip is access each_position ;
- i : ip ;
- n : integer ;
- begin
- n := 0 ;
- loop
- for j in 1 .. 100 loop i := new each_position ; end loop ;
- n := n + 1 ;
- basic_io_system.put(n,5);
- exit when n = integer'last ;
- end loop ;
- end;
-
- procedure do_memory_2 is
- type ip is access integer ;
- i : ip ;
- n : integer ;
- begin
- n := 0 ;
- loop
- for j in 1 .. 100 loop i := new integer ; end loop ;
- n := n + 1 ;
- basic_io_system.put(n,5);
- exit when n = integer'last ;
- end loop ;
- end;
-
- function starting_pos ( def : integer ) return integer is
- begin
- basic_io_system.put(" Enter Starting Position => ");
- return get_number( 0 , 0 , 0 , 32767 , 5 , def ) ;
- end ;
-
- function debug_option return character is
- begin -- debug_option
- return char_or_abort ( ' ' , ' ' , 'C' , 'P' , 'R' , 'V' , 'Q' ,
- 'X' , 'B' ) ;
- end debug_option ;
-
- begin
- crt_windows.clear_window( crt_windows.current_window ) ;
- edit_windows.store_shift ;
- users_opt := debug_opt ;
- if users_opt = ascii.nul then
- users_opt := debug_option ;
- end if ;
- loop
- case users_opt is
- when 'C' => do_memory_2 ;
- when 'P' => do_memory ;
- when 'R' => edit_windows.refresh_screen ;
- when 'V' => show_values( current_buffer ) ;
- when 'X' | 'B' |
- 'N' | 'M' => copy_debug ( users_opt ) ;
- when others => show_insides( current_buffer.e_buf ,
- starting_pos (
- current_buffer.fixed_cursor.line_start),
- 0,
- current_buffer.bufcount);
- end case ;
- basic_io_system.put_line;
- basic_io_system.put(" Enter New Debug Option ? ");
- users_opt := debug_option ;
- exit when users_opt = 'Q' ;
- end loop ;
- edit_windows.restore_shift ;
- end show_buffer ;
-
- begin -- debugger
- -- DEBUG by SAIC/Clearwater Debugger Routines 22 Jan 85
- null ;
- end debugger ;
-
- --$$$- DEBUG
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editfind
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITFIND
-
- --
- -- File 017
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_general ;
- use buffer_lines ;
-
- with edit_windows ;
- use edit_windows ;
-
- with markers ;
- use markers ;
-
- with editor_misc ;
- use editor_misc ;
-
- package editor_Find is
-
- procedure do_find_command ( go_forward : in boolean ;
- Repeat_Factor : a_repeat_factor ;
- returned_command : in out an_editor_command ) ;
-
- longest_search_target : constant integer := 255 ;
- subtype search_target_index is integer range 0 .. longest_search_target ;
- type a_target is array ( search_target_index range
- 1 .. longest_search_target) of extended_character ;
- Search_Target_Defined : boolean := false ;
- Search_Target : a_target ;
- Search_Target_Length : Type_Line_Length := 0 ;
- Replace_String_Defined: boolean := false ;
- Replace_String : a_target ;
- Replace_String_Length : Type_Line_Length := 0 ;
-
- end ;
-
- package body editor_find is
-
- Token_Kind : array ( extended_character ) of extended_character ;
- Kind_Alpha_Numeric : constant Extended_Character :=
- extended_character( character'pos('A') ) ;
-
- procedure do_find_command ( go_forward : in boolean ;
- Repeat_Factor : a_repeat_factor ;
- returned_command : in out an_editor_command ) is
-
- find_exit : exception ;
- reject_cmd : exception ;
- type type_Find_Mode is (Literal_Mode,Token_Mode) ;
- Find_Mode : type_Find_Mode ;
- Do_A_Case_Sensitive_Search : boolean ;
- Number_Found_So_Far : a_repeat_factor := 0 ;
- Verify_Each_Replacement : boolean := false ;
- Users_String_Delimiter : extended_character ;
- Minimum_Displacement_Of_Character_From_End_Of_Search_String :
- array ( extended_character ) of integer ;
- -- displacement of character from end
- Multiple_Character_Match_Displacement_Amount :
- array( search_target_index range
- 0 .. longest_search_target ) of integer ;
- -- displacement for double letters
- The_Search_Target : a_target ;
- The_Replacement_String : a_target ;
- Search_String_Length : search_target_index ;
- Replacement_String_Length : search_target_index ;
- Last_Find_Location : text_position := no_set_location ;
- Old_Find_Location : text_position := no_set_location ;
- User_Find_Character : Character ;
- User_Find_Extended_Character : Extended_Character ;
- User_Find_Editor_Command : an_editor_command ;
- Screen_Is_Not_Erased : boolean := true ;
- Use_Last_Entered_String : boolean := false ;
-
- Fixed_Cursor_Line_Start : type_buffer_position ;
- Fixed_Cursor_Buffer_Position : type_buffer_position ;
- First_Line_Character_Position : type_buffer_position ;
- Last_Line_Character_Position : type_buffer_position ;
- Lines_Leading_Spaces : type_leading_spaces ;
- Lines_Last_Column : column_position ;
- Lines_Text_Length : type_line_length ;
-
- target_found : boolean ;
- current_leading : type_leading_spaces ;
-
- procedure get_c_or_cmd( c : out character ;
- cmd: out editor_globals.an_editor_command ) is
- -- get either a printable character or else get an editor command...
- -- note that here, printable characters take priority over commands
- physical_c : character ;
- physical_command : crt.special_keys ;
- begin -- get_c_or_cmd
- crt_windows.key_input( physical_c , physical_command ) ;
- if physical_command = key_character
- and then physical_c in ' ' .. '~' then
- -- easy... is just a printable character ...????
- c := physical_c ;
- cmd := editor_customization.illegal_command ;
- -- I really wanted to use editor_globals.illegal_command.......
- else
- -- need to find out what it might be...
- translate( physical_c , physical_command , c , cmd ) ;
- end if ;
- end get_c_or_cmd ;
-
- function e_character( c : character ) return extended_character is
- begin -- e_character
- return extended_character( character'pos( c ) ) ;
- end e_character ;
-
- Procedure Get_Next_Character_Of_Find_Command is
- begin
- get_c_or_cmd( User_Find_Character , User_Find_Editor_Command ) ;
- User_Find_Extended_Character := e_character ( User_Find_Character ) ;
- If User_Find_Editor_Command = left_command then
- null ; -- put(ascii.bs);
- elsif User_Find_Editor_Command = backward_character_command then
- null ; -- put(ascii.bs);
- elsif User_Find_Character /= ascii.nul then
- put(User_Find_Character) ;
- elsIf User_Find_Editor_Command = advance_line_command then
- User_Find_Editor_Command := Illegal_Command ;
- -- NOTE: For now, we do not allow <cr> to be in a find target
- -- or a replacement string......
- -- To reinstate, simply un_comment out these lines and comment out
- -- the line turning the command illegal. Then, you'll need to
- -- correctly search past <eol> , and also correctly add
- -- multiple lines in the replace routines
- -- If Screen_Is_Not_Erased then
- -- Screen_Is_Not_Erased := false ;
- -- clear_window( master_buffer ) ;
- -- goto_line_column( master_buffer , 1 , 1 ) ;
- -- else
- -- put(ascii.cr);
- -- end if ;
- end if ;
- end Get_Next_Character_Of_Find_Command ;
-
- Procedure Skip_Blanks is
- begin
- while (User_Find_Character = ' ')
- or else ( (User_Find_Character = ascii.nul )
- and ( User_Find_Editor_Command /= reject_command ) ) loop
- Get_Next_Character_Of_Find_Command ;
- end loop ;
- end Skip_Blanks ;
-
- function map_up ( c : character ) return character is
- begin -- map_up
- if c in 'a' .. 'z' then
- return character'val( character'pos(c)
- - character'pos('a')
- + character'pos('A') ) ;
- else
- return c ;
- end if ;
- end map_up ;
-
- function map_up ( c : extended_character ) return extended_character is
- -- extended character set is the ascii representation...
- begin -- map_up
- if c in extended_character(97) .. extended_character(97 + 25) then
- return extended_character( c - 32 ) ;
- else
- return c ;
- end if ;
- end map_up ;
-
- Procedure Process_Command_Line_Options is
- begin
- User_Find_Character := map_up(User_Find_Character) ;
- while (User_Find_Character = 'L')
- or (User_Find_Character = 'T')
- or (User_Find_Character = 'V')
- or (User_Find_Character = 'C')
- or (User_Find_Character = 'I') loop
- case User_Find_Character is
- when 'L' => Find_Mode := Literal_Mode ;
- when 'T' => Find_Mode := Token_Mode ;
- when 'V' => Verify_Each_Replacement := true ;
- when 'C' => Do_A_Case_Sensitive_Search := true ;
- when 'I' => Do_A_Case_Sensitive_Search := false ;
- when others => null ;
- end case ;
- Get_Next_Character_Of_Find_Command ;
- User_Find_Character := map_up(User_Find_Character) ;
- end loop ;
- Skip_Blanks ;
- if (User_Find_Character='S') or (User_Find_Character='s') then
- Use_Last_Entered_String := true ;
- end if ;
- end Process_Command_Line_Options ;
-
- function Tok_Kind ( c : character ) return extended_character is
- begin -- tok_kind
- return token_kind( extended_character( character'pos( c ) ) ) ;
- end tok_kind ;
-
- Procedure Parse_string ( pattern : in out a_target ;
- plength : in out integer) is
- Total_Pattern_Length : integer := 0 ;
- begin
- Skip_Blanks ; -- to get the first delimiter
- if token_kind( user_find_extended_character ) = tok_kind('A')
- or else User_Find_Character = ascii.nul then
- -- error, we don't allow alpha-numerics
- error("Invalid Delimiter.", not_fatal_error ,
- operator_wait , extra_short_beep ) ;
- User_Find_Character := ascii.nul ;
- User_Find_Extended_Character := e_character( ascii.nul ) ;
- User_Find_Editor_Command := reject_command ;
- end if ;
- if User_Find_Character = ascii.nul then
- -- do nothing ...
- plength := 0 ;
- else
- Users_String_Delimiter := User_Find_Extended_Character ;
- Total_Pattern_Length := 0 ;
- loop
- Get_Next_Character_Of_Find_Command ;
- if User_Find_Editor_Command = left_command
- or else User_Find_Editor_Command = backward_character_command then
- if (pattern(Total_Pattern_Length) /= e_character(ascii.cr) )
- and (Total_Pattern_Length>0) then
- put(ascii.bs) ;
- put(' ') ;
- put(ascii.bs) ;
- Total_Pattern_Length := Total_Pattern_Length - 1 ;
- end if ;
- else
- Total_Pattern_Length := Total_Pattern_Length + 1 ;
- if User_Find_Editor_Command = advance_line_command then
- pattern( total_pattern_length ) := e_character(ascii.cr) ;
- else
- pattern(Total_Pattern_Length) := User_Find_Extended_Character ;
- end if ;
- end if ;
- exit when ( User_Find_Extended_Character = Users_String_Delimiter )
- or ( Total_Pattern_Length = Max_Line_Length )
- or ( User_Find_Editor_Command = reject_command ) ;
- end loop ;
- if Total_Pattern_Length = Max_Line_Length then
- error("Your pattern is too long " , not_fatal_error ,
- operator_wait , extra_short_beep ) ;
- User_Find_Character := ascii.nul ;
- User_Find_Extended_Character := e_character( ascii.nul ) ;
- User_Find_Editor_Command := reject_command ;
- end if ;
- plength := Total_Pattern_Length - 1 ; -- do'nt include final Delimiter
- end if ;
- end parse_string ;
-
- Procedure Set_Table is
- pla : integer ;
- -- we set up the table to tell us how far to move before checking
- -- the next character. We do the string in the reverse order that
- -- we will eventually look at it in. This makes sure that we move
- -- the minumin number of characters needed to match again.
-
- Procedure Put_Table ( c : extended_character ; i : integer ) is
- -- put the number into the table for the character c. if case
- -- is not checked, also put it in for the other case.
- begin
- Minimum_Displacement_Of_Character_From_End_Of_Search_String(c):=i;
- if not Do_A_Case_Sensitive_Search then
- if c in extended_character(65) .. extended_character( 65 + 25 ) then
- Minimum_Displacement_Of_Character_From_End_Of_Search_String
- ( c + 32 ) := i ;
- end if ;
- end if ;
- end put_table ;
-
- begin -- set_table
- -- now, this is for case sensitivity
- -- if might slow the process down horribly
- if not Do_A_Case_Sensitive_Search then
- for pla in 1 .. Search_String_Length loop
- The_Search_Target(pla) := map_up( The_Search_Target(pla) ) ;
- end loop ;
- end if ;
- if go_forward then
- for pla in extended_character loop
- Minimum_Displacement_Of_Character_From_End_Of_Search_String(pla)
- := Search_String_Length ;
- end loop ;
- For pla in 1 .. search_string_length - 1 loop
- put_table( The_Search_Target( pla ) , Search_String_Length - Pla ) ;
- end loop ;
- -- that takes care of the individual character
- put_table(The_Search_Target(search_string_length) , Max_Line_Length
- + Max_Line_Length );
- -- set specialty routine for last character
- else
- for pla in extended_character loop
- Minimum_Displacement_Of_Character_From_End_Of_Search_String(pla)
- := (-Search_String_Length) ;
- end loop ;
- -- now we have set all characters to Skip_Blanks the maximum
- -- amount possible
- for pla in reverse 2 .. Search_String_Length loop
- put_table(The_Search_Target(pla), 1-pla) ;
- end loop ;
- put_table( The_Search_Target(1) , Max_Line_Length+Max_Line_Length);
- -- special for last character
- end if ;
- end set_table ;
-
- Procedure Compare_Two is
- begin
- for match_char in 0 .. Max_Line_Length loop
- if go_forward then
- Multiple_Character_Match_Displacement_Amount(match_char) := 1 ;
- else
- Multiple_Character_Match_Displacement_Amount(match_char) := -1 ;
- end if ;
- end loop ;
- end compare_two ;
-
- Procedure put_prompt ( left , right : string ;
- repeat_factor : integer ;
- show_literal_token_prompt : boolean := true ) is
- begin
- clear_prompt(master_buffer) ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- if go_forward then
- put('>') ;
- else
- put('<') ;
- end if ;
- put(left) ;
- put('[') ;
- if repeat_factor = infinity then
- if returned_command = find_command then
- put("Last");
- else
- put("Every") ;
- end if ;
- elsif repeat_factor = 1 then
- put("Next") ;
- else
- put(repeat_factor,1) ;
- end if ;
- put("]:") ;
- if show_literal_token_prompt then
- if Find_Mode=Token_Mode then
- put(" L(it") ;
- else
- put(" T(ok") ;
- end if ;
- if Do_A_Case_Sensitive_Search then
- put(" I(nsens") ;
- else
- put(" C(ase") ;
- end if ;
- end if ;
- put(right) ;
- end put_prompt ;
-
- Procedure Return_Quit_Stop( dd : character ) is
- -- do the desired...
- -- we could also be here on a disk full condition, '!' is the code
- current_leading : type_leading_spaces ;
- begin
- current_leading := num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) ;
- if master_buffer.fixed_cursor.column_offset
- <= current_leading then
- master_buffer.fixed_cursor.column_offset
- := current_leading + 1 ;
- end if ;
- if dd = '!' then
- error("Disk Out Of Space During Find " , not_fatal_error ,
- operator_wait ,short_beep ) ;
- elsif dd = 'C' then
- jump_to_position ( master_buffer ,
- last_find_location.line ,
- last_find_location.column ,
- false ) ;
- end if ;
- current_leading := num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) ;
- if master_buffer.fixed_cursor.column_offset <= current_leading then
- master_buffer.fixed_cursor.column_offset := current_leading + 1 ;
- end if ;
- if ( dd = 'Q' ) or ( dd = '!' ) then
- Returned_Command := quit_command ;
- else
- If not screen_is_not_erased then
- show_screen( master_buffer ) ;
- end if ;
- end if ;
- show_cursor( master_buffer ) ;
- raise find_exit ;
- end return_quit_stop ;
-
- Procedure chk_abort is
- -- this procedure will check to see if an abort has been pressed,
- -- <reject>, and if so will abort the find process and will restore
- -- the screen as is ...
- dd : character ;
- begin
- if basic_io_system.key_is_pressed then
- -- they want our attention...
- clear_prompt( master_buffer ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- put(" Interrupted by user request...");
- get_next_character_of_find_command ;
- if User_Find_Editor_Command = reject_command then
- dd := 'C' ;
- else
- dd := map_up( User_Find_Character ) ;
- end if ;
- if (dd = 'Q') or (dd = 'C') or (dd = 'S') then
- return_quit_stop(dd) ;
- else
- put(ascii.bel);
- end if ;
- end if ;
- end chk_abort ;
-
- Procedure Fix_Fixed_Cursor is
- -- note the boundries of the current line for searching
- begin -- fix_fixed_cursor
- Fixed_Cursor_Line_Start := master_buffer.fixed_cursor.line_start ;
- Lines_Leading_Spaces := num_leading_spaces ( master_buffer ,
- fixed_cursor_line_start ) ;
- Lines_Text_Length := line_length( master_buffer ,
- fixed_cursor_line_start ) ;
- First_Line_Character_Position := Fixed_Cursor_Line_Start + 2 ;
- Last_Line_Character_Position := First_Line_Character_Position
- + Lines_Text_Length - 1 ;
- Lines_Last_Column := Lines_Leading_Spaces
- + Lines_Text_Length ;
- If master_buffer.fixed_cursor.column_offset > lines_last_column then
- if go_forward then
- Fixed_Cursor_Buffer_Position := Last_Line_Character_Position + 1 ;
- else
- -- do this on going backward -- else next line
- Fixed_Cursor_Buffer_Position := Last_Line_Character_Position ;
- -- assumes that we start searching at the current character
- end if ;
- elsif master_buffer.fixed_cursor.column_offset <
- Lines_Leading_Spaces then
- if go_forward then
- Fixed_Cursor_Buffer_Position := First_Line_Character_Position ;
- else
- -- do this only on going forward ..... else prior line
- Fixed_Cursor_Buffer_Position := First_Line_Character_Position - 1 ;
- end if ;
- else
- -- need to set in the middle of the line
- Fixed_Cursor_Buffer_Position := First_line_character_position
- + master_buffer.fixed_cursor
- .column_offset
- - Lines_Leading_Spaces - 1 ;
- end if ;
- end fix_fixed_Cursor ;
-
- Procedure Un_Fix_Fixed_Cursor is
- begin -- un_fix_fixed_cursor
- master_buffer.fixed_cursor.buffer_position
- := fixed_cursor_buffer_position ;
- master_buffer.fixed_cursor.column_offset
- := Lines_Leading_Spaces + fixed_cursor_buffer_position
- - first_line_character_position + 1 ;
- end un_fix_fixed_cursor ;
-
- Procedure find_The_Search_Target ( final_successfull : out boolean ) is
-
- successfull : boolean ;
-
- two_max : constant integer := Max_Line_Length + Max_Line_Length ;
-
- Function search_forward return boolean is
- Search_String_Place : search_target_index ;
- Buffer_Place : integer ;
- -- because we can set values to it temporarily which
- -- would not be valid for type_buffer_position ;
- New_Displacement : integer ;
- New_Multiple_Character_Displacement : integer ;
- Save_Buffer_Place : type_buffer_position ;
- Is_Good : boolean ;
- begin
- Fix_Fixed_Cursor ;
- -- first, tell the cursor to begin looking for the end of the
- -- string starting here...
- Buffer_Place := Fixed_Cursor_Buffer_Position
- + Search_String_Length - 1 ;
- -- the last char of the word could be here at the cursor
- -- position offset by the word length minus one
- loop
- -- here we are looping until we really find it
- loop
- --here we are looping until we either find or fail to find
- -- the first(last) character of the string.
- If Buffer_Place > Last_Line_Character_Position then
- -- past end of line, move to new line ...
- Master_Buffer.Fixed_Cursor.Column_Offset := 0 ; -- use leading sp
- If cursor_forward_line then
- -- we are ready to work this new line
- chk_abort ;
- Fix_Fixed_Cursor ;
- Buffer_Place := First_Line_Character_Position
- + Search_String_Length - 1 ;
- else
- -- unable to move, at end of buffer
- return false ; -- hit end of buffer w/o finding anything
- end if ;
- else
- -- here if still on the same line...... ready to check....
- New_Displacement
- := Minimum_Displacement_Of_Character_From_End_Of_Search_String(
- master_buffer.e_buf(type_buffer_position(Buffer_Place)).data);
- exit when ( New_Displacement = Two_Max ) ;
- -- signal for end of word is found here....
- Buffer_Place := Buffer_Place + New_Displacement ;
- end if ;
- end loop ;
- -- we end up here only when we find a valid last character .....
- Save_Buffer_Place := Buffer_Place ;
- Buffer_Place := Buffer_Place - 1 ; -- move one char back from end
- -- set to look at next character down
- Search_String_Place := Search_String_Length - 1 ;
- -- last already checked
- Is_Good := True ;
- Loop
- Exit When Search_String_Place = 0 ; -- SUCCESS !!!!
- if Do_A_Case_Sensitive_Search then
- Is_Good := The_Search_Target(Search_String_Place)
- = master_buffer.e_buf(type_buffer_position(
- Buffer_Place)).data ;
- else
- Is_Good := The_Search_Target(Search_String_Place)
- = map_up(master_buffer.e_buf(
- type_buffer_position(Buffer_Place)).data) ;
- end if ;
- Exit When Not Is_Good ;
- Search_String_Place := Search_String_Place - 1 ;
- Buffer_Place := Buffer_Place - 1 ;
- end loop ;
- if Is_Good then
- -- We Found The String ....... Return First Character Position
- Fixed_Cursor_Buffer_Position := Buffer_Place + 1 ;
- -- because the above loop went past one ...
- return True ;
- else
- -- found a mismatch
- -- last good character is at Search_String_Place + 1
- New_Multiple_Character_Displacement
- := Minimum_Displacement_Of_Character_From_End_Of_Search_String(
- master_buffer.e_buf(type_buffer_position(Buffer_Place)).data);
- if New_Multiple_Character_Displacement = two_max then
- Buffer_Place := Save_Buffer_Place + 1 ;
- -- we can always move one position.....
- -- ( failed to move more because that character was a success
- -- character for the end of the string
- else
- Buffer_Place:=Buffer_Place + New_Multiple_Character_Displacement ;
- end if ;
- -- This is pretty obvious, at the place where we first did not
- -- have a match, we will attempt to move over the appropriate
- -- number of characters to continue on our way, unless it is
- -- the end of search target character, in which case we will
- -- only move the end_Buffer_Place over one position
- Save_Buffer_Place := Save_Buffer_Place
- + Multiple_Character_Match_Displacement_Amount(
- Search_String_Place ) ;
- -- ok, This says to move over the appropriate number of
- -- characters to match the same String in the Target
- -- it is measured from the end of the string to the new
- -- place we should start checking from
- If Save_Buffer_Place > Buffer_Place then
- Buffer_Place := Save_Buffer_Place ;
- end if ; -- move the furthest of the two choices...
- -- This is the finale ... in that we will move over as much
- -- as possible, based upon knowledge gained from the last
- -- good character or the first bad character
- end if ;
- end loop ;
- end search_forward ;
-
- Function search_backward return boolean is
- Search_String_Place : search_target_index ;
- Buffer_Place : integer ;
- -- because we can set values to it temporarily which
- -- would not be valid for type_buffer_position ;
- New_Displacement : integer ;
- New_Multiple_Character_Displacement : integer ;
- Save_Buffer_Place : type_buffer_position ;
- Is_Good : boolean ;
- begin
- Fix_Fixed_Cursor ;
- -- first, tell the cursor to begin looking for the end of the
- -- string starting here...
- Buffer_Place := Fixed_Cursor_Buffer_Position ; -- first char to check
- -- the last char of the word could be here at the cursor
- -- position offset by the word length minus one
- loop
- -- here we are looping until we really find it
- loop
- --here we are looping until we either find or fail to find
- -- the first(last) character of the string.
- If Buffer_Place < first_line_character_position then
- -- past end of line, move to new line ...
- Master_Buffer.Fixed_Cursor.Column_Offset := 0 ; -- use leading sp
- If cursor_backward_line then
- -- we are ready to work this new line
- chk_abort ;
- Fix_Fixed_Cursor ;
- Buffer_Place := last_line_character_position
- - Search_String_Length + 1 ;
- else
- -- unable to move, at start of buffer
- return false ; -- hit start of buffer w/o finding anything
- end if ;
- else
- -- here if still on the same line...... ready to check....
- New_Displacement
- := Minimum_Displacement_Of_Character_From_End_Of_Search_String(
- master_buffer.e_buf(type_buffer_position(Buffer_Place)).data);
- exit when ( New_Displacement = Two_Max ) ;
- -- signal for end of word is found here....
- Buffer_Place := Buffer_Place + New_Displacement ;
- end if ;
- end loop ;
- -- we end up here only when we find a valid last character .....
- Save_Buffer_Place := Buffer_Place ;
- Buffer_Place := Buffer_Place + 1 ; -- move one char in from start
- -- set to look at next character down
- Search_String_Place := 2 ; -- first already checked
- Is_Good := True ;
- Loop
- Exit When Search_String_Place > Search_String_Length ; -- SUCCESS !!!!
- if Do_A_Case_Sensitive_Search then
- Is_Good := The_Search_Target(Search_String_Place)
- = master_buffer.e_buf(type_buffer_position(
- Buffer_Place)).data ;
- else
- Is_Good := The_Search_Target(Search_String_Place)
- = map_up(master_buffer.e_buf(
- type_buffer_position(Buffer_Place)).data) ;
- end if ;
- Exit When Not Is_Good ;
- Search_String_Place := Search_String_Place + 1 ;
- Buffer_Place := Buffer_Place + 1 ;
- end loop ;
- if Is_Good then
- -- We Found The String ....... Return First Character Position
- Fixed_Cursor_Buffer_Position := Save_Buffer_Place ;
- return True ;
- else
- -- found a mismatch
- -- last good character is at Search_String_Place - 1
- New_Multiple_Character_Displacement
- := Minimum_Displacement_Of_Character_From_End_Of_Search_String(
- master_buffer.e_buf(type_buffer_position(Buffer_Place)).data);
- if New_Multiple_Character_Displacement = two_max then
- Buffer_Place := Save_Buffer_Place - 1 ;
- -- we can always move one position.....
- -- ( failed to move more because that character was a success
- -- character for the end of the string
- else
- Buffer_Place:=Buffer_Place + New_Multiple_Character_Displacement ;
- end if ;
- -- This is pretty obvious, at the place where we first did not
- -- have a match, we will attempt to move over the appropriate
- -- number of characters to continue on our way, unless it is
- -- the end of search target character, in which case we will
- -- only move the end_Buffer_Place over one position
- Save_Buffer_Place := Save_Buffer_Place
- + Multiple_Character_Match_Displacement_Amount(
- Search_String_Place ) ;
- -- ok, This says to move over the appropriate number of
- -- characters to match the same String in the Target
- -- it is measured from the end of the string to the new
- -- place we should start checking from
- If Save_Buffer_Place < Buffer_Place then
- Buffer_Place := Save_Buffer_Place ;
- end if ; -- move the furthest of the two choices...
- -- This is the finale ... in that we will move over as much
- -- as possible, based upon knowledge gained from the last
- -- good character or the first bad character
- end if ;
- end loop ;
- end search_backward ;
-
- begin -- find_The_Search_Target
- successfull := false ; -- haven't found the The_Search_Target yet
- loop
- -- look for the The_Search_Target : we know that cursor is set as the
- -- first character possible for the match string (on the left)
- if go_forward then
- successfull := search_forward ;
- else
- successfull := search_backward ;
- end if ;
- un_fix_fixed_Cursor ;
- exit when not successfull ; -- can't find...go away...
- -- In Token_Mode Find_Mode make sure the first and last characters
- -- of the targer are on 'Token_Mode boundaries'
- exit when Find_Mode /= Token_Mode ;
- -- if not token mode, we are done and have been successfull.....
- exit when Token_Kind(The_Search_Target(1)) /= Kind_Alpha_Numeric ;
- -- if not alphanumeric, we don't do a token check anyway.....
- -- in that case, we are automatically successfull....
- if Fixed_Cursor_Buffer_Position
- > First_Line_Character_Position then
- successfull := Token_Kind(master_buffer.e_buf
- (Fixed_Cursor_Buffer_Position).data)
- /= Token_Kind(master_buffer.e_buf
- (Fixed_Cursor_Buffer_Position-1).data) ;
- -- we do not have a successfull find if we are asking for a
- -- token and the first character is the same kind as the
- -- previous character ...
- -- else on a line start boundry//ok.....
- end if ;
- if successfull
- and then Fixed_Cursor_Buffer_Position
- < Last_Line_Character_Position then
- successfull := Token_Kind(master_buffer.e_buf
- ( Fixed_Cursor_Buffer_Position
- + Search_String_Length - 1 ).data)
- /= Token_Kind(master_buffer.e_buf
- ( Fixed_Cursor_Buffer_Position
- + Search_String_Length ).data) ;
- -- we do not have a successfull find if we are asking for a
- -- token and the last character is the same kind as the
- -- following character ...
- -- else on a line end boundry//ok...or else failed previously
- -- and then we need to go around again...
- end if ;
- -- the following assumes that on a Token_Mode mismatch we will
- -- throw all info away and start one after/before the place
- -- we are at
- exit when successfull ; -- because we are done......
- -- we end up here if we found it but failed on the token check
- if go_forward then
- Master_Buffer.Fixed_Cursor.Column_Offset
- := Master_Buffer.Fixed_Cursor.Column_Offset + 1 ;
- -- because search looks for the last character at
- -- cursor+Search_String_Length-1, which will start 1 character after
- -- the current match
- else
- Master_Buffer.Fixed_Cursor.Column_Offset
- := Master_Buffer.Fixed_Cursor.Column_Offset - 1 ;
- -- again, we will make it the last character and we will
- -- then Skip_Blanks to one before it...
- end if ;
- end loop ;
- final_successfull := successfull ;
- end find_The_Search_Target ;
-
- Procedure Not_Enough_Found is
- dd : character ;
- begin
- clear_prompt( master_buffer ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- if go_forward then
- put('>') ;
- else
- put('<') ;
- end if ;
- put(" Error: ") ;
- if Number_Found_So_Far = 0 then
- put("String Not Found.") ;
- else
- put("Found only ") ;
- put(Number_Found_So_Far,0) ;
- put(" of the ") ;
- put(repeat_factor,0) ;
- put(" required.") ;
- end if ;
- put(" Options: C(ontinue, Q(uit, S(top ") ;
- dd := crt_windows.char_or_abort( ' ' , ' ' , 'C' , 'Q' , 'S' ) ;
- if not ( (dd = 'Q') or (dd = 'S') ) then
- dd := 'C' ;
- end if ;
- return_quit_stop( dd ) ;
- end not_enough_found ;
-
- Procedure replace_it is
- added_length : integer ;
- exit_replace_it : exception ;
- inserted_range : text_range ;
- successfull : boolean ;
- new_number : a_repeat_factor ;
- begin
- -- we will enter this routine with the cursor pointing to the first
- -- character of the string that we want to match
- if verify_each_replacement then
- if not screen_is_not_erased then
- show_screen( master_buffer ) ;
- Screen_Is_Not_Erased := true ;
- end if ;
- -- if not changed, then still Screen_Is_Not_Erased
- if repeat_factor = infinity then
- new_number := infinity ;
- else
- new_number := repeat_factor - number_found_so_far + 1 ;
- end if ;
- put_prompt("Replace",
- "<reject> aborts, 'R' replaces, <space> doesn't",
- new_number , false ) ;
- show_cursor( master_buffer ) ;
- get_c_or_cmd( User_Find_Character , User_Find_Editor_Command ) ;
- User_Find_Extended_Character := e_character ( User_Find_Character ) ;
- if (User_Find_Character /= 'R')
- and (User_Find_Character /= 'r') then
- if (User_Find_Editor_Command = reject_command ) then
- raise reject_cmd ;
- else
- -- we need to set up for the next find
- if go_forward then
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset + 1 ;
- -- start one over for forward
- else
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset - 1 ;
- -- start one sooner for backwards
- end if ;
- raise exit_replace_it ;
- end if ;
- end if ;
- end if ;
- -- replace The_Search_Target with The_Replacement_String
- -- first, we can set the old position because we will be sure of it
- Old_Find_Location.Line := master_buffer.fixed_cursor.file_line_number;
- Old_Find_Location.Column:= master_buffer.fixed_cursor.column_offset ;
- added_length := Replacement_String_Length - Search_String_Length ;
- -- how many added characters will there be
- if added_length > 0 then -- adding characters
- -- make sure we have room for it
- -- since block size is guaranteed to be larger than the longest line
- --
- if master_buffer.bufcount + added_length >= max_buffer_size then
- -- must get rid of something...
- if master_buffer.fixed_cursor.line_start > block_size then
- -- do the top
- push_data( master_buffer , thetop , successfull ) ;
- else
- -- do the bottom
- push_data( master_buffer , thebot , successfull ) ;
- end if ;
- if successfull then
- fix_fixed_cursor ;
- un_fix_fixed_cursor ;
- -- to set up the buffer position correctly...
- else
- error("No Disk Space During Replace.", not_fatal_error ,
- operator_wait , extra_short_beep ) ;
- raise reject_cmd ;
- end if ;
- end if ;
- shift_buffer_area(master_buffer ,
- master_buffer.fixed_cursor.buffer_position ,
- master_buffer.fixed_cursor.buffer_position
- + added_length ,
- master_buffer.bufcount
- - master_buffer.fixed_cursor.buffer_position + 1 ) ;
- else
- shift_buffer_area(master_buffer ,
- master_buffer.fixed_cursor.buffer_position
- + Search_String_Length ,
- master_buffer.fixed_cursor.buffer_position
- + Replacement_String_Length ,
- master_buffer.bufcount
- - ( master_buffer.fixed_cursor.buffer_position
- + Search_String_Length ) + 1 ) ;
- end if ;
- -- now, modify the current line's length .....
- master_buffer.e_buf( Fixed_Cursor_Line_Start ).data
- := extended_character(Lines_Text_Length + added_length ) ;
- Last_Line_Character_Position := Last_Line_Character_Position
- + added_length ;
- master_buffer.e_buf( Last_Line_Character_Position + 1 ).data
- := extended_character(Lines_Text_Length + added_length ) ;
- master_buffer.bufcount := master_buffer.bufcount + added_length ;
- -- that is what the new buffer length is
- for ind in 1 .. Replacement_String_Length loop
- master_buffer.e_buf( master_buffer.fixed_cursor.buffer_position
- + ind - 1 ) := ( The_Replacement_String(ind) ,
- no_screen_attribute ) ;
- end loop ;
- if added_length > 0 then
- Inserted_Range.Lo_Position
- := Text_Position'( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset ,
- no_screen_attribute ,
- master_buffer ) ;
- Inserted_Range.Hi_Position
- := Text_Position'( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset
- + added_length ,
- no_screen_attribute ,
- master_buffer ) ;
- marker_manager.update_markers_for_added_text( master_buffer ,
- inserted_range ) ;
- elsif added_length < 0 then
- -- deleted text
- Inserted_Range.Lo_Position
- := Text_Position'( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset
- + Replacement_String_Length ,
- no_screen_attribute ,
- master_buffer ) ;
- Inserted_Range.Hi_Position
- := Text_Position'( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset
- + Search_String_Length ,
- no_screen_attribute ,
- master_buffer ) ;
- marker_manager.update_markers_for_deleted_text( master_buffer ,
- inserted_range ) ;
- -- else if the same length, do nothing...
- end if ;
- if go_forward then
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset
- + Search_String_Length + Replacement_String_Length - 1 ;
- -- the next possible place for the string
- else
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset
- - Search_String_Length ;
- -- the next possible place on the left
- end if ;
- -- Note : going right we will offset by the substitution length,
- -- going left we offset by the The_Search_Target length !!
- Screen_Is_Not_Erased := false ;
- -- we updated the page but the screen doesn't yet show
- exception
- when exit_replace_it => null ;
- end replace_it ;
-
- begin -- do_find_command
- Old_Find_Location.Line := master_buffer.fixed_cursor.file_line_number;
- Old_Find_Location.Column := master_buffer.fixed_cursor.column_offset ;
- Last_Find_Location := Old_Find_Location ;
- if master_buffer.pagezero.tokdef then
- Find_Mode := Token_Mode ;
- else
- Find_Mode := Literal_Mode ;
- end if ;
- Do_A_Case_Sensitive_Search := master_buffer.pagezero.checkcase ;
- -- now scan for boundaries
- if Returned_Command = find_command then
- put_prompt("Find" , " <Target> =>" , repeat_factor ) ;
- else
- put_prompt("Replace" ," V(erify <trgt> <substit> =>" , repeat_factor );
- end if ;
- need_prompt := true ;
- Get_Next_Character_Of_Find_Command ;
- Skip_Blanks ;
- if User_Find_Editor_Command = reject_command then
- raise reject_cmd ;
- end if ;
- Process_Command_Line_Options ;
- if User_Find_Editor_Command = reject_command then
- raise reject_cmd ;
- end if ;
- if Use_Last_Entered_String then
- -- move pstring to this target
- If search_target_defined then
- The_Search_Target := Search_Target ;
- Search_String_Length := Search_Target_Length ;
- else
- search_string_length := 0 ;
- end if ;
- else
- -- move this target to pstring
- parse_string( The_Search_Target , Search_String_Length ) ;
- if (User_Find_Editor_Command = reject_command ) then
- raise reject_cmd ;
- end if ;
- Search_Target := The_Search_Target ;
- Search_Target_Length := Search_String_Length ;
- end if ;
- Search_Target_Defined := ( Search_String_Length >= 1 ) ;
- if Search_Target_Defined then
- set_table ; -- once we have the word, set up the table for it
- compare_two ;
- end if ;
- if Returned_Command = replace_command then
- Get_Next_Character_Of_Find_Command ;
- Skip_Blanks ;
- if (User_Find_Editor_Command = reject_command ) then
- raise reject_cmd ;
- end if ;
- Use_Last_Entered_String := false ;
- Process_Command_Line_Options ;
- if Use_Last_Entered_String then
- -- move pstring to this target
- The_Replacement_String := Replace_String ;
- Replacement_String_Length := Replace_String_Length ;
- else
- -- move this target to pstring
- parse_string(The_Replacement_String,Replacement_String_Length) ;
- if User_Find_Editor_Command = reject_command then
- raise reject_cmd ;
- end if ;
- Replace_String := The_Replacement_String ;
- Replace_String_Length := Replacement_String_Length ;
- Replace_String_Defined := true ;
- end if ;
- end if ;
- clear_prompt(master_buffer) ;
- if (not Search_Target_Defined)
- or ( ( not Replace_String_Defined )
- and ( Returned_Command=replace_command ) ) then
- error("No old pattern." , not_fatal_error ,
- operator_wait , extra_short_beep );
- else
- Number_Found_So_Far := 0 ; -- have not found any yet
- -- first, we want to make sure that the Find instruction will not
- -- find where we are now ...
- if returned_command = find_command then
- if go_forward then
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset + 1 ;
- else
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset - 1 ;
- end if ;
- end if ;
- loop
- -- Now, we are sitting where we will allow the first letter of the
- -- string we are looking for. Of course, for backwards, we will
- -- need to increment...etc.
- Find_The_Search_Target( Target_Found ) ; -- handles Token/Literal
- if target_found then
- Number_Found_So_Far := Number_Found_So_Far + 1 ;
- -- we had to find one to get here
- Last_Find_Location.Line
- := master_buffer.fixed_cursor.file_line_number;
- Last_Find_Location.Column
- := master_buffer.fixed_cursor.column_offset ;
- master_buffer.last_marked_position.data := last_find_location ;
- if returned_command = replace_command then
- replace_it ;
- if User_Find_Editor_Command = Reject_Command then
- raise reject_cmd ;
- end if ;
- else
- Old_Find_Location := Last_Find_Location ;
- -- if we are just hopping over some, then we need to set
- -- the cursor position at the correct place...
- -- we will not allow the cursor to match to any part of this
- if go_forward then
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset
- + Search_String_Length ;
- else
- If master_buffer.fixed_cursor.column_offset
- > search_string_length then
- master_buffer.fixed_cursor.column_offset
- := master_buffer.fixed_cursor.column_offset
- - Search_String_Length ;
- else
- master_buffer.fixed_cursor.column_offset := 0 ;
- end if ;
- end if ;
- -- only sets for find or actually changed replaced
- end if ;
- elsif (Number_Found_So_Far = 0) -- nothing found this time
- or ( ( repeat_factor /= infinity )
- and (Number_Found_So_Far < repeat_factor) ) then
- not_enough_found ;
- end if ;
- exit when ( (Number_Found_So_Far >= repeat_factor)
- and (repeat_factor /= infinity ) )
- or ( not target_found) ;
- end loop ;
- end if ;
- jump_to_position ( master_buffer ,
- last_find_location.line ,
- last_find_location.column ,
- false ) ;
- current_leading := num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) ;
- if master_buffer.fixed_cursor.column_offset <= current_leading then
- master_buffer.fixed_cursor.column_offset := current_leading + 1 ;
- end if ;
- If not screen_is_not_erased then
- show_screen( master_buffer ) ;
- end if ;
- show_cursor( master_buffer ) ;
- exception
- when reject_cmd => current_leading := num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) ;
- if master_buffer.fixed_cursor.column_offset
- <= current_leading then
- master_buffer.fixed_cursor.column_offset
- := current_leading + 1 ;
- end if ;
- If not screen_is_not_erased then
- show_screen( master_buffer ) ;
- end if ;
- show_cursor( master_buffer ) ;
- when find_exit => null ;
- end do_find_command ;
-
- begin -- Editor_Find
- -- FINDREPL by SAIC/Clearwater Editor Find & Replace Comds 26 Dec 84
- for posn in extended_character loop
- Token_Kind( posn ) := posn ;
- end loop ;
- for posn in extended_character( character'pos('A') )
- .. extended_character( character'pos('Z') ) loop
- Token_Kind(posn) := kind_alpha_numeric ;
- end loop ;
- for posn in extended_character( character'pos('a') )
- .. extended_character( character'pos('z') ) loop
- Token_Kind(posn) := Kind_Alpha_Numeric ;
- end loop ;
- for posn in extended_character( character'pos('0') )
- .. extended_character( character'pos('9') ) loop
- Token_Kind(posn) := Kind_Alpha_Numeric ;
- end loop ;
- end Editor_Find ;
-
- --$$$- EDITFIND
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editmain
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITMAIN
-
- --
- -- File 017
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ; -- for a file close which is accomplished
- -- within the kill command
- with basic_io_system ;
-
- with string_library ;
- use string_library ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_general ;
- use buffer_lines ;
-
- with edit_windows ;
- use edit_windows ;
-
- with markers ;
- use markers ;
- use text_position_handler ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- package editor_main_packages is
-
- procedure do_adjust_command ;
-
- procedure do_end_open_commands ( how_to_end : in an_editor_command ) ;
-
- procedure do_kill_command( direction : in boolean ) ;
-
- procedure do_zap_command ;
-
- procedure do_printer_command ;
-
- allow_alternate_prompt_command : boolean := true ;
-
- end editor_main_packages ;
-
- package body editor_main_packages is
-
- -- Printer_Device_Name : constant string := basic_io_system.printer_name ;
-
- Printer_Device_Name : constant string := "PRINTER:" ;
-
- procedure do_adjust_command is
- type mode_type is ( Relative , Left_Justify , Right_Justify , Center ) ;
- mode : mode_type ;
- amount_to_move_right : integer ;
- old_repeat_factor : a_repeat_factor ;
- new_repeat_factor : a_repeat_factor ;
- new_command : an_editor_command ;
- lines_remaining : integer ;
-
- procedure do_this_line ( current_amount : Integer ) is
- -- do the specified operation to the current line
- Old_Leading_Spaces : integer ;
- leading_spaces : Integer ;
- lmarg , rmarg : Integer ;
- Line_Leng : Integer ;
- window_line : integer ; -- because we make it and then see if it
- -- is a legal window_line_number ;
- changed_range : text_range ;
- begin -- do_this_line
- -- first, find out the leading spaces & other facts
- old_leading_spaces := num_leading_spaces ( master_buffer ,
- master_buffer.fixed_cursor ) ;
- leading_spaces := old_leading_spaces ;
- lmarg := master_buffer.pagezero.lmargin ;
- rmarg := master_buffer.pagezero.rmargin ;
- Line_Leng := line_length( master_buffer ,
- master_buffer.fixed_cursor.line_start ) ;
- -- then, figure the new leading spaces
- case mode is
- when Relative => leading_spaces := leading_spaces +
- current_amount ;
- when Left_Justify => leading_spaces := 0 ;
- when Right_Justify => leading_spaces := rmarg - line_leng ;
- when Center => leading_spaces := ( rmarg - lmarg
- - line_leng ) / 2 ;
- end case ;
- -- then, fix leading spaces if necessary
- if leading_spaces > type_leading_spaces'last then
- leading_spaces:= type_leading_spaces'last ;
- elsif leading_spaces < 0 then
- leading_spaces := 0 ;
- end if ;
- -- now, set leading spaces
- master_buffer.e_buf( master_buffer.fixed_cursor.line_start + 1 ).data
- := type_leading_spaces( leading_spaces ) ;
- -- Now, update markers for the changed text
- if leading_spaces /= old_leading_spaces then
- Changed_Range.Lo_Position.Line
- := master_buffer.fixed_cursor.file_line_number ;
- Changed_Range.Hi_Position.Line
- := master_buffer.fixed_cursor.file_line_number ;
- Changed_Range.Lo_Position.Which_Buffer := Master_Buffer ;
- Changed_Range.Hi_Position.Which_Buffer := Master_Buffer ;
- if leading_spaces > old_leading_spaces then
- -- added text
- Changed_Range.Lo_Position.Column := old_leading_spaces + 1 ;
- Changed_Range.Hi_Position.Column := leading_spaces + 1 ;
- marker_manager.update_markers_for_added_text
- ( master_buffer , changed_range ) ;
- else
- -- deleted text
- Changed_Range.Lo_Position.Column := Leading_Spaces + 1 ;
- Changed_Range.Hi_Position.Column := Old_Leading_Spaces + 1 ;
- marker_manager.update_markers_for_deleted_text
- ( master_buffer , changed_range ) ;
- end if ;
- end if ;
- -- and finally redisplay the line
- master_buffer.fixed_cursor.column_offset := leading_spaces + 1 ;
- if cursor_off_screen(master_buffer) then
- show_cursor( master_buffer ) ; -- redraws screen
- else
- window_line := master_buffer.fixed_cursor.file_line_number
- - master_buffer.top_screen_cursor.file_line_number + 1 ;
- clear_end_of_line ( master_buffer , window_line ,
- lowest_column_number( master_buffer ) ) ;
- show_line ( master_buffer ,
- master_buffer.fixed_cursor.line_start ,
- master_buffer.fixed_cursor.file_line_number ) ;
- show_cursor( master_buffer ) ;
- end if ;
- end do_this_line ;
-
- begin -- do_adjust_command
- set_repeat_prompt( true , -1 ) ;
- prompt( adjust_command_prompt ) ;
- -- set the last position
- marker_manager.load_marker( master_buffer.last_marked_position ,
- current_position ) ;
- Mode := Relative ;
- amount_to_move_right := 0 ;
- new_repeat_factor := ( -1 ) ;
- allow_alternate_prompt_command := false ;
- loop
- show_cursor( master_buffer ) ;
- -- first, get the next command
- old_repeat_factor := new_repeat_factor ;
- get_next_command( old_repeat_factor, new_repeat_factor, new_command );
- If new_repeat_factor > max_column_number then
- new_repeat_factor := max_column_number ;
- -- we don't allow any funny business here
- end if ;
- -- note that the commands are locked into the definition shown in
- -- the crt package
- case new_command is
- when up_command => lines_remaining := new_repeat_factor ;
- while ( lines_remaining > 0 )
- and then ( cursor_backward_line ) loop
- do_this_line( amount_to_move_right ) ;
- lines_remaining := lines_remaining - 1 ;
- end loop ;
- when down_command => lines_remaining := new_repeat_factor ;
- while ( lines_remaining > 0 )
- and then ( cursor_forward_line ) loop
- do_this_line( amount_to_move_right ) ;
- lines_remaining := lines_remaining - 1 ;
- end loop ;
- when right_command => amount_to_move_right :=
- amount_to_move_right + new_repeat_factor ;
- If amount_to_move_right > max_column_number
- then
- amount_to_move_right := max_column_number ;
- end if ;
- mode := relative ;
- do_this_line( new_repeat_factor ) ;
- when left_command => amount_to_move_right :=
- amount_to_move_right - new_repeat_factor ;
- if amount_to_move_right < -max_column_number
- then
- amount_to_move_right := -max_column_number;
- end if ;
- mode := relative ;
- do_this_line( - new_repeat_factor ) ;
- when copy_command => mode := center ;
- amount_to_move_right := 0 ;
- do_this_line( amount_to_move_right ) ;
- when print_screen_command => mode := left_justify ;
- amount_to_move_right := 0 ;
- do_this_line( amount_to_move_right ) ;
- when replace_command => mode := right_justify ;
- amount_to_move_right := 0 ;
- do_this_line( amount_to_move_right ) ;
- when accept_command => null ;
- when others => null ;
- end case ;
- exit when new_command = accept_command ;
- end loop ;
- -- what do we have to do to finish up ?
- need_prompt := true ; -- When we leave, we will have to re-prompt
- allow_alternate_prompt_command := true ;
- end do_adjust_command ;
-
- procedure do_kill_command ( direction : in boolean ) is
- -- only implemented for the forward direction.....
- cursor : cursor_position ;
- linestart : type_buffer_position ;
- buf_position : type_buffer_position ;
- leading_spaces : type_leading_spaces ;
- line : line_number ;
- col : column_position ;
- line_leng : type_line_length ;
- changed_range : text_range ;
-
- procedure set_posn( posn : type_buffer_position ;
- num : integer ) is
- begin
- master_buffer.e_buf(posn).data := extended_character( num ) ;
- end;
-
- begin -- do_kill_command
- set_repeat_prompt( false , 0 ) ;
- prompt( kill_command_prompt ) ;
- if crt_windows.char_or_abort( 'N' , 'Y' , 'N' ) = 'Y' then
- -- To kill all following text, these steps must be taken...
- -- First, Tell the buffer that no more text can be read in from the
- -- input file...
- master_buffer.still_reading_input_file := false ;
- if text_io.is_open(master_buffer.inputfile) then
- text_io.close(master_buffer.inputfile);
- end if ;
- -- Then, tell the buffer that no bottom blocks are waiting either...
- master_buffer.presbotblock := 0 ;
- -- Now, kill all text following us in our current buffer
- cursor := master_buffer.fixed_cursor ;
- linestart := cursor.line_start ;
- buf_position := cursor.buffer_position ;
- leading_spaces := num_leading_spaces( master_buffer , linestart ) ;
- line := cursor.file_line_number;
- col := cursor.column_offset ;
- line_leng := line_length( master_buffer , linestart ) ;
- -- find out if we are in leading spaces, text, or after all...
- if col <= leading_spaces then
- -- first possibility...easy to take care of...
- -- first, do buffer
- set_posn( linestart , 0 ) ; -- no text in line
- set_posn( linestart + 1 , col - 1 ) ; -- leading spaces
- set_posn( linestart + 2 , 0 ) ; -- no text in line
- set_posn( linestart + 3 , buffer_boundry ) ; -- eof
- -- then set sizing...
- master_buffer.bufcount := linestart + 3 ;
- -- finally, do the cursor..
- master_buffer.fixed_cursor.buffer_position := 0 ;
- elsif col <= leading_spaces + line_leng then
- -- second possibility...in the text area
- -- first, do buffer
- buf_position := linestart + col - leading_spaces + 1 ;
- set_posn( linestart , col - leading_spaces - 1 ) ;
- -- only preceding text on line
- set_posn( buf_position , col - leading_spaces - 1 ) ;
- set_posn( buf_position + 1 , buffer_boundry ) ; -- eof
- -- then set sizing...
- master_buffer.bufcount := buf_position + 1 ;
- -- finally, do the cursor..
- master_buffer.fixed_cursor.buffer_position := 0 ;
- else
- -- third possibility, following everything.....
- -- first, do buffer
- buf_position := linestart + line_leng + 3 ;
- set_posn( buf_position , buffer_boundry ) ; -- eof
- -- then set sizing...
- master_buffer.bufcount := buf_position ;
- -- finally, do the cursor..
- master_buffer.fixed_cursor.buffer_position := 0 ;
- end if ;
- -- Next, adjust the markers.....
- Changed_Range.Lo_Position.Line := line ;
- Changed_Range.Lo_Position.Column := col ;
- Changed_Range.Lo_Position.Which_Buffer := Master_Buffer ;
- Changed_Range.Hi_Position.Line := max_line_number ;
- Changed_Range.Hi_Position.Column := max_column_number ;
- Changed_Range.Hi_Position.Which_Buffer := Master_Buffer ;
- marker_manager.update_markers_for_deleted_text
- ( master_buffer , changed_range ) ;
- -- Finally, redraw the screen...
- show_screen( master_buffer , master_buffer.fixed_cursor ,
- window_height( master_buffer ) ) ;
- end if ;
- need_prompt := true ;
- end do_kill_command ;
-
- procedure do_zap_command is
- -- delete the text from the zap marker to the current position
- begin -- do_zap_command
- need_prompt := true ; -- When we leave, we will have to re-prompt
- set_repeat_prompt( false , 0 ) ; -- Turn off the counters...
- prompt( zap_command_prompt ) ;
- if crt_windows.char_or_abort( 'N' , 'Y' , 'N' ) = 'Y' then
- -- then do the zap...
- copy_text_to_copy_buffer( master_buffer ,
- text_range'(
- master_buffer.last_marked_position.data ,
- current_position ,
- no_screen_attribute ) ,
- true ) ;
- show_screen( master_buffer ) ;
- end if ;
- end do_zap_command ;
-
- procedure do_printer_command is
- printer_file : text_io.file_type ;
- line_num : integer ;
- old_cursor : cursor_position ;
- Line_Of_Text : type_text_line ;
- c : character ;
- -- note that the only reason that we are able to get away with simply
- -- saving and restoring the fixed_cursor is because we know that moving
- -- on the screen and up to one line later can NEVER push/pop the
- -- buffer....
- begin -- do_printer_command
- set_repeat_prompt( false , 0 ) ;
- prompt( line_printer_command_prompt ) ;
- if crt_windows.char_or_abort( 'N' , 'Y' , 'N' ) = 'Y' then
- -- ready to print...
- prompt( " Copying Screen Data Area To The Printer " ) ;
- text_io.open(printer_file , text_io.out_file , printer_device_name ) ;
- line_num := 1 ;
- old_cursor := master_buffer.fixed_cursor ;
- master_buffer.fixed_cursor := master_buffer.top_screen_cursor ;
- loop
- -- show the cursor for fun...
- master_buffer.fixed_cursor.column_offset :=
- num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) + 1 ;
- show_cursor( master_buffer ) ;
- -- show the line...
- get_text_line( master_buffer , master_buffer.fixed_cursor.line_start ,
- Line_Of_Text ) ;
- for posn in 1 .. line_of_text.data_length loop
- c := character'val( line_of_text.data(posn) mod 128 ) ;
- text_io.put( printer_file , c ) ;
- end loop ;
- text_io.new_line( printer_file ) ;
- line_num := line_num + 1 ;
- exit when line_num > window_height( master_buffer ) ;
- exit when not cursor_forward_line ;
- end loop ;
- text_io.close( printer_file ) ;
- master_buffer.fixed_cursor := old_cursor ;
- end if ;
- need_prompt := true ;
- exception
- when others => error(" Unable To Print " ,
- not_fatal_error ,operator_wait ,short_beep ) ;
- master_buffer.fixed_cursor := old_cursor ;
- need_prompt := true ;
- end do_printer_command ;
-
- procedure do_end_open_commands ( how_to_end : in an_editor_command ) is
- begin -- do_end_open_commands
- null;
- end do_end_open_commands ;
-
- begin -- Editor_Main_Packages
- -- EDITMAIN by SAIC/Clearwater Editor Main Packages 22 Jan 85
- -- ADJUST by SAIC/Clearwater Editor Adjust Command 20 Feb 85
- -- DELETE by SAIC/Clearwater Editor Delete/Kill/Zap/Acpt 21 Feb 85
- -- FINDREPL by SAIC/Clearwater Editor Find & Replace Comds 26 Dec 84
- -- PRINTER by SAIC/Clearwater Editor Printer Command 22 Feb 85
- -- COMMAND by SAIC/Clearwater Editor Command Interpretor 27 Dec 84
- null ;
- end Editor_Main_Packages ;
-
- --$$$- EDITMAIN
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editman2
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITMAN2
-
- --
- -- File 020
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- --
- -- Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with Direct_IO ;
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with crt_customization ;
- use crt_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- with editor_misc ;
- use editor_misc ;
-
- with markers ;
- use markers ;
-
- with editor_Find ;
- use editor_find ;
-
- package editor_more_packages is
-
- procedure do_help ( help_file : ascii_text_file_name ) ;
- -- use the designated file as a help file
-
- procedure do_help_command ;
-
- procedure do_set_information_command ;
-
- procedure shift_screen ( columns_to_move_right : in integer ) ;
-
- procedure do_verify_screen_command ;
-
- function get_marker_name return str10 ;
-
- function find_marker ( name : in str10 ) return marker_number ;
-
- procedure set_a_new_marker ;
- -- mark the current location with a new marker... and then give it
- -- a name...
-
- function jump_to_marker return text_position ;
- -- jump to a marker command
-
- end editor_more_packages ;
-
- package body editor_more_packages is
-
- block_size : constant integer := 256 ; -- cannot be changed!
- subtype block_index is integer range 0 .. block_size - 1 ;
- type block_of_data is array ( block_index
- range 0 .. block_size - 1 ) of character ;
- type type_help_text_array is
- record
- block_number : integer ;
- data : block_of_data ;
- end record ;
-
- package help_file_io is new direct_io ( type_help_text_array ) ;
- -- unvalidated telesoft ada does not allow arrays, only records...
-
- procedure do_help ( help_file : ascii_text_file_name ) is
- -- use the designated file as a help file
-
- no_file_error : exception ;
- help_file_error : exception ;
- get_block_error : exception ;
-
- key_list : crt_windows.character_set ;
-
- maximum_help_topics : constant integer := 40 ;
- subtype help_topic_index_number is INTEGER
- range 1 .. maximum_help_topics ;
- subtype topic_name_type is string ( 1 .. 28 ) ;
- blank_topic_name : constant topic_name_type
- := " " ;
- type help_topic_description is
- record
- block_number : INTEGER range 0 .. 32000 := 0 ;
- place : block_index := 0 ;
- help_code : CHARACTER := ascii.nul ;
- topic_name : topic_name_type := blank_topic_name ;
- end record ;
- type some_entries is array ( help_topic_index_number )
- of help_topic_description ;
-
- h_descript : some_entries ;
- first_text_block_in_file : constant integer := 6 ;
- Help_Data_File : help_file_io.FILE_TYPE ;
- jump_table : array ( character ) of integer ;
- good_topics : integer ;
- next_c_place : block_index ;
- subtype data_file_name is ascii_text_file_name ;
- master_option : character ;
- help_text_array : type_help_text_array ;
-
-
- procedure open_for_read ( file_handle : in out help_file_io.file_type ;
- file_name : in out data_file_name ) is
- -- Open the file setting the handle
- begin -- open_for_read
- if help_file_io.is_open(file_handle) then
- help_file_io.close(file_handle);
- end if ;
- help_file_io.open(file_handle,help_file_io.inout_file,
- no_blanks(file_name));
- exception
- when others => raise no_file_error ;
- end open_for_read ;
-
- procedure get_block ( next_input_block : in out
- help_file_io.positive_count ) is
- begin -- get_block
- help_file_io.read ( Help_Data_File , help_text_array ,
- Next_Input_Block ) ;
- Next_Input_Block := Next_Input_Block + 1 ;
- next_c_place := 0 ;
- exception
- when others => raise Get_Block_Error ;
- end get_block ;
-
- procedure initialize is
- type code_array_type is array ( 0 ..
- ( ( first_text_block_in_file - 1 ) * block_size ) - 1 )
- of character ;
- code_array : code_array_type ;
- i_block : help_file_io.positive_count ;
- final_name : data_file_name ;
-
- procedure convert_from_text_to_entry ( in_place : in integer ;
- t : out help_topic_description )
- is
-
- function int ( pla : integer ) return integer is
- begin
- return character'pos( code_array ( pla ) ) ;
- end;
-
- begin
- t.block_number := ( int( in_place + 00 ) * 64 )
- + ( int( in_place + 01 ) / 2 ) ;
- t.place := ( ( int( in_place + 01 ) mod 2 ) * 128)
- + ( int( in_place + 02 ) ) ;
- t.help_code := code_array ( in_place + 03 ) ;
- for posn in 1 .. 28 loop
- t.topic_name ( posn ) := code_array ( in_place + 3 + posn ) ;
- end loop ;
- end convert_from_text_to_entry ;
-
- begin -- initialize
- final_name := help_file ;
- open_for_read ( help_data_file , final_name ) ;
- for blockn in 1 .. first_text_block_in_file - 1 loop
- i_block := help_file_io.positive_count ( blockn ) ;
- get_block ( i_block ) ;
- for posn in 0 .. block_size - 1 loop
- code_array ( (blockn-1) * block_size + posn ) :=
- help_text_array.data(posn) ;
- end loop ;
- end loop ;
- crt_windows.clear_set ( key_list ) ;
- key_list(' ') := true ;
- for topic in 1 .. maximum_help_topics loop
- -- we must convert it over
- convert_from_text_to_entry ( (topic-1)*32 ,
- h_descript( topic ) ) ;
- if h_descript ( topic ).help_code /= ascii.nul then
- key_list( h_descript(topic).help_code):= true ;
- good_topics := topic ;
- jump_table( h_descript(topic).help_code) := topic ;
- end if ;
- end loop ;
- end initialize ;
-
- procedure show_screen is
- j : integer ;
- begin -- show_screen
- clear_window ( master_buffer ) ;
- clear_prompt ( master_buffer ) ;
- goto_prompt_line_column ( master_buffer , 1 , 1 ) ;
- put(" The following help options are intended"
- &" as a quick reference to available com-" );
- goto_line_column( master_buffer , 1 , 1 ) ;
- put(" mands. For further information, see th"
- &"e referenced section in the SAIC manual" );
- if good_topics < 17 then
- -- single column
- for topic in 1 .. good_topics loop
- goto_line_column( master_buffer , topic + 4 , 21 ) ;
- put( h_descript(topic).help_code &
- ") " & h_descript( topic ) .topic_name ) ;
- end loop ;
- else
- -- double column
- for topic in 1 .. ( good_topics + 1 ) / 2 loop
- goto_line_column( master_buffer , topic + 1 , 4 ) ;
- put( h_descript(topic).help_code &
- ") " & h_descript( topic ) .topic_name ) ;
- end loop ;
- j := 2 ;
- for topic in ( ( good_topics + 1 ) / 2 ) + 1 .. good_topics loop
- goto_line_column( master_buffer , j , 44 ) ;
- put( h_descript(topic).help_code &
- ") " & h_descript( topic ) .topic_name ) ;
- j := j + 1 ;
- end loop ;
- end if ;
- goto_line_column ( master_buffer , 23 , 22 );
- put("Enter Option (or <space> to quit) ? ");
- end show_screen ;
-
- procedure do_work is
- Next_Input_Block : help_file_io.POSITIVE_COUNT ;
- cur_topic : help_topic_index_number ;
- c : character ;
-
- procedure show_the_help_information is
- c : character ;
- begin -- show_the_help_information
- clear_window ( master_buffer ) ;
- clear_prompt ( master_buffer ) ;
- goto_prompt_line_column ( master_buffer , 1 , 1 ) ;
- loop
- c := help_text_array.data ( next_c_place ) ;
- exit when c = ascii.nul ;
- put(c);
- if next_c_place = block_size - 1 then
- get_block( next_input_block ) ; -- auto increment
- else
- next_c_place := next_c_place + 1 ;
- end if ;
- end loop ;
- end show_the_help_information ;
-
- begin -- do_work
- cur_topic := jump_table ( master_option ) ;
- loop
- next_input_block:= help_file_io.positive_count
- (h_descript(cur_topic).block_number);
- get_block ( next_input_block ) ;
- next_c_place := h_descript(cur_topic).place ;
- show_the_help_information ;
- goto_line_column ( master_buffer , 23 , 27 ) ;
- put("Enter <space> to continue...");
- c := crt_windows.char_or_abort( ascii.cr , ascii.cr , ' ' ) ;
- exit when c = ' ' ;
- if cur_topic < maximum_help_topics then
- cur_topic := cur_topic + 1 ;
- if h_descript( cur_topic ) .help_code = ascii.nul then
- cur_topic := 1 ;
- end if ;
- else
- cur_topic := 1 ;
- end if ;
- end loop ;
- end do_work ;
-
- procedure finishup is
- begin -- finishup
- help_file_io.close ( Help_Data_File ) ;
- end finishup ;
-
- procedure error_message ( there_but_bad : boolean ) is
- c : character ;
- begin
- clear_window ( master_buffer ) ;
- clear_prompt ( master_buffer ) ;
- goto_line_column ( master_buffer , 5 , 5 ) ;
- put("The Desired Help File """ & compress( help_file ) & """ is ");
- if there_but_bad then
- put("damaged on your disk and is not available.");
- goto_line_column ( master_buffer , 7 , 5 ) ;
- put("Please erase it and replace it with a good copy from your "
- & "master backup.");
- else
- put("not on your disk. Therefore,");
- goto_line_column( master_buffer , 7 , 5 ) ;
- put("this command is not available.");
- end if ;
- goto_line_column ( master_buffer , 10 , 5 ) ;
- put("Tap <space> to continue...");
- c := crt_windows.char_or_abort ( ' ' , ' ' ) ;
- end error_message ;
-
- begin -- do_help
- store_shift ;
- initialize ;
- loop
- show_screen ;
- master_option := crt_windows.goodchar ( key_list , ' ' ) ;
- exit when master_option = ' ' ;
- do_work ;
- end loop ;
- finishup ;
- restore_shift ;
- exception
- when help_file_error => error_message ( true ) ;
- restore_shift ;
- when no_file_error => error_message ( false) ;
- restore_shift ;
- when get_block_error => error_message ( true ) ;
- restore_shift ;
- end do_help ;
-
- procedure do_help_command is
- begin -- do_help_command
- do_help ( Help_On_Editor_Commands_File_Name ) ;
- end do_help_command ;
-
- procedure change_environment ( buf : in out an_editor_buffer ;
- env : in out header ) is
- -- allow the user to change the environment
- environment_prompt : constant string ( 1 .. 61 ) :=
- " Environment [options], ""?"" for Help, <space> or ""Q"" to Quit " ;
- prompt_column : constant integer := 65 ;
- change_option : character ;
-
- set_allowed_characters : constant crt_windows.character_set :=
- ( ascii.nul .. ascii.us => false ,
- ' ' => true ,
- '!' .. '>'| '@' => false ,
- '?' |
- 'A' | 'B' | 'C' |
- 'E' | 'F' | 'H' |
- 'J' | 'L' | 'P' |
- 'R' | 'S' | 'T' |
- 'W' => true ,
- 'Q' => true ,
- 'D' | 'G' | 'I' |
- 'K' | 'M' | 'N' |
- 'O' | 'U' | 'V' |
- 'X' .. ascii.del => false ) ;
-
- procedure bool ( b : boolean ) is
- begin
- if b then
- put_line("True ");
- else
- put_line("False");
- end if ;
- end bool ;
-
- procedure put ( d : basic_io_system.timer ) is
- begin -- put
- case d.day_of_week is
- when basic_io_system.sunday => put( "Sun" ) ;
- when basic_io_system.monday => put( "Mon" ) ;
- when basic_io_system.tuesday => put( "Tue" ) ;
- when basic_io_system.wednesday => put( "Wed" ) ;
- when basic_io_system.thursday => put( "Thu" ) ;
- when basic_io_system.friday => put( "Fri" ) ;
- when basic_io_system.saturday => put( "Sat" ) ;
- end case ;
- put(" ");
- case d.month is
- when 1 => put( "Jan" ) ;
- when 2 => put( "Feb" ) ;
- when 3 => put( "Mar" ) ;
- when 4 => put( "Apr" ) ;
- when 5 => put( "May" ) ;
- when 6 => put( "Jun" ) ;
- when 7 => put( "Jul" ) ;
- when 8 => put( "Aug" ) ;
- when 9 => put( "Sep" ) ;
- when 10 => put( "Oct" ) ;
- when 11 => put( "Nov" ) ;
- when 12 => put( "Dec" ) ;
- end case ;
- put(" ");
- put( d.day , 2 ) ;
- put(" ");
- put( d.year , 4 ) ;
- put(" ");
- put( d.hour , 2 ) ;
- put(":");
- if d.minute < 10 then
- put("0");
- put( d.minute , 1 ) ;
- else
- put( d.minute , 2 ) ;
- end if ;
- end put ;
-
- procedure long_put ( s : in a_target ; len : in search_target_index ) is
- -- put out the string, and show ascii.cr as <eol>
- -- we have only 67 columns to work with
- out_place : integer := 23 ;
- cur_char : search_target_index := 1 ;
- in_string : boolean := false ;
- c : character ;
- begin -- long_put
- loop
- exit when cur_char > len ;
- c := character'val( s(cur_char) ) ;
- if c = ascii.cr then
- -- an end of line
- if in_string then
- in_string := false ;
- put('"');
- out_place := out_place + 1 ;
- end if ;
- put(" <eol>");
- out_place := out_place + 6 ;
- else
- if not in_string then
- in_string := true ;
- put(" """);
- out_place := out_place + 2 ;
- end if ;
- put( c ) ;
- out_place := out_place + 1 ;
- end if ;
- cur_char := cur_char + 1 ;
- exit when out_place > 69 ;
- end loop ;
- if in_string then
- put('"');
- end if ;
- if cur_char <= len then
- put(" ...");
- end if ;
- end long_put ;
-
- procedure show_all is
- begin -- show_all
- clear_window( buf );
- goto_line_column ( buf , 2 , 1 ) ;
- -- First , show standard options
- put(" A(uto Indent "); bool( env.autoindent ) ;
- put(" B(reak Character "); put ( env.break_char ) ; put_line ;
- put(" C(ase Sensitive "); bool( env.checkcase ) ;
- put(" E(nable Commands "); bool( env.enable_cmds) ;
- put(" F(illing "); bool( env.filling ) ;
- put(" H(elp "); put_line ;
- put(" J(ustify "); bool( env.justify ) ;
- put(" L(eft Margin "); put ( env.lmargin , 3) ; put_line ;
- put(" P(aragraph Margin "); put ( env.paramargin,3); put_line ;
- put(" R(ight Margin "); put ( env.rmargin , 3) ; put_line ;
- put(" S(ave Environment "); bool( env.save_envirn) ;
- put(" T(oken Mode "); bool( env.tokdef ) ;
- put(" W(ord Processor "); bool( env.wordprocess) ;
- -- we just finished line 14
- -- Then, show targets
- goto_line_column ( buf , 16 , 3 ) ;
- put("Find Pattern : ");
- if search_target_defined then
- long_put(search_target,search_target_length);
- else
- put("<None>");
- end if ;
- goto_line_column ( buf , 17 , 3 ) ;
- put("Replace Pattern : ");
- if replace_string_defined then
- long_put(replace_string,replace_string_length);
- else
- put("<None>");
- end if ;
- -- Then, show file names
- if buf.input_file_name /= no_file then
- goto_line_column( buf , 2 , 33 ) ;
- put("Input File = ");
- put( compress( buf.input_file_name ) ) ;
- end if ;
- if buf.copy_file_name /= no_file then
- goto_line_column( buf , 3 , 33 ) ;
- put("Copied in file = ");
- put( compress( buf.copy_file_name ) ) ;
- end if ;
- if buf.output_file_name /= no_file then
- goto_line_column( buf , 4 , 33 ) ;
- put("Output File = ");
- put( compress( buf.output_file_name ) ) ;
- end if ;
- -- Then, show memory usage
- goto_line_column( buf , 5 , 33 ) ;
- put("Characters in memory = ");
- put( buf.bufcount , 0 ) ;
- if buf.prestopblock > 0 then
- goto_line_column( buf , 6 , 33 ) ;
- put("Blocks before memory = ");
- put( buf.prestopblock , 0 ) ;
- end if ;
- if buf.presbotblock > 0 then
- goto_line_column( buf , 7 , 33 ) ;
- put("Blocks after memory = ");
- put( buf.presbotblock , 0 ) ;
- end if ;
- goto_line_column( buf , 8 , 33 ) ;
- put("Characters per block = ");
- put( block_size , 0 ) ;
- if buf.still_reading_input_file then
- goto_line_column( buf , 9 , 33 ) ;
- put("Input file still being read in");
- end if ;
- goto_line_column( buf , 11 , 33 ) ;
- put("Cursor Line/Column = ");
- put( buf.fixed_cursor.file_line_number , 0 ) ;
- put(" / ");
- put( buf.fixed_cursor.column_offset , 0 ) ;
- -- Now, dates
- goto_line_column( buf , 13 , 33 ) ;
- put("Date Created : ");
- put( env.created ) ;
- goto_line_column( buf , 14 , 33 ) ;
- put("Date Last Updated : ");
- put( env.last_used ) ;
- -- Finally, do the markers
- if env.marker_count > 0 then
- goto_line_column ( buf , 19 , 1 ) ;
- put(" Markers: ");
- if env.marker_count < 7 then
- -- easy code for up to six markers
- for marker_num in 1 .. env.marker_count loop
- goto_line_column ( buf , 19 + ( marker_num - 1 ) / 2 ,
- 13 + ( ( marker_num - 1 ) mod 2 ) * 40 );
- put( env.markers(marker_num).name ) ;
- put(" [ ");
- put( env.markers(marker_num).location.data.line , 5 ) ;
- put(" / ");
- put( env.markers(marker_num).location.data.column , 3 ) ;
- put(" ]");
- end loop ;
- elsif env.marker_count < 13 then
- -- following code will work for up to 12 markers....
- for marker_num in 1 .. env.marker_count loop
- goto_line_column ( buf , 19 + ( marker_num - 1 ) / 3 ,
- 13 + ( ( marker_num - 1 ) mod 3 ) * 23 );
- put( env.markers(marker_num).name ) ;
- put(" ");
- put( env.markers(marker_num).location.data.line , 5 ) ;
- put("/");
- put( env.markers(marker_num).location.data.column , 3 ) ;
- end loop ;
- else
- -- here we will only show the names. Leave it up to the
- -- person who changes the program to use more than that...
- null ;
- end if ;
- end if ;
- -- Don't forget the copyright notice -- This line must NOT be deleted
- goto_line_column( buf , 23 , 1 ) ;
- put(
- "SAIC Text Editor modified from Text Editor Copyright (c) 1984, R. S. Cymbalski"
- );
- end show_all ;
-
- procedure revbool ( line : in window_line_number ;
- col : in window_column_number ;
- b : in out boolean ) is
- begin -- revbool
- goto_line_column ( buf , line , col ) ;
- b := not b ;
- bool ( b ) ;
- end revbool ;
-
- procedure get_brk ( line : in window_line_number ;
- col : in window_column_number ;
- c : in out character ) is
- new_c : character ;
- begin -- get_brk
- goto_line_column ( buf , line , col ) ;
- new_c := crt_windows.char_within_range_or_abort ( '.' , '!' , '~' ) ;
- if new_c > ' ' then
- c := new_c ;
- end if ;
- end get_brk ;
-
- procedure getnumb ( line : in window_line_number ;
- col : in window_column_number ;
- n : in out column_position ) is
- begin -- getnumb
- n := crt_windows.get_number( line , col , 0 ,
- column_position'last , 3 , n ) ;
- end getnumb ;
-
- begin -- change_environment
- store_shift ;
- loop
- set_prompt( master_buffer , 1 , environment_prompt ) ;
- show_all ;
- loop
- goto_prompt_line_column( buf , 1 , prompt_column ) ;
- change_option := crt_windows.goodchar(set_allowed_characters , 'Q' ) ;
- case change_option is
- when 'A' => revbool ( 2 , 22 , env.autoindent ) ;
- when 'B' => get_brk ( 3 , 22 , env.break_char ) ;
- when 'C' => revbool ( 4 , 22 , env.checkcase ) ;
- when 'E' => revbool ( 5 , 22 , env.enable_cmds) ;
- when 'F' => revbool ( 6 , 22 , env.filling ) ;
- when 'J' => revbool ( 8 , 22 , env.justify ) ;
- when 'L' => getnumb ( 9 , 22 , env.lmargin ) ;
- when 'P' => getnumb ( 10 , 22 , env.paramargin ) ;
- when 'R' => getnumb ( 11 , 22 , env.rmargin ) ;
- when 'S' => revbool ( 12 , 22 , env.save_envirn) ;
- when 'T' => revbool ( 13 , 22 , env.tokdef ) ;
- when 'W' => revbool ( 14 , 22 , env.wordprocess) ;
- if env.wordprocess then
- env.first_five := "?????" ;
- else
- env.first_five := "-----" ;
- end if ;
- env.last_five := env.first_five ;
- when others => null ;
- end case ;
- exit when ( change_option = 'H' ) or ( change_option = '?' )
- or ( change_option = 'Q' ) or ( change_option = ' ' ) ;
- end loop ;
- exit when ( change_option = ' ' ) or ( change_option = 'Q' ) ;
- -- we can only get here on a help command....
- do_help ( Help_On_Environment_Commands_File_Name );
- end loop ;
- restore_shift ;
- end change_environment ;
-
- procedure mark_tabs is
- -- set the tab settings within the file
- last_line : window_line_number := 0 ;
- last_col : window_column_number := 0 ;
- mark_opt : character ;
-
- procedure show_a_tab ( tab_number : integer ; the_tab : tabtypes ) is
- new_line : window_line_number ;
- new_col : window_column_number ;
- begin -- show_a_tab
- if tab_number mod 100 < 50 then
- -- in the first set
- new_line := ( tab_number / 100 ) + 4 ;
- new_col := ( tab_number mod 100 ) + 10 ;
- else
- -- in the second set
- new_line := ( tab_number / 100 ) + 14 ;
- new_col := ( tab_number mod 100 ) + 20 - 50 ;
- end if ;
- if ( new_line /= last_line) or else ( new_col /= last_col ) then
- goto_line_column( master_buffer , new_line , new_col ) ;
- end if ;
- case the_tab is
- when tnone => put(' ');
- when tnormal => put('T');
- when tnumber => put('N');
- end case ;
- last_line := new_line ;
- last_col := new_col + 1 ;
- end show_a_tab ;
-
- procedure show_tabs is
- line_num : integer ;
- a_number : integer ;
-
- procedure putit( number , position_to_show : integer ) is
- new_num : integer ;
- begin -- putit
- if position_to_show > 1 then
- new_num := number / position_to_show ;
- else
- new_num := number ;
- end if ;
- if ( new_num = 0 ) and then ( position_to_show /= 1 ) then
- -- the number is smaller than this, a leading zero
- put(' ');
- else
- new_num := new_num mod 10 ;
- put(new_num,1);
- end if ;
- end putit ;
-
- begin
- -- clear the work area
- clear_window( master_buffer ) ;
- clear_prompt( master_buffer ) ;
- -- put the numbers across the top
- goto_line_column( master_buffer , 1 , 10 ) ;
- for posn in 0 .. 49 loop
- putit( posn , 10 ) ;
- end loop ;
- goto_line_column( master_buffer , 11 , 20 ) ;
- for posn in 50 .. 99 loop
- putit( posn , 10 ) ;
- end loop ;
- goto_line_column( master_buffer , 2 , 10 ) ;
- for posn in 0 .. 49 loop
- putit( posn , 1 ) ;
- end loop ;
- goto_line_column( master_buffer , 12 , 20 ) ;
- for posn in 50 .. 99 loop
- putit( posn , 1 ) ;
- end loop ;
- goto_line_column( master_buffer , 3 , 9 ) ;
- for posn in 0 .. 50 loop -- logically 0 .. 49 + 1
- put("=");
- end loop ;
- goto_line_column( master_buffer , 13 , 19 ) ;
- for posn in 50 .. 100 loop -- logically 0 .. 99 + 1
- put("=");
- end loop ;
- -- Now, show the left numbers
- a_number := 0 ;
- line_num := 4 ;
- while a_number <= column_position'last loop
- goto_line_column( master_buffer , line_num , 3 ) ;
- put( a_number , 5 ) ;
- put(" |");
- line_num := line_num + 1 ;
- a_number := a_number + 100 ;
- end loop ;
- a_number := 0 ;
- line_num := 14 ;
- while a_number <= column_position'last loop
- goto_line_column( master_buffer , line_num , 13 ) ;
- put( a_number , 5 ) ;
- put(" |");
- line_num := line_num + 1 ;
- a_number := a_number + 100 ;
- end loop ;
- -- and blank out position 0
- goto_line_column( master_buffer , 4 , 10 ) ;
- put("X");
- -- Now, show the tabs
- last_line := 0 ;
- last_col := 0 ;
- for posn in 1 .. column_position'last loop
- show_a_tab( posn , master_buffer.pagezero.tabline(posn) ) ;
- end loop ;
- end show_tabs ;
-
- procedure set_single_tab is
- new_location : integer ;
- def : character ;
- tb : tabtypes ;
- begin -- set_single_tab
- loop
- clear_end_of_screen( master_buffer , 21 , 1 ) ;
- goto_line_column( master_buffer , 22 , 1 ) ;
- put(" Enter Column Number To Set/Reset Tab (<return> to exit) => ");
- new_location := crt_windows.get_number( 22 , 62 , 1 ,
- column_position'last ,3,0);
- exit when new_location = 0 ;
- -- we are here with a good tab position
- clear_end_of_screen( master_buffer , 21 , 1 ) ;
- goto_line_column( master_buffer , 22 , 1 ) ;
- put(" Current Setting at position #");
- put(new_location,3);
- put(" Is """);
- tb := master_buffer.pagezero.tabline(new_location);
- case tb is
- when tnone => put("No"); def := ' ' ;
- when tnumber => put("Numeric"); def := 'N' ;
- when tnormal => put("Normal"); def := 'T' ;
- end case ;
- put(" Tab"".");
- goto_line_column( master_buffer , 23 , 1 ) ;
- put(
- " Enter 'T' for normal tab, <space> to delete tab, or 'N' for numeric tab ? ");
- case crt_windows.char_or_abort( def , ' ' , 'T' , 'N' ) is
- when ' ' => tb := tnone ;
- when 'T' => tb := tnormal ;
- when 'N' => tb := tnumber ;
- when others => null ;
- end case ;
- master_buffer.pagezero.tabline(new_location) := tb ;
- show_a_tab( new_location , tb ) ;
- end loop ;
- end set_single_tab ;
-
- begin -- mark_tabs
- store_shift ;
- loop
- -- first, show the old tabs
- show_tabs ;
- -- now, show the instructions
- goto_line_column( master_buffer , 20 , 1 ) ;
- put(" The above tab settings are in effect. ");
- -- and get the commands
- loop
- clear_end_of_screen( master_buffer , 21 , 1 ) ;
- goto_line_column( master_buffer , 22 , 1 ) ;
- put(
- " Options: C(lear tabs, R(eset tabs, S(et tabs, H(elp, Q(uit ? ");
- mark_opt :=
- crt_windows.char_or_abort( 'Q' , 'C','R','S','H','Q','?',' ' ) ;
- if mark_opt = ' ' then
- mark_opt := 'Q' ;
- end if ;
- last_line := 0 ;
- last_col := 0 ;
- case mark_opt is
- when 'C' => for posn in 1 .. column_position'last loop
- master_buffer.pagezero.tabline(posn) := tnone ;
- show_a_tab( posn , master_buffer.pagezero.
- tabline(posn) ) ;
- end loop ;
- when 'R' => for posn in 1 .. column_position'last loop
- if posn mod 8 = 1 and then
- posn > 1 then
- master_buffer.pagezero.tabline(posn):=tnormal ;
- else
- master_buffer.pagezero.tabline( posn ):=tnone ;
- end if ;
- show_a_tab( posn , master_buffer.pagezero.
- tabline(posn) ) ;
- end loop ;
- when 'S' => set_single_tab ;
- when others => null ; -- handled outside this
- end case ;
- exit when ( mark_opt = 'Q' ) or ( mark_opt = 'H' ) or ( mark_opt = '?');
- end loop ;
- exit when mark_opt = 'Q' ;
- -- can only get here on a help request...
- do_help ( help_on_set_commands_file_name ) ;
- end loop ;
- restore_shift ;
- end mark_tabs ;
-
- procedure set_zap_marker is
- begin -- set_zap_marker
- -- setting master_buffer.last_marked_position
- marker_manager.load_marker( master_buffer.last_marked_position ,
- current_position ) ;
- end set_zap_marker ;
-
- procedure do_set_information_command is
- begin -- do_set_information_command
- set_prompt( master_buffer , 1 , editor_customization.set_command_prompt );
- case crt_windows.char_or_abort( ' ' , ' ' , 'E' , 'M' ,
- 'T' , 'Z' , 'H' , '?' ) is
- when 'E' => change_environment ( master_buffer ,
- master_buffer.pagezero ) ;
- show_screen( master_buffer,
- master_buffer.fixed_cursor, 0 );
- when 'M' => set_a_new_marker ;
- when 'T' => mark_tabs;
- show_screen( master_buffer,
- master_buffer.fixed_cursor, 0 );
- when 'Z' => set_zap_marker ;
- when 'H' => do_help ( Help_On_Set_Commands_File_Name ) ;
- show_screen( master_buffer,
- master_buffer.fixed_cursor, 0 );
- when others => null ;
- end case ;
- need_prompt := true ; -- we need to reprompt after this...
- end do_set_information_command ;
-
- procedure shift_screen ( columns_to_move_right : in integer ) is
- begin -- shift_screen
- shift( master_buffer , columns_to_move_right ) ;
- show_screen( master_buffer, master_buffer.fixed_cursor , 0 ) ;
- end shift_screen ;
-
- procedure do_verify_screen_command is
- begin -- do_verify_screen_command
- need_prompt := true ;
- show_screen( master_buffer, master_buffer.fixed_cursor,
- window_height(master_buffer) / 2 );
- end do_verify_screen_command ;
-
- function get_marker_name return str10 is
- format ,
- default ,
- new_marker : pstring ;
- final_marker : str10 := " " ;
- begin -- get_marker_name
- format := string_to_pstring(blank_marker);
- default:= string_to_pstring(blank_marker);
- new_marker := crt_windows.
- string_read( format , default , 0 , 0 , 0 , false ) ;
- new_marker := compress( new_marker ) ;
- -- that got rid of leading spaces
- final_marker := blank_marker ;
- for posn in 1 .. length( new_marker ) loop
- final_marker ( posn ) := new_marker.data ( posn ) ;
- end loop ;
- return final_marker ;
- end get_marker_name ;
-
- function find_marker ( name : in str10 ) return marker_number is
- begin -- find_marker
- for posn in 1 .. master_buffer.pagezero.marker_count loop
- if name = master_buffer.pagezero.markers ( posn ) . name then
- return posn ;
- end if ;
- end loop ;
- return 0 ;
- end find_marker ;
-
- procedure set_a_new_marker is
- -- mark the current location with a new marker... and then give it
- -- a name...
- target_marker : str10 ;
- the_marker_number : marker_number ;
- new_posn : character ;
- begin -- set_a_new_marker
- set_prompt( master_buffer , 1 ,
- " What is the new marker's name => " ) ;
- target_marker := get_marker_name ;
- if target_marker /= blank_marker then
- the_marker_number := find_marker( target_marker ) ;
- if the_marker_number > 0 then
- -- marker not found...
- set_prompt( master_buffer , 1 ,
- " Marker """ & compress(target_marker)
- & """ already exists. Reset its location (Y/N) ? ");
- if crt_windows.char_or_abort ( 'N' , 'Y' , 'N' ) = 'Y' then
- -- ok to reset its location
- marker_manager.load_marker( master_buffer.pagezero.markers
- ( the_marker_number ) .location ,
- current_position ) ;
- master_buffer.pagezero.markers(the_marker_number).name
- := target_marker ;
- end if ;
- else
- -- we are ready to set a new marker in the list
- if master_buffer.pagezero.marker_count < max_markers then
- the_marker_number := master_buffer.pagezero.marker_count + 1 ;
- marker_manager.new_marker ( master_buffer.pagezero.markers
- ( the_marker_number ) .location ) ;
- marker_manager.load_marker( master_buffer.pagezero.markers
- ( the_marker_number ) .location ,
- current_position ) ;
- master_buffer.pagezero.markers(the_marker_number).name
- := target_marker ;
- master_buffer.pagezero.marker_count := the_marker_number ;
- else
- -- no room for more markers...
- Clear_window( master_buffer ) ;
- goto_line_column( master_buffer , 3 , 1 ) ;
- for posn in 1 .. max_markers loop
- put(" ");
- put( character'val( posn + 64 ) ) ;
- put(") ");
- put( master_buffer.pagezero.markers(posn).name ) ;
- put_line ;
- end loop ;
- set_prompt( master_buffer , 1 ,
- " Too many Markers. Replace which one (or <Reject> to cancel new marker) ? ");
- new_posn := crt_windows.char_within_range_or_abort(
- ascii.nul , 'A' , character'val( max_markers + 64 )) ;
- if new_posn >= 'A' then
- -- we want to do something...
- the_marker_number := character'pos( new_posn ) - 64 ;
- marker_manager.load_marker( master_buffer.pagezero.markers
- ( the_marker_number ) .location ,
- current_position ) ;
- master_buffer.pagezero.markers(the_marker_number).name
- := target_marker ;
- end if ;
- show_screen ( master_buffer, master_buffer.fixed_cursor , 0 ) ;
- end if ;
- end if ;
- end if ;
- end set_a_new_marker ;
-
- function jump_to_marker return text_position is
- -- jump to a marker command
- target_marker : str10 ;
- the_marker_number : marker_number ;
- begin -- jump_to_marker
- set_prompt( master_buffer , 1 , " Jump to which marker => " ) ;
- target_marker := get_marker_name ;
- if target_marker /= blank_marker then
- the_marker_number := find_marker( target_marker ) ;
- if the_marker_number = 0 then
- -- marker not found...
- error(" Marker """ & compress(target_marker)
- & """ Not Found In Marker List. ",
- not_fatal_error , operator_wait , short_beep ) ;
- return no_set_location ;
- else
- return master_buffer.pagezero.markers(the_marker_number)
- .location .data ;
- end if ;
- else
- return no_set_location ;
- end if ;
- end jump_to_marker ;
-
- begin -- editor_more_packages
- -- EDITMAN2 by SAIC/Clearwater More Main Editor Packages 26 Dec 84
- -- HELP by SAIC/Clearwater Help Package 31 Dec 84
- -- SET by SAIC/Clearwater Set Package 31 Dec 84
- -- SCREEN by SAIC/Clearwater Screen Control Package 23 Jan 85
- -- UMARKER by SAIC/Clearwater User's Marker Package 22 Jan 85
- null ;
- end editor_more_packages ;
-
- --$$$- EDITMAN2
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editman3
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITMAN3
- -- Editor Revised from text Copyright (c) 1984 , R.S.Cymbalski
-
- with string_library, crt_customization, crt_windows ;
- with Wordp_Globals , editor_globals , edit_windows ;
- with buffer_package , editor_misc , markers ;
-
- use string_library, crt_customization;
- use crt , editor_customization;
- use Wordp_Globals , editor_globals , edit_windows ;
- use buffer_package ;
- use buffer_general , buffer_lines ;
- use editor_misc , markers ;
-
- package editor_even_more_packages is
-
- procedure do_justify ( txt : in out type_text_line ) ;
- -- justify single line...
-
- procedure do_re_margin_command ( start_position : cursor_position ;
- do_whole_paragraph : boolean := true ;
- number_of_paragraphs : integer := 1 ) ;
-
- procedure do_enter_exchange_mode ;
-
- end editor_even_more_packages ;
-
- package body editor_even_more_packages is
-
- a_space : constant extended_character :=
- extended_character( character'pos(' ') ) ;
- a_hyphen : constant extended_character :=
- extended_character( character'pos('-') ) ;
-
- procedure put( c : extended_character ) is
- begin -- put
- put( character'val( c ) ) ;
- end put ;
-
- procedure do_justify ( txt : in out type_text_line ) is
- how_many_spaces_to_justify : integer := 0 ;
- how_many_breaks_between_words : integer := 0 ;
- how_many_spaces_to_add_to_each_word_space : integer := 0 ;
- how_many_word_spaces_to_add_an_extra_space_to : integer := 0 ;
- posn : integer ;
- last_printable_text : type_text_length ;
- new_location : type_text_length ;
- old_location : type_text_length ;
- trailing_blanks : integer ;
- leading_spaces : type_leading_spaces ;
- first_text : type_text_length ;
- last_text : type_text_length ;
- ln_length : type_line_length ;
- -- later consider tieing markers to exact chars, even during justification
-
- procedure one_back is
- begin -- one_back
- txt.data(new_location) := txt.data(old_location) ;
- new_location := new_location - 1 ;
- old_location := old_location - 1 ;
- end one_back ;
-
- procedure add_spaces is
- begin -- add_spaces
- for add_a_space in 1..how_many_spaces_to_add_to_each_word_space loop
- txt.data(new_location) := a_space ;
- new_location := new_location - 1 ;
- end loop ;
- if how_many_word_spaces_to_add_an_extra_space_to > 0 then
- how_many_word_spaces_to_add_an_extra_space_to
- := how_many_word_spaces_to_add_an_extra_space_to - 1 ;
- txt.data(new_location) := a_space ;
- new_location := new_location - 1 ;
- end if ;
- end add_spaces ;
-
- begin -- do_justify
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- posn := last_text ;
- -- find last non-blank
- loop
- exit when posn <= first_text ; -- don't do anything
- exit when txt.data(posn) /= a_space;
- posn := posn - 1 ;
- end loop ;
- if posn > first_text then
- -- ok, we have something to work on, a word on a multi word line
- last_printable_text := posn ;
- how_many_spaces_to_justify := master_buffer.pagezero.rmargin
- - last_printable_text ;
- if how_many_spaces_to_justify > 0 then
- -- must do the work. Count the word spaces
- while posn > first_text loop
- posn := posn - 1 ;
- loop
- exit when posn = first_text
- or else txt.data(posn) = a_space ;
- posn := posn - 1 ;
- end loop ;
- if posn > first_text then
- loop
- posn := posn - 1 ;
- exit when posn = first_text
- or else txt.data(posn) /= a_space ;
- end loop ;
- how_many_breaks_between_words
- := how_many_breaks_between_words + 1 ;
- end if ;
- end loop ;
- -- ok, we know the number of word spaces and number of spaces
- if how_many_breaks_between_words > 0 then
- -- needed to justify the line
- how_many_spaces_to_add_to_each_word_space
- := how_many_spaces_to_justify / how_many_breaks_between_words ;
- how_many_word_spaces_to_add_an_extra_space_to
- := how_many_spaces_to_justify mod how_many_breaks_between_words ;
- -- work with last_text to move right
- -- work with last_printable text to begin searching for ' '
- new_location := master_buffer.pagezero.rmargin ;
- -- what about a lot of trailing blanks....
- trailing_blanks := last_text - last_printable_text ;
- if new_location + trailing_blanks >= type_text_length'last then
- -- must truncate some
- trailing_blanks := type_text_length'last - new_location - 1 ;
- last_text := last_printable_text + trailing_blanks ;
- end if ;
- new_location := new_location + trailing_blanks ;
- txt.data_length := new_location ;
- old_location := last_text ;
- -- now, start moving over...
- while new_location /= old_location loop
- -- become identical when we have moved far enough back
- while txt.data(old_location) = a_space loop
- one_back ;
- end loop ;
- while txt.data(old_location) /= a_space loop
- one_back ;
- end loop ;
- exit when new_location = old_location ;
- add_spaces ;
- end loop ;
- -- else no word spaces to work with to justify
- end if ;
- -- else already justified or else a very long line...
- end if ;
- -- else blank line...
- end if ;
- end do_justify ;
-
- procedure do_re_margin_command ( start_position : cursor_position ;
- do_whole_paragraph : boolean := true ;
- number_of_paragraphs : integer := 1 ) is
- margin_command_prompt : constant string ( 1 .. 23 )
- := "Re-Filling Paragraph..." ;
- paragraphs_remaining : integer := number_of_paragraphs ;
- orig_text : type_text_line ;
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- end_of_file: exception ;
- called_on_command_line : exception ;
- input_line_number ,
- output_line_number : line_number ;
- cursor_col : integer ;
- a_break_char:constant extended_character :=
- extended_character( character'pos(
- master_buffer.pagezero.break_char ) ) ;
- orig_cursor_location : constant
- cursor_position := master_buffer.fixed_cursor ;
-
- function load_current_text ( pos : type_buffer_position )
- return boolean is
- len : integer ;
- begin -- load_current_text
- if master_buffer.e_buf(pos).data = buffer_boundry then
- orig_text.data_length := 0 ;
- return false ;
- else
- get_text_line( master_buffer , pos , orig_text ) ;
- for posn in orig_text.data_length + 1 .. max_column_number loop
- orig_text.data(posn) := extended_character(32); -- spaces...
- end loop ;
- get_leading ( orig_text, leading, text_first, text_last, text_leng ) ;
- len := orig_text.data_length ;
- if len > 0
- and then orig_text.data( len ) /= a_space
- and then orig_text.data( len ) /= a_hyphen then
- -- must add space to end
- len := len + 1 ;
- orig_text.data_length := len ;
- orig_text.data( len ) := a_space ;
- end if ;
- return true ;
- end if ;
- end load_current_text ;
-
- procedure margin_initialize is
- begin -- margin_initialize
- -- here ready and willing to work...
- need_prompt := true ; -- When we leave, we will have to re-prompt
- -- remember the cursor position
- master_buffer.fixed_cursor := start_position ;
- if do_whole_paragraph then
- set_repeat_prompt( false , 0 ) ; -- Turn off the counters...
- prompt( margin_command_prompt ) ;
- -- must move backwards to start of current paragraph
- loop
- exit when
- not load_current_text(master_buffer.fixed_cursor.line_start);
- if( text_leng = 0 )
- or else ( orig_text.data(text_first) = a_break_char ) then
- if not cursor_forward_line then
- null ;
- end if ;
- exit ;
- end if ;
- exit when not cursor_backward_line ;
- end loop ;
- -- ok, we are at the start of a paragraph here....
- end if ;
- end margin_initialize ;
-
- procedure eat_this_line is
- -- eat the first line in the open buffer ...
- -- we know that the entire line exists...
- starting_pos : type_buffer_position ;
- ending_position : type_buffer_position ;
- begin -- eat_this_line
- starting_pos := master_buffer.last_open_position + 1 ;
- if master_buffer.e_buf(starting_pos).data /= buffer_boundry then
- ending_position := starting_pos + line_length( master_buffer ,
- starting_pos ) + 3 ;
- master_buffer.last_open_position := ending_position - 1 ;
- end if;
- end eat_this_line ;
-
- procedure read_next_line ( successfull : out boolean ) is
- -- read in the next input line and eat from buffer ...
- success : boolean ;
- begin -- read_next_line
- -- first, make sure we have one line at least in the right part of
- -- the buffer ....
- if master_buffer.last_open_position + max_bytes_in_line
- + max_bytes_in_line
- > master_buffer.bufcount then
- -- we must prepare to push/pop...
- master_buffer.fixed_cursor.line_start
- := master_buffer.first_open_position ;
- close_buffer( master_buffer ) ;
- -- if we are this close to the end...then we must need to pop from
- -- bottom...
- pop_data( master_buffer , thebot , success ) ;
- if not success then
- error( "Disk Error While Re-Filling Paragraph",
- not_fatal_error , operator_wait , short_beep ) ;
- successfull := false ;
- return ;
- end if ;
- open_buffer ( master_buffer , master_buffer.fixed_cursor.line_start ,
- max_bytes_in_line + max_bytes_in_line );
- end if ;
- input_line_number := input_line_number + 1 ;
- if load_current_text( master_buffer.last_open_position + 1 )
- and then ( text_leng > 0 )
- and then ( orig_text.data(text_first) /= a_break_char ) then
- eat_this_line ;
- successfull := true ;
- else
- successfull := false ;
- end if ;
- end read_next_line ;
-
- procedure merge_this_line ( out_line : in out type_text_line ;
- last_line_of_paragraph : boolean := false ) is
- -- move the output line over to the buffer .... make sure that
- -- we have room for two lines in area there..... when done....
- -- else we will push a block....
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- ln_start : type_buffer_position ;
- new_nxt_line : type_buffer_position ;
- successfull : boolean ;
- begin -- merge_this_line
- -- we are working out_line.data ( 1 .. out_line.data_length )
- -- check for justify....
- get_leading ( out_line , leading, text_first, text_last, text_leng ) ;
- if text_leng = 0 then
- return ; -- do nothing (happens possibly at end of paragraph)
- end if ;
- if master_buffer.pagezero.justify
- and then not last_line_of_paragraph then
- -- must justify first
- -- first, must find left boundry
- do_justify ( out_line ) ;
- get_leading ( out_line , leading, text_first, text_last, text_leng ) ;
- end if ;
- ln_start := master_buffer.first_open_position ;
- if master_buffer.first_open_position + max_bytes_in_line
- >= master_buffer.last_open_position then
- -- we must push one block...
- master_buffer.fixed_cursor.line_start := ln_start ;
- if ln_start > block_size then
- push_data( master_buffer , thetop , successfull ) ;
- else
- push_data( master_buffer , thebot , successfull ) ;
- end if ;
- if not successfull then
- error( "No Disk Space while Re-Filling.",
- not_fatal_error , operator_wait , short_beep ) ;
- return ; -- unable to update ...
- else
- ln_start := master_buffer.fixed_cursor.line_start ;
- end if ;
- end if ;
- new_nxt_line := ln_start + text_leng + 3 ;
- master_buffer.e_buf(ln_start).data
- := extended_character(text_leng) ;
- master_buffer.e_buf(ln_start+1 ).data
- := extended_character(leading) ;
- for place in 1 .. text_leng loop
- master_buffer.e_buf(ln_start + 1 + place ).data :=
- out_line.data(text_first+place-1) ;
- end loop ;
- master_buffer.e_buf(ln_start + text_leng + 2 ).data
- := extended_character(text_leng) ;
- for place in ln_start .. ln_start + text_leng + 2 loop
- master_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- master_buffer.first_open_position := new_nxt_line ;
- master_buffer.fixed_cursor.line_start := new_nxt_line ;
- output_line_number := output_line_number + 1 ;
- end merge_this_line ;
-
- procedure add_blank_at_end is
- first_pos : type_buffer_position ;
- begin
- first_pos := master_buffer.fixed_cursor.line_start ;
- for posn in first_pos .. first_pos + 2 loop
- master_buffer.e_buf(posn) := ( extended_character(0) ,
- no_screen_attribute ) ;
- end loop ;
- master_buffer.e_buf( first_pos + 3 ) := ( buffer_boundry ,
- no_screen_attribute ) ;
- master_buffer.bufcount := first_pos + 3 ;
- end ;
-
- procedure margin_this_paragraph is
- -- we get here with the current line loaded....
- out_line : type_text_line ;
- blanks : type_leading_spaces ;
- in_next_pos : type_text_length ;
- out_next_pos : type_text_length ;
- successfull : boolean ;
- word_start : type_text_length ;
- word_stop : type_text_length ;
- spaces_stop : type_text_length ;
- word_length : integer ;
- lastc : character ;
- begin -- margin_this_paragraph
- -- try to remember the column to return to...
- if do_whole_paragraph then
- cursor_col := max_column_number ;
- else
- -- we must remember where the cursor is ...
- cursor_col := master_buffer.fixed_cursor.column_offset ;
- end if ;
- -- prepare to open the buffer....
- input_line_number := master_buffer.fixed_cursor.file_line_number ;
- output_line_number := input_line_number ;
- open_buffer( master_buffer , master_buffer.fixed_cursor.line_start ,
- max_bytes_in_line + max_bytes_in_line ) ;
- eat_this_line ;
- -- ok, here with a line in memory, and buffer open...
- if do_whole_paragraph then
- -- we start with para margin blanks...
- blanks := master_buffer.pagezero.paramargin ;
- else
- blanks := leading ; -- keep leading spaces intact...
- end if ;
- for pos in 1 .. blanks loop
- out_line.data(pos) := a_space ;
- end loop ;
- out_line.data_length := blanks ;
- in_next_pos := text_first ;
- out_next_pos := blanks + 1 ;
- successfull := true ;
- loop
- -- now, loop, moving over text from input to output ...
- -- work orig_text to text_last ...
- if in_next_pos > text_last then
- read_next_line ( successfull ) ;
- in_next_pos := text_first ;
- exit when not successfull ;
- else
- -- get the next word from input, move to output if room ...
- word_start := in_next_pos ;
- loop
- in_next_pos := in_next_pos + 1 ;
- exit when ( in_next_pos > orig_text.data_length )
- or else ( orig_text.data( in_next_pos ) = a_space )
- or else ( orig_text.data( in_next_pos ) = a_hyphen ) ;
- end loop ;
- if in_next_pos > orig_text.data_length then
- word_stop := in_next_pos - 1 ;
- spaces_stop := word_stop ;
- elsif orig_text.data( in_next_pos ) = a_hyphen then
- word_stop := in_next_pos ;
- if in_next_pos < orig_text.data_length
- and then orig_text.data( in_next_pos + 1 ) = a_space then
- spaces_stop := spaces_stop + 1 ;
- else
- spaces_stop := word_stop ;
- end if ;
- -- now, kill all spaces following...
- in_next_pos := spaces_stop ;
- loop
- in_next_pos := in_next_pos + 1 ;
- exit when ( in_next_pos > orig_text.data_length )
- or else ( orig_text.data( in_next_pos ) /= a_space ) ;
- end loop ;
- else
- -- here on a single space...
- word_stop := in_next_pos - 1 ;
- -- we allow a second space in some instances......
- lastc := character'val( orig_text.data(word_stop) ) ;
- if in_next_pos < orig_text.data_length -- more text exists
- and then orig_text.data( in_next_pos + 1 ) = a_space
- and then ( ( lastc = '.' )
- or ( lastc = '!' )
- or ( lastc = '"' )
- or ( lastc = ')' )
- or ( lastc = '?' )
- or ( lastc = ',' )
- or ( lastc = ']' )
- or ( lastc = ':' ) ) then
- spaces_stop := in_next_pos + 1 ;
- in_next_pos := in_next_pos + 1 ;
- else
- spaces_stop := in_next_pos ; -- only allow one space..
- end if ;
- loop
- in_next_pos := in_next_pos + 1 ;
- exit when ( in_next_pos > orig_text.data_length )
- or else ( orig_text.data( in_next_pos ) /= a_space ) ;
- end loop ;
- -- spaces_stop := in_next_pos - 1 ; -- if we allow any number
- -- of spaces, then the above line would go in instead....
- end if ;
- -- ok, we are here with word_start , word_stop and spaces_stop
- word_length := word_stop - word_start + 1 ;
- if out_next_pos + word_length - 1
- > master_buffer.pagezero.rmargin then
- -- it cannot fit on this line.....
- out_line.data_length := out_next_pos - 1 ;
- merge_this_line ( out_line ) ;
- blanks := master_buffer.pagezero.lmargin ;
- for pos in 1 .. blanks loop
- out_line.data(pos) := a_space ;
- end loop ;
- out_line.data_length := blanks ;
- out_next_pos := blanks + 1 ;
- end if ;
- for pos in 1 .. word_length loop
- out_line.data ( out_next_pos )
- := orig_text.data ( word_start + pos - 1 ) ;
- out_next_pos := out_next_pos + 1 ;
- end loop ;
- for pos in word_stop + 1 .. spaces_stop loop
- out_line.data(out_next_pos) := a_space ;
- out_next_pos := out_next_pos + 1 ;
- end loop ;
- end if ;
- end loop ;
- -- and move last output line over to input...
- out_line.data_length := out_next_pos - 1 ;
- merge_this_line ( out_line , true ) ;
- close_buffer ( master_buffer ) ;
- -- reposition cursor-- we know that orig_cursor_location is set as the line/column we
- -- had upon entry...
- master_buffer.fixed_cursor.buffer_position := 0 ;
- master_buffer.fixed_cursor.file_line_number:= output_line_number ;
- master_buffer.fixed_cursor.column_offset := 0 ;
- -- master_buffer.fixed_cursor.line_start already set...
- if master_buffer.e_buf( master_buffer.fixed_cursor.line_start ).data
- = buffer_boundry
- -- we might have to fix up end of file...
- and then output_line_number > 1
- -- not on first line...
- and then master_buffer.e_buf(master_buffer.fixed_cursor.line_start)
- .data /= 0 then
- -- must add in three nulls....
- add_blank_at_end;
- end if ;
- -- Note that if we really wanted to make markers work after
- -- margining, here is where we would implement it...
- if do_whole_paragraph then
- jump_to_position ( master_buffer ,
- master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset ,
- false ) ;
- else
- jump_to_position ( master_buffer ,
- orig_cursor_location.file_line_number ,
- orig_cursor_location.column_offset ,
- false ) ;
- end if ;
- end margin_this_paragraph ;
-
- procedure margin_finish is
- begin -- margin_finish
- show_screen ( master_buffer ,
- master_buffer.fixed_cursor ,
- window_height ( master_buffer ) / 2 ) ;
- end margin_finish ;
-
- begin -- do_re_margin_command
- if do_whole_paragraph
- and then not ( master_buffer.pagezero.filling
- and not master_buffer.pagezero.autoindent ) then
- -- must check information on status...
- -- inappropriate environment
- error( "Inappropriate Environment.",
- not_fatal_error , operator_wait , short_beep ) ;
- return ;
- end if ;
- -- start of margining....
- margin_initialize ;
- while paragraphs_remaining > 0 loop
- paragraphs_remaining := paragraphs_remaining - 1 ;
- if do_whole_paragraph then
- -- first, skip any leading lines which are commands
- -- or blank lines
- loop
- exit when
- not load_current_text ( master_buffer.fixed_cursor.line_start )
- or else ( text_leng = 0 )
- or else ( orig_text.data(text_first) /= a_break_char ) ;
- if not cursor_forward_line then
- raise end_of_file ;
- end if ;
- end loop ;
- else
- if not load_current_text ( master_buffer.fixed_cursor.line_start) then
- raise called_on_command_line ;
- end if ;
- if ( text_leng = 0 )
- or else ( orig_text.data(text_first) = a_break_char ) then
- raise called_on_command_line ;
- end if ;
- end if ;
- -- we get here with the current line loaded, and ready to go....
- margin_this_paragraph ;
- end loop ;
- margin_finish ;
- exception
- when end_of_file => margin_finish ;
- when called_on_command_line => margin_finish ;
- end do_re_margin_command ;
-
- procedure do_enter_exchange_mode is
- -- where is the exchange cursor in the file ?
- x_line_number : line_number ;
- x_column_number : column_position ;
- -- where is the exchange cursor on the screen ?
- w_line_number : window_line_number ;
- -- what does the screen look like ?
- w_top_line : line_number ;
- w_bot_line : line_number ;
- w_left_column : column_position ;
- w_right_column : column_position ;
- -- what is the home position for exchange with a <cr> ?
- home_column : column_position := 0 ;
- -- what is the text for the current line ?
- we_have_current_text : boolean := false ;
- txt : type_text_line ;
- orig_text : type_text_line ; -- the original text line....
- command_char : character ;
- editor_command : editor_globals.an_editor_command ;
- save_cursor : cursor_position ;
-
- procedure set_window_positions is
- -- we need to set the values that tell us were the window is
- begin
- w_top_line := master_buffer.top_screen_cursor.file_line_number ;
- w_bot_line := w_top_line + window_height( master_buffer ) - 1 ;
- w_left_column := lowest_column_number( master_buffer ) ;
- w_right_column := highest_column_number( master_buffer ) ;
- end;
-
- procedure initialize_exchange is
- begin -- initialize_exchange
- set_window_positions ;
- -- where is the exchange cursor in the file ?
- x_line_number := master_buffer.fixed_cursor.file_line_number ;
- x_column_number := master_buffer.fixed_cursor.column_offset ;
- -- where is the exchange cursor on the screen ?
- w_line_number := x_line_number - w_top_line + 1 ;
- set_repeat_prompt( false , 0 ) ;
- prompt( exchange_command_prompt ) ;
- show_cursor( master_buffer ) ;
- save_cursor := master_buffer.fixed_cursor ;
- end initialize_exchange ;
-
- procedure get_c_or_command( c : out character ;
- cmd: out editor_globals.an_editor_command ) is
- -- get either a printable character or else get an editor command...
- -- note that here, printable characters take priority over commands
- physical_c : character ;
- physical_command : crt.special_keys ;
- begin -- get_c_or_command
- crt_windows.key_input( physical_c , physical_command ) ;
- if physical_command = key_character
- and then physical_c in ' ' .. '~' then
- -- easy... is just a printable character ...????
- c := physical_c ;
- cmd := editor_customization.illegal_command ;
- -- I really wanted to use editor_globals.illegal_command.......
- else
- -- need to find out what it might be...
- translate( physical_c , physical_command , c , cmd ) ;
- end if ;
- end get_c_or_command ;
-
- procedure reshow_line is
- -- for a reject command
- begin -- reshow_line ;
- clear_end_of_line ( master_buffer , w_line_number , w_left_column ) ;
- show_line ( master_buffer ,
- master_buffer.fixed_cursor.line_start ,
- master_buffer.fixed_cursor.file_line_number ) ;
- show_cursor( master_buffer ) ;
- end reshow_line ;
-
- procedure load_current_text is
- begin -- load_current_text
- save_cursor := master_buffer.fixed_cursor ;
- get_text_line( master_buffer , save_cursor.line_start , orig_text ) ;
- for posn in orig_text.data_length + 1 .. max_column_number loop
- orig_text.data(posn) := extended_character(32); -- spaces...
- end loop ;
- txt := orig_text ;
- we_have_current_text := true ;
- end load_current_text ;
-
- procedure replace_current_text is
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- old_leng : type_line_length ;
- ln_start : type_buffer_position ;
- old_nxt_line ,
- new_nxt_line : type_buffer_position ;
- successfull : boolean ;
- begin -- replace_current_text
- -- first, we need to check out this line....
- -- has it changed????
- if txt /= orig_text then
- -- yes it has changed....
- -- Then, reset the length and the leading spaces ...
- -- x_column_number - 1 is the highest column number worked with...
- if x_column_number - 1 > txt.data_length then
- txt.data_length := x_column_number - 1 ;
- end if ;
- get_leading ( txt , leading , text_first , text_last , text_leng ) ;
- ln_start := master_buffer.fixed_cursor.line_start ;
- old_leng := line_length( master_buffer , ln_start ) ;
- -- move this line into the buffer....
- -- 1: Open or close Buffer by appropriate positions
- -- At most, we will add text_leng characters, because the line
- -- must already have the 3 control characters
- if old_leng < text_leng then
- -- must make sure we have room in buffer...
- if master_buffer.bufcount - old_leng + text_leng > max_buffer_size
- then
- -- we must push one block...
- if ln_start > block_size then
- push_data( master_buffer , thetop , successfull ) ;
- else
- push_data( master_buffer , thebot , successfull ) ;
- end if ;
- if not successfull then
- error( "Unable to update line. No Temporary File Room.",
- not_fatal_error , operator_wait , short_beep ) ;
- return ; -- unable to update ...
- else
- ln_start := master_buffer.fixed_cursor.line_start ;
- end if ;
- end if ;
- end if ;
- old_nxt_line := ln_start + old_leng + 3 ;
- new_nxt_line := ln_start + text_leng + 3 ;
- shift_buffer_area ( master_buffer , old_nxt_line , new_nxt_line ,
- master_buffer.bufcount - old_nxt_line + 1 ) ;
- master_buffer.bufcount:=master_buffer.bufcount -old_leng +text_leng ;
- -- that shortens or lengthens as appropriate...
- -- 3: Add the new line
- master_buffer.e_buf(ln_start).data
- := extended_character(text_leng) ;
- master_buffer.e_buf(ln_start+1 ).data
- := extended_character(leading) ;
- for place in 1 .. text_leng loop
- master_buffer.e_buf(ln_start + 1 + place ).data :=
- txt.data(text_first+place-1) ;
- end loop ;
- master_buffer.e_buf(ln_start + text_leng + 2 ).data
- := extended_character(text_leng) ;
- for place in ln_start .. ln_start + text_leng + 2 loop
- master_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- -- 4: Adjust Markers
- -- any changes in the current line do not affect other lines, and
- -- the typeover on the current line makes it impossible to figure
- -- any better setting than the current one...
- end if ;
- we_have_current_text := false ;
- end replace_current_text ;
-
- procedure make_next_position_valid_on_screen is
- begin
- if x_column_number = w_right_column then
- -- we are going off the screen ...
- master_buffer.fixed_cursor.column_offset := x_column_number + 1 ;
- show_cursor( master_buffer ) ;
- set_window_positions ;
- goto_line_column( master_buffer , w_line_number , w_left_column ) ;
- for posn in w_left_column .. x_column_number - 1 loop
- -- put out the new line ...
- put( txt.data(posn) ) ;
- end loop ;
- end if ;
- end;
-
- procedure do_char ( c : in character ) is
- begin -- do_char
- if x_column_number <= max_column_number then
- -- first, check screen ...
- make_next_position_valid_on_screen ;
- -- then, change screen
- put( c ) ;
- -- next, change txt
- txt.data( x_column_number ) := extended_character( character'pos(c) );
- -- finally, change position
- x_column_number := x_column_number + 1 ;
- end if ;
- end do_char ;
-
- procedure backup_char is
- begin -- backup_char
- if x_column_number > 1 then
- if x_column_number = w_left_column then
- -- we are going off the screen ...
- master_buffer.fixed_cursor.column_offset := x_column_number - 1 ;
- show_cursor( master_buffer ) ;
- set_window_positions ;
- goto_line_column( master_buffer , w_line_number , w_left_column ) ;
- for posn in w_left_column .. x_column_number - 1 loop
- -- put out the new line ...
- put( txt.data(posn) ) ;
- end loop ;
- end if ;
- x_column_number := x_column_number - 1 ;
- goto_line_column( master_buffer , w_line_number , x_column_number ) ;
- txt.data( x_column_number ) := orig_text.data( x_column_number ) ;
- put( txt.data( x_column_number ) ) ;
- goto_line_column( master_buffer , w_line_number , x_column_number ) ;
- end if ;
- end backup_char ;
-
- procedure forward_char is
- begin -- forward_char
- if x_column_number <= max_column_number then
- -- first, check screen ...
- make_next_position_valid_on_screen ;
- -- then, change screen
- put( txt.data( x_column_number ) ) ;
- -- finally, change position
- x_column_number := x_column_number + 1 ;
- end if ;
- end forward_char ;
-
- procedure move_up ( new_column_number : column_position ) is
- -- a zero means first text on line
- begin -- move_up
- if cursor_backward_line then
- -- ok, we moved back a line...
- -- set the column number ;
- if new_column_number > 0 then
- master_buffer.fixed_cursor.column_offset := new_column_number ;
- else
- master_buffer.fixed_cursor.column_offset :=
- num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) + 1 ;
- end if ;
- x_column_number := master_buffer.fixed_cursor.column_offset ;
- if x_line_number = w_top_line then
- -- we must reshow screen ...
- show_cursor( master_buffer ) ;
- save_cursor := master_buffer.fixed_cursor ;
- set_window_positions ;
- x_line_number := x_line_number - 1 ;
- w_line_number := x_line_number - w_top_line + 1 ;
- else
- show_cursor( master_buffer ) ;
- x_line_number := x_line_number - 1 ;
- w_line_number := w_line_number - 1 ;
- end if ;
- end if ;
- end move_up ;
-
- procedure move_down ( new_column_number : column_position ) is
- -- a zero means first text on line
- begin -- move_down
- if cursor_forward_line then
- -- ok, we moved back a line...
- -- set the column number ;
- if new_column_number > 0 then
- master_buffer.fixed_cursor.column_offset := new_column_number ;
- else
- master_buffer.fixed_cursor.column_offset :=
- num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start ) + 1 ;
- end if ;
- x_column_number := master_buffer.fixed_cursor.column_offset ;
- if x_line_number = w_bot_line then
- -- we must reshow screen ...
- show_cursor( master_buffer ) ;
- save_cursor := master_buffer.fixed_cursor ;
- set_window_positions ;
- x_line_number := x_line_number + 1 ;
- w_line_number := x_line_number - w_top_line + 1 ;
- else
- show_cursor( master_buffer ) ;
- x_line_number := x_line_number + 1 ;
- w_line_number := w_line_number + 1 ;
- end if ;
- end if ;
- end move_down ;
-
- procedure set_home_column is
- begin -- set_home_column
- clear_prompt_end_of_line( master_buffer , 1 , 1 ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- put(">eXchange: Home column ");
- if home_column = 0 then
- -- they are setting the column
- home_column := x_column_number ;
- put("set to column #");
- put( home_column , 1 ) ;
- else
- -- resetting the column
- home_column := 0 ;
- put("erased ");
- end if ;
- goto_line_column( master_buffer , w_line_number , x_column_number ) ;
- end set_home_column ;
-
- procedure finish_exchange is
- begin -- finish_exchange
- need_prompt := true ;
- master_buffer.fixed_cursor.file_line_number := x_line_number ;
- master_buffer.fixed_cursor.column_offset := x_column_number ;
- end finish_exchange ;
-
- begin -- do_enter_exchange_mode
- initialize_exchange ;
- loop
- get_c_or_command( command_char , editor_command ) ;
- case editor_command is
- when illegal_command => -- is a character to put into line
- if command_char /= ascii.nul then
- -- is a real character...
- if not we_have_current_text then
- load_current_text ;
- end if ;
- -- Now, put the character in...
- -- and then move right...
- do_char( command_char ) ;
- end if ;
- when up_command => -- finish current line and move up
- if we_have_current_text then
- replace_current_text ;
- end if ;
- move_up( x_column_number ) ;
- when down_command => -- finish current line and move down
- if we_have_current_text then
- replace_current_text ;
- end if ;
- move_down( x_column_number ) ;
- when left_command => -- replace character & move left
- if not we_have_current_text then
- load_current_text ;
- end if ;
- backup_char ;
- when right_command => -- skip one character to the right
- if not we_have_current_text then
- load_current_text ;
- end if ;
- forward_char ;
- when accept_command => -- move the text line back into buffer
- if we_have_current_text then
- replace_current_text ;
- end if ;
- when reject_command => -- redraw the line as it was...
- if we_have_current_text then
- -- have to fix it...
- reshow_line ;
- end if ;
- when advance_line_command
- | forward_line_command => -- move to next line at home position
- if we_have_current_text then
- replace_current_text ;
- end if ;
- move_down( home_column ) ;
- when home_command => -- adjust the home position
- set_home_column ;
- when others => null ; -- skip them......
- end case ;
- exit when editor_command = accept_command
- or editor_command = reject_command ;
- end loop ;
- finish_exchange ;
- end do_enter_exchange_mode ;
-
- begin -- editor_even_more_packages
- -- EDITMAN3 by SAIC/Clearwater More Main Editor Packages 26 Dec 84
- -- REMARGIN by SAIC/Clearwater Re Margin Package 31 Dec 84
- -- EXCHANGE by SAIC/Clearwater Exchange Package 22 Feb 85
- null ;
- end editor_even_more_packages ;
-
- --$$$- EDITMAN3
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --editfile
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDITFILE
-
- --
- -- File 018
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- --
- -- Editor Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with text_io ;
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_block_io ;
- use buffer_general ;
- use buffer_lines ;
-
- with markers ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- with environment_input_output ;
-
- package editor_files is
-
- procedure editor_master_reset ;
- -- initialize the editor
-
- procedure editor_re_initialize ( Had_Old_File : out Boolean ) ;
- -- Returns true if the buffer was loaded from a text file
-
- procedure do_copy_command ;
-
- procedure do_quit_command ( partial , total : in out boolean ) ;
-
- end editor_files ;
-
- package body editor_files is
-
- procedure editor_master_reset is
- -- initialize the editor
- begin -- editor_master_reset
- -- text_io.put(" Init Buffer ");
- initialize_buffer( master_buffer , 1 ) ;
- -- Initialize a buffer as buffer #1
- -- text_io.put(" I B End ");
- master_window := crt_windows.create_window (
- 1 , basic_io_system.total_crt_col ,
- 1 , basic_io_system.total_crt_line ,
- true , 1 ) ;
- -- text_io.put(" Create Window End ");
- -- Create a screen window
- -- Make the window the entire screen, with a 1 line status area
- -- at the top of the window
- map_window( master_window , master_buffer ) ;
- -- Map the master buffer onto the master_window
- clear_prompt( master_buffer ) ;
- clear_window( master_buffer ) ;
- end editor_master_reset ;
-
- procedure editor_re_initialize ( Had_Old_File : out Boolean ) is
- -- Returns true if the buffer was loaded from a text file
- final_name : ascii_text_file_name ;
- ok : boolean ;
- working_had_old_file : boolean ;
- begin -- editor_re_initialize
- need_prompt := true ;
- clear_prompt( master_buffer ) ;
- clear_window( master_buffer ) ;
- if editor_entry_input_file_name = blank_file_name then
- ok := false ;
- else
- ok_to_read( editor_entry_input_file_name , final_name , ok ) ;
- end if ;
- if not ok then
- -- we need to read in another file name
- -- here on no input file name or file does not exist.
- if editor_entry_input_file_name /= blank_file_name then
- error( " File """ & string_library.compress(final_name)
- & """ does not exist." ,
- not_fatal_error , operator_wait , short_beep ) ;
- end if ;
- loop
- set_prompt( master_buffer , 1 ,
- editor_customization.enter_input_file_name_prompt ) ;
- editor_requested_input_file_name := get_input_filename_or_return ;
- if editor_requested_input_file_name = blank_file_name then
- -- we have to make a new file
- working_had_old_file := false ; -- No old file to load, just need to insert
- else
- if editor_requested_input_file_name( 1 ) = ascii.esc then
- -- an error, the file name did not exist
- error(" File """ & compress(editor_requested_input_file_name
- ( 2 .. editor_requested_input_file_name'length ) )
- & """ does not exist." ,
- not_fatal_error , operator_wait , short_beep ) ;
- else
- working_had_old_file := true ; -- a good file name and exists....
- end if ;
- end if ;
- exit when editor_requested_input_file_name( 1 ) /= ascii.esc ;
- end loop ;
- else
- -- a good entry file name
- editor_requested_input_file_name := final_name ;
- working_had_old_file := true ;
- end if ;
- -- here with either an old file or else nothing...
- if working_had_old_file then
- load_file( master_buffer , editor_requested_input_file_name ) ;
- show_screen( master_buffer ) ;
- else
- -- need to set the default environment
- master_buffer.input_file_name := blank_file_name ;
- re_initialize(master_buffer); -- reset as empty buffer
- environment_input_output.users_default_header(master_buffer.pagezero);
- end if ;
- had_old_file := working_had_old_file ;
- end editor_re_initialize ;
-
- procedure do_copy_command is
-
- function mapup ( s : in pstring ) return pstring is
- new_s : pstring := s ;
- begin
- for posn in 1 .. length(new_s) loop
- if new_s.data(posn) in 'a' .. 'z' then
- new_s.data(posn) := character'val( character'pos( new_s.data(posn) )
- - character'pos('a')
- + character'pos('A') );
- end if ;
- end loop ;
- return new_s ;
- end;
-
- procedure copy_in_copy_file is
- format ,
- default ,
- users_response: pstring ;
- fname : ascii_text_file_name ;
- blank_marker : constant str10 := " " ;
- marker_one : str10 ;
- marker_two : str10 ;
- place1 , place2 , place3 : integer ;
- ret_file_name : ascii_text_file_name := no_file ;
- pfile_name : pstring ;
- ok : boolean ;
- temp_marker : pstring ;
- orig_line : line_number ;
- orig_column : column_position ;
- orig_screen_line : window_line_number ;
- begin -- copy_in_copy_file
- loop
- -- while we have erroneous file names returned...
- -- or else bad marker names....
- fname := no_file ;
- marker_one := blank_marker ;
- marker_two := blank_marker ;
- clear_prompt( master_buffer ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 );
- put( Enter_Copied_In_File_Name_Prompt );
- format := string_to_pstring(" ");
- default := format ;
- users_response := crt_windows.string_read( format , default ) ;
- exit when users_response = default ; -- do nothing ...
- -- First, separate out the part from '[' on...
- if position('[',users_response) /= 0 then
- -- they asked for markers work...
- place1 := position('[',users_response) + 1 ;
- place2 := position(',',users_response) + 1 ;
- place3 := position(']',users_response) + 1 ;
- if place3 = 1 then
- place3 := length(users_response) + 2 ;
- if place2 = 1 then
- place2 := length(users_response) + 2 ;
- end if ;
- end if ;
- if place2 - place1 > 1 then
- -- we want to work first marker
- for offset in 1 .. place2 - place1 - 1 loop
- temp_marker.data(offset)
- := users_response.data( place1 + offset - 1);
- end loop ;
- set_length( temp_marker , place2 - place1 - 1 ) ;
- temp_marker := mapup( compress( temp_marker ) ) ;
- if length( temp_marker ) > marker_one'last then
- set_length( temp_marker , marker_one'last ) ;
- end if ;
- for posn in 1 .. length(temp_marker) loop
- marker_one(posn) := temp_marker.data(posn) ;
- end loop ;
- end if ;
- if place3 - place2 > 1 then
- -- we want to work second marker
- for offset in 1 .. place3 - place2 - 1 loop
- temp_marker.data(offset)
- := users_response.data( place2 + offset - 1);
- end loop ;
- set_length( temp_marker , place3 - place2 - 1 ) ;
- temp_marker := mapup( compress( temp_marker ) ) ;
- if length( temp_marker ) > marker_two'last then
- set_length( temp_marker , marker_two'last ) ;
- end if ;
- for posn in 1 .. length(temp_marker) loop
- marker_two(posn) := temp_marker.data(posn) ;
- end loop ;
- end if ;
- -- now, get rid of the excess characters to check the file name
- set_length( users_response , place1 - 2 ) ;
- -- else use blank markers already set...
- end if ;
- -- we end up here after cleaning off the marker names ( if any )
- -- Now, we will first allow the addition of .text
- if length(users_response) <= maximum_file_name_length -
- default_text_file_suffix'length then
- if position('.',users_response) = 0 then
- users_response := compress(users_response)
- & default_text_file_suffix ;
- end if;
- end if ;
- if users_response.data( length(users_response) ) = '.' then
- set_length( users_response , length(users_response) - 1 ) ;
- -- eat last '.'
- end if ;
- if length(users_response) > maximum_file_name_length then
- set_length( users_response , maximum_file_name_length ) ;
- end if ;
- fname( 1 .. length(users_response) ) :=
- users_response.data( 1 .. length(users_response) ) ;
- -- Now, check for all valid characters
- ok := true ;
- for posn in 1 .. maximum_file_name_length loop
- ok := ok and
- ( ( ( fname( posn ) = basic_io_system.directory_separator )
- and ( fname( posn ) /= ' ' ) )
- or ( fname( posn ) = '.' )
- or ( ( fname(posn)>='A' ) and ( fname(posn)<='Z' ) )
- or ( ( fname(posn)>='a' ) and ( fname(posn)<='z' ) )
- or ( ( fname(posn)>='0' ) and ( fname(posn)<='9' ) )
- or ( fname(posn) = ':' ) -- always legal......
- or ( fname(posn) = ' ' ) -- eaten by no_blanks
- ) ;
- end loop ;
- if not ok then
- -- give invalid character in name error
- error(" Bad Character In Filename """ & compress(fname) & """." ,
- not_fatal_error , operator_wait , short_beep ) ;
- else
- -- Now, check for number of characters past '.'
-
- -- And finally, check for existance of file itself
- ok_to_read( fname , pfile_name , ok ) ;
- if ok then
- -- must turn pfile_name into correct format
- fname := no_file ; -- put blanks into file name
- for posn in 1 .. length(pfile_name) loop
- -- note that we are not checking here for string too long ...
- fname(posn) := pfile_name.data(posn);
- end loop ;
- else
- -- not ok
- error(" File """ & compress(fname) & """ does not exist." ,
- not_fatal_error , operator_wait , short_beep ) ;
- end if;
- end if ;
- exit when ok ;
- end loop ; -- waiting for good file name or marker name ...
- if fname /= no_file then
- -- ok, we have a good file name to work...
- -- ready to work....
- clear_prompt( master_buffer ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 );
- if marker_one = blank_marker and marker_two = blank_marker then
- put(" Copying in entire file """ & compress(fname) & """.");
- else
- put("Copying in file """ & compress(fname) & """ from ");
- if marker_one = blank_marker then
- put("the Beginning") ;
- else
- put("Marker """ & compress(marker_one) & """" ) ;
- end if ;
- put(" to ");
- if marker_two = blank_marker then
- put("the End.") ;
- else
- put("Marker """ & compress(marker_two) & """.");
- end if ;
- end if ;
- orig_line := master_buffer.fixed_cursor.file_line_number ;
- orig_column := master_buffer.fixed_cursor.column_offset ;
- orig_screen_line := orig_line - master_buffer.top_screen_cursor.
- file_line_number + 1 ;
- copy_file( master_buffer , fname , marker_one , marker_two ) ;
- jump_to_position ( master_buffer, orig_line , orig_column ,
- false ) ;
- master_buffer.fixed_cursor.column_offset :=
- num_leading_spaces(master_buffer,
- master_buffer.fixed_cursor.line_start ) + 1 ;
- show_screen( master_buffer ) ;
- -- , master_buffer.fixed_cursor , orig_screen_line ) ;
- markers.marker_manager.load_marker(
- master_buffer.last_marked_position , current_position ) ;
- end if ;
- end copy_in_copy_file ;
-
- begin -- do_copy_command
- clear_prompt( master_buffer ) ;
- goto_prompt_line_column( master_buffer , 1 , 1 ) ;
- put( copy_command_prompt ) ;
- case crt_windows.char_or_abort( ' ' , ' ' , 'B' , 'F' ) is
- when 'B' => Copy_Text_Back_From_Copy_Buffer ( Master_Buffer ) ;
- when 'F' => copy_in_copy_file ;
- when others => null ;
- end case ;
- need_prompt := true ;
- end do_copy_command ;
-
- procedure do_quit_command ( partial , total : in out boolean ) is
- out_option : character ; -- the option selected by the user
- second_option : character ; -- secondary out option
-
- function get_yes_no return boolean is
- begin -- get_yes_no
- return crt_windows.char_or_abort( 'N' , 'Y' , 'N' ) = 'Y' ;
- end get_yes_no ;
-
- procedure get_responses is
- valid_responses : crt_windows.character_set ;
- ok_answer : boolean ;
- begin -- get_responses
- loop
- -- First, set up the valid user responses
- crt_windows.clear_set(valid_responses);
- valid_responses('B') := true ;
- valid_responses('E') := true ;
- valid_responses('R') := true ;
- valid_responses('W') := true ;
- clear_window( master_buffer ) ;
- set_prompt( master_buffer , 1 ,
- editor_customization.quit_command_prompt ) ;
- goto_line_column( master_buffer , 2 , 1 ) ;
- put_line(" B(egin editing another file without updating "
- & "current file");
- put_line(" E(xit without updating file");
- put_line(" R(eturn to the editor without updating file");
- put_line(" W(rite to a file name");
- if master_buffer.input_file_name /= no_file
- or else master_buffer.output_file_name /= no_file then
- -- we had an input file name
- put (" S(ave and update the ");
- if master_buffer.output_file_name = no_file then
- put ( "original file, """);
- put (compress(master_buffer.input_file_name));
- else
- put ( "last output file, """);
- put (compress(master_buffer.output_file_name));
- end if ;
- put_line("""");
- valid_responses('S') := true ;
- end if ;
- if master_buffer.copy_file_name /= no_file then
- -- we had a copy file name
- put (" X(change - Save into the copied in file, """);
- put (compress(master_buffer.copy_file_name));
- put_line("""");
- valid_responses('X') := true ;
- end if ;
- if editor_entry_output_file_name /= no_file
- and then editor_entry_output_file_name /=
- master_buffer.input_file_name then
- -- we had a copy file name
- put (" D(estination. Save as the specified ");
- put ( "Destination File """);
- put (compress(editor_entry_output_file_name));
- put_line("""");
- valid_responses('D') := true ;
- end if ;
- if not only_editor then
- -- we have to give the word processor as an option
- put_line(" P(rint a document without updating current file");
- valid_responses('P') := true ;
- end if ;
- put_line;
- put(" Option ? ");
- out_option := crt_windows.goodchar( valid_responses , 'R' );
- if ( ( out_option = 'B' ) or ( out_option = 'P' )
- or ( out_option = 'E' ) ) -- we are going to exit without updating
- or else ( ( out_option = 'S' ) and
- ( master_buffer.copy_file_name /= no_file ) ) then
- -- we really should have the user confirm it
- put_line;
- put_line;
- put(" Are You Sure (Y/N) ? ");
- ok_answer := get_yes_no ;
- else
- ok_answer := true ;
- end if ;
- exit when ok_answer ;
- end loop ;
- end get_responses ;
-
- function to_backup_name ( a_name : in ascii_text_file_name )
- return ascii_text_file_name is
- new_name : pstring ;
- new_ascii_name : ascii_text_file_name := no_file ;
- posn : integer ;
- begin -- to_backup_name
- new_name := compress( a_name ) ;
- posn := position('.' , new_name ) ;
- if posn = 0 then
- posn := length(new_name) + 1 ;
- end if ;
- -- Now, posn is where we will put the .bak ending
- if posn + default_backup_ending'length - 1
- > ascii_text_file_name'length then
- -- need to shorten the starting string
- posn := ascii_text_file_name'length
- - default_backup_ending'length + 1 ;
- end if ;
- set_length( new_name , posn + default_backup_ending'length - 1 ) ;
- for place in 1 .. default_backup_ending'length loop
- new_name.data( posn + place - 1 ) := default_backup_ending( place ) ;
- end loop ;
- for place in 1 .. length( new_name ) loop
- new_ascii_name ( place ) := new_name.data ( place ) ;
- end loop ;
- return new_ascii_name ;
- end to_backup_name ;
-
- procedure get_output_file_name is
- done : boolean ;
- begin -- get_output_file_name
- -- They typed in 'W' for write to file name. Get a file name
- -- and confirm that it is available for writing. Then,
- -- set editor_requested_output_file_name. If they hit a
- -- return, then we will set the second_option to 'A' for abort
- -- as well as the out_option
- --
- -- Note that we must know exactly what the screen looks like
- --
- done := false ;
- loop
- clear_end_of_screen( master_buffer , 13 , 1 ) ;
- goto_line_column ( master_buffer , 13 , 1 ) ;
- put(" Enter Output File Name ( or <return> to abort ) => ") ;
- editor_requested_output_file_name :=
- get_output_filename_or_return ;
- if editor_requested_output_file_name = blank_file_name then
- -- we want to return to the editor
- out_option := 'A' ;
- second_option := 'A' ;
- done := true ;
- elsif editor_requested_output_file_name( 1 ) = ascii.esc then
- -- an error, the file name did not exist
- error(" File """
- & compress(editor_requested_output_file_name
- ( 2 .. editor_requested_output_file_name'length ) )
- & """ is an invalid name." ,
- not_fatal_error ,
- operator_wait ,
- short_beep ) ;
- elsif file_exists ( editor_requested_output_file_name ) then
- -- we must confirm that they want to save it
- put_line;
- put_line;
- put_line(" File """ & compress(editor_requested_output_file_name)
- & """ already exists. ");
- put_line;
- -- put (" Rename it to """ &
- -- compress( to_backup_name
- -- ( editor_requested_output_file_name )
- -- ) & """ and continue (Y/N) ? ");
- put (" Delete """ &
- compress( editor_requested_output_file_name
- ) & """ and continue (Y/N) ? ");
- done := get_yes_no ; -- if they say "Y", then we will just leave.
- -- when it comes time to writing, we will automatically rename
- -- otherwise, if they say no, then re-ask the question for a
- -- file name
- else
- done := true ; -- because it does not exist...
- end if ;
- -- need to set the default environment
- exit when done ;
- end loop ;
- end get_output_file_name ;
-
- procedure get_secondary_responses is
- -- we have a response from the user which calls for another
- -- response
- valid_responses : crt_windows.character_set ;
- ok_answer : boolean ;
- begin -- get_secondary_responses
- -- not B,E,P,R
- -- First, figure out the file name for output
- -- If 'W' we must ask for it.
- if out_option = 'W' then
- get_output_file_name ;
- end if ;
- if out_option /= 'A' then
- -- if they did 'W' and then changed their mind, we changed
- -- out_option to 'A'
- case out_option is
- when 'S' => if master_buffer.output_file_name = no_file then
- editor_requested_output_file_name
- := master_buffer.input_file_name ;
- else
- editor_requested_output_file_name
- := master_buffer.output_file_name ;
- end if ;
- when 'X' => editor_requested_output_file_name
- := master_buffer.copy_file_name ;
- when 'D' => editor_requested_output_file_name
- := editor_entry_output_file_name ;
- when 'W' => null ; -- file name already set .
- when others => null ; -- I know it can't get here
- end case ;
- -- Now, get the secondary output option
- crt_windows.clear_set(valid_responses);
- valid_responses('A') := true ;
- valid_responses('B') := true ;
- valid_responses('E') := true ;
- valid_responses('R') := true ;
- clear_end_of_screen( master_buffer , 13 , 1 ) ;
- goto_line_column ( master_buffer , 13 , 1 ) ;
- put (" What do you want to do after saving the file as """);
- put ( compress(editor_requested_output_file_name));
- put_line( """.");
- put_line;
- put_line(" A(bort the current output options & return to editor");
- put_line(" B(egin editing another file");
- put_line(" E(xit the editor");
- put_line(" R(eturn to the editor to continue editing the current "
- & "file");
- if not only_editor then
- -- we have to give the word processor as an option
- put_line(" I(mmediately Print the current document using"
- & " default options");
- valid_responses('I') := true ;
- put_line(" P(rint a different document");
- valid_responses('P') := true ;
- end if ;
- put_line;
- put(" Enter Secondary Option ? ");
- second_option := crt_windows.goodchar( valid_responses , 'R' ) ;
- -- Now, figure out the partial and total quit responses
- case second_option is
- when 'A' => null ; -- take care of by caller
- when 'B' => partial := true ;
- total := false ;
- when 'E' => partial := true ;
- total := true ;
- what_to_run_next := master_menu ;
- when 'R' => partial := false ;
- total := false ;
- when 'I' => partial := true ;
- total := true ;
- what_to_run_next := format_editor_file ;
- when 'P' => partial := true ;
- total := true ;
- what_to_run_next := text_formatter ;
- when others => null ; -- I know it can't get here
- end case;
- end if ;
- end get_secondary_responses ;
-
- procedure redo_screen is
- begin -- redo_screen
- -- reshow the screen
- restore_shift ;
- jump_to_position(master_buffer,
- master_buffer.fixed_cursor.file_line_number,
- master_buffer.fixed_cursor.column_offset );
- -- that moves us back to the correct place in the file
- need_prompt := true ;
- partial := false ;
- total := false ;
- end redo_screen ;
-
- Procedure Output_Text ( Buffer : in out An_Editor_Buffer ;
- output_range : in text_range ;
- output_filenm: in ascii_text_file_name ;
- successfull : out boolean ) is
- -- Output the range of text within the buffer to the output file
- -- for now, write entire file
- unable_to_continue : exception ;
- text_output_file : text_io.file_type ;
- output_line : string ( 1 .. max_column_number ) ;
- output_length : Integer := 0 ;
- length_goal : Integer := 0 ;
- leading_spaces : Integer := 0 ;
- out_lines : Integer := 0 ;
- first_line : boolean := true ;
-
- procedure out_pstring ( s : in pstring ) is
- begin -- out_pstring
- text_io.put_line( text_output_file , s.data( 1 .. length(s) ) ) ;
- end out_pstring ;
-
- procedure out_string is
- begin -- out_string
- if first_line then
- first_line := false ;
- else
- text_io.new_line( text_output_file ) ;
- end if ;
- for space_number in 1 .. leading_spaces loop
- text_io.put( text_output_file , ' ' ) ;
- end loop ;
- if output_length > 3 then
- text_io.put(text_output_file, output_line ( 3..output_length - 1 ));
- end if ;
- out_lines := out_lines + 1 ;
- if out_lines mod 100 = 0 then
- put('.');
- end if ;
- end out_string ;
-
- procedure do_file_open is
- real_file_name : ascii_text_file_name ;
- ok : boolean ;
- begin -- do_file_open
- -- Step 1 : Open the output file
- real_file_name := output_filenm ;
- open_for_write( text_output_file , real_file_name , ok ) ;
- if ok then
- -- give some statistics
- put("Writing file """ & compress( real_file_name ) & """ => " );
- buffer.output_file_name := real_file_name ;
- editor_requested_output_file_name := real_file_name ;
- else
- -- first, give an error message
- error( " Unable to Create File """ & string_library.compress(output_filenm)
- & """." ,
- not_fatal_error , operator_wait , short_beep ) ;
- -- then, return
- raise unable_to_continue ;
- end if ;
- end do_file_open ;
-
- procedure do_environment is
- a_pstring : pstring ;
- env_code : integer ;
- put_it_out : boolean ;
- check_name : ascii_text_file_name ;
- begin -- do_environment
- put_it_out := buffer.pagezero.save_envirn ;
- if not put_it_out then
- -- see if we need to do anything because it is the default
- -- environment file name
- -- work with default_environment_file_name
- -- and editor_requested_output_file_name
- check_name := editor_requested_output_file_name ;
- loop
- if check_name = editor_requested_output_file_name then
- put_it_out := true ;
- end if ;
- exit when put_it_out or ( check_name = no_file ) ;
- check_name( 1 .. check_name'length - 1 )
- := check_name( 2 .. check_name'length ) ;
- check_name( check_name'length ) := ' ' ;
- end loop ;
- end if ;
- -- Step 2: Output The Environment
- if put_it_out then
- env_code := 0 ;
- loop
- environment_input_output.convert_header_to_string
- ( buffer.pagezero , env_code , a_pstring ) ;
- exit when env_code <= 0 ;
- if env_code = 1 then
- put("# ");
- end if ;
- out_pstring( a_pstring ) ;
- end loop ;
- end if ;
- end do_environment ;
-
- procedure char_out ( c : in editor_globals.extended_character ) is
- -- add this character to the output_line. When we hit the
- -- length_goal, then call out_string to process the line for
- -- output ...
- -- output_line : string ( 1 .. max_column_number ) ;
- -- output_length : Integer := 0 ;
- -- length_goal : Integer := 0 ;
- begin -- char_out
- output_length := output_length + 1 ;
- if output_length < 3 then
- if output_length = 1 then
- length_goal := c + 3 ;
- else
- leading_spaces := c ;
- end if ;
- else
- if output_length < length_goal then
- output_line( output_length ) := character'val( c ) ;
- else
- -- need to just output the line...
- out_string ;
- output_length := 0 ;
- end if ;
- end if ;
- end char_out ;
-
- procedure do_a_block ( what : topush ; blockn : integer ) is
- block_of_data : block ;
- successfull : boolean ;
- begin
- buffer_block_io.getblock( buffer ,
- what ,
- block_of_data , blockn , successfull ) ;
- if successfull then
- for posn in 0 .. block_minus loop
- char_out( block_of_data(posn).data ) ;
- end loop ;
- else
- error( " Unable to read temporary file for output ." ,
- not_fatal_error , operator_wait , short_beep ) ;
- raise unable_to_continue ;
- end if ;
- end ;
-
- begin -- output_text
- clear_window( buffer ) ;
- clear_prompt( buffer ) ;
- goto_line_column( buffer , 1 , 3 ) ;
- -- Open the file, then, put out the environment
- -- and Then, we have three areas to work with: the top blocks, the
- -- actual text buffer, and then the bottom blocks
- do_file_open ;
- do_environment ;
- -- Do the Top Blocks
- for blockn in 1 .. buffer.prestopblock loop
- do_a_block( thetop , blockn ) ;
- end loop ;
- -- Do The Center Information
- for posn in 1 .. buffer.bufcount loop
- char_out( buffer.e_buf( posn ).data ) ;
- end loop ;
- -- Do The Bottom Blocks
- for blockn in reverse 1 .. buffer.presbotblock loop
- do_a_block( thebot , blockn ) ;
- end loop ;
- put_line ;
- put(" Your file is ");
- put( out_lines , 1 ) ;
- put(" lines long.");
- -- Close the File
- -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- -- On the Wicat, we need to put a new_line in, even if the
- -- file does not end with a new_line....
- -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- text_io.new_line( text_output_file ) ;
- text_io.close( text_output_file ) ;
- successfull := true ;
- exception
- when unable_to_continue => successfull := false ;
- end output_text ;
-
- procedure do_output_procedures is
- new_backup_name : ascii_text_file_name ;
- out_range : text_range ;
- successfull : boolean ;
- old_posn : cursor_position := master_buffer.fixed_cursor ;
- begin -- do_output_procedures
- -- Here we are with editor_requested_output_file set
- -- please output the file
- -- if a file exists with that same name, turn it into .bak
- -- finish reading in the input file
- clear_window( master_buffer ) ;
- clear_prompt( master_buffer ) ;
- if master_buffer.still_reading_input_file then
- jump_to_position( master_buffer , max_line_number , 0 , false ) ;
- end if ;
- -- Now, take care of the backup file if necessary
- if file_exists(editor_requested_output_file_name) then
- -- must turn it into a backup file
- new_backup_name := to_backup_name( editor_requested_output_file_name);
- -- do_purge(new_backup_name); -- purge the old file if necessary
- --rename_file( editor_requested_output_file_name , new_backup_name ) ;
- do_purge( editor_requested_output_file_name ) ;
- end if ;
- Out_Range.Lo_Position.Line := 1 ;
- Out_Range.Lo_Position.Column := 1 ;
- Out_Range.Hi_Position.Line := Max_Line_Number ;
- Out_Range.Hi_Position.Column := Max_Column_Number ;
- output_text( master_buffer ,
- out_range ,
- editor_requested_output_file_name ,
- successfull ) ;
- if not successfull then
- second_option := 'R' ;
- end if ;
- if second_option = 'R' then
- -- must move back to the correct place
- jump_to_position ( master_buffer ,
- old_posn.file_line_number ,
- old_posn.column_offset ,
- false ) ;
- end if ;
- end do_output_procedures ;
-
- -- type_what_to_run_next is ( master_menu , text_editor , text_formatter ,
- -- operating_system , format_editor_file ,
- -- edit_formatter_file ) ;
-
- begin -- do_quit_command
- store_shift ; -- and only restore if we redo the screen
- get_responses ;
- if out_option = 'R' then
- redo_screen ;
- elsif ( out_option = 'B' ) or ( out_option = 'E' )
- or ( out_option = 'P' ) then
- -- we are throwing away the current work.
- partial := true ;
- total := ( out_option = 'E' ) or ( out_option = 'P' ) ;
- if out_option = 'P' then
- what_to_run_next := text_formatter ;
- else
- what_to_run_next := master_menu ;
- end if ;
- clear_window(master_buffer);
- clear_prompt(master_buffer);
- if ( out_option = 'E' ) or ( out_option = 'P' ) then
- dispose_buffer( master_buffer ) ;
- else
- -- must tell editor to ask for a new file name
- editor_entry_input_file_name := blank_file_name ;
- end if ;
- else
- -- not B,E,P,R
- -- so we need to know their follow-on response
- get_secondary_responses ;
- if second_option = 'A' then
- redo_screen ; -- because they changed their mind...
- else
- do_output_procedures ;
- if second_option = 'R' then
- -- we need to redo the screen and then return
- redo_screen ;
- else
- -- we must clear the screen, close the buffer, and exit
- clear_window(master_buffer);
- clear_prompt(master_buffer);
- if second_option = 'B' then
- -- must tell editor to ask for a new file name
- editor_entry_input_file_name := blank_file_name ;
- else
- dispose_buffer( master_buffer ) ;
- end if ;
- end if ;
- end if ;
- end if ;
- end do_quit_command ;
-
- begin -- Editor_Files
- -- EDITFILE by SAIC/Clearwater Editor File Packages 22 Jan 85
- -- INITIAL by SAIC/Clearwater Editor Initialize Package 26 Dec 84
- -- COPY by SAIC/Clearwater Editor Copy Command 26 Dec 84
- -- QUIT by SAIC/Clearwater Editor QuittCommand 22 Jan 85
- null ;
- end Editor_Files ;
-
- --$$$- EDITFILE
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --move
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ MOVE
-
- --
- -- File 022
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Movement Routine Written 12 Nov 84 - RSC
- --
- --
- -- Editor Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_lines ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- with editor_more_packages ;
- use editor_more_packages ;
-
- with markers ;
- use markers ;
- use text_position_handler ;
-
- with debugger ;
-
- package movement_package is
-
- -- ISO Editor Commands
-
- Procedure CURSOR_HORIZONTAL ( COLUMNS_TO_MOVE_RIGHT : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) ;
- -- free cursor movement within window. The cursor can move right
- -- to the last possible editable column. If it passes that, it
- -- will scroll to the next line. At the end of the file it stops.
- -- When going backwards, it can go to the first column. If it passes
- -- that, then it will move to the position following the last
- -- character on the previous line. It stops at the beginning of
- -- the file.
-
- Procedure CURSOR_VERTICAL ( LINES_TO_MOVE_DOWN : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) ;
- -- free cursor movement within window
-
- Procedure MOVE_HORIZONTAL ( COLUMNS_TO_MOVE_RIGHT : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) ;
- -- *** bound cursor movement / scroll if necessary *** --
- -- When it passes the position following the last character on
- -- a line, it moves to the first character position on the next
- -- line.
-
- Procedure MOVE_VERTICAL ( LINES_TO_MOVE_DOWN : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) ;
- -- *** bound cursor vertical movement / scroll if necessary *** --
-
- type type_of_pattern is ( word_pattern , tab_pattern , paragraph_pattern ,
- line_start_pattern , line_end_pattern ) ;
-
- function find_forward ( pattern : in type_of_pattern ;
- number_to_find : in a_repeat_factor := 1
- ) return text_position ;
-
- function find_backward ( pattern : in type_of_pattern ;
- number_to_find : in a_repeat_factor := 1
- ) return text_position ;
-
- Procedure position ( place : in text_position ;
- show_cursor_at_end : boolean := true ) ;
- -- move the cursor to the specified location. Update the screen
- -- unless requested otherwise
-
- -- SAIC Editor Commands
-
- procedure do_move_command ( movement_command : in an_editor_command ;
- repeat_factor : in a_repeat_factor ) ;
-
- procedure do_jump_command ;
-
- go_forward : boolean ;
-
- private
-
- in_deletion : boolean := false ;
- append_deletion : boolean := false ;
-
- Append_Command_Prompt : string ( 1 .. 71 ) :=
- " {Appending Deletion}: <Moving Cmds>, <Append Tog>, <Accept>, <Reject> ";
-
- StrtDel_column : column_position ;
- StrtDel_line : line_number ;
- StrtDel_Pos : text_position ;
- EndDelt_column : column_position ;
- EndDelt_line : line_number ;
- EndDelt_Pos : text_position ;
-
- end movement_package ;
-
- package body movement_package is
-
- -- Support Routines.
-
- procedure to_beginning is
- begin -- jump to the beginning of the file
- jump_to_position ( master_buffer , 1 , 0 , false ) ;
- end to_beginning ;
-
- procedure to_end is
- begin -- jump to the end of the file
- jump_to_position ( master_buffer , line_number'last , 0 , false ) ;
- end to_end ;
-
- -- ISO Editor Commands
-
- Procedure CURSOR_HORIZONTAL ( COLUMNS_TO_MOVE_RIGHT : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true) is
- -- free cursor movement within window. The cursor can move right
- -- to the last possible editable column. If it passes that, it
- -- will scroll to the next line. At the end of the file it stops.
- -- When going backwards, it can go to the first column. If it passes
- -- that, then it will move to the position following the last
- -- character on the previous line. It stops at the beginning of
- -- the file.
- number_to_move : a_repeat_factor ;
- columns_remaining_on_line : column_position ;
- begin -- cursor_horizontal
- if columns_to_move_right > 0 then
- -- forward
- number_to_move := columns_to_move_right ;
- columns_remaining_on_line := max_column_number
- - master_buffer.fixed_cursor.column_offset ;
- while number_to_move > columns_remaining_on_line loop
- -- need to simply move to the next line...
- -- and columns_remaining_on_line could be as small as zero...
- if cursor_forward_line then
- -- ok, we moved one line forward
- number_to_move := number_to_move - columns_remaining_on_line
- - 1 ;
- -- the minus one above is for the movement past the last
- -- character on the line
- master_buffer.fixed_cursor.column_offset := 1 ;
- columns_remaining_on_line := max_column_number - 1 ;
- else
- -- we were unable to move any further
- to_end ; -- so simply move to the end of the file
- number_to_move := 0 ;
- end if ;
- end loop ;
- if number_to_move > 0 then
- -- we only get here if we know we can stay on this line...
- master_buffer.fixed_cursor.column_offset :=
- master_buffer.fixed_cursor.column_offset + number_to_move ;
- end if ;
- elsif columns_to_move_right < 0 then
- -- backward
- number_to_move := - columns_to_move_right ;
- columns_remaining_on_line :=
- master_buffer.fixed_cursor.column_offset - 1 ;
- while number_to_move > columns_remaining_on_line loop
- -- need to simply move to the next line...
- -- and columns_remaining_on_line could be as small as zero...
- if cursor_backward_line then
- -- ok, we moved one line backward
- number_to_move := number_to_move - columns_remaining_on_line
- - 1 ;
- -- the minus one above is for the movement past the last
- -- character on the line
- master_buffer.fixed_cursor.column_offset
- := num_leading_spaces( master_buffer ,
- master_buffer.fixed_cursor.line_start )
- + line_length( master_buffer ,
- master_buffer.fixed_cursor.line_start ) + 1 ;
- columns_remaining_on_line :=
- master_buffer.fixed_cursor.column_offset - 1 ;
- else
- -- we were unable to move any further
- to_beginning ; -- so simply move to the start of the file
- number_to_move := 0 ;
- end if ;
- end loop ;
- if number_to_move > 0 then
- -- need to move within the current line
- master_buffer.fixed_cursor.column_offset :=
- master_buffer.fixed_cursor.column_offset - number_to_move ;
- end if ;
- end if ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- if show_cursor_at_end then
- show_cursor ( master_buffer ) ;
- end if ;
- end cursor_horizontal ;
-
- Procedure CURSOR_VERTICAL ( LINES_TO_MOVE_DOWN : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) is
- -- free cursor movement within window
- number_to_move : a_repeat_factor ;
- Old_Column : column_position ;
- begin -- cursor_vertical
- number_to_move := lines_to_move_down ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- Old_Column := master_buffer.fixed_cursor.column_offset ;
- if lines_to_move_down > 0 then
- -- forward
- while number_to_move > 0 loop
- if cursor_forward_line then
- -- ok.....
- number_to_move := number_to_move - 1 ;
- else
- number_to_move := 0 ;
- end if ;
- end loop ;
- elsif lines_to_move_down < 0 then
- -- backward
- while number_to_move < 0 loop
- if cursor_backward_line then
- -- ok
- number_to_move := number_to_move + 1 ;
- else
- number_to_move := 0 ;
- end if ;
- end loop ;
- end if ;
- master_buffer.fixed_cursor.column_offset := Old_Column ;
- if show_cursor_at_end then
- show_cursor ( master_buffer ) ;
- end if ;
- end cursor_vertical ;
-
- procedure left_and_right_columns(which_buffer : in an_editor_buffer;
- left_most_column : out column_position;
- right_most_column : out column_position) is
- temp_left : column_position ;
- begin -- left_and_right_columns
- temp_left := num_leading_spaces(which_buffer,
- which_buffer.fixed_cursor.line_start)
- + 1 ;
- left_most_column := temp_left ;
- right_most_column := temp_left
- + line_length(which_buffer ,
- which_buffer.fixed_cursor.line_start);
- end left_and_right_columns ;
-
- procedure set_cursor_position is
- target_col : column_position ;
- first_col ,
- last_col : column_position ;
- begin -- set_cursor
- left_and_right_columns( master_buffer , first_col , last_col ) ;
- if master_buffer.fixed_cursor.column_offset < first_col then
- master_buffer.fixed_cursor.buffer_position := 0 ;
- elsif master_buffer.fixed_cursor.column_offset >= last_col then
- master_buffer.fixed_cursor.buffer_position := 0 ;
- else
- master_buffer.fixed_cursor.buffer_position :=
- master_buffer.fixed_cursor.line_start
- + master_buffer.fixed_cursor.column_offset
- - first_col + 2 ;
- end if ;
- end set_cursor_position ;
-
- function char_at_position return character is
- -- return the character at the current cursor position
- begin
- set_cursor_position ;
- if master_buffer.fixed_cursor.buffer_position = 0 then
- return ascii.cr ;
- else
- return character'val ( master_buffer.e_buf(master_buffer.fixed_cursor.
- buffer_position).data ) ;
- end if ;
- end char_at_position ;
-
- Procedure MOVE_HORIZONTAL ( COLUMNS_TO_MOVE_RIGHT : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) is
- -- *** bound cursor movement / scroll if necessary *** --
- -- When it passes the position following the last character on
- -- a line, it moves to the first character position on the next
- -- line.
- --
- -- This means that we must move the cursor within the bounds of the
- -- first character on the line ( which is at column
- -- num_leading_spaces( master_buffer
- -- , master_buffer.fixed_cursor.line_start)+1
- -- and the position following the last position on the line, which is
- -- line_length( master_buffer , master_buffer.fixed_cursor.line_start )
- -- to the right of the first valid position
- number_to_move : a_repeat_factor ;
- left_most_column ,
- right_most_column ,
- columns_remaining_on_line : column_position ;
- begin -- move_horizontal
- left_and_right_columns(master_buffer,left_most_column,right_most_column);
- if columns_to_move_right > 0 then
- -- forward. Note that if we are not currently within the text area,
- -- then the first movement will move to that position
- number_to_move := columns_to_move_right ;
- if master_buffer.fixed_cursor.column_offset >= right_most_column then
- columns_remaining_on_line := 0 ;
- elsif master_buffer.fixed_cursor.column_offset >= left_most_column then
- columns_remaining_on_line := right_most_column
- - master_buffer.fixed_cursor.column_offset ;
- else
- columns_remaining_on_line := right_most_column - left_most_column;
- number_to_move := number_to_move - 1 ; -- to get to first character
- master_buffer.fixed_cursor.column_offset := left_most_column ;
- end if ;
- while number_to_move > columns_remaining_on_line loop
- -- loop through each of the lines first
- -- need to simply move to the next line...
- -- and columns_remaining_on_line could be as small as zero...
- if cursor_forward_line then
- -- ok, we moved one line forward
- number_to_move := number_to_move - columns_remaining_on_line
- - 1 ;
- -- the minus one above is for the movement past the last
- -- character on the line
- left_and_right_columns(master_buffer,
- left_most_column,right_most_column);
- master_buffer.fixed_cursor.column_offset := left_most_column ;
- columns_remaining_on_line := right_most_column - left_most_column;
- else
- -- we were unable to move any further
- to_end ; -- so simply move to the end of the file
- number_to_move := 0 ;
- end if ;
- end loop ;
- if number_to_move > 0 then
- -- need to move within the current line
- master_buffer.fixed_cursor.column_offset :=
- master_buffer.fixed_cursor.column_offset + number_to_move ;
- end if ;
- elsif columns_to_move_right < 0 then
- -- backward
- number_to_move := - columns_to_move_right ;
- -- Note that if we are not currently within the text area,
- -- then the first movement will move to that position
- if master_buffer.fixed_cursor.column_offset > right_most_column then
- columns_remaining_on_line := right_most_column - left_most_column;
- number_to_move := number_to_move - 1 ; -- to get to first character
- master_buffer.fixed_cursor.column_offset := right_most_column ;
- elsif master_buffer.fixed_cursor.column_offset > left_most_column then
- columns_remaining_on_line := master_buffer.fixed_cursor.column_offset
- - left_most_column ;
- else
- -- here in the left margin...
- columns_remaining_on_line := 0 ;
- end if ;
- while number_to_move > columns_remaining_on_line loop
- -- loop through each of the lines first
- -- need to simply move to the next line...
- -- and columns_remaining_on_line could be as small as zero...
- if cursor_backward_line then
- -- ok, we moved one line forward
- number_to_move := number_to_move - columns_remaining_on_line
- - 1 ;
- -- the minus one above is for the movement past the last
- -- character on the line
- left_and_right_columns(master_buffer,
- left_most_column,right_most_column);
- master_buffer.fixed_cursor.column_offset := right_most_column ;
- columns_remaining_on_line := right_most_column - left_most_column;
- else
- -- we were unable to move any further
- to_beginning ; -- so simply move to the end of the file
- number_to_move := 0 ;
- end if ;
- end loop ;
- if number_to_move > 0 then
- -- need to move within the current line
- master_buffer.fixed_cursor.column_offset :=
- master_buffer.fixed_cursor.column_offset - number_to_move ;
- end if ;
- end if ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- if show_cursor_at_end then
- show_cursor ( master_buffer ) ;
- end if ;
- end move_horizontal ;
-
- Procedure MOVE_VERTICAL ( LINES_TO_MOVE_DOWN : in a_repeat_factor ;
- show_cursor_at_end : in boolean := true ) is
- -- *** bound cursor vertical movement / scroll if necessary *** --
- left_most_column ,
- right_most_column ,
- target_column : column_position ;
- begin -- move_vertical
- target_column := master_buffer.fixed_cursor.column_offset ;
- cursor_vertical( lines_to_move_down , false ) ;
- left_and_right_columns(master_buffer,left_most_column,right_most_column);
- if master_buffer.fixed_cursor.column_offset > right_most_column then
- master_buffer.fixed_cursor.column_offset := right_most_column ;
- elsif master_buffer.fixed_cursor.column_offset < left_most_column then
- master_buffer.fixed_cursor.column_offset := left_most_column ;
- end if ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- if show_cursor_at_end then
- show_cursor( master_buffer ) ;
- end if ;
- end move_vertical ;
-
- -- SAIC Editor Commands
-
- function find_forward ( pattern : in type_of_pattern ;
- number_to_find : in a_repeat_factor := 1
- ) return text_position is
- still_to_do : a_repeat_factor := number_to_find ;
- old_cursor : cursor_position ;
- cc : character ;
- begin -- find_forward
- while still_to_do > 0 loop
- case pattern is
- when word_pattern => loop
- cc := char_at_position ;
- exit when not
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z')) ) ;
- old_cursor := master_buffer.fixed_cursor;
- move_horizontal ( 1 , false ) ;
- exit when old_cursor =
- master_buffer.fixed_cursor ;
- end loop ;
- -- that moved past the current word
- -- now, move past trailing blanks.
- loop
- old_cursor := master_buffer.fixed_cursor;
- move_horizontal ( 1 , false ) ;
- cc := char_at_position ;
- exit when
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z')) ) ;
- exit when old_cursor =
- master_buffer.fixed_cursor ;
- end loop ;
- when tab_pattern => -- Need to move forward to the next
- -- tab position .
- -- master_buffer.pagezero.tabline
- -- ( column_position )
- -- = ( TNONE , TNORMAL , TNUMBER )
- -- we also know master_buffer.fixed_cursor.
- -- column_offset
- loop
- old_cursor := master_buffer.fixed_cursor;
- move_horizontal( 1 , false ) ;
- exit when old_cursor = master_buffer.
- fixed_cursor
- or else master_buffer.pagezero.tabline
- ( master_buffer.fixed_cursor.
- column_offset )
- /= tnone ;
- end loop ;
- when paragraph_pattern => master_buffer.fixed_cursor.column_offset
- := 0 ;
- move_vertical(
- window_height(master_buffer) / 2 ,
- false ) ;
- when line_start_pattern => master_buffer.fixed_cursor.column_offset
- := 0 ;
- move_vertical( still_to_do , false );
- still_to_do := 1 ; -- to stop loop
- when line_end_pattern => master_buffer.fixed_cursor.column_offset
- := column_position'last ;
- move_vertical(still_to_do - 1 , false ) ;
- still_to_do := 1 ; -- to stop loop
- end case ;
- still_to_do := still_to_do - 1;
- end loop ;
- return text_position ' ( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset ,
- no_screen_attribute ,
- master_buffer ) ;
- end find_forward ;
-
- function find_backward ( pattern : in type_of_pattern ;
- number_to_find : in a_repeat_factor := 1
- ) return text_position is
- still_to_do : a_repeat_factor := number_to_find ;
- old_cursor : cursor_position ;
- cc : character ;
- begin -- find_backward
- while still_to_do > 0 loop
- case pattern is
- when word_pattern => loop
- old_cursor := master_buffer.fixed_cursor;
- move_horizontal ( -1 , false ) ;
- cc := char_at_position ;
- exit when
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z')) ) ;
- exit when old_cursor =
- master_buffer.fixed_cursor ;
- end loop ;
- -- that moved past the current word
- -- now, move past trailing blanks.
- loop
- old_cursor:= master_buffer.fixed_cursor ;
- move_horizontal ( -1 , false ) ;
- cc := char_at_position ;
- exit when not
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z')) ) ;
- exit when old_cursor =
- master_buffer.fixed_cursor ;
- end loop ;
- if old_cursor /= master_buffer
- .fixed_cursor then
- move_horizontal( 1 , false ) ;
- -- to move to first char in word
- end if ;
- when tab_pattern => -- Need to move forward to the next
- -- tab position .
- -- master_buffer.pagezero.tabline
- -- ( column_position )
- -- = ( TNONE , TNORMAL , TNUMBER )
- -- we also know master_buffer.fixed_cursor.
- -- column_offset
- loop
- old_cursor:= master_buffer.fixed_cursor ;
- move_horizontal( -1 , false ) ;
- exit when old_cursor = master_buffer.
- fixed_cursor
- or else master_buffer.pagezero.tabline
- ( master_buffer.fixed_cursor.
- column_offset )
- /= tnone ;
- end loop ;
- when paragraph_pattern => move_vertical(
- - window_height(master_buffer) / 2 ,
- false ) ;
- when line_start_pattern => master_buffer.fixed_cursor.column_offset
- := 0 ;
- move_vertical( 1 - still_to_do , false );
- still_to_do := 1 ; -- to stop loop
- when line_end_pattern => master_buffer.fixed_cursor.column_offset
- := column_position'last ;
- move_vertical(still_to_do , false ) ;
- still_to_do := 1 ; -- to stop loop
- end case ;
- still_to_do := still_to_do - 1;
- end loop ;
- return text_position ' ( master_buffer.fixed_cursor.file_line_number ,
- master_buffer.fixed_cursor.column_offset ,
- no_screen_attribute ,
- master_buffer ) ;
- end ;
-
- Procedure position ( place : in text_position ;
- show_cursor_at_end : boolean := true ) is
- -- move the cursor to the specified location. Update the screen
- -- unless requested otherwise
- begin -- position
- if place = no_set_location then
- null ; -- can't do anything
- else
- if master_buffer.fixed_cursor.file_line_number /= place.line
- or else master_buffer.fixed_cursor.column_offset /= place.column then
- -- we need to jump there
- jump_to_position ( master_buffer, place.line, place.column, false ) ;
- end if ;
- end if ;
- if show_cursor_at_end then
- show_cursor ( master_buffer ) ;
- end if ;
- end position ;
-
- procedure page_forward ( pages_to_move : a_repeat_factor ) is
- old_screen_line : window_line_number ;
- old_top : line_number ;
- begin
- old_top := master_buffer.top_screen_cursor.file_line_number ;
- old_screen_line:=master_buffer.fixed_cursor.file_line_number + 1 -old_top;
- master_buffer.fixed_cursor.column_offset := 0 ;
- move_vertical( pages_to_move * window_height( master_buffer ) , false ) ;
- if old_top + window_height(master_buffer) - 1
- < master_buffer.fixed_cursor.file_line_number then
- show_screen(master_buffer, master_buffer.fixed_cursor, old_screen_line);
- else
- show_cursor(master_buffer);
- end if ;
- end page_forward ;
-
- procedure page_backward ( pages_to_move : a_repeat_factor ) is
- old_screen_line : window_line_number ;
- old_top : line_number ;
- begin
- old_top := master_buffer.top_screen_cursor.file_line_number ;
- old_screen_line:=master_buffer.fixed_cursor.file_line_number + 1 -old_top;
- master_buffer.fixed_cursor.column_offset := 0 ;
- move_vertical( - pages_to_move * window_height( master_buffer ), false ) ;
- if old_top /= 1 then
- -- because there can be no reason to move if the top of the screen
- -- didn't move....
- show_screen(master_buffer, master_buffer.fixed_cursor, old_screen_line);
- else
- show_cursor(master_buffer);
- end if ;
- end page_backward ;
-
- procedure move_to_home_position is
- old_position : text_position ;
- begin
- old_position := current_position ;
- jump_to_position( master_buffer ,
- master_buffer.top_screen_cursor.file_line_number , 0 , false ) ;
- if old_position = current_position then
- -- we were already there...
- jump_to_position ( master_buffer ,
- master_buffer.top_screen_cursor.file_line_number
- + window_height(master_buffer) - 1 , 0 , false ) ;
- end if ;
- show_cursor( master_buffer ) ;
- end ;
-
- procedure move_to_zap_marker is
- old_position : text_position ;
- begin -- move_to_zap_marker
- old_position := current_position ;
- position ( master_buffer.last_marked_position.data ) ;
- master_buffer.last_marked_position.data := old_position ;
- end move_to_zap_marker ;
-
- procedure do_move_command ( movement_command : in an_editor_command ;
- repeat_factor : in a_repeat_factor ) is
- actual_command : an_editor_command := movement_command ;
- actual_repeat : a_repeat_factor := repeat_factor ;
- current_column : column_position ;
- current_line : line_number ;
- current_pos : text_position ;
- Old_column : column_position ;
- Old_line : line_number ;
- old_pos : text_position ;
-
- procedure get_another_command is
- begin -- get_another_command ;
- get_next_command( actual_repeat , actual_repeat , actual_command ) ;
- case actual_command is
- when advance_character_command
- => if go_forward then
- actual_command := forward_character_command ;
- else
- actual_command := backward_character_command ;
- end if;
- when advance_word_command
- => if go_forward then
- actual_command := forward_word_command ;
- else
- actual_command := backward_word_command ;
- end if;
- when advance_tab_command
- => if go_forward then
- actual_command := forward_tab_command ;
- else
- actual_command := backward_tab_command ;
- end if;
- when advance_line_command
- => if go_forward then
- actual_command := forward_line_command ;
- else
- actual_command := backward_line_command ;
- end if;
- when advance_paragraph_command
- => if go_forward then
- actual_command := forward_paragraph_command ;
- else
- actual_command := backward_paragraph_command ;
- end if;
- when advance_page_command
- => if go_forward then
- actual_command := forward_page_command ;
- else
- actual_command := backward_page_command ;
- end if;
- when advance_infinity_command
- => if go_forward then
- actual_command := jump_to_first_position_command ;
- else
- actual_command := jump_to_last_position_command ;
- end if;
- when others => null ;
- end case ;
- end get_another_command ;
-
- Procedure Cancell_A_Deletion( First_Pos,Second_Pos : in Text_Position ) is
- -- move between the two positions and reset the deletion flag to false
- -- redisplay the screen
- begin -- cancell_a_deletion
- null ;
- end cancell_a_deletion ;
-
- procedure do_delete_prompt is
- begin -- do_delete_prompt
- set_repeat_prompt ( true , -1 ) ;
- if append_deletion then
- prompt( append_command_prompt ) ;
- else
- prompt(delete_command_prompt);
- end if ;
- need_prompt:=false;
- show_cursor( master_buffer ) ;
- end do_delete_prompt ;
-
- procedure start_deletion is
- begin -- start_deletion ;
- StrtDel_line := current_buffer.fixed_cursor.file_line_number ;
- StrtDel_column := current_buffer.fixed_cursor.column_offset ;
- StrtDel_Pos := current_position ;
- allow_alternate_prompt_command := false ;
- do_delete_prompt ;
- get_another_command ;
- end start_deletion ;
-
- procedure work_deletion ( Old_Pos , New_Pos : in text_position ) is
- w_top_line : line_number ;
- w_bot_line : line_number ;
- w_left_column : column_position ;
- w_right_column : column_position ;
- orig_text : type_text_line ; -- the original text line....
- First_Line : line_number ;
- Last_Line : line_number ;
- First_Col : column_position ;
- Last_Col : integer ;
- -- col2 is an integer because we do our own error checking.....
- win_line1 : window_line_number ;
- win_col1 : window_column_number ;
- win_line2 : window_line_number ;
- win_col2 : window_column_number ;
-
- Procedure Fix_Screen_Information is
- -- get screen information for comparison...
- begin -- fix_screen_information
- w_top_line := master_buffer.top_screen_cursor.file_line_number ;
- w_bot_line := w_top_line + window_height( master_buffer ) - 1 ;
- w_left_column := lowest_column_number( master_buffer ) ;
- w_right_column := highest_column_number( master_buffer ) ;
- end fix_screen_information ;
-
- function change_into_absolute_screen_locations return boolean is
- begin -- change_into_absolute_screen_locations
- -- here, we check values of the lines and also change to relative
- -- First Line...
- if First_Line > w_bot_line then
- -- off screen towards end, skip entire operation...
- return false ;
- elsif First_Line < w_top_line then
- -- the clear starts off the page towards front of file...
- win_line1 := 1 ;
- win_col1 := w_left_column ;
- first_line:= w_top_line ;
- first_col := w_left_column ;
- else
- win_line1 := First_Line - w_top_line + 1 ;
- if first_col < w_left_column then
- win_col1 := w_left_column ;
- first_col := w_left_column ;
- else
- win_col1 := first_col ;
- end if ;
- end if ;
- -- Last Line...
- if Last_Line < w_top_line then
- -- off screen towards front, skip entire operation
- return false ;
- elsif Last_Line > w_bot_line then
- -- the clear ends off the page towards end of file
- win_line2 := window_height( master_buffer ) ;
- win_col2 := w_right_column + 1 ; -- because subtract later
- last_line := w_bot_line ;
- last_col := w_right_column + 1 ;
- else
- win_line2 := Last_Line - w_top_line + 1 ;
- if Last_Col > w_right_column then
- win_col2 := w_right_column + 1 ;
- last_col := w_right_column + 1 ;
- else
- win_col2 := Last_Col ;
- end if ;
- end if ;
- -- Now, adjust last columns....
- if win_col2 <= 1 then
- win_line2 := win_line2 - 1 ;
- last_line := last_line - 1 ;
- win_col2 := w_right_column ;
- else
- win_col2 := win_col2 - 1 ;
- end if ;
- last_col := win_col2 ;
- return true ;
- end change_into_absolute_screen_locations ;
-
- procedure Clear ( Left_Pos , Right_Pos : in text_position ) is
- -- Clear starting at left_pos and up to and including the
- -- character before right_pos ... at least one char ...
- begin -- clear
- First_Line := Left_Pos.Line ;
- Last_Line := Right_Pos.Line ;
- First_Col := Left_Pos.Column ;
- Last_Col := Right_Pos.Column ;
- if change_into_absolute_screen_locations then
- -- win_line1,win_col1 to win_line2,win_col2 are to be cleared....
- -- first work line1 = line2
- if win_line1 = win_line2 then
- -- just delete a few characters
- if win_col2 = w_right_column then
- clear_end_of_line( master_buffer , win_line1 , win_col1 ) ;
- else
- goto_line_column ( master_buffer , win_line1 , win_col1 ) ;
- for col in win_col1 .. win_col2 loop
- put(' ');
- end loop ;
- end if ;
- else
- -- first do first line.
- if win_col1 <= w_right_column then
- clear_end_of_line( master_buffer , win_line1 , win_col1 ) ;
- end if ;
- -- then do middle lines
- for line_num in win_line1 + 1 .. win_line2 - 1 loop
- clear_end_of_line( master_buffer , line_num , w_left_column ) ;
- end loop ;
- -- then do last line ...
- if win_col2 >= w_left_column then
- if win_col2 = w_right_column then
- clear_end_of_line( master_buffer , win_line2 , w_left_column ) ;
- else
- goto_line_column ( master_buffer , win_line2 , w_left_column ) ;
- for col in w_left_column .. win_col2 loop
- put(' ');
- end loop ;
- end if ;
- end if ;
- end if ;
- end if ;
- end clear ;
-
- procedure x_line_forward( which_buffer : in out an_editor_buffer ) is
- ending_position : type_buffer_position ;
- begin -- x_line_forward
- ending_position :=
- which_buffer.fixed_cursor.line_start + line_length(
- which_buffer , which_buffer.fixed_cursor.line_start ) + 3 ;
- if which_buffer.e_buf(ending_position).data = buffer_boundry then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- else
- which_buffer.moving_cursor.line_start := ending_position ;
- which_buffer.moving_cursor.file_line_number :=
- which_buffer.fixed_cursor.file_line_number + 1 ;
- which_buffer.moving_cursor.buffer_position := 0 ;
- which_buffer.moving_cursor.column_offset := 0 ;
- end if;
- end x_line_forward ;
-
- procedure x_line_backward(which_buffer : in out an_editor_buffer ) is
- a_position : type_buffer_position ;
- begin -- x_line_backward
- a_position := which_buffer.fixed_cursor.line_start ;
- if which_buffer.e_buf(a_position - 1 ).data = buffer_boundry then
- which_buffer.moving_cursor := which_buffer.fixed_cursor ;
- else
- which_buffer.moving_cursor.line_start := a_position
- - line_length( which_buffer , a_position-1 ) - 3 ;
- which_buffer.moving_cursor.file_line_number :=
- which_buffer.fixed_cursor.file_line_number - 1 ;
- which_buffer.moving_cursor.buffer_position := 0 ;
- which_buffer.moving_cursor.column_offset := 0 ;
- end if ;
- end x_line_backward ;
-
- procedure load_current_text ( to_line_number : line_number ) is
- -- get a line which is on the screen, which therefore is in memory,
- -- so no moving around is necessary....
- save_cursor : cursor_position ;
- line : line_number ;
- begin -- load_current_text
- save_cursor := master_buffer.fixed_cursor ;
- line := master_buffer.fixed_cursor.file_line_number ;
- if to_line_number > line then
- -- We need to move forward
- loop
- x_line_forward(master_buffer);
- exit when master_buffer.fixed_cursor = master_buffer.moving_cursor ;
- -- end of file
- master_buffer.fixed_cursor := master_buffer.moving_cursor ;
- line := line + 1 ;
- exit when line = to_line_number ; -- found line
- end loop ;
- -- Here on either found line or at end of file
- elsif to_line_number < line then
- -- We need to move backward
- loop
- x_line_backward(master_buffer);
- exit when master_buffer.fixed_cursor = master_buffer.moving_cursor ;
- -- end of file
- master_buffer.fixed_cursor := master_buffer.moving_cursor ;
- line := line - 1 ;
- exit when line = to_line_number ; -- found line
- end loop ;
- -- Here on either found line or at end of file
- end if ;
- -- Now, we need to move to the specified offset
- if line = to_line_number then
- get_text_line( master_buffer , master_buffer.fixed_cursor.line_start,
- orig_text ) ;
- else
- orig_text.data_length := 0 ;
- end if ;
- for posn in orig_text.data_length + 1 .. max_column_number loop
- orig_text.data(posn) := extended_character(32); -- spaces...
- end loop ;
- master_buffer.fixed_cursor := save_cursor ;
- end load_current_text ;
-
- procedure put ( c : extended_character ) is
- begin -- put
- put( character'val( c ) ) ;
- end put ;
-
- procedure Put_Back ( Left_Pos , Right_Pos : in text_position ) is
- -- put back starting at left_pos and up to and including the
- -- character before right_pos ... at least one char ...
- twindow_line : window_line_number ;
- begin -- put_back
- First_Line := Left_Pos.Line ;
- Last_Line := Right_Pos.Line ;
- First_Col := Left_Pos.Column ;
- Last_Col := Right_Pos.Column ;
- if change_into_absolute_screen_locations then
- -- win_line1,win_col1 to win_line2,win_col2 are to be put back...
- -- first work line1 = line2
- if win_line1 = win_line2 then
- -- just put back a few characters
- -- just replace a few characters
- load_current_text ( first_line ) ;
- goto_line_column ( master_buffer , win_line1 , win_col1 ) ;
- for col in win_col1 .. win_col2 loop
- put( orig_text.data(col) );
- end loop ;
- else
- -- first do first line.
- if win_col1 <= w_right_column then
- load_current_text ( first_line ) ;
- goto_line_column ( master_buffer , win_line1 , win_col1 ) ;
- for col in win_col1 .. w_right_column loop
- put( orig_text.data(col) ) ;
- end loop ;
- end if ;
- twindow_line := win_line1 ;
- -- then do middle lines
- for line_num in first_line + 1 .. last_line - 1 loop
- twindow_line := twindow_line + 1 ;
- load_current_text ( line_num ) ;
- goto_line_column( master_buffer , twindow_line , w_left_column ) ;
- for col in w_left_column .. w_right_column loop
- put( orig_text.data(col) ) ;
- end loop ;
- end loop ;
- -- then do last line ...
- if win_col2 >= w_left_column then
- load_current_text ( last_line ) ;
- goto_line_column ( master_buffer , win_line2 , w_left_column ) ;
- for col in w_left_column .. win_col2 loop
- put( orig_text.data(col) ) ;
- end loop ;
- end if ;
- end if ;
- end if ;
- end put_back ;
-
- begin -- work_deletion
- If Old_Pos /= New_Pos then
- -- we must do something...
- Fix_Screen_Information ;
- if StrtDel_Pos = New_Pos then
- -- we have moved back to the starting position
- If lt ( Old_Pos , StrtDel_Pos ) then
- -- we moved right last when moving back to the current position
- put_back ( Old_Pos , New_Pos ) ; -- puts back all but new_pos
- else
- -- we moved left last when moving back to current position
- put_back ( New_Pos , Old_Pos ) ; -- puts back all but Old_Pos
- end if ;
- elsif lt ( StrtDel_Pos , New_Pos ) then
- -- we are deleting to the right of the starting position
- if lt ( Old_Pos , StrtDel_Pos ) then
- -- we moved old .. start .. new
- put_back ( Old_Pos , StrtDel_Pos ) ;
- Clear ( StrtDel_Pos , New_Pos ) ;
- elsif lt ( Old_Pos , New_Pos ) then
- -- we are moving right to the right of the start position
- Clear ( Old_Pos , New_Pos ) ;
- else
- -- we are moving left when to the right of the start position
- Put_Back ( New_Pos , Old_Pos ) ;
- end if ;
- else
- -- we are deleting to the left of the starting position
- if gt ( Old_Pos , StrtDel_Pos ) then
- -- we moved new .. start .. old
- put_back ( Old_Pos , StrtDel_Pos ) ;
- Clear ( StrtDel_Pos , New_Pos ) ;
- elsif gt ( Old_Pos , New_Pos ) then
- -- we are moving left to the left of the start position
- Clear ( New_Pos , Old_Pos ) ;
- else
- -- we are moving right when to the left of the start position
- Put_Back ( Old_Pos , New_Pos ) ;
- end if ;
- end if ;
- show_cursor ( master_buffer ) ;
- end if ;
- end work_deletion ;
-
- procedure end_deletion ( command : in an_editor_command ) is
- del_range : text_range ;
- begin -- end_deletion
- in_deletion := false ;
- allow_alternate_prompt_command := true ;
- need_prompt := true ;
- EndDelt_line := current_buffer.fixed_cursor.file_line_number ;
- EndDelt_column := current_buffer.fixed_cursor.column_offset ;
- EndDelt_Pos := current_Position ;
- if StrtDel_Pos /= EndDelt_Pos then
- -- must do something
- del_range := text_range'( StrtDel_Pos ,
- EndDelt_Pos ,
- no_screen_attribute ) ;
- normalize_range( del_range ) ;
- -- if del_range.hi_position.column > 1 then
- -- stay on same line
- -- del_range.hi_position.column := del_range.hi_position.column - 1 ;
- -- else
- -- move to previous line
- -- del_range.hi_position.line := del_range.hi_position.line - 1 ;
- -- del_range.hi_position.column := max_column_number ;
- -- end if ;
- del_range.hi_position.column := del_range.hi_position.column - 1 ;
- Copy_Text_To_Copy_Buffer( master_buffer ,
- del_range ,
- append_deletion ,
- command = accept_command ,
- command = accept_command ) ;
- -- copy the text within the range to the copy buffer
- -- then, delete the text......
- -- move the cursor to the correct position
- -- in any case, that is the starting position....
- -- ... because on accept, the ending text is moved to starting posn
- -- ... on reject, we want to move to the beginning anyway
- -- jump_to_position ( master_buffer , del_range.lo_position.line ,
- -- del_range.lo_position.column ,
- -- false);
- -- now, update the screen as necessary
- if StrtDel_Line = EndDelt_Line then
- -- just show that line
- clear_line ( master_buffer ,
- master_buffer.fixed_cursor.file_line_number
- - master_buffer.top_screen_cursor.file_line_number + 1);
- show_line ( master_buffer ,
- master_buffer.fixed_cursor.line_start ,
- master_buffer.fixed_cursor.file_line_number ) ;
- else
- -- redraw the entire screen
- -- debugger.show_buffer ;
- show_screen ( master_buffer ,
- master_buffer.fixed_cursor ,
- 0 ) ;
- -- debugger.show_buffer ;
- end if ;
- end if ;
- end end_deletion ;
-
- begin -- do_move_command
- -- note that we must come here with only those commands which are
- -- handled, otherwise, we will return the same command back and forth
- -- forever.....
- if actual_command = start_deletion_command then
- in_deletion := true ;
- append_deletion := false ;
- start_deletion ;
- else
- in_deletion := false ;
- end if ;
- current_column := current_buffer.fixed_cursor.file_line_number ;
- current_line := current_buffer.fixed_cursor.column_offset ;
- current_pos := current_position ;
- loop
- if actual_repeat = infinity then
- -- we are moving to the beginning or end of the file
- case actual_command is
- when up_command
- | left_command
- | backward_character_command
- | backward_word_command
- | backward_tab_command
- | backward_line_command
- | backward_paragraph_command
- | backward_page_command
- | jump_to_first_position_command => to_beginning ;
- when down_command
- | right_command
- | forward_character_command
- | forward_word_command
- | forward_tab_command
- | forward_line_command
- | forward_paragraph_command
- | forward_page_command
- | jump_to_last_position_command => to_end ;
- when home_command => if in_deletion then
- append_deletion := not append_deletion;
- do_delete_prompt ;
- else
- move_to_home_position ;
- end if ;
- when jump_to_marked_position_command
- => move_to_zap_marker ;
- when accept_command => if in_deletion then
- end_deletion( accept_command ) ;
- end if ;
- when reject_command => if in_deletion then
- end_deletion( reject_command ) ;
- end if ;
- when set_forward_direction => go_forward := true ;
- set_direction ( go_forward ) ;
- show_cursor ;
- actual_command := illegal_command ;
- when set_backward_direction=> go_forward := false ;
- set_direction ( go_forward ) ;
- show_cursor ;
- actual_command := illegal_command ;
- when others => -- we need to do something else....
- if in_deletion then -- can't leave
- crt_windows.bell ;
- actual_command := illegal_command ;
- else
- current_repeat_factor:= actual_repeat ;
- current_command := actual_command ;
- return ;
- end if ;
- -- undefined for other commands such as home_command,
- -- move_to_first_line..., move_to_last_line_..., and
- -- all of the advance commands ( because the advance commands
- -- are mapped to a specific direction before we are called
- end case ;
-
- else
-
- case actual_command is
- when up_command => cursor_vertical ( - actual_repeat ) ;
- when down_command => cursor_vertical ( actual_repeat ) ;
- when right_command => cursor_horizontal( actual_repeat ) ;
- when left_command => cursor_horizontal( - actual_repeat ) ;
- when forward_character_command
- => move_horizontal ( actual_repeat ) ;
- when backward_character_command
- => move_horizontal ( - actual_repeat ) ;
- when forward_word_command
- => position ( find_forward ( word_pattern ,
- actual_repeat ) ) ;
- when backward_word_command
- => position ( find_backward( word_pattern ,
- actual_repeat ) ) ;
- when forward_tab_command
- => position ( find_forward ( tab_pattern ,
- actual_repeat ) ) ;
- when backward_tab_command
- => position ( find_backward( tab_pattern ,
- actual_repeat ) ) ;
- when forward_line_command
- => if actual_repeat = 0 then
- position ( find_backward (
- line_start_pattern ) );
- else
- position ( find_forward (
- line_start_pattern ,
- actual_repeat ) ) ;
- end if ;
- -- note that a zero repeat factor will
- -- force a call to find_backward...
- when backward_line_command
- => position ( find_backward (
- line_start_pattern ,
- actual_repeat + 1 ) ) ;
- -- note that a zero repeat factor moves
- -- to the start of the current line,
- -- because it is the #1 line_start
- -- found
- when forward_paragraph_command
- => position ( find_forward (
- paragraph_pattern ,
- actual_repeat ) ) ;
- when backward_paragraph_command
- => position ( find_backward (
- paragraph_pattern ,
- actual_repeat ) ) ;
- when forward_page_command
- => page_forward ( actual_repeat ) ;
- when backward_page_command
- => page_backward ( actual_repeat ) ;
- when home_command => if in_deletion then
- append_deletion := not append_deletion;
- do_delete_prompt ;
- else
- move_to_home_position ;
- end if ;
- when move_to_first_line_position_command
- => position ( find_backward (
- line_start_pattern , 1 ) ) ;
- when move_to_last_line_position_command
- => position ( find_forward (
- line_end_pattern , 1 ) ) ;
- when jump_to_first_position_command
- => to_beginning ;
- show_cursor( master_buffer ) ;
- when jump_to_last_position_command
- => to_end ;
- show_cursor( master_buffer ) ;
- when jump_to_marked_position_command
- => move_to_zap_marker ;
- when accept_command => if in_deletion then
- end_deletion( accept_command ) ;
- end if ;
- when reject_command => if in_deletion then
- end_deletion( reject_command ) ;
- end if ;
- when set_forward_direction => go_forward := true ;
- set_direction ( go_forward ) ;
- show_cursor ;
- actual_command := illegal_command ;
- when set_backward_direction=> go_forward := false ;
- set_direction ( go_forward ) ;
- show_cursor ;
- actual_command := illegal_command ;
- when others => -- we need to do something else....
- if in_deletion then -- can't leave
- crt_windows.bell ;
- actual_command := illegal_command ;
- else
- current_repeat_factor:= actual_repeat ;
- current_command := actual_command ;
- return ;
- end if ;
- end case;
- end if ;
- if actual_command /= illegal_command then
- Old_Column := Current_Column ;
- Old_Line := Current_Line ;
- Old_Pos := Current_Pos ;
- current_column := current_buffer.fixed_cursor.file_line_number ;
- current_line := current_buffer.fixed_cursor.column_offset ;
- Current_Pos := Current_Position ;
- if in_deletion then
- work_deletion ( Old_Pos , Current_Pos ) ;
- end if ;
- end if ;
- get_another_command ;
- end loop ;
- end do_move_command ;
-
- procedure do_jump_command is
- new_location : text_position ;
- begin -- do_jump_command
- set_prompt( master_buffer , 1 , jump_command_prompt ) ;
- case crt_windows.char_or_abort( ' ' , 'B' , 'E' , 'M' ) is
- when 'B' => to_beginning ;
- show_cursor ( master_buffer ) ;
- when 'E' => to_end ;
- show_cursor ( master_buffer ) ;
- when 'M' => new_location := jump_to_marker ;
- if new_location /= no_set_location then
- position ( new_location ) ;
- end if ;
- when others => null ;
- end case ;
- need_prompt := true ; -- we need to reprompt after this...
- end do_jump_command ;
-
- begin -- movement_package
- -- MOVE by SAIC/Clearwater Movement Package 25 Jan 84
- null ;
- end movement_package ;
-
- --$$$- MOVE
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --insert
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ INSERT
-
- --
- -- File 019
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- --
- -- Editor Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with crt_windows ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with edit_windows ;
- use edit_windows ;
-
- with markers ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_general ;
- use buffer_lines ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- with debugger ;
- use debugger ;
-
- with editor_even_more_packages ;
- use editor_even_more_packages ;
-
- package insert_package is
-
- -- note that the left and paragraph margins are defined as the number
- -- of leading spaces that will appear before the first text character.
- -- the right margin is defined as the position where the last valid
- -- character can go...
-
- procedure do_insert_command ;
-
- end;
-
- package body insert_package is
-
- procedure do_insert_command is
-
- -- where is the Insert cursor in the file ?
- i_line_number : line_number ;
- i_column_number : column_position ;
- -- where is the Insert cursor on the screen ?
- w_line_number : window_line_number ;
- -- what does the screen look like ?
- w_top_line : line_number ;
- w_bot_line : line_number ;
- w_left_column : column_position ;
- w_right_column : column_position ;
- -- what is the text for the current line ?
- txt : type_text_line ;
- type type_old_end_of_line is
- record
- data : pstring ; -- this is the actual text
- data_leng : integer := 0 ; -- how long is it?
- put_in_col: integer := 0 ; -- what column to show it in
- for_left_c: integer := 1 ; -- for what lowest column number
- end record ;
- old_end_of_line : type_old_end_of_line ;
- no_room_for_insert : exception ;
- moved_screen : boolean := false ;
- on_first_line_of_insertion : boolean ;
- first_line_first_valid_column : column_position ;
- no_text_on_current_line : boolean ;
- no_text_ever_on_current_line : boolean ;
- show_old_line_end : boolean := true ;
- we_erased_rest_of_screen : boolean := false ;
- old_line_is_at_end_of_current_line : boolean := false ;
- previous_line_start : type_buffer_position := 0 ;
- current_line_is_bobs_word_processing_command : boolean := false ;
-
- cursor_position_at_insert_entry : cursor_position ;
- cursor_position_at_insert_end : cursor_position ;
- inserted_range : text_range ;
-
- insert_started_at_stuffstart : boolean ;
- insert_ended_at_stuffstart : boolean ;
- Old_Insert_Leading_Spaces : type_leading_spaces ;
- in_numeric_tab : boolean := false ;
-
- leading_spaces : type_leading_spaces ;
- first_text ,
- last_text : type_text_length ;
- ln_length : type_line_length ;
-
- orig_text : type_text_line ;
-
- type type_numeric_info is
- record
- first_number_column: column_position ;
- -- first column where we can put a number for tab
- last_number_column : column_position ;
- -- last column where we can put a number for tab
- curr_number_column : column_position ;
- -- present column for number in numeric tab
- field_width : column_position ;
- -- total number columns allowed in numeric tab
- end record ;
- numeric_info : type_numeric_info ;
-
- command_char : character ;
- editor_command : editor_globals.an_editor_command ;
-
- a_space : constant extended_character
- := extended_character(character'pos(' ') ) ;
-
- no_last_word_processor_key : constant string
- ( 1 .. max_wp_command_length ) := " " ;
- last_word_processor_key : string ( 1 .. max_wp_command_length )
- := no_last_word_processor_key ;
- last_keystroke_was_return_on_non_wordp_command_line : boolean := false ;
- new_paragraph_key : constant string ( 1 .. max_wp_command_length )
- := ascii.cr & ".new_paragraph" & ascii.cr & " " ;
- new_paragraph_key_length : constant integer := 16 ;
- add_one_line_key : constant string ( 1 .. max_wp_command_length )
- := ascii.cr & ".add 1" & ascii.cr & " " ;
- add_one_line_key_length : constant integer := 8 ;
- last_key_not_a_word_processor_command : boolean := true ;
-
- procedure set_window_positions is
- -- we need to set the values that tell us where the window is
- begin
- w_top_line := master_buffer.top_screen_cursor.file_line_number ;
- w_bot_line := w_top_line + window_height( master_buffer ) - 1 ;
- w_left_column := lowest_column_number( master_buffer ) ;
- w_right_column := highest_column_number( master_buffer ) ;
- -- fix up the old end of line position information...
- old_end_of_line.put_in_col := old_end_of_line.put_in_col
- - old_end_of_line.for_left_c + w_left_column ;
- old_end_of_line.for_left_c := w_left_column ;
- end;
-
- procedure scroll_forward_a_line is
- begin -- scroll_forward_a_line
- w_top_line := w_top_line + 1 ;
- w_bot_line := w_bot_line + 1 ;
- -- now, to fix top and nxt cursors
- set_cursor_down_lines(master_buffer ,
- master_buffer.top_screen_cursor ,
- master_buffer.top_screen_cursor , 1 ) ;
- scroll_up_entire_window(1);
- end scroll_forward_a_line ;
-
- procedure load_current_text is
- begin -- load_current_text
- get_text_line( master_buffer ,
- master_buffer.fixed_cursor.line_start , txt ) ;
- for posn in txt.data_length + 1 .. max_column_number loop
- txt.data(posn) := a_space; -- spaces...
- end loop ;
- end load_current_text ;
-
- procedure out_end_of_line( line : window_line_number ) is
- -- show the end of the first line....
- begin -- out_end_of_line
- -- only get here after checking that length is positive
- goto_line_column( master_buffer, line , old_end_of_line.put_in_col );
- put( old_end_of_line.data ) ;
- end out_end_of_line ;
-
- procedure initialize_Insert is
- -- used to be init_insertit
- nxt_line_start : type_buffer_position ;
-
- procedure set_old_line is
- break_char : type_text_length ;
- begin -- set_old_line
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- old_insert_leading_spaces := leading_spaces ;
- if ln_length < 1 then
- break_char := i_column_number ;
- elsif i_column_number <= first_text then
- break_char := first_text ;
- else
- break_char := i_column_number ;
- end if ;
- old_end_of_line.data_leng := txt.data_length - break_char + 1 ;
- if old_end_of_line.data_leng > 0 then
- if old_end_of_line.data_leng >
- highest_column_number(master_buffer)
- - lowest_column_number(master_buffer) + 1 then
- old_end_of_line.data_leng := highest_column_number(master_buffer)
- - lowest_column_number(master_buffer) ;
- -- the above gives it up to width - 1 characters long, so it
- -- starts in column 2 on the display
- end if ;
- for posn in 1 .. old_end_of_line.data_leng loop
- old_end_of_line.data.data(posn)
- := character'val( txt.data( break_char + posn - 1 ) ) ;
- end loop ;
- set_length( old_end_of_line.data , old_end_of_line.data_leng ) ;
- old_end_of_line.put_in_col := highest_column_number(master_buffer)
- - old_end_of_line.data_leng + 1 ;
- old_end_of_line.for_left_c := lowest_column_number(master_buffer);
- end if ;
- show_old_line_end := old_end_of_line.data_leng > 0 ;
- end set_old_line ;
-
- begin -- initialize_Insert
- set_window_positions ;
- -- where is the Insert cursor in the file ?
- i_line_number := master_buffer.fixed_cursor.file_line_number ;
- i_column_number := master_buffer.fixed_cursor.column_offset ;
- if i_column_number < 1 then
- i_column_number := 1 ;
- end if ;
- -- where is the Insert cursor on the screen ?
- w_line_number := i_line_number - w_top_line + 1 ;
- set_repeat_prompt( false , 0 ) ;
- prompt( Insert_command_prompt ) ;
- show_cursor( master_buffer ) ;
- cursor_position_at_insert_entry := master_buffer.fixed_cursor ;
- load_current_text ;
- orig_text := txt ;
- -- now, work on buffer
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- nxt_line_start := master_buffer.fixed_cursor.line_start
- + ln_length + 3 ;
- open_buffer( master_buffer , nxt_line_start, max_bytes_in_line * 10 ) ;
- -- and delete current line...
- master_buffer.first_open_position
- := master_buffer.fixed_cursor.line_start ;
- -- finish with current line
- no_text_on_current_line := ( ln_length = 0 )
- or ( i_column_number <= first_text ) ;
- no_text_ever_on_current_line := no_text_on_current_line ;
- insert_started_at_stuffstart := no_text_on_current_line ;
- -- now, we need to set up the old_end_of_line ;
- set_old_line ;
- -- now, we're ready...
- -- clear the remaining portion of the line
- for posn in i_column_number .. max_column_number loop
- txt.data(posn) := a_space; -- spaces...
- end loop ;
- clear_end_of_line ( master_buffer , w_line_number , i_column_number );
- if show_old_line_end then
- if old_end_of_line.put_in_col > i_column_number then
- old_line_is_at_end_of_current_line := true ;
- out_end_of_line( w_line_number ) ;
- goto_line_column(master_buffer, w_line_number , i_column_number);
- else
- -- it does not fit on the current line...
- old_line_is_at_end_of_current_line := false ;
- we_erased_rest_of_screen := true ;
- clear_end_of_screen( master_buffer ,
- w_line_number , i_column_number ) ;
- if w_line_number = window_height(master_buffer) - 1 then
- -- must scroll page
- scroll_forward_a_line ;
- w_line_number := window_height(master_buffer) - 1 ;
- end if ;
- out_end_of_line( w_line_number + 1 ) ;
- goto_line_column(master_buffer, w_line_number , i_column_number);
- end if ;
- end if ;
- on_first_line_of_insertion := true ;
- if no_text_on_current_line then
- first_line_first_valid_column := 1 ;
- else
- first_line_first_valid_column := i_column_number ;
- end if ;
- end initialize_Insert ;
-
- procedure replace_current_text is
- leading : type_leading_spaces ;
- text_first ,
- text_last : type_text_length ;
- text_leng : type_line_length ;
- ln_start : type_buffer_position ;
- new_nxt_line : type_buffer_position ;
- successfull : boolean ;
- begin -- replace_current_text
- -- Then, reset the length and the leading spaces ...
- -- i_column_number - 1 is the highest column number worked with...
- get_leading ( txt , leading , text_first , text_last , text_leng ) ;
- ln_start := master_buffer.fixed_cursor.line_start ;
- -- now, we need to move this line into the buffer....
- -- Four steps, 1: Open or close Buffer by appropriate positions
- -- must make sure we have room in buffer...
- if ln_start+max_bytes_in_line*2 > master_buffer.last_open_position then
- -- we need to make more room
- master_buffer.first_open_position
- := master_buffer.fixed_cursor.line_start ;
- -- we must push one block...
- if ln_start > block_size then
- push_data( master_buffer , thetop , successfull ) ;
- else
- push_data( master_buffer , thebot , successfull ) ;
- end if ;
- if not successfull then
- error( "Unable to update line. No Temporary File Room.",
- not_fatal_error , operator_wait , short_beep ) ;
- return ; -- unable to update ...
- else
- master_buffer.fixed_cursor.line_start
- := master_buffer.first_open_position ;
- ln_start := master_buffer.fixed_cursor.line_start ;
- end if ;
- end if ;
- new_nxt_line := ln_start + text_leng + 3 ;
- master_buffer.first_open_position := new_nxt_line ;
- -- 3: Add the new line
- master_buffer.e_buf(ln_start).data
- := extended_character(text_leng) ;
- master_buffer.e_buf(ln_start+1 ).data
- := extended_character(leading) ;
- for place in 1 .. text_leng loop
- master_buffer.e_buf(ln_start + 1 + place ).data :=
- txt.data(text_first+place-1) ;
- end loop ;
- master_buffer.e_buf(ln_start + text_leng + 2 ).data
- := extended_character(text_leng) ;
- for place in ln_start .. ln_start + text_leng + 2 loop
- master_buffer.e_buf(place).attr := no_screen_attribute ;
- end loop ;
- master_buffer.fixed_cursor.line_start := new_nxt_line ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- master_buffer.fixed_cursor.file_line_number
- := master_buffer.fixed_cursor.file_line_number + 1 ;
- --
- previous_line_start := ln_start ; -- don't forget where it was set
- -- Initialize a new blank line....
- ln_start := new_nxt_line ;
- for posn in ln_start .. ln_start + 2 loop
- master_buffer.e_buf( posn ).data := extended_character( 0 ) ;
- master_buffer.e_buf( posn ).attr := no_screen_attribute ;
- end loop ;
- master_buffer.e_buf( ln_start + 3 ).data
- := extended_character( buffer_boundry ) ;
- load_current_text ;
- no_text_on_current_line := true ;
- no_text_ever_on_current_line := true ;
- on_first_line_of_insertion := false ;
- in_numeric_tab := false ; -- not yet processing a numeric tab
- i_line_number := i_line_number + 1 ;
- current_line_is_bobs_word_processing_command := false ;
- end replace_current_text ;
-
- function to_text_pos ( curs : cursor_position ) return text_position is
- begin -- to_text_pos
- return text_position'( curs.file_line_number ,
- curs.column_offset ,
- no_screen_attribute ,
- master_buffer ) ;
- end to_text_pos ;
-
- procedure finish_insert( Last_Command : an_editor_command ) is
-
- procedure merge_last_line is
- posn : type_text_length ;
- offs : integer ;
- leading_spaces : type_leading_spaces ;
- first_text ,
- last_text : type_text_length ;
- ln_length : type_line_length ;
- begin -- merge_last_line
- if old_end_of_line.data_leng > 0 then
- posn := i_column_number - 1 ;
- offs := 0 ;
- loop
- exit when posn = type_text_length'last ;
- exit when offs >= length( old_end_of_line.data ) ;
- posn := posn + 1 ;
- offs := offs + 1 ;
- txt.data(posn) := extended_character(
- character'pos(old_end_of_line.data.data(offs)));
- end loop ;
- txt.data_length := posn ;
- end if ;
- -- that merged the current line and end of start line
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- replace_current_text ;
- -- now, set first open position
- master_buffer.first_open_position
- := master_buffer.fixed_cursor.line_start ;
- -- now, we may need to adjust the old information
- master_buffer.fixed_cursor.line_start := previous_line_start ;
- master_buffer.fixed_cursor.buffer_position := 0 ;
- master_buffer.fixed_cursor.file_line_number
- := master_buffer.fixed_cursor.file_line_number - 1 ;
- master_buffer.fixed_cursor.column_offset := i_column_number ;
- --
- cursor_position_at_insert_end := master_buffer.fixed_cursor ;
- insert_ended_at_stuffstart := ( ln_length = 0 )
- or ( i_column_number <= first_text ) ;
- end merge_last_line ;
-
- procedure adjust_leading ( new_leading : type_leading_spaces ) is
- begin -- adjust_leading
- master_buffer.e_buf( master_buffer.fixed_cursor.line_start + 1 )
- .data := extended_character( new_leading ) ;
- cursor_position_at_insert_end.column_offset := new_leading + 1 ;
- master_buffer.fixed_cursor.column_offset := new_leading + 1 ;
- end adjust_leading ;
-
- procedure just_show_screen( which_buffer : in out an_editor_buffer ;
- first_cursor : in cursor_position ;
- last_line_num: in line_number ) is
- -- show from first cursor's line to last_line_num
- starting_position : type_buffer_position ;
- current_window_line ,
- last_window_line : window_line_number ;
- current_line_number : line_number ;
- clear_each_line : boolean ;
- begin -- just_show_screen
- which_buffer.floating_cursor := which_buffer.fixed_cursor ;
- which_buffer.fixed_cursor := first_cursor ;
- current_line_number := first_cursor.file_line_number ;
- current_window_line := current_line_number + 1
- - which_buffer.top_screen_cursor.file_line_number ;
- last_window_line := last_line_num + 1
- - which_buffer.top_screen_cursor.file_line_number ;
- clear_each_line := last_window_line /= window_height(which_buffer);
- if not clear_each_line then
- clear_end_of_screen( which_buffer , current_window_line ,
- lowest_column_number( which_buffer ) ) ;
- end if ;
- loop
- if clear_each_line then
- clear_end_of_line( which_buffer , current_window_line ,
- lowest_column_number( which_buffer ) ) ;
- end if ;
- starting_position := which_buffer.fixed_cursor.line_start ;
- show_line( which_buffer, starting_position , current_line_number ) ;
- line_forward( which_buffer );
- exit when which_buffer.fixed_cursor = which_buffer.moving_cursor ;
- which_buffer.fixed_cursor := which_buffer.moving_cursor ;
- current_line_number := current_line_number + 1 ;
- current_window_line := current_window_line + 1 ;
- exit when ( current_window_line > last_window_line ) ;
- end loop ;
- which_buffer.fixed_cursor := which_buffer.floating_cursor ;
- end just_show_screen ;
-
- procedure reshow_line is
- -- for a reject command
- begin -- reshow_line ;
- clear_end_of_line(master_buffer , w_line_number , w_left_column ) ;
- show_line ( master_buffer ,
- master_buffer.fixed_cursor.line_start ,
- master_buffer.fixed_cursor.file_line_number ) ;
- show_cursor( master_buffer ) ;
- end reshow_line ;
-
- begin -- finish_insert
- -- cursor is at position i_column_number
- txt.data_length := i_column_number - 1 ;
- merge_last_line ;
- close_buffer( master_buffer ) ;
- put_cursor_on_line( master_buffer , w_line_number ) ;
- -- to set top and next cursors
- -- When do we re-capture the leading blanks that we had when we
- -- started? When the current line is empty, and we started at
- -- stuffstart (obviously). Also,
-
- -- Old theory: Reject and started at stuffstart
- -- or No text on line and still on first line
- -- or autoindent
- -- or filling off
- if last_command = reject_command then
- -- they ended with a reject
- If ( insert_started_at_stuffstart and insert_ended_at_stuffstart )
- and then cursor_position_at_insert_entry.file_line_number
- = cursor_position_at_insert_end. file_line_number then
- -- put back orig now...
- adjust_leading( Old_Insert_Leading_Spaces ) ;
- cursor_position_at_insert_end := cursor_position_at_insert_entry ;
- else
- -- now, same as insert rules
- if insert_ended_at_stuffstart
- and then ( master_buffer.pagezero.filling
- or master_buffer.pagezero.autoindent ) then
- adjust_leading( Old_Insert_Leading_Spaces ) ;
- end if ;
- end if ;
- Inserted_Range.Lo_Position := To_Text_Pos(
- Cursor_position_at_insert_entry ) ;
- Inserted_Range.Hi_Position := To_Text_Pos(
- Cursor_position_at_insert_end ) ;
- If inserted_range.hi_position.column > 0 then
- inserted_range.hi_position.column
- := inserted_range.hi_position.column - 1 ;
- end if ;
- copy_text_to_copy_buffer( master_buffer,inserted_range,
- false, -- don't add to previous copy
- true , -- delete after copy
- false ) ; -- don't adjust cursors
- -- must set fixed cursor correctly
- adjust_leading( Old_Insert_Leading_Spaces ) ;
- -- need to redisplay screen
- if we_erased_rest_of_screen then
- show_screen( master_buffer ) ;
- else
- reshow_line ;
- end if ;
- else
- -- they ended with an accept
- if insert_ended_at_stuffstart
- and then ( master_buffer.pagezero.filling
- or master_buffer.pagezero.autoindent ) then
- adjust_leading( Old_Insert_Leading_Spaces ) ;
- end if ;
- Inserted_Range.Lo_Position := To_Text_Pos(
- Cursor_position_at_insert_entry ) ;
- Inserted_Range.Hi_Position := To_Text_Pos(
- Cursor_position_at_insert_end ) ;
- If inserted_range.hi_position.column > 0 then
- inserted_range.hi_position.column
- := inserted_range.hi_position.column - 1 ;
- end if ;
- copy_text_to_copy_buffer( master_buffer , inserted_range ,
- false , -- don't add to previous copy
- false , -- don't delete after copy
- true ) ; -- adjust cursors after adding
- -- now, check out filling...
- if master_buffer.pagezero.filling
- and not master_buffer.pagezero.autoindent then
- clear_window( master_buffer ) ;
- prompt(" Re-filling remaining portion of paragraph. ");
- do_re_margin_command( master_buffer.fixed_cursor , false ) ;
- else
- -- need to finish up this line only, if we still have the
- -- stuff on this line, otherwise, rest of screen
- if we_erased_rest_of_screen then
- -- need to show from this to end of screen
- just_show_screen( master_buffer ,
- cursor_position_at_insert_end ,
- master_buffer.top_screen_cursor.file_line_number
- + window_height(master_buffer) - 1 ) ;
- else
- -- need to show only this line
- just_show_screen( master_buffer ,
- cursor_position_at_insert_end ,
- cursor_position_at_insert_end.file_line_number);
- end if ;
- end if ;
- end if ;
- need_prompt := true ;
- end finish_insert ;
-
- procedure beep_the_bell is
- begin
- crt_windows.bell ;
- end ;
-
- procedure get_c_or_cmd( c : out character ;
- cmd: out editor_globals.an_editor_command ) is
-
- -- used to be xgetch....
-
- -- get either a printable character or else get an editor command...
- -- note that here, printable characters take priority over commands
- physical_c : character ;
- physical_command : crt.special_keys ;
- begin -- get_c_or_cmd
- crt_windows.key_input( physical_c , physical_command ) ;
- if physical_command = key_character
- and then physical_c in ' ' .. '~' then
- -- easy... is just a printable character ...????
- c := physical_c ;
- cmd := editor_customization.illegal_command ;
- -- I really wanted to use editor_globals.illegal_command.......
- else
- -- need to find out what it might be...
- translate( physical_c , physical_command , c , cmd ) ;
- end if ;
- end get_c_or_cmd ;
-
- procedure pop_down_a_line_if_there_is_a_line_end is
- begin -- pop_down_a_line_if_there_is_a_line_end
- if show_old_line_end then
- if we_erased_rest_of_screen then
- -- just need to work on our next line then...
- clear_end_of_line( master_buffer, w_line_number, i_column_number );
- else
- -- we need to clear that entire screen...
- -- it does not fit on the current line...
- we_erased_rest_of_screen := true ;
- clear_end_of_screen( master_buffer,w_line_number, i_column_number );
- end if ;
- goto_line_column( master_buffer , w_line_number , w_left_column ) ;
- put(ascii.cr); -- to ensure that we have room for a new line
- if w_line_number = window_height( master_buffer ) then
- w_line_number := w_line_number - 1 ;
- end if ;
- out_end_of_line( w_line_number + 1 ) ;
- goto_line_column(master_buffer, w_line_number , i_column_number);
- end if ;
- old_line_is_at_end_of_current_line := false ;
- end pop_down_a_line_if_there_is_a_line_end ;
-
- procedure redo_screen ( new_col : integer ) is
- first_col_to_do : integer ;
- begin -- redo_screen
- show_screen( master_buffer ) ;
- set_window_positions ;
- we_erased_rest_of_screen := true ;
- -- now, show the current line ...
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- if ln_length > 0 then
- first_col_to_do := max( first_text , w_left_column ) ;
- goto_line_column( master_buffer , w_line_number , first_col_to_do );
- for posn in first_col_to_do .. last_text loop
- put( character'val( txt.data(posn) ) ) ;
- end loop ;
- end if ;
- -- then, old line end ...
- if show_old_line_end then
- out_end_of_line( w_line_number + 1 ) ;
- end if ;
- -- and position the cursor ...
- goto_line_column( master_buffer , w_line_number , new_col ) ;
- end redo_screen ;
-
- procedure make_pos_valid_on_screen_then_char_out
- ( c : character ; how_many : integer ) is
- -- assume called AFTER the txt area is set with values...
- new_col : integer ;
- begin -- make_pos_valid_on_screen_then_char_out
- new_col := i_column_number + how_many ;
- if new_col > w_right_column then
- -- we must shift and re-do the screen
- shift( master_buffer , - max( 15, new_col - w_right_column + 5 )) ;
- redo_screen ( new_col ) ;
- elsif new_col < w_left_column then
- -- must shift and re-do screen
- shift( master_buffer ,
- max( 15 , w_left_column - new_col + 5 ) ) ;
- redo_screen ( new_col ) ;
- else
- for posn in 1 .. how_many loop
- put( c ) ;
- end loop ;
- end if ;
- i_column_number := new_col ;
- end make_pos_valid_on_screen_then_char_out ;
-
- procedure start_next_line is
- next_line_blanks : integer ; -- because we must first check to see
- -- that it is in type_leading_spaces ;
- begin -- start_next_line
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- if master_buffer.pagezero.autoindent then
- next_line_blanks := leading_spaces ;
- elsif master_buffer.pagezero.filling then
- if ln_length < 1 or else txt.data(first_text) =
- extended_character(character'pos(
- master_buffer.pagezero.break_char )) then
- next_line_blanks := master_buffer.pagezero.paramargin ;
- else
- next_line_blanks := master_buffer.pagezero.lmargin ;
- end if ;
- else
- next_line_blanks := 0 ;
- end if ;
- if next_line_blanks > type_leading_spaces'last then
- next_line_blanks := type_leading_spaces'last ;
- end if ;
- if master_buffer.pagezero.justify then
- txt.data_length := i_column_number - 1 ;
- do_justify ( txt ) ;
- i_column_number := txt.data_length + 1 ;
- end if ;
- replace_current_text ; -- to save the new text
- if we_erased_rest_of_screen then
- if i_column_number < w_right_column then
- clear_end_of_line( master_buffer , w_line_number , i_column_number);
- end if ;
- else
- we_erased_rest_of_screen := true ;
- clear_end_of_screen( master_buffer , w_line_number , i_column_number);
- end if ;
- if w_line_number = window_height(master_buffer) then
- scroll_up_entire_screen(1);
- else
- w_line_number := w_line_number + 1 ;
- end if ;
- pop_down_a_line_if_there_is_a_line_end ;
- i_column_number := next_line_blanks + 1 ;
- make_pos_valid_on_screen_then_char_out( ' ' , 0 ) ;
- goto_line_column( master_buffer , w_line_number , i_column_number ) ;
- end start_next_line ;
-
- procedure pop_over_the_current_word is
- -- scan the line we are on. Take the last word off.
- -- move down to the next line. Put the word in.
- posn : integer ;
- type word_of_text is array ( type_line_length
- range 1 .. max_line_length ) of
- extended_character ;
- new_word : word_of_text ;
- new_word_length : integer ;
- begin -- pop_over_the_current_word
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- -- look for ' ' or '-'
- posn := last_text ;
- -- find last non-blank
- loop
- exit when posn <= first_text ; -- don't do anything
- exit when txt.data(posn) /= a_space;
- posn := posn - 1 ;
- end loop ;
- if posn > first_text then
- -- ok, we have something to work on, a word on a multi word line
- -- find last '-' or ' '
- loop
- exit when posn <= first_text ; -- don't do anything
- exit when txt.data(posn) = a_space
- or else txt.data(posn) = extended_character( character'pos('-') ) ;
- posn := posn - 1 ;
- end loop ;
- if posn > first_text then
- -- ok, found it
- posn := posn + 1 ; -- move past item to stay on the line
- -- now, move posn .. last_text to next line....
- new_word_length := last_text - posn + 1 ;
- if new_word_length > type_line_length'last then
- -- error
- new_word_length := type_line_length'last ;
- end if ;
- if new_word_length >= w_right_column - w_left_column + 1 then
- -- error
- -- must be no greater than one char less than screen width
- new_word_length := w_right_column - w_left_column ;
- end if ;
- for move_char in 1 .. new_word_length loop
- new_word( move_char ) := txt.data( posn + move_char - 1 ) ;
- end loop ;
- txt.data_length := posn - 1 ; -- sets last char to stay on line
- i_column_number := posn ; -- for replace current text
- start_next_line ; -- erases extra, and everything...
- for move_char in 1 .. new_word_length loop
- put( character'val( new_word( move_char ) ) ) ;
- txt.data(i_column_number+move_char-1):=new_word(move_char);
- end loop ;
- i_column_number := i_column_number + new_word_length ;
- no_text_on_current_line := false ;
- no_text_ever_on_current_line := false ;
- end if ;
- end if ;
- end pop_over_the_current_word ;
-
- procedure do_char ( c : in character ) is
- begin -- do_char
- if i_column_number < column_position'last then
- if i_column_number = 1 then
- -- special check just for bob's word processing command
- current_line_is_bobs_word_processing_command := c = '.' ;
- end if ;
- if c /= ' ' then
- no_text_on_current_line := false ;
- no_text_ever_on_current_line := false ;
- end if ;
- if in_numeric_tab then
- -- must do special work
- -- note that we are guaranteed that the entire number is on the
- -- screen
- if c in '0' .. '9'
- or else c = '-'
- or else c = '+'
- or else c = ','
- or else c = '$'
- or else c = '(' then
- -- valid numeric tab item
- if numeric_info.first_number_column
- < numeric_info.curr_number_column then
- -- there is room for at least one number to float ...
- numeric_info.curr_number_column
- := numeric_info.curr_number_column - 1 ;
- goto_line_column ( master_buffer , w_line_number ,
- numeric_info.first_number_column ) ;
- for posn in numeric_info.curr_number_column ..
- numeric_info.last_number_column - 1 loop
- txt.data(posn) := txt.data(posn+1) ;
- put( character'val( txt.data(posn) ) ) ;
- end loop ;
- i_column_number := i_column_number - 1 ;
- else
- in_numeric_tab := false ;
- end if ;
- else
- in_numeric_tab := false ;
- end if ;
- -- else no need to do special work...
- end if ;
- txt.data(i_column_number) := extended_character( character'pos(c) );
- make_pos_valid_on_screen_then_char_out( c , 1 ) ;
- if master_buffer.pagezero.filling then
- -- these are the special considerations for filling on
- if c /= ' ' then
- if i_column_number > master_buffer.pagezero.rmargin + 1 then
- -- special work for filling when we hit the end of the line
- pop_over_the_current_word ;
- end if ;
- elsif i_column_number > master_buffer.pagezero.rmargin + 11 then
- -- only do spaces if we are 10 spaces past end
- pop_over_the_current_word ;
- end if ;
- else
- -- these are the special considerations for filling off
- null ;
- end if ;
- if old_line_is_at_end_of_current_line
- and then show_old_line_end
- and then i_column_number + 1 >= old_end_of_line.put_in_col then
- pop_down_a_line_if_there_is_a_line_end ;
- end if ;
- end if ;
- end do_char ;
-
- procedure do_a_tab is
- old_col : integer ;
- new_col : integer ;
- new_tab : tabtypes ; -- type TABTYPES is ( TNONE , TNORMAL , TNUMBER );
- begin -- do_a_tab
- -- Need to move forward to the next tab position .
- old_col := i_column_number ;
- new_col := i_column_number ;
- loop
- exit when new_col >= column_position'last ;
- -- don't allow tab past last position
- new_col := new_col + 1 ;
- new_tab := master_buffer.pagezero.tabline ( new_col ) ;
- exit when new_tab /= tnone ;
- end loop ;
- -- ok, we have i_column_number as old and new_col as new
- if new_col > i_column_number then
- if new_tab = tnone then
- -- no more tabs on line...
- beep_the_bell ;
- else
- in_numeric_tab:= master_buffer.pagezero.tabline(new_col) = tnumber ;
- for posn in i_column_number .. new_col - 1 loop
- txt.data(posn) := a_space ;
- end loop ;
- if old_line_is_at_end_of_current_line
- and then show_old_line_end
- and then new_col+ 1 >= old_end_of_line.put_in_col then
- pop_down_a_line_if_there_is_a_line_end ;
- end if ;
- make_pos_valid_on_screen_then_char_out
- ( ' ' , new_col - i_column_number ) ;
- if in_numeric_tab then
- -- must set some information....
- -- don't let the witdth be more that 1/2 screen
- if ( new_col - old_col ) * 2 > w_right_column - w_left_column then
- old_col := new_col - ( w_right_column - w_left_column ) / 2 ;
- end if;
- numeric_info.first_number_column:= old_col + 1 ;
- numeric_info.last_number_column := i_column_number - 1 ;
- numeric_info.curr_number_column := i_column_number ;
- numeric_info.field_width := i_column_number - old_col - 1 ;
- end if ;
- end if ;
- end if ;
- end do_a_tab ;
-
- procedure insert_word_processor_command( new_command : string ;
- use_length : integer ) is
- -- insert this new word processor command string into the
- -- buffer .....
- -- The string of characters associated with the function key hit
- -- If the first character is ascii.cr, then start a new line at
- -- column 1. If the length is greater than 1 and then the last
- -- character is ascii.cr, then end by starting a new line and
- -- indenting to the old indentation from before the command key.
- -- If the first character is a space, then, only put the space in
- -- if the last character was not a space
- -- current_line_is_bobs_word_processing_command : boolean := false ;
- old_leading_spaces : type_leading_spaces ;
- next_position : integer := 1 ;
- next_char : character ;
- begin -- insert_word_processor_command
- last_key_not_a_word_processor_command := false ;
- last_word_processor_key := new_command ;
- -- because in fact we are only called with a string of exactly the
- -- correct length
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- old_leading_spaces := leading_spaces ;
- loop
- -- here, display the command until we hit end or else we hit
- -- ascii.cr
- next_char := new_command( next_position ) ;
- if next_char = ascii.cr then
- -- we must move to start of a line
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- if ln_length > 0 then
- -- end the current line
- start_next_line ;
- end if ;
- i_column_number := 1 ;
- make_pos_valid_on_screen_then_char_out ( ' ' , 0 ) ;
- goto_line_column( master_buffer , w_line_number , i_column_number );
- else
- if next_char = ' '
- and then next_position = 1
- and then i_column_number > 1
- and then txt.data( i_column_number - 1 ) = a_space then
- null ; -- skip it
- else
- do_char( next_char ) ;
- end if ;
- end if ;
- next_position := next_position + 1 ;
- exit when next_position > use_length ;
- end loop ;
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- -- finally, if no text on line, then put back old_leading_spaces
- -- if required...
- if ln_length = 0 then
- if master_buffer.pagezero.autoindent then
- -- we must check to see if we should put back old blanks ...
- i_column_number := old_leading_spaces + 1 ;
- elsif master_buffer.pagezero.filling then
- -- must start a new paragraph...
- i_column_number := master_buffer.pagezero.paramargin + 1 ;
- end if ;
- txt.data_length := i_column_number - 1 ;
- for space_position in 1 .. txt.data_length loop
- txt.data( space_position ) := a_space ;
- end loop ;
- end if ;
- make_pos_valid_on_screen_then_char_out ( ' ' , 0 ) ;
- goto_line_column( master_buffer , w_line_number , i_column_number ) ;
- end insert_word_processor_command ;
-
- procedure backup_char ( cmd : editor_globals.an_editor_command ) is
- -- used to be backup and do_ctrl_w
- cc : character ;
-
- function char_at_position return character is
- -- return the character at the current cursor position
- begin
- -- if on first line and we are left of starting position, return
- -- nul
- if on_first_line_of_insertion
- and then i_column_number < first_line_first_valid_column then
- return ascii.nul ;
- else
- return character'val ( txt.data( i_column_number ) ) ;
- end if ;
- end char_at_position ;
-
- procedure move_to_posn ( posn : integer ) is
- -- if possible, move to this column position
- -- change i_column_number , screen's cursor
- -- check actual screen window boundries...
- moving_col : column_position ;
- target_col : column_position ;
- begin -- move_to_posn
- moving_col := i_column_number ;
- if on_first_line_of_insertion
- and then posn < first_line_first_valid_column then
- target_col := first_line_first_valid_column ;
- beep_the_bell ;
- else
- target_col := posn ;
- end if ;
- if target_col < w_left_column then
- -- we need to do something...
- redo_screen( target_col ) ;
- i_column_number := target_col ;
- else
- -- just move around....
- loop
- exit when moving_col = target_col ;
- put( ascii.bs ) ;
- put( ' ' ) ;
- put( ascii.bs ) ;
- moving_col := moving_col - 1 ;
- end loop ;
- i_column_number := moving_col ;
- txt.data_length := i_column_number - 1 ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- no_text_on_current_line := ( ln_length = 0 ) ;
- end if ;
- end move_to_posn ;
-
- procedure up_one_line is
- -- if possible, move up one line , reset w_line_number etc...
- ln_start : type_buffer_position ;
- -- change txt , buffer , i_column_number , screen's cursor
- -- also, set on_first_line_of_insertion if appropriate
- -- set cc to ascii.nul if unable to go up a line...
- -- check actual screen window boundries...
- begin -- up_one_line
- -- first, we work on the buffer ...
- -- check for first line.....
- if on_first_line_of_insertion then
- cc := ascii.nul ; -- no line to move back to ...
- beep_the_bell ;
- elsIf cursor_backward_line then
- -- we can do it.....
- previous_line_start := master_buffer.fixed_cursor.line_start ;
- on_first_line_of_insertion
- := master_buffer.fixed_cursor.file_line_number
- = cursor_position_at_insert_entry.file_line_number ;
- i_line_number := i_line_number - 1 ;
- w_line_number := w_line_number - 1 ;
- load_current_text ;
- -- clear the remaining portion of the line
- for posn in txt.data_length + 1 .. max_column_number loop
- txt.data(posn) := a_space; -- spaces...
- end loop ;
- get_leading( txt, leading_spaces, first_text, last_text, ln_length);
- no_text_on_current_line := ( ln_length = 0 ) ;
- no_text_ever_on_current_line := false ; -- to back up fast...
- current_line_is_bobs_word_processing_command
- := character'val( txt.data(1) ) = '.' ;
- -- now, find out about old line
- i_column_number := last_text + 1 ;
- ln_start := master_buffer.fixed_cursor.line_start ;
- master_buffer.first_open_position
- := master_buffer.fixed_cursor.line_start ;
- previous_line_start := ln_start ; -- don't forget where it was set
- -- Initialize a new blank line....
- for posn in ln_start .. ln_start + 2 loop
- master_buffer.e_buf( posn ).data := extended_character( 0 ) ;
- master_buffer.e_buf( posn ).attr := no_screen_attribute ;
- end loop ;
- master_buffer.e_buf( ln_start + 3 ).data
- := extended_character( buffer_boundry ) ;
- -- now check w_line_number < 1 or i_column_number out ...
- -- now work on screen display...
- if i_column_number > w_right_column then
- -- we must shift and re-do the screen
- shift(master_buffer,-max(15,i_column_number-w_right_column+5));
- redo_screen ( i_column_number ) ;
- elsif i_column_number < w_left_column then
- -- must shift and re-do screen
- shift(master_buffer,max(15,w_left_column-i_column_number + 5 ));
- redo_screen ( i_column_number ) ;
- elsif w_line_number < 1 then
- redo_screen ( i_column_number ) ;
- else
- -- must work it out....
- clear_end_of_screen(master_buffer,
- w_line_number, i_column_number) ;
- if show_old_line_end then
- out_end_of_line( w_line_number + 1 ) ;
- end if ;
- -- and position the cursor ...
- goto_line_column(master_buffer, w_line_number , i_column_number) ;
- end if ;
- else
- cc := ascii.nul ;
- error( "Unable to read last line. Temporary File Error.",
- not_fatal_error , operator_wait , short_beep ) ;
- end if ;
- end up_one_line ;
-
- begin -- backup_char
- case cmd is
- when backward_character_command
- | left_command => if no_text_ever_on_current_line then
- -- in this case, they can move all
- -- the way back to first char posn
- if i_column_number > 1 then
- move_to_posn(i_column_number-1);
- else
- up_one_line ;
- end if ;
- else
- -- we have had text....
- if no_text_on_current_line then
- up_one_line ;
- else
- move_to_posn(i_column_number-1);
- end if ;
- end if ;
- when advance_word_command
- | backward_word_command => loop
- if i_column_number = 1 then
- cc := ascii.cr ;
- up_one_line ;
- else
- -- must move back one char..
- i_column_number :=
- i_column_number - 1 ;
- cc := char_at_position ;
- if cc = ascii.nul then
- i_column_number :=
- i_column_number + 1 ;
- end if ;
- end if ;
- exit when
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z'))
- or ( cc = ascii.nul ) ) ;
- end loop ;
- -- that moved past the current word
- -- now, move past trailing blanks.
- if cc /= ascii.nul then
- loop
- if i_column_number = 1 then
- cc := ascii.cr ;
- up_one_line ;
- else
- -- must move back one char..
- i_column_number :=
- i_column_number - 1 ;
- cc := char_at_position ;
- if cc = ascii.nul then
- i_column_number :=
- i_column_number + 1 ;
- end if ;
- end if ;
- exit when ( cc = ascii.nul )
- or else not
- ( ((cc>='0') and (cc<='9'))
- or ((cc>='A') and (cc<='Z'))
- or ((cc>='a') and (cc<='z')) ) ;
- end loop ;
- end if ;
- if cc /= ascii.nul then
- i_column_number :=
- i_column_number + 1 ;
- end if ;
- move_to_posn( i_column_number ) ;
- when backward_line_command => cc := ascii.cr ;
- -- to end of prev line
- up_one_line ;
- when move_to_first_line_position_command =>
- move_to_posn( 1 ) ; -- 1st posn on line
- when others => null ; -- can't get here
- end case ;
- end backup_char ;
-
- begin -- do_insert_command
- initialize_insert ;
- loop
- get_c_or_cmd( command_char , editor_command ) ;
- if editor_command /= advance_line_command
- and editor_command /= forward_line_command then
- last_keystroke_was_return_on_non_wordp_command_line := false ;
- last_key_not_a_word_processor_command := true ;
- -- else is set correctly later in the case statement....
- end if ;
- case editor_command is
- when illegal_command => if command_char /= ascii.nul then
- -- is a character to put into line
- -- is a real character...
- -- Now, put the character in...
- -- and then move right...
- do_char( command_char ) ;
- end if ;
- when advance_tab_command
- | forward_tab_command => do_a_tab ;
- when word_processor_command=> insert_word_processor_command(
- word_processor_command_string ,
- word_processor_command_string_length);
- when left_command -- left 1 character
- | backward_character_command
- | advance_word_command
- | backward_word_command -- left 1 word
- | backward_line_command -- back to end of previous line
- | move_to_first_line_position_command -- to 1st position on line
- => backup_char( editor_command ) ;
- when advance_line_command
- | forward_line_command => -- <cr> command, check for special
- if master_buffer.pagezero.enable_cmds
- and then not current_line_is_bobs_word_processing_command then
- -- must check sufficiently...
- if last_keystroke_was_return_on_non_wordp_command_line
- or else ( ( not last_key_not_a_word_processor_command )
- and ( last_word_processor_key = new_paragraph_key
- or last_word_processor_key = add_one_line_key )) then
- -- we definitely want an add one here...
- insert_word_processor_command( add_one_line_key ,
- add_one_line_key_length ) ;
- last_keystroke_was_return_on_non_wordp_command_line := false;
- elsif master_buffer.pagezero.filling then
- insert_word_processor_command( new_paragraph_key ,
- new_paragraph_key_length) ;
- last_keystroke_was_return_on_non_wordp_command_line := false;
- else
- last_keystroke_was_return_on_non_wordp_command_line
- := not current_line_is_bobs_word_processing_command ;
- start_next_line ;
- end if ;
- else
- last_keystroke_was_return_on_non_wordp_command_line
- := not current_line_is_bobs_word_processing_command ;
- start_next_line ;
- end if ;
- when accept_command => null ; -- handled outside this loop
- when reject_command => null ; -- handled outside this loop
- when up_command => beep_the_bell ; -- null ; -- for now...
- when down_command => beep_the_bell ; -- null ; -- for now...
- when right_command => beep_the_bell ; -- null ; -- for now...
- when others => beep_the_bell ; -- null ; -- skip them......
- -- show_buffer ( 'V' ) ;
- end case ;
- exit when editor_command = accept_command
- or editor_command = reject_command ;
- end loop ;
- finish_Insert ( editor_command ) ;
- exception
- when no_room_for_insert => finish_insert ( accept_command ) ;
- end do_insert_command ;
-
- begin -- insert_package
- -- INSERT by SAIC/Clearwater Insert Package 14 Jan 85
- null ;
- end insert_package ;
-
- --$$$- INSERT
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --edit
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ EDIT
-
- --
- -- File 021
- --
- -- Editor Written By Robert S. Cymbalski
- -- Science Applications International Corporation
- -- Energy Systems Group
- -- Ada Software Development Project Team
- -- 2280 U.S. Highway 19 North, Suite 120
- -- Clearwater, Florida 33575
- --
- -- Main Program Written 12 Nov 84 - RSC
- -- revised 26 Dec 84 - RSC
- --
- --
- -- Editor Revised from text Copyright (c) 1984 , R.S.Cymbalski
- --
-
- with string_library ;
- use string_library ;
-
- with basic_io_system ;
-
- with crt_customization ;
- use crt_customization ;
- use crt ;
- use editor_customization ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor_globals ;
- use editor_globals ;
-
- with editor_misc ;
- use editor_misc ;
- use copy_package ;
-
- with buffer_package ;
- use buffer_package ;
- use buffer_block_io ;
- use buffer_general ;
-
- with editor_files ;
- use editor_files ;
-
- with editor_main_packages ;
- use editor_main_packages ;
-
- with insert_package ; -- Insert Text
- use insert_package ; -- Insert Text
-
- with movement_package ; -- The do_move_command is in this package
- use movement_package ; -- & home & Jump Commands
-
- with editor_more_packages ;
- use editor_more_packages ;
-
- with editor_even_more_packages ;
- use editor_even_more_packages ;
-
- with debugger ;
-
- with editor_find ;
- use editor_find ;
-
- package editor is
-
- procedure TEXT_EDITOR(SOURCE_FILE : in ASCII_TEXT_FILE_NAME ;
- DESTINATION_FILE: in ASCII_TEXT_FILE_NAME);
- -- This tool allows a SOURCE_FILE to be edited. Either file name may
- -- be empty, in which case the editor will prompt for the input file
- -- and give standard output file options.
-
- end ;
-
- package body editor is
-
- procedure TEXT_EDITOR(SOURCE_FILE : in ASCII_TEXT_FILE_NAME;
- DESTINATION_FILE: in ASCII_TEXT_FILE_NAME)
- is
- -- This tool allows a SOURCE_FILE to be edited. Either file name may
- -- be empty, in which case the editor will prompt for the input file
- -- and give standard output file options.
-
- partial_quit_request: boolean ;
- total_quit_request : boolean ;
- Loaded_A_File : boolean ;
-
- procedure err( s : string ) is
- c : extended_character ;
-
- begin
- basic_io_system.put_line;
- basic_io_system.put_line;
- basic_io_system.put( "Exception: " & s ) ;
- basic_io_system.put_line;
- basic_io_system.put_line;
- basic_io_system.put_line;
- for buf in 1 .. max_buffer_number loop
- if buffer_list( buf ) /= null then
- buffer_package.dispose_buffer( buffer_list( buf ) ) ;
- end if ;
- end loop ;
- basic_io_system.put ( " Type <space> to continue.... ");
- c := basic_io_system.get_transparent ;
- terminate_copy_package ;
- end err ;
-
- begin -- Text_Editor
- editor_master_reset ;
- -- Initialize the entire text editor.
- loop
- -- This is for the multiple entries of the editor
- editor_re_initialize( Loaded_A_File ) ;
- go_forward := true ;
- current_repeat_factor := 0 ; -- to cause command to show it as [ Once]
- set_direction ( go_forward ) ;
- total_quit_request := false ;
- -- Repeat Factor is the only item which is set in this main
- -- Procedure which is available to the called procedures...
- -- Go forward is used here also...
- If Loaded_A_File then
- current_command := illegal_command ; -- to force a read...
- else
- current_command := insert_command ;
- -- Automatically go into insert mode if
- -- no file name was given upon entry
- end if;
- loop
- partial_quit_request := false ;
- if need_prompt then
- set_direction( go_forward ) ;
- end if ;
- if current_command = illegal_command then
- get_next_command( current_repeat_factor , current_repeat_factor ,
- current_command );
- end if ;
- case current_command is
- when up_command
- | down_command
- | right_command
- | left_command
- | forward_character_command
- | backward_character_command
- | forward_word_command
- | backward_word_command
- | forward_tab_command
- | backward_tab_command
- | forward_line_command
- | backward_line_command
- | forward_paragraph_command
- | backward_paragraph_command
- | forward_page_command
- | backward_page_command
- | home_command
- | move_to_first_line_position_command
- | move_to_last_line_position_command
- | jump_to_first_position_command
- | jump_to_last_position_command
- | jump_to_marked_position_command
- => do_move_command( current_command, current_repeat_factor) ;
- when advance_character_command
- => if go_forward then
- do_move_command ( forward_character_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_character_command ,
- current_repeat_factor ) ;
- end if;
- when advance_word_command
- => if go_forward then
- do_move_command ( forward_word_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_word_command ,
- current_repeat_factor ) ;
- end if;
- when advance_tab_command
- => if go_forward then
- do_move_command ( forward_tab_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_tab_command ,
- current_repeat_factor ) ;
- end if;
- when advance_line_command
- => if go_forward then
- do_move_command ( forward_line_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_line_command ,
- current_repeat_factor ) ;
- end if;
- when advance_paragraph_command
- => if go_forward then
- do_move_command ( forward_paragraph_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_paragraph_command ,
- current_repeat_factor ) ;
- end if;
- when advance_page_command
- => if go_forward then
- do_move_command ( forward_page_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( backward_page_command ,
- current_repeat_factor ) ;
- end if;
- when advance_infinity_command
- => if go_forward then
- do_move_command ( jump_to_first_position_command ,
- current_repeat_factor ) ;
- else
- do_move_command ( jump_to_last_position_command ,
- current_repeat_factor ) ;
- end if;
- when set_forward_direction => go_forward := true ;
- set_direction ( go_forward ) ;
- show_cursor ;
- current_command := illegal_command ;
- when set_backward_direction=> go_forward := false ;
- set_direction ( go_forward ) ;
- show_cursor ;
- current_command := illegal_command ;
- when shift_screen_right => shift_screen( -current_repeat_factor);
- current_command := illegal_command ;
- when shift_screen_left => shift_screen( current_repeat_factor );
- current_command := illegal_command ;
- when adjust_command => do_adjust_command ;
- current_command := illegal_command ;
- when copy_command => do_copy_command ;
- current_command := illegal_command ;
- when start_deletion_command=> do_move_command(
- start_deletion_command,1);
- when find_command => do_find_command (go_forward,
- current_repeat_factor,
- current_command) ;
- -- Under certain circumstances,
- -- this find command can return
- -- a request to Q(uit
- if current_command/= quit_command then
- current_command := illegal_command ;
- end if ;
- when help_command => do_help_command ;
- need_prompt := true ;
- show_screen( master_buffer,
- master_buffer.fixed_cursor, 0 );
- current_command := illegal_command ;
- when insert_command => do_insert_command ;
- current_command := illegal_command ;
- when jump_command => do_jump_command ;
- current_command := illegal_command ;
- when kill_command => do_kill_command ( go_forward );
- current_command := illegal_command ;
- when print_screen_command => do_printer_command ;
- current_command := illegal_command ;
- when re_margin_command => do_re_margin_command (
- master_buffer.fixed_cursor ,
- true , current_repeat_factor ) ;
- current_command := illegal_command ;
- when quit_command => do_quit_command (
- partial_quit_request,
- total_quit_request);
- -- quit_partial =>partial_quit_request
- -- quit_total =>total_quit_request;
- if not ( partial_quit_request
- or total_quit_request ) then
- set_direction(go_forward);
- end if ;
- current_command := illegal_command ;
- when replace_command => do_find_command (go_forward,
- current_repeat_factor,
- current_command ) ;
- -- Under certain circumstances,
- -- this replace command can return
- -- a request to Q(uit
- if current_command/= quit_command then
- current_command := illegal_command ;
- end if ;
- when set_stuff_command => do_set_information_command ;
- current_command := illegal_command ;
- when verify_screen_command => do_verify_screen_command ;
- current_command := illegal_command ;
- when enter_exchange_mode => do_enter_exchange_mode ;
- current_command := illegal_command ;
- when zap_command => do_zap_command ;
- -- debugger.show_buffer ;
- current_command := illegal_command ;
- when accept_command => do_end_open_commands(accept_command) ;
- current_command := illegal_command ;
- when reject_command => do_end_open_commands(reject_command) ;
- current_command := illegal_command ;
-
- when illegal_command
- | digit_command
- | infinity_command
- | show_other_prompt_command
- | word_processor_command=> current_command := illegal_command ;
- end case ;
- exit when partial_quit_request or total_quit_request ;
- end loop;
- exit when total_quit_request ;
- end loop;
- terminate_copy_package ;
- exception
- -- when user_abort => null ;
- when constraint_error => err("Constraint Error");
- when numeric_error => err("Numeric Error");
- when program_error => err("Program Error");
- when storage_error => err("Storage Error");
- when tasking_error => err("Tasking Error");
- when others => err("Unknown Error");
- end text_editor ;
-
- begin -- Editor
- -- EDIT by SAIC/Clearwater Main Text Editor Package 26 Dec 84
- -- text_editor(no_file , no_file ) ;
- -- crt.do_crt ( crt.program_termination ) ;
- null ;
- end editor ;
-
- --$$$- EDIT
-
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- --rune.TXT;compile]edit
- --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- --$$$+ rune
-
- with crt_customization ;
- use crt_customization ;
-
- with Wordp_Globals ;
- use Wordp_Globals ;
-
- with editor ;
- use editor ;
-
- Procedure RunE is
-
- begin -- RunE ;
- text_editor( no_file , no_file ) ;
- crt.do_crt ( crt.program_termination ) ;
- end RunE ;
-
- --$$$- rune
-
-