| Front Page | News Headlines | Technical Headlines | Planning Features | Advanced Search |
OmniSolutions Sponsor Message

     

Searching for Strings

By Shawn M. Gordon

Inside VESOFT covers tips and techniques you can use with VESOFT’s products, especially MPEX. As always, I am totally open to getting input from you users of MPEX, Security/3000 or VEAudit/3000 — it helps me learn, too. Send me your tricks, and we’ll get a “3000 for 2000” cap out to you as our thanks.

There are three distinct PRINT commands within MPEX that support searching for strings (among other things), and several functions that will work within the context of other commands. Most people know how to use %PRINT@.SOURCE;SEARCH=”VARIABLE”, but we can get much more sophisticated than that. First let’s start out with some of my personal favorites, but keep in mind that all the various SEARCH criteria are available for each of the commands.

The PRINTO command is very useful. It is meant to be shorthand for looking at spoolfiles. The selection criteria can be either the DFID number or the job number. By using the keyword WAIT on an open spoolfile, you will see your display pause and wait for the spoolfile to generate more text. The update seems to be every couple of seconds, and it’s a very useful way for doing real time tracking of an executing job.

A couple of relatively recent extensions were added to PRINTO that are especially useful: the keyword IFLOW and the search parameters IFTRUE and IFFALSE. If you specify IFLOW, as in %PRINT #J123;IFLOW, then the false portion of any conditional logic in the job will display at low intensity, so you can easily distinguish what got executed within the job.

You can take this concept even further by using %PRINT #J123;SEARCH=IFTRUE or IFFALSE. What this will do is totally eliminate the false or true (respectively) portion of the job from display, so you only have to deal with the pertinent parts of the job.

The companion to this is PRINTI, which will print the input job stream. This is usually handy for looking at a job that is scheduled or in a WAIT state — and you want to know what it is going to do. You can reference it by either the #I number or the job number.

There are some very cool parameters that can be specified in conjunction with SEARCH, such as CONTEXT. You could do something like

%PRINT @.SOURCE;SEARCH=’BIRTH-DATE’;CONTEXT=2,3

This will print two lines before and three lines after the text that is found. You can extend this with the PREV keyword. Say you are programming in Pascal or C and want to find variable names that are within specific functions:

%PRINT @.SOURCE;SEARCH=”CUSTNUM”;PREV=”PROCEDURE” or “FUNCTION”;NUM

——-Printing MYPROG.SOURCE

11.5 PROCEDURE ERRORPROC (VAR F: INTEGER;

15 WRITELN (CUSTNUM:10, ‘ NOT FOUND!’);

922 FUNCTION COPYREC (VAR FILE: TSTRING): BOOLEAN;

939 IF CUSTNUM<>’XXX’ THEN

992.44 CUSTNUM:=’’;

You can get really crazy with this stuff and embed expressions within the CONTEXT parameters, such as:

%PRINT MYFILE;SEARCH=”CUSTNO” or “CUSTNUM”;&

CONTEXT=(“PROCEDURE” or “FUNCTION”), (R[0:3]=”END”)

Here, MPEX will find all the lines containing the string “CUSTNO” or “CUSTNUM.” It then prints all the lines from the immediately preceding line that contains either “PROCEDURE” or “FUNCTION” and until the immediately following line that contains “END” as its first three characters.

Now the SEARCH engine itself is also generally available within some other functions, namely FSEARCHSTRING, FCONTAINS, and FSEARCHEXP. This means that you can use file content criteria in functions such as COPY, PURGE, ALTFILE or LISTF. There is a tremendous amount of power with this.

FSEARCHSTRING(S) [INT] returns the number of lines containing the string S in the text of the current file:

%LISTF @.SOURCE(FSEARCHSTRING(‘FOO’)>0)

This finds all the files in the SOURCE group which have one or more lines containing the string ‘FOO’.

FCONTAINS(S) [BOOL] returns TRUE if the string is in the file. For example, %LISTF @.SOURCE(FCONTAINS(‘FOO’)) finds all the files in the SOURCE group which have one or more lines containing the string ‘FOO’. This is equivalent to the example for FSEARCHSTRING, but you don’t include “>0” as part of the selection criteria.

FSEARCHEXP(S) [INT] returns the number of lines that match the logical expression, just like the ones that can be passed to %PRINT ;SEARCH= specified by S. Remember, however, that since in this context S is a STRING, it must be enclosed in quotes:

%LISTF @.SOURCE (FSEARCHEXP(“‘CUST-NO’ or ‘CUST NAME’”)>0)

This will find all files that have at least one line containing either the string ‘CUST-NO’ or the string ‘CUST-NAME’.

In fact, S can include (in addition to the logical expression used by ;SEARCH=) any of the MPEX %PRINT parameters (although not all of them are useful in this context).

%LISTF @.DOC.PROD(FSEARCHEXP(“CL’blue ox’;MAX=2”)=2), 3 shows you the create/restore/modify/access dates (“,3”) of all the files in the DOC.PROD group that contain at least two occurrences of the string “blue ox” (upper- or lowercase), and stops searching each file after finding two occurrences of the string.

Check out the HELP for PRINT; there are tons of nifty tools. I’ve just tried to get your mind thinking about the various possibilities. See you next time.

Shawn Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.  


Copyright The 3000 NewsWire. All rights reserved.