199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX should have procedural interface for setting, size limit? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Help is read from a formatted text file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Entries in the file are formatted as
199767f8919635c4928607450d9e0abb932109ceToomas Soome# Ttopic [Ssubtopic] Ddescription
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note that for code simplicity's sake, the above format must be followed
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Subtopic entries must immediately follow the topic (this is used to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * produce the listing of subtopics).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If no argument(s) are supplied by the user, the help for 'help' is displayed.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(help, "help", "detailed help", command_help);
199767f8919635c4928607450d9e0abb932109ceToomas Soomehelp_getnext(int fd, char **topic, char **subtopic, char **desc)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((strlen(line) < 3) || (line[0] != '#') || (line[1] != ' '))
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if ((*cp == 'S') && (*subtopic == NULL)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomehelp_emitsummary(char *topic, char *subtopic, char *desc)
199767f8919635c4928607450d9e0abb932109ceToomas Soome } while (i++ < 30);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* page the help text from our load path */
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(buf, "%s/boot/loader.help", getenv("loaddev"));
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Verbose help not available, use '?' to list commands\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* pick up request from arguments */
199767f8919635c4928607450d9e0abb932109ceToomas Soome command_errmsg = "usage is 'help <topic> [<subtopic>]";
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* magic "index" keyword */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Scan the helpfile looking for help matching the request */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* topic mismatch */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if(matched) /* nothing more on this topic, stop scanning */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* topic matched */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* exact match, print text */
199767f8919635c4928607450d9e0abb932109ceToomas Soome while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if ((subtopic == NULL) && (s != NULL)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* topic match, list subtopics */
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(commandlist, "?", "list commands", command_commandlist);
199767f8919635c4928607450d9e0abb932109ceToomas Soomecommand_commandlist(int argc __attribute((unused)),
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (((*cmdp)->c_name != NULL) && ((*cmdp)->c_desc != NULL)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX set/show should become set/echo if we have variable
199767f8919635c4928607450d9e0abb932109ceToomas Soome * substitution happening.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(show, "show", "show variable(s)", command_show);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * With no arguments, print everything.
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (ev = environ; ev != NULL; ev = ev->ev_next) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(set, "set", "set a variable", command_set);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(setprop, "setprop", "set a variable", command_setprop);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((err = setenv(argv[1], argv[2], 1)) != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(unset, "unset", "unset a variable", command_unset);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(echo, "echo", "echo arguments", command_echo);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* getopt has already reported an error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A passable emulation of the sh(1) command of the same name.
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(read, "read", "read input from the terminal", command_read);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while ((c = getopt(argc, argv, "p:t:")) != -1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome * File pager
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(more, "more", "show contents of a file", command_more);
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(line, "*** FILE %s BEGIN ***\n", argv[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(line, "*** FILE %s END ***\n", argv[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome snprintf(command_errbuf, sizeof (command_errbuf),
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List all disk-like devices
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCOMMAND_SET(lsdev, "lsdev", "list all devices", command_lsdev);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* getopt has already reported an error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(line, "%s devices:\n", devsw[i]->dv_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(line, "%s: (unknown)\n", devsw[i]->dv_name);