HPlogo Command Interpreter Access and Variables Programmer's Guide: Series HP 3000 Computer Systems > Chapter 4 Evaluating Expressions

Using Expressions in CI Commands

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

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.)

Performing Arithmetic Operations

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.

   Description              Example       Result



   Addition                  1 + 3          4

   Subtraction               3 - 1          2

   Multiplication            2 * 4          8

   Division                 16 / 8          2

   Absolute Value          ABS(-3)          3

   Exponentiation              2^3          8

   Multiple Functions    2 * 3 + 6         12

The expression evaluator performs integer algebra. Functions are executed from left to right, in the following order of operations.

  1. Exponentiation and absolute value.

  2. Multiplication and division.

  3. Addition and subtraction.

The following example sets the variable EXP with the result of an expression. Note the order in which the operations are performed.

   :SETVAR A 1

   :SETVAR B 2

   :SETVAR C 3

   :SETVAR D 4

   :SETVAR EXP A+B*C/D

   :SHOWVAR EXP

   EXP = 2

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.

   :SETVAR EXP A+((B*C/D)

Evaluating Strings

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.

   :SETVAR ANS "abcd" + "efg"

   :SHOWVAR ANS

   ANS = abcdefg

Subtracting characters from a string deletes the first occurrence of the specified characters from the original string.

   :SETVAR ANS "abcabc" - "ab"

   :SHOWVAR ANS

   ANS = cabc

The case of string data can be altered with the downshift (DWNS) or upshift (UPS) functions. These functions are used in case-sensitive comparisons.

   :SETVAR ANS UPS("abcdEFG")

   :SHOWVAR ANS

   ANS = ABCDEFG



   :SETVAR ANS DWNS("abcdEFG")

   :SHOWVAR ANS

   ANS = abcdefg

The length of a string can be determined with the LEN function.

   :SETVAR ANS LEN("abcdefg")

   :SHOWVAR ANS

   ANS = 7

The RPT function repeats a string a specified number of times. This is often used to pad another string with blanks or zeros.

   :SETVAR ANS RPT("A",3)

   :SHOWVAR ANS

   ANS = AAA

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.

   :SETVAR ANS RTRIM("ABC    ") + LTRIM(".....DEF",".")

   :SHOWVAR ANS

   ANS = ABCDEF

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.

   :SETVAR ANS ORD("AbcD")

   :SHOWVAR ANS

   ANS = 65

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.

   :SETVAR ANS CHR(65)

   :SHOWVAR ANS

   ANS = A

Performing Bit Operations

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.

   IF ((HPUSERCAP LSR 30) BAND 1) = 1 THEN ...

or

   IF ODD(HPUSERCAP LSR 30) THEN ...

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.

   IF POS("AM",HPUSERCAPF) > 0 THEN

   [vellip]

Converting Numbers

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.

   SETVAR ANS HEX(329)

   SHOWVAR ANS

   ANS = $149



   SETVAR ANS OCTAL(329)

   SHOWVAR ANS

   ANS = %511
NOTE: The results of converting numbers using the HEX and OCTAL functions are character strings. The result cannot be used in numeric calculations.

Evaluating File Characteristics

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:

  • number of hard links

  • time of last file access

  • file owner (full user.account name and numeric ID)

  • file type (directory, symbolic link, pipe, FIFO, device link, etc.)

  • record type (fixed, root, spool, byte stream, directory, etc.)

  • file size in bytes

  • KSAM XL version

  • device type (disk, tape, port, streams, sockets, etc.)

  • whether the file has been released.

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

NumberAliasData TypeItem Description
0EXISTBooleanExistence of file
1

FILENAME ONLY

FNAME

FULL FILENAME

FULLFNAME

FULLY QUALIFIED FILENAME

StringFile name
2

GROUP

GROUPNAME

StringGroup name
3

ACCOUNT

ACCT

ACCOUNTNAME

StringAccount name
4CREATORStringFile creator name
5SECURITY MATRIXStringSecurity matrix for access
-5SECURITY MATRIXIntegerSecurity matrix for access
6

CREATED

CREATION DATE

FMTCREATED

StringFile creation date
-6

CREATION DATE INTEGER

INTCREATED

IntegerFile creation date
7

ACCESSED

FMTACCESSED

LAST ACCESS DATE

StringLast access date
-7

LAST ACCESS DATE INTEGER

INTACCESSED

IntegerLast access date
8

MODIFIED

LAST MOD DATE

FMTMODDATE

StringLast modification date
-8

LAST MOD DATE INTEGER

INTMODDATE

IntegerLast modification date
9

FILE CODE

MNEMONIC

FMTFCODE

StringFile code of disk file
-9

FCODE

INTFCODE

IntegerFile code of disk file
10USER LABELS WRITTENIntegerNumber of user labels written
11USER LABELS AVAILIntegerNumber of user labels available
12

FILE LIMIT

LIMIT

IntegerTotal number of logical records possible in the file
13

FOPTIONS

FMTFOPT

StringFile options
-13

FORMATTED FOPTIONS

INTFOPT

IntegerFile options
14

RECORD SIZE

RECSIZE

IntegerRecord size
15

BLOCK SIZE

BLKSIZE

IntegerBlock size
16

MAX EXTENTS

MAXEXT

IntegerMaximum number of extents
17

LAST EXTENT SIZE

LASTEXTSIZE

IntegerLast extent size
18

EXTENT SIZE

EXTSIZE

IntegerExtent size
19

END OF FILE

EOF

IntegerNumber of logical records in file
20

ALLOC TIME

FMTALLOCTIME

StringFile allocation time
-20

ALLOC TIME INTEGER

INTALLOCTIME

IntegerFile allocation time
21

ALLOC DATE

FMTALLOCDATE

ALLOCATED

StringFile allocation date
-21

ALLOC DATE INTEGER

INTALLOCDATE

IntegerFile allocation date
22NUM OPEN CLOSE RECSIntegerNumber of open/close records
23

DEVICE NAME

DEV NAME

StringDevice name (8 bytes
24

FMTMODTIME

LAST MOD TIME

StringLast modification time
-24

INTMODTIME

LAST MOD TIME

IntegerLast modification time
25FIRST USER LABELStringFirst user label (user label 0)
27

UNIQUE FILE ID

UFID

RECUnique file identifier (UFID)
28

BYPE FILE SIZE

BYTEFILESIZE

Integer

Total number of bytes allowed in file

29

BYTE DATA OFFSET

DATASTART

IntegerStart of file offset
30

BYTE RECORD SIZE

BYTERECSIZE

IntegerRecord size (indicates bytes)
31

BYTE BLOCK SIZE

BYTEBLKSIZE

IntegerBlock size (indicates bytes)
32

BYTE EXTENT SIZE

BYTEEXTSIZE

IntegerExtent size (indicates bytes)
33LOCKWORDStringFile lockword
34

VOLUME RESTRICTION

VOLRESTR

StringVolume restriction
35VOLUME SET NAMEStringVolume set names
36LOGSET IDStringTransaction management log set id
37

LDEV

LOGICAL DEVICE NUMBER

IntegerLogical device number
38

POSIX FULL FILE NAME

POSIXFULLFNAME

RECTerminated HFS-syntax system absolute pathname
39

NUM HARD LINKS

NUMHARDLINKS

IntegerThe current number of hard links to the file
40

ACCESS TIME

FMTACCESSTIME

LAST ACCESS TIME

StringTime of last file access (clock format)
-40

LAST ACCESS TIME INTEGER

INTACCESSTIME

IntegerTime of last file access (clock format)
41

STATUS CHANGE TIME

FMTSTATUSCHANGETIME

StringTime of last file status change (clock format)
-41INTSTATUSCHANGETIMEIntegerChange Time Integer
42

STATUS CHANGE DATE

FMTSTATUSCHANGEDATE

StringDate of the last file status change (calendar format)
-42

CHANGE DATE INTEGER

INTSTATUSCHANGEDATE

IntegerDate of the last file status change (calendar format)
43

FILE OWNER NAME

OWNER

StringFile owner
44

FILE OWNER ID

UID

IntegerFile owner identifier
45

FILE GROUP NAME

FILEGROUP

String

File group

46

FILE GROUP ID

GID

IntegerFile group identifier
47

FILE TYPE

FILETYPE

StringFile type
-47

FILE TYPE INTEGER

INTFILETYPE

IntegerFile type
48

RECORD TYPE

RECTYPE

IntegerRecord type
49

BYTE FILE SIZE

BYTEFILESIZE

IntegerCurrent file size (in bytes)
50

KSAM VERSION

KSAMVERS

IntegerKSAM XL file version
51

KSAM LABEL

KSAMPARAM

some type by referenceKSAM XL parameters
52

DEVICE TYPE

DEVTYPE

StringMPE/iX device type
-52

DEVICE TYPE INTEGER

INTDEVTYPE

IntegerMPE/iX device type
53RELEASEDBooleanSecured/Released

 

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

   :CALC FINFO('X',0)

   TRUE

   :CALC FINFO('X','EXISTS')

   TRUE





   :CALC FINFO('X',13)

   ASCII, FIXED, NOCCTL, STD

   :CALC FINFO('X','FMTFOPT')

   ASCII, FIXED, NOCCTL, STD



   :CALC FINFO('X',1)

   X.PUB.SYS



   :CALC FINFO('X','FULLFNAME')

   X.PUB.SYS



   :CALC FINFO('X',38)

   /SYS/PUB/X

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.

Comparing Results

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.

Feedback to webmaster