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 2000-2003 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Embedded Fcode Interpreter
2N/A *
2N/A * Process cmd line args and invoke Fcode engine.
2N/A */
2N/A#include <sys/types.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/wait.h>
2N/A#include <fcntl.h>
2N/A#include <unistd.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <strings.h>
2N/A#include <stropts.h>
2N/A#include <ctype.h>
2N/A
2N/A#include <fcode/engine.h>
2N/A#include <fcode/log.h>
2N/A#include <fcode/debug.h>
2N/A
2N/A#include <fcdriver/fcdriver.h>
2N/A
2N/A#define MSG_ERRLOG_DEFAULT (MSG_FATAL|MSG_ERROR|MSG_WARN|MSG_INFO|\
2N/A MSG_DEBUG|MSG_FC_DEBUG)
2N/A#define MSG_SYSLOG_DEFAULT (MSG_FATAL|MSG_ERROR|MSG_WARN)
2N/A#define DEBUG_FC_LIST (DEBUG_COMMA|DEBUG_EXEC_TRACE|\
2N/A DEBUG_EXEC_DUMP_RS|DEBUG_EXEC_DUMP_RS|\
2N/A DEBUG_EXEC_SHOW_VITALS|DEBUG_TRACING|\
2N/A DEBUG_BYTELOAD_DS|DEBUG_BYTELOAD_RS|\
2N/A DEBUG_BYTELOAD_TOKENS|DEBUG_SHOW_RS|\
2N/A DEBUG_SHOW_STACK)
2N/A
2N/Acommon_data_t common;
2N/A
2N/Avoid *fc_env;
2N/A
2N/Avoid
2N/Ausage(char *argv[])
2N/A{
2N/A log_message(MSG_ERROR, "Usage: %s <flags>\n", argv[0]);
2N/A log_message(MSG_ERROR,
2N/A " -D fcode_debug = true\n");
2N/A log_message(MSG_ERROR,
2N/A " -d <level> set debug level\n");
2N/A log_message(MSG_ERROR,
2N/A " -f <file> interpret fcode/source <file>\n");
2N/A log_message(MSG_ERROR,
2N/A " -i go 'interactive'\n");
2N/A log_message(MSG_ERROR,
2N/A " -s <string> interpret <string> as forth\n");
2N/A log_message(MSG_ERROR,
2N/A " -a FCODE image has a.out header\n");
2N/A log_message(MSG_ERROR,
2N/A " -e [<msglvl>:]<errorlog> Set error log file\n");
2N/A log_message(MSG_ERROR,
2N/A " -l <msglvl> Set syslog message level\n");
2N/A log_message(MSG_ERROR,
2N/A " -k Toggle OBP page kludge\n");
2N/A}
2N/A
2N/Afcode_env_t *env;
2N/A
2N/Aint
2N/Amain(int argc, char *argv[])
2N/A{
2N/A extern char *optarg;
2N/A extern int optind, opterr, optopt;
2N/A int c, aout = 0;
2N/A char *fcode_file = NULL;
2N/A char *forthstr = NULL;
2N/A int debug = 0;
2N/A int syslog_flags = MSG_SYSLOG_DEFAULT;
2N/A int lflag = 0;
2N/A int error_log_flags;
2N/A char *errlog = NULL;
2N/A extern void run_one_efdaemon_request(fcode_env_t *);
2N/A
2N/A common.Progname = argv[0];
2N/A common.search_path = getenv("FC_SEARCH_PATH");
2N/A common.fcode_fd = -1;
2N/A env = fc_env = clone_environment(NULL, &common);
2N/A
2N/A while ((c = getopt(argc, argv, "ad:e:f:l:iDs:k")) != EOF) {
2N/A switch (c) {
2N/A case 'a':
2N/A aout = 1;
2N/A break;
2N/A
2N/A case 'd':
2N/A debug = debug_flags_to_mask(optarg);
2N/A set_interpreter_debug_level(debug);
2N/A if (debug)
2N/A env->fcode_debug = 1;
2N/A break;
2N/A
2N/A case 'e':
2N/A if ((errlog = strchr(optarg, ':')) != NULL) {
2N/A *errlog++ = '\0';
2N/A error_log_flags = parse_msg_flags(optarg);
2N/A } else {
2N/A errlog = optarg;
2N/A error_log_flags = MSG_ERRLOG_DEFAULT;
2N/A }
2N/A open_error_log(errlog, error_log_flags);
2N/A break;
2N/A
2N/A case 'l':
2N/A syslog_flags = parse_msg_flags(optarg);
2N/A lflag++;
2N/A break;
2N/A
2N/A case 'D':
2N/A env->fcode_debug = 1;
2N/A break;
2N/A
2N/A case 'f':
2N/A fcode_file = optarg;
2N/A break;
2N/A
2N/A case 'i':
2N/A forthstr = "interact";
2N/A env->fcode_debug = 1;
2N/A break;
2N/A
2N/A case 's':
2N/A forthstr = optarg;
2N/A break;
2N/A
2N/A case '?':
2N/A usage(argv);
2N/A exit(1);
2N/A }
2N/A }
2N/A
2N/A if (forthstr) {
2N/A run_fcode(env, (uchar_t *)forthstr, strlen(forthstr));
2N/A } else if (fcode_file) {
2N/A run_fcode_from_file(env, fcode_file, aout);
2N/A } else {
2N/A if ((debug & DEBUG_FC_LIST) != 0 &&
2N/A ((error_log_flags | syslog_flags) & MSG_FC_DEBUG) == 0) {
2N/A log_message(MSG_WARN, "Warning, verbose debug flag(s)"
2N/A " on, but syslog/errlog not enabled for verbose"
2N/A " debug\n");
2N/A if (errlog)
2N/A error_log_flags |= MSG_FC_DEBUG;
2N/A else
2N/A syslog_flags |= MSG_FC_DEBUG;
2N/A }
2N/A if ((debug & ~DEBUG_FC_LIST) != 0 &&
2N/A ((error_log_flags | syslog_flags) & MSG_DEBUG) == 0) {
2N/A log_message(MSG_WARN, "Warning, debug flag(s) on, but"
2N/A " syslog/errlog not enabled for debug\n");
2N/A if (errlog)
2N/A error_log_flags |= MSG_DEBUG;
2N/A else
2N/A syslog_flags |= MSG_DEBUG;
2N/A }
2N/A
2N/A if (errlog == NULL || lflag) {
2N/A if (syslog_flags & MSG_FC_DEBUG)
2N/A log_message(MSG_WARN, "Warning, verbose debug"
2N/A " not recommended for syslog\n");
2N/A open_syslog_log("interpreter", syslog_flags);
2N/A }
2N/A run_one_efdaemon_request(env);
2N/A }
2N/A
2N/A return (0);
2N/A}