summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Winkelmann <jw@smts.ch>2006-04-12 16:06:17 +0000
committerJohannes Winkelmann <jw@smts.ch>2006-04-12 16:06:17 +0000
commitab768a4a8829d7a964efe41aee1045631c97c1bf (patch)
tree15dcffd0b2830268c91cc971065f0320c8a4229c /src
parenta4a40a4b02be44729d1e52c560c81c4ef0fc40c6 (diff)
downloadprt-get-ab768a4a8829d7a964efe41aee1045631c97c1bf.tar.gz
prt-get-ab768a4a8829d7a964efe41aee1045631c97c1bf.tar.xz
prt-get: support recursive dependent and a tree view
git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1234 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
Diffstat (limited to 'src')
-rw-r--r--src/argparser.cpp18
-rw-r--r--src/argparser.h5
-rw-r--r--src/main.cpp4
-rw-r--r--src/prtget.cpp35
-rw-r--r--src/prtget.h6
5 files changed, 58 insertions, 10 deletions
diff --git a/src/argparser.cpp b/src/argparser.cpp
index c39e626..1aabbc4 100644
--- a/src/argparser.cpp
+++ b/src/argparser.cpp
@@ -45,7 +45,9 @@ ArgParser::ArgParser( int argc, char** argv )
m_preferHigher( false ),
m_strictDiff( false ),
m_useRegex(false),
- m_fullPath(false)
+ m_fullPath(false),
+ m_recursive(false),
+ m_printTree(false)
{
}
@@ -196,6 +198,10 @@ bool ArgParser::parse()
m_useRegex = true;
} else if ( s == "--full" ) {
m_fullPath = true;
+ } else if ( s == "--recursive" ) {
+ m_recursive = true;
+ } else if ( s == "--tree" ) {
+ m_printTree = true;
} else if ( s == "-f" ) {
m_pkgaddArgs += " " + s;
@@ -382,6 +388,16 @@ bool ArgParser::printPath() const
return m_printPath;
}
+bool ArgParser::recursive() const
+{
+ return m_recursive;
+}
+
+bool ArgParser::printTree() const
+{
+ return m_printTree;
+}
+
const string& ArgParser::commandName() const
{
return m_commandName;
diff --git a/src/argparser.h b/src/argparser.h
index 1859c35..0260f06 100644
--- a/src/argparser.h
+++ b/src/argparser.h
@@ -57,6 +57,8 @@ public:
bool strictDiff() const;
bool useRegex() const;
bool fullPath() const;
+ bool recursive() const;
+ bool printTree() const;
const string& alternateConfigFile() const;
const string& pkgmkArgs() const;
@@ -107,6 +109,9 @@ private:
bool m_useRegex;
bool m_fullPath;
+ bool m_recursive;
+ bool m_printTree;
+
string m_alternateConfigFile;
string m_pkgmkArgs;
string m_pkgaddArgs;
diff --git a/src/main.cpp b/src/main.cpp
index 1af02ed..64904af 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,7 +26,7 @@ int main( int argc, char** argv )
<< endl;
} else if ( !argParser.isCommandGiven() ) {
if (argParser.commandName() != "") {
- cerr << "prt-get: Unknown command '"
+ cerr << "prt-get: Unknown command '"
<< argParser.commandName() << "'. "
<< "try prt-get help for more information" << endl;
} else {
@@ -122,7 +122,7 @@ int main( int argc, char** argv )
prtGet.readme();
break;
case ArgParser::DEPENDENT:
- prtGet.printDependendent();
+ prtGet.printDependent();
break;
case ArgParser::SYSUP:
prtGet.sysup();
diff --git a/src/prtget.cpp b/src/prtget.cpp
index 92d36d4..7d0dab4 100644
--- a/src/prtget.cpp
+++ b/src/prtget.cpp
@@ -1244,37 +1244,58 @@ bool PrtGet::printFile(const string& file)
return true;
}
-void PrtGet::printDependendent()
+void PrtGet::printDependent()
{
assertExactArgCount(1);
initRepo();
string arg = *(m_parser->otherArgs().begin());
+ printDependent(arg, 0);
+}
+
+void PrtGet::printDependent(const string& dep, int level)
+{
map<string, Package*>::const_iterator it = m_repo->packages().begin();
+ static map<string, bool> shownMap;
set<const Package*> dependent;
for ( ; it != m_repo->packages().end(); ++it ) {
// TODO: is the following line needed?
const Package* p = it->second;
- if ( p && p->dependencies().find( arg ) != string::npos ) {
+ if ( p && p->dependencies().find( dep ) != string::npos ) {
list<string> tokens;
StringHelper::split( p->dependencies(), ',', tokens );
list<string>::iterator it = find( tokens.begin(),
tokens.end(),
- arg );
+ dep );
if ( it != tokens.end() ) {
dependent.insert( p );
}
}
}
-
+
// prepared for recursive search
+ string indent = "";
+ if (m_parser->printTree()) {
+ for (int i = 0; i < level; ++i) {
+ indent += " ";
+ }
+ }
set<const Package*>::iterator it2 = dependent.begin();
for ( ; it2 != dependent.end(); ++it2 ) {
const Package* p = *it2;
+
+ if (m_parser->recursive() && !m_parser->printTree()) {
+ if (shownMap[p->name()]) {
+ continue;
+ }
+ shownMap[p->name()] = true;
+ }
+
if ( m_parser->all() || m_pkgDB->isInstalled( p->name() ) ) {
- cout << p->name();
+
+ cout << indent << p->name();
if ( m_parser->verbose() > 0 ) {
cout << " " << p->version() << "-" << p->release();
}
@@ -1283,6 +1304,10 @@ void PrtGet::printDependendent()
}
cout << endl;
+
+ if (m_parser->recursive()) {
+ printDependent( p->name(), level+2 );
+ }
}
}
}
diff --git a/src/prtget.h b/src/prtget.h
index c5ad4db..602f8c2 100644
--- a/src/prtget.h
+++ b/src/prtget.h
@@ -67,7 +67,7 @@ public:
void current();
void printDepends( bool simpleListing=false );
void printDependTree();
- void printDependendent();
+ void printDependent();
void printDiff();
void printQuickDiff();
@@ -96,6 +96,8 @@ public:
protected:
void printDepsLevel(int indent, const Package* package);
+
+ void printDependent(const std::string& dep, int level);
void executeTransaction( InstallTransaction& transaction,
bool update, bool group );
@@ -140,7 +142,7 @@ protected:
void assertMaxArgCount(int count);
void assertExactArgCount(int count);
void argCountFailure(int count, const string& specifier);
-
+
bool greaterThan( const string& v1, const string& v2 );
static bool printFile(const string& file);
};

Generated by cgit