*** getopt-long.scm-orig	2015-10-15 06:40:29.000000000 -0700
--- getopt-long.scm	2015-10-17 09:42:41.000000000 -0700
***************
*** 154,159 ****
--- 154,173 ----
  ;;; (option-ref (getopt-long ...) 'x-includes 42) => "/usr/include"
  ;;; (option-ref (getopt-long ...) 'not-a-key! 31) => 31
  
+ ;;; (option-ref/many OPTIONS KEY DEFAULT)
+ ;;; Return value in alist OPTIONS using KEY, a symbol; or DEFAULT if not
+ ;;; found.  If multiple arg-options provided a list is returned.  The value
+ ;;; is either a string, a list or `#t'.
+ ;;;
+ ;;; For example, if the above was executed with multiple x-includes flags,
+ ;;; then all will be returned in a list:
+ ;;;
+ ;;; (getopt-long '("my-prog" "-vk" "/tmp" "foo1" "--x-includes=/usr/include"
+ ;;;                "--x-includes=/opt/includd" "--" "-fred" "foo2" "foo3")
+ ;;;                grammar)
+ ;;; (option-ref/many (getopt-long ...) 'x-includes 42)
+ ;;; => ("/usr/include" "/opt/include")
+ 
  ;;; Code:
  
  (define-module (ice-9 getopt-long)
***************
*** 162,168 ****
    #:use-module (ice-9 match)
    #:use-module (ice-9 regex)
    #:use-module (ice-9 optargs)
!   #:export (getopt-long option-ref))
  
  (define %program-name (make-fluid "guile"))
  (define (program-name)
--- 176,182 ----
    #:use-module (ice-9 match)
    #:use-module (ice-9 regex)
    #:use-module (ice-9 optargs)
!   #:export (getopt-long option-ref option-ref/many))
  
  (define %program-name (make-fluid "guile"))
  (define (program-name)
***************
*** 368,371 ****
--- 382,397 ----
  The value is either a string or `#t'."
    (or (assq-ref options key) default))
  
+ (define (option-ref/many options key default)
+   "Return value, or values, in alist OPTIONS using KEY, a symbol; or DEFAULT if not found.
+ The value is either a string, a list or `#t'."
+   (let loop ((rez #f) (opts options))
+     (if (null? opts) (or rez default)
+ 	(if (eq? key (caar opts))
+ 	    (cond
+ 	     ((pair? rez) (loop (cons (cdar opts) res) (cdr opts)))
+ 	     (rez (loop (list (cdar opts) rez) (cdr opts)))
+ 	     (else (loop (cdar opts) (cdr opts))))
+ 	    (loop rez (cdr opts))))))
+ 
  ;;; getopt-long.scm ends here
