Author: jkupec
Date: Thu Oct 16 18:06:11 2008
New Revision: 11379
URL: http://svn.opensuse.org/viewcvs/zypp?rev=11379&view=rev
Log:
- backup pager code
Modified:
trunk/zypper/src/misc.cc
trunk/zypper/src/utils/pager.cc
trunk/zypper/src/utils/pager.h
Modified: trunk/zypper/src/misc.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/misc.cc?rev=11379&r1=11378&r2=11379&view=diff
==============================================================================
--- trunk/zypper/src/misc.cc (original)
+++ trunk/zypper/src/misc.cc Thu Oct 16 18:06:11 2008
@@ -167,7 +167,7 @@
s << processRichText(licenseText);
// show in pager unless we are read by a machine or the pager fails
- if (zypper.globalOpts().machine_readable || !show_in_pager(s.str()))
+ if (zypper.globalOpts().machine_readable || !show_text_in_pager(s.str()))
zypper.out().info(s.str(), Out::QUIET);
// lincense prompt
Modified: trunk/zypper/src/utils/pager.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/utils/pager.cc?rev=11379&r1=11378&r2=11379&view=diff
==============================================================================
--- trunk/zypper/src/utils/pager.cc (original)
+++ trunk/zypper/src/utils/pager.cc Thu Oct 16 18:06:11 2008
@@ -10,10 +10,13 @@
#include <fstream>
#include
#include //for wait()
+#include <iterator>
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
#include "zypp/TmpPath.h"
+#include "zypp/Pathname.h"
+#include "zypp/PathInfo.h"
#include "../main.h"
@@ -22,7 +25,9 @@
using namespace std;
using namespace zypp;
-string pager_help_exit(const string & pager)
+// ---------------------------------------------------------------------------
+
+static string pager_help_exit(const string & pager)
{
string endfour = pager.substr(pager.size()-4,4);
if (endfour == "less")
@@ -32,7 +37,9 @@
return string();
}
-string pager_help_navigation(const string & pager)
+// ---------------------------------------------------------------------------
+
+static string pager_help_navigation(const string & pager)
{
string endfour = pager.substr(pager.size()-4,4);
if (endfour == "less")
@@ -46,46 +53,108 @@
return string();
}
-//gets true if successfully display in pager
-bool show_in_pager(const string & text)
+// ---------------------------------------------------------------------------
+
+static bool show_in_pager(const string & pager, const Pathname & file)
+{
+ ostringstream cmdline;
+ cmdline << "'" << pager << "' '" << file << "'";
+
+ switch(fork())
+ {
+ case -1:
+ WAR << "fork failed" << endl;
+ return false;
+
+ case 0:
+ execlp("sh","sh","-c",cmdline.str().c_str(),(char *)0);
+ WAR << "exec failed with " << strerror(errno) << endl;
+ exit(1); // cannot return false here, because here is another process
+ // so only kill myself
+ //! \todo FIXME proper exit code, message?
+
+ default:
+ wait(0); //wait until pager end to disallow possibly terminal collision
+ }
+
+ return true;
+}
+
+// ---------------------------------------------------------------------------
+
+bool show_text_in_pager(const string & text, const string & intro)
{
const char* envpager = getenv("PAGER");
if (!envpager)
- envpager="more"; //basic posix default, must be in PATH
+ envpager = "more"; // basic posix default, must be in PATH
string pager(envpager);
+
filesystem::TmpFile tfile;
- string tpath = tfile.path().absolutename().c_str();
+ string tpath = tfile.path().absolutename().asString();
ofstream os(tpath.c_str());
+ // intro
+ if (!intro.empty())
+ os << intro << endl;
+
+ // navigaion hint
string help = pager_help_navigation(pager);
if (!help.empty())
os << "(" << help << ")" << endl << endl;
+
+ // the text
os << text;
+ // exit hint
help = pager_help_exit(pager);
if (!help.empty())
os << endl << endl << "(" << help << ")";
os.close();
- ostringstream cmdline;
- cmdline << pager <<" "<http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/utils/pager.h?rev=11379&r1=11378&r2=11379&view=diff
==============================================================================
--- trunk/zypper/src/utils/pager.h (original)
+++ trunk/zypper/src/utils/pager.h Thu Oct 16 18:06:11 2008
@@ -10,6 +10,29 @@
#include <string>
-bool show_in_pager(const std::string & text);
+namespace zypp
+{
+ class Pathname;
+}
+
+/**
+ * Opens $PAGER with given \a text. If $PAGER is not set, uses 'more' as
+ * a fallback.
+ *
+ * \param text Text to show.
+ * \param intro Explanatory note to show at the start of the text.
+ * \return true if there was no problem opening the pager
+ */
+bool show_text_in_pager(const std::string & text, const std::string & intro = "");
+
+/**
+ * Opens $PAGER with given \a file. If $PAGER is not set, uses 'more' as
+ * a fallback.
+ *
+ * \param file File to show.
+ * \param intro Explanatory note to show at the start of the text.
+ * \return true if there was no problem opening the pager
+ */
+bool show_file_in_pager(const zypp::Pathname & file, const std::string & intro = "");
#endif /*PAGER_H_*/
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org