Support a simple search path search for the shell

This commit is contained in:
Ali Mashtizadeh 2015-01-23 12:15:50 -08:00
parent 6cc254dd24
commit a4859ddcc6

View File

@ -145,6 +145,47 @@ Cmd_Spawn(int argc, const char *argv[])
printf("Process result: %d\n", status);
}
const char *searchpath[] = {
"",
"/sbin/",
"/bin/",
"/tests/",
NULL
};
void
Cmd_Run(int argc, const char *argv[])
{
int i, status;
char path[256];
struct stat sb;
if (argc == 0)
return;
i = 0;
while (searchpath[i] != NULL) {
strcpy(path, searchpath[i]);
strcat(path, argv[0]);
status = OSStat(path, &sb);
if (status != 0) {
i++;
continue;
}
status = OSSpawn(path);
if (status > 100000) {
printf("Spawn failed!\n");
}
status = OSWait(status);
printf("Process result: %d\n", status);
return;
}
printf("Unknown command '%s'\n", argv[0]);
}
void
DispatchCommand(char *buf)
{
@ -193,8 +234,10 @@ DispatchCommand(char *buf)
Cmd_Spawn(argc, (const char **)argv);
} else if (strcmp(argv[0], "#") == 0) {
// Ignore comments
} else if (buf[0] != '\0') {
printf("Unknown command '%s'\n", buf);
} else if (buf[0] == '\0') {
// Ignore empty lines
} else {
Cmd_Run(argc, (const char **)argv);
}
}