Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / soreduce / SO_Group.cpp
blob532c12b1eac3a73209206ed2acb7eb3294c73da0
1 // -*- C++ -*-
2 // File: SO_Group.cpp
4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Process.h"
8 #include "ace/Pipe.h"
10 #include "Library.h"
11 #include "SO_Group.h"
13 SO_Group::SO_Group ()
14 : undef_wrapper_ ("nothing"),
15 undefs_(undef_wrapper_.imports()),
16 libs_ (0),
17 max_libs_ (128),
18 num_libs_(0)
20 libs_ = new Library*[max_libs_];
23 SO_Group::~SO_Group ()
25 for (int i = 0; i < num_libs_; delete libs_[i++])
27 // No action.
30 delete [] libs_;
33 void
34 SO_Group::add_executable (const char * path)
36 ACE_Process proc;
37 ACE_Process_Options opts;
39 ACE_HANDLE pipe[2];
40 ACE_Pipe io(pipe);
42 opts.set_handles (ACE_STDIN,pipe[1]);
44 int result = opts.command_line ("ldd %s",path);
45 // Prevent compiler warning about "unused variable" if ACE_ASSERT is
46 // an empty macro.
47 ACE_UNUSED_ARG (result);
48 ACE_ASSERT (result == 0);
50 proc.spawn (opts);
51 if (ACE_OS::close(pipe[1]) == -1)
52 ACE_DEBUG ((LM_DEBUG, "%p\n", "close"));
53 opts.release_handles();
55 const int max_line_length = 1000;
56 char line[max_line_length];
58 while (true)
60 ACE_OS::memset (line,0,max_line_length);
61 int len = 0;
62 int nread = 0;
63 int bogus = 0;
65 // Skip initial whitespace.
66 while ((nread = ACE_OS::read (pipe[0], line,1)) == 1
67 && (*line == ' ' || *line == '\t'))
69 // No action.
72 if (nread != 1)
74 break;
77 // read the library name
78 len = 1;
80 while ((nread = ACE_OS::read (pipe[0], line + len, 1)) == 1
81 && (line[len] != ' '))
83 if (! bogus && ++len == max_line_length)
85 bogus = 1;
86 break;
90 if (nread != 1 || bogus)
92 break;
95 line[len] = 0;
96 char * dot = ACE_OS::strchr (line,'.');
98 if (dot != 0)
100 *dot = 0;
103 char * libname = line + 3; // skip over "lib"
105 // check to see if this is a new library
106 int found = 0;
108 for (int i = 0; !found && i < num_libs_; ++i)
110 found = (libs_[i]->name() == libname);
113 if (!found)
115 Library *nlib = new Library(libname);
116 ACE_OS::memset (line,0,max_line_length);
118 // Skip over '=> '.
119 if (ACE_OS::read (pipe[0], line, 3) != 3)
121 break;
124 // get library path
125 len = 0;
127 while ((nread = ACE_OS::read(pipe[0],line + len,1)) == 1 &&
128 (line[len] != ' '))
130 if (! bogus && ++len == max_line_length)
132 bogus = 1;
133 break;
137 if (nread != 1 || bogus)
139 break;
142 line[len] = 0;
143 nlib->set_path (line);
144 libs_[num_libs_++] = nlib;
145 ACE_ASSERT (num_libs_ < max_libs_); // grow max libs?
148 // Skip the rest of the line.
149 while ((nread = ACE_OS::read (pipe[0], line, 1)) == 1
150 && *line != '\n')
152 // No action.
155 if (nread != 1)
157 break;
160 proc.wait ();
161 ACE_OS::close (pipe[0]);
163 undef_wrapper_.add_source(path,1);
164 // now do the ldd, iterate over the results to add new libs, etc.
167 void
168 SO_Group::analize ()
170 for (int passcount = 0; undefs_.modified (); ++passcount)
172 ACE_DEBUG ((LM_DEBUG,
173 "pass %d, undef count = %d\n",
174 passcount,
175 undefs_.size ()));
177 for (int i = 0; i < num_libs_; libs_[i++]->resolve (undefs_))
179 // No action.
184 void
185 SO_Group::write_results ()
187 for (int i = 0; i < num_libs_; libs_[i++]->write_export_list (1))
189 // No action.
193 void
194 SO_Group::load_modules ()
196 for (int i = 0; i < num_libs_; libs_[i++]->load_modules ())
198 // No action.
202 void
203 SO_Group::list_libs ()
205 ACE_DEBUG ((LM_DEBUG, "Libs subject to analysis:\n"));
207 for (int i = 0; i < num_libs_; ++i)
209 if (libs_[i]->has_modules ())
211 ACE_DEBUG ((LM_DEBUG, " %s\n", libs_[i]->name ().c_str ()));