summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sysinstall/command.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1995-09-18 16:53:06 +0000
committerpeter <peter@FreeBSD.org>1995-09-18 16:53:06 +0000
commit89e0ab3dba9ef542f52287fd1820072c4de7d393 (patch)
treed8d32666544a3c5d9db7a5472c5fa4292681da66 /usr.sbin/sysinstall/command.c
parentea496cc61fd7886ad990ab3876ac97ea2530a3bd (diff)
downloadFreeBSD-src-89e0ab3dba9ef542f52287fd1820072c4de7d393.zip
FreeBSD-src-89e0ab3dba9ef542f52287fd1820072c4de7d393.tar.gz
This mega-commit brings in Jordan's latest sysinstall version..
This looks like it was developed offline, and is being spammed over the top of the existing. "That's fine by me! I dont really care how you do it, just get it in there..." said Jordan in a conversation a short while ago...
Diffstat (limited to 'usr.sbin/sysinstall/command.c')
-rw-r--r--usr.sbin/sysinstall/command.c68
1 files changed, 25 insertions, 43 deletions
diff --git a/usr.sbin/sysinstall/command.c b/usr.sbin/sysinstall/command.c
index 5d132c4..1fad8d2 100644
--- a/usr.sbin/sysinstall/command.c
+++ b/usr.sbin/sysinstall/command.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: command.c,v 1.10 1995/05/29 11:01:05 jkh Exp $
+ * $Id: command.c,v 1.11.4.1 1995/07/21 11:45:35 rgrimes Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -72,28 +72,19 @@ command_clear(void)
numCommands = 0;
}
-/* Add a shell command under a given key */
-void
-command_shell_add(char *key, char *fmt, ...)
+static void
+addit(char *key, int type, void *cmd, void *data)
{
- va_list args;
- char *cmd;
int i;
- cmd = (char *)safe_malloc(1024);
- va_start(args, fmt);
- vsnprintf(cmd, 1024, fmt, args);
- va_end(args);
-
/* First, look for the key already present and add a command to it */
for (i = 0; i < numCommands; i++) {
if (!strcmp(commandStack[i]->key, key)) {
if (commandStack[i]->ncmds == MAX_NUM_COMMANDS)
- msgFatal("More than %d commands stacked up behind %s??",
- MAX_NUM_COMMANDS, key);
- commandStack[i]->cmds[commandStack[i]->ncmds].type = CMD_SHELL;
- commandStack[i]->cmds[commandStack[i]->ncmds].ptr = (void *)cmd;
- commandStack[i]->cmds[commandStack[i]->ncmds].data = NULL;
+ msgFatal("More than %d commands stacked up behind %s??", MAX_NUM_COMMANDS, key);
+ commandStack[i]->cmds[commandStack[i]->ncmds].type = type;
+ commandStack[i]->cmds[commandStack[i]->ncmds].ptr = cmd;
+ commandStack[i]->cmds[commandStack[i]->ncmds].data = data;
++(commandStack[i]->ncmds);
return;
}
@@ -105,40 +96,31 @@ command_shell_add(char *key, char *fmt, ...)
commandStack[numCommands] = safe_malloc(sizeof(Command));
strcpy(commandStack[numCommands]->key, key);
commandStack[numCommands]->ncmds = 1;
- commandStack[numCommands]->cmds[0].type = CMD_SHELL;
- commandStack[numCommands]->cmds[0].ptr = (void *)cmd;
- commandStack[numCommands++]->cmds[0].data = NULL;
+ commandStack[numCommands]->cmds[0].type = type;
+ commandStack[numCommands]->cmds[0].ptr = cmd;
+ commandStack[numCommands++]->cmds[0].data = data;
}
/* Add a shell command under a given key */
void
-command_func_add(char *key, commandFunc func, void *data)
+command_shell_add(char *key, char *fmt, ...)
{
- int i;
+ va_list args;
+ char *cmd;
- /* First, look for the key already present and add a command to it */
- for (i = 0; i < numCommands; i++) {
- if (!strcmp(commandStack[i]->key, key)) {
- if (commandStack[i]->ncmds == MAX_NUM_COMMANDS)
- msgFatal("More than %d commands stacked up behind %s??",
- MAX_NUM_COMMANDS, key);
- commandStack[i]->cmds[commandStack[i]->ncmds].type = CMD_FUNCTION;
- commandStack[i]->cmds[commandStack[i]->ncmds].ptr = (void *)func;
- commandStack[i]->cmds[commandStack[i]->ncmds].data = data;
- ++(commandStack[i]->ncmds);
- return;
- }
- }
- if (numCommands == MAX_CMDS)
- msgFatal("More than %d commands accumulated??", MAX_CMDS);
+ cmd = (char *)safe_malloc(1024);
+ va_start(args, fmt);
+ vsnprintf(cmd, 1024, fmt, args);
+ va_end(args);
- /* If we fell to here, it's a new key */
- commandStack[numCommands] = safe_malloc(sizeof(Command));
- strcpy(commandStack[numCommands]->key, key);
- commandStack[numCommands]->ncmds = 1;
- commandStack[numCommands]->cmds[0].type = CMD_FUNCTION;
- commandStack[numCommands]->cmds[0].ptr = (void *)func;
- commandStack[numCommands++]->cmds[0].data = data;
+ addit(key, CMD_SHELL, cmd, NULL);
+}
+
+/* Add a shell command under a given key */
+void
+command_func_add(char *key, commandFunc func, void *data)
+{
+ addit(key, CMD_FUNCTION, func, data);
}
/* arg to sort */
OpenPOWER on IntegriCloud