From db083ceaa136f9d8b987b0f9d151a1a3578d3709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 16 Aug 2020 23:14:16 +0200 Subject: Setup directories for dist. --- main | 1 + module/directories.scm | 15 +++++++++++++++ module/main.scm | 27 ++++++++++++++++++--------- module/repl.scm | 4 ---- module/util.scm | 15 +++++++++++++++ tzget | 3 +++ 6 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 module/directories.scm diff --git a/main b/main index f9bf296e..89c38e51 100755 --- a/main +++ b/main @@ -4,5 +4,6 @@ here=$(dirname $(realpath $0)) . $here/env GUILE=${GUILE:-guile} +# GUILE_LOAD_PATH=$here/module exec $GUILE -e main -s $here/module/main.scm "$@" diff --git a/module/directories.scm b/module/directories.scm new file mode 100644 index 00000000..32cd382a --- /dev/null +++ b/module/directories.scm @@ -0,0 +1,15 @@ +(define-module (directories) + :use-module (util)) + +(define-public runtime-directory + (or (getenv "XDG_RUNTIME_DIR") + "/tmp")) + +(define-public system-config-directory "/etc/calp") + +(define user-config-directory + (path-append + (or (getenv "XDG_CONFIG_HOME") + (and=> (getenv "HOME") + (lambda (s) (path-append s "/.config")))) + "/calp")) diff --git a/module/main.scm b/module/main.scm index 5455b20a..361c5473 100644 --- a/module/main.scm +++ b/module/main.scm @@ -1,9 +1,6 @@ ;; -*- geiser-scheme-implementation: guile -*- -(when (current-filename) - (add-to-load-path (dirname (current-filename)))) - -(set! (@ (global) basedir) (car %load-path)) +;; config (catch 'misc-error (lambda () (use-modules (autoconfig))) @@ -63,6 +60,8 @@ "Can " (i "not") " be given with an equal after --option." (br) "Can be given multiple times.")) + (setup-zoneinfo) + (help (single-char #\h) (description "Print this help")))) @@ -111,7 +110,8 @@ (when stprof (statprof-start)) - (cond [(eqv? #t repl) (repl-start (format #f "~a/calp-~a" (runtime-dir) (getpid)))] + (cond [(eqv? #t repl) (repl-start (format #f "~a/calp-~a" + runtime-directory (getpid)))] [repl => repl-start]) (if altconfig @@ -120,10 +120,12 @@ (primitive-load altconfig) (throw 'option-error "Configuration file ~a missing" altconfig))) ;; if not altconfig, then regular config - (let ((config-file (format #f "~a/.config/calp/config.scm" - (getenv "HOME")))) - (when (file-exists? config-file) - (primitive-load config-file)))) + + (awhen (find file-exists? + (list + (path-append user-config-directory "/config.scm") + (path-append system-config-directory "/config.scm"))) + (primitive-load it))) ;; NOTE this doesn't stop at first non-option, meaning that -o flags @@ -157,6 +159,13 @@ (throw 'return) ) + ;; ((@ (cache) load-cache)) + + ;; (when (option-ref opts 'setup-zoneinfo #f) + ;; (get-config 'libexec)/tzget + + ;; ) + (let ((ropt (ornull (option-ref opts '() '()) '("term")))) ((case (string->symbol (car ropt)) diff --git a/module/repl.scm b/module/repl.scm index 18e01d99..44a3ba2f 100644 --- a/module/repl.scm +++ b/module/repl.scm @@ -5,10 +5,6 @@ :use-module (util exceptions) ) -(define-public (runtime-dir) - (or (getenv "XDG_RUNTIME_DIR") - "/tmp")) - (define-public (repl-start address) (define lst (string->list address)) (format (current-error-port) diff --git a/module/util.scm b/module/util.scm index c1381edd..d5cf86a7 100644 --- a/module/util.scm +++ b/module/util.scm @@ -528,6 +528,21 @@ (define-public ->string ->str) +(define-public (path-append . strings) + (fold (lambda (s done) + (string-append + done + (if (string-null? s) + (string-append s "/") + (if (char=? #\/ (string-last done)) + (if (char=? #\/ (string-first s)) + (string-drop s 1) s) + (if (char=? #\/ (string-first s)) + s (string-append "/" s)))))) + (let ((s (car strings))) + (if (string-null? s) + "/" s)) + (cdr strings))) diff --git a/tzget b/tzget index 14c9b668..86758c75 100755 --- a/tzget +++ b/tzget @@ -5,8 +5,11 @@ # - the directory with the zoneinfo files # - the names of the zoneinfo files to be parsed +# Where to savze the file CACHE_DIR=${CACHE_DIR:-~/.cache/calp} +# Which file to get TAR=tzdata-latest.tar.gz +# Where to get it from TZ_SRC="https://www.iana.org/time-zones/repository/$TAR" mkdir -p $CACHE_DIR -- cgit v1.2.3