The global_replace procedure can be used for many
filtering tasks. However any DECTPU commands can be
used to build filters. The file being filtered is read
into the buffer "filter_buffer" before the user filters
are applied and written out afterwards.
The following filter uses the DECTPU EDIT procedure to
convert all characters to upper case:
EDIT( filter_buffer, UPPER, OFF)
Note that while a similar effect is possible using the
COMPARE/IGNORE=CASE command, the filter can be applied
to individual tests, whereas the IGNORE qualifier
applies only to collections.
The following filter searches for numbers and replaces
them only if they are in a specified range:
POSITION (BEGINNING_OF (filter_buffer));
LOOP
found_range := SEARCH_QUIETLY (number, FORWARD);
EXITIF found_range = 0;
POSITION (END_OF(found_range));
MOVE_HORIZONTAL(1);
value := INT(STR(found_range));
IF (value>350) AND (value<570)
THEN
COPY_TEXT ("XXX");
ERASE (found_range);
ENDIF;
ENDLOOP;
The initial POSITION is required to ensure that the
whole of the filter_buffer is processed, because the
editing point is undefined at the start of each filter.
Then, as each number is processed, the editing point is
moved to the end of the number. The MOVE_HORIZONTAL
procedure call is necessary because the previous
POSITION leaves the editing point at the last character
of the number, which would result in an immediate match
on the next call to SEARCH_QUIETLY.