factor-out environment.
* gash/environment.scm: New file. * build-aux/build-guile.sh (SCM_FILES): Add it. * gash/peg.scm: Include it. (assignment, %global-variables, set-shell-opt!, variable): Remove.
This commit is contained in:
parent
23a13b0890
commit
56a36baee5
|
@ -39,6 +39,7 @@ SCM_FILES="
|
|||
gash/bournish-commands.scm
|
||||
gash/builtins.scm
|
||||
gash/config.scm
|
||||
gash/environment.scm
|
||||
gash/guix-build-utils.scm
|
||||
gash/gash.scm
|
||||
gash/io.scm
|
||||
|
|
|
@ -24,10 +24,11 @@
|
|||
|
||||
#:use-module (gash bournish-commands)
|
||||
#:use-module (gash config)
|
||||
#:use-module (gash environment)
|
||||
#:use-module (gash gash)
|
||||
#:use-module (gash job)
|
||||
#:use-module (gash io)
|
||||
#:use-module (gash peg)
|
||||
;;#:use-module (gash peg)
|
||||
|
||||
#:export (
|
||||
%builtin-commands
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
;;; Gash -- Guile As SHell
|
||||
;;; Copyright © 2018 R.E.W. van Beusekom <rutger.van.beusekom@gmail.com>
|
||||
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
;;;
|
||||
;;; This file is part of Gash.
|
||||
;;;
|
||||
;;; Gash 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.
|
||||
;;;
|
||||
;;; Gash 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 Gash. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
(define-module (gash environment)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:export (
|
||||
%global-variables
|
||||
assignment
|
||||
set-shell-opt!
|
||||
variable
|
||||
))
|
||||
|
||||
;; FIXME: export/env vs set
|
||||
(define %global-variables
|
||||
(map identity ;; FIXME: make mutable
|
||||
`(,(cons "SHELLOPTS" "")
|
||||
,(cons "PIPESTATUS" "([0]=\"0\"")
|
||||
,(cons "?" "0")
|
||||
,@(map (lambda (key-value)
|
||||
(let* ((key-value (string-split key-value #\=))
|
||||
(key (car key-value))
|
||||
(value (cadr key-value)))
|
||||
(cons key value)))
|
||||
(environ)))))
|
||||
|
||||
(define (assignment name value)
|
||||
(set! %global-variables
|
||||
(assoc-set! %global-variables name value))
|
||||
#t)
|
||||
|
||||
(define (variable name)
|
||||
(or (assoc-ref %global-variables (string-drop name 1)) ""))
|
||||
|
||||
(define (set-shell-opt! name set?)
|
||||
(let* ((shell-opts (variable "SHELLOPTS"))
|
||||
(options (if (string-null? shell-opts) '()
|
||||
(string-split shell-opts #\:)))
|
||||
(new-options (if set? (delete-duplicates (sort (cons name options) string<))
|
||||
(filter (negate (cut equal? <> name)) options)))
|
||||
(new-shell-opts (string-join new-options ":")))
|
||||
(assignment "SHELLOPTS" new-shell-opts)))
|
|
@ -15,6 +15,7 @@
|
|||
#:use-module (ice-9 regex)
|
||||
|
||||
#:use-module (gash config)
|
||||
#:use-module (gash environment)
|
||||
#:use-module (gash job)
|
||||
#:use-module (gash pipe)
|
||||
#:use-module (gash peg)
|
||||
|
@ -72,7 +73,7 @@ gash [options]
|
|||
(display (string-append "
|
||||
GASH " %version "
|
||||
|
||||
Copryright (C) 2016,2017,2018 R.E.W. van Beusekom, rutger.van.beusekom@gmail.com.
|
||||
Copryright (C) 2016,2017,2018 R.E.W. van Beusekom <rutger.van.beusekom@gmail.com>
|
||||
|
||||
This is gash, Guile As SHell. Gash is free software and is covered by
|
||||
the GNU General Public License version 3 or later, see COPYING for the
|
||||
|
|
34
gash/peg.scm
34
gash/peg.scm
|
@ -12,17 +12,15 @@
|
|||
#:use-module (srfi srfi-26)
|
||||
|
||||
#:use-module (gash builtins)
|
||||
#:use-module (gash environment)
|
||||
#:use-module (gash gash)
|
||||
#:use-module (gash io)
|
||||
#:use-module (gash job)
|
||||
#:use-module (gash util)
|
||||
|
||||
#:export (
|
||||
assignment
|
||||
%global-variables
|
||||
parse
|
||||
peg-trace?
|
||||
set-shell-opt!
|
||||
))
|
||||
|
||||
(define (wrap-parser-for-users for-syntax parser accumsym s-syn)
|
||||
|
@ -276,15 +274,6 @@
|
|||
(('else-part o ...) `(begin ,@(map transform o)))
|
||||
(_ ast)))
|
||||
|
||||
(define (set-shell-opt! name set?)
|
||||
(let* ((shell-opts (assoc-ref %global-variables "SHELLOPTS"))
|
||||
(options (if (string-null? shell-opts) '()
|
||||
(string-split shell-opts #\:)))
|
||||
(new-options (if set? (delete-duplicates (sort (cons name options) string<))
|
||||
(filter (negate (cut equal? <> name)) options)))
|
||||
(new-shell-opts (string-join new-options ":")))
|
||||
(assignment "SHELLOPTS" new-shell-opts)))
|
||||
|
||||
(define (builtin ast)
|
||||
(when (> %debug-level 0)
|
||||
(format (current-error-port) "builtin ast=~s\n" ast))
|
||||
|
@ -307,19 +296,6 @@
|
|||
command)))
|
||||
(else #f)))))
|
||||
|
||||
;; FIXME: export/env vs set
|
||||
(define %global-variables
|
||||
(map identity ;; FIXME: make mutable
|
||||
`(,(cons "SHELLOPTS" "")
|
||||
,(cons "PIPESTATUS" "([0]=\"0\"")
|
||||
,(cons "?" "0")
|
||||
,@(map (lambda (key-value)
|
||||
(let* ((key-value (string-split key-value #\=))
|
||||
(key (car key-value))
|
||||
(value (cadr key-value)))
|
||||
(cons key value)))
|
||||
(environ)))))
|
||||
|
||||
(define (glob pattern)
|
||||
(define (glob? pattern)
|
||||
(and (string? pattern) (string-match "\\?|\\*" pattern)))
|
||||
|
@ -355,14 +331,6 @@
|
|||
(define (doublequotes . o)
|
||||
(string-join (append-map glob o) ""))
|
||||
|
||||
(define (assignment name value)
|
||||
(set! %global-variables
|
||||
(assoc-set! %global-variables name value))
|
||||
#t)
|
||||
|
||||
(define (variable name)
|
||||
(or (assoc-ref %global-variables (string-drop name 1)) ""))
|
||||
|
||||
(define (expression . args)
|
||||
(append-map glob args))
|
||||
|
||||
|
|
Loading…
Reference in New Issue