Update domain name to kpe.io
[getopt.git] / main.lisp
index b6b5070fa5ca15913dce2f11763a90d948a5bb43..b64ade2e9660278079120c64aa0530e34e0ca97b 100644 (file)
--- a/main.lisp
+++ b/main.lisp
   (and (> (length arg) 2)
        (char= #\- (schar arg 0))
        (char= #\- (schar arg 1))
-       (char/= #\- (schar arg 3))))
+       (char/= #\- (schar arg 2))))
 
 (defun decompose-arg (arg option-type)
   "Returns base-name,argument"
   (let ((start (ecase option-type
-                (:long 2)
-                (:short 1)))
-       (name-end (position #\= arg)))
+                 (:long 2)
+                 (:short 1)))
+        (name-end (position #\= arg)))
 
     (values (subseq arg start name-end)
-           (when name-end (subseq arg (1+ name-end))))))
+            (when name-end (subseq arg (1+ name-end))))))
 
 (defun analyze-arg (arg)
   "Analyzes an argument. Returns option-type,base-name,argument"
   (let* ((option-type (cond ((is-short-option arg) :short)
-                           ((is-long-option arg) :long)
-                           (t :arg))))
+                            ((is-long-option arg) :long)
+                            (t :arg))))
     (if (or (eq option-type :short) (eq option-type :long))
-       (multiple-value-bind (base arg) (decompose-arg arg option-type)
-         (values option-type base arg))
-       (values :arg arg nil))))
+        (multiple-value-bind (base arg) (decompose-arg arg option-type)
+          (values option-type base arg))
+        (values :arg arg nil))))
 
 
 (defun find-option (name options)
   "Find an option in option list. Handles using unique abbreviations"
   (let* ((option-names (mapcar #'car options))
-        (pos (match-unique-abbreviation name option-names)))
+         (pos (match-unique-abbreviation name option-names)))
     (when pos
       (nth pos options))))
 
   "Returns position of ABBR in STRINGS. ABBR may be a unique abbreviation.
 Returns NIL if no match found."
   (let ((len (length abbr))
-       (matches nil))
+        (matches nil))
     (dotimes (i (length strings))
       (let* ((s (nth i strings))
-            (l (length s)))
-       (cond
-         ((= len l)
-          (when (string= abbr s)
-            (push (cons s i) matches)))
-         ((< len l)
-          (when (string= abbr (subseq s 0 len))
-            (push (cons s i) matches))))))
+             (l (length s)))
+        (cond
+          ((= len l)
+           (when (string= abbr s)
+             (push (cons s i) matches)))
+          ((< len l)
+           (when (string= abbr (subseq s 0 len))
+             (push (cons s i) matches))))))
     (when (= 1 (length matches))
       (cdr (first matches)))))
 
@@ -106,31 +106,32 @@ opts is a list of option lists. The fields of the list are
       (setq finished-options t))
      (t
       (let ((arg (car pos)))
-       (multiple-value-bind (option-list option-type base-name argument)
-           (match-option (car pos) options)
-         (cond
-           ((and option-list (not (eq option-type :arg)))
-            (cond
-              (argument
-               (case (second option-list)
-                 (:none
-                  (push base-name errors))
-                 (t
-                  (push (cons base-name argument) out-opts))))
-              ((null argument)
-               (if (and (eq :required (second option-list)) (null (cdr pos)))
-                   (push base-name errors)
-                   (if (or (is-short-option (second pos))
-                           (is-long-option (second pos)))
-                       (if (eq :required (second option-list))
-                           (push base-name errors)
-                           (push (cons base-name (third option-list)) out-args))
-                       (progn
-                         (push (cons base-name (second pos)) out-opts)
-                         (setq pos (cdr pos))))))))
-           (t
-            (if (or (eq :long option-type)
-                    (eq :short option-type))
-                (push (nth-value 0 (decompose-arg arg option-type)) errors)
-              (push arg out-args))))))))))
+        (multiple-value-bind (option-list option-type base-name argument)
+            (match-option (car pos) options)
+          (cond
+            ((and option-list (not (eq option-type :arg)))
+             (cond
+               (argument
+                (case (second option-list)
+                  (:none
+                   (push base-name errors))
+                  (t
+                   (push (cons base-name argument) out-opts))))
+               ((null argument)
+                (if (and (eq :required (second option-list)) (null (cdr pos)))
+                    (push base-name errors)
+                    (if (or (eq :none (second option-list))
+                            (is-short-option (second pos))
+                            (is-long-option (second pos)))
+                        (if (eq :required (second option-list))
+                            (push base-name errors)
+                            (push (cons base-name (third option-list)) out-opts))
+                        (progn
+                          (push (cons base-name (second pos)) out-opts)
+                          (setq pos (cdr pos))))))))
+            (t
+             (if (or (eq :long option-type)
+                     (eq :short option-type))
+                 (push (nth-value 0 (decompose-arg arg option-type)) errors)
+               (push arg out-args))))))))))