diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-18 13:42:09 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-18 13:42:09 +0200 |
commit | 1ecb3fb821f49450ba4b08ad7d7a23d3acb75c47 (patch) | |
tree | cd7f14d2659809286e59c929e91fe5c02c138002 /src/user/test/main.c | |
parent | f56aa2f7e4b8e6430e123f714507032a33955a09 (diff) | |
download | TCE-1ecb3fb821f49450ba4b08ad7d7a23d3acb75c47.tar.gz TCE-1ecb3fb821f49450ba4b08ad7d7a23d3acb75c47.zip |
Improvements. Next: initrd.
Diffstat (limited to 'src/user/test/main.c')
-rw-r--r-- | src/user/test/main.c | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/src/user/test/main.c b/src/user/test/main.c index e7a6b4f..c98a619 100644 --- a/src/user/test/main.c +++ b/src/user/test/main.c @@ -41,24 +41,31 @@ void list_dir(FILE f, int lv) { file_info info; while ((r = read(f, i, 256, buf)) > 0) { + if (strcmp(buf, ".") == 0 || strcmp(buf, "..") == 0) { + i++; + continue; + } for (k = 0; k < lv; k++) printk(" "); - printk(buf); printk("\t\t"); - + printk(buf); stat_relative(f, buf, &info); - printk_hex(info.type); + if (info.type & FT_DIR) printk("/"); + printk(" \t"); + + if (info.type & FT_FILE) printk("file "); + if (info.type & FT_DIR) printk("dir "); + if (info.type & FT_SYMLINK) printk("symlink "); + if (info.type & FT_DEV) printk("dev "); + if (info.type & FT_TERMINAL) printk("term "); + if (info.type & FT_DIR) { - printk("\t"); - if (strcmp(buf, ".") != 0 && strcmp(buf, "..") != 0) { - FILE ff = open_relative(f, buf, 0); - if (ff <= 0) { - printk("error: "); printk_int(ff); printk("\n"); - } else { - printk("fd: "); printk_int(ff); printk("\n"); - list_dir(ff, lv+1); - close(ff); - } + printk(" \t"); + FILE ff = open_relative(f, buf, 0); + if (ff <= 0) { + printk("error: "); printk_int(ff); printk("\n"); } else { - printk("\n"); + printk("fd: "); printk_int(ff); printk("\n"); + list_dir(ff, lv+1); + close(ff); } } else { printk("\n"); @@ -67,6 +74,10 @@ void list_dir(FILE f, int lv) { } } +void fprint(FILE f, char *s) { + write(f, 0, strlen(s), s); +} + int main() { printk("(test app) malloc(42) = "); printk_hex((uint32_t)malloc(42)); @@ -93,27 +104,35 @@ int main() { close(f); } - printk(" -> YOUR SHELL IS STARTING UP, SIR.\n"); f = open("/.ui/klog", 0); if (f <= 0) { printk(" -> Error #"); printk_int(f); printk(" - too bad. Exiting.\n"); } else { - char *s = "Hello, writing from your opened file!\n"; - write(f, 0, strlen(s), s); + fprint(f, " -> Now reading && writing from/to virtual terminal '/.ui/klog'\n"); while (1) { - char *s = " > "; - write(f, 0, strlen(s), s); + fprint(f, " > "); char buffer[256]; int l = read(f, 0, 255, buffer); buffer[l] = 0; if (buffer[l-1] == '\n') { - char *s = "You said: "; - write(f, 0, strlen(s), s); - write(f, 0, l, buffer); + buffer[l-1] = 0; l--; + + if (strcmp(buffer, "about") == 0) { + fprint(f, "Trivial/Computing Environment v0.1.0 - useless shell, first ediiton.\n"); + } else if (strcmp(buffer, "help") == 0) { + fprint(f, "Available commands: about, help, exit.\n"); + } else if (strcmp(buffer, "exit") == 0) { + fprint(f, "Exiting the shell. I think the system is pretty likely to panic.\n"); + break; + } else if (strcmp(buffer, "gotosleep") == 0) { + while (1) thread_sleep(1000); + } else { + fprint(f, "Unknown command. "); + fprint(f, buffer); + } } else { - char *s = "oops\n"; - write(f, 0, strlen(s), s); + fprint(f, " - - - oops\n"); } } } |