xref: /titanic_51/usr/src/uts/common/sys/kobj_lex.h (revision a8ae99647dd4d540346030718e08a083b0fbdf42)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_KOBJ_LEX_H
28 #define	_SYS_KOBJ_LEX_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * This file contains declarations for lex and its associated functions that
38  * are used by the kernel to parse the contents of system files.
39  *
40  * These lex functions are for a few selected kernel modules that are required
41  * to parse contents of file(s) on disk. This file is not for general kernel
42  * usage.
43  */
44 
45 #define	isunary(ch)	((ch) == '~' || (ch) == '-')
46 
47 #define	iswhite(ch)	((ch) == ' ' || (ch) == '\t')
48 
49 #define	isnewline(ch)	((ch) == '\n' || (ch) == '\r' || (ch) == '\f')
50 
51 #define	isdigit(ch)	((ch) >= '0' && (ch) <= '9')
52 
53 #define	isxdigit(ch)	(isdigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || \
54 			((ch) >= 'A' && (ch) <= 'F'))
55 
56 #define	isalpha(ch)	(((ch) >= 'a' && (ch) <= 'z') || \
57 			((ch) >= 'A' && (ch) <= 'Z'))
58 
59 #define	isalphanum(ch)	(isalpha(ch) || isdigit(ch))
60 
61 #define	isnamechar(ch)	(isalphanum(ch) || (ch) == '_' || (ch) == '-')
62 
63 typedef enum {
64 	UNEXPECTED = -1,
65 	EQUALS,
66 	AMPERSAND,
67 	BIT_OR,
68 	STAR,
69 	POUND,
70 	COLON,
71 	SEMICOLON,
72 	COMMA,
73 	SLASH,
74 	WHITE_SPACE,
75 	NEWLINE,
76 	EOF,
77 	STRING,
78 	HEXVAL,
79 	DECVAL,
80 	NAME
81 } token_t;
82 
83 #ifdef DEBUG
84 /* string values for token_t */
85 extern char *tokennames[];
86 #endif /* DEBUG */
87 
88 /*
89  * return 1 with sptr pointing to the string represented by token
90  * On error returns NULL. The memory pointed to by sptr should be
91  * freed using free_string function.
92  */
93 int kobj_get_string(u_longlong_t *sptr, char *token);
94 void kobj_free_string(void *ptr, int len);
95 
96 /*
97  * returns decimal/octal/hex number in valuep
98  * return 0 on success, -1 on failure
99  */
100 int kobj_getvalue(const char *token, u_longlong_t *valuep);
101 
102 /* prints a formated message via cmn_err */
103 /*PRINTFLIKE3*/
104 extern void kobj_file_err(int type,  struct _buf *file, char *fmt, ...)
105 	__KPRINTFLIKE(3);
106 
107 /*
108  * returns the next token in the file on success,
109  * return -1 on failure
110  */
111 token_t kobj_lex(struct _buf *file, char *val, size_t size);
112 
113 void kobj_find_eol(struct _buf *file);
114 
115 #ifdef	__cplusplus
116 }
117 #endif
118 
119 #endif /* !_SYS_KOBJ_LEX_H */
120