Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \ QFILES.F 2025-07-21
- sys @ application
- pad value cf ( -- a ) \ current file handle
- -? : HANDLE ( "name" -- ; -- )
- create -1 , 0 c, max-path allot does> to cf ;
- \ Store, fetch, print filename of the current handle
- : !FNAME ( a u -- ) max-path min cf cell+ pack count upper ;
- : @FNAME ( -- a u ) cf cell+ count ;
- : .FNAME ( -- ) @fname type space ;
- \ File error handler
- : ?FERR ( ? n a u -- ? )
- rot if cr .fname type ." error" abort end 2drop ;
- : FREAD ( a u -- a u2 ) over swap cf @ read-file s" read" ?ferr ;
- : FREADLN ( a u -- a u2 flag ) over swap cf @ read-line s" read" ?ferr ;
- : FWRITE ( a u -- ) cf @ write-file s" write" ?ferr ;
- : FWRITELN ( a u -- ) cf @ write-line s" write" ?ferr ;
- : FSEEK ( ud -- ) cf @ reposition-file s" seek" ?ferr ;
- : FPOS ( -- ud ) cf @ file-position s" position" ?ferr ;
- : FSIZE ( -- ud ) cf @ file-size s" size" ?ferr ;
- : FOPEN ( fam -- ) @fname rot open-file s" open" ?ferr cf ! ;
- : FCREAT ( fam -- ) @fname rot create-file s" create" ?ferr cf ! ;
- : FCLOSE ( -- ) cf @ cf on close-file drop ;
- \ Parse the DOS command line for the n'th blank delimited
- \ parameter. Return address, length and true if found, or
- \ false otherwise.
- : ARG ( n -- adr len -1 | 0 )
- >r 0 0 cmdtail r> 0 ?do
- 2nip bl skip 2dup bl scan rot over - -rot
- loop 2drop dup if -1 end and ;
- sys !
- behead cf cf
- 0 [if]
- Quick Files
- Suited to small turnkey applications with simple command-line
- requirements e.g. one or two filenames.
- - File operations are performed on the 'current' handle.
- - Executing a handle's name makes it 'current'.
- - FOPEN and FCREAT take a filename from the current handle.
- The user is responsible for initializing the handle with !FNAME
- before calling FOPEN or FCREAT .
- - FCLOSE closes the disk file and sets the handle file-id to -1.
- Errors are not reported. The filename field is left unchanged
- allowing easy re-opening or even overwriting the closed file.
- - FREAD FREADLN return the buffer address in addition to the
- number of bytes read.
- - ?FERR is not limited to 'ior's. Can be used to abort on any
- error condition related to the current handle.
- Porting:
- CMDTAIL ( -- a u ) return the DOS command-line string
- MAX-PATH ( -- u ) maximum length of path/filename
- UPPER ( a u -- ) convert string to upper case
- PACK ( a u a2 -- a2 ) as for PLACE but leave dest addr
- END macro for 'EXIT THEN'
- Licence:
- Public Domain. Use at your own risk.
- [then]
Advertisement
Add Comment
Please, Sign In to add comment