2006-08-11 13:55:18 +00:00
|
|
|
#include "types.h"
|
2006-08-14 21:22:13 +00:00
|
|
|
#include "stat.h"
|
|
|
|
#include "user.h"
|
2006-08-11 13:55:18 +00:00
|
|
|
#include "fs.h"
|
|
|
|
#include "fcntl.h"
|
|
|
|
|
|
|
|
char *args[100];
|
2006-08-14 21:22:13 +00:00
|
|
|
void parse(char buf[]);
|
2006-08-11 13:55:18 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
while(1){
|
2006-08-12 11:38:57 +00:00
|
|
|
puts("$ ");
|
2006-08-19 23:41:34 +00:00
|
|
|
memset (buf, '\0', sizeof(buf));
|
2006-08-11 13:55:18 +00:00
|
|
|
gets(buf, sizeof(buf));
|
|
|
|
if(buf[0] == '\0')
|
|
|
|
continue;
|
|
|
|
pid = fork();
|
|
|
|
if(pid == 0){
|
2006-08-14 21:22:13 +00:00
|
|
|
parse(buf);
|
2006-08-19 23:41:34 +00:00
|
|
|
if (buf[0] == 'c' && buf[1] == 'd' && buf[2] == '\0') { // cd
|
|
|
|
chdir(&buf[3]);
|
|
|
|
} else {
|
|
|
|
exec(buf, args);
|
|
|
|
printf(1, "%s: not found\n", buf);
|
|
|
|
exit();
|
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
}
|
|
|
|
if(pid > 0)
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 21:22:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
parse(char buf[])
|
|
|
|
{
|
|
|
|
int j = 1;
|
|
|
|
int i;
|
|
|
|
args[0] = buf;
|
|
|
|
for (i = 0; buf[i] != '\0'; i++) {
|
|
|
|
if (buf[i] == ' ') {
|
|
|
|
buf[i] = '\0';
|
2006-08-19 23:41:34 +00:00
|
|
|
args[j++] = buf + i + 1;
|
2006-08-14 21:22:13 +00:00
|
|
|
if (j >= 100) {
|
|
|
|
printf(2, "too many args\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-19 23:41:34 +00:00
|
|
|
args[j] = '\0';
|
2006-08-14 21:22:13 +00:00
|
|
|
}
|