IF - conditionally execute a series of system commands.

Syntax:

IF expression ["command"]*
IF expression :command
I = ABBrev(S1,S2)         N = ABS(N)
F = ATAN(N)               F = COS(N)
S = CallS(S1)             I = CallSS()
I = CallV(S1)             S = CTIME()
S = CurrentCatalog()      I = DAYs()
I = DeLaY(I)              S = DRUNid()
I = DateToSeconds(S)      F = EXP(N)
I = ExecFile(S1)          S = FIELD(S1,I,S2,S3)
I = FIX(N)                S = FORMat(X,I1,I2,S1,S2)
I = Gcos8()               I = HOURs()
I = inCRUN()              F = LN(N)
S = LOWer(S1)             I = Length(S1)
I = MarkIII()             S = NOW()
N = NUMber(S,I)           F = PI()
I = RanDom(S1)            I = ReadFile(S1)
S = ReplaceString(S1,I1,S2,I2)
S = SecondsToDate(I,S)    X = SELect(I1,X0,X1,...)
F = SIN(N)                S = SNUMB()
F = SQRT(N)               S = SubString(S1,I1,I2)
I = SWitch(I)             I = SWitch1()
I = SWitch2()             S = SystemID()
S = ToDay()               S = TYPE(X)
I = UNIX()                S = UPper(S1)
S = UserID()              I = VIPscreen()
S = WeekDay(S)            I = WriteFile(S1)
N = _()

Examples:

if 1+1-2 == 0 "echo it works"
if weekday=="Friday" :echo Leave
if ReadFile("user/pathname") > 0  "l user/pathname"

Description:

IF lets you execute commands conditionally. This is especially useful for building command files (CRUN/DRUN) when decisions must be made during execution.

The "expression" command line argument may contain the basic arithmetic operations (addition, subtraction, division, multiplication, modulus and exponentiation **), logical comparisons, bit twiddling operations (And, Or, Exclusive OR, Negation), and a large number of functions supported by IF, EVAL, and EXEC.

An expression value may be a STRING, an INTEGER, or a FLOATING value. A STRING consists of characters enclosed in either ", ', or `. The following escape sequences are used to represent difficult characters.

*e    end of string (ASCII NUL = 000)
*(    { - left curly brace
*)    } - right curly brace
*<    [ - left square bracket
*>    ] - right square bracket
*t    tab
**    *
*'    '
*"    "
*n    new-line
*r    carriage return (no line feed)
*f    ASCII formfeed
*b    backspace
*v    vertical tab
*x    rubout (octal 177)
*nnn  nnn is 1-3 character octal number

INTEGER means numbers without a decimal point and FLOATING means numbers with a decimal point.

IF performs type conversion automatically where allowed. In most cases, INTEGER is converted to FLOATING when two operands are mixed INTEGER and FLOATING. Both INTEGER and FLOATING are converted to STRING if STRING operands are combined with INTEGER or FLOATING operands. When type conversion is not allowed, IF issues the message "Operand type mismatch".

IF reports all errors to the terminal; diagnostic messages show the command line with an error indicator that tries to show where the error was encountered. More precisely, the error indicator points to where the IF expression parser last read a character. The error is usually in the sub-expression that ends at the indicator position.

The table below lists operators from highest to lowest binding strength. Operators of equal strength are executed either from left to right (denoted by [LR]) or from right to left (denoted by [RL]).

[LR] Function(arglist)
[RL] **                (Exponentiation)
[RL] - ~ !             (Unary Minus, Negation and Not)
[LR] >> <<             (Shift right and left)
[LR] &                 (AND)
[LR] ^^                 (Exclusive OR)
[LR] |                 (OR)
[LR] * / %             (Multiply, Divide, Modulus)
[LR] + -               (Add, Subtract)
[LR] == != > < <= >=   (Logical Operators)
[LR] &&                (Logical AND)
[LR] ||                (Logical OR)

Functions:

IF recognizes a set of functions that perform various operations. These functions are described below. In these descriptions, function arguments are indicated by the characters S, I, F or N for STRING, INTEGER, FLOATING, or NUMERIC (either INTEGER or FLOATING). IF converts the value as required. The descriptions indicate the type of the return value using the same convention. Function names may be abbreviated by omitting any or all letters shown in lowercase. Note that functions which require no arguments can be specified with or without ().

The list that follows marks optional arguments by enclosing them in square brackets []. You do not actually put in the square brackets when you use the functions.

_ () returns N
_ represents the value of the expression from a former invocation of the IF command. Since IF stores the expression value in the UST core file, IF can only keep FLOATING and INTEGER values. If IF finds the stored value has an invalid type, (possibly because no previous IF command had been executed), IF terminates with the error message "strange value read for _".

Files Used:

fc*nn
where "nn" is an integer from 00 to 99. These files are used for collecting output from the CallS function. The number "nn" is the TSS callss depth.

See Also:

expl eval

abbrev
expl if abs
expl if atan
expl if calls
expl if callss
expl if callv
expl if cos
expl if ctime
expl if currentcatalog
expl if datetoseconds
expl if days
expl if delay
expl if drunid
expl if execfile
expl if exp
expl if field
expl if fix
expl if format
expl if gcos8
expl if hours
expl if incrun
expl if length
expl if ln
expl if lower
expl if markii
expl if now
expl if number
expl if pi
expl if random
expl if readfile
expl if replacestring
expl if secondstodate
expl if select
expl if sin
expl if snumb
expl if sqrt
expl if substr
expl if switch
expl if systemid
expl if today
expl if type
expl if unix
expl if upper
expl if userid
expl if vipscreen
expl if weekday
expl if writefile

Notes:

The CallS function only returns the first line of output, and only works with those commands that support ">" redirection convention. Most such commands are written in B, C or Pascal.

Copyright © 1996, Thinkage Ltd.