2018-11-21 19:58:03 +00:00
|
|
|
;;; The Geesh Shell Interpreter
|
|
|
|
;;; Copyright 2018 Timothy Sample <samplet@ngyro.com>
|
|
|
|
;;;
|
|
|
|
;;; This file is part of Geesh.
|
|
|
|
;;;
|
|
|
|
;;; Geesh 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.
|
|
|
|
;;;
|
|
|
|
;;; Geesh 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 Geesh. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (geesh built-ins set)
|
|
|
|
#:use-module (geesh environment)
|
|
|
|
#:use-module (ice-9 match))
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; The 'set' utility.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
2018-11-26 01:59:18 +00:00
|
|
|
(define (option? o)
|
|
|
|
(memq o *option-names*))
|
|
|
|
|
|
|
|
(define (option-letter? chr)
|
|
|
|
(assoc chr *option-letters*))
|
|
|
|
|
|
|
|
(define (set-option! option value args)
|
|
|
|
(setopt! option value)
|
|
|
|
(unless (null? args)
|
|
|
|
(set-program-arguments (cons (car (program-arguments)) args))))
|
2018-11-21 19:58:03 +00:00
|
|
|
|
Globalize the environment module
Instead of passing around references to the environment, just treat it
as a global. The old way was just the remains of an idea to make the
environment immutable and keep the interpreter from manipulating any
global state. By making everything global and mutable, we will have
less impedance mismatch with POSIX going forward.
The following changelog is only a sketch, since nearly every function
has changed.
* geesh/environment.scm: Replace this module with one that treats the
environment as a global resource.
* tests/environment.scm: Delete file.
* Makefile.am: Remove it from the list of tests.
* geesh/shell.scm, geesh/eval.scm, geesh/repl.scm, geesh/word.scm,
geesh/built-ins/break.scm, geesh/built-ins/continue.scm,
geesh/built-ins/echo.scm, geesh/built-ins/export.scm,
geesh/built-ins/false.scm, geesh/built-ins/read.scm,
geesh/built-ins/readonly.scm, geesh/built-ins/set.scm,
geesh/built-ins/true.scm, geesh/built-ins/unset.scm: Remove 'env'
parameters and use the new environment module.
* .dir-locals.el: Update indentation of functions that no longer take
an 'env' parameter and add with-arguments, with-environ, and
with-variables from the new environment module.
* tests/shell.scm, tests/word.scm: Update environment creation and
manipulation in tests.
2018-11-25 05:47:09 +00:00
|
|
|
(define (main . args)
|
2018-11-21 19:58:03 +00:00
|
|
|
(match args
|
2018-11-26 01:59:18 +00:00
|
|
|
(("-o")
|
|
|
|
(for-each (lambda (option)
|
|
|
|
(format #t "~a\t~a~%"
|
|
|
|
option (getopt option)))
|
|
|
|
*option-names*)
|
|
|
|
EXIT_SUCCESS)
|
|
|
|
(("+o")
|
|
|
|
(for-each (lambda (option)
|
|
|
|
(format #t "set ~a ~a~%"
|
|
|
|
(if (getopt option) "-o" "+o") option))
|
|
|
|
*option-names*)
|
|
|
|
EXIT_SUCCESS)
|
|
|
|
(_ (let loop ((args args))
|
|
|
|
(match args
|
|
|
|
(() EXIT_SUCCESS)
|
|
|
|
(("--" . args)
|
|
|
|
(set-program-arguments (cons (car (program-arguments)) args))
|
|
|
|
EXIT_SUCCESS)
|
|
|
|
(("-o" option-string . args)
|
|
|
|
(let ((option (string->symbol option-string)))
|
|
|
|
(match option
|
|
|
|
((? option?)
|
|
|
|
(setopt! option #t)
|
|
|
|
(loop args))
|
|
|
|
(_ (format (current-error-port)
|
|
|
|
"~a: set: invalid option ~a~%"
|
|
|
|
(car (program-arguments)) option)
|
|
|
|
EXIT_FAILURE))))
|
|
|
|
(("+o" option-string . args)
|
|
|
|
(let ((option (string->symbol option-string)))
|
|
|
|
(match option
|
|
|
|
((? option?)
|
|
|
|
(setopt! option #f)
|
|
|
|
(loop args))
|
|
|
|
(_ (format (current-error-port)
|
|
|
|
"~a: set: invalid option ~a~%"
|
|
|
|
(car (program-arguments)) option)
|
|
|
|
EXIT_FAILURE))))
|
|
|
|
((op . args)
|
|
|
|
(match (string->list op)
|
|
|
|
((#\- (? option-letter? chr))
|
|
|
|
(setopt! (assoc-ref *option-letters* chr) #t)
|
|
|
|
(loop args))
|
|
|
|
((#\+ (? option-letter? chr))
|
|
|
|
(setopt! (assoc-ref *option-letters* chr) #f)
|
|
|
|
(loop args))
|
2018-12-04 15:09:38 +00:00
|
|
|
(_ (loop (cons* "--" op args)))))
|
2018-11-26 01:59:18 +00:00
|
|
|
(_ (format (current-error-port)
|
|
|
|
"~a: set: invalid options ~s~%"
|
|
|
|
(car (program-arguments)) args)
|
|
|
|
EXIT_FAILURE))))))
|