trsearch is a csh script, based on progsearch, with a similar user interface and some additional functionality. The current version (1.0) also supports the 'traditional' progsearch modes of operation. The principal changes introduced are
- By default, the 5 lines preceeding each string occurence are examined. This allows most string occurences to be assigned to a Fortran statement type, even on continuation lines
- The context in which a string occurs can be specified more exactly
- Strings are only matched as 'whole words' - for example, a search for 'shot' will not locate occurences of 'imds_shot'
- By default, comment lines are not searched.
The file selection implemented in progsearch is unchanged. The argument parsing was rewritten to accomodate extra arguments, and the searchgrep script now calls a perl script sgrepf2.pl, which executes the grep command, identifies the output lines which correspond to a Fortran statement containing the search string, and then uses the perl module FtnStmt.pl to print only those lines corresponding to statements of the requested type.
The output format is now enhanced, with the search strings ( usually - work in progress..) highlighted.
( See also these examples ) trsearch is invoked by a command of the form
trsearch.csh <target> <str> [<str2> <str3> ] [ [ <key1> <key2> ] [-k] [ <keyn1> <keyn2> ] ]
where
- <target>
- is the name of a Transp executable to be searched.
- <str>
- is the 1st string to be searched for
- <str2> <str3>
- are optional additional strings to search for
- <key1> <key2>
- are optional traditional keywords
- -k
- is an optional flag denote the start of 'new' keywords
- <keyn1> <keyn2>
- are optional 'New' keywords. These may also be given as a single argument, delimited by commas
The traditional progsearch keywords are supported -
- nolib
- Libraries associated with the target code are not searched
- noinc
- Include files are not searched
- nocomment
- Comment lines are not searched
- codesymbol
- No comment lines, no substrings
- codeassign
- Looks for assignment to a symbol ( Cf Lval below )
while FtnStmt supports these additional keywords ( at the time of writing ) -
- IO
- String occurs in an IO list ( = read | write )
- all|any
- display all occurences of String
- comment
- include comment lines ( Df do not.. )
- def_code
- String is defined ( as a procedure ) eg Subroutine, Function, module keywords
- def_var
- String is defined ( as a code symbol ) eg real, dimension, character keywords
- lval|codeassign
- String is assigned to ( occurs to left of = sign )
- other
- String occurs in an unclassified statement
- read
- String occurs in a read statement
- write
- String occurs in a print or write statement
If none of the 'new' keywords are present, then a traditional search ( grep & sfilter ) is performed
trread -h displays help information -
>trsearch.csh -h Help is at hand ?trsearch: required arguments missing - syntax: trsearch <progname> <str1> [strs...] [keyword]" to search program sources for specified strings." At least one search string must be given. trailing argument may be a keyword: keyword = "noinc" to suppress include file searches' "nolib" to suppress library searches' "nocomment" to suppress comment lines' "codesymbol" to suppress comments, substrings' "codeassign" to look for assign statements' 'New' keywords : IO String occurs in an IO list all|any display all occurences of String comment include comment lines ( Df do not.. ) def_code String is defined ( as a procedure ) def_var String is defined ( as a code symbol ) lval|codeassign String is assigned to other String occurs in an unclassified statement read String occurs in a read statement write String occurs in a print or write sta
Known Bugs
- Highlighting of string in output is fragile ( whole word requirement not yet coded )
- Conditional statements are not classified - if(... )
- No warning if statement continuations exceed size of search window
Wishlist
- add more keywords
- library directories containing a file utility.inf not to be searched by default - would provide mechanism to skip portlib, uread etc if not wanted
- Option ''first' to stop search after 1st success - eg if looking for a ( unique ) subroutine definition
- Implement functionality of libsearch, allsearch within trsearch
- keyword to increase size of search window
- multiple search strings - search for all in same pass ( eg grep -e "str1|str2" .. )