hbase

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

regexec.c (1932B)


      1 /*
      2  * Changes by Gunnar Ritter, Freiburg i. Br., Germany, November 2002.
      3  *
      4  * Sccsid @(#)regexec.c	1.7 (gritter) 2/6/05
      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 regexec = _regexec	*/
     32 
     33 int
     34 regexec(const regex_t *ep, const char *s, size_t n, regmatch_t *mp, int flg)
     35 {
     36 	Exec ex;
     37 	int ret;
     38 
     39 	ex.flags = flg | (ep->re_flags & (REG_NEWLINE|REG_ICASE|REG_AVOIDNULL));
     40 	ex.str = (const unsigned char *)s;
     41 	ex.match = mp;
     42 	ex.mb_cur_max = ep->re_mb_cur_max;
     43 	if ((ex.nmatch = n) != 0) /* impose limits from compile flags */
     44 	{
     45 		if (ep->re_flags & REG_NOSUB)
     46 			n = ex.nmatch = 0;
     47 		else if (ep->re_flags & REG_ONESUB)
     48 			ex.nmatch = 1;
     49 		else if (n > ep->re_nsub + 1)
     50 			ex.nmatch = ep->re_nsub + 1;
     51 	}
     52 	if (ep->re_flags & REG_DFA && ex.nmatch <= 1)
     53 		ret = libuxre_regdfaexec(ep->re_dfa, &ex);
     54 	else
     55 		ret = libuxre_regnfaexec(ep->re_nfa, &ex);
     56 	/*
     57 	* Fill unused part of mp[].
     58 	*/
     59 	if (ret != 0)
     60 		ex.nmatch = 0;
     61 	while (n > ex.nmatch)
     62 	{
     63 		n--;
     64 		mp[n].rm_so = -1;
     65 		mp[n].rm_eo = -1;
     66 	}
     67 	return ret;
     68 }