1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 * <regexp.h> library support
27 #define _REGEXP_DECLARE
43 block(void* handle
, void* data
, size_t size
)
45 register Env_t
* env
= (Env_t
*)handle
;
47 if (data
|| (size
= roundof(size
, ALIGN_BOUND2
)) > (env
->buf
+ env
->size
- env
->cur
))
49 data
= (void*)env
->cur
;
55 _re_comp(regexp_t
* re
, const char* pattern
, char* handle
, unsigned int size
)
57 register Env_t
* env
= (Env_t
*)handle
;
60 if (size
<= sizeof(Env_t
))
62 env
->buf
= env
->cur
= (char*)env
+ sizeof(Env_t
);
63 env
->size
= size
- sizeof(Env_t
);
64 regalloc(env
, block
, REG_NOFREE
);
65 n
= regcomp(&env
->re
, pattern
, REG_LENIENT
|REG_NULL
);
89 re
->re_nbra
= env
->re
.re_nsub
;
94 _re_exec(regexp_t
* re
, const char* subject
, const char* handle
, int anchor
)
96 register Env_t
* env
= (Env_t
*)handle
;
98 regmatch_t match
[elementsof(re
->re_braslist
)+1];
100 if (regexec(&env
->re
, subject
, elementsof(match
), match
, 0) || anchor
&& match
[0].rm_so
)
102 re
->re_loc1
= (char*)subject
+ match
[0].rm_so
;
103 re
->re_loc2
= (char*)subject
+ match
[0].rm_eo
;
104 for (n
= 1; n
<= env
->re
.re_nsub
; n
++)
106 re
->re_braslist
[n
-1] = (char*)subject
+ match
[n
].rm_so
;
107 re
->re_braelist
[n
-1] = (char*)subject
+ match
[n
].rm_eo
;
117 if (!sp
&& !(sp
= sfstropen()))