;; This is a hashmap of loaded files
(new Tree 'archives)
-;; A copy of the executable
-(define core:core (read-file "/proc/self/exe"))
+;; A copy of the executable (file descriptor 3)
+(define core:core
+ (letn ((FD 3) (SZ (seek FD)) (BUFFER (dup "" SZ)))
+ (seek FD 0) (read FD BUFFER SZ) BUFFER))
+(map delete '(FD SZ BUFFER GNU GNU))
(context 'archive)
-
(setf main nil)
-
-(constant 'AR "/usr/bin/ar" 'TAR "/bin/tar" 'FILE "/usr/bin/file")
+(constant
+ 'AR "/usr/bin/ar"
+ 'TAR (exists file? '("/bin/tar" "/usr/bin/tar"))
+ 'FILE "/usr/bin/file" )
(define (tar-able PATH)
(when (file? FILE)
;; 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.
-(if (find (dup "x" 40) core nil 391704)
+(if (find (dup "x" 40) core nil 300000)
(let ((P (+ $it 41))) ; skip marker and newline
(constant 'incore P)
(while (regex "([^\n]+)\n([^\n]+)\n" core 0 P)
(constant
'load
- (letex ((LOAD load) (CTX '(if (1 (args)) (args 1)) MAIN))
+ (letex ((LOAD load) (CTX '(if (1 (args)) (args 1) MAIN)))
(fn () (if (archives (args 0))
(eval-string (archive:get $it (args 0)) CTX)
- (LOAD (args 0) CTX))))
+ (LOAD (args 0) (eval CTX)))))
'read-file
- (letex ((READ-FILE read-file) (CTX '(if (1 (args)) (args 1)) MAIN))
+ (letex ((READ-FILE read-file) (CTX '(if (1 (args)) (args 1) MAIN)))
(fn ()
(if (archives (args 0)) (archive:get $it (args 0) CTX)
(READ-FILE (args 0)))))