Refining file handling.

This commit is contained in:
Brad Nelson
2022-09-05 18:31:44 -07:00
parent 8cd205a9a5
commit 0dbe262abf
4 changed files with 20 additions and 15 deletions

View File

@ -18,15 +18,6 @@
r> close-file drop
;
: cat ( "path" -- )
bl parse r/o bin open-file throw { fh }
begin
here 80 fh read-file throw
dup 0= if drop fh close-file throw exit then
here swap type
again
;
: cp ( "src" "dst" -- )
bl parse r/o bin open-file throw { inf }
bl parse w/o bin create-file throw { outf }
@ -46,6 +37,22 @@
close-file throw
;
internals definitions
: cremit ( ch -- ) dup nl = if drop cr else emit then ;
: crtype ( a n -- ) for aft dup c@ cremit 1+ then next drop ;
forth definitions internals
: cat ( "path" -- )
bl parse r/o bin open-file throw { fh }
begin
here 80 fh read-file throw
dup 0= if drop fh close-file throw exit then
here swap crtype
again
;
internals definitions
( Leave some room for growth of starting system. )
0 value saving-base

View File

@ -409,11 +409,11 @@ e: check-snapshots
out: remember
out: restore
out: save
out: cat
out: touch
out: rm
out: mv
out: cp
out: cat
out: dump-file
;e

View File

@ -39,9 +39,6 @@ start-size value capacity
: down ( n -- n ) begin dup length < over text + c@ nl <> and while 1+ repeat 1+ length min ;
: ndown ( n -- n ) 10 for down next ;
: cremit ( ch -- ) dup nl = if drop cr else emit then ;
: crtype ( a n -- ) for aft dup c@ cremit 1+ then next drop ;
: update
caret nup dup 0<> if 1+ 1+ then { before }
before ndown ndown { after }

View File

@ -125,8 +125,9 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
X("DELETE-FILE", DELETE_FILE, cell_t len = n0; DROP; \
memcpy(filename, a0, len); filename[len] = 0; \
n0 = unlink(filename); n0 = n0 ? errno : 0) \
X("RENAME-FILE", RENAME_FILE, memcpy(filename, a1, n0); filename[n0] = 0; \
memcpy(filename2, a3, n2); filename2[n2] = 0; \
X("RENAME-FILE", RENAME_FILE, \
cell_t len = n0; DROP; memcpy(filename, a0, len); filename[len] = 0; DROP; \
cell_t len2 = n0; DROP; memcpy(filename2, a0, len2); filename2[len2] = 0; \
n0 = rename(filename, filename2); n0 = n0 ? errno : 0) \
X("WRITE-FILE", WRITE_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
n0 = write(fd, a0, len); n0 = n0 != len ? errno : 0) \