]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-output.cc
apt-private/private-output.cc: fix cppcheck output
[apt.git] / apt-private / private-output.cc
index bbd8545ad1cc1c979ee510b42b213d605cfd41a0..8f190a5516f2ab24833d0f12064fe5e5b2d82611 100644 (file)
@@ -22,6 +22,8 @@
 #include <iostream>
 #include <langinfo.h>
 #include <unistd.h>
+#include <signal.h>
+#include <sys/ioctl.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -32,8 +34,24 @@ std::ostream c0out(0);
 std::ostream c1out(0);
 std::ostream c2out(0);
 std::ofstream devnull("/dev/null");
+
+
 unsigned int ScreenWidth = 80 - 1; /* - 1 for the cursor */
 
+// SigWinch - Window size change signal handler                                /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+static void SigWinch(int)
+{
+   // Riped from GNU ls
+#ifdef TIOCGWINSZ
+   struct winsize ws;
+  
+   if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col >= 5)
+      ScreenWidth = ws.ws_col - 1;
+#endif
+}
+                                                                       /*}}}*/
 bool InitOutput()                                                      /*{{{*/
 {
    if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
@@ -47,6 +65,10 @@ bool InitOutput()                                                    /*{{{*/
    if (_config->FindI("quiet",0) > 1)
       c1out.rdbuf(devnull.rdbuf());
 
+   // deal with window size changes
+   signal(SIGWINCH,SigWinch);
+   SigWinch(0);
+
    if(!isatty(1))
    {
       _config->Set("APT::Color", "false");
@@ -72,7 +94,7 @@ bool InitOutput()                                                     /*{{{*/
 static std::string GetArchiveSuite(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator ver) /*{{{*/
 {
    std::string suite = "";
-   if (ver && ver.FileList() && ver.FileList())
+   if (ver && ver.FileList())
    {
       pkgCache::VerFileIterator VF = ver.FileList();
       for (; VF.end() == false ; ++VF)
@@ -146,6 +168,10 @@ static std::string GetArchitecture(pkgCacheFile &CacheFile, pkgCache::PkgIterato
    pkgCache::VerIterator inst = P.CurrentVer();
    pkgCache::VerIterator cand = policy->GetCandidateVer(P);
 
+   // this may happen for packages in dpkg "deinstall ok config-file" state
+   if (inst.IsGood() == false && cand.IsGood() == false)
+      return P.VersionList().Arch();
+
    return inst ? inst.Arch() : cand.Arch();
 }
                                                                        /*}}}*/