Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 39
Editing a Character String
You can supply multiple commands in the same template by separating the commands
with two slashes. For example:
Editing Commands: An Example
The following sample program features a command interpreter with the ability to accept
an FC command typed by the user. By typing “FC,” the user is given the opportunity to
edit the last command entered.
The example is made up of three procedures:
The main procedure simply calls the INITIALIZE^TERMINAL procedure to open
the terminal and then calls the COMMAND^INTERPRETER procedure.
The INITIALIZE^TERMINAL and SAVE^STARTUP^MESSAGE procedures read
the Startup message, save it in a global data structure, and then open the file
specified as the IN file in the Startup message.
The COMMAND^INTERPRETER procedure prompts the user to enter a
command, which can be up to eight characters long. The procedure converts any
lower-case alphabetic characters to upper case, and then processes the command
itself. If no such command exists, then the program displays a diagnostic
message.
If the user types the FC command, then the COMMAND^INTERPRETER
procedure calls the FC procedure to edit the previous command. The FC
procedure returns 1 after successfully editing the command and the
COMMAND^INTERPRETER procedure executes the edited command. If FC
returns 0 (without successfully editing the command), then the
COMMAND^INTERPRETER procedure prompts the user for another command.
The COMMAND^INTERPRETER procedure exits only when the user types the
EXIT command.
The FC procedure is called by the COMMAND^INTERPRETER procedure when
the user types the FC command. The FC procedure displays the previous
command and prompts the user to enter a template that the FIXSTRING procedure
will use to edit the command. If the user types just two slash characters, then FC
returns 0 to the COMMAND^INTERPRETER. Otherwise the FC procedure edits
the command according to the input.
Once FIXSTRING has edited the command, the FC procedure repeats, offering the
user the chance to edit the new command. The user refuses by pressing carriage
return in response to the FC prompt, which causes the FC procedure to return 1 to
the COMMAND^INTERPRETER procedure.
Before string: fup filea,filrv
Template: idup // rec
After string: fup dup filea,filec