Forráskód Böngészése

Switch variables from int to bool where appropriate

Guillem Jover 12 éve
szülő
commit
cf21cccb98

+ 7 - 5
dselect/baselist.cc

@@ -313,7 +313,8 @@ void baselist::refreshinfo() {
 void baselist::wordwrapinfo(int offset, const char *m) {
   int usemax= xmax-5;
   debug(dbg_general, "baselist[%p]::wordwrapinfo(%d, '%s')", this, offset, m);
-  int wrapping=0;
+  bool wrapping = false;
+
   for (;;) {
     int offleft=offset; while (*m == ' ' && offleft>0) { m++; offleft--; }
     const char *p= strchr(m,'\n');
@@ -321,12 +322,13 @@ void baselist::wordwrapinfo(int offset, const char *m) {
     while (l && isspace(m[l-1])) l--;
     if (!l || (*m == '.' && l == 1)) {
       if (wrapping) waddch(infopad,'\n');
-      waddch(infopad,'\n');
-      wrapping= 0;
+      waddch(infopad, '\n');
+      wrapping = false;
     } else if (*m == ' ' || usemax < 10) {
       if (wrapping) waddch(infopad,'\n');
       waddnstr(infopad, m, l);
-      waddch(infopad,'\n'); wrapping= 0;
+      waddch(infopad, '\n');
+      wrapping = false;
     } else {
       int x, y DPKG_ATTR_UNUSED;
 
@@ -354,7 +356,7 @@ void baselist::wordwrapinfo(int offset, const char *m) {
         if (l <= 0) break;
         waddch(infopad,'\n');
       }
-      wrapping= 1;
+      wrapping = false;
     }
     if (!p) break;
     if (getcury(infopad) == (MAX_DISPLAY_INFO - 1)) {

+ 2 - 2
dselect/dselect.h

@@ -163,7 +163,7 @@ void mywerase(WINDOW *win);
 void curseson();
 void cursesoff();
 
-extern int expertmode;
+extern bool expertmode;
 
 struct colordata {
        int fore;
@@ -173,7 +173,7 @@ struct colordata {
 extern colordata color[];
 
 /* Evil recommends flag variable. */
-extern int manual_install;
+extern bool manual_install;
 
 enum urqresult { urqr_normal, urqr_fail, urqr_quitmenu };
 enum quitaction { qa_noquit, qa_quitchecksave, qa_quitnochecksave };

+ 5 - 5
dselect/main.cc

@@ -62,7 +62,7 @@
 
 static const char printforhelp[] = N_("Type dselect --help for help.");
 
-int expertmode= 0;
+bool expertmode = false;
 
 static const char *admindir = ADMINDIR;
 
@@ -239,7 +239,7 @@ extern "C" {
   static void
   set_expert(const struct cmdinfo*, const char *v)
   {
-    expertmode= 1;
+    expertmode = true;
   }
 
   static int
@@ -319,7 +319,7 @@ static const struct cmdinfo cmdinfos[]= {
   { 0,              0,   0,  0,  0,          0               }
 };
 
-static int cursesareon= 0;
+static bool cursesareon = false;
 void curseson() {
   if (!cursesareon) {
     const char *cup, *smso;
@@ -339,7 +339,7 @@ void curseson() {
       ohshit(_("terminal lacks necessary features, giving up"));
     }
   }
-  cursesareon= 1;
+  cursesareon = true;
 }
 
 void cursesoff() {
@@ -348,7 +348,7 @@ void cursesoff() {
     refresh();
     endwin();
   }
-  cursesareon=0;
+  cursesareon = false;
 }
 
 extern void *operator new(size_t size) {

+ 3 - 3
dselect/pkgcmds.cc

@@ -133,12 +133,12 @@ void packagelist::setwant(pkginfo::pkgwant nwarg) {
   movecursorafter(bot);
 }
 
-int manual_install = 0;
+bool manual_install = false;
 
 void packagelist::kd_select()   {
-	manual_install = 1;
+	manual_install = true;
 	setwant(pkginfo::want_install);
-	manual_install = 0;
+	manual_install = false;
 }
 void packagelist::kd_hold()     { setwant(pkginfo::want_hold);      }
 void packagelist::kd_deselect() { setwant(pkginfo::want_deinstall); }

+ 21 - 12
dselect/pkgdepcon.cc

@@ -114,9 +114,12 @@ int packagelist::resolvesuggest() {
   return maxchangemade;
 }
 
-static int dep_update_best_to_change_stop(perpackagestate *& best, pkginfo *trythis) {
+static bool
+dep_update_best_to_change_stop(perpackagestate *& best, pkginfo *trythis)
+{
   // There's no point trying to select a pure virtual package.
-  if (!trythis->clientdata) return 0;
+  if (!trythis->clientdata)
+    return false;
 
   debug(dbg_depcon, "update_best_to_change(best=%s{%d}, test=%s{%d});",
         best ? pkg_name(best->pkg, pnaw_always) : "",
@@ -125,7 +128,8 @@ static int dep_update_best_to_change_stop(perpackagestate *& best, pkginfo *tryt
 
   // If the problem is caused by us deselecting one of these packages
   // we should not try to select another one instead.
-  if (trythis->clientdata->spriority == sp_deselecting) return 1;
+  if (trythis->clientdata->spriority == sp_deselecting)
+    return true;
 
   // If we haven't found anything yet then this is our best so far.
   if (!best) goto yes;
@@ -133,27 +137,30 @@ static int dep_update_best_to_change_stop(perpackagestate *& best, pkginfo *tryt
   // If only one of the packages is available, use that one
   if (!pkg_is_informative(trythis, &trythis->available) &&
       pkg_is_informative(best->pkg, &best->pkg->available))
-    return 0;
+    return false;
   if (pkg_is_informative(trythis, &trythis->available) &&
       !pkg_is_informative(best->pkg, &best->pkg->available))
     goto yes;
 
   // Select the package with the lowest priority (ie, the one of whom
   // we were least sure we wanted it deselected).
-  if (trythis->clientdata->spriority > best->spriority) return 0;
+  if (trythis->clientdata->spriority > best->spriority)
+    return false;
   if (trythis->clientdata->spriority < best->spriority) goto yes;
 
   // Pick the package with the must fundamental recommendation level.
-  if (trythis->priority > best->pkg->priority) return 0;
+  if (trythis->priority > best->pkg->priority)
+    return false;
   if (trythis->priority < best->pkg->priority) goto yes;
 
   // If we're still unsure we'll change the first one in the list.
-  return 0;
+  return false;
 
  yes:
   debug(dbg_depcon, "update_best_to_change(); yes");
 
-  best=trythis->clientdata; return 0;
+  best = trythis->clientdata;
+  return false;
 }
 
 int
@@ -207,7 +214,8 @@ packagelist::deselect_one_of(pkginfo *per, pkginfo *ped, dependency *dep)
 int packagelist::resolvedepcon(dependency *depends) {
   perpackagestate *best, *fixbyupgrade;
   deppossi *possi, *provider;
-  int r, foundany;
+  bool foundany;
+  int r;
 
   if (debug_has_flag(dbg_depcon)) {
     varbuf pkg_names;
@@ -273,16 +281,17 @@ int packagelist::resolvedepcon(dependency *depends) {
       for (possi= depends->list;
            possi;
            possi= possi->next) {
-        foundany= 0;
+        foundany = false;
         if (possi->ed->pkg.clientdata)
-          foundany = 1;
+          foundany = true;
         if (dep_update_best_to_change_stop(best, &possi->ed->pkg))
           goto mustdeselect;
         for (provider = possi->ed->depended.available;
              provider;
              provider = provider->rev_next) {
           if (provider->up->type != dep_provides) continue;
-          if (provider->up->up->clientdata) foundany= 1;
+          if (provider->up->up->clientdata)
+            foundany = true;
           if (dep_update_best_to_change_stop(best, provider->up->up)) goto mustdeselect;
         }
         if (!foundany) addunavailable(possi);

+ 5 - 1
dselect/pkginfo.cc

@@ -63,7 +63,11 @@ const struct helpmenuentry *packagelist::helpmenulist() {
                  recur;
 }
 
-int packagelist::itr_recursive() { return recursive; }
+bool
+packagelist::itr_recursive()
+{
+  return recursive;
+}
 
 const packagelist::infotype packagelist::infoinfos[]= {
   { &packagelist::itr_recursive,     &packagelist::itd_relations         },

+ 12 - 10
dselect/pkglist.cc

@@ -221,7 +221,7 @@ void packagelist::ensurestatsortinfo() {
             "packagelist[%p]::ensurestatsortinfos() i=%d ssavail=%d",
             this, index, table[index]->ssavail);
     }
-    calcssadone= 1;
+    calcssadone = true;
     break;
   case sso_state:
     debug(dbg_general, "packagelist[%p]::ensurestatsortinfos() calcsssdone=%d",
@@ -254,7 +254,7 @@ void packagelist::ensurestatsortinfo() {
             "packagelist[%p]::ensurestatsortinfos() i=%d ssstate=%d",
             this, index, table[index]->ssstate);
     }
-    calcsssdone= 1;
+    calcsssdone = true;
     break;
   default:
     internerr("unknown statsortorder %d", statsortorder);
@@ -366,9 +366,9 @@ void packagelist::initialsetup() {
   unavdone= 0;
   currentinfo= 0;
   headings= 0;
-  verbose= 0;
-  calcssadone= calcsssdone= 0;
-  searchdescr= 0;
+  verbose = false;
+  calcssadone = calcsssdone = false;
+  searchdescr = false;
 }
 
 void packagelist::finalsetup() {
@@ -420,7 +420,7 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) {
 
   if (!nitems)
     ohshit(_("there are no packages"));
-  recursive= 0;
+  recursive = false;
   sortorder= so_priority;
   statsortorder= sso_avail;
   versiondisplayopt= vdo_both;
@@ -432,7 +432,7 @@ packagelist::packagelist(keybindings *kb, pkginfo **pkgltab) : baselist(kb) {
   // takes over responsibility for pkgltab (recursive)
   initialsetup();
 
-  recursive= 1;
+  recursive = true;
   nitems= 0;
   if (pkgltab) {
     add(pkgltab);
@@ -445,7 +445,9 @@ packagelist::packagelist(keybindings *kb, pkginfo **pkgltab) : baselist(kb) {
   finalsetup();
 }
 
-void perpackagestate::free(int recursive) {
+void
+perpackagestate::free(bool recursive)
+{
   if (pkg->set->name) {
     if (modstatdb_get_status() == msdbrw_write) {
       if (uprec) {
@@ -496,7 +498,7 @@ packagelist::checksearch(char *rx)
   if (str_is_unset(rx))
     return false;
 
-  searchdescr=0;
+  searchdescr = false;
   if (searchstring[0]) {
     regfree(&searchfsm);
     searchstring[0]=0;
@@ -518,7 +520,7 @@ packagelist::checksearch(char *rx)
      if (rx[r]=='i')
        opt|=REG_ICASE;
      else if (rx[r]=='d')
-       searchdescr=1;
+       searchdescr = true;
      r++;
    }
   }

+ 8 - 7
dselect/pkglist.h

@@ -81,7 +81,7 @@ struct perpackagestate {
   ssstateval ssstate;
   varbuf relations;
 
-  void free(int recursive);
+  void free(bool recursive);
 };
 
 class packagelist : public baselist {
@@ -99,27 +99,28 @@ protected:
   struct perpackagestate **table;
 
   // Misc.
-  int recursive, nallocated, verbose;
+  int nallocated;
+  bool recursive, verbose;
   enum { so_unsorted, so_section, so_priority, so_alpha } sortorder;
   enum { sso_unsorted, sso_avail, sso_state } statsortorder;
   enum { vdo_none, vdo_available, vdo_both } versiondisplayopt;
-  int calcssadone, calcsssdone;
+  bool calcssadone, calcsssdone;
   struct perpackagestate *headings;
 
   // Package searching flags
-  int searchdescr;
+  bool searchdescr;
   regex_t searchfsm;
 
   // Information displays
   struct infotype {
-    int (packagelist::*relevant)(); // null means always relevant
+    bool (packagelist::*relevant)(); // null means always relevant
     void (packagelist::*display)(); // null means end of table
   };
   const infotype *currentinfo;
   static const infotype infoinfos[];
   static const infotype *const baseinfo;
-  int itr_recursive();
-  int itr_nonrecursive();
+  bool itr_recursive();
+  bool itr_nonrecursive();
   void severalinfoblurb();
   void itd_mainwelcome();
   void itd_explaindisplay();

+ 2 - 1
dselect/pkgsublist.cc

@@ -183,7 +183,8 @@ void repeatedlydisplay(packagelist *sub,
     debug(dbg_general, "repeatedlydisplay(packagelist[%p]) once", sub);
     if (unredisplay) unredisplay->enddisplay();
     for (;;) {
-      manual_install = 0; /* Remove flag now that resolvesuggest has seen it. */
+      /* Reset manual_install flag now that resolvesuggest() has seen it. */
+      manual_install = false;
       newl= sub->display();
       if (!newl) break;
       debug(dbg_general, "repeatedlydisplay(packagelist[%p]) newl", sub);

+ 9 - 9
utils/start-stop-daemon.c

@@ -156,12 +156,12 @@ enum action_code {
 };
 
 static enum action_code action;
-static int testmode = 0;
+static bool testmode = false;
 static int quietmode = 0;
 static int exitnodo = 1;
-static int background = 0;
-static int close_io = 1;
-static int mpidfile = 0;
+static bool background = false;
+static bool close_io = true;
+static bool mpidfile = false;
 static int signal_nr = SIGTERM;
 static int user_id = -1;
 static int runas_uid = -1;
@@ -866,13 +866,13 @@ parse_options(int argc, char * const *argv)
 			pidfile = optarg;
 			break;
 		case 'q':  /* --quiet */
-			quietmode = 1;
+			quietmode = true;
 			break;
 		case 's':  /* --signal <signal> */
 			signal_str = optarg;
 			break;
 		case 't':  /* --test */
-			testmode = 1;
+			testmode = true;
 			break;
 		case 'u':  /* --user <username>|<uid> */
 			userspec = optarg;
@@ -909,13 +909,13 @@ parse_options(int argc, char * const *argv)
 			umask_str = optarg;
 			break;
 		case 'b':  /* --background */
-			background = 1;
+			background = true;
 			break;
 		case 'C': /* --no-close */
-			close_io = 0;
+			close_io = false;
 			break;
 		case 'm':  /* --make-pidfile */
-			mpidfile = 1;
+			mpidfile = true;
 			break;
 		case 'R':  /* --retry <schedule>|<timeout> */
 			schedule_str = optarg;