[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 14:03:04 CET 2007


Hello,
On Sun, Dec 09, 2007 at 08:36:01PM +0800, Ulion wrote:
> 2007/12/9, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
[...]
> > 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.

Maybe if you compile with -O0, but otherwise you wouldn't want to use a
compiler that is _that_ stupid.
But yes, e.g. Atmel still recommends such IMO really stupid things.

> @@ -707,7 +708,28 @@
>      mp_input_rm_key_fd(fd);
>  }
>  
> +int mp_input_parse_and_queue_cmds(const char *str) {
> +    int cmd_num = 0;
> +    mp_cmd_t *cmd;
>  
> +    while (*str == '\n')
> +        ++str;
> +    while (*str) {
> +        size_t len = strcspn(str, "\n");
> +        char cmdbuf[len+1];

Hmm... I think creating arbitrary-size arrays on the stack is a really
bad idea, what does everyone else think?

> +        av_strlcpy(cmdbuf, str, len+1);
> +        cmd = mp_input_parse_cmd(cmdbuf);
> +        if (cmd) {
> +            mp_input_queue_cmd(cmd);
> +            ++cmd_num;
> +        }

cmd is only used in the while loop, so you could move the declaration
inside it. Doesn't matter much though.

> +        str += len;
> +        while (*str == '\n')
> +            ++str;
> +    }
> +    return cmd_num;
> +}

It might be worth handling \r as well as \n btw.
The change would be simply replacing "\n" by "\n\r" in strcspn and
"*str == '\n'" by "*str && strchr("\r\n", *str)".
The *str check is because the specification seems unclear to me how
strchr(str, 0); is supposed to behave.
Well, I guess that makes "while (*str == '\n' || *str == '\r')" simpler
than my strchr hack ;-)

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list