--- /var/local/src/multimouse/MouseRemote/client/MouseRemote.pl	Sun Oct 10 11:36:30 1999
+++ MouseRemote	Wed Mar 24 22:33:19 2004
@@ -19,14 +19,19 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 # See the COPYING file for more copyright info
-#
+
+
+# 2004/03/24 -- Marc MERLIN <marc_soft@merlins.org>
+# Fixed to read files from standard FHS locations
+# Wrapped fifo read into a loop since it kept exiting on my system
+
 
 my $DEBUG = 0;				# turn on for debugging messages
 my $X10_FIFO = "/dev/x10fifo";		# name of FIFO provided by MultiMouse
-my $CONFIG = "MouseRemote.conf";	# name of config file to read
-my $PIDFILE = "MouseRemote.pid";	# pid of this run
+my $CONFIG = "/etc/MouseRemote.conf";	# name of config file to read
+my $PIDFILE = "/var/run/MouseRemote.pid";	# pid of this run
 my $DEBOUNCE_EXPIRE = 0.75;		# after this many seconds, a new keypress registers
-my $DEFAULT_DEVICE = 'WEB';		# default device at startup (PC/CD/WEB/DVD/PHONE)
+my $DEFAULT_DEVICE = 'DVD';		# default device at startup (PC/CD/WEB/DVD/PHONE)
 
 my $VERSION = 0.90;			# version number
 
@@ -52,16 +57,59 @@
 my( @command,				# holds the user-defined commands
     @repeat );				# set if user wants auto-repeat for cmd
 
+use strict;
+use Fcntl;				# defines for sysopen()
+use Time::HiRes;			# timers with granularity < 1 sec.
 use vars qw|%key2num|;			# var defined in MouseRemoteKeys.pl
-require "MouseRemoteKeys.pl";		# read keycode definitions
+
+
+# These are all of the keys that the MouseRemote
+# interface passes through the mouse port. There
+# are other buttons, but they don't get through.
+
+%key2num = (
+	chup =>		0x02,
+	chdown =>	0x03,
+	mute =>		0x05,
+	volup =>	0x06,
+	voldown =>	0x07,
+	play =>		0x0d,
+	stop =>		0x0e,
+	power =>	0x0f,
+	rew =>		0x1c,
+	ff =>		0x1d,
+	0 =>		0x40,
+	1 =>		0x41,
+	2 =>		0x42,
+	3 =>		0x43,
+	4 =>		0x44,
+	5 =>		0x45,
+	6 =>		0x46,
+	7 =>		0x47,
+	8 =>		0x48,
+	9 =>		0x49,
+	ent =>		0x4a,
+	pause =>	0x4e,
+	'last' =>	0x4f,
+	disp =>		0x5c,
+	ab =>		0x5d,
+	'shift' =>	0x6b,
+	guide =>	0x6d,
+	'select' =>	0x93,
+	rec =>		0xff,
+
+	pc =>		0x2b,
+	phone =>	0x4b,
+	web =>		0x8b,
+	cd =>		0xab,
+	dvd =>		0xcb,
+);
+
 my %num2key;				# convert number->keyname
 foreach( keys %key2num ) {		# read keyname->number hash
 	$num2key{$key2num{$_}} = $_;	# and convert to number->keyname
 }
 
-use strict;
-use Fcntl;				# defines for sysopen()
-use Time::HiRes;			# timers with granularity < 1 sec.
 
 while( $ARGV[0] =~ /^-/ ) {
 	if( $ARGV[0] =~ /^-c/ ) {
@@ -105,20 +153,25 @@
 $SIG{CHLD} = \&myChld;			# intercept SIGCHLD for fork()
 
 my( $len, $data );
-while( ($len = sysread( X10, $data, 3 )) != undef ) {	# read data
-	my( $type, $byte, $end ) = unpack('CCC',$data);	# convert data
-	if( !$eat_key &&				# eating key due to child?
-			($byte != $debounce ||		# different key pressed
-			Time::HiRes::gettimeofday()-$debounce_time > $DEBOUNCE_EXPIRE) ) {	# or time is up
-		printf( ">> %02X Device:$device\n", $byte ) if $DEBUG;
-		if( $type == 0x08 && $end == 0x7F ) {	# packet always has this wrapper
-			&process($byte);
-		}
-	}
-	else {				# eat the keypress
-		printf( "Eating key %02X\n", $byte ) if $DEBUG;
-	}
+while (1)
+{
+    while( ($len = sysread( X10, $data, 3 )) != undef ) {	# read data
+	    my( $type, $byte, $end ) = unpack('CCC',$data);	# convert data
+	    if( !$eat_key &&				# eating key due to child?
+			    ($byte != $debounce ||		# different key pressed
+			    Time::HiRes::gettimeofday()-$debounce_time > $DEBOUNCE_EXPIRE) ) {	# or time is up
+		    printf( ">> %02X Device:$device\n", $byte ) if $DEBUG;
+		    if( $type == 0x08 && $end == 0x7F ) {	# packet always has this wrapper
+			    &process($byte);
+		    }
+	    }
+	    else {				# eat the keypress
+		    printf( "Eating key %02X\n", $byte ) if $DEBUG;
+	    }
+    }
+    #print "Left main loop, re-entering...\n";
 }
+# we're not going there anymore -- Marc
 die "MouseRemote FIFO Error: $!\n";	# MultiMouse probably died
 
 # Handle the debounced keypress
