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
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.
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]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <fcode/private.h>
34 #include <fcode/log.h>
36 #include <fcdriver/fcdriver.h>
39 byte_loadfile(fcode_env_t
*env
)
46 void *ptr
= (void *) TOS
;
56 define_hook(fcode_env_t
*env
, char *name
, int len
, char *fcimage
)
58 static void (*byteload_ptr
)(fcode_env_t
*env
) = byte_loadfile
;
60 header(env
, name
, len
, 0);
61 COMPILE_TOKEN(&do_colon
);
63 PUSH(DS
, (fstack_t
) fcimage
);
64 PUSH(DS
, strlen(fcimage
));
66 COMPILE_TOKEN(&byteload_ptr
);
71 * simple parser for builtin-driver matching.
73 * Consists of alias:target<CR>
75 * <Key>[;<key>[;<key>]]
78 * <path to fcode image>
81 #define PARSE_LINE 256
84 line_error(char *where
, int line
, char *msg
)
86 log_message(MSG_ERROR
, "%s:%d: %s\n", where
, line
, msg
);
90 make_builtin_hooks(fcode_env_t
*env
, char *where
)
94 char *buffer
, *line
, *target
, *next
;
97 where
= "/fcode/aliases";
99 if ((fd
= fopen(where
, "r")) == NULL
) {
103 buffer
= MALLOC(PARSE_LINE
+1);
105 while ((line
= fgets(buffer
, PARSE_LINE
, fd
)) != NULL
) {
107 if ((next
= strpbrk(line
, " \t#\n")) != NULL
)
109 if (strlen(line
) == 0)
111 if ((target
= strchr(line
, ':')) == NULL
) {
112 line_error(where
, lnum
, "Badly formed line");
116 if (strlen(line
) == 0) {
117 line_error(where
, lnum
, "Badly formed alias");
120 if (strlen(target
) == 0) {
121 line_error(where
, lnum
, "Badly formed target");
124 for (; line
; line
= next
) {
125 if ((next
= strchr(line
, ';')) != NULL
)
127 if (strlen(line
) == 0)
128 line_error(where
, lnum
, "Null key in alias");
130 define_hook(env
, line
, strlen(line
), target
);