summaryrefslogtreecommitdiff
path: root/src/user/test
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-18 19:06:35 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-18 19:06:35 +0200
commit478c691187fbc9ba4ccaacf92f57828eef20041c (patch)
tree4cb4b00d7da1fd533cebc347f3641cc0455935f5 /src/user/test
parent7e6454020ed1143e05e83a683606f318995458e5 (diff)
downloadTCE-478c691187fbc9ba4ccaacf92f57828eef20041c.tar.gz
TCE-478c691187fbc9ba4ccaacf92f57828eef20041c.zip
Simple shell added. Simple fprintf function added too.
Diffstat (limited to 'src/user/test')
-rw-r--r--src/user/test/main.c93
1 files changed, 20 insertions, 73 deletions
diff --git a/src/user/test/main.c b/src/user/test/main.c
index eb289ca..411cc71 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -4,6 +4,8 @@
int threads = 0;
+FILE out = 0;
+
void thread_cascade(void* d) {
int n = (int)d;
@@ -45,30 +47,30 @@ void list_dir(FILE f, int lv) {
i++;
continue;
}
- for (k = 0; k < lv; k++) printk(" ");
- printk(buf);
+ for (k = 0; k < lv; k++) fprint(out, " ");
+ fprint(out, buf);
stat_relative(f, buf, &info);
- if (info.type & FT_DIR) printk("/");
- printk(" \t");
+ if (info.type & FT_DIR) fprint(out, "/");
+ fprint(out, " \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_FILE) fprint(out, "file ");
+ if (info.type & FT_DIR) fprint(out, "dir ");
+ if (info.type & FT_SYMLINK) fprint(out, "symlink ");
+ if (info.type & FT_DEV) fprint(out, "dev ");
+ if (info.type & FT_TERMINAL) fprint(out, "term ");
if (info.type & FT_DIR) {
- printk(" \t");
+ fprint(out, " \t");
FILE ff = open_relative(f, buf, 0);
if (ff <= 0) {
- printk("error: "); printk_int(ff); printk("\n");
+ fprintf(out, "error: %i\n", ff);
} else {
- printk("fd: "); printk_int(ff); printk("\n");
+ fprintf(out, "fd: %i\n", ff);
list_dir(ff, lv+1);
close(ff);
}
} else {
- printk("\n");
+ fprint(out, "\n");
}
i++;
}
@@ -77,20 +79,14 @@ void list_dir(FILE f, int lv) {
void list_root() {
FILE f = open("/", 0);
if (f <= 0) {
- printk(" -> Could not open '/', error #");
- printk_int(f);
- printk("...\n");
+ fprintf(out, " -> Could not open '/', error #%i\n", f);
} else {
- printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n");
+ fprintf(out, "Now enumerating '/' (fd %i) :\n", f);
list_dir(f, 1);
close(f);
}
}
-void fprint(FILE f, char *s) {
- write(f, 0, strlen(s), s);
-}
-
int main(char** args) {
char**a;
if (args != 0) {
@@ -102,66 +98,17 @@ int main(char** args) {
printk("\n");
}
- printk("(test app) malloc(42) = ");
- printk_hex((uint32_t)malloc(42));
- printk("\n");
-
printk(" -> Creating thread cascade (total 2**4 = 16 threads)\n");
thread_new(thread_cascade, (void*)4);
- printk(" -> Main thread now sleeping...\n");
while (1) {
thread_sleep(100);
if (threads == 0) break;
}
- printk("\n -> Ok, let's try something else.\n");
- list_root();
-
- FILE f = open("/.ui/klog", 0);
- if (f <= 0) {
- printk(" -> Error #"); printk_int(f); printk(" - too bad. Exiting.\n");
- } else {
- fprint(f, " -> Now reading && writing from/to virtual terminal '/.ui/klog'\n");
- while (1) {
- fprint(f, " > ");
-
- char buffer[256];
- int l = read(f, 0, 255, buffer);
- buffer[l] = 0;
- if (buffer[l-1] == '\n') {
- buffer[l-1] = 0; l--;
+ printk("\n");
- 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. See you later!\n");
- break;
- } else if (strcmp(buffer, "gotosleep") == 0) {
- while (1) thread_sleep(1000);
- } else if (strcmp(buffer, "spawn") == 0) {
- char *args[] = {"hello", "world", 0};
- int pid = run("/somewhere/bin/test", args);
- if (pid < 0) {
- printk("Error "); printk_int(pid); printk("\n");
- } else {
- printk("Launched, pid="); printk_int(pid); printk("\n");
- int ret = waitpid(pid);
- printk("Exited, ret="); printk_int(ret); printk("\n");
- }
- } else if (strcmp(buffer, "root") == 0) {
- list_root();
- } else {
- fprint(f, "Unknown command : ");
- fprint(f, buffer);
- fprint(f, "\n");
- }
- } else {
- fprint(f, " - - - oops\n");
- }
- }
- }
+ out = open("/.ui/klog", 0);
+ list_root();
return 0;
}