functions

Functions can be used in $[...] and /test expressions. A function call is made with a function name, followed by a parenthesized list of comma-separated arguments.

In the following list of functions and descriptions, arguments s and t are any string value, and i and j are any integer value.

ascii(s)
(int) Integer code of the first character of s, The character does not have to be ASCII, but may be any character allowed by your locale.
char(i)
(str) character with integer code i. If i is outside the range allowed by your locale, it will be silently forced into the allowed range.
columns()
(int) Number of columns on the screen. See also: hooks (RESIZE), lines.
echo(s)
(int) Echoes s to the screen, like /echo, and returns 1.
filename(s)
(str) Performs filename expansion on s as described under "filenames".
ftime(s,i)
(str) Formats a system time i (obtained from time()) according to format s. If s is "@", a raw system time will be displayed. Any other s will be used as a strftime(3) format if your system supports it. If s is blank or strftime() is not supported, "%c" will be used. See your local strftime(3) man page for a description of the format string. The format may also be affected by the locale, determined by %LANG. See also: time(), %TZ.
fwrite(s,t)
Writes string t to the end of file s.
getopts(s, t)
(int) Parse macro options according to format s. See "getopts()".
getpid()
(int) The operating system's process id for tf.
idle()
(int) Number of seconds since the last keypress.
idle(s)
(int) Number of seconds since the last text was received on the socket connected to world s, or -1 on error.
kbdel(i)
(int) Delete from the cursor to position i in the input buffer. Returns the new position.
kbgoto(i)
(int) Move the cursor to position i in the input buffer. Returns the new position (which may be different than i if i would put the cursor outside the buffer).
kbhead()
(str) Return the current input up to the cursor.
kblen()
(int) Length of current input line.
kbmatch()
(int) Finds one of "()[]{}" under or to the right of the cursor, and returns the position of its match, or -1 if not found. (See also: keybindings)
kbpoint()
(int) Return the current position of the cursor in input.
kbtail()
(str) Return the current input after the cursor.
kbwordleft()
(int) Position of beginning of word. (See also: %wordpunct)
kbwordright()
(int) Position just past end of word. (See also: %wordpunct)
keycode(s)
(str) String generated by typing the key labelled s, as defined in the termcap entry corresponding to the value of %TERM. See also: keybindings.
lines()
(int) Number of lines on the screen. To get the number of lines in the output window, use the expression (lines() - (visual ? isize+1 : 0)). See also: hooks (RESIZE), columns.
mod(i,j)
(int) Remainder of i divided by j.
moresize()
(int) Number of lines queued at a more prompt.
pad([s, i]...)
(str) There may be any number of (s, i) pairs. For each pair, s padded with spaces to a length equal to the absolute value of i. If i is positive, s is right-justified; If i is negative, s is left-justified. The result is the concatenation of all the padded strings.
rand()
(int) Random number in the range [0, system maximum].
rand(j)
(int) Random number in the range [0, j - 1].
rand(i,j)
(int) Random number in the range [i, j].
read()
(str) Reads a line from keyboard input. See seperate "read()" topic.
regmatch(s, t)
(int) Returns 1 if string t matches regexp s, otherwise returns 0. Subexpressions can later be extracted using the Pn variables or %Pn substitutions. (See also: regexp)
send(s, t, i)
(int) Sends string s to world t, or the current world if world is blank. An end-of-line will be appended unless i is 0.
send(s, t)
Equivilent to send(s, t, 1).
send(s)
Equivilent to send(s, "", 1).
strcat(...)
(str) Join strings (takes any number of string arguments).
strchr(s, t)
(int) First position within s of any character contained in t, or -1 if not found. (For you C programmers, this is actually more like strcspn() or strpbrk()).
strcmp(s, t)
(int) Returns a number less than, equal to, or greater than 0 if s is lexicographically less than, equal to, or greater than t, respectively.
strlen(s)
(int) Length of string s.
strncmp(s, t, i)
(int) Like strcmp(), but compares only the first i characters of s and t.
strrchr(s, t)
(int) Last position within s of any character contained in t, or -1 if not found.
strrep(s, i)
(str) Returns a string containing i repetitions of s.
strstr(s, t)
(int) First position of t within s, or -1 if not found.
substr(s, i)
substr(s, i, j)
(str) Substring of s, starting at position i, with length j. If j is omitted, it defaults to the remaining length of s. If i or j is negative, they are counted as absolute values from the end of s.
systype()
(str) System type, either "unix" or "os/2".
time()
(int) System time (typically seconds since 00:00:00 GMT, January 1, 1970). See also: /time, ftime().
tolower(s)
(str) Convert all characters in s to lower case.
toupper(s)
(str) Convert all characters in s to upper case.

String positions are always counted from 0. Therefore the first character of a string s is substr(s, 0, 1), and the last character is substr(s, strlen(s)-1).

Range checking is done on string positions. Any position given outside the allowed range will be silently forced to the closest value that is in the range.

Macros and builtin commands can be called as functions. Currently, a command called as ``$[command("word1 word2... wordN")]'' will be executed as if by ``/command word1 word2... wordN''. This argument passing syntax is subject to change in future versions, so you shouldn't rely too heavily on passing multiple words in this way.

To evaluate a function for its "side effect" only, you can call it from /test and ignore the return value (e.g., "/test kbdel(0)").

Examples:

Capitalize first letter of string s:

      strcat(toupper(substr(s, 0, 1)), substr(s, 1))

Extract the number from a string dbref of the form "(#123PML)":

      0 + substr(dbref, strchr(dbref, "#") + 1)

See: expressions


Back to index
Back to tf home page
Copyright © 1995, 1996, 1997 Ken Keys