🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by R.W.Bell Fri, 20 Nov 1992 20:11
Replacing strings in multiple files..
#116
Author: R.W.Bell
Date: Fri, 20 Nov 1992 20:11
95 lines
3723 bytes
Someone wanted to replace a string in multiple file at DCL ??
Ken Selvia wrote this, works just dandy !!!

Enjoy..Bob Bell

---------------------------------

$EDIT/TPU/NOSECTION/COMMAND=SYS$INPUT/NODISPLAY
!
! This program is put into the public domain.
! You may do anything you want with it.
!
! Send comments or suggestions to UCS_KAS@SHSUODIN  (BITNET)
! Ken Selvia
! 5-APR-1988
!
PROCEDURE tpu$init_procedure
LOCAL next_file, search_string, replace_string,
      lower_string, total_files, total_strings, changed,
      search_size, case_match;
SET(FACILITY_NAME, "REPLACE");
SET(SUCCESS,OFF);
IF GET_INFO (COMMAND_LINE,"FILE_NAME") = "" THEN
    MESSAGE(" ");
    MESSAGE(" REPLACE - Multiple file search and replace utility.");
    MESSAGE(" ");
    MESSAGE(" Usage:    REPLACE file.name  (wildcards allowed)");
    MESSAGE("           SEARCH STRING");
    MESSAGE("           REPLACEMENT STRING");
    MESSAGE(" ");
    QUIT;
ENDIF;
MESSAGE ("Enter search and replace strings.");
MESSAGE ("The search is not case sensitive if search string is lower case.");
search_string := READ_LINE ("Enter search string: ");
replace_string := READ_LINE ("Enter replacement string: ");
IF LENGTH (search_string) = 0 THEN
        MESSAGE ("No search string given. Aborting...");
        QUIT;
ENDIF;
total_files := 0;
total_strings := 0;
lower_string := search_string;
CHANGE_CASE (lower_string,LOWER);
case_match := (lower_string = search_string);
search_size := LENGTH (search_string);
work_buffer := CREATE_BUFFER ("work");
POSITION (work_buffer);
LOOP
    ERASE (work_buffer);
    next_file := FILE_SEARCH (GET_INFO (COMMAND_LINE,"FILE_NAME"));
    EXITIF next_file = "";
    READ_FILE (next_file);
    POSITION (BEGINNING_OF (work_buffer));
    SET (OUTPUT_FILE,CURRENT_BUFFER,FILE_PARSE (next_file));
    changed := substitute(search_string,
                          replace_string,
                          search_size,
                          case_match);
    IF changed > 0 THEN
        total_files := total_files + 1;
        total_strings := total_strings + changed;
        WRITE_FILE (work_buffer);
    ENDIF;
    MESSAGE (FAO ("Replaced !ZL string!%S in file !AS",changed,next_file));
ENDLOOP;
SET(NO_WRITE, work_buffer);
MESSAGE (FAO ("Total files modified: !ZL", total_files));
MESSAGE (FAO ("Total strings replaced: !ZL", total_strings));
QUIT;
ENDPROCEDURE

PROCEDURE substitute(target,replacement,size,ignore_case)
local modified_count;
ON_ERROR
    RETURN (modified_count);
ENDON_ERROR
modified_count := 0;
LOOP
    IF ignore_case THEN
        POSITION (SEARCH (target ,FORWARD,NO_EXACT));
    ELSE
        POSITION (SEARCH (target,FORWARD,EXACT));
    ENDIF;
    ERASE_CHARACTER (size);
    COPY_TEXT (replacement);
    modified_count := modified_count + 1;
ENDLOOP;
ENDPROCEDURE
!    This line is only executed when compiling the TPU program.
     SAVE ("sys$disk:replace");
     QUIT;
$REPLACE :== "EDIT/TPU/SECT=''F$ENVI(""DEFAULT"")'REPLACE/NODISP/NOCOMM"
$EXIT
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads