From 73bb0e48640b842824a0b45fe4854df8ff7faf7b Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 13:44:20 -0400 Subject: bugfixes, init program, hello world --- src/user/init/main.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/user/init/main.c') diff --git a/src/user/init/main.c b/src/user/init/main.c index 9a411e7..c301a78 100644 --- a/src/user/init/main.c +++ b/src/user/init/main.c @@ -1,29 +1,31 @@ #include #include -#include +#include void main() { - tell_user_sz("\n\nThis is a userland program.\n"); - - tell_user_sz("Opening sd0:TEST.TXT.\n"); - struct file *f = open_file("sd0:TEST.TXT"); + struct file *f = open_file("SYS/STARTUP.RC"); if (!f) { - tell_user_sz("Failed to open.\n"); + tell_user_sz("\nCould not open SYS/STARTUP.RC"); return; } - tell_user_sz("Length: "); - uint32_t size = file_size(f); - tell_user_n(size); - tell_user_sz(" bytes\n\nContents:\n"); - - char *buf = get_block(size + 1); - read_from_file(f, size, buf); - buf[size] = '\0'; + char buf[1024]; + char *bufp = buf; + while (read_from_file(f, 1, bufp)) { + if (*bufp == '\n') { + if (bufp == buf) + continue; + *bufp = '\0'; + try_run_command(buf); + bufp = buf; + } + else + ++bufp; + } + if (bufp != buf) { + *bufp = '\0'; + try_run_command(buf); + } close_file(f); - - tell_user_sz(buf); - - tell_user_sz("\n\nGoodbye!\n"); } -- cgit v1.2.3