source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/libxutil/lexis.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

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