Cross Reference: regclass.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libast
/
common
/
regex
/
regclass.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
1
N/A
/***********************************************************************
1
N/A
* *
1
N/A
* This software is part of the ast package *
1
N/A
* Copyright (c) 1985-2011 AT&T Intellectual Property *
1
N/A
* and is licensed under the *
1
N/A
* Common Public License, Version 1.0 *
1
N/A
* by AT&T Intellectual Property *
1
N/A
* *
1
N/A
* A copy of the License is available at *
1
N/A
*
http://www.opensource.org/licenses/cpl1.0.txt
*
1
N/A
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1
N/A
* *
1
N/A
* Information and Software Systems Research *
1
N/A
* AT&T Research *
1
N/A
* Florham Park NJ *
1
N/A
* *
1
N/A
* Glenn Fowler <gsf@research.att.com> *
1
N/A
* David Korn <dgk@research.att.com> *
1
N/A
* Phong Vo <kpv@research.att.com> *
1
N/A
* *
1
N/A
***********************************************************************/
1
N/A
#
pragma
prototyped
1
N/A
/*
1
N/A
* RE character class support
1
N/A
*/
1
N/A
1
N/A
#
include
"
reglib.h
"
1
N/A
1
N/A
struct
Ctype_s
;
typedef
struct
Ctype_s
Ctype_t
;
1
N/A
1
N/A
struct
Ctype_s
1
N/A
{
1
N/A
const
char
*
name
;
1
N/A
size_t
size
;
1
N/A
regclass_t
ctype
;
1
N/A
Ctype_t
*
next
;
1
N/A
#
if
_lib_wctype
1
N/A
wctype_t
wtype
;
1
N/A
#
endif
1
N/A
};
1
N/A
1
N/A
static
Ctype_t
*
ctypes
;
1
N/A
1
N/A
/*
1
N/A
* this stuff gets around posix failure to define isblank,
1
N/A
* and the fact that ctype functions are macros
1
N/A
* and any local extensions that may not even have functions or macros
1
N/A
*/
1
N/A
1
N/A
#
if
_need_iswblank
1
N/A
1
N/A
int
1
N/A
_reg_iswblank
(
wint_t
wc
)
1
N/A
{
1
N/A
static
int
initialized
;
1
N/A
static
wctype_t
wt
;
1
N/A
1
N/A
if
(!
initialized
)
1
N/A
{
1
N/A
initialized
=
1
;
1
N/A
wt
=
wctype
(
"blank"
);
1
N/A
}
1
N/A
return
iswctype
(
wc
,
wt
);
1
N/A
}
1
N/A
1
N/A
#
endif
1
N/A
1
N/A
static
int
Isalnum
(
int
c) {
return
iswalnum
(c); }
1
N/A
static
int
Isalpha
(
int
c) {
return
iswalpha
(c); }
1
N/A
static
int
Isblank
(
int
c) {
return
iswblank
(c); }
1
N/A
static
int
Iscntrl
(
int
c) {
return
iswcntrl
(c); }
1
N/A
static
int
Isdigit
(
int
c) {
return
iswdigit
(c); }
1
N/A
static
int
Notdigit
(
int
c) {
return
!
iswdigit
(c); }
1
N/A
static
int
Isgraph
(
int
c) {
return
iswgraph
(c); }
1
N/A
static
int
Islower
(
int
c) {
return
iswlower
(c); }
1
N/A
static
int
Isprint
(
int
c) {
return
iswprint
(c); }
1
N/A
static
int
Ispunct
(
int
c) {
return
iswpunct
(c); }
1
N/A
static
int
Isspace
(
int
c) {
return
iswspace
(c); }
1
N/A
static
int
Notspace
(
int
c) {
return
!
iswspace
(c); }
1
N/A
static
int
Isupper
(
int
c) {
return
iswupper
(c); }
1
N/A
static
int
Isword
(
int
c) {
return
iswalnum
(c) || c ==
'_'
; }
1
N/A
static
int
Notword
(
int
c) {
return
!
iswalnum
(c) && c !=
'_'
; }
1
N/A
static
int
Isxdigit
(
int
c) {
return
iswxdigit
(c);}
1
N/A
1
N/A
#
if
_lib_wctype
1
N/A
1
N/A
static
int
Is_wc_1
(
int
);
1
N/A
static
int
Is_wc_2
(
int
);
1
N/A
static
int
Is_wc_3
(
int
);
1
N/A
static
int
Is_wc_4
(
int
);
1
N/A
static
int
Is_wc_5
(
int
);
1
N/A
static
int
Is_wc_6
(
int
);
1
N/A
static
int
Is_wc_7
(
int
);
1
N/A
static
int
Is_wc_8
(
int
);
1
N/A
static
int
Is_wc_9
(
int
);
1
N/A
static
int
Is_wc_10
(
int
);
1
N/A
static
int
Is_wc_11
(
int
);
1
N/A
static
int
Is_wc_12
(
int
);
1
N/A
static
int
Is_wc_13
(
int
);
1
N/A
static
int
Is_wc_14
(
int
);
1
N/A
static
int
Is_wc_15
(
int
);
1
N/A
static
int
Is_wc_16
(
int
);
1
N/A
1
N/A
#
endif
1
N/A
1
N/A
#
define
SZ
(s) s,(
sizeof
(s)-
1
)
1
N/A
1
N/A
static
Ctype_t
ctype
[] =
1
N/A
{
1
N/A
{
SZ
(
"alnum"
),
Isalnum
},
1
N/A
{
SZ
(
"alpha"
),
Isalpha
},
1
N/A
{
SZ
(
"blank"
),
Isblank
},
1
N/A
{
SZ
(
"cntrl"
),
Iscntrl
},
1
N/A
{
SZ
(
"digit"
),
Isdigit
},
1
N/A
{
SZ
(
"graph"
),
Isgraph
},
1
N/A
{
SZ
(
"lower"
),
Islower
},
1
N/A
{
SZ
(
"print"
),
Isprint
},
1
N/A
{
SZ
(
"punct"
),
Ispunct
},
1
N/A
{
SZ
(
"space"
),
Isspace
},
1
N/A
{
SZ
(
"upper"
),
Isupper
},
1
N/A
{
SZ
(
"word"
),
Isword
},
1
N/A
{
SZ
(
"xdigit"
),
Isxdigit
},
1
N/A
1
N/A
#
define
CTYPES
13
1
N/A
1
N/A
#
if
_lib_wctype
1
N/A
{ 0, 0,
Is_wc_1
},
1
N/A
{ 0, 0,
Is_wc_2
},
1
N/A
{ 0, 0,
Is_wc_3
},
1
N/A
{ 0, 0,
Is_wc_4
},
1
N/A
{ 0, 0,
Is_wc_5
},
1
N/A
{ 0, 0,
Is_wc_6
},
1
N/A
{ 0, 0,
Is_wc_7
},
1
N/A
{ 0, 0,
Is_wc_8
},
1
N/A
{ 0, 0,
Is_wc_9
},
1
N/A
{ 0, 0,
Is_wc_10
},
1
N/A
{ 0, 0,
Is_wc_11
},
1
N/A
{ 0, 0,
Is_wc_12
},
1
N/A
{ 0, 0,
Is_wc_13
},
1
N/A
{ 0, 0,
Is_wc_14
},
1
N/A
{ 0, 0,
Is_wc_15
},
1
N/A
{ 0, 0,
Is_wc_16
},
1
N/A
1
N/A
#
define
WTYPES
16
1
N/A
1
N/A
#
else
1
N/A
1
N/A
#
define
WTYPES
0
1
N/A
1
N/A
#
endif
1
N/A
};
1
N/A
1
N/A
#
if
_lib_wctype
1
N/A
1
N/A
static
int
Is_wc_1
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+0].
wtype
); }
1
N/A
static
int
Is_wc_2
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
1
].
wtype
); }
1
N/A
static
int
Is_wc_3
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
2
].
wtype
); }
1
N/A
static
int
Is_wc_4
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
3
].
wtype
); }
1
N/A
static
int
Is_wc_5
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
4
].
wtype
); }
1
N/A
static
int
Is_wc_6
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
5
].
wtype
); }
1
N/A
static
int
Is_wc_7
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
6
].
wtype
); }
1
N/A
static
int
Is_wc_8
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
7
].
wtype
); }
1
N/A
static
int
Is_wc_9
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
8
].
wtype
); }
1
N/A
static
int
Is_wc_10
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
9
].
wtype
); }
1
N/A
static
int
Is_wc_11
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
10
].
wtype
); }
1
N/A
static
int
Is_wc_12
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
11
].
wtype
); }
1
N/A
static
int
Is_wc_13
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
12
].
wtype
); }
1
N/A
static
int
Is_wc_14
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
13
].
wtype
); }
1
N/A
static
int
Is_wc_15
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
14
].
wtype
); }
1
N/A
static
int
Is_wc_16
(
int
c) {
return
iswctype
(c,
ctype
[
CTYPES
+
15
].
wtype
); }
1
N/A
1
N/A
#
endif
1
N/A
1
N/A
/*
1
N/A
* return pointer to ctype function for :class:] in s
1
N/A
* s points to the first char after the initial [
1
N/A
* dynamic wctype classes are locale-specific
1
N/A
* dynamic entry locale is punned in Ctype_t.next
1
N/A
* the search does a lazy (one entry at a time) flush on locale mismatch
1
N/A
* if e!=0 it points to next char in s
1
N/A
* 0 returned on error
1
N/A
*/
1
N/A
1
N/A
regclass_t
1
N/A
regclass
(
const
char
* s,
char
** e)
1
N/A
{
1
N/A
register
Ctype_t
*
cp
;
1
N/A
register
int
c;
1
N/A
register
size_t
n;
1
N/A
register
const
char
* t;
1
N/A
Ctype_t
*
lc
;
1
N/A
Ctype_t
*
xp
;
1
N/A
Ctype_t
*
zp
;
1
N/A
1
N/A
if
(!(c = *s++))
1
N/A
return
0;
1
N/A
for
(t = s; *t && (*t != c || *(t +
1
) !=
']'
); t++);
1
N/A
if
(*t != c || !(n = t - s))
1
N/A
return
0;
1
N/A
for
(
cp
=
ctypes
;
cp
;
cp
=
cp
->
next
)
1
N/A
if
(n ==
cp
->
size
&&
strneq
(s,
cp
->
name
, n))
1
N/A
goto
found
;
1
N/A
xp
=
zp
= 0;
1
N/A
lc
= (
Ctype_t
*)
setlocale
(
LC_CTYPE
,
NiL
);
1
N/A
for
(
cp
=
ctype
;
cp
< &
ctype
[
elementsof
(
ctype
)];
cp
++)
1
N/A
{
1
N/A
#
if
_lib_wctype
1
N/A
if
(!
zp
)
1
N/A
{
1
N/A
if
(!
cp
->
size
)
1
N/A
zp
=
cp
;
1
N/A
else
if
(!
xp
&&
cp
->
next
&&
cp
->
next
!=
lc
)
1
N/A
xp
=
cp
;
1
N/A
}
1
N/A
#
endif
1
N/A
if
(n ==
cp
->
size
&&
strneq
(s,
cp
->
name
, n) && (!
cp
->
next
||
cp
->
next
==
lc
))
1
N/A
goto
found
;
1
N/A
}
1
N/A
#
if
_lib_wctype
1
N/A
if
(!(
cp
=
zp
))
1
N/A
{
1
N/A
if
(!(
cp
=
xp
))
1
N/A
return
0;
1
N/A
cp
->
size
= 0;
1
N/A
if
(!
streq
(
cp
->
name
, s))
1
N/A
{
1
N/A
free
((
char
*)
cp
->
name
);
1
N/A
cp
->
name
= 0;
1
N/A
}
1
N/A
}
1
N/A
if
(!
cp
->
name
)
1
N/A
{
1
N/A
if
(!(
cp
->
name
= (
const
char
*)
memdup
(s, n +
1
)))
1
N/A
return
0;
1
N/A
*((
char
*)
cp
->
name
+ n) = 0;
1
N/A
}
1
N/A
/* mvs.390 needs the (char*) cast -- barf */
1
N/A
if
(!(
cp
->
wtype
=
wctype
((
char
*)
cp
->
name
)))
1
N/A
{
1
N/A
free
((
char
*)
cp
->
name
);
1
N/A
cp
->
name
= 0;
1
N/A
return
0;
1
N/A
}
1
N/A
cp
->
size
= n;
1
N/A
cp
->
next
=
lc
;
1
N/A
#
endif
1
N/A
found
:
1
N/A
if
(e)
1
N/A
*e = (
char
*)t +
2
;
1
N/A
return
cp
->
ctype
;
1
N/A
}
1
N/A
1
N/A
/*
1
N/A
* associate the ctype function fun with name
1
N/A
*/
1
N/A
1
N/A
int
1
N/A
regaddclass
(
const
char
*
name
,
regclass_t
fun
)
1
N/A
{
1
N/A
register
Ctype_t
*
cp
;
1
N/A
register
Ctype_t
*
np
;
1
N/A
register
size_t
n;
1
N/A
1
N/A
n =
strlen
(
name
);
1
N/A
for
(
cp
=
ctypes
;
cp
;
cp
=
cp
->
next
)
1
N/A
if
(
cp
->
size
== n &&
strneq
(
name
,
cp
->
name
, n))
1
N/A
{
1
N/A
cp
->
ctype
=
fun
;
1
N/A
return
0;
1
N/A
}
1
N/A
if
(!(
np
=
newof
(0,
Ctype_t
,
1
, n +
1
)))
1
N/A
return
REG_ESPACE
;
1
N/A
np
->
size
= n;
1
N/A
np
->
name
=
strcpy
((
char
*)(
np
+
1
),
name
);
1
N/A
np
->
ctype
=
fun
;
1
N/A
np
->
next
=
ctypes
;
1
N/A
ctypes
=
np
;
1
N/A
return
0;
1
N/A
}
1
N/A
1
N/A
/*
1
N/A
* return pointer to ctype function for token
1
N/A
*/
1
N/A
1
N/A
regclass_t
1
N/A
classfun
(
int
type
)
1
N/A
{
1
N/A
switch
(
type
)
1
N/A
{
1
N/A
case
T_ALNUM
:
return
Isword
;
1
N/A
case
T_ALNUM_NOT
:
return
Notword
;
1
N/A
case
T_DIGIT
:
return
Isdigit
;
1
N/A
case
T_DIGIT_NOT
:
return
Notdigit
;
1
N/A
case
T_SPACE
:
return
Isspace
;
1
N/A
case
T_SPACE_NOT
:
return
Notspace
;
1
N/A
}
1
N/A
return
0;
1
N/A
}