SSGREP

SSGREP is a tool for searching SourceSafe, and is far more powerful than Find in files in the SourceSafe GUI. By default, for known file types SourceSafe strips comments before searching, and thus you only get matches in the actual program code. With SSGREP you can search for more than one string at a time, and you can use the regular expressions of Perl. You can search more than one project hierarchy in the same search. There are a few more goodies too.

Command-line syntax:

ssgrep -config config-file | -VSS SS-path [-window n] [-noignorecase]
       [-comments] [-HTML] [-crossref]
       [-lang SQL|VB|C ... ] [-type filetype ...] [-all]
       searchstr1 [searchstr2 ...]
-config Config-file that lists several SourceSafe projects that SSGREP is to search in. With SSGREP, the version-designator column in the config-file has no significance, as SSGREP always searches the most recently checked-in version of each file.
-VSS Specifies an SS-path for a singular SourceSafe project for SSGREP to search. SSGREP will search the most recently checked-in version of each file.
-window Specifies how many lines around the matching lines that SSGREP is to include in the output. The default value for n is 1, which means that SSGREP only prints the lines that matches the search strings. If you specify n = 0, SSGREP will only list the file name. If you specify n > 1, SSGREP will display also n - 1 lines before and after the matching lines.
-[no]ignorecase Whether SSGREP is to make case-sensitive searches. By default, SSGREP ignores case.
-comments Specifies that SSGREP should not strip the files from comments when searching, but also search for matches within comments. See below, for which files SSGREP knows how to strip comments.
   If you do not specify -comments, SSGREP will only search in text outside the comments.
-HTML Instructs SSGREP to format the output in HTML. In HTML format, SSGREP surrounds all matches in tags to have them rendered underlined and in bold face. The idea is that this makes it easier to see what SSGREP actually matched.
   Obviously you need a web browser for the output to be meaningful. Use > to redirect the output to a file.
   Without -HTML, SSGREP prints the output in plain text.
-crossref -crossref is useful if you are search for a number of stored procedures or similar, to see where they are referenced. You get one section for each matching unique string. That is, if you specify a search pattern of my_.*_sp, you will get one section for my_first_sp, my_second_sp, my_third_sp etc in alphabetic order. Thus, the same file can appear in different places in the output. If there are more than one match on a single line, that line is printed for the first match on that line only.
-type Specifies that SSGREP is to search only files of the specified type(s). You can specify multiple -type 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: -type .sp -type TRI. As the example indicates the type names are case-insenstive.
-lang This is a shortcut to -type 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 -type you can specify multiple -lang on the command line. You can mix -lang and -type.
-all Search all subprojects. Without -all SSGREP skips projects where it does not anticipate anything interesting. Currently the list of skipped projects consists of all projects of which the path ends in SQL/SCRIPTS. (Where you typically keep update scripts and the like, and hits in them are usually not very relevant.)
Searchstr1 ... Search string that SSGREP is look for. SSGREP interprets the search string as a regular expression according to the rules of Perl. The manual page for SSREPLACE, includes a crash-course in regular expressions.
   Here I only mention that if your search strings include only letters, digits and underscore, you don't have to worry that the search string is interpreted in a way you did not intend. Beware that a period (.) carries the meaning of "any character". Such a special character you need to prepend with a backslash (\) to search for the character itself.
   If you specify more than search string, SSGREP searches for all strings.

SSGREP does not search files that are binary according to SourceSafe. This is not affected by the -all switch.

SSGREP prints it output to the command-line window, unless you redirect the output to a file with >. Beside the matching files and the matching lines, SSGREP also prints a header with the command-line switches and arguments.

SSGREP's ability to strip code from comments is not universal, but is restricted to the file types that AbaPerls is well versed in. More precisely, these are the file types where SSGREP is able to ignore comments: Visual Basic files (.BAS, .FRM, and .CLS), SQL files (.SQL, .SP, .TBL, .FKEY, .TRI, .INS, .IX, .VIEW, .SQLFUNC, .SQLINC, and .TYPE), SQRW files (.SQR och .DAT) and C files (.CPP, .C, .HPP, and .H).

Please note that just like other AbaPerls tools, SSGREP does not honour your SourceSafe settings.

It may take considerable time to search big projects. Therefore it may be advantageous to define a config-file that is narrower than usual. If you only want search stored procedures for a number of projects, you could define a config-file like this:

NISSE ssdb/$/nisse/4.20/sql/sp
KALLE ssdb/$/nisse/2.12/sql/sp
LENA  lenadb/$/lena/1.0/sql/sp