Changeset View
Changeset View
Standalone View
Standalone View
head/sys/boot/common/commands.c
Show All 27 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <stand.h> | #include <stand.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
char *command_errmsg; | char *command_errmsg; | ||||
char command_errbuf[256]; /* XXX should have procedural interface for setting, size limit? */ | /* XXX should have procedural interface for setting, size limit? */ | ||||
char command_errbuf[COMMAND_ERRBUFSZ]; | |||||
static int page_file(char *filename); | static int page_file(char *filename); | ||||
/* | /* | ||||
* Help is read from a formatted text file. | * Help is read from a formatted text file. | ||||
* | * | ||||
* Entries in the file are formatted as | * Entries in the file are formatted as | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | command_help(int argc, char *argv[]) | ||||
} | } | ||||
free(t); | free(t); | ||||
free(s); | free(s); | ||||
free(d); | free(d); | ||||
} | } | ||||
pager_close(); | pager_close(); | ||||
close(hfd); | close(hfd); | ||||
if (!matched) { | if (!matched) { | ||||
sprintf(command_errbuf, "no help available for '%s'", topic); | snprintf(command_errbuf, sizeof(command_errbuf), | ||||
"no help available for '%s'", topic); | |||||
free(topic); | free(topic); | ||||
if (subtopic) | if (subtopic) | ||||
free(subtopic); | free(subtopic); | ||||
return(CMD_ERROR); | return(CMD_ERROR); | ||||
} | } | ||||
free(topic); | free(topic); | ||||
if (subtopic) | if (subtopic) | ||||
free(subtopic); | free(subtopic); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | pager_output(cp); | ||||
if (pager_output("\n")) | if (pager_output("\n")) | ||||
break; | break; | ||||
} | } | ||||
pager_close(); | pager_close(); | ||||
} else { | } else { | ||||
if ((cp = getenv(argv[1])) != NULL) { | if ((cp = getenv(argv[1])) != NULL) { | ||||
printf("%s\n", cp); | printf("%s\n", cp); | ||||
} else { | } else { | ||||
sprintf(command_errbuf, "variable '%s' not found", argv[1]); | snprintf(command_errbuf, sizeof(command_errbuf), | ||||
"variable '%s' not found", argv[1]); | |||||
return(CMD_ERROR); | return(CMD_ERROR); | ||||
} | } | ||||
} | } | ||||
return(CMD_OK); | return(CMD_OK); | ||||
} | } | ||||
COMMAND_SET(set, "set", "set a variable", command_set); | COMMAND_SET(set, "set", "set a variable", command_set); | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | command_read(int argc, char *argv[]) | ||||
switch(c) { | switch(c) { | ||||
case 'p': | case 'p': | ||||
prompt = optarg; | prompt = optarg; | ||||
break; | break; | ||||
case 't': | case 't': | ||||
timeout = strtol(optarg, &cp, 0); | timeout = strtol(optarg, &cp, 0); | ||||
if (cp == optarg) { | if (cp == optarg) { | ||||
sprintf(command_errbuf, "bad timeout '%s'", optarg); | snprintf(command_errbuf, sizeof(command_errbuf), | ||||
"bad timeout '%s'", optarg); | |||||
return(CMD_ERROR); | return(CMD_ERROR); | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
return(CMD_OK); | return(CMD_OK); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
page_file(char *filename) | page_file(char *filename) | ||||
{ | { | ||||
int result; | int result; | ||||
result = pager_file(filename); | result = pager_file(filename); | ||||
if (result == -1) | if (result == -1) { | ||||
sprintf(command_errbuf, "error showing %s", filename); | snprintf(command_errbuf, sizeof(command_errbuf), | ||||
"error showing %s", filename); | |||||
} | |||||
return result; | return result; | ||||
} | } | ||||
/* | /* | ||||
* List all disk-like devices | * List all disk-like devices | ||||
*/ | */ | ||||
COMMAND_SET(lsdev, "lsdev", "list all devices", command_lsdev); | COMMAND_SET(lsdev, "lsdev", "list all devices", command_lsdev); | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |