I failed to make sense of the explanations on manual.ps p 172 concerning
(dump-scsh-program <main> <fname>)
fname is, I found out, the name of the object image.
main apparently must be a symbol designating the main procedure.
But how does SCSH/Scheme48 know what to compile?
I tried (load "myfile") from the interpreter, but that only worked
after I had removed the #! ...!# top.
Dumping then did work, and adding the *three* lines
#!/usr/local/lib/scsh/scshvm \
-o /usr/local/lib/scsh/scshvm -i
!#
to the image file made it executable.
It actually did execute, but failed where the interpreted original succeeded,
with the error message "no such file", which is part of the program.
Here is the interpreted original:
#!/usr/local/bin/scsh \
-e textcoding -s
!#
; find out the coding of a textfile that observes the Emacs File Variables
convention
; (see the chapter on 'file variables' in the Emacs Info manual)
(define (displine str) (display (string-append str (string #\newline))))
(define (fatal err str) (displine str) (exit err))
(define (textfile? f) (regexp-search (rx "text") (run/string (file ,f))))
(define file "")
(define size 0)
(define codingre (rx (: bow "coding: " (submatch (** 4 24 (| alphanum "-")))
eow)))
(define port 0)
(define match #f)
(define (headgetcoding)
(let ((line (read-line port)))
(set! match (regexp-search (rx (: "-*- " (submatch (+ any)) " -*-")) line))
(and match
(set! match (regexp-search codingre line) (match:substring match 1)))
match))
(define (eofsearch re)
(let loop ((line (read-line port)))
(cond
((not (string? line)) #f)
((begin (set! match (regexp-search re line)) match) #t)
(else (loop (read-line port)))
) ) )
(define (tailgetcoding)
(seek port (max 0 (- size 800)))
(and (eofsearch (rx "Local Variables:")) (eofsearch codingre))
)
(define (textcoding args)
(and (null? args) (fatal 5 "need 1 argument"))
(set! file (car args))
(or (file-readable? file) (fatal 4 "no such file"))
(or (textfile? file) (fatal 3 "not even a text file"))
(set! size (file-size file))
(set! port (open-input-file file))
(if (or (headgetcoding) (tailgetcoding))
(displine (match:substring match 1))
(displine "no coding found")
)
(close port)
(exit (if match 0 1))
)
;; (dump-scsh-program textcoding "textcoding.bin")
; Local Variables:
; coding: utf-8
; mode: scheme
; End:
|