3 Programming with Eloquence

The character oriented development environment

Starting the character oriented Development Environment

The eloq or eloqcore command used to start Eloquence is executed from the HP-UX prompt. Syntax is as follows:

NOTE: The character oriented development environment is not available on NT platform

Here is an explanation of the options associated with eloq and eloqcore:

-help
Causes the usage screen to be displayed. The usage screen shows the syntax of the command along with the options available. In other words, it shows the basics of how to use the command.
-r[ecord] file name
Records every keyboard action performed by the user and stores it in the specified file.
-p[lay] file name
Plays back the keyboard action in the specified file, previously recorded using -r file name.
-n[otask]
Only applicable for the eloq command. This option disables Eloquence programmatic task processing. In other words, the tasking statements REQUEST #, ATTACH #, DETACH, and RELEASE # are disabled. Note that this option does not disable HP-UX background processing.
-t[race][level]
Causes a trace to be performed on the specified program. If no program name is specified, a trace is performed on any program run in the Eloquence environment. Levels available are 0 (default)= trace lines, 1 = trace explicit assignments, and 2 = trace all assignments. Refer to page 282 for more information.
-sfa
Activates the statement flow analyzer (SFA). The SFA records which statements have been executed and the execution time for each statement within a program.
-taskid #
Starts a specific HP-UX process as the primary task. Replace # with the desired taskid number.
Notice that you can specify either eloq or eloqcore. eloq is an interface to eloqcore; therefore, using eloqcore is slightly faster. The advantage that eloq has over eloqcore is that it allows you to use the Eloquence tasking statements--REQUEST #, ATTACH #, ATTACH, DETACH, and RELEASE #.

Executing the eloq or eloqcore command by itself starts the Eloquence program and causes a blank screen to appear. At this point, you are in the Eloquence development environment. You may create, edit, or run applications. To exit Eloquence and return to the HP-UX environment, type QUIT and press RETURN.

Specifying a program name along with the eloq or eloqcore command (for example, eloq ABC) causes the program specified to be run in the Eloquence environment. Once the program has completed, control returns to the HP-UX environment.

Input Redirection

You can use input redirection, as follows:

Example:

eloqcore program name input file name
and you can "press" a softkey by entering a line such as

:KEY#4
in the input data file.

Quitting Eloquence

The QUIT command terminates Eloquence, but gives a warning if a program has been modified but not stored, and gives you the alternative of cancelling.

The QQUIT command terminates Eloquence without giving such a warning.

QUIT and QQUIT do not check for "secondary" tasks.

Program Execution and Edit Commands

The following commands help you enter, run, and edit programs. It is important to note that these commands are only available when running the character oriented development environment. This is not intended to be a complete list of all development environment commands and statements. These are simply the specific commands to run and edit a program. For more information on storing and retrieving files, refer to page 195 and page 36 later in this chapter.

All these commands except list and store (lower case) are executed from within Eloquence. The list and store commands are executed from the HP-UX prompt. To execute a command, type it on the terminal and press RETURN.

The development commands are:

RUN
Runs an Eloquence program.
CONTINUE
Continues running a program.
AUTO
Automatically numbers lines.
REN
Renumbers program lines.
DEL
Deletes one or more program lines.
FETCH
Displays one program line for editing.
HOP
'Advanced step' functionality
LIST and list
Displays or prints a list of program lines.
[RE-]STORE and store
Syntax checks the current program or an ASCII text file and converts it to an Eloquence program file.
INDENT
Indents all program lines and structured constructs. Refer to page 161 for a full description of this command.
All development commands except DEL can be executed from the keyboard but not from a program. For the most part, other Eloquence operations are stored in a program line or executed from the keyboard.

Parameter Values

The syntax rules used in this manual are listed under page 16 , and a complete list of terms and definitions are in the glossary. However, the following three terms are so often used as parameters that they are given here as well:

line number
An integer from 1 through 32767.
line label
A unique name assigned to a program line. It can contain up to 15 alphanumeric characters including the underscore. The first character must be a capital letter. The line label is separated from the line number by one or more spaces and must be followed by a colon.
line id
A program line can be referenced by either its line number (GOTO 150) or line label (GOTO Routine). Using line labels allows your code to be moved and is a useful program documentation tool.

The RUN Command

The RUN command is used to load and run a specified program. Syntax for this command is as follows:

RUN [file specifier [,line id] ]

The file specifier is a string expression containing the file name and, optionally, the volume specifier as described in page 195 . The optional line id specifies a starting line number. Program files (files with the extension .PROG) can be loaded and run in this way. For example, RUN "START" loads and runs a program named START.PROG. RUN "START",50 loads and runs the program named START.PROG beginning at line 50. For more details on file operations, refer to page 195 .

If the program to be run is already in memory, it is not necessary to specify the file specifier. In this case the following syntax is appropriate:

RUN [line id]

RUN clears all the variables in a pre-run initialization and then begins execution of the program lines. The optional line id references a line in the main program and specifies that execution is to begin at that line. Omitting the line id causes execution to begin with the first line in memory. For example, executing RUN 150 causes execution to begin with line 150.

A complete list of the pre-run default conditions can be found in page 383 .

The CONTINUE Command

Program execution, if suspended, may be resumed with the CONTINUE command. (Program suspension occurs if a PAUSE command is encountered or if BREAK or CTRL Y is pressed.)

If the optional line id is not specified, execution resumes with the next program line to be executed. No pre-run initialization occurs with CONTINUE.

The AUTO Command

The AUTO command allows lines to be numbered automatically as they are entered and stored.

AUTO [beginning line number [,incremental value ] ]

If neither parameter is specified, executing AUTO causes line numbering to begin with the last line number in memory plus 10 and is incremented by 10 as lines are stored. The optional beginning line number and the incremental value must be positive integers from 1 to 32767. For example, executing AUTO 5,5 causes numbering to begin with 5 and increment by 5.

Automatic line numbering remains in effect until DELETE LINE is pressed or a program line is executed.

The REN Command

The REN (renumber) command causes program lines in memory to be renumbered.

If no parameters are specified, all lines in memory are numbered in intervals of 10, beginning with 10. For example, REN 100,5 causes program lines to be renumbered in intervals of 5, beginning with line 100 (resulting in 100, 105, 110, and so on). All line references in the program are automatically adjusted as the lines are renumbered.

The DEL Command

The DEL (delete) command is used to delete a line or section of a program.

DEL first line id [,last line id]

NOTE: DEL is allowed as a program statement; however, references to line labels must be local to the current environment (main program or subprogram).

Specifying one line identifier causes only that line to be deleted. Specifying two line identifiers causes that block of lines to be deleted. For example, to delete line 40 and lines 100 through 150 from a program, execute DEL 40 and DEL 100,150.

The DEL SUB statement is available for deleting subprograms, as described in page 177 .

A program statement also can be deleted by re-entering only the program line number.

The FETCH Command

Use the FETCH command to bring to the display for editing any program line in memory.

FETCH [line id]

When a line id is not specified, the current line is displayed. If the specified line does not exist, the next-highest numbered line in memory is displayed. If there are no lines beyond the specified line, the highest numbered line in memory is displayed. For example, to fetch line number 300, execute FETCH 300.

To fetch the highest line in memory, execute FETCH 32767.

If no program line is active and no line id is specified, the first line is displayed.

FETCH, like LIST, outputs as default to the system printer, unless system printer 8 (display) has been specified.

HOP key

The HOP command provides the same functionality as the 'advanced step' softkey on system softkeyset. In addition of entering the HOP statement in order to execute a 'step over' or 'advanced step' operation during program debugging, you may press ^G (ctrl-G).

LASTLINE

The LASTLINE keyword does return the last line number used in current program.

This makes it more convenient, to dynamically load subprograms or functions below the end of the program.

For example:

LOAD SUB "SUBX",LASTLINE+1,1

The LIST and list Commands

Two "list" commands are available in the development version. One is used in the Eloquence environment (LIST), the other in the HP-UX environment (list).

Both commands can produce a listing of a program; however the following tasks can only be done by one of the commands:

NOTE: Both commands are usable only on Eloquence program files (not .DATA, .FORM, or .ROOT files).

From Within the Eloquence Environment

The LIST command (upper case) is used to obtain a listing of the program or a section of the program currently in memory. The listing is output on the device specified as the system printer (the display is set to be the system printer when Eloquence is started). Syntax for the LIST command is as follows:

If no parameters are specified, the entire program in memory is listed. If one line identifier is specified, the program is listed from that line to the end. If two line identifiers are specified, that segment of the program, including beginning and ending lines, is listed. If a string is specified, the program lines containing that string are listed.

For Example:

LIST
Lists the entire program.


LIST 50
Lists the program beginning with line 50.


LIST 200,250
Lists lines 200 through 250.


LIST "ABC"
Lists all lines containing the string ABC.


LIST "ABC";50
Lists all lines beginning with line 50 that contain the string ABC.


LIST "ABC";200,250
Lists all lines from 200 through 250 that contain the string ABC.


LIST 50;20
Lists the 20 lines starting at line 50.

To output LIST to a device other than the display, first specify the device via the SYSTEM PRINTER IS statement. Syntax for this statement is as follows:

All successive system printer output is now directed to the device specified rather than the display (printer number 8). Execute LIST to output a listing of the program. For example:

SYSTEM PRINTER IS 0
LIST
To redefine the display as the system printer, execute SYSTEM PRINTER IS 8. Executing SCRATCH ALL also returns output to the display, as does exiting and reentering Eloquence or the HP-UX operating system. See page 249 for more details on SYSTEM PRINTER IS and other printer options.

Within the HP-UX Environment

The list command (lower case letters) is used to obtain a listing of a program, to cross-reference check a program, or to convert a program file (.PROG) to an ASCII text file. The "list" command is executed from the HP-UX prompt. Syntax for the command is as follows:

The following options are available:

-l
Lists the specified program to the standard output device. This is the default unless the -x option is specified.
-n
This option causes no line numbers to be listed, unless referenced.
-x[lcvs]
This option does a cross-reference check on the specified file. Options for -x are l (labels and line numbers), c (constants), v (variables), and s (subprograms and functions). The default is for all the -x options to be set. Refer to page 284 for more information.
program name
Replace program name with the name of a program file.
password
If the program was stored in protected mode, then the program can be listed only, if the correct password is supplied.
user-defined file name
The user-defined file name can be any name that conforms to HP-UX naming conventions. This file will contain ASCII text.
With the "list" command it is possible to convert an Eloquence program file to an ASCII text file that can then be changed using an editing program (for example, vi). This is done by making use of the >user-defined file name option. Once edited, the "store" command can convert the ASCII text file back to an Eloquence program file.

For example, the following "list" command converts the Eloquence program file ABC.PROG to an ASCII text file named abc.txt:

list ABC >abc.txt
At this point, the ASCII text file abc.txt can be edited using the vi editor. Once editing is completed, abc.txt is converted back to an Eloquence program file using the "store" command:

store -o ABC abc.txt

The [RE-]STORE and store Commands

The purpose of the store command is to do an Eloquence syntax check on an ASCII text file and convert it to an Eloquence program file. The store command is executed from the HP-UX prompt. Syntax for the command is as follows:

Here is an explanation of the available options:

-help
This option causes the usage screen to be displayed. The usage screen shows the syntax of the command along with the options available. In other words, it shows the basics of how to use the command.
-o file name
This option is used to specify an output file name. If not specified, the input file name will be used. Whether the output file name is specified or not, the extension .PROG is automatically added to the file name. (Note that this option must be specified if reading from stdin.)
-n
This option specifies that an output file not be created; however, the syntax of the input file is still checked.
-v
This option causes the lines of the file being stored to be output to the standard output device. Normally this is the display.
-s
This option activates SPACE DEPENDENT mode. Refer to page 51 for more information.
-t wdth
tab width (default is 8, 0 = off)
When editing your programs in an HP-UX editor (like vi) rather than the integrated Eloquence editor, tab characters provide a convenient way to format your source code.
Tab characters in the source code caused a syntax error. When specifying a tab width, all tab characters read from input file are replaced by the appropriate number of spaces. A zero tab width will disable tab expansion.
This may also be controlled by the $TAB directive.
-f lno
first line number (default is 1).
When no line numbers are included in source code, store will provide its own, starting with 1.This commandline switch makes it possible to define the first line number to use for automatically generated line numbers. This may also be controlled by the $LINE directive.
-i inc
line number increment (default is 1)
This commandline switch makes it possible to define the increment, used for automatically generated line numbers.
This may also be controlled by the $LINE directive.
-e
If the -e commandline argument is present, store will output error messages is a format more suitable for automatic processing.
input file
Replace input file with the name of the ASCII text file to be converted to an Eloquence program file. It is also possible to replace input file with a hyphen (for example, store -o ABC -). Specifying a hyphen (-) as the input file will force reading from the standard input device (stdin). If this is done, -o file name must also be specified; otherwise, the store command will not know where to put the data it reads from the standard input device.
password
The program can be secured against listing and re-storeing by supplying a password
If the -e commandline argument is present, the error message will be of the following format:

   store: "file.in", line 1: IMPROPER STATEMENT
   ^      ^          ^       ^
   |      |          |       The error message
   |      |          The line number of the input file
   |      The name of the input file or stdin if read from stdin
   To indicate it's a message from the store utility
For example:

Put the invalid statement below in a file named "file.in":

   STOP HERE
Without the -e commandline argument, store will output the following error message:

   STOP HERE
        ^
   IMPROPER STATEMENT
   store: "file.in", line 37
With the -e commandline argument, store will output the following error message:

  store: "file.in", line 1: IMPROPER STATEMENT
To explain the store command, suppose you create an ASCII text file using the vi editor, and it contains the sample program shown in this chapter under page 44 . Also suppose the name of the ASCII text file is games.txt. The next step is to check the syntax of the ASCII text file and convert it to an Eloquence program file. This is done by issuing the following command:

  store games.txt
Notice that no output file is specified; therefore, the input file name (games) is used to create the Eloquence program file (games.PROG). This program file is now ready to be run.

NOTE: If a variable contains the linefeed character, the store command cannot proceed.

The following "store" command also could be used:

   store -o GAMES games.txt
The resulting Eloquence program file is GAMES.PROG. Notice that the .PROG extension is automatically added. If GAMES.PROG had been specified as the output file, the result would have been GAMES.PROG.PROG, so do not include the .PROG extension when specifying an output file.

Directives

The following directives, if included in the source code, make it possible to control the behavior of some store options within the code.

$TAB wdth

This will define a different tab character handling.

For example:

$TAB 8

Sets the tab expansion to 8 for subsequent source lines.

$LINE fline,inc

Defines a different automatically generated line numbers.

For example:

$LINE 1000,10

Presets the next automatically generated line number to 1000 and the line increment to 10.

$LINE 1000

Presets the next automatically generated line number to 1000 and the line increment to 10.

Using store with the C preprocessor

The C preprocessor is a macro processor which provides the following functionality:

Using the C preprocessor with Eloquence makes it possible to use the preprocessor functionality.

For example:

   ! This is a sample program Eloquence program using the
   ! C preprocessor
   #define MAXLOOP 10
   SUB Sample(INTEGER Partno)
   ! include the common block
   #include "common"
   ! The subprogram body
      DBASE IS Db$
      IN DATA SET "PARTS" USE REMOTE LISTS Part_1
      DBGET(Db$,"PARTS",7,S(*),"@",Buf$,Partno)
      ...
      FOR I=1 TO MAXLOOP
         ...
      NEXT I
      ...
   ! include the definitions for PARTS
   #include "PARTS"
   SUBEND
To make this a Eloquence PROG file, you could use the following command line:

   cc -E sample | store -o SAMPLE -
The C preprocessor replaces the #include directives by the referenced file content and the macros by the definitions. When a syntax error in an included file is detected, store is able to understand the preprocessor location information and will report the file name and position.

Please refer to the appropriate HP-UX documentation for more information.

Running a Program

Once the program lines are entered, you can run them immediately. For example, run the guessing game program on the character oriented development environment:

RUN "GAMES" ENTER

I'm thinking of a number between 0 and 9
You have three guesses
Enter guess number, 1
Now, 5
Too low
Enter guess number, 2
Now, 8
Too high
Enter Guess number, 3
Now, 7
Sorry, the number was: 6.

                                Game Score
                                You     Me
                                 0       1

Do you want to play again?  (YES/NO)
This program will run until you enter "NO" (in capitals, with or without quotes) to the INPUT prompt Do you want to play again (YES/NO). You may halt the program at any other time by pressing BREAK or CTRL Y. When a program is halted, the line to have been executed next is displayed.

After halting a program, you can restart it from the line displayed by using the CONT (continue) command or restart from the beginning by using RUN.

Program Termination

Five statements are available for halting program execution--STOP, END, PAUSE, WAIT and SLEEP. The STOP statement may appear anywhere in the program; it halts execution and resets all file and return pointers.

The END statement halts program execution, like STOP, but is intended to be the last line in the main program. Any lines beyond END can still be executed (via branching or subroutines). END cannot be executed from the keyboard.

The PAUSE statement suspends execution, but does not reset program or file pointers. This allows you to do such things as check program variables and modify lines. Execution resumes by executing the CONT (continue) command. PAUSE cannot be executed from the keyboard.

Here is a typical use for STOP and END:

120 INPUT "Enter your Sales file access code,";Salescode
130 IF Salescode  <  1000 THEN Access_error
140 ! User code invalid for all Sales file access
150 IF Salescode  <> 9999 THEN Unauth_error
160 ! User code invalid for file update, read only allowed
170 ! Pass above tests then OK to update Sales file
180 Sales_update! Start of Sales file update program
 .
 .
 .
560 Access_error:!
570 DISP "Sorry, you are not allowed to enter the Sales file"
580 STOP
590 Unauth_error:!
600 DISP "Sorry, You can't enter the Sales file update program"
610 DISP "You have read access only"
620 STOP
630 Endit:!
640 END
Note the use of STOP when there are multiple error conditions. Each error thus can display the correct reason for denying access, and the program will halt. No other error condition will be executed unnecessarily. Also note the use of the line label Endit, so the last line can be accessed without executing any error routines. STOP, of course, can be used anywhere within a program.

The WAIT statement delays program execution a specified number of milliseconds before continuing. The syntax is as follows:

WAIT [numeric expression]

The numeric expression can range from -231 through 231-1 (about 33 seconds); a negative number defaults to 0. The wait can be interrupted by pressing CTRL Y, in the character oriented runtime environment or a user-defined softkey. Examples are given later in this chapter and also in page 151 . More information on SLEEP is available in chapter 13.

Error Messages

When an error occurs, the terminal beeps and displays either an error number or a warning message. The number references a description that will help find the cause of the error. There are three main types of errors.

Syntax Errors

Each line entered is automatically checked for syntax errors. The system will not accept an invalid Eloquence statement, and will help you by showing where the statement fails. However, a mistake in typing that accidentally forms another valid Eloquence statement cannot be detected. Note the following example:


3*(5/7 RETURN
This example causes the message IMPROPER EXPRESSION to appear on the following line and the cursor to flash below the omitted closing parenthesis. If you had entered both parentheses correctly, but typed the minus operator "-" instead of the division sign "/", no error message would be displayed.

If you are using the store command and an error occurs during the syntax check, no program (.PROG) file is created.

Run-Time Errors

These errors only appear when a program is run. A run-time error will halt the program and display the line number where the error was found. Consider this fragment of a payroll program:

190 INPUT "Please Enter Number of Employees;",Emp_quantity
200 Emp_bonus = Total_bonus/Emp_quantity
210 PRINT Emp_bonus
If the operator enters an Emp_quantity of 0, the terminal will display ERROR 31 IN LINE 200. Error 31 indicates attempted division by 0. Note that this error can only be detected at run time, as a division by zero will only occur if an Emp_quantity of 0 is entered.

The line number displayed by a run-time error need not be the incorrect line. It merely shows the point at which the error was detected. These run-time errors can be handled (or "trapped") by the program by using the ON ERROR statement, as described in page 151 .

Internal Errors

If an irretrievable system condition occurs while Eloquence is running, it stops and issues an error message. The error message contains the reason Eloquence stopped, the source-code file name, and the source-code line number. Please make a note of this information, and report it to Marxmeier Software AG. To continue working, restart Eloquence. The following internal error message serves as an example of this type of error:

Internal error processing line 4420
Assertion failed: (ssp->ofs < seg->symsz)
file prerun.c, line 227

Storing a Program

Once the program lines are in memory, you can make a permanent copy on a disk file by executing the STORE statement. The syntax is as follows:

STORE "file name"

For example, to create a program file named GAME and store the guessing game program in it, type in and execute the following:

STORE "GAME"
This statement assumes that there is no other file on the disk already named GAME. Later, you may wish to store another version of the program in the same file by using the RE-STORE statement.

To see what files are now on the disk, execute the CAT (catalog) statement:


CAT
total 4
-rw-rw-rw-   1 john    tstctr      1070 Oct 12 10:59 GAME.PROG
The CAT listing shows you that GAME is a program file (.PROG) and requires 1070 bytes of disk space. The program was saved on October 12th at 10:59 (24 hour clock). The program belongs to the group tstctr and to the user john. The user, group, and others have read and write access to the program.

Later, use the LOAD statement to copy a previously-stored program back into the computer memory.

For more details on CAT, STORE, RE-STORE and the other storage operations, refer to page 195 .

NOTE: There is a difference between the STORE statement (upper case) and the store command (lower case). The STORE statement is executed from the Eloquence prompt or from within a program, while the store command is executed from the HP-UX prompt. Refer to page 29 and page 32 for more information on the store command.

NOTE: The STORE statement, like the store command, is only available in the development version of Eloquence (not the run-time version).

Listing a Program

To see a copy of the program, use the LIST command. If you have many corrections to make in a program, it is better to list the program on the display and then edit and store each line from the listing, rather than FETCHing or retyping individual lines.

To get a printed listing, first specify the printer's address by using the SYSTEM PRINTER IS statement. (The system printer is usually set to address 8.) Then execute LIST again. For more information on printers, see page 249 .

For example, to obtain a printed listing of the guessing game example, the program should be retrieved from the disk, the system printer set to 0, and the LIST command executed as follows:

LOAD "GAME"
SYSTEM PRINTER IS 0
LIST
NOTE: The command to obtain a printed listing of the guessing game example from the HP-UX prompt is as follows:

list GAME | lp
NOTE: This command produces a listing and pipes it to the lp command. Refer to the HP-UX documentation for more information on piping and the lp command.

The INDENT Command

The INDENT command is used to change all program line indentation. The syntax is as follows:

INDENT starting column, increment

All program lines are re-positioned with the first character of each keyword starting in the specified column. Keywords are not placed in that column when numbers or labels already occupy the column. Comment (!) lines are not moved. Comments following statements are not moved unless they would overlap the statement.

Structured constructs (IFTHENELSE, REPEAT, SELECT, LOOP, WHILE) are indented an additional incremental value. Intermediate keywords in a construct (CASE, CASE ELSE, etc.) are not indented. If structured constructs do not match properly, either the indentation does not occur at the starting column at the end of the program segment or the listing returns to the starting column too soon. In either case the indentation is reset to the starting column at the beginning of each program segment (main program, multiple line function, subprogram, etc.).

The INDENT command also re-positions the FOR/NEXT, DEFFN/FNEND, and SUB/SUBEND system keyword pairs and certain Report Writer constructs. A sample program indented using INDENT 10,2 is shown on the next page.

NOTE: The maximum line length is 512 characters.

Listed below is the structure of a program before executing INDENT:

10 !
20 !  INDENT does not change the position of comment lines.
30 !
40    INPUT " Enter a number:";X
50    IF X>10 THEN
60    PRINT "X>10."
70    ELSE
80    PRINT "X<=10";
90    IF X>0 THEN
100   PRINT ", but>0."
110   END IF
120   FOR I=1 TO X
130   Sum=Sum+X                               ! Trailing comments are not
140   NEXT I                                  ! moved unless they get in
150   DISP "Sum from 1 - ";VAL$(X);" is";Sum  ! the way.
160   END IF
170   CALL Y
180   END
190   SUB Y
200   DISP "(ALMOST DONE)"
210   LOOP
220   READ A$
230   EXIT IF A$=" "
240   DISP A$
250   WAIT 1000
260   END LOOP
270   DATA 5 seconds,4 seconds,3 seconds,2 second,1 second,DONE," "
280   SUBEND
Listed below is the structure of the previous program after executing INDENT 10,2:

10 !
20 ! INDENT does not change the position of comment lines.
30 !
40       INPUT "  Enter a number:";X
50       IF X>10 THEN
60         PRINT "X>10."
70       ELSE
80         PRINT "X<=10";
90         IF X>0 THEN
100          PRINT ", but>0."
110        END IF
120        FOR I=1 TO X
130          Sum=Sum+X                       ! Trailing comments are not
140        NEXT I                            ! moved unless they get
150        DISP "Sum from 1 - ";VAL$(X);" is";Sum  ! in the way.
160      END IF
170      CALL Y
180      END
190      SUB Y
200        DISP "(ALMOST DONE)"
210        LOOP
220          READ A$
230          EXIT IF A$=" "
240          DISP A$
250          WAIT 1000
260        END LOOP
270        DATA 5 seconds,4 seconds,3 seconds,2 second,1 second,DONE," "
280      SUBEND

Interrupting a Program

The execution of a program can be stopped by pressing CTRL Y. This is known as interrupting a program. When CTRL Y is pressed in the run-time version of Eloquence, the program currently loaded is stopped, Eloquence is stopped, and control returns to the HP-UX operating system. In the developmental version of Eloquence, what happens when CTRL Y is pressed depends on where the program was started. If started from inside Eloquence, the program is stopped and control returns to Eloquence. If started from the HP-UX prompt, the program is stopped, Eloquence is stopped, and control returns to the HP-UX operating system.

Other interruptions are made when an error is encountered, the end of a file is reached, or a softkey (SFK) is pressed. These interruptions can be handled using the appropriate ON statement. (In other words, you may define action to be taken when CTRL Y is pressed using the ON HALT statement.) ON interrupts may be disabled using the OFF statement. Executing SCRATCH ALL or starting Eloquence again also disables ON interrupts.

Program debugging

Once a program is stored in user memory, it can be executed, one line at a time, by using the single-step mode. The easiest way to enter the single-step mode is by pressing the BREAK key while the computer is at a ready state. The computer then displays the first line to be executed. Pressing the BREAK key successively executes each line, displays any result, and displays the next line to be executed. The single-step mode is automatically cancelled by RUN or CONT[INUE].

Another way to enter the single-step mode is to execute a GOTO statement from the keyboard. From this point, continue (as mentioned in the above paragraph) by pressing the BREAK key to execute each program line.

HOP (Debugging Aid)

Syntax:

HOP [line id]

HOP will resume execution until reaching either the next line if line id is not specified or the line specified. Execution will stop before executing line.

This is an advantage in the debugging process, because functions, subprograms and loops may be executed, and execution stops after processing.

Example:

   10 FOR I=1 TO 10
   20   X=X+I
   30 NEXT I
   40 DISP X
   50 END
HOP 30 will resume execution until reaching line 30. Line 30 will be displayed. If you enter HOP execution will continue until line 40 is to be executed.

Tracing Program Operations

A convenient method of debugging program operation is to trace the logical flow and variable assignments. There are two tracing methods available--statement tracing and external tracing. These two methods can be used separately or together; however, in most instances they are used separately.

Statement Tracing

Seven tracing statements are available. Executing each statement sets a corresponding trace mode which outputs all related information to the device currently set as the system printer (SYSTEM PRINTER IS). The tracing statements available are as follows:

TRACE
Monitors all executed lines for specified program segments.
TRACE WAIT
Causes a WAIT instruction to occur after each TRACE output.
TRACE PAUSE
Causes a PAUSE instruction to occur at specified program lines.
TRACE VARIABLES
Lists the values of specified variables changed during the specified program segment.
TRACE ALL VARIABLES
Monitors the value of all variables within a program.
TRACE ALL
Enables both TRACE and TRACE ALL VARIABLES mode at the same time.
NORMAL
Cancels any previous TRACE modes.
XTRACE
Turn external trace within a program on or off.
NOTE: In the development mode of Eloquence tracing statements can be either programmed or executed from the keyboard. In the run-time mode the statements must already be present in the program to be run. If not, use the external tracing method.

The TRACE Statement

The TRACE statement is used to trace program logic flow in all or part of a program. When any branching occurs in a program, both the line number where the branch is from and the line number where the branch is to are output. Syntax for this statement is as follows:

TRACE [beginning line id [,ending line id] ]

When a branch occurs, the output is in the following format:

TRACE--FROM line number TO line number

If no line ids are specified, all branches in the program are monitored. When one line id is specified, tracing does not begin until that line is executed. If a second line id is specified, tracing is switched off when that line is executed. Since TRACE operates dynamically, tracing may be switched on and off many times throughout the execution of a program. The beginning line id must be present in memory or tracing will never occur; the ending line id turns off the TRACE only if that line number is encountered.

The TRACE WAIT Statement

Use the TRACE WAIT statement in conjunction with any other TRACE statement to cause a specified delay after each statement that causes a trace output. It is used to monitor and examine trace output as it occurs. Syntax for this statement is as follows:

TRACE WAIT number of milliseconds

The delay is specified by a numeric expression in the range -32768 through 32767, which indicates the number of milliseconds after each trace printout. A negative number defaults to 0.

The TRACE PAUSE Statement

To check whether or not a line in a program is reached, or to monitor the number of times a specified line is executed, use the TRACE PAUSE statement. Syntax for this statement is as follows:

TRACE PAUSE line id [,numeric expression]

When only the line id is specified, the running program stops just before the specified line is executed. When the numeric expression is specified, it is rounded to an integer--call it N. The program will then stop when the specified line is reached for the Nth time; the line is not executed. Execution is resumed with that line by executing the CONT[INUE] command. Every subsequent execution of that line causes execution to pause. This type of tracing can be disabled by letting the line id be one that is not in memory. The most efficient way is to let it be lower than the lowest-numbered line. Also see page 282 , later in this chapter.

The TRACE VARIABLES Statement

To trace changes in values of variables without using an output statement, use the TRACE VARIABLES statement. Syntax for this statement is as follows:

TRACE VARIABLES variable list

The variable list can contain simple numerics, strings, and array specifiers. There can be from one to five items separated by commas. The value of any variable which changes is printed. The output is in the following format:

TRACE--LINE line number variable name [(subscripts)] = value

The line number is the line in which the change occurred. If the change comes from a keyboard operation, the line number is replaced by KEYBOARD. The new value of the variable is indicated. In the case of an array, the values of the subscript at the time will be printed following the name.

When an entire array changes value, the printout is in the following format:

TRACE--LINE lne number array name (*) CHANGED VALUE

Tracing variables also detects changes in subprograms or variables passed by reference. For example, say TRACE VARIABLES A,B is executed and the value of A is passed by reference to a subprogram. If the corresponding variable in the subprogram is changed, a trace message for variable A occurs.

The TRACE ALL VARIABLES Statement

To trace all variables, use the TRACE ALL VARIABLES statement. Syntax for this statement is as follows:

TRACE ALL VARIABLES [beginning line id [,ending line id] ]

When no line ids are specified, all variables are traced throughout the program. When one line id is specified, tracing begins after that line is executed. The ending line causes tracing to stop after that line is executed. TRACE ALL VARIABLES cancels and is cancelled by TRACE VARIABLES.

This method of tracing can be turned off by letting the first line id be one not in memory, such as an undefined label or line number lower than the lowest line number in memory. Also see page 282 , later in this chapter.

The TRACE ALL Statement

Use the TRACE ALL statement to trace all program logic and variables. This statement is equivalent to executing both TRACE and TRACE ALL VARIABLES.

TRACE ALL

Although the volume of printout is high, TRACE ALL is useful if a logic problem in a program has not been isolated with selective tracing.

The NORMAL Statement

All tracing modes are cancelled by either executing any SCRATCH statement or by using the NORMAL statement:

NORMAL

External Tracing

External tracing is initiated when -t is specified with the eloq command, or with XTRACE inside a program. Note that the eloq command is executed from the HP-UX prompt. The syntax is as follows:

eloq -t [race] [level] [program name] [2>trace file]

If no program name is specified, the trace is performed on every program run. If a program name is specified, the trace will occur on only that program.

Three options are available for the level parameter--0 (default), 1, and 2.

Level 0 monitors all executed lines.

Level 1 monitors explicit assignments (for example, A=B*5).

Level 2 monitors implicit assignments like dbget and unpack.

The optional 2>trace file parameter is used to put the output of the trace into a file or display the output on another terminal. If 2>trace file is not specified, the trace output is displayed on the terminal, prior to the program output.

To send trace output to a file, replace trace file with the desired file name. You can then send this file to the printer or display it on the terminal. Here is an example:

eloq -t ABC 2>abctrace
This command (1) executes the program ABC, (2) performs a trace, (3) routes the trace output to the file abctrace, and (4) displays the program output on the terminal.

To display trace output on another terminal, replace trace file with the terminal address. Here is an example:

eloq -t ABC 2>/dev/tty1p5
This command (1) executes the program ABC, (2) performs a trace, (3) displays trace output on terminal tty1p5, and (4) displays the program output on the terminal that the command was executed from.

To turn on External tracing within a program, use

 XTRACE [tracing level]
                      ......
                      ......                
Setting external trace level is identical to the -t option when starting Eloquence. The trace will be directed to stderr in both cases.

NOTE: External tracing is available in either the development or run-time mode of Eloquence. Note that XTRACE or XTRACE -1 will disable external tracing. XTRACE 2 will have the same effect as eloqcore -t2 command.

Program Cross-Referencing

The purpose of program cross-referencing is to examine a program file and list where constants, line numbers, line labels, variables, functions, and subprograms appear. Cross-referencing of a program is done by using the list command with the -x option plus the options associated with -x. Note that the list command is executed from the HP-UX prompt. The syntax is as follows:

list -x [options]

Options associated with -x are l (labels and line numbers), c (constants), v (variables), and s (subprograms and functions). If no options are specified with -x, all of the options (l, c, v, and s) are set. In other words, the default is that a cross-reference be performed on all line labels, line numbers, constants, variables, subprograms, and functions.

Here is a short program named ADVERT. Following the program is the complete cross-reference table obtained by executing list -x ADVERT.

10       OPTION BASE 1
20       INTEGER Not_used        ! Variable declared, but not used
30       DIM Sign$(7)[15]        ! Constants used in declaratives
40       Sign$(1)="           "
50       Sign$(2)="           "
60       Sign$(3)="           "
70       Sign$(4)="           "
80       Sign$(5)="           "
90       Sign$(6)="           "
100      Sign$(7)="           "
110      DISP "  ",LIN(10)
120 Put_up_sign:                 ! Label not referenced
130      FOR Line=1 TO 7         ! Line not declared
140         DISP SPA(30);Sign$(Line)
150      NEXT Line
160      RESTORE
170 Again:                       !
180      READ Message$           ! Message$ not declared
190      CURSOR (31,13)
200      DISP "  "&Message$&"  "
210      WAIT 900
220      IF Message$[1,1]="D" THEN 240
230      GOTO Again
240 Last_sign:                   ! Another unreferenced label
250      WAIT 2000
260      CURSOR (29,13)
270      DISP "  "&"Buy Wonder-Shave Cream"&"  "
280      END
290  !
300      DATA "  Dina  ","  doesn't   ", "  treat him "," right ..."
310      DATA "  but if  ","  he'd shave  ","Dina might!"
The cross reference listing is as follows:

segment: main
Symbol          Type  References
--------------- ----- -------------------------------------------------
1               CONST  220  220   40  130
10              CONST  110
13              CONST  190   260
2               CONST   50
2000            CONST  250
29              CONST  260
3               CONST   60
30              CONST  140
31              CONST  190
4               CONST   70
5               CONST   80
6               CONST   90
7               CONST  100   130
900             CONST  210
240             LINE   220
Again           LABEL  170   230
Last_sign       LABEL  240
Put_up_sign     LABEL  120
Message$        X      200   180   220
Sign$           X(1)    60   100    50    40    30    80    70   90   140
Line            R      140   150   130
Not_used        I       20
Integer numbers are listed first in the cross reference listing. These include numeric constants in declaratives, functions, etc. and referenced line numbers. The right-hand column lists all Eloquence links where each constant or line-number reference appears.

Next, all names are listed. The second column identifies each name type. Possible name types are listed in the table below.

Summary of Image Symbols
Type Description Type Description
LABELLine LabelsRReal Precision Variable
SUBPSubprogram LabelsSShort Precision Variable
N FUNNumeric FunctionsIInteger Precision Variable
$FUNString FunctionsXString Variable
LINELine NumbersDDouble Integer Precision Variable
CONSTConstants  

A number in parentheses following variable types R, S, I or X indicates the array's number of dimensions. The right-hand column lists all line numbers where each label appears.

The SCRATCH Statement

All or part of the user work area can be erased using a SCRATCH statement.

Here is a summary of the SCRATCH statements:

SCRATCH
Erases programs and variables.
SCRATCH A[LL]
Erases the entire user area.
SCRATCH C
Erases the values of all variables, including those in common (COM).
SCRATCH P
Erases programs and variables.
SCRATCH V
Erases the values of all variables except those in common. Do not use this statement in subprograms.
NOTE: If SCRATCH, SCRATCH A, or SCRATCH P is executed in a program,which run in run-time mode, the program and Eloquence will stop, thus returning control to the HP-UX environment.

The Reset Table in page 384 lists all conditions reset by SCRATCH statements.

Display Function Characters

The are two forms of special characters. They are obtained by selecting the appropriate special character set. (Consult your terminal manual for the method of switching character sets.)


Eloquence Language Manual - 19 DEC 2002