r1142 - in tools/prt-get/trunk: . doc src
Author: jw Date: 2006-04-04 22:12:42 +0200 (Tue, 04 Apr 2006) New Revision: 1142 Modified: tools/prt-get/trunk/ChangeLog tools/prt-get/trunk/doc/prt-get.8 tools/prt-get/trunk/src/prtget.cpp tools/prt-get/trunk/src/prtget.h Log: prt-get: if set, use $PAGER for 'cat' and 'readme' Modified: tools/prt-get/trunk/ChangeLog =================================================================== --- tools/prt-get/trunk/ChangeLog 2006-04-04 18:50:25 UTC (rev 1141) +++ tools/prt-get/trunk/ChangeLog 2006-04-04 20:12:42 UTC (rev 1142) @@ -7,6 +7,7 @@ - allow to remove log files of successful builds - print update summary right before running the addcommand - print full add command and PACKAGE_DIR info when using install/update -v +- Make 'cat' and 'readme' use $PAGER if set * 0.5.11 29.05.2005 Johannes Winkelmann - add --path to 'ls' Modified: tools/prt-get/trunk/doc/prt-get.8 =================================================================== --- tools/prt-get/trunk/doc/prt-get.8 2006-04-04 18:50:25 UTC (rev 1141) +++ tools/prt-get/trunk/doc/prt-get.8 2006-04-04 20:12:42 UTC (rev 1142) @@ -190,7 +190,7 @@ .TP .B readme <port> -Print the port's README file if it exists +Print the port's README file if it exists; if set, uses $PAGER .TP .B depends <package1> [<package2> ...] @@ -339,7 +339,7 @@ .TP .B cat <package> [<file>] -Prints out the file to stdout. If <file> is not specified, 'Pkgfile' is used +Prints out the file to stdout. If <file> is not specified, 'Pkgfile' is used. If set, uses $PAGER .TP .B edit <package> <file> Modified: tools/prt-get/trunk/src/prtget.cpp =================================================================== --- tools/prt-get/trunk/src/prtget.cpp 2006-04-04 18:50:25 UTC (rev 1141) +++ tools/prt-get/trunk/src/prtget.cpp 2006-04-04 20:12:42 UTC (rev 1142) @@ -1212,6 +1212,25 @@ 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 @@ } 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 @@ 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; Modified: tools/prt-get/trunk/src/prtget.h =================================================================== --- tools/prt-get/trunk/src/prtget.h 2006-04-04 18:50:25 UTC (rev 1141) +++ tools/prt-get/trunk/src/prtget.h 2006-04-04 20:12:42 UTC (rev 1142) @@ -128,7 +128,7 @@ string m_cacheFile; int m_returnValue; - + bool m_useRegex; /*! Name of default configuration file */ @@ -142,7 +142,8 @@ void assertMaxArgCount(int count); void assertExactArgCount(int count); void argCountFailure(int count, const string& specifier); - + + static bool printFile(const string& file); }; #endif /* _PRTGET_H_ */
participants (1)
-
crux@crux.nu