/*
regcomp.c - TRE POSIX compatible regex compilation functions.
Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdlib.h>
#include <regex.h>
#include <limits.h>
#include <stdint.h>
#include <ctype.h>
#include "tre.h"
#include <assert.h>
/***********************************************************************
from tre-compile.h
***********************************************************************/
typedef struct {
int position;
int code_min;
int code_max;
int *tags;
int assertions;
tre_ctype_t class;
tre_ctype_t *neg_classes;
int backref;
} tre_pos_and_tags_t;
/***********************************************************************
from tre-ast.c and tre-ast.h
***********************************************************************/
/* The different AST node types. */
typedef enum {
LITERAL,
CATENATION,
ITERATION,
UNION
} tre_ast_type_t;
/* Special subtypes of TRE_LITERAL. */
#define EMPTY -1 /* Empty leaf (denotes empty string). */
#define ASSERTION -2 /* Assertion leaf. */
#define TAG -3 /* Tag leaf. */
#define BACKREF -4 /* Back reference leaf. */
#define IS_SPECIAL(x) ((x)->code_min < 0)
#define IS_EMPTY(x) ((x)->code_min == EMPTY)
#define IS_ASSERTION(x) ((x)->code_min == ASSERTION)
#define IS_TAG(x) ((x)->code_min == TAG)
#define IS_BACKREF(x) ((x)->code_min == BACKREF)
/* A generic AST node. All AST nodes consist of this node on the top
level with `obj' pointing to the actual content. */
typedef struct {
tre_ast_type_t type; /* Type of the node. */
void *obj; /* Pointer to actual node. */
int nullable;
int submatch_id;
int num_submatches;
int num_tags;
tre_pos_and_tags_t *firstpos;
tre_pos_and_tags_t *lastpos;
} tre_ast_node_t;
/* A "literal" node. These are created for assertions, back references,
tags, matching parameter settings, and all expressions that match one
character. */
typedef struct {
long code_min;
long code_max;
int position;
tre_ctype_t class;
tre_ctype_t *neg_classes;
} tre_literal_t;
/* A "catenation" node. These are created when two regexps are concatenated.
If there are more than one subexpressions in sequence, the `left' part
holds all but the last, and `right' part holds the last subexpression
(catenation is left associative). */
typedef struct {
tre_ast_node_t *left;
tre_ast_node_t *right;
} tre_catenation_t;
/* An "iteration" node. These are created for the "*", "+", "?", and "{m,n}"
operators. */
typedef struct {
/* Subexpression to match. */
tre_ast_node_t *arg;
/* Minimum number of consecutive matches. */
int min;
/* Maximum number of consecutive matches. */
int max;
/* If 0, match as many characters as possible, if 1 match as few as
possible. Note that this does not always mean the same thing as
matching as many/few repetitions as possible. */
unsigned int minimal:1;
} tre_iteration_t;
/* An "union" node. These are created for the "|" operator. */
typedef struct {
tre_ast_node_t *left;
tre_ast_node_t *right;
} tre_union_t;
static tre_ast_node_t *
tre_ast_new_node(tre_mem_t mem, int type, void *obj)
{
tre_ast_node_t *node = tre_mem_calloc(mem, sizeof *node);
if (!node || !obj)
return 0;
node->obj = obj;
node->type = type;
node->nullable = -1;
node->submatch_id = -1;
return node;
}
static tre_ast_node_t *
tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position)
{
tre_ast_node_t *node;
tre_literal_t *lit;
lit = tre_mem_calloc(mem, sizeof *lit);
node = tre_ast_new_node(mem, LITERAL, lit);
if (!node)
return 0;
lit->code_min = code_min;
lit->code_max = code_max;
lit->position = position;
return node;
}
static tre_ast_node_t *
tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max, int minimal)
{
tre_ast_node_t *node;
tre_iteration_t *iter;
iter = tre_mem_calloc(mem, sizeof *iter);
node = tre_ast_new_node(mem, ITERATION, iter);
if (!node)
return 0;
iter->arg = arg;
iter->min = min;
iter->max = max;
iter->minimal = minimal;
node->num_submatches = arg->num_submatches;
return node;
}
static tre_ast_node_t *
tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right)
{
tre_ast_node_t *node;
tre_union_t *un;
if (!left)
return right;
un = tre_mem_calloc(mem, sizeof *un);
node = tre_ast_new_node(mem, UNION, un);
if (!node || !right)
return 0;
un->left = left;
un->right = right;
node->num_submatches = left->num_submatches + right->num_submatches;
return node;
}
static tre_ast_node_t *
tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right)
{
tre_ast_node_t *node;
tre_catenation_t *cat;
if (!left)
return right;
cat = tre_mem_calloc(mem, sizeof *cat);
node = tre_ast_new_node(mem, CATENATION, cat);
if (!node)
return 0;
cat->left = left;
cat->right = right;
node->num_submatches = left->num_submatches + right->num_submatches;
return node;
}
/***********************************************************************
from tre-stack.c and tre-stack.h
***********************************************************************/
typedef struct tre_stack_rec tre_stack_t;
/* Creates a new stack object. `size' is initial size in bytes, `max_size'
is maximum size, and `increment' specifies how much more space will be
allocated with realloc() if all space gets used up. Returns the stack
object or NULL if out of memory. */
static tre_stack_t *
tre_stack_new(int size, int max_size, int increment);
/* Frees the stack object. */
static void
tre_stack_destroy(tre_stack_t *s);
/* Returns the current number of objects in the stack. */
static int
tre_stack_num_objects(tre_stack_t *s);
/* Each tre_stack_push_*(tre_stack_t *s, <type> value) function pushes
`value' on top of stack `s'. Returns REG_ESPACE if out of memory.
This tries to realloc() more space before failing if maximum size
has not yet been reached. Returns REG_OK if successful. */
#define declare_pushf(typetag, type) \
static reg_errcode_t tre_stack_push_ ## typetag(tre_stack_t *s, type value)
declare_pushf(voidptr, void *);
declare_pushf(int, int);
/* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost
element off of stack `s' and returns it. The stack must not be
empty. */
#define declare_popf(typetag, type) \
static type tre_stack_pop_ ## typetag(tre_stack_t *s)
declare_popf(voidptr, void *);
declare_popf(int, int);
/* Just to save some typing. */
#define STACK_PUSH(s, typetag, value) \
do \
{ \
status = tre_stack_push_ ## typetag(s, value);
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共2000个文件
c:1583个
h:414个
sh:3个
musl libc 是一个轻量级的 C 标准库实现,与其他 C 标准库有着一些显著的区别和特点。 它非常适合用于嵌入式系统的开发。嵌入式系统通常对资源消耗有较高要求,而 musl libc 的小体积和高效性使得它成为开发嵌入式系统的理想选择。 一些 Linux 发行版如 Alpine Linux 就采用了 musl libc 作为其默认的 C 标准库实现。相比其他标准库,musl libc 更加轻量,因此在资源受限的环境下可以提供更好的性能。 对于追求性能的计算任务,musl libc 也可以发挥其优势。在一些高性能计算领域,开发者可能会选择使用 musl libc 来取得更好的性能表现。 由于 musl libc 对安全性有着极高的要求,一些对安全性要求较高的应用场景也会选择使用 musl libc。这包括一些安全相关的系统软件、网络安全产品等。 musl libc 遵循 POSIX 标准,提供了符合 POSIX 规范的函数和接口。因此,它也适用于跨平台开发,可以在不同的 POSIX 兼容系统上进行良好的移植性。
资源推荐
资源详情
资源评论
收起资源包目录
musl libc 源码实现 (2000个子文件)
regcomp.c 74KB
dynlink.c 66KB
crypt_des.c 33KB
crypt_blowfish.c 29KB
regexec.c 28KB
exp2l.c 20KB
vfprintf.c 16KB
__rem_pio2_large.c 16KB
iconv.c 14KB
j0.c 14KB
log_data.c 14KB
j1.c 13KB
malloc.c 13KB
lookup_name.c 12KB
powl.c 12KB
erfl.c 12KB
lgammal.c 12KB
pthread_create.c 11KB
crypt_sha512.c 11KB
aio.c 11KB
pow.c 11KB
pow_data.c 10KB
lgamma_r.c 10KB
erf.c 10KB
__tz.c 10KB
malloc.c 10KB
floatscan.c 10KB
vfwprintf.c 9KB
res_msend.c 9KB
j0f.c 9KB
j1f.c 8KB
crypt_sha256.c 8KB
fmal.c 8KB
crypt_md5.c 8KB
glob.c 8KB
log2_data.c 8KB
fnmatch.c 7KB
jn.c 7KB
expm1.c 7KB
sysconf.c 7KB
tgammal.c 6KB
exp_data.c 6KB
dcngettext.c 6KB
vfscanf.c 6KB
lgammaf_r.c 6KB
getifaddrs.c 6KB
vfwscanf.c 6KB
strftime.c 6KB
pthread_cond_timedwait.c 5KB
sqrtl.c 5KB
tgamma.c 5KB
atanl.c 5KB
posix_spawn.c 5KB
__tanl.c 5KB
erff.c 5KB
ioctl.c 5KB
qsort.c 5KB
powf.c 5KB
getnameinfo.c 5KB
log10l.c 5KB
__rem_pio2l.c 5KB
ccosh.c 5KB
dlstart.c 5KB
csinh.c 5KB
__rem_pio2.c 5KB
logl.c 5KB
log2l.c 4KB
sqrt.c 4KB
jnf.c 4KB
exp.c 4KB
log1pl.c 4KB
sem_open.c 4KB
ctanh.c 4KB
strptime.c 4KB
exp2.c 4KB
tre-mem.c 4KB
fstatat.c 4KB
__tan.c 4KB
atan.c 4KB
ns_parse.c 4KB
clock_adjtime.c 4KB
free.c 4KB
log1p.c 4KB
__cosl.c 4KB
getopt_long.c 4KB
__init_tls.c 4KB
cbrt.c 4KB
getaddrinfo.c 4KB
fma.c 4KB
expm1l.c 4KB
realpath.c 4KB
expl.c 3KB
strstr.c 3KB
memmem.c 3KB
log2.c 3KB
pleval.c 3KB
asin.c 3KB
getgr_a.c 3KB
__cexp.c 3KB
atan2.c 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
我要出家当道士
- 粉丝: 9877
- 资源: 46
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功