VS Functionality in UnixImitated, never duplicated |
|
From "Migration", Access to Wang, January 1994 |
|
[ Prior Article ] [ Return to the Catalog of articles ] [ Next Article ] |
One of the most powerful aspects of the VS environment is its tools. Powerful, easy-to-use utilities have been a part of the Wang environment from the start. Most of these programs have a consistent appearance and similar operation, making them easy to learn, and most can be run interactively or under program control. When run interactively, the user is guided through the parameters through entry screens, help text, and other reminders.
Unix also has a long history of tools; indeed, it sometimes appears to be nothing more than a collection of small utilities. Unix tools show have large differences in use and philosophy: most have no provision for screen entry and nearly all perform only one specific function. There are several reasons for these differences:
Unix tools were developed over a period of twenty years by many authors.
Unix utilities are designed to be connected together to form larger applications; it is expected you will have to create your own tools using these "building blocks." VS utilities attempt to cover all possible uses within a single program.
The VS has only a few types of terminals and all have the same dimensions (24 rows, 80 columns) and character set, making it easy to design screen-oriented applications. Unix users use a myriad of terminal types whose characteristics can vary widely, so screen applications are difficult to create.
To illustrate these differences, I have selected three Wang utilities - COPY, DISPLAY, and CREATE - and matched them with similar functions in the Unix environment. As you'll see, there are powerful benefits to creating your own tools within the Unix environment.
The most likely replacement for the Wang COPY utility is the Unix cp utility. cp accepts the names of input and output files and creates similar files. For example, cp file1 file2 would copy file1 to file2. Wild cards can also be used; cp file* /usr/lib/files would copy all files beginning with "file" to the directory /usr/lib/files.
Like the MS-DOS COPY function, cp happily overwrites existing files with the same name unless you go to some trouble to avoid that by passing an optional argument; this is sometimes referred to as the noclobber option. Other options include one to copy all files in the directories below and another to preserve the date, time, and security profile of the original file.
Another file copy tool is the dd utility, which is primarily intended to write files to tape. dd can be used to perform conversions, including character case conversions, ASCII to EBCDIC conversions, and others. Unlike cp (and most other Unix tools), dd does not have the usual input and output argument; instead, it assumes that incoming information is sent through Standard Input and output information returned through Standard Output. To copy a file from one to another with a conversion to upper case, enter dd conv=upper < file1 > file2. (The left- pointing arrow indicates the name following is Standard Input, the right-pointing arrow, Standard Output. This notation is similar to other operating systems, including MS-DOS.)
Other copy tools include cpio, tar, and vendor-specific backup utilities like HP's fbackup. All of these tools are intended for backup purposes and do not create an output file with the same organization as the input file. Instead, multiple files are merged together into a single file and written to the output medium.
It's important to note that there are no provisions in Unix for files to be locked during file processing, so you must be absolutely sure that the file is not in use or risk a poor copy if the file is modified during the copy.
The Wang DISPLAY utility is a remarkable piece of work. It is capable of displaying any VS file type in a variety of formats (record, block, data, hex). It can retrieve records based on index values and print all or part of a file. There is nothing comparable in any other environment I have seen - including Unix.
Much of the problem in displaying Unix files lies in the limited types of files Unix understands. As I discussed in the September column, Unix knows about only a few different file types and relies completely on the application to extract and use information from any other file type. Indexed files - directly supported by the VS operating system - are considered "applications" under this philosophy. Thus, it would be impossible to develop a truly universal file display tool for Unix systems.
However, there are some powerful display tools in the Unix environment, particularly if you work with text files. The more utility is an example: it accepts the name of a file and displays it page by page. (Some versions of Unix include a utility called pg that performs much the same function as more.) more is similar to the MS-DOS tool of the same name, except it can be run directly as well as through standard input. For example, entering more /etc/passwd will display the password file; typing cat /etc/passwd | more will also display the password file by dumping the contents of the file to Standard Output, which is then piped to more as Standard Input.
Since almost all versions of Unix have more or pg they are sure bets if you need to display text files. Their limitations include poor support for non-text file contents and page movements in one direction only. The less utility handles all of these needs and more (pun intended). less is a commonly- available replacement for more that allows movement up or down in a file and can display the contents of binary files. Like more and pg, it can accept wild-card file specifications and display multiple files in sequence; unlike either, it allows you to return to files displayed previously and search for text strings across multiple files. Other features include: bookmarks to note places to return; a multitude of display options that include the ability to "squeeze" text files so multiple blank lines are reduced to one; powerful search capabilities that allow use of Regular Expressions (industrial-strength wild cards); and the ability to position the viewer by record number or percentage of file size. Enter less /etc/passwd to display the password file. To find out what groups user uid belongs to, try grep uid /etc/group | less -S; the -S option chops the display so the lines are more readable.
less is available from a variety of sources. Drop me a line at one of the addresses listed below if you are interested in a copy and can't find it through other sources. Versions are available for Unix and MS-DOS systems.
One of the other gems in the VS utility collection, CREATE is too broad to consider replacing with a single tool. Instead, each likely use of CREATE must be considered separately. Possible uses include:
Extracting selected records from one or more files and combining them into a single output file.
Creating empty files.
Extracting selected columns of data from one or more files.
Establishing new index paths in a file.
As before, Unix systems do not understand any indexed file form so it is usually necessary to convert indexed files to consecutive format ("unload" the files in the parlance of some vendors) before applying Unix tools to them. Similarly, any indexed output must use product-specific utilities to perform this indexing. Look for vendor-supplied tools for these purposes. Note that consecutive files are not text files any more than a consecutive file containing binary packed decimal data elements is a text file; it is sometimes necessary to write a program to present data elements in a display format.
After getting around the problem of indexed file support, there are many Unix tools for text file manipulation. Records can be searched and selected using the grep tool, a pattern-matching utility that returns lines that match its specification to Standard Output. Columns of data can be extracted using the cut and paste commands; column specifications can be in the form of character position on a line (for fixed-length fields) or the column number (for variable-length fields). The head command displays the first rows of a file, while the tail command displays the last.
Complex text manipulations are also possible with the awk language, which was created for text scanning and conversion. A less powerful tool for similar purposes is sed (the "stream editor"), which can search for strings and convert their values using a set of rules. Both of these tools replace the functions of CONVERTC in the Wang environment.
One disadvantage of Unix is that you must wade through all of the possible means of accomplishing a task to find the methods that works best for you. One advantage is that you can tailor this solution specifically to your needs. All of the Unix tools discussed can be connected using script languages or C to form powerful tools for your environment. It can pay to be a tool maker.
UNIX Communications
Bart Anderson, Barry Costales, & Harry Henderson
SAMS, Carmel, Indiana; 1991
ISBN 0-672-22773-8
Large collection of information on Unix communications, including internal and external forms. Covers mail systems, file movement between systems, news, file archiving systems, and terminal utilities. Assumes little familiarity with Unix to begin.
Copyright © 1994 Dennis S. Barnes
Reprints of this article are permitted without notification
if the source of the information is clearly identified