The following is an example of an external function.
/*
* FUNCTION: parse - break a field into smaller
fields
* This function breaks a field into two smaller subfields; the
* source field is considered to
consist of two subfields
separated
* by one or more separator characters. The first subfield is then
* copied to destination; the separators
are skipped up to the first
* non-separator, and the remaining
characters are move up to
the
* start of the source field. (That
is, the source field
is changed
* by this function.)
* NOTE: a sequence of
separator characters
will be skipped
over
* as a unit, rather than each
occurrence denoting a null
token.
*
* INPUT:
* destination: field where first
subfield is placed.
* source: original
field to be broken up.
* separators:
field containing separator
characters.
* RETURN CODE: number of characters copied in destination
field.
* EXAMPLE:
* If source contains "Wilmington, Ohio"
and separators
* are ", .", then
"Wilmington" will be placed in the
destination,
* "Ohio" will be left in source, and the return code
will contain
* the number 10.
*/
DEFARG_COUNT(3)
DEFARG(destination,char,out)
DEFARG(source,char,both)
DEFARG(separators,char,in)
L_ _parse:
load (r.0, r.2)
L_ _parse1:
load (r.1, int.F_ _FUNCT_ARG3)
L_ _parse2:
jmp (*ch.0 == *ch.1, L_ _parse4)
/* match */
incr (r.1, im.1)
jmp (*ch.1 != im.0, L_ _parse2)
incr (r.0, im.1)
jmp (*ch.0 != im.0, L_ _parse1)
/* end of src string, return it as dst1, null as
dst2. */
strcpy (*ch.3, *ch.2)
L_ _parse3:
load (*ch.2, im.0)
strlen (*ch.3)
rts ()
L_ _parse4: /* copy substrings to out
area. */
load (*ch.0, im.0) /* null terminate 1st dst string.
*/
strcpy (*ch.3, *ch.2)
/* skip over separator characters. */
L_ _parse5:
incr (r.0, im.1)
load (r.1, int.F_
_FUNCT_ARG3)
L_ _parse6:
jmp (*ch.0 ==
*ch.1, L_ _parse5) /* separator.
*/
incr (r.1, im.1)
jmp (*ch.1 != im.0, L_ _parse6)
/* at end of separators. */
jmp (*ch.0 == im.0, L_ _parse3)
/* separators end the string*/
L_ _parse7:
/* copy remaining string to dst2.
*/
strcpy (*ch.2, *ch.0)
/* look out for overlapping copy,OK on
6386*/
strlen (*ch.3)
rts ()