Example 2–4 dectpu command file gsr.tpu – Compaq DEC Text Processing Utility AA-PWCBD-TE User Manual
Page 25
Getting Started with DECTPU
2.2 Invoking DECTPU from a DCL Command Procedure
Example 2–3 DCL Command Procedure INVISIBLE_TPU.COM
! This command procedure invokes DECTPU without an editor.
! The file GSR.TPU contains the edits to be made.
! Specify the file to which you want the edits made as p1.
!
$ EDIT/TPU/NOSECTION/COMMAND=gsr.tpu/NODISPLAY ’p1’
!
The DECTPU command file GSR.TPU, which is used as the file specification
for the /COMMAND qualifier, performs a search through the current buffer
and replaces a string or a pattern with a string. Example 2–4 shows the file
GSR.TPU. GSR.TPU does not create or manipulate any windows.
Example 2–4 DECTPU Command File GSR.TPU
PROCEDURE global_search_replace (str_or_pat, str2)
! This procedure performs a search through the current
! buffer and replaces a string or a pattern with a new string
LOCAL src_range, replacement_count;
! Return to caller if string not found
ON_ERROR
msg_text := FAO (’Completed !UL
replacement!%S’, replacement_count);
MESSAGE (msg_text);
RETURN;
ENDON_ERROR;
replacement_count := 0;
LOOP
src_range := SEARCH (str_or_pat, FORWARD);
! Search returns a range if found
ERASE (src_range);
! Remove first string
POSITION (END_OF (src_range));
! Move to right place
COPY_TEXT (str2);
! Replace with second string
replacement_count := replacement_count + 1;
ENDLOOP;
ENDPROCEDURE;
! global_search_replace
! Executable statements
input_file := GET_INFO (COMMAND_LINE, "file_name");
main_buffer:= CREATE_BUFFER ("main", input_file);
POSITION (BEGINNING_OF (main_buffer));
global_search_replace ("xyz$_", "user$_");
pat1:= "" & LINE_BEGIN & "t";
POSITION (BEGINNING_OF (main_buffer));
global_search_replace (pat1, "T");
WRITE_FILE (main_buffer, "newfile.dat");
QUIT;
To use the DCL command procedure INVISIBLE_TPU.COM interactively,
invoke it with the DCL command @ (at sign). For example, to use INVISIBLE_
TPU.COM interactively on a file called MY_FILE.TXT, type the following at the
DCL prompt:
$ @invisible_tpu my_file.txt
You must explicitly write out any modified buffers before leaving the editor with
QUIT or EXIT. If you use QUIT before writing out such buffers, DECTPU quits
without saving the modifications. If you use EXIT, DECTPU asks if it should
write the file before exiting.
Getting Started with DECTPU 2–5