Programming considerations
Consider these points when you are coding a filter program:
- You need to be an experienced programmer who is aware of overall system implications.
- Do not send a long-term explicit or implied WAIT in the filter program because it can reduce the throughput of the Print Interface LPD or IPP Server.
- The filter program runs in 31-bit addressing mode.
- Code the filter program to be reentrant.
- All filter programs run in problem state.
- Programming exceptions cause an Infoprint Server abend. An ESTAE is in effect while a filter program is running.
- A DLL filter, in the initialization function, can obtain a work area and pass a pointer to that work area to other functions in the filter program. Using the work area, one function can pass data to another function.
- Future Infoprint Server program maintenance might require that you recompile your filter programs.
When a UNIX filter reads from stdin, the read function can obtain fewer than the requested number of bytes. You must code your UNIX filter accordingly.
In most programming and scripting languages, the read function obtains the requested number of bytes if the program reads from a file on disk. The read function can obtain fewer than the requested number of bytes if the program reads from a pipe or socket. When Infoprint Server runs a UNIX filter, the UNIX filter's stdin is a pipe. The read function returns zero bytes when end-of-file (end-of-input) is reached on a file, pipe, or socket.
If a UNIX filter needs to
obtain a specific number of bytes from stdin before
it can process the data, it must continue to invoke the read function
until it obtains that number of bytes or end-of-file is reached.
Each time the program invokes the read function, it must adjust the
buffer pointer and bytes requested to account for data that is already
obtained. It is often convenient to create a function in the UNIX filter for this purpose. Here
is some representative pseudo-code:
function: read_x_bytes
input arguments: buffer_ptr
bytes_requested
returns: success or failure
{
curr_ptr = buffer_ptr
total_bytes_obtained = 0
do {
bytes_obtained = read( curr_ptr,
bytes_requested - total_bytes_obtained )
curr_ptr = curr_ptr + bytes_obtained
total_bytes_obtained = total_bytes_obtained + bytes_obtained
} while ((bytes_obtained > 0) AND
(total_bytes_obtained < bytes_requested))
if (total_bytes_obtained EQUALS bytes_requested)
return success
else
return failure
}