Move simple interpreter 'perform' into interp.c and call it
interp_builtin_cmd().
This commit is contained in:
parent
44eebfff73
commit
3a4a3639d2
@ -47,6 +47,8 @@ extern char command_errbuf[COMMAND_ERRBUFSZ];
|
||||
/* interp.c */
|
||||
void interact(void);
|
||||
void interp_emit_prompt(void);
|
||||
int interp_builtin_cmd(int argc, char *argv[]);
|
||||
|
||||
/* Called by interp.c for interp_*.c embedded interpreters */
|
||||
int interp_include(const char *filename); /* Execute commands from filename */
|
||||
void interp_init(void); /* Initialize interpreater */
|
||||
|
@ -139,3 +139,35 @@ interp_emit_prompt(void)
|
||||
putchar(' ');
|
||||
free(pr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform a builtin command
|
||||
*/
|
||||
int
|
||||
interp_builtin_cmd(int argc, char *argv[])
|
||||
{
|
||||
int result;
|
||||
struct bootblk_command **cmdp;
|
||||
bootblk_cmd_t *cmd;
|
||||
|
||||
if (argc < 1)
|
||||
return(CMD_OK);
|
||||
|
||||
/* set return defaults; a successful command will override these */
|
||||
command_errmsg = command_errbuf;
|
||||
strcpy(command_errbuf, "no error message");
|
||||
cmd = NULL;
|
||||
result = CMD_ERROR;
|
||||
|
||||
/* search the command set for the command */
|
||||
SET_FOREACH(cmdp, Xcommand_set) {
|
||||
if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
|
||||
cmd = (*cmdp)->c_fn;
|
||||
}
|
||||
if (cmd != NULL) {
|
||||
result = (cmd)(argc, argv);
|
||||
} else {
|
||||
command_errmsg = "unknown command";
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
@ -35,38 +35,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <string.h>
|
||||
#include "bootstrap.h"
|
||||
|
||||
/*
|
||||
* Perform the command
|
||||
*/
|
||||
static int
|
||||
perform(int argc, char *argv[])
|
||||
{
|
||||
int result;
|
||||
struct bootblk_command **cmdp;
|
||||
bootblk_cmd_t *cmd;
|
||||
|
||||
if (argc < 1)
|
||||
return(CMD_OK);
|
||||
|
||||
/* set return defaults; a successful command will override these */
|
||||
command_errmsg = command_errbuf;
|
||||
strcpy(command_errbuf, "no error message");
|
||||
cmd = NULL;
|
||||
result = CMD_ERROR;
|
||||
|
||||
/* search the command set for the command */
|
||||
SET_FOREACH(cmdp, Xcommand_set) {
|
||||
if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
|
||||
cmd = (*cmdp)->c_fn;
|
||||
}
|
||||
if (cmd != NULL) {
|
||||
result = (cmd)(argc, argv);
|
||||
} else {
|
||||
command_errmsg = "unknown command";
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
interp_init(void)
|
||||
{
|
||||
@ -86,7 +54,7 @@ interp_run(const char *input)
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (perform(argc, argv)) {
|
||||
if (interp_builtin_cmd(argc, argv)) {
|
||||
printf("%s: %s\n", argv[0], command_errmsg);
|
||||
free(argv);
|
||||
return CMD_ERROR;
|
||||
@ -195,7 +163,7 @@ interp_include(const char *filename)
|
||||
|
||||
/* Parse the command */
|
||||
if (!parse(&argc, &argv, sp->text)) {
|
||||
if ((argc > 0) && (perform(argc, argv) != 0)) {
|
||||
if ((argc > 0) && (interp_builtin_cmd(argc, argv) != 0)) {
|
||||
/* normal command */
|
||||
printf("%s: %s\n", argv[0], command_errmsg);
|
||||
if (!(sp->flags & SL_IGNOREERR)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user