8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / efcode / packages / parse.c
blobb75dd73ee59182b164a2f2dae06b910cb9820333
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <strings.h>
33 #include <fcode/private.h>
34 #include <fcode/log.h>
36 #include <fcdriver/fcdriver.h>
38 void
39 byte_loadfile(fcode_env_t *env)
41 int len;
43 load_file(env);
44 len = (int) POP(DS);
45 if (len) {
46 void *ptr = (void *) TOS;
47 PUSH(DS, 1);
48 byte_load(env);
49 FREE(ptr);
50 } else {
51 drop(env);
55 void
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);
62 env->state |= 1;
63 PUSH(DS, (fstack_t) fcimage);
64 PUSH(DS, strlen(fcimage));
65 compile_string(env);
66 COMPILE_TOKEN(&byteload_ptr);
67 semi(env);
71 * simple parser for builtin-driver matching.
73 * Consists of alias:target<CR>
74 * where alias is:
75 * <Key>[;<key>[;<key>]]
77 * and target is:
78 * <path to fcode image>
81 #define PARSE_LINE 256
83 static void
84 line_error(char *where, int line, char *msg)
86 log_message(MSG_ERROR, "%s:%d: %s\n", where, line, msg);
89 void
90 make_builtin_hooks(fcode_env_t *env, char *where)
92 FILE *fd;
93 int lnum = 0, len;
94 char *buffer, *line, *target, *next;
96 if (where == NULL)
97 where = "/fcode/aliases";
99 if ((fd = fopen(where, "r")) == NULL) {
100 return;
103 buffer = MALLOC(PARSE_LINE+1);
105 while ((line = fgets(buffer, PARSE_LINE, fd)) != NULL) {
106 lnum++;
107 if ((next = strpbrk(line, " \t#\n")) != NULL)
108 *next = '\0';
109 if (strlen(line) == 0)
110 continue;
111 if ((target = strchr(line, ':')) == NULL) {
112 line_error(where, lnum, "Badly formed line");
113 continue;
115 *target++ = 0;
116 if (strlen(line) == 0) {
117 line_error(where, lnum, "Badly formed alias");
118 continue;
120 if (strlen(target) == 0) {
121 line_error(where, lnum, "Badly formed target");
122 continue;
124 for (; line; line = next) {
125 if ((next = strchr(line, ';')) != NULL)
126 *next++ = '\0';
127 if (strlen(line) == 0)
128 line_error(where, lnum, "Null key in alias");
129 else
130 define_hook(env, line, strlen(line), target);
133 FREE(buffer);
134 fclose(fd);