| 286 | } |
| 287 | |
| 288 | int |
| 289 | xo_encoder_init (xo_handle_t *xop, const char *name) |
| 290 | { |
| 291 | xo_encoder_setup(); |
| 292 | |
| 293 | char opts_char = '\0'; |
| 294 | const char *col_opts = strchr(name, ':'); |
| 295 | const char *plus_opts = strchr(name, '+'); |
| 296 | |
| 297 | /* |
| 298 | * Find the option-separating character (plus or colon) which |
| 299 | * appears first in the options string. |
| 300 | */ |
| 301 | const char *opts = (col_opts == NULL) ? plus_opts |
| 302 | : (plus_opts == NULL) ? col_opts |
| 303 | : (plus_opts < col_opts) ? plus_opts : col_opts; |
| 304 | |
| 305 | if (opts) { |
| 306 | opts_char = *opts; |
| 307 | |
| 308 | /* Make a writable copy of the name */ |
| 309 | size_t len = strlen(name); |
| 310 | char *copy = alloca(len + 1); |
| 311 | memcpy(copy, name, len); |
| 312 | copy[len] = '\0'; |
| 313 | |
| 314 | char *opts_copy = copy + (opts - name); /* Move to ':' */ |
| 315 | *opts_copy++ = '\0'; /* Trim it off */ |
| 316 | |
| 317 | opts = opts_copy; /* Use copy as options */ |
| 318 | name = copy; /* Use trimmed copy as name */ |
| 319 | } |
| 320 | |
| 321 | /* Can't have names containing '/' or ':' */ |
| 322 | if (strchr(name, '/') != NULL || strchr(name, ':') != NULL) { |
| 323 | xo_failure(xop, "invalid encoder name: %s", name); |
| 324 | return -1; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * First we look on the list of known (registered) encoders. |
| 329 | * If we don't find it, we follow the set of paths to find |
| 330 | * the encoding library. |
| 331 | */ |
| 332 | xo_encoder_node_t *xep = xo_encoder_find(name); |
| 333 | if (xep == NULL) { |
| 334 | xep = xo_encoder_discover(name); |
| 335 | if (xep == NULL) { |
| 336 | xo_failure(xop, "encoder not founde: %s", name); |
| 337 | return -1; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | xo_set_encoder(xop, xep->xe_handler); |
| 342 | |
| 343 | int rc = xo_encoder_handle(xop, XO_OP_CREATE, name, NULL, 0); |
| 344 | if (rc == 0 && opts != NULL) { |
| 345 | xo_encoder_op_t op; |
no test coverage detected