The following commit has been merged in the master branch:
commit f426b031ac858fa30ace69959a43b61fb40f4be9
Author: Guillem Jover <[email protected]>
Date:   Wed Feb 10 02:13:30 2010 +0100

    dselect: Use max/min instead of lesserint/greaterint

diff --git a/TODO b/TODO
index 84693f7..cf7528e 100644
--- a/TODO
+++ b/TODO
@@ -45,7 +45,6 @@ TODO
    - Use internerr instead of assert, and print more meaninful messages.
    - Make actionfunction return int, and avoid global exitcode variables.
    - Move ACTION and OBSOLETE, etc to ‘myopt.h’.
-   - Use max/min in dselect instead of lesserint/greaterint.
    - Refactor packageslump into generic code.
    - Refactor subprocess execution (argument building etc).
    - Replace raw write and read calls with safe variants (signals etc).
diff --git a/dselect/basecmds.cc b/dselect/basecmds.cc
index b4d4d60..ed172d9 100644
--- a/dselect/basecmds.cc
+++ b/dselect/basecmds.cc
@@ -72,7 +72,7 @@ void baselist::kd_top() {
 void baselist::kd_bottom() {
   topofscreen= nitems - list_height;
   if (topofscreen < 0) topofscreen= 0;
-  setcursor(lesserint(topofscreen + list_height - 1, nitems-1));
+  setcursor(min(topofscreen + list_height - 1, nitems - 1));
 }
 
 void baselist::kd_redraw() {
diff --git a/dselect/baselist.cc b/dselect/baselist.cc
index 81accf5..68904fc 100644
--- a/dselect/baselist.cc
+++ b/dselect/baselist.cc
@@ -281,7 +281,7 @@ void baselist::dosearch() {
   int offset, index;
   if (debug) fprintf(debug,"baselist[%p]::dosearch(); searchstring=`%s'\n",
                      this,searchstring);
-  for (offset=1, index=greaterint(topofscreen,cursorline+1);
+  for (offset = 1, index = max(topofscreen, cursorline + 1);
        offset<nitems;
        offset++, index++) {
     if (index >= nitems) index -= nitems;
@@ -298,8 +298,8 @@ void baselist::dosearch() {
 
 void baselist::refreshinfo() {
   pnoutrefresh(infopad, infotopofscreen,leftofscreen, info_row,0,
-               lesserint(info_row + info_height - 1, info_row + 
MAX_DISPLAY_INFO - 1),
-               lesserint(total_width - leftofscreen - 1, xmax - 1));
+               min(info_row + info_height - 1, info_row + MAX_DISPLAY_INFO - 
1),
+               min(total_width - leftofscreen - 1, xmax - 1));
   
   if (whatinfo_height) {
     mywerase(whatinfowin);
diff --git a/dselect/basetop.cc b/dselect/basetop.cc
index 0b5f521..801d002 100644
--- a/dselect/basetop.cc
+++ b/dselect/basetop.cc
@@ -26,12 +26,10 @@
 #include "dselect.h"
 
 void baselist::refreshlist() {
-  redrawitemsrange(topofscreen,lesserint(nitems,topofscreen+list_height));
+  redrawitemsrange(topofscreen, min(nitems, topofscreen + list_height));
   int y, x, maxy, maxx;
-  y= lesserint(list_row + list_height - 1,
-               list_row + nitems - topofscreen - 1);
-  x= lesserint(total_width - leftofscreen - 1,
-               xmax - 1);
+  y = min(list_row + list_height - 1, list_row + nitems - topofscreen - 1);
+  x = min(total_width - leftofscreen - 1, xmax - 1);
   pnoutrefresh(listpad, 0, leftofscreen, list_row, 0, y, x);
   getmaxyx(listpad,maxy,maxx);
   y++;
@@ -50,5 +48,5 @@ void baselist::redrawitemsrange(int start, int end) {
 
 void baselist::refreshcolheads() {
   pnoutrefresh(colheadspad, 0,leftofscreen, colheads_row,0,
-               colheads_row, lesserint(total_width - leftofscreen - 1, xmax - 
1));
+               colheads_row, min(total_width - leftofscreen - 1, xmax - 1));
 }
diff --git a/dselect/dselect.h b/dselect/dselect.h
index 5513d61..92ff6ea 100644
--- a/dselect/dselect.h
+++ b/dselect/dselect.h
@@ -134,9 +134,6 @@ public:
   virtual ~baselist();
 };
 
-static inline int lesserint(int a, int b) { return a<b ? a : b; }
-static inline int greaterint(int a, int b) { return a>b ? a : b; }
-
 void displayhelp(const struct helpmenuentry *menu, int key);
 
 void mywerase(WINDOW *win);
diff --git a/dselect/methlist.cc b/dselect/methlist.cc
index 1c82c1d..e83ff94 100644
--- a/dselect/methlist.cc
+++ b/dselect/methlist.cc
@@ -86,7 +86,7 @@ void methodlist::redrawthisstate() {
           _("Access method `%s'."),
           table[cursorline]->name);
   pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
-               thisstate_row, lesserint(total_width - 1, xmax - 1));
+               thisstate_row, min(total_width - 1, xmax - 1));
 }
 
 void methodlist::redraw1itemsel(int index, int selected) {
diff --git a/dselect/pkgcmds.cc b/dselect/pkgcmds.cc
index efd7842..26332a9 100644
--- a/dselect/pkgcmds.cc
+++ b/dselect/pkgcmds.cc
@@ -215,7 +215,7 @@ void packagelist::kd_versiondisplay() {
   ldrawnstart= ldrawnend= -1;
   redrawtitle();
   redrawcolheads();
-  redrawitemsrange(topofscreen,lesserint(topofscreen+list_height,nitems));
+  redrawitemsrange(topofscreen, min(topofscreen + list_height, nitems));
   refreshlist();
 }
 
@@ -226,7 +226,7 @@ void packagelist::kd_verbose() {
   ldrawnstart= ldrawnend= -1;
   redrawtitle();
   redrawcolheads();
-  redrawitemsrange(topofscreen,lesserint(topofscreen+list_height,nitems));
+  redrawitemsrange(topofscreen, min(topofscreen + list_height, nitems));
   refreshlist();
 }
 
diff --git a/dselect/pkgdepcon.cc b/dselect/pkgdepcon.cc
index 542b5df..0817b55 100644
--- a/dselect/pkgdepcon.cc
+++ b/dselect/pkgdepcon.cc
@@ -61,13 +61,13 @@ int packagelist::checkdependers(pkginfo *pkg, int 
changemade) {
   if (pkg->available.valid) {
     for (possi= pkg->available.depended; possi; possi= possi->nextrev) {
       if (!useavailable(possi->up->up)) continue;
-      changemade= greaterint(changemade,resolvedepcon(possi->up));
+      changemade = max(changemade, resolvedepcon(possi->up));
     }
   }
   if (pkg->installed.valid) {
     for (possi= pkg->installed.depended; possi; possi= possi->nextrev) {
       if (useavailable(possi->up->up)) continue;
-      changemade= greaterint(changemade,resolvedepcon(possi->up));
+      changemade = max(changemade, resolvedepcon(possi->up));
     }
   }
   return changemade;
@@ -94,7 +94,7 @@ int packagelist::resolvesuggest() {
       for (depends= findinfo(table[index]->pkg)->depends;
            depends;
            depends= depends->next) {
-        changemade= greaterint(changemade,resolvedepcon(depends));
+        changemade = max(changemade, resolvedepcon(depends));
       }
       changemade= checkdependers(table[index]->pkg,changemade);
       for (depends= findinfo(table[index]->pkg)->depends;
@@ -108,7 +108,7 @@ int packagelist::resolvesuggest() {
                 this, index, table[index]->pkg->name, changemade);
     }
     if (!changemade) break;
-    maxchangemade= greaterint(maxchangemade, changemade);
+    maxchangemade = max(maxchangemade, changemade);
   }
   if (debug)
     fprintf(debug,"packagelist[%p]::resolvesuggest() done; maxchangemade=%d\n",
diff --git a/dselect/pkgtop.cc b/dselect/pkgtop.cc
index b5ff386..826877c 100644
--- a/dselect/pkgtop.cc
+++ b/dselect/pkgtop.cc
@@ -108,10 +108,10 @@ void packagelist::redrawthisstate() {
   const char *section= table[cursorline]->pkg->section;
   const char *priority= pkgprioritystring(table[cursorline]->pkg);
   char *buf= new char[500+
-                      greaterint((table[cursorline]->pkg->name
-                                  ? strlen(table[cursorline]->pkg->name) : 0),
-                                 (section ? strlen(section) : 0) +
-                                 (priority ? strlen(priority) : 0))];
+                      max((table[cursorline]->pkg->name ?
+                           strlen(table[cursorline]->pkg->name) : 0),
+                          (section ? strlen(section) : 0) +
+                          (priority ? strlen(priority) : 0))];
     
   if (table[cursorline]->pkg->name) {
     sprintf(buf,
@@ -130,7 +130,7 @@ void packagelist::redrawthisstate() {
   }
   mvwaddnstr(thisstatepad,0,0, buf, total_width);
   pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
-               thisstate_row, lesserint(total_width - 1, xmax - 1));
+               thisstate_row, min(total_width - 1, xmax - 1));
 
   delete[] buf;
 }

-- 
dpkg's main repository


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

Reply via email to