]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/trusts_commands.c
fixes for clang
[irc/quakenet/newserv.git] / trusts / trusts_commands.c
index 2aee70c73ecb701b1d142f53e7a1618ad2e1758f..95a986010062daaa8a1a5ab97a1a71efcbbc06b8 100644 (file)
@@ -98,25 +98,12 @@ static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup,
     outputtree(np, marker, originalgroup, th, depth + 1);
 }
 
-static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
-  nick *sender = source;
-  trustgroup *tg;
+static void displaygroup(nick *sender, trustgroup *tg) {
   trusthost *th, **p2;
-  time_t t;
   unsigned int marker;
   array parents;
   int i;
-
-  if(cargc < 1)
-    return CMD_USAGE;
-
-  tg = tg_strtotg(cargv[0]);
-  if(!tg) {
-    controlreply(sender, "Couldn't find a trustgroup with that id.");
-    return CMD_ERROR;
-  }
-
-  t = time(NULL);
+  time_t t = time(NULL);
 
   /* abusing the ternary operator a bit :( */
   controlreply(sender, "Name:            : %s", tg->name->content);
@@ -147,6 +134,40 @@ static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
   array_free(&parents);
 
   controlreply(sender, "End of list.");
+}
+
+static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
+  nick *sender = source;
+  trustgroup *tg = NULL;
+  int found = 0, remaining = 50;
+  char *name;
+
+  if(cargc < 1)
+    return CMD_USAGE;
+
+  name = cargv[0];
+
+  tg = tg_strtotg(name);
+
+  if(tg) {
+    displaygroup(sender, tg);
+    return CMD_OK;
+  }
+
+  for(tg=tglist;tg;tg=tg->next) {
+    if(match(name, tg->name->content))
+      continue;
+
+    displaygroup(sender, tg);
+    if(--remaining == 0) {
+      controlreply(sender, "Maximum number of matches reached.");
+      return CMD_OK;
+    }
+    found = 1;
+  }
+
+  if(!found)
+    controlreply(sender, "No matches found.");
 
   return CMD_OK;
 }
@@ -192,7 +213,7 @@ static int trusts_cmdtrustdump(void *source, int argc, char **argv) {
     return CMD_ERROR;
   }
 
-  for(i=0,tg=tglist;i<totalcount&&th;tg=tg->next,i++)
+  for(i=0,tg=tglist;i<totalcount&&tg;tg=tg->next,i++)
     atg[i] = tg;
 
   qsort(atg, totalcount, sizeof(trustgroup *), comparetgs);