Ticket #1012: simplify-long-option-value-handling.patch
File simplify-long-option-value-handling.patch, 2.1 KB (added by , 11 years ago) |
---|
-
getopt-long.scm
434 434 (else (error 'long-option-name 435 435 "invalid list" lst))))) 436 436 437 (define long-option-value-cs438 (char-set-union char-set:letter+digit439 char-set:punctuation440 (char-set #\_ #\^ #\$ #\=)))441 442 437 (define (long-option-value lst) 443 438 (if (null? lst) (list #f lst) 444 439 (let loop ((lst lst) (ax (list))) … … 447 442 448 443 ((and (char? (car lst)) (car lst)) => 449 444 (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)))) 466 446 467 447 (else (error 'long-option-value 468 448 "invalid list" lst)))))) -
tests/run.scm
134 134 135 135 )) 136 136 137 (define cmdline2 '("--meta-filter= \"Note=,Archive Name=Brown\""137 (define cmdline2 '("--meta-filter=Note=,Archive Name=Brown" 138 138 "-d" "data" "FormSubmit.html")) 139 140 139 141 140 (test-group "grammar2" 142 141 … … 150 149 151 150 ) 152 151 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 153 171 (test-group "uknown option" 154 172 155 173 (test