;;; -*-lisp-*- ;;; ;;; Evaluate expressions and run scripts ;;; ;;; (c) 2020 Mark Wooding ;;; ;;;----- Licensing notice --------------------------------------------------- ;;; ;;; This file is part of Runlisp, a tool for invoking Common Lisp scripts. ;;; ;;; Runlisp is free software: you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by the ;;; Free Software Foundation; either version 3 of the License, or (at your ;;; option) any later version. ;;; ;;; Runlisp is distributed in the hope that it will be useful, but WITHOUT ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ;;; for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Runlisp. If not, see . (cl:defpackage #:runlisp (:use #:common-lisp)) (cl:in-package #:runlisp) (setf *features* (remove :runlisp-script *features*)) (let ((*package* (find-package "COMMON-LISP-USER"))) (let ((token (cons 'token nil)) (args uiop:*command-line-arguments*) (list nil)) (flet ((foreach-form (func arg) (with-input-from-string (in arg) (loop (let ((form (read in nil token))) (when (eq form token) (return)) (funcall func form))))) (print-form (form) (format t "~@[~{~S~^ ~}~%~]" (multiple-value-list (eval form))))) (loop (let ((arg (pop args))) (when (or (null arg) (string= arg "--")) (return)) (when (zerop (length arg)) (error "empty argument (no indicator)")) (let ((rest (subseq arg 1))) (ecase (char arg 0) (#\! (push (lambda () (foreach-form #'eval rest)) list)) (#\? (push (lambda () (foreach-form #'print-form rest)) list)) (#\< (push (lambda () (load rest)) list))))))) (let ((uiop:*command-line-arguments* args)) (mapc #'funcall (nreverse list)))))