sl@0: /* sl@0: * regcomp and regexec - front ends to re_ routines sl@0: * sl@0: * Mostly for implementation of backward-compatibility kludges. Note sl@0: * that these routines exist ONLY in char versions. sl@0: * sl@0: * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. sl@0: * sl@0: * Development of this software was funded, in part, by Cray Research Inc., sl@0: * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics sl@0: * Corporation, none of whom are responsible for the results. The author sl@0: * thanks all of them. sl@0: * sl@0: * Redistribution and use in source and binary forms -- with or without sl@0: * modification -- are permitted for any purpose, provided that sl@0: * redistributions in source form retain this entire copyright notice and sl@0: * indicate the origin and nature of any modifications. sl@0: * sl@0: * I'd appreciate being given credit for this package in the documentation sl@0: * of software which uses it, but that is not a requirement. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, sl@0: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY sl@0: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL sl@0: * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, sl@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, sl@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; sl@0: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, sl@0: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR sl@0: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF sl@0: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sl@0: * sl@0: */ sl@0: sl@0: #include "regguts.h" sl@0: sl@0: /* sl@0: - regcomp - compile regular expression sl@0: */ sl@0: int sl@0: regcomp(re, str, flags) sl@0: regex_t *re; sl@0: CONST char *str; sl@0: int flags; sl@0: { sl@0: size_t len; sl@0: int f = flags; sl@0: sl@0: if (f®_PEND) { sl@0: len = re->re_endp - str; sl@0: f &= ~REG_PEND; sl@0: } else sl@0: len = strlen(str); sl@0: sl@0: return re_comp(re, str, len, f); sl@0: } sl@0: sl@0: /* sl@0: - regexec - execute regular expression sl@0: */ sl@0: int sl@0: regexec(re, str, nmatch, pmatch, flags) sl@0: regex_t *re; sl@0: CONST char *str; sl@0: size_t nmatch; sl@0: regmatch_t pmatch[]; sl@0: int flags; sl@0: { sl@0: CONST char *start; sl@0: size_t len; sl@0: int f = flags; sl@0: sl@0: if (f®_STARTEND) { sl@0: start = str + pmatch[0].rm_so; sl@0: len = pmatch[0].rm_eo - pmatch[0].rm_so; sl@0: f &= ~REG_STARTEND; sl@0: } else { sl@0: start = str; sl@0: len = strlen(str); sl@0: } sl@0: sl@0: return re_exec(re, start, len, nmatch, pmatch, f); sl@0: }