/*-
* 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$");
/*
* Simple commandline interpreter, toplevel and misc.
*
* XXX may be obsoleted by BootFORTH or some other, better, interpreter.
*/
#include <stand.h>
#include <string.h>
#include "bootstrap.h"
#ifdef BOOT_FORTH
#include "ficl.h"
#else
#define RETURN(x) return(x)
#endif
#include "linenoise/linenoise.h"
static char *prompt(void);
#ifndef BOOT_FORTH
/*
* Perform the command
*/
int
{
int result;
if (argc < 1)
return(CMD_OK);
/* set return defaults; a successful command will override these */
/* search the command set for the command */
}
} else {
command_errmsg = "unknown command";
}
}
#endif /* ! BOOT_FORTH */
/*
* Interactive mode
*/
void
{
/* Read our default configuration. */
} else if (*rc != '\0')
include(rc);
printf("\n");
/*
* Before interacting, we might want to autoboot.
*/
/*
* Not autobooting, go manual
*/
printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
}
}
/*
* Read commands from a file, then execute them.
*
* We store the commands in memory and close the source file so that the media
* holding it can safely go away while we are executing.
*
* Commands may be prefixed with '@' (so they aren't displayed) or '-' (so
* that the script won't stop if they fail).
*/
static int
{
int i;
int res;
char **argvbuf;
/*
* Since argv is static, we need to save it here.
*/
for (i = 0; i < argc; i++)
for (i = 0; i < argc; i++)
return(res);
}
/*
* Header prepended to each line. The text immediately follows the header.
* We try to make this short in order to save memory -- the loader has
* limited memory available, and some of the forth files are very long.
*/
struct includeline
{
int line;
char text[0];
};
/*
* The PXE TFTP service allows opening exactly one connection at the time,
* so we need to read included file into memory, then process line by line
* as it may contain embedded include commands.
*/
int
include(const char *filename)
{
return(CMD_ERROR);
}
/*
* Read the script into memory.
*/
line = 0;
line++;
/* Allocate script line structure and copy line, flags */
if (*cp == '\0')
continue; /* ignore empty line, save memory */
continue; /* ignore comment */
/* On malloc failure (it happens!), free as much as possible and exit */
}
"file '%s' line %d: memory allocation failure - aborting",
return (CMD_ERROR);
}
} else {
}
}
/*
* Execute the script
*/
if (res != FICL_VM_STATUS_OUT_OF_TEXT) {
"Error while including %s, in the line %d:\n%s",
break;
} else
}
(void) bf_run("");
}
return(res);
}
/*
* Emit the current prompt; use the same syntax as the parser
* for embedding environment variables.
*/
static char *
prompt(void)
{
int n = 0;
while (*p != 0) {
if ((*p == '$') && (*(p+1) == '{')) {
;
*cp = 0;
p = cp + 1;
continue;
}
promptbuf[n++] = *p;
p++;
}
promptbuf[n++] = ' ';
promptbuf[n] = '\0';
return (promptbuf);
}