summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-18 19:40:11 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-18 19:40:11 +0200
commitac10c1a29c44b0cb29960cd0f792c7361bc430ce (patch)
tree33466e227a0214d40de373b72c83a750dba29195
parent478c691187fbc9ba4ccaacf92f57828eef20041c (diff)
downloadTCE-ac10c1a29c44b0cb29960cd0f792c7361bc430ce.tar.gz
TCE-ac10c1a29c44b0cb29960cd0f792c7361bc430ce.zip
Added some stuff.
-rw-r--r--src/kernel/ui/vt.cpp8
-rw-r--r--src/user/init/main.c10
-rw-r--r--src/user/lib/include/stdio.h8
-rw-r--r--src/user/lib/include/string.h2
-rw-r--r--src/user/lib/std/stdio.c25
-rw-r--r--src/user/lib/std/string.c2
-rw-r--r--src/user/test/main.c34
-rw-r--r--src/user/yosh/main.c107
8 files changed, 118 insertions, 78 deletions
diff --git a/src/kernel/ui/vt.cpp b/src/kernel/ui/vt.cpp
index 2bd82ca..34dfbe9 100644
--- a/src/kernel/ui/vt.cpp
+++ b/src/kernel/ui/vt.cpp
@@ -25,7 +25,13 @@ void vt::put_at(int l, int c, int ch) {
text[l * w + c].fgcolor = fgcolor;
text[l * w + c].bgcolor = bgcolor;
text[l * w + c].ch = ch;
- if (output != 0) output->text_put(l, c, ch, fgcolor, bgcolor);
+ if (output != 0) {
+ if (output->connected_vt != this) {
+ output = 0;
+ } else {
+ output->text_put(l, c, ch, fgcolor, bgcolor);
+ }
+ }
}
void vt::put(int c) {
diff --git a/src/user/init/main.c b/src/user/init/main.c
index 7d4ea0e..54dd4b6 100644
--- a/src/user/init/main.c
+++ b/src/user/init/main.c
@@ -5,20 +5,20 @@
int main(char** args) {
int i;
- FILE term = open("/.ui/klog", 0);
+ term = open("/.ui/klog", 0);
if (term <= 0) return -1;
- fprint(term, "(init) Trivial/Computing Environment says hello. Press super to go home.\n");
+ print("(init) Trivial/Computing Environment says hello. Press super to go home.\n");
for (i = 0; args[i] != 0; i++) {
if (i == 0) continue;
- fprintf(term, "(init) Spawning %s...\n", args[i]);
+ printf("(init) Spawning %s...\n", args[i]);
int pid = run(args[i], 0);
if (pid < 0) {
- fprint(term, "(init) Error. Sorry.\n");
+ print("(init) Error. Sorry.\n");
} else {
waitpid(pid);
}
}
- fprint(term, "(init) Goodbye.\n");
+ print("(init) Goodbye.\n");
}
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h
index 91fe169..6c3a974 100644
--- a/src/user/lib/include/stdio.h
+++ b/src/user/lib/include/stdio.h
@@ -3,11 +3,19 @@
#include <stdarg.h>
+extern FILE term;
+
+void print(char *s);
+void printf(char *s, ...);
+char *readln();
+
void fprint(FILE f, char *s);
void fprint_int(FILE f, int number);
void fprint_hex(FILE f, unsigned number);
void fprintf(FILE f, char *s, ...);
+void vsfprintf(FILE f, char *s, va_list arg);
+
char* freadln(FILE f);
#endif
diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h
index f14af35..87d8da2 100644
--- a/src/user/lib/include/string.h
+++ b/src/user/lib/include/string.h
@@ -14,7 +14,7 @@ uint16_t *memsetw(uint16_t *dest, uint16_t val, int count);
int strlen(const char *str);
char *strcpy(char *dest, const char *src);
char *strdup(const char *src);
-char *strchr(const char *str, char c);
+char *strchr(const char *str, int c);
char *strcat(char *dest, const char *src);
int strcmp(const char *s1, const char *s2);
diff --git a/src/user/lib/std/stdio.c b/src/user/lib/std/stdio.c
index 2bce2e3..1628a78 100644
--- a/src/user/lib/std/stdio.c
+++ b/src/user/lib/std/stdio.c
@@ -2,6 +2,24 @@
#include <stdio.h>
#include <tce/syscall.h>
+FILE term = 0;
+void print(char *s) { fprint(term, s); }
+void printf(char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vsfprintf(term, format, ap);
+ va_end(ap);
+}
+char* readln() { return freadln(term); }
+
+void fprintf(FILE f, char* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vsfprintf(f, format, ap);
+ va_end(ap);
+}
+
+
void fprint(FILE f, char *s) {
write(f, 0, strlen(s), s);
}
@@ -54,10 +72,7 @@ void fprint_hex(FILE f, unsigned v) {
fprint(f, s);
}
-void fprintf(FILE f, char* format, ...) {
- va_list ap;
- va_start(ap, format);
-
+void vsfprintf(FILE f, char *format, va_list ap) {
char* start = format;
while (*format) {
@@ -78,8 +93,6 @@ void fprintf(FILE f, char* format, ...) {
}
}
if (start != format) write(f, 0, format - start, start);
-
- va_end(ap);
}
char* freadln(FILE f) {
diff --git a/src/user/lib/std/string.c b/src/user/lib/std/string.c
index 7cd8ede..21dbd03 100644
--- a/src/user/lib/std/string.c
+++ b/src/user/lib/std/string.c
@@ -6,7 +6,7 @@ int strlen(const char *str) {
return i-1;
}
-char *strchr(const char *str, char c) {
+char *strchr(const char *str, int c) {
while (*str) {
if (*str == c) return (char*)str;
str++;
diff --git a/src/user/test/main.c b/src/user/test/main.c
index 411cc71..3457ac3 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -4,8 +4,6 @@
int threads = 0;
-FILE out = 0;
-
void thread_cascade(void* d) {
int n = (int)d;
@@ -47,30 +45,30 @@ void list_dir(FILE f, int lv) {
i++;
continue;
}
- for (k = 0; k < lv; k++) fprint(out, " ");
- fprint(out, buf);
+ for (k = 0; k < lv; k++) print(" ");
+ print(buf);
stat_relative(f, buf, &info);
- if (info.type & FT_DIR) fprint(out, "/");
- fprint(out, " \t");
+ if (info.type & FT_DIR) print("/");
+ print(" \t");
- 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_FILE) print("file ");
+ if (info.type & FT_DIR) print("dir ");
+ if (info.type & FT_SYMLINK) print("symlink ");
+ if (info.type & FT_DEV) print("dev ");
+ if (info.type & FT_TERMINAL) print("term ");
if (info.type & FT_DIR) {
- fprint(out, " \t");
+ print(" \t");
FILE ff = open_relative(f, buf, 0);
if (ff <= 0) {
- fprintf(out, "error: %i\n", ff);
+ printf("error: %i\n", ff);
} else {
- fprintf(out, "fd: %i\n", ff);
+ printf("fd: %i\n", ff);
list_dir(ff, lv+1);
close(ff);
}
} else {
- fprint(out, "\n");
+ print("\n");
}
i++;
}
@@ -79,9 +77,9 @@ void list_dir(FILE f, int lv) {
void list_root() {
FILE f = open("/", 0);
if (f <= 0) {
- fprintf(out, " -> Could not open '/', error #%i\n", f);
+ printf(" -> Could not open '/', error #%i\n", f);
} else {
- fprintf(out, "Now enumerating '/' (fd %i) :\n", f);
+ printf("Now enumerating '/' (fd %i) :\n", f);
list_dir(f, 1);
close(f);
}
@@ -107,7 +105,7 @@ int main(char** args) {
}
printk("\n");
- out = open("/.ui/klog", 0);
+ term = open("/.ui/klog", 0);
list_root();
return 0;
diff --git a/src/user/yosh/main.c b/src/user/yosh/main.c
index 957060e..7586ab0 100644
--- a/src/user/yosh/main.c
+++ b/src/user/yosh/main.c
@@ -3,33 +3,33 @@
#include <stdlib.h>
#include <stdio.h>
-FILE out, cwd_f;
+FILE cwd_f;
char *cwd;
void about() {
- fprint(out, "Trivial/Computing Environment v0.1.0 - yosh 2.\n");
+ print("Trivial/Computing Environment v0.1.0 - yosh 2.\n");
}
void help(char *args[]) {
if (args[1] == 0) {
- fprint(out, "Available commands: about, help, exit, ls, cd, switch.\n");
+ print("Available commands: about, help, exit, ls, cd, switch.\n");
} else if (strcmp(args[1], "about") == 0) {
- fprint(out, "Usage:\tabout\nShows some info about yosh. Very usefull.\n");
+ print("Usage:\tabout\nShows some info about yosh. Very usefull.\n");
} else if (strcmp(args[1], "help") == 0) {
- fprint(out, "Usage:\thelp\n\thelp <command>\n");
- fprint(out, "Shows some info about the command you want, or commands in general.\n");
+ print("Usage:\thelp\n\thelp <command>\n");
+ print("Shows some info about the command you want, or commands in general.\n");
} else if (strcmp(args[1], "exit") == 0) {
- fprint(out, "Usage:\texit\n");
- fprint(out, "Exits the shell.\nWill probably make your system panic if you only have a shell running.\n");
+ print("Usage:\texit\n");
+ print("Exits the shell.\nWill probably make your system panic if you only have a shell running.\n");
} else if (strcmp(args[1], "cd") == 0) {
- fprint(out, "Usage:\tcd <location>\nGoes to the location specified.\n");
+ print("Usage:\tcd <location>\nGoes to the location specified.\n");
} else if (strcmp(args[1], "ls") == 0) {
- fprint(out, "Usage:\tls\n\tls <location>...\nShows the content of the current/specified directory.\n");
+ print("Usage:\tls\n\tls <location>...\nShows the content of the current/specified directory.\n");
} else if (strcmp(args[1], "switch") == 0) {
- fprint(out, "Usage:\tswitch <vt name>\nSwitchs focus to specified virtual terminal.\n");
- fprint(out, "Type `ls /.ui` to see available terminals.\n");
+ print("Usage:\tswitch <vt name>\nSwitchs focus to specified virtual terminal.\n");
+ print("Type `ls /.ui` to see available terminals.\n");
} else {
- fprintf(out, "No such command: %s\n", args[1]);
+ printf("No such command: %s\n", args[1]);
}
}
@@ -97,8 +97,12 @@ char* path_cat (char* a, char* b) {
int la = strlen(a);
int lb = strlen(b);
- ret = (char*)malloc(la + lb + 2);
+ ret = (char*)malloc(la + lb + 3);
memcpy(ret, a, la);
+ if (ret[la-1] != '/') {
+ ret[la] = '/';
+ la++;
+ }
memcpy(ret + la, b, lb);
if (ret[la + lb - 1] != '/') {
ret[la + lb] = '/';
@@ -112,7 +116,7 @@ char* path_cat (char* a, char* b) {
void cd(char **args) {
if (args[1] == 0) {
- fprint(out, "Usage: cd <directory>\n");
+ print("Usage: cd <directory>\n");
}
if (strcmp(args[1], ".") == 0) return;
@@ -121,18 +125,18 @@ void cd(char **args) {
file_info info;
int i = stat(newcwd, &info);
if (i == E_NOT_FOUND) {
- fprint(out, "No such file or directory.\n");
+ print("No such file or directory.\n");
free(newcwd);
} else if (i < 0) {
- fprintf(out, "Error stating: %i\n", i);
+ printf("Error stating: %i\n", i);
free(newcwd);
} else if ((info.type & FT_DIR) == 0) {
- fprint(out, "Not a directory.\n");
+ print("Not a directory.\n");
free(newcwd);
} else {
FILE nf = open(newcwd, 0);
if (nf <= 0) {
- fprintf(out, "Error opening: %i\n", nf);
+ printf("Error opening: %i\n", nf);
free(newcwd);
} else {
free(cwd);
@@ -152,26 +156,26 @@ void ls_dir(FILE f) {
if (strcmp(buf, ".") == 0 || strcmp(buf, "..") == 0) continue;
- fprintf(out, " %s", buf);
+ printf(" %s", buf);
stat_relative(f, buf, &info);
- if (info.type & FT_DIR) fprint(out, "/");
- fprint(out, " \t");
+ if (info.type & FT_DIR) print("/");
+ print(" \t");
- 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_FILE) print("file ");
+ if (info.type & FT_DIR) print("dir ");
+ if (info.type & FT_SYMLINK) print("symlink ");
+ if (info.type & FT_DEV) print("dev ");
+ if (info.type & FT_TERMINAL) print("term ");
- fprint(out, "\t");
+ print("\t");
if (info.type & FT_TERMINAL) {
- fprintf(out, "%ix%i", info.size >> 16, info.size & 0xFFFF);
+ printf("%ix%i", info.size >> 16, info.size & 0xFFFF);
} else if ((info.type & FT_DEV) == 0) {
- fprintf(out, "%i", info.size);
+ printf("%i", info.size);
}
- fprint(out, "\n");
+ print("\n");
}
}
@@ -181,18 +185,18 @@ void ls(char **args) {
} else {
int i;
for (i = 1; args[i] != 0; i++) {
- fprintf(out, "Contents of %s :\n", args[i]);
+ printf("Contents of %s :\n", args[i]);
char* d = path_cat(cwd, args[i]);
file_info info;
int e = stat(d, &info);
if (e == E_NOT_FOUND) {
- fprint(out, " No such file or directory\n");
+ print(" No such file or directory\n");
} else if (e < 0) {
- fprintf(out, " Error stating: %i\n", e);
+ printf(" Error stating: %i\n", e);
} else {
FILE ff = open(d, 0);
if (ff <= 0) {
- fprintf(out, " Error opening: %i\n", ff);
+ printf(" Error opening: %i\n", ff);
} else {
ls_dir(ff);
close(ff);
@@ -205,7 +209,7 @@ void ls(char **args) {
void t_switch(char** args) {
if (args[1] == 0) {
- fprint(out, "Usage: switch <vt_name>\n");
+ print("Usage: switch <vt_name>\n");
return;
}
char* p = path_cat("/.ui/", args[1]);
@@ -213,13 +217,13 @@ void t_switch(char** args) {
if ((i = link(p, "/.dev/vgatxt", LM_OUTPUT_TO)) == 0) {
link("/.dev/ps2kbd", p, LM_OUTPUT_TO);
} else {
- fprintf(out, "Error %i\n", i);
+ printf("Error %i\n", i);
}
}
int main(char **sh_args) {
- out = open("/.ui/home", 0);
- if (out <= 0) {
+ term = open("/.ui/home", 0);
+ if (term <= 0) {
return -1;
}
@@ -227,11 +231,13 @@ int main(char **sh_args) {
cwd = strdup("/");
cwd_f = open(cwd, 0);
+
+ char *path = path_cat(sh_args[0], "..");
while (1) {
- fprintf(out, " %s ", cwd);
+ printf(" %s ", cwd);
- char *s = freadln(out);
+ char *s = readln();
if (s == 0) return -1;
int l = strlen(s);
if (s[l-1] == '\n') {
@@ -256,7 +262,7 @@ int main(char **sh_args) {
} else if (strcmp(c_args[0], "help") == 0) {
help(c_args);
} else if (strcmp(c_args[0], "exit") == 0) {
- fprint(out, "Exiting the shell. See you later!\n");
+ print("Exiting the shell. See you later!\n");
break;
} else if (strcmp(c_args[0], "cd") == 0) {
cd(c_args);
@@ -265,18 +271,27 @@ int main(char **sh_args) {
} else if (strcmp(c_args[0], "switch") == 0) {
t_switch(c_args);
} else {
- char *c = path_cat(cwd, c_args[0]);
+ char *c;
+ if (strchr(c_args[0], '/')) {
+ c = path_cat(cwd, c_args[0]);
+ } else {
+ c = path_cat(path, c_args[0]);
+ }
int pid = run(c, c_args + 1);
if (pid <= 0) {
- fprintf(out, "Error %i\n", pid);
+ if (pid == E_NOT_FOUND) {
+ printf("Error: no such file %s\n", c);
+ } else {
+ printf("Error %i\n", pid);
+ }
} else {
int ret = waitpid(pid);
- fprintf(out, "Exited with status %i\n", ret);
+ printf(" -> child (pid %i) exited with status %i\n", pid, ret);
}
free(c);
}
} else {
- fprint(out, "[freadln fail, sorry.]\n");
+ print("[freadln fail, sorry.]\n");
}
free(s);
}