xref: /titanic_52/usr/src/uts/common/sys/kobj_lex.h (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
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 2004 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 	EQUALS,
65 	AMPERSAND,
66 	BIT_OR,
67 	STAR,
68 	POUND,
69 	COLON,
70 	SEMICOLON,
71 	COMMA,
72 	SLASH,
73 	WHITE_SPACE,
74 	NEWLINE,
75 	EOF,
76 	STRING,
77 	HEXVAL,
78 	DECVAL,
79 	NAME
80 } token_t;
81 
82 #ifdef DEBUG
83 /* string values for token_t */
84 extern char *tokennames[];
85 #endif /* DEBUG */
86 
87 /*
88  * return 1 with sptr pointing to the string represented by token
89  * On error returns NULL. The memory pointed to by sptr should be
90  * freed using free_string function.
91  */
92 int kobj_get_string(u_longlong_t *sptr, char *token);
93 void kobj_free_string(void *ptr, int len);
94 
95 /*
96  * returns decimal/octal/hex number in valuep
97  * return 0 on success, -1 on failure
98  */
99 int kobj_getvalue(const char *token, u_longlong_t *valuep);
100 
101 /* prints a formated message via cmn_err */
102 /*PRINTFLIKE3*/
103 extern void kobj_file_err(int type,  struct _buf *file, char *fmt, ...)
104 	__KPRINTFLIKE(3);
105 
106 /*
107  * returns the next token in the file on success,
108  * return -1 on failure
109  */
110 token_t kobj_lex(struct _buf *file, char *val, size_t size);
111 
112 void kobj_find_eol(struct _buf *file);
113 
114 #ifdef	__cplusplus
115 }
116 #endif
117 
118 #endif /* !_SYS_KOBJ_LEX_H */
119