Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

advance(3) OSS Library Calls Reference Manual
NAME
advance - Matches regular expressions
LIBRARY
None. This application program interface is implemented as a macro.
SYNOPSIS
#include <regexp.h>
int advance(
const char *string,
const char *expbuf);
extern char *loc1, *loc2, *locs;
PARAMETERS
string Points to a null-terminated string of characters in the step( ) function, to be
searched for a match.
expbuf Points to a character array where the compiled regular expression is stored.
DESCRIPTION
The compile( ), advance( ), and step( ) macros are used for general-purpose expression matching.
The advance( ) macro tests whether an initial substring of the string parameter matches the
expression pointed to by the expbuf parameter. Using the same parameters that were passed to it,
the step( ) macro calls the advance( ) macro. The step( ) macro increments a pointer through the
string parameter characters and calls advance( ) until a nonzero value, which indicates a match,
is returned, or until the end of the expression pointed to by the string parameter is reached. To
unconditionally constrain string to point to the beginning of the expression, call the advance( )
macro directly instead of calling step( ).
When the advance( ) macro encounters an * (asterisk) or a \{ \} sequence in the regular expres-
sion, it advances its pointer to the string to be matched as far as possible and recursively calls
itself, trying to match the remainder of the regular expression. As long as there is no match, the
advance( ) macro backs up along the string until it finds a match or reaches the point in the string
where the initial match with the * or \{ \} character occurred.
It is sometimes desirable to stop this backing up before the initial pointer position in the string is
reached. When the locs global character pointer is matched with the character at the pointer posi-
tion in the string during the backing-up process, the advance( ) macro breaks out of the recursive
loop that backs up and returns the value 0 (zero).
NOTES
The advance( ) macro can be called by native processes only.
The functionality provided by advance( ), compile( ), and step( ) is defined as 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>
...
116 Hewlett-Packard Company 527187-017