HP 3000 Manuals

To Create a Calculator [ Command Interpreter Access and Variables Programmer's Guide ] MPE/iX 5.0 Documentation


Command Interpreter Access and Variables Programmer's Guide

To Create a Calculator 

The CALCIT command file provides the user with an interactive calculator.
The user is prompted for an equation to be solved or an MPE/iX command to
execute.  To exit CALCIT, the user enters a carriage return.

Note that the CENTER command file is called to center the display
headings on the user's terminal.  After an equation is solved, the result
is displayed on the terminal using escape sequences to append the result
to the original input line and to underline it.  The predefined variable
HPMSGFENCE is used to suppress error messages.

The CALCIT prompt is based on the command file name.  By dereferencing
the latest command entered in the history stack (!-1), the name that
called this command file becomes a part of the prompt.  If the command
file name is changed to COMPUTE, for example, the prompt automatically
becomes COMPUTE ==>.

_________________________________________________________________________________
|                                                                               |
|     PARM ENH_CH=D                                                             |
|     COMMENT Interactive calculator using calc and input                       |
|     ECHO ![CHR(27) + "h" + CHR(27) + "J"]                                     |
|     CENTER "MPE/iX INTERACTIVE CALCULATOR"                                    |
|     CENTER ": executes any MPE/iX command!"                                   |
|     CENTER "Type [RETURN] to exit"                                            |
|     ECHO                                                                      |
|     SETVAR CALCIT_ESC CHR(27) + "A" + RPT(CHR(27) + "C", 64)                  |
|     SETVAR CALCIT_PROMPT LFT(UPS("!-1"), POS(' ',"!-1" + ' ')-1) + ' ==> '    |
|     WHILE SETVAR (CALCIT_EXPR, RTRIM(INPUT(CALCIT_PROMPT))) <> '' DO          |
|       COMMENT Save length before trimming leading blanks                      |
|       SETVAR CALCIT_LEN LEN(CALCIT_EXPR)                                      |
|       SETVAR CALCIT_EXPR LTRIM(CALCIT_EXPR)                                   |
|       IF LFT(CALCIT_EXPR,1) = ":" THEN                                        |
|         CONTINUE                                                              |
|         ![RHT(CALCIT_EXPR,LEN)CALCIT_EXPR)-1)]                                |
|       ELSE                                                                    |
|         SETVAR HPMSGFENCE 2                                                   |
|         SETVAR CIERROR 0                                                      |
|         CONTINUE                                                              |
|         SETVAR HPRESULT !CALCIT_EXPR                                          |
|         SETVAR HPMSGFENCE 0                                                   |
|         IF CIERROR <> 0 THEN                                                  |
|           COMMENT User entered an invalid expression.                         |
|           COMMENT Display error.                                              |
|           ECHO ![RPT(' ',LEN(CALCIT_PROMPT) + HPCIERRCOL-17)]^                |
|           ECHO !HPCIERRMSG                                                    |
|         ELSE                                                                  |
|           ECHO ![LFT(CALCIT_ESC, 2 + (LEN(CALCIT_PROMPT) + CALCIT_LEN) * 2) +&|
|                ' = ' + CHR(27) + '&d!ENH_CH']!HPRESULT                        |
|         ENDIF                                                                 |
|       ENDIF                                                                   |
|     ENDWHILE                                                                  |
|     DELETEVAR CALCIT_@                                                        |
_________________________________________________________________________________

          Figure 7-9.  Calculator Command File 

The following example shows the terminal display to calculate the
equation 5 + 7.
_______________________________________________________________
|                                                             |
|                                                             |
|      :CALCIT                                                |
|                              MPE/iX INTERACTIVE CALCULATOR  |
|                               : executes any MPE/iX command |
|                                  Type [RETURN] to exit      |
|                                                             |
|      CALCIT ==> 5+7 = 12                                    |
|      CALCIT ==>                                             |
|      :                                                      |
|                                                             |
_______________________________________________________________

            



MPE/iX 5.0 Documentation