|
@@ -81,6 +81,7 @@ int main(int argc, char** argv)
|
|
|
}
|
|
|
|
|
|
bool outputPath = false;
|
|
|
+ bool outputSort = false;
|
|
|
QString label;
|
|
|
if (argc == 3)
|
|
|
{
|
|
@@ -89,14 +90,23 @@ int main(int argc, char** argv)
|
|
|
}
|
|
|
if (argc == 4)
|
|
|
{
|
|
|
- if (QString(argv[2]).compare("-paths")!=0)
|
|
|
+ QString arg2 = QString::fromLatin1(argv[2]);
|
|
|
+ if (arg2.compare("-paths")!=0 && arg2.compare("-sort")!=0)
|
|
|
{
|
|
|
- displayError(argv[0], QString("Wrong argument: %1").arg(argv[2]));
|
|
|
+ displayError(argv[0], QString("Wrong argument: %1").arg(arg2));
|
|
|
return EXIT_FAILURE;
|
|
|
}
|
|
|
label = QLatin1String(argv[3]);
|
|
|
outputTopologicalOrder = false;
|
|
|
- outputPath = true;
|
|
|
+ if (arg2.compare("-paths") == 0)
|
|
|
+ {
|
|
|
+ outputPath = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ outputSort = true;
|
|
|
+ }
|
|
|
+
|
|
|
if (verbose)
|
|
|
{
|
|
|
qDebug() << "label:" << label;
|
|
@@ -207,7 +217,7 @@ int main(int argc, char** argv)
|
|
|
if (mygraph.cycleDetected())
|
|
|
{
|
|
|
std::cerr << "Cycle detected !" << std::endl;
|
|
|
- QList<int> path;
|
|
|
+ QList<int> path;
|
|
|
mygraph.findPath(mygraph.cycleOrigin(), mygraph.cycleEnd(), path);
|
|
|
|
|
|
for(int i = 0; i < path.size(); ++i)
|
|
@@ -268,16 +278,50 @@ int main(int argc, char** argv)
|
|
|
{
|
|
|
// TODO Make sure label is valid
|
|
|
QList<int> out;
|
|
|
+ if (mygraph.topologicalSort(out))
|
|
|
+ {
|
|
|
+ for(int i=0; i < out.size(); i++)
|
|
|
+ {
|
|
|
+ // Assume all targets depend on the first lib
|
|
|
+ // We could get all sinks and find all paths
|
|
|
+ // from the rootId to the sink vertices.
|
|
|
+ int rootId = out.last();
|
|
|
+ int labelId = vertexLabelToId[label];
|
|
|
+ QList<QList<int>*> paths;
|
|
|
+ mygraph.findPaths(labelId, rootId, paths);
|
|
|
+ for(int i=0; i < paths.size(); i++)
|
|
|
+ {
|
|
|
+ QList<int>* p = paths[i];
|
|
|
+ Q_ASSERT(p);
|
|
|
+ for(int j=0; j < p->size(); j++)
|
|
|
+ {
|
|
|
+ int id = p->at(j);
|
|
|
+ std::cout << vertexIdToLabel[id].toStdString();
|
|
|
+ if (j != p->size() - 1)
|
|
|
+ {
|
|
|
+ std::cout << " ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i != paths.size() - 1)
|
|
|
+ {
|
|
|
+ std::cout << ";";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (outputSort)
|
|
|
+ {
|
|
|
+ // TODO Make sure label is valid
|
|
|
+ QList<int> out;
|
|
|
int labelId = vertexLabelToId[label];
|
|
|
if (mygraph.topologicalSort(out, labelId))
|
|
|
{
|
|
|
for(int i=0; i < out.size(); i++)
|
|
|
{
|
|
|
int id = out.at(i);
|
|
|
- if (vertexIdToLabel[id].isEmpty())
|
|
|
- std::cout << "<" << id << ">";
|
|
|
- else
|
|
|
- std::cout << vertexIdToLabel[id].toStdString();
|
|
|
+ std::cout << vertexIdToLabel[id].toStdString();
|
|
|
|
|
|
if (i != out.size() - 1)
|
|
|
{
|