!************************************************************************** ! * ! © Copyright 2007 Hewlett-Packard Development Company, L.P. * ! * ! Confidential computer software. Valid license from HP required for * ! possession, use or copying. Consistent with FAR 12.211 and 12.212, * ! Commercial Computer Software, Computer Software Documentation, and * ! Technical Data for Commercial Items are licensed to the U.S. Government * ! under vendor's standard commercial license. * ! * !************************************************************************** ! ! SYS$LIBRARY:DTM$UFDEFINES.TPU ! ! This file is provided for use with the user defined filter ! feature of Digital Test Manager. It contains a global replace ! procedure and strings and patterns that can be used to build ! patterns to be replaced. ! PROCEDURE global_replace ( pattern_to_replace, replacement_string; search_mode, evaluate_replacement, convert_linefeeds) ! ! DESCRIPTION: ! ! Replace all occurences of a given pattern with a given string ! in the buffer "filter_buffer". ! ! PARAMETERS: ! ! pattern_to_replace The pattern to be replaced. ! ! replacement_string The string to be substituted. ! ! search_mode (optional) The mode of pattern matching ! to be used when searching for ! the pattern. Should be one of: ! NO_EXACT (default) ! EXACT ! TPU$K_SEARCH_CASE ! TPU$K_SEARCH_DIACRITICAL ! ! evaluate_replacement (optional) Specifies whether the replacement ! string is to be evaluated. ! Should be one of: ! OFF, 0 (default) ! ON, 1 ! If specified as ON or 1, ! the replacement string is ! evaluated before use. This is ! needed if the replacement ! string contains any partial ! pattern variables. In this ! case, any string literals ! in the replacement string ! must be specified as nested ! strings and partial pattern ! variables converted to ! strings using STR. ! ! convert_linefeeds (optional) Specifies whether any linefeed ! characters in the replacement ! string are to be converted ! into line breaks. ! Should be one of: ! OFF, 0 (default) ! ON, 1 ! LOCAL found_range, mode, evaluate, convert_lf, replacement, i; ON_ERROR [OTHERWISE]: MESSAGE(ERROR_TEXT); ENDON_ERROR; IF search_mode = TPU$K_UNSPECIFIED THEN mode := NO_EXACT; ELSE mode := search_mode; ENDIF; IF evaluate_replacement = TPU$K_UNSPECIFIED THEN evaluate := OFF; ELSE evaluate := evaluate_replacement; ENDIF; IF convert_linefeeds = TPU$K_UNSPECIFIED THEN convert_lf := OFF; ELSE convert_lf := convert_linefeeds; ENDIF; POSITION (BEGINNING_OF (filter_buffer)); LOOP found_range := SEARCH_QUIETLY (pattern_to_replace, FORWARD, mode); EXITIF found_range = 0; POSITION (found_range); IF (evaluate=ON) OR (evaluate=1) THEN replacement := EXECUTE("RETURN(" + replacement_string + ")"); ELSE replacement := replacement_string; ENDIF; IF (convert_lf=ON) OR (convert_lf=1) THEN LOOP EXITIF LENGTH (replacement) = 0; i := INDEX (replacement, ascii(10)); IF i = 0 then COPY_TEXT (replacement); EXITIF; ELSE IF i > 1 THEN COPY_TEXT (SUBSTR(replacement, 1, i-1)); ENDIF; SPLIT_LINE; EXITIF i = LENGTH(replacement); replacement := SUBSTR(replacement, i+1); ENDIF; ENDLOOP; ELSE COPY_TEXT (replacement); ENDIF; ERASE (found_range); ENDLOOP; ENDPROCEDURE ! ! "null" which matches the null string. It can be used to specify ! optional pattern elements. For example, the pattern "'A' + ('B'|null)" ! matches the strings "A" and "AB" ! null := ""; ! ! Upper and lower case letters, including the shorthand "uc" and "lc" to ! match single upper or lower case letters. ! ! NOTE: These patterns require the use of the "EXACT" or "DTM$K_SEARCH_CASE" ! keyword as the third parameter to procedure "global_replace", otherwise ! they will match both upper and lower case letters. ! upper_case_letters := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; upper_case_letter := any(upper_case_letters); uc := any(upper_case_letters); lower_case_letters := "abcdefghijklmnopqrstuvwxyz"; lower_case_letter := any(lower_case_letters); lc := any(lower_case_letters); ! ! "letter" and the shorthand "l" which match a single letter ! and "word", which matches any sequence of letters. ! letters := upper_case_letters + lower_case_letters; letter := any(letters); l := any(letters); word := span(letters); ! ! "digit" and the shorthand "d" which match a single digit ! and "number", which matches any sequence of digits. ! digits := "0123456789"; digit := any(digits); d := any(digits); number := span(digits); ! ! "identifier" which matches a string starting with a letter and ! followed by any combination of letters, digits, underscores ! and dollars. This would match most OpenVMS symbols and logical names. ! This pattern can be redefined to meet other requirements. ! identifier := letter + span(letters + digits + '_' + '$'); ! "space" and the shorthand "s" match a single space, "spaces" matches ! a sequence of spaces, "tab" the tab character, "white_space" and the ! shorthand "ws" match any sequence of spaces and tabs and ! "optional_white_space" and the shorthand "ows" match white space ! or nothing. "lf" matches a linefeed and can also be used in ! the replacement string, in conjunction with the convert_linefeeds ! parameter to global_replace, to insert or retain a line break. ! space := ' '; s := ' '; spaces := span(space); tab := ascii(9); white_space := span(space+tab); ws := span(space+tab); optional_white_space := (span(space+tab)|null); ows := (span(space+tab)|null); lf := ascii(10);