Revision dd04911c libavfilter/graphparser.c

View differences:

libavfilter/graphparser.c
26 26
#include "graphparser.h"
27 27
#include "avfilter.h"
28 28
#include "avfiltergraph.h"
29
#include "parseutils.h"
29 30

  
30 31
#define WHITESPACES " \n\t"
31 32

  
......
44 45
}
45 46

  
46 47
/**
47
 * Consumes a string from *buf.
48
 * @return a copy of the consumed string, which should be free'd after use
49
 */
50
static char *consume_string(const char **buf)
51
{
52
    char *out = av_malloc(strlen(*buf) + 1);
53
    char *ret = out;
54

  
55
    *buf += strspn(*buf, WHITESPACES);
56

  
57
    do{
58
        char c = *(*buf)++;
59
        switch (c) {
60
        case '\\':
61
            *out++ = *(*buf)++;
62
            break;
63
        case '\'':
64
            while(**buf && **buf != '\'')
65
                *out++ = *(*buf)++;
66
            if(**buf) (*buf)++;
67
            break;
68
        case 0:
69
        case ']':
70
        case '[':
71
        case '=':
72
        case ',':
73
        case ';':
74
        case ' ':
75
        case '\n':
76
            *out++ = 0;
77
            break;
78
        default:
79
            *out++ = c;
80
        }
81
    } while(out[-1]);
82

  
83
    (*buf)--;
84
    *buf += strspn(*buf, WHITESPACES);
85

  
86
    return ret;
87
}
88

  
89
/**
90 48
 * Parse "[linkname]"
91 49
 * @param name a pointer (that need to be free'd after use) to the name between
92 50
 *        parenthesis
......
97 55
    char *name;
98 56
    (*buf)++;
99 57

  
100
    name = consume_string(buf);
58
    name = av_get_token(buf, "]");
101 59

  
102 60
    if(!name[0]) {
103 61
        av_log(log_ctx, AV_LOG_ERROR,
......
162 120
                                     int index, AVClass *log_ctx)
163 121
{
164 122
    char *opts = NULL;
165
    char *name = consume_string(buf);
123
    char *name = av_get_token(buf, "=,");
166 124
    AVFilterContext *ret;
167 125

  
168 126
    if(**buf == '=') {
169 127
        (*buf)++;
170
        opts = consume_string(buf);
128
        opts = av_get_token(buf, "[],\n");
171 129
    }
172 130

  
173 131
    ret = create_filter(graph, index, name, opts, log_ctx);

Also available in: Unified diff