Use common menu / parse functions.
Adapt to new console / exec_netbsd arguments.
This commit is contained in:
parent
a1fc367b4b
commit
a577f67769
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.4 1997/07/26 01:51:01 thorpej Exp $ */
|
||||
/* $NetBSD: main.c,v 1.5 1997/09/17 18:52:41 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -43,21 +43,24 @@
|
|||
|
||||
#include <libi386.h>
|
||||
|
||||
int errno;
|
||||
static char *consdev;
|
||||
int errno;
|
||||
|
||||
extern char bootprog_name[], bootprog_rev[], bootprog_date[],
|
||||
bootprog_maker[];
|
||||
extern char etherdev[];
|
||||
|
||||
#ifdef SUPPORT_NFS /* XXX */
|
||||
int debug = 0;
|
||||
#endif
|
||||
|
||||
#define TIMEOUT 5
|
||||
#define POLL_FREQ 10
|
||||
|
||||
#define MAXBOOTFILE 20
|
||||
void command_help __P((char *));
|
||||
void command_quit __P((char *));
|
||||
void command_boot __P((char *));
|
||||
|
||||
struct bootblk_command commands[] = {
|
||||
{ "help", command_help },
|
||||
{ "?", command_help },
|
||||
{ "quit", command_quit },
|
||||
{ "boot", command_boot },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
#ifdef COMPAT_OLDBOOT
|
||||
int
|
||||
|
@ -84,15 +87,54 @@ bootit(filename, howto)
|
|||
const char *filename;
|
||||
int howto;
|
||||
{
|
||||
if (exec_netbsd(filename, 0, howto, etherdev, consdev) < 0)
|
||||
if (exec_netbsd(filename, 0, howto) < 0)
|
||||
printf("boot: %s\n", strerror(errno));
|
||||
else
|
||||
printf("boot returned\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
helpme()
|
||||
static void
|
||||
print_banner(void)
|
||||
{
|
||||
|
||||
printf("\n"
|
||||
">> %s, Revision %s\n"
|
||||
">> (%s, %s)\n"
|
||||
">> Memory: %d/%d k\n"
|
||||
"Press return to boot now, any other key for boot menu\n"
|
||||
"starting in ",
|
||||
bootprog_name, bootprog_rev,
|
||||
bootprog_maker, bootprog_date,
|
||||
getbasemem(), getextmem());
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char c;
|
||||
|
||||
initio(CONSDEV_AUTO);
|
||||
gateA20();
|
||||
|
||||
print_banner();
|
||||
|
||||
c = awaitkey(TIMEOUT, 1);
|
||||
if ((c != '\r') && (c != '\n') && (c != '\0')) {
|
||||
printf("type \"?\" or \"help\" for help.\n");
|
||||
bootmenu(); /* does not return */
|
||||
}
|
||||
|
||||
bootit("netbsd", 0);
|
||||
|
||||
/* if that fails, let BIOS look for boot device */
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
command_help(arg)
|
||||
char *arg;
|
||||
{
|
||||
printf("commands are:\n"
|
||||
"boot [filename] [-adrs]\n"
|
||||
|
@ -101,183 +143,22 @@ helpme()
|
|||
"quit\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* chops the head from the arguments and returns the arguments if any,
|
||||
* or possibly an empty string.
|
||||
*/
|
||||
static char *
|
||||
gettrailer(arg)
|
||||
char *arg;
|
||||
/* ARGSUSED */
|
||||
void
|
||||
command_quit(arg)
|
||||
char *arg;
|
||||
{
|
||||
char *options;
|
||||
|
||||
if ((options = strchr(arg, ' ')) == NULL)
|
||||
options = "";
|
||||
else
|
||||
*options++ = '\0';
|
||||
/* trim leading blanks */
|
||||
while (*options && *options == ' ')
|
||||
options++;
|
||||
|
||||
return (options);
|
||||
printf("Exiting... goodbye...\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int
|
||||
parseopts(opts, howto)
|
||||
char *opts;
|
||||
int *howto;
|
||||
void
|
||||
command_boot(arg)
|
||||
char *arg;
|
||||
{
|
||||
int tmpopt = 0;
|
||||
char *filename;
|
||||
int howto;
|
||||
|
||||
opts++; /* skip - */
|
||||
while (*opts && *opts != ' ') {
|
||||
tmpopt |= netbsd_opt(*opts);
|
||||
if (tmpopt == -1) {
|
||||
printf("-%c: unknown flag\n", *opts);
|
||||
helpme();
|
||||
return (0);
|
||||
}
|
||||
opts++;
|
||||
}
|
||||
*howto = tmpopt;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
parseboot(arg, filename, howto)
|
||||
char *arg;
|
||||
char **filename;
|
||||
int *howto;
|
||||
{
|
||||
char *opts = NULL;
|
||||
|
||||
*filename = 0;
|
||||
*howto = 0;
|
||||
|
||||
/* if there were no arguments */
|
||||
if (!*arg)
|
||||
return (1);
|
||||
|
||||
/* format is... */
|
||||
/* [[xxNx:]filename] [-adrs] */
|
||||
|
||||
/* check for just args */
|
||||
if (arg[0] == '-') {
|
||||
opts = arg;
|
||||
} else { /* at least a file name */
|
||||
*filename = arg;
|
||||
|
||||
opts = gettrailer(arg);
|
||||
if (!*opts)
|
||||
opts = NULL;
|
||||
else if (*opts != '-') {
|
||||
printf("invalid arguments\n");
|
||||
helpme();
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
/* at this point, we have dealt with filenames. */
|
||||
|
||||
/* now, deal with options */
|
||||
if (opts) {
|
||||
if (!parseopts(opts, howto))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
docommand(arg)
|
||||
char *arg;
|
||||
{
|
||||
char *options;
|
||||
|
||||
options = gettrailer(arg);
|
||||
|
||||
if ((strcmp("help", arg) == 0) ||
|
||||
(strcmp("?", arg) == 0)) {
|
||||
helpme();
|
||||
return;
|
||||
}
|
||||
if (strcmp("quit", arg) == 0) {
|
||||
printf("Exiting... goodbye...\n");
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp("boot", arg) == 0) {
|
||||
char *filename;
|
||||
int howto;
|
||||
if (parseboot(options, &filename, &howto))
|
||||
bootit(filename, howto);
|
||||
return;
|
||||
}
|
||||
printf("unknown command\n");
|
||||
helpme();
|
||||
}
|
||||
|
||||
void
|
||||
bootmenu()
|
||||
{
|
||||
printf("\ntype \"?\" or \"help\" for help.\n");
|
||||
for (;;) {
|
||||
char input[80];
|
||||
|
||||
input[0] = '\0';
|
||||
printf("> ");
|
||||
gets(input);
|
||||
|
||||
docommand(input);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
awaitkey(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = TIMEOUT * POLL_FREQ;
|
||||
|
||||
while (i--) {
|
||||
if (iskey()) {
|
||||
/* flush input buffer */
|
||||
while (iskey())
|
||||
getchar();
|
||||
|
||||
return (1);
|
||||
}
|
||||
delay(1000000 / POLL_FREQ);
|
||||
if (!(i % POLL_FREQ))
|
||||
printf("%d\b", i / POLL_FREQ);
|
||||
}
|
||||
printf("0\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
print_banner(void)
|
||||
{
|
||||
|
||||
printf("\n");
|
||||
printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
|
||||
printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
|
||||
printf(">> Memory: %d/%d k\n", getbasemem(), getextmem());
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
consdev = initio(CONSDEV_AUTO);
|
||||
gateA20();
|
||||
|
||||
print_banner();
|
||||
|
||||
printf("press any key for boot menu\n"
|
||||
"starting in %d\b", TIMEOUT);
|
||||
|
||||
if (awaitkey())
|
||||
bootmenu(); /* does not return */
|
||||
|
||||
bootit("netbsd", 0);
|
||||
|
||||
/* if that fails, let BIOS look for boot device */
|
||||
return (1);
|
||||
if (parseboot(arg, &filename, &howto))
|
||||
bootit(filename, howto);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue