Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash -- Guile As SHell
|
2019-02-15 15:10:35 +00:00
|
|
|
;;; Copyright © 2018, 2019 Timothy Sample <samplet@ngyro.com>
|
2018-11-21 18:34:30 +00:00
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; This file is part of Gash.
|
2018-11-21 18:34:30 +00:00
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash is free software: you can redistribute it and/or modify
|
2018-11-21 18:34:30 +00:00
|
|
|
;;; 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.
|
|
|
|
;;;
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; Gash is distributed in the hope that it will be useful,
|
2018-11-21 18:34:30 +00:00
|
|
|
;;; 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
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
|
2018-11-21 18:34:30 +00:00
|
|
|
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
(define-module (gash built-ins utils)
|
2019-08-26 02:02:29 +01:00
|
|
|
#:use-module (gash compat)
|
2018-11-21 18:34:30 +00:00
|
|
|
#:use-module (ice-9 match)
|
2022-04-29 01:15:11 +01:00
|
|
|
#:use-module (srfi srfi-14)
|
2018-11-26 03:42:05 +00:00
|
|
|
#:export (get-evaluator
|
2018-12-31 10:08:49 +00:00
|
|
|
built-in?
|
2019-06-07 16:51:53 +01:00
|
|
|
split-assignment
|
2019-06-15 01:58:23 +01:00
|
|
|
string->positive-integer
|
2019-10-11 14:43:19 +01:00
|
|
|
string->nonnegative-integer
|
2019-06-15 01:58:23 +01:00
|
|
|
string->exit-status))
|
2018-11-21 18:34:30 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; Utility functions shared by built-ins.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
2018-11-26 03:42:05 +00:00
|
|
|
;; We need to be able to run Shell code from the 'dot' and 'eval'
|
|
|
|
;; built-ins. This is a bit of trickery to avoid a module dependency
|
|
|
|
;; loop.
|
|
|
|
(define (get-evaluator)
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
(module-ref (resolve-interface '(gash eval)) 'eval-sh))
|
2018-11-26 03:42:05 +00:00
|
|
|
|
2018-12-31 10:08:49 +00:00
|
|
|
;; Similar to 'get-evaluator', we avoid a dependency loop by looking
|
|
|
|
;; up functions dynamically.
|
|
|
|
(define (built-in? name)
|
|
|
|
(let ((search-special-built-ins
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
(module-ref (resolve-interface '(gash built-ins))
|
2018-12-31 10:08:49 +00:00
|
|
|
'search-special-built-ins))
|
|
|
|
(search-built-ins
|
Remove (almost) all references to Geesh.
gash/environment.scm: Remove file.
geesh/*: Move these files into the 'gash' folder and replace all
instances of the word 'geesh'.
scripts/geesh.in: Remove file.
HACKING, INSTALL, Makefile.am, configure.ac, guix.scm,
tests/bootstrap/bash-without-bash.scm, tests/spec/Makefile.am,
tests/spec/check-spec, tests/spec/oil.scm, tests/unit/*,
tools/coverage.in: Replace all instances of the word 'geesh'.
Co-authored-by: Jan Nieuwenhuizen <janneke@gnu.org>
2019-02-15 00:55:07 +00:00
|
|
|
(module-ref (resolve-interface '(gash built-ins))
|
2018-12-31 10:08:49 +00:00
|
|
|
'search-built-ins)))
|
|
|
|
(or (search-special-built-ins name)
|
|
|
|
(search-built-ins name))))
|
|
|
|
|
2018-11-21 18:34:30 +00:00
|
|
|
(define (split-assignment assignment)
|
|
|
|
(match (string-index assignment #\=)
|
|
|
|
(#f (values assignment #f))
|
|
|
|
(index (let ((name (substring assignment 0 index)))
|
|
|
|
(match (substring assignment (1+ index))
|
|
|
|
((? string-null?) (values name #f))
|
|
|
|
(value (values name value)))))))
|
2019-06-07 16:51:53 +01:00
|
|
|
|
|
|
|
(define char-set:ascii-digit
|
|
|
|
(char-set-intersection char-set:ascii char-set:digit))
|
|
|
|
|
|
|
|
(define (string->positive-integer s)
|
|
|
|
"Return the positive integer represented by the string @var{s}. If
|
2019-11-26 01:02:12 +00:00
|
|
|
@var{s} does not represent a positive, decimal integer return
|
2019-06-07 16:51:53 +01:00
|
|
|
@code{#f}."
|
|
|
|
(and=> (and (string-every char-set:ascii-digit s) (string->number s))
|
|
|
|
(lambda (n)
|
|
|
|
(and (exact-integer? n) (> n 0) n))))
|
2019-06-15 01:58:23 +01:00
|
|
|
|
2019-10-11 14:43:19 +01:00
|
|
|
(define (string->nonnegative-integer s)
|
|
|
|
"Return the nonnegative integer represented by the string @var{s}.
|
|
|
|
If @var{s} does not represent a nonnegative, decimal integer return
|
|
|
|
@code{#f}."
|
|
|
|
(and=> (and (string-every char-set:ascii-digit s) (string->number s))
|
|
|
|
(lambda (n)
|
|
|
|
(and (exact-integer? n) (>= n 0) n))))
|
|
|
|
|
2019-06-15 01:58:23 +01:00
|
|
|
(define (string->exit-status s)
|
|
|
|
"Return the exit status represented by the string @var{s}. If
|
|
|
|
@var{s} does not represent an exit status (a decimal integer from 0 to
|
|
|
|
255) return @code{#f}."
|
|
|
|
(and=> (and (string-every char-set:ascii-digit s) (string->number s))
|
|
|
|
(lambda (n)
|
|
|
|
(and (exact-integer? n) (>= n 0) (<= n 255) n))))
|