ASE provides an embeddable processor of a dialect of the AWK programming language. The language implemented is slightly different from {the version developed by Brian W. Kernighan, http://cm.bell-labs.com/cm/cs/awkbook/index.html} and has been adjusted to the author's preference.
A set of primitive functions is needed to create an instance of the AWK processor. A primitive function is a user-defined function to help the library perform system-dependent operations such as memory allocation, character class handling.
A caller of ##ase_awk_open## should fill in most of the fields of a ##ase_awk_prmfns_t## structure and pass the structure to it. The function pointers in the miscellaneous group labeled [misc] is defined as follows:
The fourth field of the group is passed to its member functions as the first argument on invocation. The function pointed by the ##sprintf## field should ensure that the resuliting string is null-terminated and ##%s## and ##%c## are accepted for the ##ase_char_t*## and ##ase_char_t## type respectively regardless the character mode.
The functions in these groups perform the memory operations and character class related operations respectively. They follow the style of the memory allocation functions and character class handling functions of the standard C library except that they accept a pointer to the user-defined data as the first argument, thus providing more flexibility. The pointer to the user-defined data is specified into the ##custom_data## field of each group. The ##realloc## field, however, can be ##ASE_NULL##, in which case the functions pointed by the free and the malloc field replace the role of the function pointed by the ##realloc## field.
The source code is handled by a source input handler provided by the user. The optional source code output handler can be provided to have the internal parse tree converted back to the source code.
The ##in## field of the ase_awk_srcios_t is mandatory and should be filled in. The ##out## field can be set to ##ASE_NULL## or can point to a source output handling function. The ##custom_data## field is passed to the source handlers as the second argument. The first parameter ##cmd## of the source input handler is one of ##ASE_AWK_IO_OPEN##, ##ASE_AWK_IO_CLOSE##, ##ASE_AWK_IO_READ##. The first parameter ##cmd## of the source output handler is one of ##ASE_AWK_IO_OPEN##, ##ASE_AWK_IO_CLOSE##, ##ASE_AWK_IO_WRITE##. The third parameter ##data## and the fourth parameter ##count## are the pointer to the buffer to read data into and its size if the first parameter ##cmd## is ##ASE_AWK_IO_READ## while they are the pointer to the data and its size if ##cmd## is ##ASE_AWK_IO_WRITE##.
The source handler should return a negative value for an error and zero or a positive value otherwise. However, there is a subtle difference in the meaning of the return value depending on the value of the first parameter ##cmd##.
When ##cmd## is ##ASE_AWK_IO_OPEN##, the return value of -1 and 1 indicates the failure and the success respectively. In addition, the return value of 0 indicates that the operation is successful but has reached the end of the stream. The library calls the handler with ##ASE_AWK_IO_CLOSE## for deinitialization if the return value is 0 or 1. When ##cmd## is ##ASE_AWK_IO_CLOSE##, the return value of -1 and 0 indicate the failure and the success respectively. When ##cmd## is ##ASE_AWK_IO_READ## or ##ASE_AWK_IO_WRITE##, the return value of -1 indicates the failure, 0 the end of the stream, and other positive values the number of characters read or written.