* scm2bin.scm 1.0
@ 2003-07-30 16:26 Thien-Thi Nguyen
2003-08-04 15:58 ` Paul Jarc
0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2003-07-30 16:26 UTC (permalink / raw)
Cc: guile-user
since "guile SCRIPT" doesn't work as the SHELL value in a crontab file,
i thought i'd reinvent the wheel and do scm2bin instead (as yet another
form of procrastination ;-). play session:
$ cat > hello-world.scm
(use-modules (ice-9 rw))
(write-line "hello-world!")
(format #t "(command-line) => ~S\n" (command-line))
^D
$ guile -s scm2bin.scm hello-world.scm
$ ./scm2bin.out how are you
hello-world!
(command-line) => ("./scm2bin.out" "how" "are" "you")
$ guile -s scm2bin.scm -o hi hello-world.scm
$ ./hi how are you
hello-world!
(command-line) => ("./hi" "how" "are" "you")
etc. this will eventually make it into guile-tools (guile-1.4.1.94).
probably the user interface will be stable enough to get hobbit on board
At Some Point. note that the implementation relies on "guile-tools
guile-config", which can be grabbed from:
http://www.glug.org/alt/guile-1.4.1.93.tar.gz
happy hacking,
thi
_____________________________________________________
cd ~/stash/
tar xzOf ttn-do-141.tar.gz ttn-do-141/scm2bin.scm
#!/bin/sh
# -*- scheme -*-
exec guile -s $0 "$@"
!#
;;; ID: scm2bin.scm,v 1.1 2003/07/30 16:15:15 ttn Exp
;;;
;;; Copyright (C) 2003 Thien-Thi Nguyen
;;; This program is part of ttn-do, released under GNU GPL v2 with ABSOLUTELY
;;; NO WARRANTY. See http://www.gnu.org/copyleft/gpl.txt for details.
;;; Commentary:
;; Usage: scm2bin --help
;; scm2bin --version
;; scm2bin [OPTIONS] SCM
;; where SCM is a scheme (.scm) program, and OPTIONS
;; (defaults in square brackets) is zero or more of:
;; --output, -o FILE -- use FILE for output [scm2bin.out]
;;; Code:
(define *scm2bin-version* "1.0")
(use-modules (ice-9 rw))
(define (usage)
(for-each write-line
'("Usage: scm2bin --help"
" scm2bin --version"
" scm2bin [OPTIONS] SCM"
" where SCM is a scheme (.scm) program, and OPTIONS"
" (defaults in square brackets) is zero or more of:"
" --output, -o FILE -- use FILE for output [scm2bin.out]"
;; " --main, -m PROC -- use PROC as main [main]"
)))
(use-modules (srfi srfi-13))
(define (write-C-string p s)
(string-for-each
(lambda (c)
(case c
((#\newline) (display "\\n\"\n \"" p))
((#\\) (display #\\ p) (display #\\ p))
((#\") (display #\\ p) (display #\" p))
(else (display c p))))
s))
(define *boilerplate-C* "
static int actual_main (int argc, char **argv) {
SCM port = scm_open_input_string (gh_str02scm (program));
while (1) {
SCM form = scm_read (port);
if (SCM_EOF_OBJECT_P (form)) break;
scm_eval_x (form);
}
return 0;
}
int main (int argc, char **argv) {
gh_enter (argc, argv, actual_main);
return 0;
}
")
(use-modules (scripts slurp) (ice-9 getopt-long))
;;; main
(let ((parsed (getopt-long (command-line)
'((version)
(help (single-char #\h))
(output (single-char #\o)
(value #t))
(main (single-char #\m)
(value #t))))))
(cond ((option-ref parsed 'help #f)
(usage)
(exit #t))
((option-ref parsed 'version #f)
(format #t "scm2bin ~A\n" *scm2bin-version*)
(exit #t))
((null? (option-ref parsed '() #f))
(usage)
(exit #f))
(else
(let* ((name (car (option-ref parsed '() #f)))
(in (if (file-exists? name)
(slurp name)
(begin
(format #t "scm2bin: cannot read: ~A\n"
name)
(exit #f))))
(out (option-ref parsed 'output "scm2bin.out"))
(tmp (open-output-file "scm2bin.c")))
(format tmp "#include <libguile.h>\n")
(format tmp "static char program[] = \"")
(write-C-string tmp in)
(format tmp "\";\n\n")
(format tmp *boilerplate-C*)
(close tmp)
(system (format #f "~A -o ~A ~A ~A ~A"
"`guile-tools guile-config acsubst CC`"
out
"`guile-tools guile-config compile`"
"scm2bin.c"
"`guile-tools guile-config link`")))
(delete-file "scm2bin.c")
(exit #t))))
;;; scm2bin.scm ends here
Compilation finished at Wed Jul 30 18:18:12
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-07-30 16:26 scm2bin.scm 1.0 Thien-Thi Nguyen
@ 2003-08-04 15:58 ` Paul Jarc
2003-08-05 8:14 ` Thien-Thi Nguyen
0 siblings, 1 reply; 7+ messages in thread
From: Paul Jarc @ 2003-08-04 15:58 UTC (permalink / raw)
Cc: guile-user, guile-sources
Thien-Thi Nguyen <ttn@surf.glug.org> wrote:
> since "guile SCRIPT" doesn't work as the SHELL value in a crontab file,
> i thought i'd reinvent the wheel and do scm2bin instead
Why not just add the usual stanza at the top of SCRIPT, and use SCRIPT
alone as the SHELL value?
> #!/bin/sh
> # -*- scheme -*-
> exec guile -s $0 "$@"
> !#
paul
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-08-04 15:58 ` Paul Jarc
@ 2003-08-05 8:14 ` Thien-Thi Nguyen
2003-08-05 14:00 ` Joshua Judson Rosen
2003-08-05 15:48 ` Paul Jarc
0 siblings, 2 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2003-08-05 8:14 UTC (permalink / raw)
Cc: guile-user, guile-sources
Date: Mon, 04 Aug 2003 11:58:50 -0400
From: prj@po.cwru.edu (Paul Jarc)
Why not just add the usual stanza at the top of SCRIPT, and use
SCRIPT alone as the SHELL value?
cron expects SHELL to name a command interpreter, not a cron job.
other formulations that may (i haven't tried them) work:
SHELL=/home/ttn/local/bin/guile
08 * * * * -s /home/ttn/etc/cron/hourly.scm
SHELL=/some/simple/guile-shell
08 * * * * /home/ttn/etc/cron/hourly.scm
thi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-08-05 8:14 ` Thien-Thi Nguyen
@ 2003-08-05 14:00 ` Joshua Judson Rosen
2003-08-05 17:11 ` Thien-Thi Nguyen
2003-08-05 15:48 ` Paul Jarc
1 sibling, 1 reply; 7+ messages in thread
From: Joshua Judson Rosen @ 2003-08-05 14:00 UTC (permalink / raw)
Cc: guile-user, prj, guile-sources
[-- Attachment #1.1: Type: text/plain, Size: 947 bytes --]
On Tue, Aug 05, 2003 at 04:14:48AM -0400, Thien-Thi Nguyen wrote:
> Date: Mon, 04 Aug 2003 11:58:50 -0400
> From: prj@po.cwru.edu (Paul Jarc)
>
> Why not just add the usual stanza at the top of SCRIPT, and use
> SCRIPT alone as the SHELL value?
>
> cron expects SHELL to name a command interpreter, not a cron job.
Then, with Paul's stanza, you could just leave SHELL as /bin/sh,
couldn't you? ;)
If you're using `(getenv "SHELL")' somewhere inside your scripts, you
could even set SHELL in the stanza..., though, it does seem hairier to
manually add the same header to every one of your scripts, and that
might be what your `scm2bin' is doing, as far as I know (I think that
I'll go read it, now ;))....
But, I'm a little confused, now.... Just what kind of crontab entries
are you writing?
--
"Telling the truth to people who misunderstand you
is generally promoting a falsehood, isn't it?" --A. Hope
[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: Type: text/plain, Size: 139 bytes --]
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-08-05 8:14 ` Thien-Thi Nguyen
2003-08-05 14:00 ` Joshua Judson Rosen
@ 2003-08-05 15:48 ` Paul Jarc
1 sibling, 0 replies; 7+ messages in thread
From: Paul Jarc @ 2003-08-05 15:48 UTC (permalink / raw)
Cc: guile-user, guile-sources
Thien-Thi Nguyen <ttn@glug.org> wrote:
> SHELL=/some/simple/guile-shell
> 08 * * * * /home/ttn/etc/cron/hourly.scm
That should work, where guile-shell contains:
#!/bin/sh
# cron invokes "$SHELL" -c "command". $1 is -c; $2 is the name of our script.
exec guile -s "$2"
paul
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-08-05 14:00 ` Joshua Judson Rosen
@ 2003-08-05 17:11 ` Thien-Thi Nguyen
2003-08-05 18:12 ` Paul Jarc
0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2003-08-05 17:11 UTC (permalink / raw)
Cc: guile-user, prj
From: Joshua Judson Rosen <rozzin@geekspace.com>
Date: Tue, 5 Aug 2003 10:00:16 -0400
Then, with Paul's stanza, you could just leave SHELL as /bin/sh,
couldn't you? ;)
that's the starting premise, so the answer is of course, yes. what
other circular ponderings are we interested in today?
If you're using `(getenv "SHELL")' somewhere inside your scripts, you
could even set SHELL in the stanza..., though, it does seem hairier
to manually add the same header to every one of your scripts, and
that might be what your `scm2bin' is doing, as far as I know (I think
that I'll go read it, now ;))....
thank you for being rational.
But, I'm a little confused, now.... Just what kind of crontab entries
are you writing?
the kind that show up in "watch pstree" as extra clutter when requiring
a cron to /bin/sh to guile double fork. background:
http://www.glug.org/maint/explanation.html
(guile-sources trimmed from cc.)
thi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: scm2bin.scm 1.0
2003-08-05 17:11 ` Thien-Thi Nguyen
@ 2003-08-05 18:12 ` Paul Jarc
0 siblings, 0 replies; 7+ messages in thread
From: Paul Jarc @ 2003-08-05 18:12 UTC (permalink / raw)
Cc: guile-user, rozzin
Thien-Thi Nguyen <ttn@glug.org> wrote:
> But, I'm a little confused, now.... Just what kind of crontab entries
> are you writing?
>
> the kind that show up in "watch pstree" as extra clutter when requiring
> a cron to /bin/sh to guile double fork. background:
If all you want is to get rid of the extra process, sh has exec.
paul
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-08-05 18:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-30 16:26 scm2bin.scm 1.0 Thien-Thi Nguyen
2003-08-04 15:58 ` Paul Jarc
2003-08-05 8:14 ` Thien-Thi Nguyen
2003-08-05 14:00 ` Joshua Judson Rosen
2003-08-05 17:11 ` Thien-Thi Nguyen
2003-08-05 18:12 ` Paul Jarc
2003-08-05 15:48 ` Paul Jarc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).