Changeset 5747:17e1c9dacc8f in roaraudio for libroar
- Timestamp:
- 11/14/12 04:32:25 (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/config.c
r5466 r5747 432 432 } 433 433 434 static const struct { 435 const char * name; 436 const char * path; 437 const int with_product; 438 const int with_provider; 439 } __paths[] = { 440 {"prefix", ROAR_PREFIX, 0, 0}, 441 {"prefix-bin", ROAR_PREFIX_BIN, 0, 0}, 442 {"prefix-lib", ROAR_PREFIX_LIB, 0, 0}, 443 {"prefix-inc", ROAR_PREFIX_INC, 0, 0}, 444 {"prefix-man", ROAR_PREFIX_MAN, 0, 0}, 445 {"prefix-pc", ROAR_PREFIX_PC, 0, 0}, 446 {"prefix-comp-libs", ROAR_PREFIX_COMP_LIBS, 0, 0}, 447 {"prefix-comp-bins", ROAR_PREFIX_COMP_BINS, 0, 0}, 448 {"prefix-plugins", ROAR_PREFIX_PLUGINS, 1, 1}, 449 {"prefix-buildsystem", ROAR_PREFIX_BUILDSYSTEM, 0, 0} 450 }; 451 452 static int __product2path(char * path, size_t pathlen, int null_as_universal, const char * product) { 453 const char * c; 454 const char * e; 455 const char * s; 456 const char * b; 457 458 if ( product == NULL ) { 459 if ( null_as_universal ) { 460 snprintf(path, pathlen, "/universal/universal"); 461 } else { 462 path[0] = 0; 463 } 464 return 0; 465 } 466 467 b = strstr(product, " "); 468 c = strstr(product, "<"); 469 e = strstr(product, ">"); 470 471 if ( b == NULL || c == NULL || e == NULL || c < b || e < c ) { 472 roar_err_set(ROAR_ERROR_ILLSEQ); 473 return -1; 474 } 475 476 c++; 477 478 s = strstr(c, "/"); 479 480 if ( s == NULL ) { 481 snprintf(path, pathlen, "/unreg-%.*s/%.*s", (int)(size_t)(e-c), c, (int)(size_t)(b-product), product); 482 } else { 483 snprintf(path, pathlen, "/%.*s-%.*s/%.*s", (int)(size_t)(s-c), c, (int)(size_t)(e-s-1), s+1, (int)(size_t)(b-product), product); 484 } 485 486 return 0; 487 } 488 489 static int __provider2path(char * path, size_t pathlen, const char * provider) { 490 const char * c; 491 const char * e; 492 const char * s; 493 494 if ( provider == NULL ) { 495 path[0] = 0; 496 return 0; 497 } 498 499 c = strstr(provider, "<"); 500 e = strstr(provider, ">"); 501 502 if ( c == NULL || e == NULL || e < c ) { 503 roar_err_set(ROAR_ERROR_ILLSEQ); 504 return -1; 505 } 506 507 c++; 508 509 s = strstr(c, "/"); 510 511 if ( s == NULL ) { 512 snprintf(path, pathlen, "/unreg-%.*s", (int)(size_t)(e-c), c); 513 } else { 514 snprintf(path, pathlen, "/%.*s-%.*s", (int)(size_t)(s-c), c, (int)(size_t)(e-s-1), s+1); 515 } 516 517 return 0; 518 519 roar_err_set(ROAR_ERROR_NOTSUP); 520 return -1; 521 } 522 523 char * roar_libroar_get_path(const char * name, int null_as_universal, const char * product, const char * provider) { 524 char buf_product[1024]; 525 char buf_provider[1024]; 526 ssize_t len_prefix, len_product, len_provider; 527 size_t i; 528 char * ret, * p; 529 530 if ( name == NULL ) { 531 roar_err_set(ROAR_ERROR_NOENT); 532 return NULL; 533 } 534 535 for (i = 0; i < (sizeof(__paths)/sizeof(*__paths)); i++) { 536 if ( !!strcmp(__paths[i].name, name) ) 537 continue; 538 539 if ( ((null_as_universal || product != NULL) && !__paths[i].with_product) || 540 (provider != NULL && !__paths[i].with_provider) ) { 541 roar_err_set(ROAR_ERROR_INVAL); 542 return NULL; 543 } 544 545 if ( __product2path(buf_product, sizeof(buf_product), null_as_universal, product) == -1 ) 546 return NULL; 547 548 if ( __provider2path(buf_provider, sizeof(buf_provider), provider) == -1 ) 549 return NULL; 550 551 len_prefix = roar_mm_strlen(__paths[i].path); 552 len_product = roar_mm_strlen(buf_product); 553 len_provider = roar_mm_strlen(buf_provider); 554 555 p = ret = roar_mm_malloc(len_prefix+len_product+len_provider+1); 556 if ( ret == NULL ) 557 return NULL; 558 559 memcpy(p, __paths[i].path, len_prefix); 560 p += len_prefix; 561 if ( p[-1] == '/' ) 562 p--; 563 memcpy(p, buf_product, len_product); 564 p += len_product; 565 memcpy(p, buf_provider, len_provider); 566 p += len_provider; 567 568 *p = 0; 569 570 return ret; 571 } 572 573 roar_err_set(ROAR_ERROR_NOENT); 574 return NULL; 575 } 576 434 577 //ll
Note: See TracChangeset
for help on using the changeset viewer.