Properly parse numbers from the command line or in version strings

This commit is contained in:
Renaud Casenave-Péré 2015-04-27 18:17:36 +02:00
parent 7ba21e011c
commit fa14b3dae4
4 changed files with 13 additions and 9 deletions

View file

@ -57,7 +57,7 @@
(defun initialize (&optional argv) (defun initialize (&optional argv)
"Initialize the jobs module." "Initialize the jobs module."
(format t "Initialize Job system~%") (format t "Initialize Job system~%")
(let ((thread-count (get-command-line-option-int argv "-j" 1))) (let ((thread-count (get-command-line-option-number argv "-j" 1)))
(when (> thread-count 0) (when (> thread-count 0)
(setf *thread-list* (setf *thread-list*
(make-array (list thread-count) :initial-contents (make-array (list thread-count) :initial-contents

View file

@ -30,7 +30,8 @@ Store values like the drivers version."
*minor-version* min)) *minor-version* min))
(setf *major-version* (gl:get-integer :major-version) (setf *major-version* (gl:get-integer :major-version)
*minor-version* (gl:get-integer :minor-version))) *minor-version* (gl:get-integer :minor-version)))
(setf *glsl-version* (gl:get-string :shading-language-version))) (setf *glsl-version* (with-input-from-string (in (gl:get-string :shading-language-version))
(read in))))
(defun version-supported-p (version) (defun version-supported-p (version)
(multiple-value-bind (maj min) (floor version 10) (multiple-value-bind (maj min) (floor version 10)

View file

@ -37,9 +37,9 @@
Create an opengl context attached to a window and initialize the shader system." Create an opengl context attached to a window and initialize the shader system."
(format t "Initialize Render module~%") (format t "Initialize Render module~%")
(let ((title (get-command-line-option argv "--title" "Stoe")) (let ((title (get-command-line-option argv "--title" "Stoe"))
(width (get-command-line-option-int argv "--width" 800)) (width (get-command-line-option-number argv "--width" 800))
(height (get-command-line-option-int argv "--height" 600)) (height (get-command-line-option-number argv "--height" 600))
(version (get-command-line-option-int argv "--opengl"))) (version (get-command-line-option-number argv "--opengl")))
(if version (if version
(progn (progn
(gl-utils:initialize version) (gl-utils:initialize version)

View file

@ -17,7 +17,7 @@
:make-clock :clock-time :clock-delta :make-clock :clock-time :clock-delta
:update-clock :compare-clocks :update-clock :compare-clocks
:get-command-line-option :get-command-line-option
:get-command-line-option-int)) :get-command-line-option-number))
(in-package :stoe.utils) (in-package :stoe.utils)
(declaim (optimize (debug 3) (safety 3) (speed 0))) (declaim (optimize (debug 3) (safety 3) (speed 0)))
@ -154,9 +154,12 @@
(let ((opt (member optname argv :test #'equal))) (let ((opt (member optname argv :test #'equal)))
(or opt default))) (or opt default)))
(defun get-command-line-option-int (argv optname &optional default) (defun get-command-line-option-number (argv optname &optional default)
"Return the option designated by `optname' from the command-line `argv'." "Return the option designated by `optname' from the command-line `argv' as a number."
(let ((opt (get-command-line-option argv optname))) (let ((opt (get-command-line-option argv optname)))
(if opt (if opt
(parse-integer opt) (let ((value (with-input-from-string (in opt)
(read in))))
(assert (numberp value))
value)
default))) default)))