;;; Copyright (c) 2019 David Ireland. All rights reserved. ;;; BSD 3-Clause License: http://opensource.org/licenses/BSD-3-Clause (import args scheme srfi-69 srfi-13 chicken.port chicken.process-context) (include "shen-core.scm") (define (usage) (with-output-to-port (current-error-port) (lambda () (print "Usage: shen [options] [...args...]") (print " -h, --help : Prints help and exits") (print " -l, --load : Loads Shen ") (print " -e, --eval : Evaluates ") (print " -r, --repl : Run the REPL, even if -l or -e are provided") (print "Any additional arguments are passed to the Shen system in") (print "the variable shen-wasp.*argv*"))) (exit 1)) (define opts (list (args:make-option (e eval) #:required "evaluate") (args:make-option (l load) #:required "load") (args:make-option (h help) #:none "display") (args:make-option (r repl) #:none "repl") )) (define (process-load file) (map (lambda (x) (kl:shen.eval-without-macros x)) (kl:read-file file))) (define (process-eval str) (let ((shen (with-input-from-string str read))) (if (list? shen) (map (lambda (x) (kl:shen.eval-without-macros x)) shen) (kl:shen.eval-without-macros x)))) (receive (options operands) (args:parse (command-line-arguments) opts) (cond ((alist-ref 'load options) (process-load (alist-ref 'load options))) ((alist-ref 'eval options) (process-eval (alist-ref 'evaluate options))) ((alist-ref 'help options) (usage)) (else (kl:shen.shen))))