瀏覽代碼

dumplots: Let prefix be a String

Bryan Drewery 7 年之前
父節點
當前提交
72218e4a7b
共有 4 個文件被更改,包括 15 次插入9 次删除
  1. 6 2
      src/botnet.cc
  2. 3 1
      src/cmds.cc
  3. 5 5
      src/dccutil.cc
  4. 1 1
      src/dccutil.h

+ 6 - 2
src/botnet.cc

@@ -625,14 +625,18 @@ tell_bots(int idx, int up, const char *nodename)
   }
 
   if (group.length() == 0 && !nodename) {
-    dumplots(idx, nodename ? "Matching: " : (up ? "Up: " : "Down: "), static_cast<bd::String>(bots.join(" ")).c_str());
+    dumplots(idx, nodename ? "Matching: " : (up ? "Up: " : "Down: "),
+        bots.join(" "));
   } else {
     // Sort by nodes
     std::sort(nodes.begin(), nodes.end(), sortNodes);
     for (size_t i = 0; i < nodes.length(); ++i) {
       const bd::String node(nodes[i]);
       const bd::Array<bd::String> botsInNode(nodeBots[node]);
-      dumplots(idx, bd::String::printf("%*s: ", int(maxNodeNameLength), node.c_str()).c_str(), static_cast<bd::String>(botsInNode.join(" ")).c_str());
+      dumplots(idx,
+          bd::String::printf("%*s: ",
+            int(maxNodeNameLength), node.c_str()),
+            botsInNode.join(" "));
     }
   }
 

+ 3 - 1
src/cmds.cc

@@ -944,7 +944,9 @@ static void cmd_groups(int idx, char *par)
     // Display all groups and which bots are in them
     for (const auto& group : allgroups) {
       const bd::Array<bd::String> bots(groupBots[group]);
-      dumplots(idx, bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()).c_str(), static_cast<bd::String>(bots.join(" ")).c_str());
+      dumplots(idx,
+          bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()),
+          bots.join(" "));
     }
     dprintf(idx, "Total groups: %zu\n", allgroups.length());
   }

+ 5 - 5
src/dccutil.cc

@@ -217,14 +217,14 @@ colorbuf(char *buf, size_t len, int idx, size_t bufsiz)
 
 /* Dump a potentially super-long string of text.
  */
-void dumplots(int idx, const char *prefix, const bd::String& data)
+void dumplots(int idx, const bd::String& prefix, const bd::String& data)
 {
   if (unlikely(!*data)) {
-    dprintf(idx, "%s\n", prefix);
+    dprintf(idx, "%s\n", prefix.c_str());
     return;
   }
 
-  const size_t max_data_len = 120 - strlen(prefix);
+  const size_t max_data_len = 120 - prefix.length();
   bd::Array<bd::String> lines = data.split('\n');
   size_t i = 0;
 
@@ -245,7 +245,7 @@ void dumplots(int idx, const char *prefix, const bd::String& data)
         ++pos;
 
       if (bd::String(line(pos)).find("\n") != bd::String::npos) // Newline in remaining: dump it
-        dprintf(idx, "%s%s\n", prefix, bd::String(line(pos)).c_str());
+        dprintf(idx, "%s%s\n", prefix.c_str(), bd::String(line(pos)).c_str());
       else {
         const size_t tpos = line[pos] == ' ' ? pos + 1 : pos; // Trim out the space
         if (lines.length() - (i + 1) > 0) // Wrapped text: prepend to next line if possible
@@ -255,7 +255,7 @@ void dumplots(int idx, const char *prefix, const bd::String& data)
       }
       line.resize(pos);
     }
-    dprintf(idx, "%s%s\n", prefix, line.c_str());
+    dprintf(idx, "%s%s\n", prefix.c_str(), line.c_str());
     ++i;
   }
 }

+ 1 - 1
src/dccutil.h

@@ -37,7 +37,7 @@ namespace bd {
 
 
 void init_dcc(void);
-void dumplots(int, const char *, const bd::String&);
+void dumplots(int, const bd::String&, const bd::String&);
 void rdprintf(const char*, int, const char *, ...) __attribute__((format(printf, 3, 4)));
 void dprintf(int, const char *, ...) __attribute__((format(printf, 2, 3)));
 void dprintf_real(int, char*, size_t, size_t, const char* = NULL);