From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.bugs Subject: bug#21698: accessing multiple flagged values with (ice-9 getopt-long) Date: Sat, 17 Oct 2015 10:05:53 -0700 Message-ID: <0B36F95D-923F-465F-A7CA-52C98F58AFC7@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_D42C07B0-EF94-4EA9-82E5-B3C94F8D9D47" X-Trace: ger.gmane.org 1445109627 11414 80.91.229.3 (17 Oct 2015 19:20:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Oct 2015 19:20:27 +0000 (UTC) Cc: Matthew Wette To: 21698@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Oct 17 21:20:14 2015 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZnX1T-0000S3-3L for guile-bugs@m.gmane.org; Sat, 17 Oct 2015 21:20:07 +0200 Original-Received: from localhost ([::1]:59537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnX1S-0006NZ-7k for guile-bugs@m.gmane.org; Sat, 17 Oct 2015 15:20:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnWE5-0007k8-R6 for bug-guile@gnu.org; Sat, 17 Oct 2015 14:29:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnWE2-0001ME-LS for bug-guile@gnu.org; Sat, 17 Oct 2015 14:29:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnWE2-0001MA-IF for bug-guile@gnu.org; Sat, 17 Oct 2015 14:29:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZnWE2-0007Ys-DR for bug-guile@gnu.org; Sat, 17 Oct 2015 14:29:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matt Wette Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 17 Oct 2015 18:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21698 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.144510649028996 (code B ref -1); Sat, 17 Oct 2015 18:29:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 17 Oct 2015 18:28:10 +0000 Original-Received: from localhost ([127.0.0.1]:54605 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnWDB-0007Xb-AI for submit@debbugs.gnu.org; Sat, 17 Oct 2015 14:28:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54872) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZnUvz-0005di-81 for submit@debbugs.gnu.org; Sat, 17 Oct 2015 13:06:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnUvy-0008QO-1A for submit@debbugs.gnu.org; Sat, 17 Oct 2015 13:06:18 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:46325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUvx-0008QK-U4 for submit@debbugs.gnu.org; Sat, 17 Oct 2015 13:06:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUvx-0004Ig-16 for bug-guile@gnu.org; Sat, 17 Oct 2015 13:06:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnUvt-0008Ps-03 for bug-guile@gnu.org; Sat, 17 Oct 2015 13:06:16 -0400 Original-Received: from vms173025pub.verizon.net ([206.46.173.25]:52141) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnUvs-0008Ph-Fq for bug-guile@gnu.org; Sat, 17 Oct 2015 13:06:12 -0400 Original-Received: from [192.168.2.127] ([72.87.204.128]) by vms173025.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0NWD009H2JHVGUC0@vms173025.mailsrvcs.net> for bug-guile@gnu.org; Sat, 17 Oct 2015 12:05:56 -0500 (CDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=WpDWSorv c=1 sm=1 tr=0 a=Jf1g6iwM2K3MHzQE8uPn/Q==:117 a=o1OHuDzbAAAA:8 a=oR5dmqMzAAAA:8 a=5lJygRwiOn0A:10 a=2uEN-48ru5wOoboNUTwA:9 a=CjuIK1q_8ugA:10 a=hZV0AYy1jCtPVrdHdrEA:9 a=l57CAgH5AiQDqgUi:21 a=_W_S_7VecoQA:10 a=QpKWWIOaL3wNxZuwVIAA:9 a=boEB8yKzicCxs0FBlv8A:9 X-Mailer: Apple Mail (2.2104) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Mailman-Approved-At: Sat, 17 Oct 2015 14:28:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-Mailman-Approved-At: Sat, 17 Oct 2015 15:20:02 -0400 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7862 Archived-At: --Apple-Mail=_D42C07B0-EF94-4EA9-82E5-B3C94F8D9D47 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This is in reference to guile-2.0.11. The (ice-9 getopt-long) module does not provide a process for accessing = multiple command line arguments. A patch for ice-9/getopt-long.scm is attached which adds the procedure = getopt-ref/many to access multiple argument values. The following program and results illustrate the use of the current = getopt-ref and the proposed getopt-ref/many: mwette$ ./gotest.scm -f foo1 -b bar1 -f foo2 baz1 baz2 program arguments: ("./gotest.scm" "-f" "foo1" "-b" "bar1" "-f" "foo2" "baz1" "baz2") getopt using option-ref: foo: "foo2" bar: "bar1" getopt using option-ref/many: foo: ("foo1" "foo2") bar: "bar1" where mwette$ cat gotest.scm=20 #!/opt/local/bin/guile !# (use-modules (ice-9 getopt-long)) (define spec '((foo (single-char #\f) (value #t)) (bar (single-char #\b) (value #t)))) (let* ((args (program-arguments)) (opts (getopt-long args spec))) (simple-format #t "program arguments:\n") (simple-format #t "~S\n" args) (simple-format #t "\ngetopt using option-ref:\n") (simple-format #t "foo: ~S\n" (option-ref opts 'foo #f)) (simple-format #t "bar: ~S\n" (option-ref opts 'bar #f)) (simple-format #t "\ngetopt using option-ref/many:\n") (simple-format #t "foo: ~S\n" (option-ref/many opts 'foo #f)) (simple-format #t "bar: ~S\n" (option-ref/many opts 'bar #f)) ) --Apple-Mail=_D42C07B0-EF94-4EA9-82E5-B3C94F8D9D47 Content-Type: multipart/mixed; boundary="Apple-Mail=_D66DC0BE-2CBC-4D8A-AF46-69E69764E4BB" --Apple-Mail=_D66DC0BE-2CBC-4D8A-AF46-69E69764E4BB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii This is in reference to guile-2.0.11.

The (ice-9 getopt-long) module does not = provide a process for accessing multiple command line = arguments.

A = patch for ice-9/getopt-long.scm  is attached which adds the = procedure getopt-ref/many to access multiple argument values.

The following program = and results illustrate the use of the current getopt-ref and the = proposed getopt-ref/many:

mwette$ ./gotest.scm -f foo1 -b bar1 -f foo2 baz1 = baz2

program arguments:

("./gotest.scm" "-f" "foo1" "-b" = "bar1" "-f" "foo2" "baz1" "baz2")


getopt using option-ref:

foo: "foo2"

bar: "bar1"


getopt using option-ref/many:

foo: ("foo1" = "foo2")

bar: "bar1"



where

mwette$ cat = gotest.scm 

#!/opt/local/bin/guile

!#

(use-modules (ice-9 getopt-long))


(define spec

 '((foo (single-char #\f) (value #t))

   (bar (single-char #\b) (value #t))))


(let* ((args (program-arguments))

       (opts (getopt-long args = spec)))

  (simple-format #t "program arguments:\n")

  (simple-format #t "~S\n" args)


  (simple-format #t "\ngetopt using option-ref:\n")

  (simple-format #t "foo: ~S\n" (option-ref opts 'foo = #f))

  (simple-format #t "bar: ~S\n" (option-ref opts 'bar = #f))


  (simple-format #t "\ngetopt using = option-ref/many:\n")

  (simple-format #t "foo: ~S\n" (option-ref/many opts = 'foo #f))

  (simple-format #t "bar: ~S\n" (option-ref/many opts = 'bar #f))

  )

= --Apple-Mail=_D66DC0BE-2CBC-4D8A-AF46-69E69764E4BB Content-Disposition: attachment; filename=getopt-long.patch Content-Type: application/octet-stream; name="getopt-long.patch" Content-Transfer-Encoding: 7bit *** 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 --Apple-Mail=_D66DC0BE-2CBC-4D8A-AF46-69E69764E4BB Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
--Apple-Mail=_D66DC0BE-2CBC-4D8A-AF46-69E69764E4BB-- --Apple-Mail=_D42C07B0-EF94-4EA9-82E5-B3C94F8D9D47--