diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-13 16:16:43 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-13 16:16:43 +0100 |
commit | 5bc7fcc00507bbc5ff5bf957a1589209f8495534 (patch) | |
tree | f18969c395f6e74e0f299948e376abbe74577f68 /src/sysbin/shell/main.c | |
parent | 41a4f5309ef298da764bf1dca1254e734a4417f0 (diff) | |
download | kogata-5bc7fcc00507bbc5ff5bf957a1589209f8495534.tar.gz kogata-5bc7fcc00507bbc5ff5bf957a1589209f8495534.zip |
Shell begins to be usefull.
Diffstat (limited to 'src/sysbin/shell/main.c')
-rw-r--r-- | src/sysbin/shell/main.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/sysbin/shell/main.c b/src/sysbin/shell/main.c index 54cec06..1929025 100644 --- a/src/sysbin/shell/main.c +++ b/src/sysbin/shell/main.c @@ -4,22 +4,58 @@ #include <debug.h> #include <stdio.h> +#include <unistd.h> #include <syscall.h> +void ls(char* dir) { + fd_t f = open(dir, FM_READDIR); + if (f) { + dirent_t i; + int ent_no = 0; + while (readdir(f, ent_no++, &i)) { + printf("%s\n", i.name); + } + close(f); + } else { + printf("Could not open directory '%s'\n", dir); + } +} + int main(int argc, char **argv) { dbg_printf("[shell] Starting\n"); /*fctl(stdio, FC_SET_BLOCKING, 0);*/ - puts("Hello, world!\n"); + puts("Kogata shell.\n"); + + chdir("sys:"); while(true) { - puts("> "); char buf[256]; + printf("\n%s> ", getcwd(buf, 256)); + getline(buf, 256); - printf("You said: '%s'. I don't understand a word of that.\n\n", buf); + if (!strncmp(buf, "cd ", 3)) { + chdir(buf + 3); + } else if (!strcmp(buf, "ls")) { + if (getcwd(buf, 256)) { + ls(buf); + } + } else if (!strncmp(buf, "ls ", 3)) { + char buf2[256]; + if (getcwd(buf2, 256)) { + if (pathncat(buf2, buf + 3, 256)) { + ls(buf2); + } + } + } else if (!strcmp(buf, "exit")) { + break; + } else { + printf("No such command.\n"); + } } + printf("Bye.\n"); return 0; } |