1 #include <lunaix/fctrl.h>
2 #include <lunaix/foptions.h>
3 #include <lunaix/lunistd.h>
4 #include <lunaix/proc.h>
5 #include <lunaix/status.h>
7 #include <klibc/string.h>
8 #include <ulibc/stdio.h>
13 Simple shell - (actually this is not even a shell)
14 It just to make the testing more easy.
18 parse_cmdline(char* line, char** cmd, char** arg_part)
21 line = strltrim_safe(line);
24 while ((c = line[l])) {
32 *arg_part = strltrim_safe(line + l);
38 int errno = geterrno();
41 printf("Error: Not a directory\n");
44 printf("Error: No such file or directory\n");
47 printf("Error: Invalid parameter or operation\n");
50 printf("Error: Not supported\n");
53 printf("Error: File system is read only\n");
56 printf("Error: Out of memory\n");
59 printf("Error: Fail to open (%d)\n", errno);
70 printf("\n Simple shell. Use <PG_UP> or <PG_DOWN> to scroll.\n\n");
75 size_t sz = read(stdin, buf, 512);
77 printf("fail to read user input (%d)\n", geterrno());
81 parse_cmdline(buf, &cmd, &argpart);
85 if (streq(cmd, "cd")) {
86 if (chdir(argpart) < 0) {
89 } else if (streq(cmd, "ls")) {
90 int fd = open(argpart, 0);
94 struct dirent ent = { .d_offset = 0 };
96 while ((status = readdir(fd, &ent)) == 1) {
97 printf(" %s\n", ent.d_name);
106 printf("unknow command");