2 * Copyright (c) 2005 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/lib/libsys/genhooks/parse.c,v 1.1 2005/05/08 18:14:56 dillon Exp $
39 * Parse the system call configuration file.
44 struct sys_info
**sys_array
;
48 static int parse_base(lex_token
*tok
);
49 static int parse_add(lex_token
*tok
);
50 static int parse_int(lex_token
*tok
, int *ret_p
);
51 static int parse_type(lex_token
*tok
, sys_type
**type_pp
);
54 parse_file(const char *path
)
60 t
= lex_gettoken(&tok
);
61 while (t
!= TOK_EOF
) {
70 lex_error(&tok
, "Expected command directive");
78 parse_base(lex_token
*tok
)
82 t
= lex_gettoken(tok
);
84 sys_sectname
= lex_string(tok
);
85 t
= lex_gettoken(tok
);
87 lex_error(tok
, "Expected section extension symbol");
90 t
= lex_skip_token(tok
, TOK_SEMI
);
95 parse_add(lex_token
*tok
)
103 info
= zalloc(sizeof(sys_info
));
105 parse_int(tok
, &info
->sysno
);
107 t
= lex_skip_token(tok
, TOK_OBRACE
);
109 while (t
!= TOK_CBRACE
) {
112 t
= lex_gettoken(tok
);
113 parse_type(tok
, &info
->func_ret
);
114 t
= lex_skip_token(tok
, TOK_OPAREN
);
115 while (t
!= TOK_CPAREN
) {
116 t
= parse_type(tok
, &type
);
119 t
= lex_gettoken(tok
);
120 info
->func_args
= realloc(info
->func_args
,
121 sizeof(sys_type
) * (info
->nargs
+ 1));
122 info
->func_args
[info
->nargs
++] = type
;
128 if (info
->nargs
== 1 &&
129 strcmp(info
->func_args
[0]->type_name
, "void") == 0
132 /* XXX free/cleanup */
135 t
= lex_skip_token(tok
, TOK_CPAREN
);
136 t
= lex_skip_token(tok
, TOK_SEMI
);
138 case TOK_IMPLEMENTATION
:
139 t
= lex_gettoken(tok
);
142 t
= lex_gettoken(tok
);
145 lex_error(tok
, "Expected 'direct'");
148 t
= lex_skip_token(tok
, TOK_SEMI
);
151 lex_error(tok
, "Expected command directive");
155 t
= lex_skip_token(tok
, TOK_CBRACE
);
156 if (sys_count
<= info
->sysno
) {
157 sys_array
= realloc(sys_array
,
158 sizeof(sys_info
*) * (info
->sysno
+ 1));
159 while (sys_count
<= info
->sysno
)
160 sys_array
[sys_count
++] = NULL
;
162 sys_array
[info
->sysno
] = info
;
168 parse_int(lex_token
*tok
, int *ret_p
)
172 if (t
!= TOK_INTEGER
) {
173 lex_error(tok
, "Expected integer");
177 return(lex_gettoken(tok
));
182 parse_type(lex_token
*tok
, sys_type
**type_pp
)
187 type
= zalloc(sizeof(sys_type
));
189 if ((t
& TOK_SYMBOL
) == 0) {
190 lex_error(tok
, "Expected type identifier");
193 type
->type_name
= lex_string(tok
);
194 t
= lex_gettoken(tok
);
195 if (t
!= TOK_COMMA
&& t
!= TOK_CPAREN
) {
196 if ((t
& TOK_SYMBOL
) == 0) {
197 lex_error(tok
, "Expected name identifier");
200 type
->var_name
= lex_string(tok
);
201 t
= lex_gettoken(tok
);
203 type
->var_name
= NULL
;