Changeset 21404

Show
Ignore:
Timestamp:
04.01.2010 17:43:22 (9 years ago)
Author:
davidb
Message:

Introduction of pathname_cat which concatenates values for path variables such as CLASSPATH and PATH. Uses ':' for Unix, ';' for Windows

Location:
main/trunk/greenstone2/common-src/src/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/lib/fileutil.cpp

    r14177 r21404  
    3838 
    3939 
    40 // returns the proper concatenation of the two paths 
     40// returns the proper concatenation of directory + directory/filename 
    4141text_t filename_cat (text_t path1, text_t path2) { 
    4242  text_t::iterator here; 
     
    108108} 
    109109 
     110 
     111 
     112// returns the proper concatenation of the two paths, as in 
     113// /usr/bin:/usr/local/bin (for Unix) and c:\usr\bin;c:\usr\local\bin (for windows) 
     114 
     115text_t pathname_cat (text_t path1, text_t path2) { 
     116  text_t::iterator here; 
     117  text_t::iterator begin; 
     118  text_t::iterator end; 
     119 
     120  // make sure there are no slashes at the end of path1 
     121 
     122  if (!path1.empty()) { 
     123    // remove all trailing slashes 
     124    here = path1.end(); 
     125    --here; 
     126    begin = path1.begin(); 
     127    while (here != begin && (*here == '/' || *here == '\\')) { 
     128      --here; 
     129    } 
     130    ++here; 
     131    path1.erase(here,path1.end()); 
     132     
     133    // add one final slash 
     134#ifdef __WIN32__ 
     135    path1 += ";"; 
     136#else 
     137    path1 += ":"; 
     138#endif  
     139  } 
     140 
     141  // make sure there are no slashes at the end of path2 
     142  here = path2.end(); 
     143  --here; 
     144  begin = path2.begin(); 
     145  while (here != begin && (*here == '/' || *here == '\\')) { 
     146    --here; 
     147  } 
     148  ++here; 
     149  path2.erase (here, path2.end()); 
     150   
     151  text_t fullpath = path1 + path2; 
     152   
     153  // make sure all the right slashes are used 
     154  here = fullpath.begin(); 
     155  end = fullpath.end(); 
     156  while (here != end) { 
     157#ifdef __WIN32__ 
     158    if (*here == '/') *here = '\\'; 
     159#else 
     160    if (*here == '\\') *here = '/'; 
     161#endif 
     162    ++here ; 
     163  } 
     164  return fullpath; 
     165} 
     166 
     167text_t pathname_cat (text_t path1, text_t path2, text_t path3) { 
     168  return pathname_cat(pathname_cat(path1,path2),path3); 
     169} 
     170 
     171text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4) { 
     172  return pathname_cat(pathname_cat(pathname_cat(path1,path2),path3),path4); 
     173} 
     174 
     175text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4,  
     176             text_t path5) { 
     177  return pathname_cat(pathname_cat(pathname_cat(pathname_cat(path1,path2),path3), 
     178                   path4),path5); 
     179} 
     180 
     181text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4,  
     182             text_t path5, text_t path6) { 
     183  return pathname_cat(pathname_cat(path1,path2,path3,path4,path5),path6); 
     184} 
     185 
     186 
     187 
     188 
     189 
    110190// returns true if filename can be opened 
    111191bool file_exists (const text_t &filename) { 
  • main/trunk/greenstone2/common-src/src/lib/fileutil.h

    r1837 r21404  
    3131 
    3232 
    33 // returns the proper concatenation of the two paths 
     33// returns the proper concatenation of directory + directory/filename 
    3434text_t filename_cat (text_t path1, text_t path2); 
    3535text_t filename_cat (text_t path1, text_t path2, text_t path3); 
     
    3838             text_t path5); 
    3939text_t filename_cat (text_t path1, text_t path2, text_t path3, text_t path4,  
     40             text_t path5, text_t path6); 
     41 
     42 
     43// returns the proper concatenation of the two paths, as in 
     44// /usr/bin:/usr/local/bin (for Unix) and c:\usr\bin;c:\usr\local\bin (for windows) 
     45text_t pathname_cat (text_t path1, text_t path2); 
     46text_t pathname_cat (text_t path1, text_t path2, text_t path3); 
     47text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4); 
     48text_t pathname_cat (text_t path1, text_t path2, text_t path3, text_t path4,  
     49             text_t path5); 
     50text_t pathhname_cat (text_t path1, text_t path2, text_t path3, text_t path4,  
    4051             text_t path5, text_t path6); 
    4152