os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/generic/regfronts.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * regcomp and regexec - front ends to re_ routines
sl@0
     3
 *
sl@0
     4
 * Mostly for implementation of backward-compatibility kludges.  Note
sl@0
     5
 * that these routines exist ONLY in char versions.
sl@0
     6
 *
sl@0
     7
 * Copyright (c) 1998, 1999 Henry Spencer.  All rights reserved.
sl@0
     8
 * 
sl@0
     9
 * Development of this software was funded, in part, by Cray Research Inc.,
sl@0
    10
 * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
sl@0
    11
 * Corporation, none of whom are responsible for the results.  The author
sl@0
    12
 * thanks all of them. 
sl@0
    13
 * 
sl@0
    14
 * Redistribution and use in source and binary forms -- with or without
sl@0
    15
 * modification -- are permitted for any purpose, provided that
sl@0
    16
 * redistributions in source form retain this entire copyright notice and
sl@0
    17
 * indicate the origin and nature of any modifications.
sl@0
    18
 * 
sl@0
    19
 * I'd appreciate being given credit for this package in the documentation
sl@0
    20
 * of software which uses it, but that is not a requirement.
sl@0
    21
 * 
sl@0
    22
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
sl@0
    23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
sl@0
    24
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
sl@0
    25
 * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sl@0
    26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
sl@0
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
sl@0
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
sl@0
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
sl@0
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
sl@0
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sl@0
    32
 *
sl@0
    33
 */
sl@0
    34
sl@0
    35
#include "regguts.h"
sl@0
    36
sl@0
    37
/*
sl@0
    38
 - regcomp - compile regular expression
sl@0
    39
 */
sl@0
    40
int
sl@0
    41
regcomp(re, str, flags)
sl@0
    42
regex_t *re;
sl@0
    43
CONST char *str;
sl@0
    44
int flags;
sl@0
    45
{
sl@0
    46
	size_t len;
sl@0
    47
	int f = flags;
sl@0
    48
sl@0
    49
	if (f&REG_PEND) {
sl@0
    50
		len = re->re_endp - str;
sl@0
    51
		f &= ~REG_PEND;
sl@0
    52
	} else
sl@0
    53
		len = strlen(str);
sl@0
    54
sl@0
    55
	return re_comp(re, str, len, f);
sl@0
    56
}
sl@0
    57
sl@0
    58
/*
sl@0
    59
 - regexec - execute regular expression
sl@0
    60
 */
sl@0
    61
int
sl@0
    62
regexec(re, str, nmatch, pmatch, flags)
sl@0
    63
regex_t *re;
sl@0
    64
CONST char *str;
sl@0
    65
size_t nmatch;
sl@0
    66
regmatch_t pmatch[];
sl@0
    67
int flags;
sl@0
    68
{
sl@0
    69
	CONST char *start;
sl@0
    70
	size_t len;
sl@0
    71
	int f = flags;
sl@0
    72
sl@0
    73
	if (f&REG_STARTEND) {
sl@0
    74
		start = str + pmatch[0].rm_so;
sl@0
    75
		len = pmatch[0].rm_eo - pmatch[0].rm_so;
sl@0
    76
		f &= ~REG_STARTEND;
sl@0
    77
	} else {
sl@0
    78
		start = str;
sl@0
    79
		len = strlen(str);
sl@0
    80
	}
sl@0
    81
sl@0
    82
	return re_exec(re, start, len, nmatch, pmatch, f);
sl@0
    83
}