idefine(3)

Section: Interp SDK (3)
Updated: 2009-07-30

NAME

idefine - implements a substitution-based macro processor

SYNOPSIS

#include itypes.h
#include idefine.h

void init_define( void );
void instal_macro( ibyte *inbuf );
void assign_macro( ibyte *inbuf, Interp_T cp );
void undef_macro( ibyte *inbuf );
void insert_macro( ibyte *name, ibyte *defn );
void remove_macro( ibyte *name );
iword expand_macro(ibyte *inbuf,ibyte *outbuf,iword ondx,iword outmax);
void list_all_macros( void );
void macro_usage_info( void );

DESCRIPTION

This API implements a simple substitution-based macro processor that supports input rescanning - after macro substitution, the resulting text is examined for macros. Macro lookup allows for redefinition of macros - the most recent definition is used. The macros themselves exist in two parts: the name and the definition (substitution text.) This API allows you to add, delete, and list macro definitions, and initiate macro expansion on an input buffer. The term "token", as used here, refers to an unbroken string of letters and digits. All other characters are treated as separators.

LIST OF FUNCTIONS

Function
Description
init_define
Resets the macro name and definition tables to their empty state. This has the effect of removing all existing definitions.
instal_macro
Accepts a pointer to a buffer containing a macro definition of the form:
define name=definition with embedded blanks.
The definition is parsed into its name and definition parts and added to the end of the macro definition tables.
assign_macro
Accepts a pointer to a buffer and a pointer to the interp control block. The buffer contains a macro definition of the form:
assign name=sym
Where sym may take on one of the following values:
%n - Pop the data stack, convert the value to its equivalent Hex-ASCII representation and use the resultant string as the definition, or
%s - Pop the data stack, treat the value as a pointer to a zero terminated string, and use the string as the definition.
The definition is then added to end of the macro definition table.
undef_macro
Accepts a pointer to a buffer containing a macro undefinition of the form:
undefine name.
The undefinition is parsed into its name and the macro is deleted from the table (if it is there.) It is not considered an error to undefine a macro that does not exist.
insert_macro
Accepts pointers to the name and definition strings. Adds the macro to the end of the table.
remove_macro
Accepts a pointer to a buffer containing the name of the macro to be deleted. If the macro name is found in the table, that macro is removed. It is not considered an error to remove a macro that is not in the table.
expand_macro
Accepts pointers to input and output buffers, the output buffer index (where to begin writing in the output buffer), and the maximum index value for the output buffer. The input buffer is read, token by token. If the token is a macro, the definition replaces the name. Replacement text is rescanned for macros. Only tokens that are not macros are copied to the output buffer. The value returned is the new starting index in the output buffer.
list_all_macros
Dumps the content of the macro table to the output.
macro_usage_info
List macroprocessor memory usage information that is intended to be used as a guide for adjusting MAXPTR, MAXTBL, MAXDEF, and BUFSIZE in the Makefile.