/[gentoo-alt]/trunk/aix-miscutils/ldd/aixdll-query.cc
Gentoo

Contents of /trunk/aix-miscutils/ldd/aixdll-query.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1634 - (show annotations) (download) (as text)
Wed Jul 9 07:30:57 2008 UTC (6 years, 5 months ago) by haubi
File MIME type: text/x-c++src
File size: 3258 byte(s)
have it compile on linux too, for packaging
1 /* Copyright 2008 Gentoo Foundation
2 * Distributed under the terms of the GNU General Public License v2
3 * Author: Michael Haubenwallner <haubi@gentoo.org>
4 */
5
6 #include <string>
7 #include <map>
8 #include <iostream>
9 #include <errno.h>
10 #include <string.h>
11
12 #include "ObjectReader.h"
13
14 using namespace aixdll;
15
16 typedef ObjectReader::ObjectContainer ObjectContainer;
17 typedef std::map<std::string, bool> QuestionContainer;
18
19 bool query(std::string const& filename, QuestionContainer const& questions)
20 {
21 ObjectReader reader;
22 ObjectContainer objects;
23
24 if (reader.readObjects(filename, filename, objects) == 0) {
25 std::cerr << "ldd: " << filename << ": " << strerror(ENOENT) << std::endl;
26 return true;
27 }
28
29 for(ObjectContainer::iterator o = objects.begin()
30 ; o != objects.end()
31 ; o++
32 ) {
33 if (questions.find("FILE") != questions.end()) {
34 std::cout << " FILE='";
35 if ((*o)->key()->path()) {
36 std::cout << (*o)->key()->path()->asIdentifier();
37 }
38 std::cout << (*o)->key()->name()->base() << "';";
39 }
40 if (questions.find("MEMBER") != questions.end()) std::cout
41 << " MEMBER='"
42 << (*o)->key()->name()->member()
43 << "';"
44 ;
45 if (questions.find("FLAGS") != questions.end()) std::cout
46 << " FLAGS='"
47 << (*o)->flags()
48 << "';"
49 ;
50 if (questions.find("FORMAT") != questions.end()) std::cout
51 << " FORMAT='"
52 << (*o)->format()
53 << "';"
54 ;
55 SharedObject *sharedObject = dynamic_cast<SharedObject*>(o->ptr());
56 StaticObject *staticObject = dynamic_cast<StaticObject*>(o->ptr());
57 if (sharedObject) {
58 if (questions.find("SHROBJ") != questions.end()) std::cout
59 << " SHROBJ=true;"
60 ;
61 if (questions.find("RUNPATH") != questions.end()) std::cout
62 << " RUNPATH='"
63 << sharedObject->runpath()->asSeparated()
64 << "';"
65 ;
66 if (questions.find("DEPLIBS") != questions.end()) {
67 std::cout
68 << " DEPLIBS=\""
69 ;
70 SharedObject::DependencyContainer const& deps = sharedObject->getDependencies();
71 for(SharedObject::DependencyContainer::const_iterator dep = deps.begin()
72 ; dep != deps.end()
73 ; dep++
74 ) {
75 std::cout << " '";
76 if ((*dep)->key()) {
77 std::cout << (*dep)->key()->asIdentifier();
78 } else {
79 std::cout << (*dep)->name()->asIdentifier();
80 }
81 std::cout << "'";
82 }
83 std::cout << "\";";
84 }
85 } else {
86 if (questions.find("SHROBJ") != questions.end()) std::cout
87 << " SHROBJ=false;"
88 ;
89 if (questions.find("RUNPATH") != questions.end()) std::cout
90 << " RUNPATH='';"
91 ;
92 if (questions.find("DEPLIBS") != questions.end()) std::cout
93 << " DEPLIBS='';"
94 ;
95 }
96
97 std::cout << std::endl;
98 }
99
100 return false;
101 }
102
103 int main(int argc, char **argv)
104 {
105 int i;
106 QuestionContainer questions;
107
108 if (argc < 2) {
109 std::cout << argv[0] << " file [what1 [what2] [whatn]]\n"
110 "available for [what]:\n"
111 "\tFILE MEMBER FLAGS FORMAT SHROBJ RUNPATH DEPLIBS"
112 << std::endl;
113 return 0;
114 }
115
116 for(i = 2; i < argc; i++) {
117 questions[argv[i]] = true;
118 }
119
120 if (questions.size() == 0) {
121 questions["FILE"] = true;
122 questions["MEMBER"] = true;
123 questions["FLAGS"] = true;
124 questions["FORMAT"] = true;
125 questions["SHROBJ"] = true;
126 questions["RUNPATH"] = true;
127 questions["DEPLIBS"] = true;
128 }
129
130 return query(argv[1], questions);
131 }

  ViewVC Help
Powered by ViewVC 1.1.20