--- /dev/null	Tue Feb 13 07:11:51 2018
+++ new/usr/src/lib/libc/port/regex/tre-internal.h	Tue Feb 13 07:11:51 2018
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+  tre-internal.h - TRE internal definitions
+*/
+
+#ifndef	_TRE_INTERNAL_H
+#define	_TRE_INTERNAL_H
+
+#include <sys/sysmacros.h>
+
+#include <bitstring.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "tre.h"
+
+#define	TRE_REGEX_T_FIELD value
+
+#ifdef TRE_DEBUG
+#include <stdio.h>
+#define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/0)
+#else /* !TRE_DEBUG */
+#define DPRINT(msg) do { } while(/*CONSTCOND*/0)
+#endif /* !TRE_DEBUG */
+
+#define elementsof(x)	( sizeof(x) / sizeof(x[0]) )
+
+#define tre_mbrtowc(pwc, s, n, ps) (mbrtowc((pwc), (s), (n), (ps)))
+#define tre_mbrtowc_l(pwc,s,n,ps,l) (mbrtowc_l((pwc), (s), (n), (ps), (l)))
+
+typedef wint_t tre_cint_t;
+#define TRE_CHAR_MAX WCHAR_MAX
+
+#define TRE_MB_CUR_MAX MB_CUR_MAX
+#define TRE_MB_CUR_MAX_L MB_CUR_MAX_L
+
+#define tre_isalnum iswalnum
+#define tre_isalpha iswalpha
+#define tre_isblank iswblank
+#define tre_iscntrl iswcntrl
+#define tre_isdigit iswdigit
+#define tre_isgraph iswgraph
+#define tre_islower iswlower
+#define tre_isprint iswprint
+#define tre_ispunct iswpunct
+#define tre_isspace iswspace
+#define tre_isupper iswupper
+#define tre_isxdigit iswxdigit
+
+#define tre_tolower towlower
+#define tre_toupper towupper
+#define tre_strlen  wcslen
+
+#define tre_isalnum_l iswalnum_l
+#define tre_isdigit_l iswdigit_l
+#define tre_islower_l iswlower_l
+#define tre_isupper_l iswupper_l
+#define tre_isxdigit_l iswxdigit_l
+#define tre_tolower_l towlower_l
+#define tre_toupper_l towupper_l
+
+typedef wctype_t tre_ctype_t;
+#define tre_isctype iswctype
+#define tre_ctype   wctype
+#define tre_isctype_l iswctype_l
+#define tre_ctype_l   wctype_l
+
+typedef enum { STR_WIDE, STR_BYTE, STR_MBS } tre_str_type_t;
+
+/* Returns number of bytes to add to (char *)ptr to make it
+   properly aligned for the type. */
+#define ALIGN(ptr, type) \
+  ((((long)ptr) % sizeof(type)) \
+   ? (sizeof(type) - (((long)ptr) % sizeof(type))) \
+   : 0)
+
+#define STRF "ls"
+
+/* Types to handle bracket expressions. */
+typedef enum {
+  TRE_BRACKET_MATCH_TYPE_UNUSED = 0,
+  TRE_BRACKET_MATCH_TYPE_CHAR,		/* Single character value */
+  TRE_BRACKET_MATCH_TYPE_RANGE_BEGIN,	/* Collation range begin */
+  TRE_BRACKET_MATCH_TYPE_RANGE_END,	/* Collation range end */
+  TRE_BRACKET_MATCH_TYPE_CLASS,		/* Character class */
+  TRE_BRACKET_MATCH_TYPE_EQUIVALENCE,	/* Collation equivalence value */
+} tre_bracket_match_type_t;
+
+typedef struct {
+  tre_bracket_match_type_t type;
+  tre_cint_t value;
+} tre_bracket_match_t;
+
+#define TRE_BRACKET_MATCH_FLAG_NEGATE	1
+
+typedef struct {
+  int num_bracket_matches;
+  int flags;
+  tre_bracket_match_t bracket_matches[0];
+} tre_bracket_match_list_t;
+
+#define SIZEOF_BRACKET_MATCH_LIST_N(n)	(sizeof(tre_bracket_match_list_t) + \
+					 sizeof(tre_bracket_match_t) * (n))
+#define SIZEOF_BRACKET_MATCH_LIST(l)	SIZEOF_BRACKET_MATCH_LIST_N( \
+					 (l)->num_bracket_matches)
+
+/* The "count" field is the number of time the tag was set, initially zero.
+   The "first" field contains the first set value (when "count" equals 1).
+   The "value" field contains the current value of the tag, if "count" is
+   greater than zero (the tag's current value is -1 if "count" is zero).
+   The "touch" field is the touch value, a montonically increasing value
+   (maintained by the caller) set each time the tag itself is set. */
+typedef struct {
+  int count;
+  int first;
+  int value;
+  int touch;
+} tre_tag_t;
+
+/* TNFA transition type. A TNFA state is an array of transitions,
+   the terminator is a transition with NULL `state'. */
+typedef struct tnfa_transition tre_tnfa_transition_t;
+
+struct tnfa_transition {
+  /* Range of accepted characters. */
+  tre_cint_t code_min;
+  tre_cint_t code_max;
+  /* Pointer to the destination state. */
+  tre_tnfa_transition_t *state;
+  /* ID number of the destination state. */
+  int state_id;
+  /* -1 terminated array of tags (or NULL). */
+  int *tags;
+  /* Matching parameters settings (or NULL). */
+  int *params;
+  /* Assertion bitmap. */
+  int assertions;
+  /* Assertion parameters. */
+  union {
+    /* Bracket matches. */
+    tre_bracket_match_list_t *bracket_match_list;
+    /* Back reference assertion. */
+    int backref;
+  } u;
+};
+
+/* Assertions. */
+#define ASSERT_AT_BOL		  1   /* Beginning of line. */
+#define ASSERT_AT_EOL		  2   /* End of line. */
+#define ASSERT_BRACKET_MATCH	  4   /* Matches in `bracket_match_list'. */
+#define ASSERT_AT_BOW		  8   /* Beginning of word. */
+#define ASSERT_AT_EOW		 16   /* End of word. */
+#define ASSERT_AT_WB		 32   /* Word boundary. */
+#define ASSERT_AT_WB_NEG	 64   /* Not a word boundary. */
+#define ASSERT_BACKREF		128   /* A back reference in `backref'. */
+#define ASSERT_LAST		128
+
+/* Tag directions. */
+typedef enum {
+  TRE_TAG_MINIMIZE = 0,
+  TRE_TAG_MAXIMIZE,
+  TRE_TAG_LEFT_MAXIMIZE,
+} tre_tag_direction_t;
+
+/* Parameters that can be changed dynamically while matching. */
+typedef enum {
+  TRE_PARAM_COST_INS	    = 0,
+  TRE_PARAM_COST_DEL	    = 1,
+  TRE_PARAM_COST_SUBST	    = 2,
+  TRE_PARAM_COST_MAX	    = 3,
+  TRE_PARAM_MAX_INS	    = 4,
+  TRE_PARAM_MAX_DEL	    = 5,
+  TRE_PARAM_MAX_SUBST	    = 6,
+  TRE_PARAM_MAX_ERR	    = 7,
+  TRE_PARAM_DEPTH	    = 8,
+  TRE_PARAM_LAST	    = 9
+} tre_param_t;
+
+/* Unset matching parameter */
+#define TRE_PARAM_UNSET -1
+
+/* Signifies the default matching parameter value. */
+#define TRE_PARAM_DEFAULT -2
+
+/* Instructions to compute submatch register values from tag values
+   after a successful match.  */
+struct tre_submatch_data {
+  /* Tag that gives the value for rm_so (submatch start offset). */
+  int so_tag;
+  /* Tag that gives the value for rm_eo (submatch end offset). */
+  int eo_tag;
+};
+
+typedef struct tre_submatch_data tre_submatch_data_t;
+
+/* LAST MATCHED structures */
+struct __previous_type;
+struct __previous_branch_type;
+struct __current_type;
+struct __current_branch_type;
+
+typedef struct __previous_branch_type {
+  struct __previous_branch_type *next;
+  struct __previous_type *last_matched; int n_last_matched; int cmp_tag; int n_tags;
+  int tot_branches;
+  int tot_last_matched;
+  int tot_tags;
+  bitstr_t tags[0];
+} tre_last_matched_branch_pre_t;
+
+typedef struct __previous_type {
+  struct __previous_type *next;
+  tre_last_matched_branch_pre_t *branches; int n_branches; int start_tag;
+  int tot_branches;
+  int tot_last_matched;
+  int tot_tags;
+} tre_last_matched_pre_t;
+
+typedef struct __current_branch_type {
+  int *tags;
+  struct __current_type *last_matched; int n_last_matched; int cmp_tag; int n_tags;
+} tre_last_matched_branch_t;
+
+typedef struct __current_type {
+  tre_last_matched_branch_t *branches; int n_branches; int start_tag;
+} tre_last_matched_t;
+
+/* TNFA definition. */
+typedef struct tnfa tre_tnfa_t;
+
+struct tnfa {
+  tre_tnfa_transition_t *transitions;
+  tre_tnfa_transition_t *initial;
+  tre_tnfa_transition_t *final;
+  tre_submatch_data_t *submatch_data;
+  tre_tag_direction_t *tag_directions;
+  int *minimal_tags;
+  tre_last_matched_branch_t *last_matched_branch;
+  locale_t loc;
+  unsigned int num_transitions;
+  int first_char;
+  unsigned int num_submatches;
+  unsigned int num_submatches_invisible;
+  int num_tags;
+  int num_minimals;
+  int end_tag;
+  int num_states;
+  int cflags;
+  int have_backrefs;
+  int num_reorder_tags;
+  int have_approx;
+  int params_depth;
+};
+
+int
+tre_compile(regex_t *preg, const tre_char_t *regex, size_t n, int cflags,
+	    locale_t loc);
+
+void
+tre_free(regex_t *preg);
+
+reg_errcode_t
+tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags,
+		const tre_tnfa_t *tnfa, const tre_tag_t *tags, int match_eo);
+
+reg_errcode_t
+tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, int len,
+		      tre_str_type_t type, tre_tag_t *match_tags, int eflags,
+		      int *match_end_ofs);
+
+reg_errcode_t
+tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string,
+		       int len, tre_str_type_t type, tre_tag_t *match_tags,
+		       int eflags, int *match_end_ofs);
+
+#endif	/* _TRE_INTERNAL_H */
