#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;
while (1) {
getcwd(pwd, 512);
- printf("%s$ ", pwd);
+ printf("[\033[2m%s\033[39;49m]$ ", pwd);
size_t sz = read(stdin, buf, 512);
if (sz < 0) {
printf("fail to read user input (%d)\n", geterrno());
struct dirent ent = { .d_offset = 0 };
int status;
while ((status = readdir(fd, &ent)) == 1) {
- printf(" %s\n", ent.d_name);
+ if (ent.d_type == DT_DIR) {
+ printf(" \033[3m%s\033[39;49m\n", ent.d_name);
+ } else {
+ printf(" %s\n", ent.d_name);
+ }
}
if (status < 0)
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)) > 0) {
+ write(stdout, cat_buf, sz);
+ }
+ if (sz < 0) {
+ sh_printerr();
+ }
+ close(fd);
+ printf("\n");
+ }
} else {
printf("unknow command");
}