/******************************************************************************

       File: mtregex.h
    Package:
Description: thread-safe regular expressions

-------------------------------------------------------------------------------
Copyright (c) 1986 by University of Toronto.
Written by Henry Spencer.  Not derived from licensed software.

Permission is granted to anyone to use this software for any
purpose on any computer system, and to redistribute it freely,
subject to the following restrictions:

1. The author is not responsible for the consequences of use of
   this software, no matter how awful, even if they arise
   from defects in it.

2. The origin of this software must not be misrepresented, either
   by explicit claim or by omission.

3. Altered versions must be plainly marked as such, and must not
   be misrepresented as being the original software.

Beware that some of this code is subtly aware of the way operator
precedence is structured in regular expressions.  Serious changes in
regular-expression syntax might require a total rethink.

Definitions etc. for regexp(3) routines.

Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
not the System V one.
-------------------------------------------------------------------------------

Cleaned up by Alex Meyer (a_l_e_x at i-n-k-t-o-m-i dot c_o_m) 5/5/98
1. Consolidated into one header and one source file
2. Converted to ANSI C
3. Removed globals to make thread-safe
4. Normalized error returns (got rid of regerror)
5. Removed C++ reserved words

$Id$

******************************************************************************/

#ifndef MTREGEX_H
#define MTREGEX_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */


typedef struct {
  char     regstart;    /* Internal use only */
  char     reganch;     /* Internal use only */
  char    *regmust;     /* Internal use only */
  size_t   regmlen;     /* Internal use only */
  char     program[1];  /* Unwarranted chumminess with compiler */
} MtRegexT;


#define NSUBEXP  10

typedef struct {
  const char  *startp[NSUBEXP];
  const char  *endp[NSUBEXP];
} MtRegexMatchT;


#define MTREGEX_SUCCESS  1
#define MTREGEX_FAIL     0

MtRegexT *MtRegexCompile(const char *exp, const char **errmsgP);

int MtRegexMatch(const MtRegexT   *prog,
                 MtRegexMatchT    *matches,
                 const char       *string,
                 const char      **errmsgP);

int MtRegexSubstitute(const MtRegexT        *prog,
                      const MtRegexMatchT   *matches,
                      const char            *source,
                      char                  *dest,
                      const char           **errmsgP);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* !MTREGEX_H */
