Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
OSS Library Calls (a - d) compile(3)
INIT The INIT( ) macro is used for dependent declarations and initializations. In the
regexp.h header file this macro is located right after the compile( ) macro
declarations and opening { (left brace). Your INIT( ) declarations must end with
a ; (semicolon).
The INIT( ) macro is frequently used to set a register variable to point to the
beginning of the regular expression, so that this pointer can be used in declara-
tions for GETC(),PEEKC( ), and UNGETC( ). Alternatively, you can use
INIT( ) to declare external variables that GETC(),PEEKC( ), and UNGETC()
need.
GETC( ) The GETC( ) macro returns the value of the next character (byte) in the regular-
expression pattern. Successive calls to GETC( ) return successive characters of
the regular expression.
PEEKC( ) The PEEKC( ) macro returns the next character (byte) in the regular expression.
Immediate subsequent calls to this macro return the same byte, which is also the
next character returned by the GETC( ) macro.
UNGETC(c)TheUNGETC( ) macro causes the c parameter to be returned by the next call to
the GETC( ) and PEEKC( ) macros. No more than one character of pushback is
ever needed because this character is guaranteed to be the last character read by
the GETC( ) macro. The value of the UNGETC( ) macro is always ignored.
RETURN(ptr)TheRETURN( ) macro is used for normal exit of the compile( ) macro. The
value of the ptr parameter is a pointer to the character following the last charac-
ter of the compiled regular expression. This is useful in programs that manage
memory allocation.
ERROR(val)TheERROR( ) macro is the abnormal return from the compile( ) macro. This
macro should never return from a call. In this macro, val is an error number,
which is described in the ERRORS section of this reference page.
NOTES
The compile( ) macro can be called by native processes only.
The functionality provided by advance( ), compile( ), and step( ) is defined to be obsolete by
POSIX. Functions such as regcomp( ) and regexec() should be used instead.
EXAMPLES
The following is an example of the regular expression macros and calls from the grep command:
#define INIT register char *sp=instring;
#define GETC( ) (*sp++)
#define PEEKC( ) (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return;
#define ERROR(c) regerr( )
#include <regexp.h>
...
compile (patstr, expbuf, &expbuf[ESIZE], ’\0’);
...
if (step (linebuf, expbuf))
succeed( );
...
527187-017 Hewlett-Packard Company 1−123