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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/fmanip (Version 11.3.0) and /externals/g4tools/include/tools/fmanip (Version 11.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_fmanip                                4 #ifndef tools_fmanip
  5 #define tools_fmanip                                5 #define tools_fmanip
  6                                                     6 
  7 #include "file"                                     7 #include "file"
  8 #include "sep"                                      8 #include "sep"
  9 #include "sout"                                     9 #include "sout"
 10 #include <ostream>                                 10 #include <ostream>
 11                                                    11 
 12 namespace tools {                                  12 namespace tools {
 13                                                    13 
 14 inline bool find_with_dirs(std::ostream& a_out     14 inline bool find_with_dirs(std::ostream& a_out,
 15                            const std::vector<s     15                            const std::vector<std::string>& a_dirs,
 16                            const std::string&      16                            const std::string& a_file,
 17                            std::string& a_path     17                            std::string& a_path,
 18                            bool a_verbose = fa     18                            bool a_verbose = false ) {
 19   std::vector<std::string>::const_iterator it;     19   std::vector<std::string>::const_iterator it;
 20   for(it=a_dirs.begin();it!=a_dirs.end();++it)     20   for(it=a_dirs.begin();it!=a_dirs.end();++it) {
 21     if((*it).empty()) {                            21     if((*it).empty()) {
 22       // with a "" in dirs, this case could so     22       // with a "" in dirs, this case could solve :
 23       // - a_file in the current directory.        23       // - a_file in the current directory.
 24       // - a_file with an absolute path name.      24       // - a_file with an absolute path name.
 25       a_path = a_file; //may be an absolute fi     25       a_path = a_file; //may be an absolute file name.
 26     } else {                                       26     } else {
 27       a_path = *it;                                27       a_path = *it;
 28       a_path += sep();                             28       a_path += sep();
 29       a_path += a_file;                            29       a_path += a_file;
 30     }                                              30     }
 31                                                    31 
 32     if(a_verbose) {                                32     if(a_verbose) {
 33       a_out << "find_with_dirs :"                  33       a_out << "find_with_dirs :"
 34             << " look for " << sout(a_path) <<     34             << " look for " << sout(a_path) << " ..."
 35             << std::endl;                          35             << std::endl;
 36     }                                              36     }
 37                                                    37 
 38     if(file::exists(a_path)) {                     38     if(file::exists(a_path)) {
 39       if(a_verbose) {                              39       if(a_verbose) {
 40         a_out << "find_with_dirs :"                40         a_out << "find_with_dirs :"
 41               << " found " << sout(a_path) <<      41               << " found " << sout(a_path) << "."
 42               << std::endl;                        42               << std::endl;
 43       }                                            43       }
 44       return true;                                 44       return true;
 45     }                                              45     }
 46   }                                                46   }
 47   a_path.clear();                                  47   a_path.clear();
 48                                                    48 
 49   if(a_verbose) {                                  49   if(a_verbose) {
 50     a_out << "find_with_dirs :"                    50     a_out << "find_with_dirs :"
 51           << " " << sout(a_file) << " not foun     51           << " " << sout(a_file) << " not found."
 52           << std::endl;                            52           << std::endl;
 53   }                                                53   }
 54                                                    54 
 55   return false;                                    55   return false;
 56 }                                                  56 }
 57                                                    57 
 58 }                                                  58 }
 59                                                    59 
 60 #include "get_env"                                 60 #include "get_env"
 61                                                    61 
 62 namespace tools {                                  62 namespace tools {
 63                                                    63 
 64 inline bool find_with_env(std::ostream& a_out,     64 inline bool find_with_env(std::ostream& a_out,
 65                           const std::string& a     65                           const std::string& a_env,
 66                           const std::string& a     66                           const std::string& a_file,
 67                           std::string& a_path,     67                           std::string& a_path,
 68                           bool a_verbose = fal     68                           bool a_verbose = false ) {
 69   std::string PATH;                                69   std::string PATH;
 70   if(!get_env(a_env,PATH)) {                       70   if(!get_env(a_env,PATH)) {
 71     //look for a a_file in current directory.      71     //look for a a_file in current directory.
 72     if(file::exists(a_file)) {                     72     if(file::exists(a_file)) {
 73       //a_out << "tools::find_with_env :"          73       //a_out << "tools::find_with_env :"
 74       //      << " env variable " << sout(a_en     74       //      << " env variable " << sout(a_env) << " not defined, but file " << sout(a_file) << " exists."
 75       //      << std::endl;                        75       //      << std::endl;
 76       a_path = a_file;                             76       a_path = a_file;
 77       return true;                                 77       return true;
 78     }                                              78     }
 79     a_out << "tools::find_with_env : env varia     79     a_out << "tools::find_with_env : env variable " << sout(a_env) << " not defined." << std::endl;
 80     a_path.clear();                                80     a_path.clear();
 81     return false;                                  81     return false;
 82   }                                                82   }
 83   if(a_verbose) {                                  83   if(a_verbose) {
 84     a_out << "find_with_env : env " << sout(a_     84     a_out << "find_with_env : env " << sout(a_env) << " is " << sout(PATH) << std::endl;
 85   }                                                85   }
 86                                                    86 
 87   std::vector<std::string> dirs;                   87   std::vector<std::string> dirs;
 88   words(PATH,psep(),false,dirs); //or true ?       88   words(PATH,psep(),false,dirs); //or true ?
 89                                                    89 
 90   return find_with_dirs(a_out,dirs,a_file,a_pa     90   return find_with_dirs(a_out,dirs,a_file,a_path,a_verbose);
 91 }                                                  91 }
 92                                                    92 
 93 }                                                  93 }
 94                                                    94 
 95 #endif                                             95 #endif