liblist.cxx
Go to the documentation of this file.
1 // liblist.cxx
2 //
3 // David Adams
4 // September 2016
5 //
6 // List all libraries accessible on the library path.
7 
8 #include <string>
9 #include <iostream>
10 #include <vector>
11 #include <sstream>
12 #include <memory>
13 #include "cetlib/LibraryManager.h"
14 
15 using std::string;
16 using std::cout;
17 using std::endl;
18 using std::ostream;
19 using std::istringstream;
21 
22 typedef std::vector<std::string> NameList;
23 
24 int main(int argc, char** argv) {
25  const string myname = "listlibs";
26  bool help = false;
27  string libtype = "tool";
28  string pattern;
29  if ( argc > 1 ) {
30  string arg = argv[1];
31  if ( arg == "-h" ) help = true;
32  else libtype = arg;
33  }
34  if ( argc > 2 ) {
35  string arg = argv[2];
36  if ( arg == "-h" ) help = true;
37  else pattern = arg;
38  }
39  if ( help ) {
40  cout << "Usage: " << argv[0] << " [type] [pattern]" << endl;
41  cout << " Lists plugin libraries of a specified type." << endl;
42  cout << " type [tool] - library type (tool, service, module, ...)" << endl;
43  cout << " pattern [] - pattern in library name" << endl;
44  return 0;
45  }
46  // Find the libs.
47  NameList libnames;
48  LibraryManager libmgr(libtype);
49  unsigned int nlib = libmgr.getLoadableLibraries(libnames);
50  if ( pattern.size() ) {
51  NameList newnames;
52  for ( string libname : libnames ) {
53  if ( libname.find(pattern) != string::npos ) newnames.push_back(libname);
54  }
55  libnames = newnames;
56  }
57  unsigned int nsel = libnames.size();
58  if ( pattern.size() && nlib > 0 ) cout << "Selected " << nsel << " of ";
59  else cout << "Found ";
60  cout << nlib << " " << libtype << " librar";
61  cout << (nlib==1 ? "y" : "ies");
62  cout << (nsel ? ":" : ".");
63  for ( string libname : libnames ) {
64  cout << "\n " << libname;
65  }
66  cout << endl;
67  return 0;
68 }
int main(int argc, char **argv)
Definition: liblist.cxx:24
std::string string
Definition: nybbler.cc:12
size_t getLoadableLibraries(std::vector< std::string > &list) const
std::string pattern
Definition: regex_t.cc:35
QTextStream & endl(QTextStream &s)
std::vector< std::string > NameList
Definition: liblist.cxx:22