diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-14 15:01:46 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-14 15:01:46 +0100 |
commit | 51def2fc45d98b59be0413fcb9c25cbb0bbca211 (patch) | |
tree | 8b57930186622a8fad2aeb6fa6aac1025f9db224 /src/sysbin/shell | |
parent | 4672f514591f0f7110103c4cd898909aef95b635 (diff) | |
download | kogata-51def2fc45d98b59be0413fcb9c25cbb0bbca211.tar.gz kogata-51def2fc45d98b59be0413fcb9c25cbb0bbca211.zip |
Fix blocking channel && channel write on circular-overflow. (see ipc.c)
Diffstat (limited to 'src/sysbin/shell')
-rw-r--r-- | src/sysbin/shell/main.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/sysbin/shell/main.c b/src/sysbin/shell/main.c index 1929025..2eb2c6c 100644 --- a/src/sysbin/shell/main.c +++ b/src/sysbin/shell/main.c @@ -14,7 +14,10 @@ void ls(char* dir) { dirent_t i; int ent_no = 0; while (readdir(f, ent_no++, &i)) { - printf("%s\n", i.name); + if (i.st.type & FT_DIR) + printf("%s/\n", i.name); + else + printf("%s\n", i.name); } close(f); } else { @@ -22,10 +25,28 @@ void ls(char* dir) { } } +void cat(char* file) { + fd_t f = open(file, FM_READ); + if (f) { + char buf[129]; + size_t p = 0; + while (true) { + size_t r = read(f, p, 128, buf); + p += r; + buf[r] = 0; + puts(buf); + if (r < 128) break; + } + close(f); + } else { + printf("Could not open file '%s'\n", file); + } +} + int main(int argc, char **argv) { dbg_printf("[shell] Starting\n"); - /*fctl(stdio, FC_SET_BLOCKING, 0);*/ + fctl(1, FC_SET_BLOCKING, 0); puts("Kogata shell.\n"); @@ -49,6 +70,13 @@ int main(int argc, char **argv) { ls(buf2); } } + } else if (!strncmp(buf, "cat ", 4)) { + char buf2[256]; + if (getcwd(buf2, 256)) { + if (pathncat(buf2, buf+4, 256)) { + cat(buf2); + } + } } else if (!strcmp(buf, "exit")) { break; } else { |