The EXEC command allows externally defined subroutines to be accessed from the sort. It allows different sorting and storage algorithms to be used via the sort language.
<function-name
> is a string by which the new external routine is known.
The arguments associated with <function-name
>
are specific to the corresponding routine.
<function-name
>
will be forced to be LOWER-case, see example below.
The return code of the routine is tested for success. A non-zero return code will stop processing the current event at that point.
There are two sets of arguments, associated with the two routines defined below in the C language ...
The <function-name
>_init
routine is optional, and will only be executed if the
init
section of the exec command is specified.
If present, the init routine will be executed once only before
any events are processed.
The current maximum number of arguments that may be passed to an
exec routine may be found in Appendix A.
Example
... exec printit sortword ...
will require the following C code ...
int printit(short *sortword) { printf("Sortword value = %d\n",*sortword); return 0; }
If it is necessary to execute a routine to tidy up after the sort has finished, but not yet exited, a hook mechanism is provided for that purpose. This allows a user-provided routine to be executed at the sort program flushing stage immediately before exit. The mechanism to connect the routine into the sort program is to execute a routine called flush_hook_add() in the <function-name>_init routine.
Such a mechanism could be useful if the current state or a set of variables needs to be saved.