From 51def2fc45d98b59be0413fcb9c25cbb0bbca211 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 14 Mar 2015 15:01:46 +0100 Subject: Fix blocking channel && channel write on circular-overflow. (see ipc.c) --- src/sysbin/shell/main.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/sysbin/shell') 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 { -- cgit v1.2.3