Ticket #1012: simplify-long-option-value-handling.patch

File simplify-long-option-value-handling.patch, 2.1 KB (added by evhan, 11 years ago)
  • getopt-long.scm

     
    434434          (else (error 'long-option-name
    435435                       "invalid list" lst)))))
    436436
    437 (define long-option-value-cs
    438   (char-set-union char-set:letter+digit
    439                   char-set:punctuation
    440                   (char-set #\_ #\^ #\$ #\=)))
    441 
    442437(define (long-option-value lst)
    443438  (if (null? lst) (list #f lst)
    444439      (let loop ((lst lst)  (ax (list)))
     
    447442             
    448443              ((and (char? (car lst)) (car lst)) =>
    449444               (lambda (c)
    450                  (cond ((char=? c #\")
    451                         (let quote-loop ((lst (cdr lst)) (ax ax))
    452                           (if (null? lst) (error 'long-option-value
    453                                                  "unclosed option value quotation")
    454                               (if (char=? (car lst) #\")
    455                                   (loop (cdr lst) ax)
    456                                   (quote-loop (cdr lst) (cons (car lst) ax))))))
    457 
    458                        ((char-set-contains? char-set:blank c)
    459                         (list (list->string (reverse ax)) (cdr lst)))
    460 
    461                        ((char-set-contains? long-option-value-cs c)
    462                         (loop (cdr lst) (cons c ax)))
    463 
    464                        (else  (error 'long-option-value
    465                                      "invalid option character" c)))))
     445                 (loop (cdr lst) (cons c ax))))
    466446             
    467447              (else (error 'long-option-value
    468448                           "invalid list" lst))))))
  • tests/run.scm

     
    134134 
    135135  ))
    136136
    137 (define cmdline2 '("--meta-filter=\"Note=,Archive Name=Brown\""
     137(define cmdline2 '("--meta-filter=Note=,Archive Name=Brown"
    138138                   "-d" "data" "FormSubmit.html"))
    139    
    140139
    141140(test-group "grammar2"
    142141
     
    150149   
    151150    )
    152151
     152(test-group "nonalnum"
     153
     154    (define nonalnum-grammar
     155      '((foo (value #t))))
     156
     157    (define nonalnum-cmdline
     158      '("--foo=value contains non-alnum chars: !@#$%^&*()"))
     159   
     160    (define nonalnum-values
     161      '((@)
     162        (foo . "value contains non-alnum chars: !@#$%^&*()")))
     163
     164    (test
     165     nonalnum-values
     166     (getopt-long nonalnum-cmdline nonalnum-grammar)
     167     )
     168
     169    )
     170
    153171(test-group "uknown option"
    154172
    155173    (test