diff options
author | Johannes Winkelmann <jw@smts.ch> | 2006-04-04 20:12:42 +0000 |
---|---|---|
committer | Johannes Winkelmann <jw@smts.ch> | 2006-04-04 20:12:42 +0000 |
commit | 5c03d74720d53e93e1f2221d9014e62c189dcded (patch) | |
tree | 38819bd2571726e2abadf3593ac06e2f91ffce37 /src | |
parent | e4d5098bb00064b3f4e8bc32c956ccb9996f3faa (diff) | |
download | prt-get-5c03d74720d53e93e1f2221d9014e62c189dcded.tar.gz prt-get-5c03d74720d53e93e1f2221d9014e62c189dcded.tar.xz |
prt-get: if set, use $PAGER for 'cat' and 'readme'
git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1142 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
Diffstat (limited to 'src')
-rw-r--r-- | src/prtget.cpp | 37 | ||||
-rw-r--r-- | src/prtget.h | 5 |
2 files changed, 25 insertions, 17 deletions
diff --git a/src/prtget.cpp b/src/prtget.cpp index e66cfd0..9deb26b 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -1212,6 +1212,25 @@ void PrtGet::readme() const Package* p = m_repo->getPackage( arg ); if ( p ) { string file = p->path() + "/" + p->name() + "/README"; + printFile(file); + } else { + cerr << "Package '" << arg << "' not found" << endl; + m_returnValue = PG_GENERAL_ERROR; + return; + } +} + +bool PrtGet::printFile(const string& file) +{ + if (!File::fileExists(file)) { + return false; + } + + char* pager = getenv("PAGER"); + if (pager) { + Process proc(pager, file); + proc.executeShell(); + } else { FILE* fp = fopen( file.c_str(), "r" ); char buf[255]; if ( fp ) { @@ -1220,15 +1239,11 @@ void PrtGet::readme() } fclose( fp ); } - - } else { - cerr << "Package '" << arg << "' not found" << endl; - m_returnValue = PG_GENERAL_ERROR; - return; } + + return true; } - void PrtGet::printDependendent() { assertExactArgCount(1); @@ -1623,19 +1638,11 @@ void PrtGet::cat() fileName = *it; } string file = p->path() + "/" + p->name() + "/" + fileName; - FILE* fp = fopen( file.c_str(), "r" ); - char buf[255]; - if ( fp ) { - while ( fgets( buf, 255, fp ) ) { - cout << buf; - } - fclose( fp ); - } else { + if (!printFile(file)) { cerr << "File '" << *it << "' not found" << endl; m_returnValue = PG_GENERAL_ERROR; return; } - } else { cerr << "Package '" << arg << "' not found" << endl; m_returnValue = PG_GENERAL_ERROR; diff --git a/src/prtget.h b/src/prtget.h index 1b93fbb..2a27c21 100644 --- a/src/prtget.h +++ b/src/prtget.h @@ -128,7 +128,7 @@ protected: string m_cacheFile; int m_returnValue; - + bool m_useRegex; /*! Name of default configuration file */ @@ -142,7 +142,8 @@ protected: void assertMaxArgCount(int count); void assertExactArgCount(int count); void argCountFailure(int count, const string& specifier); - + + static bool printFile(const string& file); }; #endif /* _PRTGET_H_ */ |