home *** CD-ROM | disk | FTP | other *** search
- \ Bundle - create a "Forth Archive" file that contains several other files.
- \ The Forth Archive file may be later processed so that the other files
- \ are recreated. The archive file itself contains the Forth program used
- \ to unbundle, so the unbundling is achieved simply by loading the archive
- \ file.
- \
- \ Usage:
- \
- \ bundling archive-filename \ Start a new Forth archive file called
- \ \ "archive-filename". Suggested extension: .FAR
- \ adding filename \ Add a file to the archive
- \ end-bundle \ Close the archive file
-
- variable bundle-buf
- decimal
- : append-file ( -- )
- begin
- bundle-buf @ 4096 ifd @ fgets ( #bytes-read)
- dup 0>
- while
- bundle-buf @ swap ofd @ fputs
- repeat
- ;
- : adding \ filename ( -- )
- [compile] ""
- dup ( name name)
- read-open ( name)
- " extract " ofd @ fputs count ofd @ fputs newline ofd @ fputc
- append-file
- ascii ` ofd @ fputc newline ofd @ fputc
- ifd @ close
- ;
- : bundling \ archive-filename ( -- )
- writing
- [""] extract.fth read-open
- append-file
- ifd @ close
- 4096 alloc-mem bundle-buf ! \ Grab some memory
- ;
- : end-bundle ( -- )
- ofd @ close
- bundle-buf @ 4096 free-mem \ Give back the memory
- ;
-