Contents | < Browse | Browse >
`tparam'
--------
The function `tparam' can encode display commands with any number of
parameters and allows you to specify the buffer space. It is the
preferred function for encoding parameters for all but the `cm'
capability. Its ANSI C declaration is as follows:
char *tparam (char *CTLSTRING, char *BUFFER, int SIZE, int PARM1,...)
The arguments are a control string CTLSTRING (the value of a terminal
capability, presumably), an output buffer BUFFER and SIZE, and any
number of integer parameters to be encoded. The effect of `tparam' is
to copy the control string into the buffer, encoding parameters
according to the `%' sequences in the control string.
You describe the output buffer by its address, BUFFER, and its size
in bytes, SIZE. If the buffer is not big enough for the data to be
stored in it, `tparam' calls `malloc' to get a larger buffer. In
either case, `tparam' returns the address of the buffer it ultimately
uses. If the value equals BUFFER, your original buffer was used.
Otherwise, a new buffer was allocated, and you must free it after you
are done with printing the results. If you pass zero for SIZE and
BUFFER, `tparam' always allocates the space with `malloc'.
All capabilities that require parameters also have the ability to
specify padding, so you should use `tputs' to output the string
produced by `tparam'. Padding. Here is an example.
{
char *buf;
char buffer[40];
buf = tparam (command, buffer, 40, parm);
tputs (buf, 1, fputchar);
if (buf != buffer)
free (buf);
}
If a parameter whose value is zero is encoded with `%.'-style
encoding, the result is a null character, which will confuse `tputs'.
This would be a serious problem, but luckily `%.' encoding is used only
by a few old models of terminal, and only for the `cm' capability. To
solve the problem, use `tgoto' rather than `tparam' to encode the `cm'
capability.