Improve handling of gnuplot executable.

(`which` at startup, check for executable)
This commit is contained in:
interp 2003-01-16 11:10:38 +00:00
parent 1b5098bea0
commit 0656602636
1 changed files with 19 additions and 5 deletions

View File

@ -9,6 +9,7 @@
define-record-types define-record-types
locks locks
let-opt let-opt
receiving
) )
(begin (begin
@ -30,8 +31,8 @@
(define (state-counter) (define (state-counter)
(state:counter (get-servlet-data))) (state:counter (get-servlet-data)))
;; Leave this global. Server is running on a single system. ;; Leave this global. Servers are running on a single system.
(define gnuplot "/usr/bin/gnuplot") (define gnuplot #f) ;; Set in main.
(define lock (make-lock)) (define lock (make-lock))
(define (profile req . maybe-update-text) (define (profile req . maybe-update-text)
@ -63,7 +64,11 @@
,new-url ,new-url
POST POST
(p "This uses " (var "gnuplot") " that is searched at " (p "This uses " (var "gnuplot") " that is searched at "
,input-field ,change-button))) ,input-field ,change-button (br)
,(if (not (gnuplot-executable? gnuplot))
'(font (@ (color "red"))
"Note: There is no executable.")
#f))))
(li (URL ,(reset-address new-url) (li (URL ,(reset-address new-url)
"Delete files and reset profile state."))) "Delete files and reset profile state.")))
(hr) (hr)
@ -90,13 +95,16 @@
(reset-and-return-to-main-page req)) (reset-and-return-to-main-page req))
(else (else
(let ((new-gnuplot-location (input-field-value input-field bindings))) (let ((new-gnuplot-location (input-field-value input-field bindings)))
(if (and new-gnuplot-location (if (gnuplot-executable? new-gnuplot-location)
(file-executable? new-gnuplot-location))
(begin (begin
(set! gnuplot new-gnuplot-location) (set! gnuplot new-gnuplot-location)
(profile req (format #f "Gnuplot is now searched at ~a." gnuplot))) (profile req (format #f "Gnuplot is now searched at ~a." gnuplot)))
(profile req "Please enter a file name of an existing executable."))))))) (profile req "Please enter a file name of an existing executable.")))))))
(define (gnuplot-executable? gnuplot-file-name)
(and gnuplot-file-name
(file-executable? gnuplot-file-name)))
(define (new-profile req) (define (new-profile req)
(let ((state (get-servlet-data))) (let ((state (get-servlet-data)))
(format #t "profiling...~%") (format #t "profiling...~%")
@ -223,8 +231,14 @@ plot '~a' title 'Servlet Profiling ~a' with lines"
(define (main req) (define (main req)
;; We'll fill this out soon. ;; We'll fill this out soon.
(set! gnuplot (search-gnuplot))
(set-servlet-data! (make-state #f #f 0)) (set-servlet-data! (make-state #f #f 0))
(reset-profiling-state!) (reset-profiling-state!)
(profile req)) (profile req))
(define (search-gnuplot)
(receive (status ports) (run/collecting (1) (which gnuplot))
(if (zero? status)
(read-line ports)
"")))
)) ))