Refining file handling.
This commit is contained in:
@ -18,15 +18,6 @@
|
|||||||
r> close-file drop
|
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" -- )
|
: cp ( "src" "dst" -- )
|
||||||
bl parse r/o bin open-file throw { inf }
|
bl parse r/o bin open-file throw { inf }
|
||||||
bl parse w/o bin create-file throw { outf }
|
bl parse w/o bin create-file throw { outf }
|
||||||
@ -46,6 +37,22 @@
|
|||||||
close-file throw
|
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
|
internals definitions
|
||||||
( Leave some room for growth of starting system. )
|
( Leave some room for growth of starting system. )
|
||||||
0 value saving-base
|
0 value saving-base
|
||||||
|
|||||||
@ -409,11 +409,11 @@ e: check-snapshots
|
|||||||
out: remember
|
out: remember
|
||||||
out: restore
|
out: restore
|
||||||
out: save
|
out: save
|
||||||
|
out: cat
|
||||||
out: touch
|
out: touch
|
||||||
out: rm
|
out: rm
|
||||||
out: mv
|
out: mv
|
||||||
out: cp
|
out: cp
|
||||||
out: cat
|
|
||||||
out: dump-file
|
out: dump-file
|
||||||
;e
|
;e
|
||||||
|
|
||||||
|
|||||||
@ -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 ;
|
: down ( n -- n ) begin dup length < over text + c@ nl <> and while 1+ repeat 1+ length min ;
|
||||||
: ndown ( n -- n ) 10 for down next ;
|
: 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
|
: update
|
||||||
caret nup dup 0<> if 1+ 1+ then { before }
|
caret nup dup 0<> if 1+ 1+ then { before }
|
||||||
before ndown ndown { after }
|
before ndown ndown { after }
|
||||||
|
|||||||
@ -125,8 +125,9 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
X("DELETE-FILE", DELETE_FILE, cell_t len = n0; DROP; \
|
X("DELETE-FILE", DELETE_FILE, cell_t len = n0; DROP; \
|
||||||
memcpy(filename, a0, len); filename[len] = 0; \
|
memcpy(filename, a0, len); filename[len] = 0; \
|
||||||
n0 = unlink(filename); n0 = n0 ? errno : 0) \
|
n0 = unlink(filename); n0 = n0 ? errno : 0) \
|
||||||
X("RENAME-FILE", RENAME_FILE, memcpy(filename, a1, n0); filename[n0] = 0; \
|
X("RENAME-FILE", RENAME_FILE, \
|
||||||
memcpy(filename2, a3, n2); filename2[n2] = 0; \
|
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) \
|
n0 = rename(filename, filename2); n0 = n0 ? errno : 0) \
|
||||||
X("WRITE-FILE", WRITE_FILE, cell_t fd = n0; DROP; cell_t len = n0; DROP; \
|
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) \
|
n0 = write(fd, a0, len); n0 = n0 != len ? errno : 0) \
|
||||||
|
|||||||
Reference in New Issue
Block a user