Deleted Added
full compact
command.c (8549) command.c (8556)
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: command.c,v 1.2 1995/05/11 09:01:24 jkh Exp $
7 * $Id: command.c,v 1.3 1995/05/16 02:52:56 jkh Exp $
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 101 unchanged lines hidden (view full) ---

117 int i;
118
119 /* First, look for the key already present and add a command to it */
120 for (i = 0; i < numCommands; i++) {
121 if (!strcmp(commandStack[i]->key, key)) {
122 if (commandStack[i]->ncmds == MAX_NUM_COMMANDS)
123 msgFatal("More than %d commands stacked up behind %s??",
124 MAX_NUM_COMMANDS, key);
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 101 unchanged lines hidden (view full) ---

117 int i;
118
119 /* First, look for the key already present and add a command to it */
120 for (i = 0; i < numCommands; i++) {
121 if (!strcmp(commandStack[i]->key, key)) {
122 if (commandStack[i]->ncmds == MAX_NUM_COMMANDS)
123 msgFatal("More than %d commands stacked up behind %s??",
124 MAX_NUM_COMMANDS, key);
125 commandStack[i]->cmds[commandStack[i]->ncmds].type = CMD_FUNC;
125 commandStack[i]->cmds[commandStack[i]->ncmds].type = CMD_FUNCTION;
126 commandStack[i]->cmds[commandStack[i]->ncmds].ptr = (void *)func;
127 commandStack[i]->cmds[commandStack[i]->ncmds].data = data;
128 ++(commandStack[i]->ncmds);
129 return;
130 }
131 }
132 if (numCommands == MAX_CMDS)
133 msgFatal("More than %d commands accumulated??", MAX_CMDS);
134
135 /* If we fell to here, it's a new key */
136 commandStack[numCommands] = safe_malloc(sizeof(Command));
137 strcpy(commandStack[numCommands]->key, key);
138 commandStack[numCommands]->ncmds = 1;
126 commandStack[i]->cmds[commandStack[i]->ncmds].ptr = (void *)func;
127 commandStack[i]->cmds[commandStack[i]->ncmds].data = data;
128 ++(commandStack[i]->ncmds);
129 return;
130 }
131 }
132 if (numCommands == MAX_CMDS)
133 msgFatal("More than %d commands accumulated??", MAX_CMDS);
134
135 /* If we fell to here, it's a new key */
136 commandStack[numCommands] = safe_malloc(sizeof(Command));
137 strcpy(commandStack[numCommands]->key, key);
138 commandStack[numCommands]->ncmds = 1;
139 commandStack[numCommands]->cmds[0].type = CMD_FUNC;
139 commandStack[numCommands]->cmds[0].type = CMD_FUNCTION;
140 commandStack[numCommands++]->cmds[0].ptr = (void *)func;
141}
142
143/* arg to sort */
144static int
145sort_compare(const void *p1, const void *p2)
146{
147 return strcmp(((Command *)p1)->key, ((Command *)p2)->key);

--- 9 unchanged lines hidden (view full) ---

157void
158command_execute(void)
159{
160 int i, j, ret;
161 commandFunc func;
162
163 for (i = 0; i < numCommands; i++) {
164 for (j = 0; j < commandStack[i]->ncmds; j++) {
140 commandStack[numCommands++]->cmds[0].ptr = (void *)func;
141}
142
143/* arg to sort */
144static int
145sort_compare(const void *p1, const void *p2)
146{
147 return strcmp(((Command *)p1)->key, ((Command *)p2)->key);

--- 9 unchanged lines hidden (view full) ---

157void
158command_execute(void)
159{
160 int i, j, ret;
161 commandFunc func;
162
163 for (i = 0; i < numCommands; i++) {
164 for (j = 0; j < commandStack[i]->ncmds; j++) {
165 if (commandStack[i].type == CMD_SHELL) {
165 /* If it's a shell command, run system on it */
166 if (commandStack[i]->cmds[j].type == CMD_SHELL) {
166 msgNotify("Executing command: %s",
167 commandStack[i]->cmds[j].ptr);
168 ret = system((char *)commandStack[i]->cmds[j].ptr);
169 msgDebug("Command `%s' returns status %d\n",
170 commandStack[i]->cmds[j].ptr, ret);
171 }
172 else {
167 msgNotify("Executing command: %s",
168 commandStack[i]->cmds[j].ptr);
169 ret = system((char *)commandStack[i]->cmds[j].ptr);
170 msgDebug("Command `%s' returns status %d\n",
171 commandStack[i]->cmds[j].ptr, ret);
172 }
173 else {
173 func = (commandFunc)commandStack[i]->cmds.ptr;
174 /* It's a function pointer - call it with the key and the data */
175 func = (commandFunc)commandStack[i]->cmds[j].ptr;
174 msgNotify("Executing internal command @ %0x", func);
176 msgNotify("Executing internal command @ %0x", func);
175 ret = (*func)(commandStack[i]->cmds.key,
176 commandStack[i]->cmds.data);
177 ret = (*func)(commandStack[i]->key,
178 commandStack[i]->cmds[j].data);
177 msgDebug("Function @ %x returns status %d\n",
178 commandStack[i]->cmds[j].ptr, ret);
179 }
180 }
181 }
182}
179 msgDebug("Function @ %x returns status %d\n",
180 commandStack[i]->cmds[j].ptr, ret);
181 }
182 }
183 }
184}