[Mplayer-cvslog] CVS: main/input input.c,1.9,1.10 input.h,1.5,1.6

Alban Bedel CVS albeu at mplayer.dev.hu
Sat Feb 23 22:13:38 CET 2002


Update of /cvsroot/mplayer/main/input
In directory mplayer:/var/tmp.root/cvs-serv1703/input

Modified Files:
	input.c input.h 
Log Message:
Fixed bug with comments in input.conf parser
Added a command queue to let mplayer send command to himself


Index: input.c
===================================================================
RCS file: /cvsroot/mplayer/main/input/input.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- input.c	20 Feb 2002 14:45:18 -0000	1.9
+++ input.c	23 Feb 2002 21:13:35 -0000	1.10
@@ -196,6 +196,8 @@
 #define MP_FD_GOT_CMD (1<<3)
 #define MP_FD_NO_SELECT (1<<4)
 
+#define CMD_QUEUE_SIZE 10
+
 typedef struct mp_input_fd {
   int fd;
   void* read_func;
@@ -213,6 +215,8 @@
 static unsigned int num_key_fd = 0;
 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
 static unsigned int num_cmd_fd = 0;
+static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE];
+static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0;
 
 // this is the key currently down
 static int key_down[MP_MAX_KEY_DOWN];
@@ -757,10 +761,39 @@
   return NULL;  
 }
 
+int
+mp_input_queue_cmd(mp_cmd_t* cmd) {
+  if(cmd_queue_length  >= CMD_QUEUE_SIZE)
+    return 0;
+  cmd_queue[cmd_queue_end] = cmd;
+  cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE;
+  cmd_queue_length++;
+  return 1;
+}
+
+static mp_cmd_t*
+mp_input_get_queued_cmd(void) {
+  mp_cmd_t* ret;
+
+  if(cmd_queue_length == 0)
+    return NULL;
+
+  ret = cmd_queue[cmd_queue_start];
+  
+  cmd_queue_length--;
+  cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE;
+  
+  return ret;
+}  
+
 mp_cmd_t*
 mp_input_get_cmd(int time, int paused) {
   mp_cmd_t* ret;
 
+  ret = mp_input_get_queued_cmd();
+  if(ret)
+    return ret;
+
   ret = mp_input_read_keys(time,paused);
   if(ret)
     return ret;
@@ -811,19 +844,16 @@
 mp_input_get_key_name(int key) {
   int i;
 
-  if(key == ' ')
-    return "SPACE";
-
-  if(key >> 8 == 0) {
-    snprintf(key_str,2,"%c",(char)key);
-    return key_str;
-  }
-
   for(i = 0; key_names[i].name != NULL; i++) {
     if(key_names[i].key == key)
       return key_names[i].name;
   }
   
+  if(key >> 8 == 0) {
+    snprintf(key_str,2,"%c",(char)key);
+    return key_str;
+  }
+
   return NULL;
 }
 
@@ -924,13 +954,13 @@
       }
     }
     // Empty buffer : return
-    if(bs <= 1) {
+    if(bs <= 0) {
       printf("Input config file %s parsed : %d binds\n",file,n_binds);
       if(binds)
 	cmd_binds = binds;
       return 1;
     }
-      
+    
     iter = buffer;
 
     if(comments) {
@@ -1011,7 +1041,7 @@
       }
       for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++)
 	/* NOTHING */;
-      if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) {
+      if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) {
 	if(iter == buffer) {
 	  printf("Buffer is too small for command %s\n",buffer);
 	  mp_input_free_binds(binds);
@@ -1033,9 +1063,11 @@
 	memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t));
       }
       keys[0] = 0;
+      end++;
       if(bs > (end-buffer))
 	memmove(buffer,end,bs-(end-buffer));
       bs -= (end-buffer);
+      buffer[bs-1] = '\0';
       continue;
     }
   }

Index: input.h
===================================================================
RCS file: /cvsroot/mplayer/main/input/input.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- input.h	17 Feb 2002 01:06:50 -0000	1.5
+++ input.h	23 Feb 2002 21:13:35 -0000	1.6
@@ -86,6 +86,9 @@
 void
 mp_input_rm_key_fd(int fd);
 
+int
+mp_input_queue_cmd(mp_cmd_t* cmd);
+
 mp_cmd_t*
 mp_input_get_cmd(int time, int paused);
 




More information about the MPlayer-cvslog mailing list