Less and WINLOCUtilities to make life easier for users |
|
From "Migration", Access to Wang, February 1995 |
|
[ Prior Article ] [ Return to the Catalog of articles ] [ Next Article ] |
Some of the most important elements of a system user's life are subtle. Consider the value of a good display utility: no one notices how the Wang DISPLAY utility seamlessly moves between all types of files, changing its behavior to meet the requirements of the file type or the desires of the user.
A change in operating environment can severely challenge your assumptions. The move to Unix was shocking to our development staff in the loss of some functionality, in addition to gaining in other areas. File display options remain somewhat elusive, but the less file display utility has solved much of the immediate need. The following is a description of less and its use.
Displaying the contents of files is a common activity for programmers, system administrators, and technical users. Most versions of Unix provide the more utility for some of this need, and other display programs (pg, view, etc.) may also be included. None of these tools provide all of the features required by technical users, including:
Display binary files without destroying a terminal session by interpreting non-text elements as screen control characters (e.g. "raw mode").
The ability to move forward and backward within a file.
Search capability across multiple files.
The capability of alternately "wrapping" long text lines (so all portions of the line are visible) or "truncating" the line (so that the lines are more readable).
The capability of accepting ambiguous (wild card) file specifications or Standard Input.
Access to other utilities from within a display, including a file editor.
In response to these and other desires, the less utility was created in the mid-1980's by Mark Nudelman and subsequently ported to MS-DOS by Mark Lord. Its name is a play on more ("less is more") and it can be used in all instances where more would be used.
Normally, less is started with the name of the file (or files) to be displayed; e.g. less myfile.txt. It can also accept data through Standard Input (cat myfile.txt | less) or use ambiguous file names (less /tmp/my*). A range of optional characteristics can also be passed to control initial options such as the display format (long lines wrapped or truncated) or the amount of file information displayed at the bottom of the screen. If you frequently use the same set of parameters, they may be inserted into the environment variable LESS and will be used for all sessions. For example, my startup profile includes the statement LESS="-iscS", which is equivalent to typing less -iscS myfile.txt or less -i -s -c -S myfile.txt. These options may also be changed from within the program during the display session. The file display page can be moved forward by pressing f, backward with b; exit the program by pressing q. Pressing h will bring up a help screen with further key explanations. Most key sequences for vi also work, including colon commands (:q to quit, etc.). Like vi, the G key will proceed to the bottom of the file, while g (or 1G) will go to the top. You can go to specific lines by entering the line number, or go to an approximate position by entering a number and the percent sign; for example, to go to the middle of the file, enter 50%.
less provides search capabilities that are similar to those in the vi editor, allowing you to enter simple text or a Regular Expression. Forward and backward searches are supported.
Here are some other examples of uses for less:
Use less as a front-end when editing script files. Search for the area to be changed, then press v to enter vi at that position in the file. When you are through changing the script file, return to display the modified file.
Display a number of files by entering a wild card, then search for text in all of them by entering ESC before entering the search string. Mark the locations of found text with a letter code (using m plus a letter) and return to them quickly by pressing a single quote and the letter (e.g. 'a to return to the a mark).
Use less to display your Unix manual pages. Most Unix systems use the environment variable PAGER to set up the viewer used for system purposes; set this to less and you will be able to go back and forth within manual pages.
Use less to view records as they are written to an output file by displaying a file opened for output the pressing F (proceed forward indefinitely); you will drop to the bottom of the file and see each record as it is written. (This is similar to using tail -f.)
As good as it is, less is still missing a few things, including:
A Windows version ("WinLess"?) with support for drag-and- drop file specification.
Text/hexadecimal display a la LIST.COM.
The ability to scroll right on long lines.
Support for predetermined file markers that can be loaded with the file.
A version for the Wang VS.
One of the growing problems we faced as PCs began to replace Wang workstations was the need to support Wang function keys without expensive Wang keyboards or requiring end users to learn cryptic alternate key sequences. We used a number of approaches, including VT100 terminal products with key remapping and function key "cheater" strips attached to the keyboard, and changes to the applications. In most cases, we gave up and purchased Wang keyboards, sacrificing cost and future compatibility for current need.
WINLOC 3.1 (Wang's terminal emulator for Windows) has many amenities that make it attractive to all users (see Access to Wang, April 1993), including pull-down menus for Wang PF keys and Word Processing commands that can be used in lieu of a Wang keyboard. This standard configuration did not meet our needs for these reasons:
The DP keyboard menu did not provide "accelerator" keys that would allow its easy use without the mouse. (Accelerator keys are the underlined letters on a Windows menu that will perform a function from the keyboard in combination with the ALT key.)
The DP keyboard menu did not resemble the physical layout of the keyboard, which would have provided visual clues about its usage.
Our shop - like many others - uses the standard WP editor, not WP Plus, so the word processing commands were different.
An undocumented feature of WINLOC is the ability to tailor these pull-down menus to your own needs. By changing this file I was able to consolidate DP and WP functions into a single menu, provide a physical layout similar to a Wang keyboard, add accelerator keys for fast keyboard-only access, and change the program name in the Windows title area. The modified WINLOC.INI file is shown below (see Figure 1); the resulting screen display is shown in Figure 2.
The syntax for this file is similar to some Microsoft products, including Word for Windows macros and Visual basic. Some of the details of this syntax:
The Title= expression sets the program name that will be displayed in the Windows title bar and under the icon when the program is minimized.
Menus are indicated as square brackets denoting section breaks (e.g. [Menu1]). The original WINLOC.INI file had two special menus; this was reduced to a single menu.
An ampersand (&) creates an accelerator key out of the next letter. For example, the expression Title=&Keyboard will set the title display to show Keyboard (note underline).
A vertical bar (|) can be used to break the display into horizontal columns. In the example, this break occurs prior to CANCEL command.
A dash (-) will create a horizontal bar in the menu. These bars have been used to break up groups of four PF key values to simulate the grouping of Wang function keys (e.g. prior to F1, F5, F9, etc.).
As a result of these changes it is now practical to use standard keyboard keys instead of PF keys or the mouse. For example, pressing ALT+K will bring up the keyboard menu; merely press ENTER for PF16, the first value on the display. Similarly, ALT+K followed by H will invoke the Help processor. Other keys can be selected by accelerator key (where such keys are set) or by using the cursor keys to move to the desired value, followed by ENTER to accept the choice.
For those inclined to experiment further, there are many other ways to arrange your WINLOC menus. Try setting up a four-across grouping of the function keys that resembles a Wang keyboard. You could also experiment with multi-key combinations that might function like glossaries. Drop me a copy if you discover something new.
Figure 1: Sample WINLOC.INI File
;========================================================== ; WINLOC.INI ; Wang Local Office Connection for Windows ; Initialization File ;========================================================== ; Modified 6/2/94 (dsb) to include WP keys [Title] Title=Revised WINLOC Settings [Hotkeys] Key1=PF, 0x0000 Key2=ENTER, 0xff1c Key3=RETURN, 0xff1c Key4=EXEC, 0x4f Key5=CANCEL, 0x6e Key6=HELP, 0x6f Key7=NEXT, 0x51 Key8=PFK-1, 0x3b Key9=PREV, 0x49 [Menu1] Title=&Keyboard Key1=F16 (E&xit),0x6D Key2=&Help,0x6f Key3=-F1 &Indent,0x3B Key4=F2 &Page,0x3C Key5=F3 Cen&ter,0x3D Key6=F4 &Dec Tab,0x3E Key7=-F5 &Format,0x3F Key8=F6 Mer&ge,0x40 Key9=F7 &Note,0x41 Key10=F8 Stop,0x42 Key11=-F9 &Search,0x43 Key12=F10 &Replace,0x44 Key13=F11 &Copy,0x68 Key14=F12 &Move,0x69 Key15=-F13 C&ommand,0x6A Key16=F14 Subscript,0x6B Key17=F15 (blank),0x6C Key18=F16 Go To,0x6D Key19=|C&ancel,0x6e Key20=Exec,0x4f Key21=-F17 ^Indent,0x54 Key22=F18 ^Page,0x55 Key23=F19 ^Center,0x56 Key24=F20 ^Dec Tab,0x57 Key25=-F21 ^Format,0x58 Key26=F22 ^Merge,0x59 Key27=F23 ^Note,0x5A Key28=F24 ^Stop,0x5B Key29=-F25 ^Search,0x5C Key30=F26 ^Replace,0x5D Key31=F27 ^Copy,0x5E Key32=F28 ^Move,0x5F Key33=-F29 ^Command,0x60 Key34=F30 Superscript,0x61 Key35=F31 ^(blank),0x62 Key36=F32 ^Go To,0x63
Figure 2: Sample WINLOC Screen (with modified WINLOC.INI file)
Copyright © 1995 Dennis S. Barnes
Reprints of this article are permitted without notification
if the source of the information is clearly identified