User guide
3.3. GLOBAL FUNCTIONS 57
destination task or device (specified by pkt
id!pkt). If this fiel d is positive it refer s to
a task, if it is -1 it r e fe r s to the clock device and other negative val ues refer to other
devices. If the packet is queued successfully this field is updated to hold the current
task’s identifier and the result i s non ze r o, otherwise the result is zero with result2
set to 101 if the destination id is invalid, and to 111 if pkt link was not equal to
notinuse (=-1). If the destination was a runnable task of higher priority than the
current one, th en the current task immediately becomes suspended in RUN state and
control is given to the destination, otherwise the curr ent task continues to r un normally.
Interaction with the resident Cintpos devices is described i n Chapter 6.
n := randno(upb) CIN:y, POS:y, NAT:y
This function returns a random integer in the range 1 to upb. It uses a seed held
in global variable randseed which can be set using setseed described below. Its
implementation is as follows:
LET randno(upb) = VALOF
{ randseed := randseed*2147001325 + 715136305
RETURN ABS(randseed/3) REM upb + 1
}
res := rdargs(keys, argv, upb) CIN:y, POS:y, NAT:y
This impl e me ntation of BCPL incorporates a command language interpreter which
is described in Chapter 4. Most commands require arguments and these are easily read
using rdargs.
The first argument (keys) specifies the argument format. The second and third
arguments provide a vector (argv) with a given upper bound (upb) into which the
decoded arguments will be placed. If rdargs is succ es sfu l , it returns the number of
words used in a rgv to represent the decoded command arguments, but on failure, it
returns zero.
The stri ng keys holds the list of argument keywords separated by commas (,).
Alternative keywords for a given argument are separated by equal signs (=). The
expected number of arguments is one more than the number of commas in the key
string. If rdargs returns successfully, this number of elements at the start of argv wil l
hold the decoded arguments.
Arguments can have qualifiers of the form /A, /K, /N, /S and /P. The qualifier
letters can be in either upper or lower case. The qualifier /A means that the argument
must b e given. /K means that, if the argument is given, it must include its keyword.
/N specifies that the argument must be a number. /S indicates that the argument is
a switch parameter se t to TRUE by its keyword. /P indicates that a prompt will be
given for the argument if it has not already b ee n set. Pr omp ti ng only happens if the
currently selected input and output streams are connected to an interactive terminal.
If the pr ompt is for a switch argument (/S) it expects a yes/no response. Typing
yes or y is treated as yes, any other response is treated as no. If rdargs re t ur ns
successfully argv!0, argv!1 etc will hold the arguments settings. A setting of zero
means the argument was not given. A setting of -1 means the argument was a switch
set the TRUE. Othe r wis e , if /N was specified the setting will point to a word in argv