commands.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include <stand.h>
#include <string.h>
#include "bootstrap.h"
const char *command_errmsg;
/* XXX should have procedural interface for setting, size limit? */
char command_errbuf[COMMAND_ERRBUFSZ];
/*
* Help is read from a formatted text file.
*
* Entries in the file are formatted as
# Ttopic [Ssubtopic] Ddescription
help
text
here
#
*
* Note that for code simplicity's sake, the above format must be followed
* exactly.
*
* Subtopic entries must immediately follow the topic (this is used to
* produce the listing of subtopics).
*
* If no argument(s) are supplied by the user, the help for 'help' is displayed.
*/
static int
{
for (;;) {
return(0);
continue;
*ep++ = 0;
*ep++ = 0;
} else if (*cp == 'D') {
}
}
continue;
}
return(1);
}
}
static int
{
int i;
pager_output(" ");
pager_output(" ");
}
do {
pager_output(" ");
} while (i++ < 30);
}
return (pager_output("\n"));
}
static int
{
/* page the help text from our load path */
printf("Verbose help not available, use '?' to list commands\n");
return(CMD_OK);
}
/* pick up request from arguments */
switch(argc) {
case 3:
case 2:
break;
case 1:
break;
default:
command_errmsg = "usage is 'help <topic> [<subtopic>]";
return(CMD_ERROR);
}
/* magic "index" keyword */
/* Scan the helpfile looking for help matching the request */
pager_open();
while(help_getnext(hfd, &t, &s, &d)) {
if (doindex) { /* dink around formatting */
if (help_emitsummary(t, s, d))
break;
/* topic mismatch */
if(matched) /* nothing more on this topic, stop scanning */
break;
} else {
/* topic matched */
matched = 1;
/* exact match, print text */
if (pager_output(buf))
break;
if (pager_output("\n"))
break;
}
/* topic match, list subtopics */
if (help_emitsummary(t, s, d))
break;
}
}
free(t);
free(s);
free(d);
}
pager_close();
if (!matched) {
"no help available for '%s'", topic);
if (subtopic)
return(CMD_ERROR);
}
if (subtopic)
return(CMD_OK);
}
static int
{
struct bootblk_command **cmdp;
int res;
char name[20];
res = 0;
pager_open();
if (res)
break;
}
}
pager_close();
return(CMD_OK);
}
/*
* substitution happening.
*/
static int
{
char *cp;
if (argc < 2) {
/*
* With no arguments, print everything.
*/
pager_open();
pager_output("=");
}
if (pager_output("\n"))
break;
}
pager_close();
} else {
} else {
return(CMD_ERROR);
}
}
return(CMD_OK);
}
static int
{
int err;
if (argc != 2) {
command_errmsg = "wrong number of arguments";
return(CMD_ERROR);
} else {
return(CMD_ERROR);
}
}
return(CMD_OK);
}
static int
{
int err;
if (argc != 3) {
command_errmsg = "wrong number of arguments";
return(CMD_ERROR);
} else {
return(CMD_ERROR);
}
}
return(CMD_OK);
}
static int
{
int err;
if (argc != 2) {
command_errmsg = "wrong number of arguments";
return(CMD_ERROR);
} else {
return(CMD_ERROR);
}
}
return(CMD_OK);
}
static int
{
char *s;
nl = 0;
optind = 1;
optreset = 1;
switch(ch) {
case 'n':
nl = 1;
break;
case '?':
default:
/* getopt has already reported an error */
return(CMD_OK);
}
}
if (s != NULL) {
printf("%s", s);
free(s);
}
if (!nl)
printf("\n");
return(CMD_OK);
}
/*
* A passable emulation of the sh(1) command of the same name.
*/
static int
{
char *prompt;
int timeout;
char *cp;
char *name;
int c;
timeout = -1;
optind = 1;
optreset = 1;
switch(c) {
case 'p':
break;
case 't':
"bad timeout '%s'", optarg);
return(CMD_ERROR);
}
break;
default:
return(CMD_OK);
}
}
if (timeout >= 0) {
while (!ischar())
return(CMD_OK); /* is timeout an error? */
}
return(CMD_OK);
}
/*
* File pager
*/
static int
{
int i;
int res;
char line[80];
res=0;
pager_open();
if (pager_output(line))
break;
if (!res) {
}
}
pager_close();
if (res == 0)
return CMD_OK;
else
return CMD_ERROR;
}
static int
{
int result;
if (result == -1) {
"error showing %s", filename);
}
return result;
}
/*
* List all disk-like devices
*/
static int
{
char line[80];
verbose = 0;
optind = 1;
optreset = 1;
switch(ch) {
case 'v':
verbose = 1;
break;
case '?':
default:
/* getopt has already reported an error */
return(CMD_OK);
}
}
pager_open();
if (pager_output(line))
break;
break;
} else {
if (pager_output(line))
break;
}
}
pager_close();
return(CMD_OK);
}