]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-utils.cc
call dpkg with --no-triggers by default
[apt.git] / apt-private / private-utils.cc
index 813f193294d051e7c9f2e5fce079707943baa9d3..775bf7e799331e3d287f476474531793c26b5539 100644 (file)
@@ -1,50 +1,76 @@
-#include <cstdlib>
+#include <config.h>
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
-#include "private-utils.h"
 
 
+#include <apt-private/private-utils.h>
 
 
-// DisplayFileInPager - Display File with pager                                /*{{{*/
-void DisplayFileInPager(std::string filename)
-{
-   std::string pager = _config->Find("Dir::Bin::Pager", 
-                                        "/usr/bin/sensible-pager");
+#include <cstdlib>
+#include <unistd.h>
 
 
+// DisplayFileInPager - Display File with pager                                /*{{{*/
+bool DisplayFileInPager(std::string const &filename)
+{
    pid_t Process = ExecFork();
    if (Process == 0)
    {
       const char *Args[3];
    pid_t Process = ExecFork();
    if (Process == 0)
    {
       const char *Args[3];
-      Args[0] = pager.c_str();
       Args[1] = filename.c_str();
       Args[1] = filename.c_str();
-      Args[2] = 0;
+      Args[2] = NULL;
+      if (isatty(STDOUT_FILENO) == 1)
+      {
+        // likely installed, provided by sensible-utils
+        std::string const pager = _config->Find("Dir::Bin::Pager",
+              "sensible-pager");
+        Args[0] = pager.c_str();
+        execvp(Args[0],(char **)Args);
+        // lets try some obvious alternatives
+        Args[0] = getenv("PAGER");
+        if (Args[0] != NULL)
+           execvp(Args[0],(char **)Args);
+
+        Args[0] = "pager";
+        execvp(Args[0],(char **)Args);
+      }
+      // we could read the file ourselves, but… meh
+      Args[0] = "cat";
       execvp(Args[0],(char **)Args);
       exit(100);
    }
       execvp(Args[0],(char **)Args);
       exit(100);
    }
-         
+
    // Wait for the subprocess
    // Wait for the subprocess
-   ExecWait(Process, "sensible-pager", false);
+   return ExecWait(Process, "pager", false);
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/
-
-// EditFileInSensibleEditor - Edit File with editor                            /*{{{*/
-void EditFileInSensibleEditor(std::string filename)
+// EditFileInSensibleEditor - Edit File with editor                    /*{{{*/
+bool EditFileInSensibleEditor(std::string const &filename)
 {
 {
-   std::string editor = _config->Find("Dir::Bin::Editor", 
-                                        "/usr/bin/sensible-editor");
-
    pid_t Process = ExecFork();
    if (Process == 0)
    {
    pid_t Process = ExecFork();
    if (Process == 0)
    {
+      // likely installed, provided by sensible-utils
+      std::string const editor = _config->Find("Dir::Bin::Editor",
+           "sensible-editor");
       const char *Args[3];
       Args[0] = editor.c_str();
       Args[1] = filename.c_str();
       const char *Args[3];
       Args[0] = editor.c_str();
       Args[1] = filename.c_str();
-      Args[2] = 0;
+      Args[2] = NULL;
+      execvp(Args[0],(char **)Args);
+      // the usual suspects we can try as an alternative
+      Args[0] = getenv("VISUAL");
+      if (Args[0] != NULL)
+        execvp(Args[0],(char **)Args);
+
+      Args[0] = getenv("EDITOR");
+      if (Args[0] != NULL)
+        execvp(Args[0],(char **)Args);
+
+      Args[0] = "editor";
       execvp(Args[0],(char **)Args);
       exit(100);
    }
       execvp(Args[0],(char **)Args);
       exit(100);
    }
-         
+
    // Wait for the subprocess
    // Wait for the subprocess
-   ExecWait(Process, "sensible-editor", false);
+   return ExecWait(Process, "editor", false);
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/