-all: packnl packnl.8
+all: packnl packnl.8 incore.lsp.8
packnl: packnl.lsp incore.lsp main-args.lsp
newlisp -x incore.lsp $@
echo 'xxxxxxxxxxxxxxxxxxxxxx''xxxxxxxxxxxxxxxxxx' >> $@
for F in $^ ; do echo "$$F\n$$(stat -c %s $$F)" ; cat $$F ; done >> $@
-packnl.8: packnl.8.adoc
- a2x -d manpage -f manpage $V $^
+%.8: %.8.adoc
+ asciidoctor -b manpage $^
;; Use (archive pathname) to register all members of the nominated ar
;; style archive.
+;; This is a hashmap of loaded files
(new Tree 'archives)
+;; A copy of the executable
(define core:core (read-file "/proc/self/exe"))
(context 'archive)
(setf main nil)
-(constant 'AR "/usr/bin/ar")
+(constant 'AR "/usr/bin/ar" 'TAR "/bin/tar" 'FILE "/usr/bin/file")
+(define (tar-able PATH)
+ (when (file? FILE)
+ (if (exec (format "%s -Z %s" FILE PATH))
+ (find " tar archive" ($it 0)))))
+
+;; Install indexes for all members of the given archive file
(define (archive:archive PATH)
;;(write-line 2 (string (list 'archive PATH)))
(map (fn (F) (archives F PATH) F)
- (exec (format "%s t %s" AR PATH))))
+ (if (directory? PATH) (directory PATH "^[^.]")
+ (ends-with PATH ".a") (exec (format "%s t %s" AR PATH))
+ (tar-able PATH) (exec (format "%s tf %s" TAR PATH))
+ '()
+ )))
-(define (get-ar PATH MEMBER)
- ;;(write-line 2 (string (list 'get-ar PATH MEMBER)))
+;; Read a member of an external archive
+(define (get-stdin CMD)
(let ((I (pipe)) (O (pipe)) (DATA "") (ALL "")
(SUB (fn (I O)
- (close (I 1)) (close (O 0)) (close 0)
- (process (format "%s p %s %s" AR PATH MEMBER) (I 0) (O 1)))))
+ (map close (list (I 1) (O 0) 0))
+ (process CMD (I 0) (O 1)))))
(fork (SUB I O))
(close (O 1)) (close (I 0)) (close (I 1))
(while (> (or (read (O 0) DATA 1000000) 0)) (extend ALL DATA))
(close (I 0))
ALL))
+;; Read an archive member. The given PATH is either a string path for
+;; an external archive file or the (position length) list for an
+;; incore packaged member.
(define (get PATH MEMBER)
(if (list? PATH) ((PATH 0) (PATH 1) core)
- (ends-with PATH ".a") (get-ar PATH MEMBER)))
+ (directory? PATH) (read-file (format "%s/%s" PATH MEMBER))
+ (ends-with PATH ".a") (get-stdin (format "%s p %s %s" AR PATH MEMBER))
+ (tar-able PATH) (get-stdin (format "%s xOf %s %s" TAR PATH MEMBER))
+ ))
;; Discover and load an in-core archive by means of a marker row of 40
;; "x", and then a series of pathname\nsize\nbytes[size] members.
--- /dev/null
+= incore.lsp(8)
+:doctype: manpage
+:revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
+
+== NAME
+
+incore.lsp - module for wrapping newlisp's load and read-file
+functions to handle both in-core and external "ar" or "tar" archives
+as local files.
+
+== SYNOPSIS
+
+_embedding directive in Makefile_
+
+[pass]
+----
+_binary_: _main.lsp_ _other.lsp*_
+ newlisp -x incore.lsp $@
+ chmod a+x $@
+ echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' >> $@
+ for F in $^ ; do \
+ echo "$$F\n$$(stat -c %s $$F)" ; cat $$F ; \
+ done >> $@
+----
+
+== DESCRIPTION
+
+*incore.lsp* is a newlisp module intended to be used for application
+embedding into self-contained script collections.
+
+*incore.lsp* is the main scripting that locates application scripts
+appended to the running binary and sets these up as in-core archive
+files. It wraps the newlisp functions +load+, +read-file+ and +file?+
+so as to locate local files via the archives paths first. It will thus
+locate any self-contained files first, before trying to find them as
+external files.
+
+When the binary has files appended, the very first file is processed
+as the application main script.
+
+=== newlisp API
+
+(*archives*)::
+
+*archives* is a hashtable of known "local" files associated with
+archiving details. These local files are associate with in-core access
+details or with external archive pathname, which is an external
+directory path, and +ar+ archive file (ending with ".a") or a +tar+
+archive file (detemined via the +file+ command).
+
+(*archive* _PATH_)::
+
+*archive* is a context for the archive handling support functions,
+including the "context function" to register archive accesible files
+with the given _PATH_ as an external archive path. The given path is
+processed and all content files are added to the *archives* hashtable
+with the given access path. Note that the any current access
+assignment will be overwritten.
++
+.Loading from known tar archive file.
+====
+----
+(archive "/usr/share/myapp/utilities-version-2.5.tgz")
+(load "framework.lsp")
+----
+This example illustrates how to make the files of a tar archive file
+available for loading as if local files.
+====
+
+== SEE ALSO
+
+*newlisp*, *ar*, *tar*, *packnl*
+
+== AUTHOR
+
+Ralph Ronnquist <ralph.ronnwuidt@gmail.com>
-packnl(8)
-=========
+= packnl(8)
:doctype: manpage
:revdate: {sys:date "+%Y-%m-%d %H:%M:%S"}
:COLON: :
:EQUALS: =
:NEWLINE: \n
-NAME
-----
-packnl - Pack newlisp scripts into an embedded binary.
-
-SYNOPSIS
---------
+== NAME
-*packnl* -w _binary_ _member-option_*
+packnl - Pack newlisp scripts into an embedded binary.
-*packnl* -u _binary_ _path_
+== SYNOPSIS
-*packnl* -t _binary_
+*packnl* *-w* _binary_ _main.lsp_ _member-option_* +
+*packnl* *-u* _binary_ _path_ +
+*packnl* *-t* _binary_
-DESCRIPTION
------------
+== DESCRIPTION
-*packnl* is a utility to pack a newlisp application into a binary
-using the embedding feature of newlisp. Such a packed binary will have
-the special +incore.lsp+ as embedded script, and it is then extended
-with the given application files in a "simple archive" format.
+*packnl* is a utility to package up a newlisp application into a
+binary using the embedding feature of newlisp. Such a packed binary
+will have the special +incore.lsp+ as embedded script, and it is then
+extended with the given application files in a "simple archive"
+format.
The first application script is "main script" and it is loaded
automatically. Additional application scripts and files are set up to
only secondarily looked up in the filesystem.
-OPTIONS
--------
+== OPTIONS
-Command Options
-~~~~~~~~~~~~~~~
+=== Command Options
*-w* _binary_ _members_::
The *-t* command option is used for enlisting then names of the
included members of an embedded binary.
-Member Otions
-~~~~~~~~~~~~~
+=== Member Otions
-*_member_*::
+_member_::
-All member arguments other than the options below are undestood to
+Member arguments other than the options below are undestood to
nominate scripts to embed with file names as given.
*-a* _library_::
subsequent relative pathnames (file members and libraries) are found
relative that working directory.
-SEE ALSO
---------
+== NOTES
+
+Note that _ar_ typically adds members using their basenames. With
++packnl+ packaging the added modules would thus be loaded by
+basenames.
+
+== SEE ALSO
*newlisp*, *ar*
-AUTHOR
-------
+== AUTHOR
Ralph Ronnquist <ralph.ronnquist@gmail.com>