[FFmpeg-devel] [PATCH] match input format names split by commas

Måns Rullgård mans
Fri Jan 16 21:43:15 CET 2009


Baptiste Coudurier <baptiste.coudurier at gmail.com> writes:

> Hi Michael,
>
> Michael Niedermayer wrote:
>> On Thu, Jan 15, 2009 at 03:38:29PM -0800, Baptiste Coudurier wrote:
>>> Hi,
>>>
>>> $subject, this enables using "mov", "mp4, "mj2" etc..
>> [...]
>>> Index: libavformat/utils.c
>>> ===================================================================
>>> --- libavformat/utils.c	(revision 16617)
>>> +++ libavformat/utils.c	(working copy)
>>> @@ -153,6 +153,20 @@
>>>      return 0;
>>>  }
>>>  +static int match_format(const char *name, const char *names)
>>> +{
>>> +    if (!name || !names)
>>> +        return 0;
>>> +    for (;;) {
>>> +        if (!strncasecmp(name, names, strlen(name)))
>>> +            return 1;
>>> +        if (!(names = strchr(names, ',')))
>>> +            break;
>>> +        names++;
>>> +    }
>>> +    return 0;
>>> +}
>> with this m will match mp4
>
> Hehe, auto completion ;)
> New patch attached.
>
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 16614)
> +++ libavformat/utils.c	(working copy)
> @@ -153,6 +153,24 @@
>      return 0;
>  }
>
> +static int match_format(const char *name, const char *names)
> +{
> +    int len, namelen;
> +    if (!name || !names)
> +        return 0;
> +    namelen = strlen(name);
> +    for (;;) {
> +        const char *p = strchr(names, ',');
> +        if (!p)
> +            return !strcasecmp(name, names);
> +        len = FFMAX(p - names, namelen);
> +        if (!strncasecmp(name, names, len))
> +            return 1;
> +        names = p+1;
> +    }
> +    return 0;
> +}

Simpler (untested):

while (p = strchr(names, ',')) {
    len = FFMAX(p - names, namelen);
    if (!strncasecmp(name, names, len))
        return 1;
    names = p+1;
}
return strcasecmp(name, names);

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list