Comment detail

起動オプションの解析 (Nested Flatten)

SRFI-37 や SLIB を使う方法もありますが、とりあえずは gauche.parseopt 版。 -oq のような指定や -d1, -d2 のような指定には対応していないようです。

ところで起動例にある -s オプションは -d ですよね?

;; エラー処理で悩んでしまった。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(use gauche.parseopt)
(use gauche.sequence)

(define (main args)
  (let-args (cdr args)
      ((output "o|output" #f)
       (quiet  "q|quiet"  #f)
       (debug  "d|debug=i" 0)
       . argv)
    (cond
     ((not output)
      (format (current-error-port)
              "output option is not supplied.~%"))
     ((not (memv debug '(0 1 2)))
      (format (current-error-port)
              "debug option's value must be 0, 1, or 2: ~A~%" debug))
     ((null? argv)
      (format (current-error-port)
              "no arguments are supplied.~%"))
     (else
      (format #t "[options]~%o(output): ON~%q(quote): ~A~%d(debug): ~A~%~%"
              (if quiet 'ON 'OFF)
              debug)
      (format #t "[parameters]~%# of pamameters: ~A~%" (length argv))
      (for-each-with-index (lambda (i x) (format #t "~A: ~A~%" (+ i 1) x))
                           argv)
      (exit 0)))
    1))

Index

Feed

Other

Link

Pathtraq

loading...