| 141 | #define WHITESPACES " \n\t\r" |
| 142 | |
| 143 | char *av_get_token(const char **buf, const char *term) |
| 144 | { |
| 145 | char *out = av_realloc(NULL, strlen(*buf) + 1); |
| 146 | char *ret = out, *end = out; |
| 147 | const char *p = *buf; |
| 148 | if (!out) |
| 149 | return NULL; |
| 150 | p += strspn(p, WHITESPACES); |
| 151 | |
| 152 | while (*p && !strspn(p, term)) { |
| 153 | char c = *p++; |
| 154 | if (c == '\\' && *p) { |
| 155 | *out++ = *p++; |
| 156 | end = out; |
| 157 | } else if (c == '\'') { |
| 158 | while (*p && *p != '\'') |
| 159 | *out++ = *p++; |
| 160 | if (*p) { |
| 161 | p++; |
| 162 | end = out; |
| 163 | } |
| 164 | } else { |
| 165 | *out++ = c; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | do |
| 170 | *out-- = 0; |
| 171 | while (out >= end && strspn(out, WHITESPACES)); |
| 172 | |
| 173 | *buf = p; |
| 174 | |
| 175 | char *small_ret = av_realloc(ret, out - ret + 2); |
| 176 | return small_ret ? small_ret : ret; |
| 177 | } |
| 178 | |
| 179 | char *av_strtok(char *s, const char *delim, char **saveptr) |
| 180 | { |