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 ***********************************************************************/
32 #if CC_NATIVE == CC_ASCII
39 * return a pointer to the isalpha() identifier matching
40 * name in the CC_ASCII sorted tab of num elements of
41 * size siz where the first member of each
44 * [xxx] brackets optional identifier characters
45 * * starts optional identifier characters
47 * 0 returned if name not found
48 * otherwise if next!=0 then it points to the next
49 * unmatched char in name
53 strpsearch(const void* tab
, size_t num
, size_t siz
, const char* name
, char** next
)
55 register char* lo
= (char*)tab
;
56 register char* hi
= lo
+ (num
- 1) * siz
;
58 #if CC_NATIVE != CC_ASCII
59 register unsigned char* m
;
61 register unsigned char* s
;
62 register unsigned char* t
;
67 #if CC_NATIVE != CC_ASCII
68 m
= ccmap(CC_NATIVE
, CC_ASCII
);
70 c
= MAP(m
, *((unsigned char*)name
));
73 mid
= lo
+ (sequential
? 0 : (((hi
- lo
) / siz
) / 2) * siz
);
74 if (!(v
= c
- MAP(m
, *(s
= *((unsigned char**)mid
)))) || *s
== '[' && !(v
= c
- MAP(m
, *++s
)) && (v
= 1))
76 t
= (unsigned char*)name
;
79 if (!v
&& (*s
== '[' || *s
== '*'))
84 else if (v
&& *s
== ']')
89 else if (!isalpha(*t
))
99 while ((mid
-= siz
) >= lo
&& (s
= *((unsigned char**)mid
)) && ((c
== MAP(m
, *s
)) || *s
== '[' && c
== MAP(m
, *(s
+ 1))));
107 v
= MAP(m
, *t
) - MAP(m
, *s
);