Recorded macros have the inherent limitation of playing back one fixed sequence of commands. Often you need a macro to execute repeatedly until some condition is satisfied. This requires that you use flow control statements to govern the actions your macro takes.
All editor functions return a true or false value. The macro flow control operators that use these values are:
Operator | Meaning |
+>label | Branch to label if last function yields TRUE |
->label | Branch to label if last function yields FALSE |
=>label | Branch unconditionally to label |
:>label | Define label |
These rudimentary operators are not as sophisticated as a high-level language's IF statement or FOR loop. They are more like an assembly language's conditional jump instruction. However, they provide the essential capabilities needed for writing loops and other conditional constructs.
If you frequently perform multiple-window editing, a macro that restores the display to a single window can be helpful. Such a macro requires the following logic:
1.Switch to the next window.
2.If the switch is not successful (meaning that only one window is present), end the macro.
3.If the switch is successful (another window is present), close that window and go back to step one.
This macro will be called CloseWindows and assigned to SHIFT+CTRL+W.
·To create the CloseWindows macro:
1.From the File menu, choose All Files.
PWB displays the All Files dialog box.
Notice that your TOOLS.INI file is in the list of open files, even though you did not explicitly open it. PWB opens TOOLS.INI to load its configuration information (unless when you specify /DT on the PWB command line).
2.Select TOOLS.INI file in the list of open files.
3.Choose OK.
PWB opens a window and displays your TOOLS.INI file.
4.Find the section of TOOLS.INI that begins with [pwb]. This is the section where PWB keeps its startup configuration information.
5.In the PWB section, type the following two new lines:
CloseWindows:= :>Loop Openfile -> Meta Window Window =>Loop
CloseWindows: SHIFT+CTRL+W
If you want these definitions to take effect immediately, select both lines and press ALT+= to execute the Assign function. You can also assign the definitions one at a time.
6.Choose Save from the File menu to make this macro and key assignment part of your TOOLS.INI file.
The next time you start PWB, the CloseWindows macro is defined and assigned to the SHIFT+CTRL+W key.
The first line you typed uses the := operator to associate the macro definition with the name “CloseWindows.” After the operator is the list of functions and macro operators that specify what the macro is to do. The second line is a separate statement that uses the : operator to assign the macro to the SHIFT+CTRL+W key.
The CloseWindows macro works as follows:
1.:>Loop defines a label called Loop. There cannot be a space between the :> operator and the label name.
2.Openfile switches to the window under the active window.
3.The -> operator examines the return value from the Openfile function. If the function returns false because there is no other window, the -> operator exits the macro.
4.The phrase Meta Window closes the active window.
5.Window returns to the window you started from.
6.=>Loop unconditionally transfers control back to the Loop label and starts the sequence again.
When this macro is defined, you can press SHIFT+CTRL+W whenever you want to close all windows except the active window.