ia64/xen-unstable

view tools/xfrd/lexis.h @ 1921:24ecc060e9d7

bitkeeper revision 1.1108.21.1 (41062740xHG36OEbpVAmVX5N9WCaNw)

make vmlinuz really stripped
author cl349@freefall.cl.cam.ac.uk
date Tue Jul 27 09:58:24 2004 +0000 (2004-07-27)
parents 0e23f01219c6
children
line source
1 /*
2 *
3 * This library is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as
5 * published by the Free Software Foundation; either version 2.1 of the
6 * License, or (at your option) any later version. This library is
7 * distributed in the hope that it will be useful, but WITHOUT ANY
8 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this library; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
17 #ifndef _XUTIL_LEXIS_H_
18 #define _XUTIL_LEXIS_H_
20 #include "sys_string.h"
22 #ifdef __KERNEL__
23 # include <linux/ctype.h>
24 #else
25 # include <ctype.h>
26 #endif
28 /** @file
29 * Lexical analysis.
30 */
32 /** Class of characters treated as space. */
33 #define space_class ((char []){ '\n', '\r', '\t', ' ', '\f' , 0 })
35 /** Class of separator characters. */
36 #define sep_class "{}()<>[]@!;"
38 #define comment_class "#"
40 /** Determine if a character is in a given class.
41 *
42 * @param c character to test
43 * @param s null-terminated string of characters in the class
44 * @return 1 if c is in the class, 0 otherwise.
45 */
46 static inline int in_class(int c, const char *s){
47 return s && (strchr(s, c) != 0);
48 }
50 /** Determine if a character is in the space class.
51 *
52 * @param c character to test
53 * @return 1 if c is in the class, 0 otherwise.
54 */
55 static inline int in_space_class(int c){
56 return in_class(c, space_class);
57 }
59 static inline int in_comment_class(int c){
60 return in_class(c, comment_class);
61 }
63 /** Determine if a character is in the separator class.
64 * Separator characters terminate tokens, and do not need space
65 * to separate them.
66 *
67 * @param c character to test
68 * @return 1 if c is in the class, 0 otherwise.
69 */
70 static inline int in_sep_class(int c){
71 return in_class(c, sep_class);
72 }
74 /** Determine if a character is in the alpha class.
75 *
76 * @param c character to test
77 * @return 1 if c is in the class, 0 otherwise.
78 */
79 static inline int in_alpha_class(int c){
80 return isalpha(c);
81 }
83 /** Determine if a character is in the octal digit class.
84 *
85 * @param c character to test
86 * @return 1 if c is in the class, 0 otherwise.
87 */
88 static inline int in_octal_digit_class(int c){
89 return '0' <= c && c <= '7';
90 }
92 /** Determine if a character is in the decimal digit class.
93 *
94 * @param c character to test
95 * @return 1 if c is in the class, 0 otherwise.
96 */
97 static inline int in_decimal_digit_class(int c){
98 return isdigit(c);
99 }
101 /** Determine if a character is in the hex digit class.
102 *
103 * @param c character to test
104 * @return 1 if c is in the class, 0 otherwise.
105 */
106 static inline int in_hex_digit_class(int c){
107 return isdigit(c) || in_class(c, "abcdefABCDEF");
108 }
111 static inline int in_string_quote_class(int c){
112 return in_class(c, "'\"");
113 }
115 static inline int in_printable_class(int c){
116 return ('A' <= c && c <= 'Z')
117 || ('a' <= c && c <= 'z')
118 || ('0' <= c && c <= '9')
119 || in_class(c, "!$%&*+,-./:;<=>?@^_`{|}~");
120 }
122 extern int is_decimal_number(const char *s, int n);
123 extern int is_hex_number(const char *s, int n);
124 extern int is_keyword(const char *s, const char *k);
125 extern int is_keychar(const char *s, char c);
127 #endif /* !_XUTIL_LEXIS_H_ */