[Access to Wang masthead]

Search Tools Revisited

Want more power and flexibility? Look to UNIX

From "VS Workshop",  Access to Wang, February 1993
  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

Many programmers I talk to are busy studying their code, either for normal maintenance purposes or for a larger purpose - such as a redesign or major system revision. The informational expectations of business users everywhere are changing rapidly, fueled by the personal control personal computers and data base products have given them.

Of course, a large amount of effort has been expended into your current source files, and this investment should be treated with some respect. The sudden rise of COBOL's popularity in the face of newer, "cooler" languages is a testimonial to the power of the program modernization and re- engineering fad sweeping many businesses.

If you have more than a few programs, and more than a few programmers have worked on them, you will probably find it necessary to make some high-level assessments of your program code. Typically this means tiresome repetitive searches across entire libraries - searches for multiple variations on a string's format as well as for multiple strings. And if your plans call for revisions, it may be necessary to use the generated search information manually, tediously editing information by hand.

If you need to unlock some of the secrets in your source code, here are a few ideas for ways to make it easier.

The new FINDTEXT

The FINDTEXT search tool - available from the United States Society of Wang users in their USERAIDS package - has been covered in this column before, such as in March 1989. Like prior versions, it searches entire libraries or selected files only, searches any file type, works in foreground or background, shows results on the screen or in a report, and works rapidly. Version 2.99.03 from USSWU adds a few interesting features:


ENTER INPUT   LIBRARY  = &SRCHLIB,
              VOLUME   = &SRCHVOL,
              SELECT   = NO
ENTER OPTIONS TEXT     = &SEARCH,
              MODE     = PRINT,
              CASE     = YES
ENTER INPUT

The remainder of the procedure will work fine.

In short, FINDTEXT is a good choice for searching for explicit strings, particularly in background. But what if you wish to search for information only partly known or wish to convert located strings to others?

Find and convert with CONVERTC

CONVERTC is a unique tool in the VS environment, and it has many applications. It can be used to search for multiple strings, with combinations of known and unknown elements. Located strings can be translated into others and a new file created. The parameter files used by CONVERTC can be used for future conversions or as documentation for the converted code. Drawbacks to CONVERTC include its sluggishness and inability to be run in background or under complete program control in foreground.

A simple search example: search for multiple strings by adding single- quoted literals (search strings) on the left (search) side of the parameter file and a pound sign (#) to print the found lines on the right (action) side.

If you wish to search for information that is not complete CONVERTC offers search criteria that may use the question mark as a wild card. For example, the search string ' D'?'-LINE.' will return D1-LINE, D2-LINE, D- LINE, and any number of other strings. Searches may also be conducted within column specifications - though these are the most unreliable searches offered by CONVERTC.

CONVERTC also offers interactive editing of found lines when the ampersand character (&) is used on the action side. When the search string is found, the line is displayed for modification with sufficient room to add lines below. Lines immediately above and below the found string are also shown as an aid to understanding the context.

One of the most interesting features of CONVERTC is the area change toggle commands. Areas of a file can be "fenced" so that changes only occur within these areas. For example, to change elements in the DATA DIVISION of a COBOL file perform the following steps:

This type of selective conversion is very powerful, and CONVERTC might be considered the best conversion tool available for the VS - if it worked completely. Be sure to test the converted code carefully, since CONVERTC overlooks items to be changed and may introduce false elements in the output code. (For additional information on CONVERTC see this column in the April 1992 issue of Access to Wang.)

Visitors from other worlds

As good as the tools above are - and other good VS tools are available - I have begun to gravitate to the grep, sed, awk and other tools most commonly available within UNIX environments. The power and flexibility of these search and modification tools is due to the use of a common search specification nomenclature known are Regular Expressions. Here are some of the elements of Regular Expressions used for search purposes:

CharacterMatch value
 . (period) Matches any single character
 [abc] Matches a, b, or c
 [a-z] Matches any character in the range a to z (e.g any lower-case letter)
 [^e] Matches any characters not in the set
 ^ Matches the beginning of a line of text
 $ Matches the end of a line of text
 a|b Matches either expression a or b
 * Matches zero or more cases of the prior element
 + Matches one or more cases of the prior element
 ? Matches zero or one case of the prior element

As you can see, the wild card elements are considerably more advanced than those used by PC or VS file specifications. Correct use of them requires some practice and a willingness to type out commands like this without laughing:


awk -F: 'BEGIN {OFS="\t"}
{print $1, $3, $4, $6}' /etc/passwd

(This awk script lists a UNIX password file in easily-understood columns - not in its native form, which is nearly unreadable. The example is from UNIX Programmer's Reference by John Valley (Que, 1991).)

The awk and sed programming languages can be used to convert source code and other information into a new form; they are powerful tools but are generally available only on UNIX systems. grep (a.k.a. egrep or fgrep) is a search tool, and versions are commonly included with MS-DOS language tools. grep and its derivatives are all fast non-interactive search tools that offer real power in locating text fast. I often transfer VS source files to the PC or UNIX environments to take advantage of these tools.

If you are interested in working with any of these tools and don't have a UNIX system near you, you can get some of their functionality in PC tools that are available from commercial and shareware sources. PC versions of the awk language and other UNIX tools are available from MKS ((800) 265-2797). Simpler versions of the other tools can be had for the PC through the PiCnix toolset, available from PC bulletin boards or directly from the author (Peter Stephen Heitman, P.O. Box 668, Hadley, MA 01035; $15). Another source of UNIX tools is Coherent, a UNIX-like operating system for the PC that costs $99.95 and includes all of the tools mentioned above (Mark Williams, (800) 627-5967). A version of grep is included with Borland's Turbo C/C++ products for the PC and through other sources.

Let me know if you are interested in further dabblings in tools beyond the VS world for Wang maintenance purposes. The composite of these worlds can work better than either alone.


  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  


Copyright © 1993 Dennis S. Barnes
Reprints of this article are permitted without notification if the source of the information is clearly identified