commit 1667171c4f4524d05a7bf59c6b2cd7c7696d3cf0
parent 3199ff5d43e2c0a52e6428b91f81189ff50dd96d
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 20 Sep 2022 21:06:27 -0400
app/cos: blkpack Hello World!
Diffstat:
5 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/fs/app/cos/blk.fs b/fs/app/cos/blk.fs
@@ -0,0 +1,3 @@
+( ----- 000 )
+Hello...
+World!
diff --git a/fs/app/cos/tools/blkpack.c b/fs/app/cos/tools/blkpack.c
@@ -1,6 +1,3 @@
-// This doesn't actually work, I'm just drafting how it would look.
-// compiles successfully! does it work? hum...
-
#[ 10 const BUMP_GRANULARITY ]#
int lineno;
@@ -15,7 +12,7 @@ void emptylines(int n)
int getmarker(char *line) // returns -1 on error, blkid otherwise
{
- if (sscanf("( ----- %d )\n", line)) {
+ if (sscanf("( ----- %d )", line)) {
return pspop();
} else {
return -1;
@@ -70,18 +67,16 @@ extern void blkpack() {
lineno++;
line = readline();
cnt = strlen(line);
- if (cnt <= 0) { break; } // EOF
- if (cnt > 65) {
+ if (cnt > 64) {
fprintf(
lineno, blkid,
"Line %d too long (blk %d)\n", ConsoleOut());
abort();
}
if (getmarker(line) >= 0) { break; } // we have a marker early
- line[0]--; // remove newline
puts(line);
// pad line to 64 chars
- for (i=cnt-1; i<64; i++) { stdout(' '); }
+ for (i=cnt; i<64; i++) { stdout(' '); }
}
if (blkline == 16) {
lineno++;
diff --git a/fs/sys/io.fs b/fs/sys/io.fs
@@ -1,15 +1,13 @@
\ Input/Output. See doc/io
-create _buf( $100 allot
-here value _)buf
-
struct+[ IO
: :write ( a n self -- ) >r begin ( a n ) ?dup while
2dup r@ :writebuf ?dup not if _ioerr then
( a n written-n ) tuck - ( a written-n new-n ) rot> + swap repeat ( a )
drop rdrop ;
: :putback ( c hdl ) to putback ;
- : :putc ( c hdl -- ) swap _buf( c! _buf( 1 rot :writebuf not if _ioerr then ;
+ create _buf 1 allot
+ : :putc ( c hdl -- ) swap _buf c! _buf 1 rot :writebuf not if _ioerr then ;
: :puts ( str hdl -- ) swap c@+ rot :write ;
]struct
@@ -40,11 +38,14 @@ extends IO struct[ MemIO
\ read stdin for a maximum of STR_MAXSZ-1 characters until LF is encountered,
\ then return a string representing that read line. The LF character is not
\ included. Aborts on LNSZ overflow.
+create _buf( $100 allot
+here value _)buf
+
(S -- str )
: readline
_buf( 1+ >r begin ( ) \ V1=buf
V1 _)buf = if abort" readline overflow" then
- stdin dup LF = not while 8b to!+ V1 repeat drop
+ stdin dup 0>= over LF <> and while 8b to!+ V1 repeat drop
r> _buf( - 1- ( len ) _buf( c! _buf( ( str ) ;
\ Call w with ConsoleIn being overwritten with StdIn.
diff --git a/fs/tests/cc/lib.fs b/fs/tests/cc/lib.fs
@@ -32,5 +32,6 @@ memio MemIO :buf( s c@+ []= #
S" foo 42 bar" foo 42 #eq
S" foo baz bar" foo -1 #eq
+S" ( ----- %d )" S" ( ----- 000 )" sscanf # 0 #eq
testend
diff --git a/testblkpack.fs b/testblkpack.fs
@@ -0,0 +1,3 @@
+f<< /app/cos/tools/blkpack.fs
+' blkpack S" /app/cos/blk.fs" with-stdin-file
+bye