Go to the first, previous, next, last section, table of contents.


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. See section 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.

Go to the first, previous, next, last section, table of contents.