#include <ulibc/stdio.h>
char pwd[512];
+char cat_buf[1024];
/*
Simple shell - (actually this is not even a shell)
case ENOMEM:
printf("Error: Out of memory\n");
break;
+ case EISDIR:
+ printf("Error: This is a directory\n");
+ break;
default:
printf("Error: Fail to open (%d)\n", errno);
break;
char buf[512];
char *cmd, *argpart;
+ printf("\n Simple shell. Use <PG_UP> or <PG_DOWN> to scroll.\n\n");
+
while (1) {
getcwd(pwd, 512);
- printf("%s> ", pwd);
+ printf("%s$ ", pwd);
size_t sz = read(stdin, buf, 512);
if (sz < 0) {
printf("fail to read user input (%d)\n", geterrno());
}
buf[sz - 1] = '\0';
parse_cmdline(buf, &cmd, &argpart);
+ if (cmd[0] == 0) {
+ goto cont;
+ }
if (streq(cmd, "cd")) {
if (chdir(argpart) < 0) {
sh_printerr();
close(fd);
}
+ } else if (streq(cmd, "cat")) {
+ int fd = open(argpart, 0);
+ if (fd < 0) {
+ sh_printerr();
+ } else {
+ int sz;
+ while ((sz = read(fd, cat_buf, 1024)) == 1024) {
+ write(stdout, cat_buf, 1024);
+ }
+ if (sz < 0) {
+ sh_printerr();
+ } else {
+ write(stdout, cat_buf, sz);
+ }
+ close(fd);
+ }
} else {
printf("unknow command");
}
+ cont:
printf("\n");
}
}
\ No newline at end of file