The following commit has been merged in the master branch:
commit b4efb601b445580a3a46ce873eec3a80893dd08f
Author: Guillem Jover <[email protected]>
Date:   Fri Jul 16 14:03:41 2010 +0200

    Convert limiteddescription() to pkg_summary()
    
    Move clamping of summary size to callers. This makes the function more
    generic so that it can be reused in other contexts.

diff --git a/src/enquiry.c b/src/enquiry.c
index d8e1a4f..69e702d 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -118,7 +118,10 @@ static void describebriefly(struct pkginfo *pkg) {
   maxl= 57;
   l= strlen(pkg->name);
   if (l>20) maxl -= (l-20);
-  limiteddescription(pkg,maxl,&pdesc,&l);
+
+  pkg_summary(pkg, &pdesc, &l);
+  l = min(l, maxl);
+
   printf(" %-20s %.*s\n",pkg->name,l,pdesc);
 }
 
diff --git a/src/main.h b/src/main.h
index 17ba2d4..b17810b 100644
--- a/src/main.h
+++ b/src/main.h
@@ -171,8 +171,7 @@ void printarch(const char *const *argv);
 void printinstarch(const char *const *argv);
 void cmpversions(const char *const *argv) DPKG_ATTR_NORET;
 
-void limiteddescription(struct pkginfo *pkg,
-                        int maxl, const char **pdesc_r, int *l_r);
+void pkg_summary(struct pkginfo *pkg, const char **pdesc_ret, int *len_ret);
 
 /* from select.c */
 
diff --git a/src/pkg-show.c b/src/pkg-show.c
index c1b8789..853278e 100644
--- a/src/pkg-show.c
+++ b/src/pkg-show.c
@@ -31,19 +31,20 @@
 #include "main.h"
 
 void
-limiteddescription(struct pkginfo *pkg,
-                   int maxl, const char **pdesc_r, int *l_r)
+pkg_summary(struct pkginfo *pkg, const char **pdesc_r, int *len_ret)
 {
-       const char *pdesc, *p;
+       const char *pdesc;
+       size_t len;
 
        pdesc = pkg->installed.description;
        if (!pdesc)
                pdesc = _("(no description available)");
-       p = strchr(pdesc, '\n');
-       if (!p)
-               p = pdesc + strlen(pdesc);
 
-       *l_r = min(p - pdesc, maxl);
+       len = strcspn(pdesc, "\n");
+       if (len == 0)
+               len = strlen(pdesc);
+
+       *len_ret = len;
        *pdesc_r = pdesc;
 }
 
diff --git a/src/query.c b/src/query.c
index 7eb94e2..9783847 100644
--- a/src/query.c
+++ b/src/query.c
@@ -124,7 +124,9 @@ Desired=Unknown/Install/Remove/Purge/Hold\n\
     *head = true;
   }
 
-  limiteddescription(pkg,dw,&pdesc,&l);
+  pkg_summary(pkg, &pdesc, &l);
+  l = min(l, dw);
+
   printf(format,
          "uihrp"[pkg->want],
          "ncHUFWti"[pkg->status],

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to