(defpackage time-adder (:use cl))
(in-package time-adder)

(defun alist2seconds (alist)
 (multiple-value-bind 
  (second minute hour date month year day summerp timezone)
  (get-decoded-time)
  (declare (ignore day summerp))
  (apply 'encode-universal-time
   (mapcar (lambda (name default) (or (cdr (assoc name alist)) default))
    '(second minute hour date month year timezone)
    (list second minute hour date month year timezone)))))

(defun seconds2alist (seconds)
 (multiple-value-bind 
  (second minute hour date month year day summerp timezone)
  (decode-universal-time seconds)
  (declare (ignore day summerp))
  (mapcar 'cons
   '(second minute hour date month year timezone)
   (list second minute hour date month year timezone))))

(defun a-b+c (&optional (a nil) (b nil) (c nil)
              &aux (a (when (listen) (read nil nil)))
                   (b (when (listen) (read nil nil)))
                   (c (when (listen) (read nil nil))))
 (seconds2alist (+ (-  (alist2seconds a) (alist2seconds b)) 
                 (alist2seconds c))))

(defun help-text ()
 (print "Try running ./a-b+c.exe with no standard inputs.
Its defaults for a, b and c are the current time.
Then maybe try
./a-b+c.exe <<EOG
((minute . 6) (hour . 3))
((minute . 14) (hour . 1))
EOG
or
./a-b+c.exe <<EOG
((minute . 6) (hour . 3))
((minute . 14) (hour . 1))
((date . 3) (year . 1992))
EOG
"))

(when 
 (or (string= "--help" (second (ext:command-args)))
     (string= "-h" (second (ext:command-args))))
 (help-text))

(handler-case 
 (loop (prin1 (a-b+c)) (terpri)
  (let ((char (read-char-no-hang t nil)))
   (if char (unread-char char) (return))))
 (t (error) (format t "Error: ~a~%" error) (help-text)))
(si:quit)