! Page 71 ! Edit a file in the current window. If the file is already in a buffer, ! use the old buffer. If not, create a new buffer. ! 13-jan-1987, AAW. eve_read_file is a copy of eve_get_file, with a last ! line added to do a SET NOWRITE. ! ! Parameters: ! ! read_file_parameter String containing file name - input procedure tpu$local_init eve$arg1_read_file := eve$arg1_buffer; endprocedure; procedure eve_read_file (read_file_parameter) local read_file_name, ! Local copy of read_file_parameter temp_buffer_name, ! String for buffer name based on read_file_name file_search_result, ! Latest string returned by file_search temp_file_name, ! First file name string returned by file_search loop_buffer, ! Buffer currently being checked in loop file_count, ! Number of files matching the spec temp_answer, ! Answer to "Create file?" new_buffer, ! New buffer created if needed found_a_buffer, ! True if buffer found with same name want_new_buffer; ! True if file should go into a new buffer on_error if error = tpu$_parsefail then message (fao ("Don't understand file name: !AS", read_file_name)); if eve$x_starting_up then eve$set_status_line (current_window); endif; return; endif; endon_error; if eve$check_bad_window then message ("Cursor has been moved to a text window; try command again"); return; endif; if not (eve$prompt_string (read_file_parameter, read_file_name, "File to get: ", "No file specified")) then return; endif; ! Protect against earlier file_search with same file name. file_search_result := file_search (eve$kt_null); temp_file_name := eve$kt_null; erase (eve$choice_buffer); ! Flesh out with full file spec, using default device and directory ! if they are defined. if get_info(eve$default_dir,"type") = UNSPECIFIED then eve$default_dir := eve$kt_null; endif; read_file_name := file_parse (read_file_name,eve$default_dir); file_count := 0; loop file_search_result := file_search (read_file_name); exitif file_search_result = eve$kt_null; file_count := file_count + 1; eve$add_choice (file_search_result); temp_file_name := file_search_result; endloop; if file_count > 1 then ! If read_file is called from eve$init_procedure, can't handle ! multiple choices, so set status line on main window and return if eve$x_starting_up then eve$set_status_line (current_window); endif; eve$display_choices (fao ("Ambiguous file name: !AS", read_file_name)); return; endif; ! Set-up to see if we already have a buffer by that name if temp_file_name = eve$kt_null then temp_buffer_name := file_parse (read_file_name, eve$kt_null, eve$kt_null, name) + file_parse (read_file_name, eve$kt_null, eve$kt_null, type); else temp_buffer_name := file_parse (temp_file_name, eve$kt_null, eve$kt_null, name) + file_parse (temp_file_name, eve$kt_null, eve$kt_null, type); endif; read_file_name := file_parse (read_file_name); ! Make sure we don't try to use a wildcard file-spec to create a new file. if file_count = 0 then if eve$is_wildcard (read_file_name) then message(fao("No files matching: !AS", read_file_name)); if eve$x_starting_up then eve$set_status_line (current_window); endif; return; endif; endif; loop_buffer := get_info (buffers, eve$kt_first); loop exitif loop_buffer = 0; if temp_buffer_name = get_info (loop_buffer, eve$kt_name) then found_a_buffer := 1; exitif 1; endif; loop_buffer := get_info (buffers, "next"); endloop; ! If there is a buffer by that name, is it the exact same file? ! If so, switch to that buffer. Otherwise use a new buffer, ! asking for a new buffer name (null new name will abort). if found_a_buffer then ! Have a buffer with the same name if temp_file_name = eve$kt_null then ! No file on disk if read_file_name = get_info (loop_buffer, eve$kt_output_file) then want_new_buffer := 0; else want_new_buffer := 1; endif; else ! Check to see if the same file if (temp_file_name = get_info (loop_buffer, eve$kt_output_file)) or (temp_file_name = get_info (loop_buffer, eve$kt_file_name)) then want_new_buffer := 0; else want_new_buffer := 1; endif; endif; if want_new_buffer then message (fao ("Buffer name !AS is in use", temp_buffer_name)); temp_buffer_name := read_line ("Type a new buffer name or press Return to cancel: "); if temp_buffer_name = eve$kt_null then message ("No new buffer created"); else new_buffer := eve$create_buffer (temp_buffer_name, read_file_name, temp_file_name); endif; else if current_buffer = loop_buffer then message (fao ("Already editing file !AS", read_file_name)); else map (current_window, loop_buffer); endif; endif; else ! No buffer with the same name, so create a new buffer new_buffer := eve$create_buffer (temp_buffer_name, read_file_name, temp_file_name); endif; if new_buffer <> 0 then set (eob_text, new_buffer, "[End of file]"); set (margins, new_buffer, eve$x_default_left_margin, get_info (current_window, eve$kt_width) - eve$x_default_right_margin); eve_set_nowrite; endif; ! Correct the status line in any event eve$set_status_line (current_window); endprocedure;