31 lines
954 B
Common Lisp
31 lines
954 B
Common Lisp
;;;; clscopes/util
|
|
|
|
;;;; Common utilities for the scopes project.
|
|
|
|
(defpackage :scopes/util
|
|
(:use :common-lisp)
|
|
(:export #:home-path #:relative-path #:runtime-path #:system-path))
|
|
|
|
(in-package :scopes/util)
|
|
|
|
(defun split-filename (name)
|
|
(let* ((parts (str:rsplit "." name :limit 2))
|
|
(n (car parts))
|
|
(type (cadr parts)))
|
|
(when (string= n "") ; leading dot, e.g. ".env"
|
|
(setf n name)
|
|
(setf type nil))
|
|
(values n type)))
|
|
|
|
(defun relative-path (name &rest dirs)
|
|
(multiple-value-bind (n type) (split-filename name)
|
|
(make-pathname :name n :type type :directory (cons :relative dirs))))
|
|
|
|
(defun runtime-path (name &rest dirs)
|
|
(merge-pathnames (apply #'relative-path name dirs)))
|
|
|
|
(defun home-path (name &rest dirs)
|
|
(merge-pathnames (apply #'relative-path name dirs) (user-homedir-pathname)))
|
|
|
|
(defun system-path (sys name &rest dirs)
|
|
(asdf:system-relative-pathname sys (apply #'relative-path name dirs)))
|