Contents:
Command-Line Syntax
How the Matching Files are Handled
Format of the Replacement File
A Crash-Course in Perl Regexps
ssreplace -config config-file | -VSS SS-path [-comments] [-HTML]
[-lang VB|SQL|C ...] [-type filetype ... ]
[-nolist] [-edit] [-rename] repl-file
-config | Config-file that determines which SourceSafe projects that SSREPLACE is to search in. With SSREPLACE, the version-designator column in the config-file has no signficance, as SSREPLACE always searches the most recently checked-in version of each file. |
-VSS | Specifies an SS-path for a singular SourceSafe project for SSREPLACE to search. SSREPLACE will search the most recently checked-in version of each file. |
-comments |
Whether SSREPLACE is to search and replace also within comments,
or only in text outside comments. See the page for SSGREP, for which file types
AbaPerls knows how to strip comments from the code. If you do not specify -comments, |
-HTML |
Instructs SSREPLACE to produce the list of changes in HTML format, with
underlining the performed replacements. This greatly enhances readability. As you will need a web browser to read the output, it is adviceable to use > to redirect the output to a file. |
-type |
Specifies that SSREPLACE is to search only files of the specified
type(s). You can specify multiple on the command
line. You can specify the file type with a leading period, but this is not
required. Example: to search only stored procedures and triggers you could
specify: . As the example indicates
the type names are case-insenstive. |
-lang |
This is a shortcut to that permits you to
specify all types for a certain programming language in one go. The following
values are recognized:SQL – The SQL files according to the AbaPerls SQL directory structure. VB – Files of the types .BAS, .CLS, .FRM and .VB. C – Files of the types .C, .CPP, .H and .HPP. As with you can specify multiple on the command line. You can mix
and . |
-nolist |
Normally, SSPREPLACE prints all replacements it performs (or is about to perform
if you do not specify -edit-nolistThe output is printed to the command-line window. Use > to redirect output to a file. |
-edit |
You need to specify -edit-edit |
-rename |
With -renameNote that you need to be extra careful when you use -rename-editIf you do not specify -rename |
| repl-file |
File with the replacements to perform. Each line consists of old-string,
new-string and repl-options. The fields are separated by white space. The
three fields are used as input to the s/// operator in Perl with a
few twists. See further
below for more details on the format. |
-VSS,SSREPLACE ignores files that are binary according to SourceSafe. SSREPLACE also ignores projects with a path ending in SQL/SCRIPTS (since these typically are conversion scripts etc, that you have no interest to change.)
The default for SSREPLACE is to search and replace only outside comments. SSREPLACE first strips the code of comments, performs the replacements and then puts the comments back. (This is the same procedure as the AbaPerls file-loading process employs). In most cases you are not likely to notice this, but since AbaPerls does not really keep track on where on the line the comment is (most comments are at the end...), you may see changes if you put your comments in "odd" places.
-- (two hyphens) are comments and ignored. Unless they appear in the beginning of the line, the
hyphens must be preceded by space to work as a comment delimiter. (That is, two
hyphens
in the middle of old-string or new-string does not start a comment.) A
line may be empty, or consist of comments only.For each line that SSREPLACES traverses, SSREPLACES applies the replacements in repl-file in the order they appear in the file. That is, the second replacement is applied on the result of the first replacement. Thus, some carefulness may be in order.
A short description for the reader who already knows Perl regexps: the
replacements are carried out with the operator s///. You need to
observe the following differences with regards to how you use s/// in a Perl
script:
-- (two hyphens),
you must be prepend it with a backslash, or else the string will be taken for
a comment.igo to s///, that is
replacements are case-insensitive, and carried out for all matches on the line.What is said here, also applies to the search strings you pass to SSGREP and the patterns you can use in GRANT.TEMPLATE, except for the operator \_ which is specific to SSREPLACE.
All alphanumeric characters (letters, digits and underscore) representes themselves. (Note: I'm here only considering the letters of the English alphabet. What happens if you specify characters outside ASCII is up to Perl, and not defined by AbaPerls.) An alphanumeric character preceded by a backslash, represents in many cases some special function. A non-alphanumeric character preceded by a backslash always match that character and nothing else. If the character does not have any special meaning, the backslash is optional. The following non-alphanumeric characters are operators in regexps, and must be preceded by backslash to match the character itself: $ @ / ( ) [ { + ? \ * . ^ |
Also keep in mind, that if old-string starts with two hyphens, you need to use a backslash to prevent AbaPerls to intepret them as a comment delimiter.
The follow table lists the most commonly used components to build regular expressions.
. | Matches any character. |
* | Previous regular expression 0 or more times. hej*
matches "he", "hej", "hejj", but not "hejhej". The expreission (hej)*
matches "hejhej".
|
+ | Previous regular expression 1 or more times. |
? | Previous regular expression 0 or 1 time. E.g. EXEC(UTE)?
matches "EXEC" and "EXECUTE". |
() | Grouping to control in which order the expressions are evaluated, but also to get a back reference to use in new-string, more below. |
^ | Matches beginning of line. |
$ | Matches end of line. |
[] | A group of possible characters. Works like in SQL. For
instance, [^0-9] matches all non-digit characters.
|
| | Separates alternatives. E.g. (nisse|pelle) matches
both "nisse" and "pelle".
|
\_ | Matches a space character. (Applies to SSREPLACE only; this is not a Perl operator.) |
\b | Matches word boundary. If you wish to search for "insid", but
not want a match for "insidnew" or "newinsid", specify \binsid\b as
your search string.
|
| \s matches a white-space character, i.e. space or
tab. \S matches all characters that \s does not match. |
| \w matches a word charcater, that is, a-z,
A-Z, 0-9
and underscore. Whether it will match letters like ÅÄÖ is up to Perl. \W
matches everything that \w does not match. |
| \d matches a digit, 0-9. \D matches
everything else. |
@ $ / \
If new-string begins with two hyphens, you must precede them with backslash to prevent SSREPLACE to interpret the hyphens as a comment delimiter.
The following special characters are of interest:
\U | Change the case of the letters following \U to
uppercase. |
\L | Change the case of the letters following \L to
lowercase. |
\E | Closes \U or \L.
|
\_ | Inserts a space. This is not a Perl operator, but added by SSREPLACE. |
| Refers back to parenthesized grous in old-string.
$1 refers to the first parenthesis etc. You can also write ${1}.
See example below.
|
Say that we are change the datatype for all columns and variables that has "curcode" in the name from "ab_code" to "aba_curcode". We write this in the replacement file as:
(curcode\s+)ab_code ${1}aba_curcode
${1} here refers back to "curcode" and all white-space that follows
it. "aba_curcode" will then appear in the same column as "ab_code" did.
I, which instructs
SSREPLACE to use a case-sensitive search.You could also use G or O
to prevent SSREPLACE to use s/// with the g and o options, but it is
questionable
whether this is a good idea.
The option x enables extednded regular expressions in Perl.
These are beyond the scope of this crash-course.
An advanced option is e which means that new-string is a
Perl-expression. If you use e, you still need to use \_ to specify a space.
You cannot use the options s and m with SSREPLACE.
For detailed information about these options, please refer to the Perl documentation.