Functions
get-accessible-paths.cc File Reference
#include "boost/filesystem.hpp"
#include "cetlib/getenv.h"
#include "cetlib/split.h"
#include <iostream>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file get-accessible-paths.cc.

43 {
44  if (argc != 3) {
45  return 1;
46  }
47 
48  std::string const envname{argv[1]};
49  std::string spec{argv[2]};
50  std::string to_match{spec};
51  auto const last_slash = to_match.find("/");
52  bool const slash_found{last_slash != std::string::npos};
53  std::string const prefix = slash_found ? to_match.substr(0, last_slash) : ""s;
54  if (slash_found) {
55  to_match.erase(0, last_slash + 1);
56  }
57 
58  if (spec.empty() || spec[0] == '/') {
59  print_paths("/"s + prefix, "/"s + to_match, true);
60  }
61 
62  if (spec[0] != '/') {
63  print_paths("./"s + prefix, to_match, false);
64  }
65 
66  if (spec[0] != '/' && spec.find("./") != 0) {
67  // Find paths on environment variable
68  auto const env = cet::getenv(envname);
69  std::vector<std::string> paths;
70  cet::split(env, ':', back_inserter(paths));
71  for (auto const& path : paths) {
72  if (path == "."s)
73  continue;
74  print_paths(path + prefix, to_match, false);
75  }
76  }
77 }
std::string string
Definition: nybbler.cc:12
std::string getenv(std::string const &name)
Definition: getenv.cc:15
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
static QCString * s
Definition: config.cpp:1042