PROCEDURE COPY_FROM_LIBRARY ! This TPU procedure will read the file named in a COBOL copy statement ! into a buffer with the same name local index1, index2, mark1, mark2, mark3, range1, buffer_ptr, delimiter, copy_buffer_name; on_error [TPU$_STRNOTFOUND]: [otherwise]: position (mark3); return; endon_error; ! put current line into a temp buffer for manipulation ! if buffer doesn't exist, create it mark3 := mark (none); range1 := current_line; buffer_ptr := edt$find_buffer ("COPY_LIBRARY"); if buffer_ptr = 0 then buffer_ptr := create_buffer ("COPY_LIBRARY"); set (no_write, buffer_ptr); endif; position (beginning_of (buffer_ptr)); erase (current_buffer); copy_text (range1); ! now look for the word "copy". If it isn't there, send a message and exit move_horizontal (-current_offset); index2 := search ("COPY", forward); if index2 = 0 then message ("Word 'COPY' not found - Operation aborted !"); position (mark3); return; endif; ! now look for the file to be copied. It will be delimited by single or ! double quotes, or if not by quotes, by a space. position (index2); index2 := search ("'", forward); if index2 = 0 then index2 := search ('"', forward); if index2 = 0 then index2 := search (" ", forward); if index2 = 0 then message ("File name delimiter not found - Operation aborted !"); position (mark3); return; endif; delimiter := " "; else delimiter := '"'; endif; else delimiter := "'"; endif; ! mark the beginning of the name position (index2); move_horizontal (1); mark1 := mark (none); ! now look for the ending delimiter. If not found send a message and exit if delimiter = " " then index2 := search (delimiter | ".", forward); else index2 := search (delimiter, forward); endif; if index2 = 0 then message ("Ending delimiter not found - Operation aborted !"); position (mark3); return; endif; ! mark the end of the name and put it into a string variable position (index2); move_horizontal (-1); range1 := create_range (mark1, mark (none), none); position (mark1); copy_buffer_name := erase_character (length (range1)); copy_text (copy_buffer_name); ! look for a "." in the name. If it doesn't appear, use .LIB extension index1 := index (copy_buffer_name, "."); if index1 = 0 then copy_buffer_name := copy_buffer_name + ".LIB"; endif; ! see if we have a buffer for this file already, if not, create it. ! in either case, read in the file and put it on the screen buffer_ptr := edt$find_buffer (copy_buffer_name); if buffer_ptr = 0 then buffer_ptr := create_buffer (copy_buffer_name, copy_buffer_name); set (no_write, buffer_ptr); else erase (buffer_ptr); position (beginning_of (buffer_ptr)); read_file (copy_buffer_name); set (output_file, buffer_ptr, copy_buffer_name); endif; position (beginning_of (buffer_ptr)); map (current_window, buffer_ptr); ! save the file name for use elsewhere... dal_input_file := copy_buffer_name; set (status_line, current_window, reverse, copy_buffer_name); ENDPROCEDURE;