2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1999 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <strings.h>
2N/A
2N/A#include <fcode/private.h>
2N/A#include <fcode/log.h>
2N/A
2N/A#include <fcdriver/fcdriver.h>
2N/A
2N/Avoid
2N/Abyte_loadfile(fcode_env_t *env)
2N/A{
2N/A int len;
2N/A
2N/A load_file(env);
2N/A len = (int) POP(DS);
2N/A if (len) {
2N/A void *ptr = (void *) TOS;
2N/A PUSH(DS, 1);
2N/A byte_load(env);
2N/A FREE(ptr);
2N/A } else {
2N/A drop(env);
2N/A }
2N/A}
2N/A
2N/Avoid
2N/Adefine_hook(fcode_env_t *env, char *name, int len, char *fcimage)
2N/A{
2N/A static void (*byteload_ptr)(fcode_env_t *env) = byte_loadfile;
2N/A
2N/A header(env, name, len, 0);
2N/A COMPILE_TOKEN(&do_colon);
2N/A env->state |= 1;
2N/A PUSH(DS, (fstack_t) fcimage);
2N/A PUSH(DS, strlen(fcimage));
2N/A compile_string(env);
2N/A COMPILE_TOKEN(&byteload_ptr);
2N/A semi(env);
2N/A}
2N/A
2N/A/*
2N/A * simple parser for builtin-driver matching.
2N/A *
2N/A * Consists of alias:target<CR>
2N/A * where alias is:
2N/A * <Key>[;<key>[;<key>]]
2N/A *
2N/A * and target is:
2N/A * <path to fcode image>
2N/A */
2N/A
2N/A#define PARSE_LINE 256
2N/A
2N/Astatic void
2N/Aline_error(char *where, int line, char *msg)
2N/A{
2N/A log_message(MSG_ERROR, "%s:%d: %s\n", where, line, msg);
2N/A}
2N/A
2N/Avoid
2N/Amake_builtin_hooks(fcode_env_t *env, char *where)
2N/A{
2N/A FILE *fd;
2N/A int lnum = 0, len;
2N/A char *buffer, *line, *target, *next;
2N/A
2N/A if (where == NULL)
2N/A where = "/fcode/aliases";
2N/A
2N/A if ((fd = fopen(where, "r")) == NULL) {
2N/A return;
2N/A }
2N/A
2N/A buffer = MALLOC(PARSE_LINE+1);
2N/A
2N/A while ((line = fgets(buffer, PARSE_LINE, fd)) != NULL) {
2N/A lnum++;
2N/A if ((next = strpbrk(line, " \t#\n")) != NULL)
2N/A *next = '\0';
2N/A if (strlen(line) == 0)
2N/A continue;
2N/A if ((target = strchr(line, ':')) == NULL) {
2N/A line_error(where, lnum, "Badly formed line");
2N/A continue;
2N/A }
2N/A *target++ = 0;
2N/A if (strlen(line) == 0) {
2N/A line_error(where, lnum, "Badly formed alias");
2N/A continue;
2N/A }
2N/A if (strlen(target) == 0) {
2N/A line_error(where, lnum, "Badly formed target");
2N/A continue;
2N/A }
2N/A for (; line; line = next) {
2N/A if ((next = strchr(line, ';')) != NULL)
2N/A *next++ = '\0';
2N/A if (strlen(line) == 0)
2N/A line_error(where, lnum, "Null key in alias");
2N/A else
2N/A define_hook(env, line, strlen(line), target);
2N/A }
2N/A }
2N/A FREE(buffer);
2N/A fclose(fd);
2N/A}