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

Ulion ulion2002 at gmail.com
Sun Dec 9 13:36:01 CET 2007


2007/12/9, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> 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);
> }

OK, use you code with some changes.

> which also gets rid of the ugly "for(;;)".

I ever read from somewhere, in the the compiled asm code, for(;;) just
loop, but while(1) still check.

> 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?

It's another patch, I forgot to purge it.

Here's updated patch.

-- 
Ulion
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: input_parse_and_queue_cmds2.diff
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20071209/828e1179/attachment.asc>


More information about the MPlayer-dev-eng mailing list