xref: /titanic_50/usr/src/uts/common/sys/kobj_lex.h (revision 6b1aed11aada50610fd9f5a9e033c24ca7ee5f0c)
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  * Copyright 2015 PALO, Richard.  All rights reserved.
27  */
28 
29 #ifndef _SYS_KOBJ_LEX_H
30 #define	_SYS_KOBJ_LEX_H
31 
32 #include <sys/ctype.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * This file contains declarations for lex and its associated functions that
40  * are used by the kernel to parse the contents of system files.
41  *
42  * These lex functions are for a few selected kernel modules that are required
43  * to parse contents of file(s) on disk. This file is not for general kernel
44  * usage.
45  */
46 
47 #define	isunary(ch)	((ch) == '~' || (ch) == '-')
48 
49 #define	iswhite(ch)	((ch) == ' ' || (ch) == '\t')
50 
51 #define	isnewline(ch)	((ch) == '\n' || (ch) == '\r' || (ch) == '\f')
52 
53 #define	isalphanum(ch)	(isalpha(ch) || isdigit(ch))
54 
55 #define	isnamechar(ch)	(isalphanum(ch) || (ch) == '_' || (ch) == '-')
56 
57 typedef enum {
58 	UNEXPECTED = -1,
59 	EQUALS,
60 	AMPERSAND,
61 	BIT_OR,
62 	STAR,
63 	POUND,
64 	COLON,
65 	SEMICOLON,
66 	COMMA,
67 	SLASH,
68 	WHITE_SPACE,
69 	NEWLINE,
70 	EOF,
71 	STRING,
72 	HEXVAL,
73 	DECVAL,
74 	NAME
75 } token_t;
76 
77 #ifdef DEBUG
78 /* string values for token_t */
79 extern char *tokennames[];
80 #endif /* DEBUG */
81 
82 /*
83  * return 1 with sptr pointing to the string represented by token
84  * On error returns NULL. The memory pointed to by sptr should be
85  * freed using free_string function.
86  */
87 int kobj_get_string(u_longlong_t *sptr, char *token);
88 void kobj_free_string(void *ptr, int len);
89 
90 /*
91  * returns decimal/octal/hex number in valuep
92  * return 0 on success, -1 on failure
93  */
94 int kobj_getvalue(const char *token, u_longlong_t *valuep);
95 
96 /* prints a formated message via cmn_err */
97 /*PRINTFLIKE3*/
98 extern void kobj_file_err(int type,  struct _buf *file, char *fmt, ...)
99 	__KPRINTFLIKE(3);
100 
101 /*
102  * returns the next token in the file on success,
103  * return -1 on failure
104  */
105 token_t kobj_lex(struct _buf *file, char *val, size_t size);
106 
107 void kobj_find_eol(struct _buf *file);
108 
109 #ifdef	__cplusplus
110 }
111 #endif
112 
113 #endif /* !_SYS_KOBJ_LEX_H */
114