feat: taskfs for export process to filesystem
[lunaix-os.git] / lunaix-os / kernel / demos / simple_sh.c
index 8243ae1d85352141c36274a0462942a1b1354c0d..693bb75b63bec8ccfeae625834f2999fd4c7b061 100644 (file)
@@ -8,6 +8,7 @@
 #include <ulibc/stdio.h>
 
 char pwd[512];
 #include <ulibc/stdio.h>
 
 char pwd[512];
+char cat_buf[1024];
 
 /*
     Simple shell - (actually this is not even a shell)
 
 /*
     Simple shell - (actually this is not even a shell)
@@ -55,6 +56,9 @@ sh_printerr()
         case ENOMEM:
             printf("Error: Out of memory\n");
             break;
         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;
         default:
             printf("Error: Fail to open (%d)\n", errno);
             break;
@@ -71,7 +75,7 @@ sh_main()
 
     while (1) {
         getcwd(pwd, 512);
 
     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());
         size_t sz = read(stdin, buf, 512);
         if (sz < 0) {
             printf("fail to read user input (%d)\n", geterrno());
@@ -94,7 +98,11 @@ sh_main()
                 struct dirent ent = { .d_offset = 0 };
                 int status;
                 while ((status = readdir(fd, &ent)) == 1) {
                 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)
                 }
 
                 if (status < 0)
@@ -102,6 +110,21 @@ sh_main()
 
                 close(fd);
             }
 
                 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");
         }
         } else {
             printf("unknow command");
         }