Make 'trap' handle a numerical action.
* gash/built-ins/utils.scm (string->nonnegative-integer): New procedure. * gash/built-ins/trap.scm (main): If the first argument is a number, treat it as if the action were '-'.
This commit is contained in:
parent
38001cb76d
commit
6990d656bc
|
@ -17,6 +17,7 @@
|
|||
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
(define-module (gash built-ins trap)
|
||||
#:use-module (gash built-ins utils)
|
||||
#:use-module (gash compat)
|
||||
#:use-module (gash environment)
|
||||
#:use-module (ice-9 match))
|
||||
|
@ -54,6 +55,8 @@
|
|||
(match args
|
||||
(() "print")
|
||||
(("--" . args) (main args))
|
||||
(((? string->nonnegative-integer n) conditions ...)
|
||||
(apply main (cons "-" args)))
|
||||
((action conditions ..1)
|
||||
(let ((handler (action->handler action)))
|
||||
(for-each (lambda (condition)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
built-in?
|
||||
split-assignment
|
||||
string->positive-integer
|
||||
string->nonnegative-integer
|
||||
string->exit-status))
|
||||
|
||||
;;; Commentary:
|
||||
|
@ -68,6 +69,14 @@
|
|||
(lambda (n)
|
||||
(and (exact-integer? n) (> n 0) n))))
|
||||
|
||||
(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))))
|
||||
|
||||
(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
|
||||
|
|
Loading…
Reference in New Issue