4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Just in case we're not in a build environment, make sure that
30 * TEXT_DOMAIN gets set to something.
32 #if !defined(TEXT_DOMAIN)
33 #define TEXT_DOMAIN "SYS_TEST"
52 if (tabp
->lines
!= NULL
) {
53 assert(tabp
->alloc
> 0);
54 for (line
= 0; (line
< tabp
->nlines
); ++line
) {
55 md_tab_line_t
*linep
= &tabp
->lines
[line
];
57 if (linep
->context
!= NULL
)
59 if (linep
->cname
!= NULL
)
61 if (linep
->argv
!= NULL
) {
62 assert(linep
->alloc
> 0);
72 * (re)allocate argv array
80 /* allocate in chunks */
81 argc
= roundup(argc
, TAB_ARG_ALLOC
);
82 if (argc
< linep
->alloc
)
86 if (linep
->alloc
== 0) {
87 linep
->argv
= Malloc(argc
* sizeof (*linep
->argv
));
89 assert(linep
->argv
!= NULL
);
91 Realloc(linep
->argv
, (argc
* sizeof (*linep
->argv
)));
94 /* zero out new stuff */
95 (void) memset(&linep
->argv
[linep
->alloc
], 0,
96 ((argc
- linep
->alloc
) * sizeof (*linep
->argv
)));
98 /* adjust for new size */
103 * (re)allocate line array
111 /* allocate in chunks */
112 nlines
= roundup(nlines
, TAB_LINE_ALLOC
);
113 if (nlines
< tabp
->alloc
)
117 if (tabp
->alloc
== 0) {
118 assert(tabp
->lines
== NULL
);
119 tabp
->lines
= Malloc(nlines
* sizeof (*tabp
->lines
));
121 assert(tabp
->lines
!= NULL
);
123 Realloc(tabp
->lines
, (nlines
* sizeof (*tabp
->lines
)));
126 /* zero out new stuff */
127 (void) memset(&tabp
->lines
[tabp
->alloc
], 0,
128 ((nlines
- tabp
->alloc
) * sizeof (*tabp
->lines
)));
130 /* adjust for new size */
131 tabp
->alloc
= nlines
;
135 * parse up md.tab struct
145 char *p
= tabp
->data
;
146 char *e
= tabp
->data
+ tabp
->total
- 1;
150 /* we can count on '\n\0' as the last characters */
151 assert(tabp
->total
>= 2);
152 assert(tabp
->data
[tabp
->total
- 2] == '\n');
153 assert(tabp
->data
[tabp
->total
- 1] == '\0');
155 /* allocate context buffer "file line XXX" */
156 assert(tabp
->filename
!= NULL
);
157 len
= strlen(tabp
->filename
) +
158 strlen(dgettext(TEXT_DOMAIN
, "%s line %u")) + 20 + 1;
159 context
= Malloc(len
);
162 while (p
< e
&& *p
!= '\0') {
163 md_tab_line_t
*linep
;
166 /* allocate new line */
167 realloc_lines(tabp
, (tabp
->nlines
+ 1));
168 linep
= &tabp
->lines
[tabp
->nlines
];
169 (void) snprintf(context
, len
,
170 dgettext(TEXT_DOMAIN
, "%s line %u"), tabp
->filename
,
179 /* coalesce \ continuations */
182 if ((*t
== '\\') && (*(t
+ 1) == '\n')) {
190 /* leading whitespace */
191 while ((*p
!= '\n') && (isspace(*p
)))
202 while ((p
< e
) && (*p
!= '\n')) {
205 /* allocate new token */
206 realloc_argv(linep
, (linep
->argc
+ 1));
207 argvp
= &linep
->argv
[linep
->argc
++];
209 /* find end of token */
211 while ((*p
!= '\n') && (! isspace(*p
)))
221 /* eat white space */
223 while ((p
< e
) && (*p
!= '\n') && (isspace(*p
)))
228 /* fill in the rest */
229 assert((linep
->argc
> 0) && (linep
->argv
!= NULL
) &&
230 (linep
->argv
[0][0] != '\0') &&
231 (! isspace(linep
->argv
[0][0])));
232 linep
->context
= Strdup(context
);
233 linep
->type
= meta_get_init_type(linep
->argc
, linep
->argv
);
234 linep
->cname
= meta_canonicalize(NULL
, linep
->argv
[0]);
235 /* if cname is NULL then the meta/hsp name is invalid */
236 if (linep
->cname
== NULL
) {
237 (void) mderror(ep
, MDE_SYNTAX
, metatab_name
);
247 * read in md.tab file and return struct
255 md_tab_t
*tabp
= NULL
;
262 if (filename
== NULL
)
264 if ((fd
= open(filename
, O_RDONLY
, 0)) < 0) {
265 (void) mdsyserror(ep
, errno
, filename
);
268 if (fstat(fd
, &statbuf
) != 0) {
269 (void) mdsyserror(ep
, errno
, filename
);
274 tabp
= Zalloc(sizeof (*tabp
));
275 tabp
->filename
= Strdup(filename
);
276 tabp
->total
= statbuf
.st_size
+ 2; /* terminating "\n\0" */
277 tabp
->data
= Malloc(tabp
->total
);
282 while (sofar
< statbuf
.st_size
) {
285 if ((cnt
= read(fd
, p
, 8192)) < 0) {
286 (void) mdsyserror(ep
, errno
, filename
);
288 } else if (cnt
== 0) {
289 (void) mderror(ep
, MDE_SYNTAX
, filename
);
295 tabp
->data
[tabp
->total
- 2] = '\n';
296 tabp
->data
[tabp
->total
- 1] = '\0';
299 if (close(fd
) != 0) {
300 (void) mdsyserror(ep
, errno
, filename
);
307 parse_tab(tabp
, filename
, ep
);
309 /* return success if file was correctly parsed */
313 /* cleanup, return error */
323 * find line in md.tab
333 char *cname
= meta_canonicalize(sp
, name
);
336 /* if name is not legal meta name then return NULL */
340 for (line
= 0; (line
< tabp
->nlines
); ++line
) {
341 md_tab_line_t
*linep
= &tabp
->lines
[line
];
343 assert((linep
->argc
> 0) && (linep
->argv
[0] != NULL
));
344 if (((linep
->type
& type
) != 0) &&
345 (strcmp(linep
->cname
, cname
) == 0)) {