changeset 25319:50a30be5300c

Add new function for parsing and queueing multi-commands separated by \n or \r.
author ulion
date Tue, 11 Dec 2007 08:03:47 +0000
parents 641296552e82
children 4fbf536cc033
files input/input.c input/input.h
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Mon Dec 10 21:33:22 2007 +0000
+++ b/input/input.c	Tue Dec 11 08:03:47 2007 +0000
@@ -21,6 +21,7 @@
 #include "osdep/getch2.h"
 #include "osdep/keycodes.h"
 #include "osdep/timer.h"
+#include "avstring.h"
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "m_config.h"
@@ -707,6 +708,28 @@
     mp_input_rm_key_fd(fd);
 }
 
+int mp_input_parse_and_queue_cmds(const char *str) {
+    int cmd_num = 0;
+
+    while (*str == '\n' || *str == '\r' || *str == ' ')
+        ++str;
+    while (*str) {
+        mp_cmd_t *cmd;
+        size_t len = strcspn(str, "\r\n");
+        char *cmdbuf = malloc(len+1);
+        av_strlcpy(cmdbuf, str, len+1);
+        cmd = mp_input_parse_cmd(cmdbuf);
+        if (cmd) {
+            mp_input_queue_cmd(cmd);
+            ++cmd_num;
+        }
+        str += len;
+        while (*str == '\n' || *str == '\r' || *str == ' ')
+            ++str;
+        free(cmdbuf);
+    }
+    return cmd_num;
+}
 
 mp_cmd_t*
 mp_input_parse_cmd(char* str) {
--- a/input/input.h	Mon Dec 10 21:33:22 2007 +0000
+++ b/input/input.h	Tue Dec 11 08:03:47 2007 +0000
@@ -255,6 +255,12 @@
 mp_cmd_t*
 mp_input_parse_cmd(char* str);
 
+/**
+ * Parse and queue commands separated by '\n'.
+ * @return count of commands new queued.
+ */
+int mp_input_parse_and_queue_cmds(const char *str);
+
 /// These filters allow you to process the command before MPlayer.
 /// If a filter returns a true value mp_input_get_cmd will return NULL.
 void