<commit_before>(cl:in-package :cl-user)
#-asdf (require :asdf)

(let ((*standard-output* (make-broadcast-stream)))
  #+sbcl (require :sb-posix))

(defpackage :ros
  (:use :cl)
  (:shadow :load :eval :package :restart :print :write)
  (:export :run :*argv* :*main* :quit :script :quicklisp :getenv :opt
           :ignore-shebang :roswell :exec :setenv :unsetenv))

(in-package :ros)
(defvar *verbose* 0)
(defvar *argv* nil)
(defvar *ros-opts* nil)
(defvar *main* nil)

;; small tools
(defun getenv (x)
  #+sbcl(sb-posix:getenv x)
  #-sbcl(funcall (read-from-string "asdf::getenv") x))

#+(and unix sbcl) ;; from swank
(progn
  (sb-alien:define-alien-routine ("execvp" %execvp) sb-alien:int
    (program sb-alien:c-string)
    (argv (* sb-alien:c-string)))

  (defun execvp (program args)
    "Replace current executable with another one."
    (let ((a-args (sb-alien:make-alien sb-alien:c-string
                                       (+ 1 (length args)))))
      (unwind-protect
           (progn
             (loop for index from 0 by 1
                and item in (append args '(nil))
                do (setf (sb-alien:deref a-args index)
                         item))
             (when (minusp
                    (%execvp program a-args))
               (let ((errno (sb-impl::get-errno)))
                 (case errno
                   (2 (error "No such file or directory: ~S" program))
                   (otherwise
                    (error "execvp(3) failed. (Code=~D)" errno))))))
        (sb-alien:free-alien a-args)))))

(defun setenv (name value)
  (declare (ignorable name value))
  #+sbcl(funcall (read-from-string "sb-posix:setenv") name value 1)
  #+ccl(ccl:setenv name value t))

(defun unsetenv (name)
  (declare (ignorable name))
  #+sbcl(funcall (read-from-string "sb-posix:unsetenv") name)
  #+ccl(ccl:unsetenv name))

(defun quit (&optional (return-code 0) &rest rest)
  (let ((ret (or (and (numberp return-code) return-code) (first rest) 0)))
    (ignore-errors(funcall 'asdf::quit ret))
    #+sbcl(ignore-errors(funcall (read-from-string "cl-user::exit") :code ret))
    #+sbcl(ignore-errors(funcall (read-from-string "cl-user::quit") :unix-status ret))))

(defun exec (args)
  #+(and unix sbcl)
  (execvp (first args) args)
  (funcall (read-from-string "uiop/run-program:run-program")
           (format nil "~{~A~^ ~}" args))
  (quit -1))

(defun ros-opts ()
  (or *ros-opts*
      (setf *ros-opts*
            (let((*read-eval*))
              (read-from-string (getenv "ROS_OPTS"))))))

(defun opt (param)
  (second (assoc param (ros-opts) :test 'equal)))

(defun quicklisp (&key path (environment "QUICKLISP_HOME"))
  (unless (find :quicklisp *features*)
    (cl:load
     (make-pathname
      :name "setup"
      :type "lisp"
      :defaults (or path
                    (and environment (getenv environment))
                    (opt "quicklisp"))))
    (let ((symbol (read-from-string "ql:*local-project-directories*")))
      (set symbol (cons (ensure-directories-exist (merge-pathnames "local-projects/" (opt "homedir")))
                        (symbol-value symbol))))))

#+quicklisp
(push (ensure-directories-exist (merge-pathnames "local-projects/" (opt "homedir"))) ql:*local-project-directories*)
<commit_msg>ros:quicklisp have to check setup.lisp exist or not.<commit_after>(cl:in-package :cl-user)
#-asdf (require :asdf)

(let ((*standard-output* (make-broadcast-stream)))
  #+sbcl (require :sb-posix))

(defpackage :ros
  (:use :cl)
  (:shadow :load :eval :package :restart :print :write)
  (:export :run :*argv* :*main* :quit :script :quicklisp :getenv :opt
           :ignore-shebang :roswell :exec :setenv :unsetenv))

(in-package :ros)
(defvar *verbose* 0)
(defvar *argv* nil)
(defvar *ros-opts* nil)
(defvar *main* nil)

;; small tools
(defun getenv (x)
  #+sbcl(sb-posix:getenv x)
  #-sbcl(funcall (read-from-string "asdf::getenv") x))

#+(and unix sbcl) ;; from swank
(progn
  (sb-alien:define-alien-routine ("execvp" %execvp) sb-alien:int
    (program sb-alien:c-string)
    (argv (* sb-alien:c-string)))

  (defun execvp (program args)
    "Replace current executable with another one."
    (let ((a-args (sb-alien:make-alien sb-alien:c-string
                                       (+ 1 (length args)))))
      (unwind-protect
           (progn
             (loop for index from 0 by 1
                and item in (append args '(nil))
                do (setf (sb-alien:deref a-args index)
                         item))
             (when (minusp
                    (%execvp program a-args))
               (let ((errno (sb-impl::get-errno)))
                 (case errno
                   (2 (error "No such file or directory: ~S" program))
                   (otherwise
                    (error "execvp(3) failed. (Code=~D)" errno))))))
        (sb-alien:free-alien a-args)))))

(defun setenv (name value)
  (declare (ignorable name value))
  #+sbcl(funcall (read-from-string "sb-posix:setenv") name value 1)
  #+ccl(ccl:setenv name value t))

(defun unsetenv (name)
  (declare (ignorable name))
  #+sbcl(funcall (read-from-string "sb-posix:unsetenv") name)
  #+ccl(ccl:unsetenv name))

(defun quit (&optional (return-code 0) &rest rest)
  (let ((ret (or (and (numberp return-code) return-code) (first rest) 0)))
    (ignore-errors(funcall 'asdf::quit ret))
    #+sbcl(ignore-errors(funcall (read-from-string "cl-user::exit") :code ret))
    #+sbcl(ignore-errors(funcall (read-from-string "cl-user::quit") :unix-status ret))))

(defun exec (args)
  #+(and unix sbcl)
  (execvp (first args) args)
  (funcall (read-from-string "uiop/run-program:run-program")
           (format nil "~{~A~^ ~}" args))
  (quit -1))

(defun ros-opts ()
  (or *ros-opts*
      (setf *ros-opts*
            (let((*read-eval*))
              (read-from-string (getenv "ROS_OPTS"))))))

(defun opt (param)
  (second (assoc param (ros-opts) :test 'equal)))

(defun quicklisp (&key path (environment "QUICKLISP_HOME"))
  (unless (find :quicklisp *features*)
    (let ((path (make-pathname
                 :name "setup"
                 :type "lisp"
                 :defaults (or path
                               (and environment (getenv environment))
                               (opt "quicklisp")))))
      (when (probe-file path)
        (cl:load path)
        (let ((symbol (read-from-string "ql:*local-project-directories*")))
          (set symbol (cons (ensure-directories-exist (merge-pathnames "local-projects/" (opt "homedir")))
                            (symbol-value symbol))))
        t))))

#+quicklisp
(push (ensure-directories-exist (merge-pathnames "local-projects/" (opt "homedir"))) ql:*local-project-directories*)

{'fraction_non_alphanumeric': 0.16576900059844404, 'fraction_numerical': 0.002992220227408737, 'mean_word_length': 2.601831896551724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5787873', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2310, 'n_words': 584}