Changeset 5832:f0b38d5ea016 in roaraudio for libroar/config.c


Ignore:
Timestamp:
01/06/13 16:15:56 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_libroar_get_path_static() and make use of it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/config.c

    r5831 r5832  
    436436} 
    437437 
    438 static const struct { 
     438static const struct pathinfo { 
    439439 const char * name; 
    440440 const char * path; 
     
    487487 {"bin-pinentry",       ROAR_HAVE_BIN_PINENTRY, 0, 0}, 
    488488 {"bin-ssh_askpass",    ROAR_HAVE_BIN_SSH_ASKPASS, 0, 0}, 
    489  {"bin-gtk_led_askpass", ROAR_HAVE_BIN_GTK_LED_ASKPASS, 0, 0}, 
    490  {"bin-x11_ssh_askpass", ROAR_HAVE_BIN_X11_SSH_ASKPASS, 0, 0}, 
    491  {"bin-gnome_ssh_askpass", ROAR_HAVE_BIN_GNOME_SSH_ASKPASS, 0, 0}, 
     489 {"bin-gtk-led-askpass", ROAR_HAVE_BIN_GTK_LED_ASKPASS, 0, 0}, 
     490 {"bin-x11-ssh-askpass", ROAR_HAVE_BIN_X11_SSH_ASKPASS, 0, 0}, 
     491 {"bin-gnome-ssh-askpass", ROAR_HAVE_BIN_GNOME_SSH_ASKPASS, 0, 0}, 
    492492 {"bin-gpg",            ROAR_HAVE_BIN_GPG, 0, 0}, 
    493493 {"bin-eject",          ROAR_HAVE_BIN_EJECT, 0, 0}, 
    494494 
    495495 // devices: 
    496  {"dev-stdin",          ROAR_PREFIX_DEV "/stdin", 0, 0}, 
     496 {"dev-stdin",                  ROAR_PREFIX_DEV "/stdin", 0, 0}, 
    497497 {"dev-default-pwmled",         ROAR_PREFIX_DEV "/ttyS0", 0, 0}, 
     498 {"dev-default-dmx4linux",      ROAR_PREFIX_DEV "/dmx", 0, 0}, 
    498499 
    499500#ifdef ROAR_DEFAULT_CDROM 
     
    512513 // proc: 
    513514#ifdef ROAR_PROC_NET_DECNET 
    514  {"proc-net-decnet",     ROAR_PROC_NET_DECNET, 0, 0}, 
     515 {"proc-net-decnet",            ROAR_PROC_NET_DECNET, 0, 0}, 
    515516#endif 
    516517#ifdef ROAR_PROC_NET_DECNET_NEIGH 
    517  {"proc-net-decnet-neigh", ROAR_PROC_NET_DECNET_NEIGH, 0, 0}, 
     518 {"proc-net-decnet-neigh",      ROAR_PROC_NET_DECNET_NEIGH, 0, 0}, 
    518519#endif 
    519520#ifdef ROAR_PROC_NET_ARP 
    520  {"proc-net-arp",        ROAR_PROC_NET_ARP, 0, 0}, 
     521 {"proc-net-arp",               ROAR_PROC_NET_ARP, 0, 0}, 
    521522#endif 
    522523 
    523524 // sysconf: 
    524  {"sysconf-hosts",       ROAR_PREFIX_SYSCONF "/hosts", 0, 0}, 
    525  {"sysconf-roarserver",  ROAR_PREFIX_SYSCONF "/roarserver", 0, 0}, 
     525 {"sysconf-hosts",              ROAR_PREFIX_SYSCONF "/hosts", 0, 0}, 
     526 {"sysconf-roarserver",         ROAR_PREFIX_SYSCONF "/roarserver", 0, 0}, 
    526527 
    527528 // special dirs: 
    528  {"dir-nx-home",         "/NX-HOME-DIR", 0, 0} 
     529 {"dir-nx-home",                "/NX-HOME-DIR", 0, 0} 
    529530}; 
    530531 
     
    606607} 
    607608 
     609static const struct pathinfo * __lookup_path(const char * name) { 
     610 size_t i; 
     611 
     612 if ( name == NULL ) { 
     613  roar_err_set(ROAR_ERROR_FAULT); 
     614  return NULL; 
     615 } 
     616 
     617 for (i = 0; i < (sizeof(__paths)/sizeof(*__paths)); i++) 
     618  if ( !strcmp(__paths[i].name, name) ) 
     619   return &(__paths[i]); 
     620 
     621 roar_err_set(ROAR_ERROR_NOENT); 
     622 return NULL; 
     623} 
     624 
    608625char * roar_libroar_get_path(const char * name, int null_as_universal, const char * product, const char * provider) { 
     626 const struct pathinfo * path; 
    609627 char buf_product[384]; 
    610628 char buf_provider[384]; 
    611629 ssize_t len_prefix, len_product, len_provider; 
    612  size_t i; 
    613630 char * ret, * p; 
    614631 
    615632 ROAR_DBG("roar_libroar_get_path(name='%s', null_as_universal=%i, product='%s', provider='%s') = ?", name, null_as_universal, product, provider); 
    616633 
    617  if ( name == NULL ) { 
    618   roar_err_set(ROAR_ERROR_FAULT); 
    619   return NULL; 
    620  } 
    621  
    622  for (i = 0; i < (sizeof(__paths)/sizeof(*__paths)); i++) { 
    623   if ( !!strcmp(__paths[i].name, name) ) 
    624    continue; 
    625  
    626   if ( ((null_as_universal || product != NULL) && !__paths[i].with_product) || 
    627        (provider != NULL && !__paths[i].with_provider) ) { 
    628    roar_err_set(ROAR_ERROR_INVAL); 
    629    return NULL; 
    630   } 
    631  
    632   if ( __product2path(buf_product, sizeof(buf_product), null_as_universal, product, __paths[i].with_product) == -1 ) 
    633    return NULL; 
    634  
    635   if ( __provider2path(buf_provider, sizeof(buf_provider), provider) == -1 ) 
    636    return NULL; 
    637  
    638   len_prefix = roar_mm_strlen(__paths[i].path); 
    639   len_product = roar_mm_strlen(buf_product); 
    640   len_provider = roar_mm_strlen(buf_provider); 
    641  
    642   p = ret = roar_mm_malloc(len_prefix+len_product+len_provider+1); 
    643   if ( ret == NULL ) 
    644    return NULL; 
    645  
    646   memcpy(p, __paths[i].path, len_prefix); 
    647   p += len_prefix; 
    648   if ( p[-1] == '/' ) 
    649    p--; 
    650   memcpy(p, buf_product, len_product); 
    651   p += len_product; 
    652   memcpy(p, buf_provider, len_provider); 
    653   p += len_provider; 
    654  
    655   *p = 0; 
    656  
    657   return ret; 
    658  } 
    659  
    660  roar_err_set(ROAR_ERROR_NOENT); 
    661  return NULL; 
     634 path = __lookup_path(name); 
     635 if ( path == NULL ) 
     636  return NULL; 
     637 
     638 if ( ((null_as_universal || product != NULL) && !path->with_product) || 
     639      (provider != NULL && !path->with_provider) ) { 
     640  roar_err_set(ROAR_ERROR_INVAL); 
     641  return NULL; 
     642 } 
     643 
     644 if ( __product2path(buf_product, sizeof(buf_product), null_as_universal, product, path->with_product) == -1 ) 
     645  return NULL; 
     646 
     647 if ( __provider2path(buf_provider, sizeof(buf_provider), provider) == -1 ) 
     648  return NULL; 
     649 
     650 len_prefix = roar_mm_strlen(path->path); 
     651 len_product = roar_mm_strlen(buf_product); 
     652 len_provider = roar_mm_strlen(buf_provider); 
     653 
     654 p = ret = roar_mm_malloc(len_prefix+len_product+len_provider+1); 
     655 if ( ret == NULL ) 
     656  return NULL; 
     657 
     658 memcpy(p, path->path, len_prefix); 
     659 p += len_prefix; 
     660 if ( p[-1] == '/' ) 
     661  p--; 
     662 memcpy(p, buf_product, len_product); 
     663 p += len_product; 
     664 memcpy(p, buf_provider, len_provider); 
     665 p += len_provider; 
     666 
     667 *p = 0; 
     668 
     669 return ret; 
     670} 
     671 
     672const char * roar_libroar_get_path_static(const char * name) { 
     673 const struct pathinfo * path; 
     674 
     675 path = __lookup_path(name); 
     676 if ( path == NULL ) 
     677  return NULL; 
     678 
     679 return path->path; 
    662680} 
    663681 
Note: See TracChangeset for help on using the changeset viewer.