HP 3000 Manuals

regcomp [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

regcomp 

Compile a regular expression.

Syntax 

     #include <regex.h>
     int regcomp (regex_t *reg, const char *regstr, int flags);

Parameters 

reg              points to an object where regcomp() stores the compiled
                 regular expression.  regex_t is defined in <regex.h>.

regstr           points to the regular expression as a string (the way it
                 might be specified for a command like grep).

flags            gives a variety of flags for the compilation.  Flags are
                 given by symbols defined in <regex.h> which can be ORed
                 together.  The recognized symbols are:

                 REG_EXTENDED           uses extended regular expressions
                                        (see regexp(3)).  The default is
                                        to interpret regstr as a basic
                                        regular expression.

                 REG_ICASE              ignores the case of letters in
                                        matches.  The setting of LC_CTYPE
                                        affects which characters are
                                        considered to be opposite cases
                                        of each other.

                 REG_NEWLINE            treats the newline character as a
                                        regular character, without its
                                        special meaning.

                 REG_NOSUB              indicates that regcomp() should
                                        only report success or failure,
                                        and not set reg->re_nsub (see the
                                        following section).  It also
                                        affects the behavior of
                                        regexec(3)

Return Values 

0          Successful compile

Error      Not successful compile
code

Description 

regcomp() compiles a regular expression for later use.  Early
implementations of regcomp() generated executable code that determined
whether or not strings matched regstr.  Under POSIX.2, regcomp() may
generate executable code and/or data which speeds pattern-matching.  The
result of regcomp() is a structure of the regex_t type which is stored in
reg.  This structure type contains at least the following field:

size_t     is usually set to the number of parenthesized subexpressions
re_nsub    found in regstr.  These subexpressions are delimited with

                \(\)

           in basic regular expressions and

                ()

           in extended regular expressions.  regcomp() does not set
           re_nsub if REG_NOSUB is turned on in flags.

Errors 

If regcomp() successfully compiles regstr it returns zero; otherwise, it
returns one of the following symbolic values:

REG_BADBR         CAUSE           The contents of

                                       \{\}

                                  were invalid:  not a number, too large a number, more
                                  than two numbers, first number larger than second.
                  ACTION          Make sure that the contents of \{\} or {} are valid.

          Table 4-0.  (cont.) 

REG_BADPAT        CAUSE           regstr was an invalid regular expression.
                  ACTION          Specify a valid regular expression

REG_BADRPT        CAUSE           regstr contained a ?, *, or + that was not preceded
                                  by a valid regular expression.
                  ACTION          Make sure that every unquoted /, *, or + in regstr is
                                  preceded by a valid regular expression.

REG_EBRACE        CAUSE           regstr contained a \{\} imbalance.
                  ACTION          Make sure that all { and } characters and all \{ and
                                  \} characters appear in matched pairs in regstr.

REG_EBRACK        CAUSE           regstr contained a [] imbalance.
                  ACTION          Make sure that all [ and ] characters appear in
                                  matched pairs in regstr.

REG_ECOLLATE      CAUSE           regstr contained a reference to an invalid collating
                                  element.
                  ACTION          Make sure that all collating elements referenced in
                                  regstr are valid in the locale indicated by
                                  LC_COLLATE.

REG_ECTYPE        CAUSE           regstr contained a reference to an invalid character
                                  class.
                  ACTION          Make sure that all character classes referenced in
                                  regstr are valid in the locale indicated by LC_CTYPE.

REG_EESCAPE       CAUSE           regstr contained a trailing \.
                  ACTION          Remove the trailing \ or complete the escape
                                  sequence.

REG_ENEWLINE      CAUSE           A newline was found before the end of a pattern, and
                                  the REG_ENEWLINE flag was not set.
                  ACTION          Set the REG_ENEWLINE flag, or check the pattern for a
                                  missing /.

REG_EPAREN        CAUSE           regstr contained a () or \(\) imbalance.
                  ACTION          Make sure that all ( and ) characters and all \( and
                                  \) characters appear in matched pairs in regstr.

          Table 4-0.  (cont.) 

REG_ERANGE        CAUSE           A range expression contained an invalid endpoint.
                                  For example, an equivalence or character class is not
                                  valid.
                  ACTION          Specify a valid endpoint.

REG_ESPACE        CAUSE           There were not enough free system resources for
                                  regcomp() to compile regstr 
                  ACTION          Free up more resources or specify a less complex
                                  regular expression.

REG_ESUBREG       CAUSE           The number in a \number construct was greater than
                                  the number of matching subexpressions.
                  ACTION          Make sure that number is less than or equal to the
                                  number of matching subexpressions.

REG_EFATAL        CAUSE           An internal error occurred.
                  ACTION          Contact your system manager.

See Also 

grep(1), regexec(), regfree(), regexp(3)



MPE/iX 5.0 Documentation