From fc12ef7e8fe197fc23580243c48809bf1a162f9c Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak Date: Sat, 5 Mar 2011 15:35:25 -0600 Subject: [PATCH 2/4] Added fixes for options stuff --- options.lisp | 17 ++++++++++------- stumpwm.lisp | 9 ++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/options.lisp b/options.lisp index 961e37b..f5608cb 100644 --- a/options.lisp +++ b/options.lisp @@ -33,21 +33,24 @@ (let ((options-list ;; Each element of this list is of the form ;; (option-symbol help-text &rest text-to-match) - '(('help "Show this help text and exit." "--help" "-h") - ('version "Print the version of the program and exit." "--version" "-v") - ('replace "Replace any window manager already running." "--replace")))) + '((help "Show this help text and exit." "--help" "-h") + (version "Print the version of the program and exit." "--version" "-v") + (replace "Replace any window manager already running." "--replace")))) (defun parse-options (args) (let ((struct (make-instance 'options))) (loop for i in args do - (loop for (symbol help &rest matches) in options-list do + (loop for (symbol help . matches) in options-list do (when (member i matches :test #'string=) (setf (slot-value struct symbol) t)))) struct)) (defun show-help () - (loop for (symbol help &rest matches) in options-list do - (format t "~{~a~^, ~}~20,1T~a" matches help)))) + (loop for (symbol help . matches) in options-list do + (format t "~{~a~^, ~}~20,1T~a~%" matches help)))) (defun get-option (option &optional (struct *options*)) - (slot-value option struct)) + ;; Fallback in the event of code that fires off early [not needed any more] + ;; (when (not struct) + ;; (setf struct (parse-options (argv)))) + (slot-value struct option)) diff --git a/stumpwm.lisp b/stumpwm.lisp index c19f214..a6512e9 100644 --- a/stumpwm.lisp +++ b/stumpwm.lisp @@ -26,11 +26,15 @@ (export '(cancel-timer run-with-timer stumpwm - timer-p)) + timer-p + *version*)) ;;; Main +;; Defining *version* here to avoid warnings +(defvar *version* nil) + (defun load-rc-file (&optional (catch-errors t)) "Load the user's .stumpwmrc file or the system wide one if that doesn't exist. Returns a values list: whether the file loaded (t if no @@ -210,6 +214,7 @@ of those expired." (throw :top-level :quit)))) (defun stumpwm-internal (display-str) + (handle-options) ;;get --help and --version out of the way now (multiple-value-bind (host display screen protocol) (parse-display-string display-str) (declare (ignore screen)) (setf *display* (xlib:open-display host :display display :protocol protocol) @@ -232,8 +237,6 @@ of those expired." (if success (and *startup-message* (message *startup-message* (print-key *escape-key*))) (message "^B^1*Error loading ^b~A^B: ^n~A" rc err)))) - ;; Options that must be acted on here are acted on - (handle-options) (when *last-unhandled-error* (message-no-timeout "^B^1*StumpWM Crashed With An Unhandled Error!~%Copy the error to the clipboard with the 'copy-unhandled-error' command.~%^b~a^B^n~%~%~a" (first *last-unhandled-error*) (second *last-unhandled-error*))) -- 1.7.1