From c83dbcbdc8df1faba4a67e79d0f9c4018cd33d71 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Sun, 25 Nov 2018 20:57:08 -0500 Subject: [PATCH] Add options to the environment * geesh/environment.scm (*options*): New variable. (getopt): New public function. (setopt!): New public function. (*option-names*): New public variable. (*option-letters*): New public variable. --- geesh/environment.scm | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/geesh/environment.scm b/geesh/environment.scm index 6063d56..2136878 100644 --- a/geesh/environment.scm +++ b/geesh/environment.scm @@ -37,6 +37,10 @@ defun! unsetfun! with-arguments + getopt + setopt! + *option-names* + *option-letters* call-with-continue continue call-with-break @@ -234,6 +238,50 @@ made from within the dynamic extent of @var{thunk}." (set! inside-args (program-arguments)) (set-program-arguments outside-args))))) + +;;; Options. + +(define *options* + (map (cut cons <> #f) + '(allexport + errexit + ignoreeof + monitor + noclobber + noglob + noexec + nolog + notify + nounset + verbose + vi + xtrace))) + +(define (getopt name) + "Get the value of the option named @var{name}." + (match (assq name *options*) + ((_ . value) value))) + +(define (setopt! name value) + "Set the value of the option named @var{name} to @var{value}." + (match (assq name *options*) + ((? pair? p) (set-cdr! p value)))) + +(define *option-names* + (map car *options*)) + +(define *option-letters* + '((#\a . allexport) + (#\e . errexit) + (#\m . monitor) + (#\C . noclobber) + (#\f . noglob) + (#\n . noexec) + (#\b . notify) + (#\u . nounset) + (#\v . verbose) + (#\x . xtrace))) + ;;; Prompts