/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2012 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* posix regex executor25* single unsized-string interface26*/2728#include "reglib.h"2930/*31* standard wrapper for the sized-record interface32*/3334int35regexec(const regex_t* p, const char* s, size_t nmatch, regmatch_t* match, regflags_t flags)36{37if (flags & REG_STARTEND)38{39int r;40int m = match->rm_so;41regmatch_t* e;4243if (!(r = regnexec(p, s + m, match->rm_eo - m, nmatch, match, flags)) && m > 0)44for (e = match + nmatch; match < e; match++)45if (match->rm_so >= 0)46{47match->rm_so += m;48match->rm_eo += m;49}50return r;51}52return regnexec(p, s, s ? strlen(s) : 0, nmatch, match, flags);53}5455/*56* 20120528: regoff_t changed from int to ssize_t57*/5859#if defined(__EXPORT__)60#define extern __EXPORT__61#endif6263#undef regexec64#if _map_libc65#define regexec _ast_regexec66#endif6768extern int69regexec(const regex_t* p, const char* s, size_t nmatch, oldregmatch_t* oldmatch, regflags_t flags)70{71if (oldmatch)72{73regmatch_t* match;74size_t i;75int r;7677if (!(match = oldof(0, regmatch_t, nmatch, 0)))78return -1;79if (!(r = regexec_20120528(p, s, nmatch, match, flags)))80for (i = 0; i < nmatch; i++)81{82oldmatch[i].rm_so = match[i].rm_so;83oldmatch[i].rm_eo = match[i].rm_eo;84}85free(match);86return r;87}88return regexec_20120528(p, s, 0, NiL, flags);89}909192