|
|
Command Interpreter Access and Variables Programmer's Guide: Series HP 3000 Computer Systems > Chapter 4 Evaluating ExpressionsUsing Expressions in CI Commands |
|
The CI provides an expression evaluator that supports a large selection of arithmetic operations; number conversions; file information; and string, bit, and variable operations. (Appendix B provides a table of commonly used functions. Refer to the MPE/iX Commands Reference Manual (32650-90003) for a complete list of expression evaluator functions.) Standard addition, subtraction, multiplication, and division functions, as well as exponentiation, absolute value, and modulo arithmetic functions, are valid arithmetic operations in the CI. The standard expression symbols are used in the CI as in other programming languages. The following examples show the common arithmetic symbols used by the CI.
The expression evaluator performs integer algebra. Functions are executed from left to right, in the following order of operations.
The following example sets the variable EXP with the result of an expression. Note the order in which the operations are performed.
The multiplication and division functions are performed first from left to right. The integer result is added to A. Note that division is an integer function; results are truncated, not rounded. Parentheses can be inserted to clarify or to alter the logical order of operations. The following example provides the expression from the previous example with parentheses included for clarification.
String functions provide a means of analyzing strings. These functions include adding and subtracting characters in a string, determining the length of a string, determining the position of a particular character in a string, adjusting the case of characters, repeating a a character in a string, and removing leading or trailing characters from a string. Strings are evaluated character by character from left to right. Adding two strings concatenates the contents of the second string to the end of the first.
Subtracting characters from a string deletes the first occurrence of the specified characters from the original string.
The case of string data can be altered with the downshift (DWNS) or upshift (UPS) functions. These functions are used in case-sensitive comparisons.
The length of a string can be determined with the LEN function.
The RPT function repeats a string a specified number of times. This is often used to pad another string with blanks or zeros.
The LTRIM and RTRIM functions trim leading or trailing characters from the left or right of a string. Blanks are trimmed from the string unless a trim character is specified in the command.
ASCII characters can be defined by their ordinal representation. Note that if the parameter of the ordinal function consists of more than one character, the ordinal representation of only the first character is returned. The other characters are ignored.
Ordinal numbers can likewise be defined by their ASCII character representation. This is often used for escape sequences and control sequences that have no printable counterpart.
Integer data can be evaluated and adjusted by using the bit operations provided with the CI. These include bit shift left (LSL), bit shift right (LSR), and circular shifts (CSL and CSR). Also, logical OR, AND, NOT, and XOR operations are available. Because AM capability is identified by a 1 in the second bit of the predefined variable HPUSERCAP, either of the following expressions can be used to see if a user has AM capability.
or
Note that the preceding examples show the use of the bit operations. A simpler way of determining if a user has AM capability would be the following method.
Numeric values can be converted from decimal representation to octal or hexadecimal string equivalents. Numeric output is identified by three prefixes: # represents decimal, $ represents hexadecimal, and % represents octal. If no prefix is specified, decimal is assumed. In the following example, the decimal number 329 is converted to its hexadecimal and octal string representations.
The FINFO function retrieves file specifications for the identified file. This is useful in creating files, verifying that a file exists, or identifying file specifications. The type of file information requested is identified by a numeric entry or an alias for the numeric entry, similar to the parameters of the FINFO function. Note that aliases are strings and must be enclosed in parentheses. String, boolean, or numeric data is returned depending on the option specified. FINFO recognizes HFS (hierarchical file system) names and supports the FLABELINFO intrinsic items relating to POSIX. Examples include:
Refer to New Features of MPE/iX: Using The Hierarchical File System (32650-90351). The following table provides some of the most commonly used FINFO options, by number and alias, and a description of the results. FINFO passes the name of the file using either MPE syntax (the default) or HFS syntax. You can enter CALC FINFO('.1',0) and receive TRUE as output, and filename in HFS can end in any character. If MPE syntax, the file name can include password, group, and account specifications. The file name can backreference a file equation and optionally be preceded by an asterisk. If HFS syntax, the file name must start with either a dot (.) or a slash (/). For files located in HFS directories, traverse directory entries (TD) access is required to all directories specified in the formal design. If there is no TD access, FINFO fails. If the file can be named using both MPE syntax and HFS syntax (for example, FILEA.MYGROUP.MYACCT and /MYACCT/MYGROUP/FILEA), the file can be either permanent or temporary. If a temporary and a permanent file have the same name, FINFO returns information about the temporary file only. Refer to the MPE/iX Commands Reference Manual (32650-90003) for a complete description of the FINFO options. Table 4-1 FIFO Specifications
The FINFO function is often used in file maintenance routines to create, delete, or determine certain characteristics of a file. The following examples demonstrate the responses to several FINFO requests about the file X.PUB.SYS
The last example asks for the absolute pathname of the file "X" (HFS syntax). Compare this with the example immediately preceding it, which asks for the file name in MPE syntax. The comparison operators, equal (=), less than (<), greater than (>), not equal to (<>), less than or equal to (<=), and equal to or greater than (>=), are provided in the CI expression evaluator. These expressions produce a boolean result that can be used to set the criteria for a conditional branch or a looping structure. |
|