123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #!/bin/bash
- set -x -e -o pipefail
- cd $(mktemp -d)
- curl -s -L http://prdownloads.sourceforge.net/sbcl/sbcl-2.3.6-x86-64-linux-binary.tar.bz2 > sbcl.tar.bz2
- tar -xf sbcl.tar.bz2
- SBCL_DIR=$(ls | grep -v sbcl.tar.bz2)
- cp "$SBCL_DIR/output/sbcl.core" "$SBCL_DIR/src/runtime/"
- cat <<-EOF > ./spell.lisp
- (defvar *randomness* (make-random-state t))
- (defun split-string (string delimiter)
- (loop with len = (length string)
- with start = 0
- for end = (position delimiter string :start start)
- for substr = (if end
- (subseq string start end)
- (subseq string start))
- while end
- append (list substr)
- do (setf start (1+ end))
- until (= end len)))
- (defun list-files-in-directory (directory-path)
- (let* ((files (directory (merge-pathnames "*.*" (pathname directory-path))))
- (directory-pathname (pathname directory-path)))
- (mapcar #'(lambda (file)
- (merge-pathnames (pathname file) directory-pathname))
- files)))
- (defun bins-list ()
- (apply #'append
- (mapcar #'list-files-in-directory
- (loop for path in (split-string (sb-ext:posix-getenv "PATH") #\:)
- collect (format NIL "~a~c" path #\/)))))
- (defun random-bin (bins-list)
- (namestring (nth (random (length bins-list) *randomness*) bins-list)))
- (defun random-cmd (bins-list)
- (let ((number-of-pipes (random 4 *randomness*))
- (cmd-str ""))
- (if (> number-of-pipes 0)
- (progn
- (dotimes (i (+ 1 number-of-pipes))
- (setq cmd-str (concatenate 'string cmd-str (format NIL "~A | " (random-bin bins-list)))))
- (setq cmd-str (concatenate 'string (subseq cmd-str 0 (- (length cmd-str) 3)) (format NIL "~%"))))
- (setq cmd-str (concatenate 'string cmd-str (format NIL "~A~%" (random-bin bins-list)))))
- cmd-str))
-
- (format T "~a" (random-cmd (bins-list)))
- EOF
- $SBCL_DIR/src/runtime/sbcl --script spell.lisp
|