Changeset 5747:17e1c9dacc8f in roaraudio


Ignore:
Timestamp:
11/14/12 04:32:25 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Provide a more common interface for path config.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5743 r5747  
    88          protocol-rplay and protocol-gopher (Closes: #311) 
    99        * Allow RAT builds on systems with full linkage. 
     10        * Provide a more common interface for path config. 
    1011 
    1112v. 1.0beta7 - Tue Oct 23 2012 23:28 CEST 
  • doc/man1/roar-config.1

    r5672 r5747  
    2727 
    2828.TP 
     29\fB--product PRODUCT\fR 
     30Product string for --path. 
     31 
     32.TP 
     33\fB--provider PROVIDER\fR 
     34Provider string for --path. 
     35 
     36.TP 
     37\fB--universal\fR 
     38Use universal path for --path. 
     39 
     40.TP 
    2941\fB--libs\fR 
    3042Show linker flags (\-lxxx) needed to link library 
  • include/libroar/config.h

    r5465 r5747  
    153153#define roar_libroar_iswarn(cfg) (((cfg) == NULL ? roar_libroar_get_config_ptr() : (cfg))->nowarncounter ? 0 : 1) 
    154154 
     155// get a buffer to a system local path (prefix). 
     156// name is the symbolic name of the path, e.g. "prefix-lib". 
     157// null_as_universal tells of NULL is considered as "universal". 
     158// if not set NULL is considered 'do not add product path, give root prefix'. 
     159// product is the name of the product in standard "product <id/vendor>" format. 
     160// provider is the "<id/vendor>" format. If NULL this is ignored. 
     161// Returns buffer which needs to be freed with roar_mm_free(). 
     162// Not all paths support product/provider part. If not supported they are ignored. 
     163char * roar_libroar_get_path(const char * name, int null_as_universal, const char * product, const char * provider); 
     164 
    155165#endif 
    156166 
  • libroar/config.c

    r5466 r5747  
    432432} 
    433433 
     434static 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 
     452static 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 
     489static 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 
     523char * 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 
    434577//ll 
  • roarclients/Makefile

    r5737 r5747  
    9090        $L 
    9191roar-config: roar-config.o 
    92         $(LNL) 
     92        $L 
    9393roarvorbis: roarvorbis.o 
    9494        ${CC} ${LDFLAGS} -o roarvorbis roarvorbis.o $(VORBISLIBS) $(LIBS) 
  • roarclients/roar-config.c

    r5674 r5747  
    5353}, * flags_ptr = NULL; 
    5454 
    55 const struct path { 
    56  const char * name; 
    57  const char * path; 
    58 } paths[] = { 
    59  {"prefix",     ROAR_PREFIX}, 
    60  {"prefix-bin", ROAR_PREFIX_BIN}, 
    61  {"prefix-lib", ROAR_PREFIX_LIB}, 
    62  {"prefix-inc", ROAR_PREFIX_INC}, 
    63  {"prefix-man", ROAR_PREFIX_MAN}, 
    64  {"prefix-pc",  ROAR_PREFIX_PC}, 
    65  {"prefix-comp-libs", ROAR_PREFIX_COMP_LIBS}, 
    66  {"prefix-comp-bins", ROAR_PREFIX_COMP_BINS}, 
    67  {"prefix-plugins", ROAR_PREFIX_PLUGINS}, 
    68  {"prefix-buildsystem", ROAR_PREFIX_BUILDSYSTEM}, 
    69  {"<<<END>>>", NULL} 
    70 }; 
    71  
    72 void print_path(const char * name) { 
    73  size_t i; 
    74  
    75  for (i = 0; i < (sizeof(paths)/sizeof(*paths)); i++) { 
    76   if ( !strcasecmp(name, paths[i].name) ) { 
    77    printf("%s\n", paths[i].path); 
    78    return; 
    79   } 
    80  } 
     55void print_path(const char * name, int null_as_universal, const char * product, const char * provider) { 
     56 char * path = roar_libroar_get_path(name, null_as_universal, product, provider); 
     57 if ( path == NULL ) 
     58  return; 
     59 printf("%s\n", path); 
     60 roar_mm_free(path); 
    8161} 
    8262 
     
    8767 
    8868 printf( 
    89         "  --version          - Show version of library\n" 
    90         "  --path NAME        - Print path NAME\n" 
    91         "  --libs             - Show linker flags (-lxxx) needed to link library\n" 
    92         "  --cflags           - Show compiler flags needed to link library\n" 
    93         "  --output-pc        - Output PC format\n" 
    94         "  --output-normal    - Output PC format\n" 
     69        "  --version           - Show version of library\n" 
     70        "  --path NAME         - Print path NAME\n" 
     71        "  --product PRODUCT   - Product string for --path\n" 
     72        "  --provider PROVIDER - Provider string for --path\n" 
     73        "  --universal         - Use universal path for --path\n" 
     74        "  --libs              - Show linker flags (-lxxx) needed to link library\n" 
     75        "  --cflags            - Show compiler flags needed to link library\n" 
     76        "  --output-pc         - Output PC format\n" 
     77        "  --output-normal     - Output PC format\n" 
    9578       ); 
    9679 
     
    10184int main (int argc, char * argv[]) { 
    10285 enum { NORMAL, PC } mode = NORMAL; 
     86 int null_as_universal = 0; 
     87 const char * product = NULL; 
     88 const char * provider = NULL; 
    10389 int i, h; 
    10490 int cflags = 0; 
     
    117103   usage(); 
    118104   return 0; 
     105  } else if ( !strcmp(argv[i], "--product") ) { 
     106   product = argv[++i]; 
     107  } else if ( !strcmp(argv[i], "--provider") ) { 
     108   provider = argv[++i]; 
     109  } else if ( !strcmp(argv[i], "--universal") ) { 
     110   null_as_universal = 1; 
    119111  } else if ( !strcmp(argv[i], "--path") ) { 
    120    print_path(argv[++i]); 
     112   print_path(argv[++i], null_as_universal, product, provider); 
    121113  } else if ( !strcmp(argv[i], "--libs") ) { 
    122114   libs   = 1; 
Note: See TracChangeset for help on using the changeset viewer.