فهرست منبع

* Fixed ambiguous cmds
* Fixed invalid cmds
* Added hits to binds


svn: 902

Bryan Drewery 22 سال پیش
والد
کامیت
55c8aea0d5
5فایلهای تغییر یافته به همراه43 افزوده شده و 9 حذف شده
  1. 1 0
      doc/UPDATES
  2. 1 1
      misc/grep
  3. 5 3
      src/core_binds.c
  4. 33 4
      src/tclhash.c
  5. 3 1
      src/tclhash.h

+ 1 - 0
doc/UPDATES

@@ -9,6 +9,7 @@ This is a summary of ChangeLog basically.
 5.Fixed a potential bug in share.
 6.Traffic stats are now properly cleared on leaf bots every day.
 7.Removed a bunch of unused code on leaf bots.
+8.Cmds over dcc now recognize ambiguous cmds and if a cmd is not valid.
 
 1.1.4 (Quickly advanced to 1.1.5)
 

+ 1 - 1
misc/grep

@@ -1,3 +1,3 @@
 #!/bin/sh
 grep=`which grep`
-grep "$@" | grep -v "^Binary" | grep -v "src/_" | grep -v "help." | grep -v "CVS" | grep -v ".deps.*\.Po"
+grep "$@" | grep -v "^Binary" | grep -v "src/_" | grep -v "help\." | grep -v "CVS" | grep -v ".deps.*\.Po"

+ 5 - 3
src/core_binds.c

@@ -47,7 +47,7 @@ void core_binds_init()
 void check_bind_dcc(const char *cmd, int idx, const char *text)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  int x;
+  int x, hits;
 #ifdef S_DCCPASS
   bind_entry_t *entry = NULL;
   bind_table_t *table = NULL;
@@ -92,10 +92,12 @@ void check_bind_dcc(const char *cmd, int idx, const char *text)
   }
 #endif /* S_DCCPASS */
 
-  x = check_bind(BT_dcc, cmd, &fr, dcc[idx].user, idx, args);
+  x = check_bind_hits(BT_dcc, cmd, &fr, &hits, dcc[idx].user, idx, args);
   putlog(LOG_DEBUG, "*", "%s RETURNED: %d", cmd, x);
-  if (x == -1)
+  if (hits == 0)
     dprintf(idx, "What?  You need '%shelp'\n", dcc_prefix);
+  else if (hits > 1)
+    dprintf(idx, "Ambiguous command.\n");
 
   free(args);
 }

+ 33 - 4
src/tclhash.c

@@ -27,12 +27,14 @@ static bind_table_t *bind_table_list_head = NULL;
 static int check_bind_executing = 0;
 static int already_scheduled = 0;
 /* main routine for bind checks */
+static int bind_vcheck_hits (bind_table_t *table, const char *match, struct flag_record *flags, int *hits, va_list args);
 static void bind_table_really_del(bind_table_t *table);
 static void bind_entry_really_del(bind_table_t *table, bind_entry_t *entry);
 
 void binds_init(void)
 {
 	bind_table_list_head = NULL;
+	egg_bzero(&cmdlist, 500);
 }
 
 static int internal_bind_cleanup()
@@ -345,21 +347,44 @@ static int bind_entry_exec(bind_table_t *table, bind_entry_t *entry, void **al)
 }		
 
 int check_bind(bind_table_t *table, const char *match, struct flag_record *flags, ...)
+{
+	va_list args;
+	int ret;
+
+	va_start (args, flags);
+	ret = bind_vcheck_hits (table, match, flags, NULL, args);	
+	va_end (args);
+
+	return ret;
+}
+
+int check_bind_hits(bind_table_t *table, const char *match, struct flag_record *flags, int *hits,...)
+{
+        va_list args;
+        int ret;
+
+        va_start (args, hits);
+        ret = bind_vcheck_hits (table, match, flags, hits, args);
+        va_end (args);
+
+	return ret;
+}
+
+static int bind_vcheck_hits (bind_table_t *table, const char *match, struct flag_record *flags, int *hits, va_list ap)
 {
 	void *args[11] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
 	bind_entry_t *entry = NULL, *next = NULL, *winner = NULL;
 	int i, cmp, retval;
 	int tie = 0, matchlen = 0;
-	va_list ap;
 
 	Assert(table);
 	check_bind_executing++;
 
-        va_start(ap, flags);
 	for (i = 1; i <= table->nargs; i++) {
 		args[i] = va_arg(ap, void *);
 	}
-	va_end(ap);
+
+	if (hits) (*hits) = 0;
 
 	/* Default return value is 0 */
 	retval = 0;
@@ -407,13 +432,17 @@ int check_bind(bind_table_t *table, const char *match, struct flag_record *flags
 		}
 		if (cmp) continue; /* Doesn't match. */
 
+		if (hits) (*hits)++;
+
 		retval = bind_entry_exec(table, entry, args);
 		if ((table->flags & BIND_BREAKABLE) && (retval & BIND_RET_BREAK)) break;
 	}
 	/* If it's a partial match table, see if we have 1 winner. */
 	if (winner && tie == 1) {
+		if (hits) (*hits)++;
 		retval = bind_entry_exec(table, winner, args);
-	}
+	} else if (hits && tie) (*hits) = tie;
+
 	check_bind_executing--;
 	return(retval);
 }

+ 3 - 1
src/tclhash.h

@@ -66,7 +66,9 @@ typedef struct bind_table_b {
 void kill_binds(void);
 void binds_init();
 
-int check_bind(bind_table_t *table, const char *match, struct flag_record *_flags, ...);
+int check_bind(bind_table_t *table, const char *match, struct flag_record *flags, ...);
+int check_bind_hits(bind_table_t *table, const char *match, struct flag_record *flags, int *hits, ...);
+
 bind_table_t *bind_table_add(const char *name, int nargs, const char *syntax, int match_type, int flags);
 void bind_table_del(bind_table_t *table);
 bind_table_t *bind_table_lookup(const char *name);