Changeset 5811:28f6eed531d7 in roaraudio


Ignore:
Timestamp:
01/05/13 01:29:03 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

improved roar_env_render_path_r() and added support for it to roar-config

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/man1/roar-config.1

    r5801 r5811  
    55.SH NAME 
    66 
    7 roar-config \- get information of installed RoarAudio librarys 
     7roar-config \- get information of installed RoarAudio libraries 
    88 
    99.SH SYNOPSIS 
     
    1717roar-config [\-\-product PRODUCT] [\-\-provider PROVIDER] [\-\-universal] \-\-path PATH 
    1818 
     19roar-config \-\-render\-path PATH 
     20 
    1921.SH DESCRIPTION 
    2022 
    2123This small tool prints information about installed versions and needed flags to work 
    22 with the RoarAudio librarys. 
     24with the RoarAudio libraries. 
    2325 
    2426.SH "OPTIONS" 
     
    6163 
    6264.TP 
     65\fB--render-path PATH\fR 
     66Render the given path. The path can be any absolute path, a path relative to the user's home directory 
     67(prefixed with ~/) or a path relative to a path as used by --path (prefixed with $ and path name). 
     68 
     69.TP 
    6370\fB--libs\fR 
    6471Show linker flags (\-lxxx) needed to link library 
  • libroar/env.c

    r5754 r5811  
    121121} 
    122122 
     123static char * __get_path(const char ** inpath) { 
     124 char buf_path[64]; 
     125 size_t i; 
     126 
     127 (*inpath)++; 
     128 
     129 for (i = 0; i < sizeof(buf_path); i++) { 
     130  if ( (*inpath)[i] == '/' || (*inpath)[i] == 0 ) { 
     131   break; 
     132  } else { 
     133   buf_path[i] = (*inpath)[i]; 
     134  } 
     135 } 
     136 
     137 if ( i == sizeof(buf_path) ) { 
     138  roar_err_set(ROAR_ERROR_NOSPC); 
     139  return NULL; 
     140 } 
     141 
     142 buf_path[i] = 0; 
     143 
     144 (*inpath) += i; 
     145 
     146 return roar_libroar_get_path(buf_path, 0, NULL, NULL); 
     147} 
     148 
    123149int roar_env_render_path_r(char * out, size_t len, const char * inpath) { 
    124150 size_t inlen; 
     
    126152 size_t homelen = 0; 
    127153 const char * home; 
    128  enum { UNKNOWN, COPY, HOME } mode = UNKNOWN; 
     154 const char * prefix = NULL; 
     155 char * prefix_path = NULL; 
     156 enum { UNKNOWN, COPY, HOME, PREFIX } mode = UNKNOWN; 
    129157 
    130158 if ( len == 0 && inpath == NULL ) 
     
    159187  needlen = inlen + homelen - 1; 
    160188  mode    = HOME; 
    161  } 
    162  
    163  if ( len < (needlen + 1) ) 
    164   return -1; 
     189  prefix  = home; 
     190  inpath++; 
     191 } else if ( inpath[0] == '$' ) { 
     192  prefix_path = __get_path(&inpath); 
     193  if ( prefix_path == NULL ) 
     194   return -1; 
     195  needlen = roar_mm_strlen(inpath) + roar_mm_strlen(prefix_path) + 1; 
     196  mode    = PREFIX; 
     197  prefix  = prefix_path; 
     198 } 
     199 
     200 if ( len < (needlen + 1) ) { 
     201  if ( prefix_path != NULL ) 
     202   roar_mm_free(prefix_path); 
     203  roar_err_set(ROAR_ERROR_NOSPC); 
     204  return -1; 
     205 } 
    165206 
    166207 switch (mode) { 
     
    170211   break; 
    171212  case HOME: 
    172     roar_mm_strlcpy(out, home, len); 
    173     roar_mm_strlcat(out, inpath+1, len); // strip only ~, so we have the / if home is not /-terminated. 
     213  case PREFIX: 
     214    roar_mm_strlcpy(out, prefix, len); 
     215    roar_mm_strlcat(out, inpath, len); // strip only ~, so we have the / if home is not /-terminated. 
    174216   break; 
    175217  default: 
     218    if ( prefix_path != NULL ) 
     219     roar_mm_free(prefix_path); 
     220    roar_err_set(ROAR_ERROR_NOTSUP); 
    176221    return -1; 
    177222   break; 
    178223 } 
    179224 
     225 if ( prefix_path != NULL ) 
     226  roar_mm_free(prefix_path); 
    180227 return 0; 
    181228} 
  • roarclients/roar-config.c

    r5810 r5811  
    142142} 
    143143 
     144void print_renderpath(const char * path) { 
     145 char buf[1024]; 
     146 
     147 if ( roar_env_render_path_r(buf, sizeof(buf), path) != 0 ) { 
     148  fprintf(stderr, "Error: Can not render path: %s: %s\n", path, roar_errorstring); 
     149  return; 
     150 } 
     151 printf("%s\n", buf); 
     152} 
     153 
    144154void usage (void) { 
    145155 printf("Usage: roar-config --version\n" 
    146156        "       roar-config --compare-versions VERSIONA OPERATOR VERSIONB\n" 
    147157        "       roar-config [{--output-pc|--output-normal}] [--libs] [--cflags] [LIB]\n" 
    148         "       roar-config [--product PRODUCT] [--provider PROVIDER] [--universal] --path PATH\n"); 
     158        "       roar-config [--product PRODUCT] [--provider PROVIDER] [--universal] --path PATH\n" 
     159        "       roar-config --render-path PATH\n"); 
    149160 
    150161 printf("\nOptions:\n\n"); 
     
    158169        "  --provider PROVIDER - Provider string for --path\n" 
    159170        "  --universal         - Use universal path for --path\n" 
     171        "  --render-path PATH  - Print a rendered path\n" 
    160172        "  --libs              - Show linker flags (-lxxx) needed to link library\n" 
    161173        "  --cflags            - Show compiler flags needed to link library\n" 
     
    199211  } else if ( !strcmp(argv[i], "--path") ) { 
    200212   print_path(argv[++i], null_as_universal, product, provider); 
     213  } else if ( !strcmp(argv[i], "--render-path") ) { 
     214   print_renderpath(argv[++i]); 
    201215  } else if ( !strcmp(argv[i], "--libs") ) { 
    202216   libs   = 1; 
Note: See TracChangeset for help on using the changeset viewer.