[MPlayer-dev-eng] [PATCH] Add a function for parse and queue multiple cmds seperated by line-break

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Dec 9 12:40:37 CET 2007


Hello,
On Sun, Dec 09, 2007 at 07:07:50PM +0800, Ulion wrote:
> Index: input/input.c
> ===================================================================
> --- input/input.c	(revision 25326)
> +++ input/input.c	(working copy)
> @@ -707,6 +707,25 @@
>      mp_input_rm_key_fd(fd);
>  }
>  
> +int mp_input_parse_and_queue_cmds(char *str) {
> +    char *cmdstr = str;
> +    char *nextcmd = cmdstr;
> +    int cmd_num = 0;
> +    mp_cmd_t *cmd;
> +    for (;;) {
> +        strsep(&nextcmd, "\n");
> +        cmd = mp_input_parse_cmd(cmdstr);
> +        if (cmd) {
> +            mp_input_queue_cmd(cmd);
> +            ++cmd_num;
> +        }
> +        if (!nextcmd)
> +            break;
> +        nextcmd[-1] = '\n';
> +        cmdstr = nextcmd;
> +    }
> +    return cmd_num;
> +}

I really think this should be changed to work with
"const char *".
Personally I'd suggest something like
while (*str) {
  size_t len = strcspn(str, "\n");
  cmdstr = malloc(len+1);
  av_strlcpy(cmdstr, str, len+1);
  str += len;
  // skip delimiter if any
  if (*str) str++;
  [parse and queue code here]
  free(cmdstr);
}
which also gets rid of the ugly "for(;;)".
In addition I think it also fixes the weird behaviour
that your code would interpret
"cmd1\n"
as two commands, namely "cmd1" and "".

> @@ -719,6 +738,10 @@
>    assert(str != NULL);
>  #endif
>  
> +  // Ignore heading spaces.
> +  while (str[0] == ' ' || str[0] == '\t')
> +    ++str;
> +
>    if (strncmp(str, "pausing ", 8) == 0) {
>      pausing = 1;
>      str = &str[8];

Wasn't that part of another patch by you?

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list