hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

regcomp.c (2393B)


      1 /*
      2  * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002.
      3  *
      4  * Sccsid @(#)regcomp.c	1.6 (gritter) 9/22/03
      5  */
      6 /*  UNIX(R) Regular Expresssion Library
      7  *
      8  *  Note: Code is released under the GNU LGPL
      9  *
     10  *  Copyright (C) 2001 Caldera International, Inc.
     11  *
     12  *  This library is free software; you can redistribute it and/or
     13  *  modify it under the terms of the GNU Lesser General Public
     14  *  License as published by the Free Software Foundation; either
     15  *  version 2 of the License, or (at your option) any later version.
     16  *
     17  *  This library is distributed in the hope that it will be useful,
     18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20  *  Lesser General Public License for more details.
     21  *
     22  *  You should have received a copy of the GNU Lesser General Public
     23  *  License along with this library; if not, write to:
     24  *        Free Software Foundation, Inc.
     25  *        59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     26  */
     27 
     28 /*	#include "synonyms.h"	*/
     29 #include "re.h"
     30 
     31 /*	#pragma weak regcomp = _regcomp	*/
     32 
     33 int
     34 regcomp(regex_t *ep, const char *pat, int flags)
     35 {
     36 	Tree *tp;
     37 	Lex lex;
     38 
     39 	if ((tp=libuxre_regparse(&lex, (const unsigned char *)pat, flags)) == 0)
     40 		goto out;
     41 	ep->re_nsub = lex.nleft;
     42 	ep->re_flags = lex.flags & ~(REG_NOTBOL | REG_NOTEOL | REG_NONEMPTY);
     43 	ep->re_col = lex.col;
     44 	ep->re_mb_cur_max = lex.mb_cur_max;
     45 	/*
     46 	* Build the engine(s).  The factors determining which are built:
     47 	*  1. If the pattern built insists on an NFA, then only build NFA.
     48 	*  2. If flags include REG_NOSUB or REG_ONESUB and not (1),
     49 	*     then only build DFA.
     50 	*  3. Otherwise, build both.
     51 	* Since libuxre_regdfacomp() modifies the tree and libuxre_regnfacomp()
     52 	* doesn't, libuxre_regnfacomp() must be called first, if both are to
     53 	* be called.
     54 	*/
     55 	if (ep->re_nsub != 0 && (flags & (REG_NOSUB | REG_ONESUB)) == 0
     56 		|| lex.flags & REG_NFA)
     57 	{
     58 		ep->re_flags |= REG_NFA;
     59 		if ((lex.err = libuxre_regnfacomp(ep, tp, &lex)) != 0)
     60 			goto out;
     61 	}
     62 	if ((lex.flags & REG_NFA) == 0)
     63 	{
     64 		ep->re_flags |= REG_DFA;
     65 		if ((lex.err = libuxre_regdfacomp(ep, tp, &lex)) != 0)
     66 		{
     67 			if (ep->re_flags & REG_NFA)
     68 				libuxre_regdelnfa(ep->re_nfa);
     69 		}
     70 	}
     71 out:;
     72 	if (lex.err != 0 && lex.col != 0)
     73 		(void)libuxre_lc_collate(lex.col);
     74 	if (tp != 0)
     75 		libuxre_regdeltree(tp, lex.err);
     76 	return lex.err;
     77 }