2006-08-11 15:55:18 +02:00
|
|
|
#include "types.h"
|
2006-08-14 23:22:13 +02:00
|
|
|
#include "stat.h"
|
|
|
|
#include "user.h"
|
2006-08-11 15:55:18 +02:00
|
|
|
#include "fs.h"
|
|
|
|
#include "fcntl.h"
|
|
|
|
|
|
|
|
char *args[100];
|
2006-08-14 23:22:13 +02:00
|
|
|
void parse(char buf[]);
|
2006-08-11 15:55:18 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
while(1){
|
2006-08-12 13:38:57 +02:00
|
|
|
puts("$ ");
|
2006-08-20 01:41:34 +02:00
|
|
|
memset (buf, '\0', sizeof(buf));
|
2006-08-11 15:55:18 +02:00
|
|
|
gets(buf, sizeof(buf));
|
|
|
|
if(buf[0] == '\0')
|
|
|
|
continue;
|
|
|
|
pid = fork();
|
|
|
|
if(pid == 0){
|
2006-08-14 23:22:13 +02:00
|
|
|
parse(buf);
|
2006-08-20 01:41:34 +02: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 15:55:18 +02:00
|
|
|
}
|
|
|
|
if(pid > 0)
|
|
|
|
wait();
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 23:22:13 +02: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-20 01:41:34 +02:00
|
|
|
args[j++] = buf + i + 1;
|
2006-08-14 23:22:13 +02:00
|
|
|
if (j >= 100) {
|
|
|
|
printf(2, "too many args\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-20 01:41:34 +02:00
|
|
|
args[j] = '\0';
|
2006-08-14 23:22:13 +02:00
|
|
|
}
|