spinix-hive/pfth/linux.fth

89 lines
1.5 KiB
Forth
Raw Normal View History

\ List the files in the current directory
: ls
get-file-struct
0= if exit then
spi_currdir @
begin
dup spi_buf spi_readblock drop
512 0 do
i spi_buf + dup c@
if
dup c@ 229 = \ Deleted file
over 11 + c@ 15 = or \ Long name
if
drop
else
dup 11 type bl emit
dup 28 + @ .
cr drop
then
else
r> r> 2drop 2drop exit
then
32 +loop
1+
again
;
\ Type the file to the console
: cat bl word count 0 open-file
if
drop
." Could not open file" cr
else
begin
dup pad 100 rot read-line drop
0 = if drop close-file drop exit then
pad swap type cr
again
then
;
\ Remove a file
: rm bl word count delete-file
if
." File does not exist" cr
then
;
\ Copy a file to another file
: cp
bl word count 0 open-file
if
drop
." Could not open input file" cr
exit
then
bl word count 0 create-file
if
drop
." Could not open output file" cr
close-file drop
exit
then
begin
over pad 100 rot read-file drop dup
while
over pad -rot write-file drop
repeat
drop
close-file drop
close-file drop
;
\ Copy a file to memory and then to another file
: cp1 bl word count 0 open-file
if
drop
." Could not open file" cr
else
dup here unused rot read-file drop
swap close-file drop
bl word count 0 create-file drop
dup rot here swap rot
write-file drop
close-file drop
then
;