[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[STUMP] contrib/mpd.lisp sbcl support
From: |
Vitaly Mayatskikh |
Subject: |
[STUMP] contrib/mpd.lisp sbcl support |
Date: |
Wed, 13 Feb 2008 20:42:58 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Hi there!
I've modified a bit mpd.lisp to support sbcl. I'm not sure if original
mpd.lisp was designed for cmucl, may be for clisp?
--- mpd.lisp.bak 2008-02-13 12:13:58.000000000 +0100
+++ mpd.lisp 2008-02-13 16:29:06.000000000 +0100
@@ -35,13 +35,29 @@
;;mpd client
(defparameter *mpd-socket* nil)
-(defparameter *mpd-server* "localhost")
+(defparameter *mpd-server*
+ #+cmu
+ "localhost"
+ #+sbcl
+ #(127 0 0 1)
+ )
(defparameter *mpd-port* 6600)
+(defmacro with-mpd-connection (&body body)
+ `(if *mpd-socket*
+ (handler-case (progn ,@body)
+ (error (c) (progn
+ (message "Error with mpd connection: ~a" c)
+ (setf *mpd-socket* nil))))
+ (message "Error: not connected to mpd~%")))
+
(defun mpd-send (command)
"Send command to stream ending with newline"
(with-mpd-connection
- (ext:write-char-sequence
+ (#+cmu
+ ext:write-char-sequence
+ #+sbcl
+ write-sequence
(concatenate 'string command (string #\Newline))
*mpd-socket*)))
@@ -78,11 +94,19 @@
(defun mpd-connect ()
"Connect to mpd server"
- (setf *mpd-socket*
+ (setq *mpd-socket*
+ #+cmu
(handler-case (socket:socket-connect *mpd-port* *mpd-server*
:element-type 'character)
((or system::simple-os-error error)
(err)
+ (format t "Error connecting to mpd: ~a~%" err)))
+ #+sbcl
+ (handler-case (let ((s (make-instance 'sb-bsd-sockets:inet-socket
:type :stream :protocol :tcp)))
+ (sb-bsd-sockets:socket-connect s *mpd-server*
*mpd-port*)
+ (sb-bsd-sockets:socket-make-stream s :input t :output
t :buffering :none))
+ ((or simple-error error)
+ (err)
(format t "Error connecting to mpd: ~a~%" err))))
(when *mpd-socket*
(read-line *mpd-socket*)))
@@ -98,13 +122,6 @@
(mpd-send cmd)
(mpd-receive))
-(defmacro with-mpd-connection (&body body)
- `(if *mpd-socket*
- (handler-case (progn ,@body)
- (error (c) (progn
- (message "Error with mpd connection: ~a" c)
- (setf *mpd-socket* nil))))
- (message "Error: not connected to mpd~%")))
;;mpd formatter
(dolist (a '((#\m fmt-mpd-status)))
I've noticed that stumpish doesn't handle situations when stumpwm'
commands run not very fast and it returns just string
STUMPWM_COMMAND_RESULT. I've modified result waiting loop a bit:
--- stumpish.bak 2008-02-13 20:39:10.000000000 +0100
+++ stumpish 2008-02-13 12:20:20.000000000 +0100
@@ -25,12 +25,12 @@ function wait_result ()
do
RESULT=`xprop -root -f STUMPWM_COMMAND_RESULT 8s
STUMPWM_COMMAND_RESULT 2>/dev/null`
- if echo "$RESULT" | grep -v -q 'not found.$'
+ if echo "$RESULT" | grep -v -q 'not found.$' && [ x"$RESULT" !=
x"STUMPWM_COMMAND_RESULT" ];
then
break;
fi
- sleep 1;
+ usleep 100;
done
xprop -root -remove STUMPWM_COMMAND_RESULT
--
wbr, Vitaly
- [STUMP] contrib/mpd.lisp sbcl support,
Vitaly Mayatskikh <=