[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Wed Oct 24 05:09:00 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-24 10:08:13 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     src/dcc.c src/dns.c src/egg_timer.c src/logfile.c src/script.c
     src/script_api.h src/tcl.c src/tcldcc.c src/tclhash.c
     src/mod/perlscript.mod/perlscript.c
     src/mod/tclscript.mod/tclscript.c

Log message:

* Added support for optional args for scripts.
* Added a ".perl" command.
* Converted some stuff in tcldcc.c, based on Oskar Liljeblad's patch.
* Fixed compile warnings in tcl module.
* Added error reporting when loading perl scripts.

---------------------- diff included ----------------------
Index: eggdrop1.7/src/dcc.c
diff -u eggdrop1.7/src/dcc.c:1.62 eggdrop1.7/src/dcc.c:1.63
--- eggdrop1.7/src/dcc.c:1.62	Sun Oct 21 01:02:48 2001
+++ eggdrop1.7/src/dcc.c	Wed Oct 24 05:08:03 2001
@@ -4,7 +4,7 @@
  *   disconnect on a dcc socket
  *   ...and that's it!  (but it's a LOT)
  *
- * $Id: dcc.c,v 1.62 2001/10/21 06:02:48 stdarg Exp $
+ * $Id: dcc.c,v 1.63 2001/10/24 10:08:03 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -77,7 +77,7 @@
 
 static script_str_t dcc_script_strings[] = {
 	{"", "dcc_command_chars", &dcc_command_chars},
-	0
+	{0}
 };
 
 void dcc_init()
Index: eggdrop1.7/src/dns.c
diff -u eggdrop1.7/src/dns.c:1.29 eggdrop1.7/src/dns.c:1.30
--- eggdrop1.7/src/dns.c:1.29	Thu Oct 18 20:55:05 2001
+++ eggdrop1.7/src/dns.c	Wed Oct 24 05:08:03 2001
@@ -4,7 +4,7 @@
  *   provides the code used by the bot if the DNS module is not loaded
  *   DNS script commands
  *
- * $Id: dns.c,v 1.29 2001/10/19 01:55:05 tothwolf Exp $
+ * $Id: dns.c,v 1.30 2001/10/24 10:08:03 stdarg Exp $
  */
 /*
  * Written by Fabian Knittel <fknittel at gmx.de>
@@ -58,7 +58,7 @@
 static script_simple_command_t scriptdns_cmds[] = {
 	{"", NULL, NULL, NULL, 0},
 	{"dnslookup", script_dnslookup, "sc", "ip-address/hostname callback", SCRIPT_INTEGER},
-	0
+	{0}
 };
 
 void dns_init()
Index: eggdrop1.7/src/egg_timer.c
diff -u eggdrop1.7/src/egg_timer.c:1.3 eggdrop1.7/src/egg_timer.c:1.4
--- eggdrop1.7/src/egg_timer.c:1.3	Wed Oct 17 01:08:11 2001
+++ eggdrop1.7/src/egg_timer.c	Wed Oct 24 05:08:03 2001
@@ -29,7 +29,7 @@
 	{"timer", script_single_timer, "iic", "seconds microseconds callback", SCRIPT_INTEGER},
 	{"rtimer", script_repeat_timer, "iic", "seconds microseconds callback", SCRIPT_INTEGER},
 	{"killtimer", timer_destroy, "i", "timer-id", SCRIPT_INTEGER},
-	0
+	{0}
 };
 
 void timer_init()
@@ -51,7 +51,7 @@
 
 int timer_create_complex(egg_timeval_t *howlong, Function callback, void *client_data, int flags)
 {
-	egg_timer_t *timer, *prev, *next;
+	egg_timer_t *timer, *prev;
 	egg_timeval_t trigger_time;
 
 	timer_get_time(&trigger_time);
@@ -147,7 +147,8 @@
 	Function callback;
 	void *client_data;
 
-	while (timer = timer_list_head) {
+	while (timer_list_head) {
+		timer = timer_list_head;
 		timer_get_time(&curtime);
 		if (timer->trigger_time.sec > curtime.sec || (timer->trigger_time.sec == curtime.sec && timer->trigger_time.usec > curtime.usec)) break;
 
Index: eggdrop1.7/src/logfile.c
diff -u eggdrop1.7/src/logfile.c:1.5 eggdrop1.7/src/logfile.c:1.6
--- eggdrop1.7/src/logfile.c:1.5	Sat Oct 20 22:44:30 2001
+++ eggdrop1.7/src/logfile.c	Wed Oct 24 05:08:03 2001
@@ -48,13 +48,13 @@
 static int script_putloglev(char *level, char *chan, char *text);
 
 static script_command_t log_script_cmds[] = {
-	{"", "putlog", script_putlog, (void *)LOG_MISC, 1, 0, "s", "text", SCRIPT_INTEGER, SCRIPT_WANTS_CD},
-	{"", "putcmdlog", script_putlog, (void *)LOG_CMDS, 1, 0, "s", "text", SCRIPT_INTEGER, SCRIPT_WANTS_CD},
-	{"", "putxferlog", script_putlog, (void *)LOG_FILES, 1, 0, "s", "text", SCRIPT_INTEGER, SCRIPT_WANTS_CD},
-	{"", "putloglev", script_putloglev, NULL, 3, 0, "sss", "level channel text", SCRIPT_INTEGER, 0},
-	{"", "logfile", (Function) logfile_add, NULL, 3, 0, "sss", "modes channel filename", SCRIPT_STRING, 0},
-	{"", "stoplog", logfile_del, NULL, 1, 0, "s", "filename", SCRIPT_INTEGER, 0},
-	0
+	{"", "putlog", script_putlog, (void *)LOG_MISC, 1, "s", "text", SCRIPT_INTEGER, SCRIPT_PASS_CDATA},
+	{"", "putcmdlog", script_putlog, (void *)LOG_CMDS, 1, "s", "text", SCRIPT_INTEGER, SCRIPT_PASS_CDATA},
+	{"", "putxferlog", script_putlog, (void *)LOG_FILES, 1, "s", "text", SCRIPT_INTEGER, SCRIPT_PASS_CDATA},
+	{"", "putloglev", script_putloglev, NULL, 3, "sss", "level channel text", SCRIPT_INTEGER, 0},
+	{"", "logfile", (Function) logfile_add, NULL, 3, "sss", "modes channel filename", SCRIPT_STRING, 0},
+	{"", "stoplog", logfile_del, NULL, 1, "s", "filename", SCRIPT_INTEGER, 0},
+	{0}
 };
 
 static script_str_t log_script_strings[] = {
Index: eggdrop1.7/src/mod/perlscript.mod/perlscript.c
diff -u eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.5 eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.6
--- eggdrop1.7/src/mod/perlscript.mod/perlscript.c:1.5	Tue Oct 23 03:47:51 2001
+++ eggdrop1.7/src/mod/perlscript.mod/perlscript.c	Wed Oct 24 05:08:03 2001
@@ -39,7 +39,14 @@
 	fread(data, size, 1, fp);
 	data[size] = 0;
 	fclose(fp);
-	perl_eval_pv(data, TRUE);
+	eval_pv(data, TRUE);
+	if (SvTRUE(ERRSV)) {
+		char *msg;
+		int len;
+
+		msg = SvPV(ERRSV, len);
+		putlog(LOG_MISC, "*", "Perl error: %s", msg);
+	}
 	free(data);
 	return(0);
 }
@@ -69,10 +76,18 @@
 	}
 	PUTBACK;
 
-	count = call_sv((SV *)me->callback_data, G_SCALAR);
+	count = call_sv((SV *)me->callback_data, G_EVAL|G_SCALAR);
 
 	SPAGAIN;
 
+	if (SvTRUE(ERRSV)) {
+		char *msg;
+		int len;
+
+		msg = SvPV(ERRSV, len);
+		retval = POPi;
+		putlog(LOG_MISC, "*", "Perl error: $s", msg);
+	}
 	if (count > 0) {
 		retval = POPi;
 	}
@@ -93,6 +108,7 @@
 	if (me->syntax) free(me->syntax);
 	if (me->name) free(me->name);
 	sv_2mortal((SV *)me->callback_data);
+	SvREFCNT_dec((SV *)me->callback_data);
 	free(me);
 	return(0);
 }
@@ -184,26 +200,39 @@
 	script_command_t *cmd = (script_command_t *) XSANY.any_i32;
 	script_var_t retval;
 	SV *result = NULL;
-	mstack_t *args;
-	int i, len, my_err;
+	mstack_t *args, *cbacks;
+	int i, len, my_err, simple_retval;
+	int skip, nopts;
 	char *syntax;
 	void **al;
 
 	/* Check for proper number of args. */
 	/* -1 means "any number" and implies pass_array. */
-	if (cmd->nargs >= 0 && cmd->nargs != items) {
+	if (cmd->flags & SCRIPT_VAR_ARGS) i = (cmd->nargs <= items);
+	else i = (cmd->nargs >= 0 && cmd->nargs == items);
+	if (!i) {
 		Perl_croak(aTHX_ cmd->syntax_error);
 		return;
 	}
 
-	/* Initialize argstack. We want at least 5 items. */
-	args = mstack_new(2*items+5);
-
-	/* Callback's client data is first arg. */
-	mstack_push(args, cmd->client_data);
+	/* We want at least 10 items. */
+	args = mstack_new(2*items+10);
+	cbacks = mstack_new(items);
+
+	/* Reserve space for 3 optional args. */
+	mstack_push(args, NULL);
+	mstack_push(args, NULL);
+	mstack_push(args, NULL);
 
+	/* Parse arguments. */
 	syntax = cmd->syntax;
-	for (i = 0; i < items; i++) {
+	if (cmd->flags & SCRIPT_VAR_FRONT) {
+		skip = items - cmd->nargs;
+		if (skip < 0) skip = 0;
+		syntax += skip;
+	}
+	else skip = 0;
+	for (i = skip; i < items; i++) {
 		switch (*syntax++) {
 			case SCRIPT_BYTES: /* Byte-array. */
 			case SCRIPT_STRING: { /* String. */
@@ -247,38 +276,43 @@
 				/* Doesn't take up a perl object. */
 				i--;
 				break;
-			case '*':
-				/* Repeat last entry. */
-				if (*(syntax - 2) == 'l') syntax -= 3;
-				else syntax -= 2;
-				i--; /* No perl object. */
-				break;
 			default:
 				goto argerror;
 		} /* End of switch. */
 	} /* End of for loop. */
 
-	/* Ok, now we have our arg stack. */
+	/* Ok, now we have our args. */
 
 	memset(&retval, 0, sizeof(retval));
 
 	al = (void **)args->stack; /* Argument list shortcut name. */
-
-	/* If they don't want their client data, bump the pointer. */
-	if (!(cmd->flags & SCRIPT_WANTS_CD)) {
-		al++;
-		args->len--;
+	nopts = 0;
+	if (cmd->flags & SCRIPT_PASS_COUNT) {
+		al[2-nopts] = (void *)(args->len - 3);
+		nopts++;
+	}
+	if (cmd->flags & SCRIPT_PASS_RETVAL) {
+		al[2-nopts] = (void *)&retval;
+		nopts++;
+	}
+	if (cmd->flags & SCRIPT_PASS_CDATA) {
+		al[2-nopts] = cmd->client_data;
+		nopts++;
 	}
+	al += (3-nopts);
+	args->len -= (3-nopts);
 
-	if (cmd->flags & SCRIPT_COMPLEX) {
-		if (cmd->pass_array) cmd->callback(&retval, args->len, al);
-		else cmd->callback(&retval, al[0], al[1], al[2], al[3], al[4]);
+	if (cmd->flags & SCRIPT_PASS_ARRAY) {
+		simple_retval = cmd->callback(args->len, al);
 	}
 	else {
+		simple_retval = cmd->callback(al[0], al[1], al[2], al[3], al[4], al[5], al[6], al[7], al[8], al[9]);
+	}
+
+	if (!(cmd->flags & SCRIPT_PASS_RETVAL)) {
 		retval.type = cmd->retval_type;
 		retval.len = -1;
-		if (cmd->pass_array) retval.value = (void *)cmd->callback(args->len, al);
-		else retval.value = (void *)cmd->callback(al[0], al[1], al[2], al[3], al[4]);
+		retval.value = (void *)simple_retval;
 	}
 
 	my_err = retval.type & SCRIPT_ERROR;
@@ -297,14 +331,48 @@
 
 argerror:
 	mstack_destroy(args);
+	for (i = 0; i < cbacks->len; i++) {
+		script_callback_t *cback;
+		cback = (script_callback_t *)cbacks->stack[i];
+		cback->delete(cback);
+	}
+	mstack_destroy(cbacks);
 	Perl_croak(aTHX_ cmd->syntax_error);
 }
 
+static int dcc_cmd_perl(struct userrec *u, int idx, char *text)
+{
+	SV *result;
+	char *msg;
+	int len;
+
+	if (must_be_owner && !(isowner(dcc[idx].nick))) return(0);
+
+	len = strlen(text);
+
+	result = eval_pv(text, FALSE);
+	if (SvTRUE(ERRSV)) {
+		msg = SvPV(ERRSV, len);
+		dprintf(idx, "Perl error: %s\n", msg);
+	}
+	else {
+		msg = SvPV(result, len);
+		dprintf(idx, "Perl result: %s\n", msg);
+	}
+
+	return(0);
+}
+
+static cmd_t my_dcc_cmds[] = {
+	{"perl", "n", (Function) dcc_cmd_perl, NULL},
+	{0}
+};
+
 static registry_simple_chain_t my_functions[] = {
 	{"script", NULL, 0},
 	{"load script", my_load_script, 2},
 	{"create cmd", my_create_cmd, 2},
-	0
+	{0}
 };
 
 static void init_xs_stuff()
@@ -343,14 +411,9 @@
 char *perlscript_LTX_start(Function *global_funcs)
 {
 	char *embedding[] = {"", "-e", "0"};
+	bind_table_t *BT_dcc;
 
 	global = global_funcs;
-	ginterp = perl_alloc();
-	perl_construct(ginterp);
-	perl_parse(ginterp, init_xs_stuff, 3, embedding, NULL);
-	registry_add_simple_chains(my_functions);
-        registry_lookup("script", "playback", &journal_playback, &journal_playback_h);
-        if (journal_playback) journal_playback(journal_playback_h, journal_table);
 
 	module_register("perlscript", perlscript_table, 1, 2);
 	if (!module_depend("perlscript", "eggdrop", 107, 0)) {
@@ -358,11 +421,23 @@
 		return "This module requires eggdrop1.7.0 of later";
 	}
 
+	ginterp = perl_alloc();
+	perl_construct(ginterp);
+	perl_parse(ginterp, init_xs_stuff, 3, embedding, NULL);
+	registry_add_simple_chains(my_functions);
+        registry_lookup("script", "playback", &journal_playback, &journal_playback_h);
+        if (journal_playback) journal_playback(journal_playback_h, journal_table);
+
+	BT_dcc = find_bind_table2("dcc");
+	if (BT_dcc) add_builtins2(BT_dcc, my_dcc_cmds);
 	return(NULL);
 }
 
 static char *perlscript_close()
 {
+	bind_table_t *BT_dcc = find_bind_table2("dcc");
+	if (BT_dcc) rem_builtins2(BT_dcc, my_dcc_cmds);
+	PL_perl_destruct_level = 1;
 	perl_destruct(ginterp);
 	perl_free(ginterp);
 	module_undepend("perlscript");
Index: eggdrop1.7/src/mod/tclscript.mod/tclscript.c
diff -u eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.12 eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.13
--- eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.12	Sun Oct 21 20:49:25 2001
+++ eggdrop1.7/src/mod/tclscript.mod/tclscript.c	Wed Oct 24 05:08:03 2001
@@ -286,14 +286,74 @@
 	return(result);
 }
 
-static int my_argument_parser(Tcl_Interp *myinterp, int objc, Tcl_Obj *CONST objv[], char *syntax, script_argstack_t *argstack)
+static int my_argument_cleanup(mstack_t *args, mstack_t *bufs, mstack_t *cbacks)
 {
-	Tcl_Obj *objptr;
-	int i, err = 0, len = 0;
-	void *arg;
+	int i;
+
+	for (i = 0; i < bufs->len; i++) {
+		free((void *)bufs->stack[i]);
+	}
+	if (cbacks) {
+		for (i = 0; i < cbacks->len; i++) {
+			script_callback_t *cback;
+
+			cback = (script_callback_t *)cbacks->stack[i];
+			cback->delete(cback);
+		}
+		mstack_destroy(cbacks);
+	}
+	mstack_destroy(bufs);
+	mstack_destroy(args);
+	return(0);
+}
 
-	for (i = 1; i < objc; i++) {
+static int my_command_handler(ClientData client_data, Tcl_Interp *myinterp, int objc, Tcl_Obj *CONST objv[])
+{
+	script_command_t *cmd = (script_command_t *)client_data;
+	script_var_t retval;
+	Tcl_Obj *tcl_retval = NULL, *objptr;
+	mstack_t *args, *bufs, *cbacks;
+	int *al; /* Argument list to pass to the callback*/
+	int nopts; /* Number of optional args we're passing. */
+	int simple_retval; /* Return value for simple commands. */
+	int i, len, err = TCL_OK;
+	int skip;
+	char *syntax;
+
+	/* Check for proper number of args. */
+	if (cmd->flags & SCRIPT_VAR_ARGS) i = (cmd->nargs <= (objc-1));
+	else i = (cmd->nargs < 0 || cmd->nargs == (objc-1));
+	if (!i) {
+		Tcl_WrongNumArgs(myinterp, 0, NULL, cmd->syntax_error);
+		return(TCL_ERROR);
+	}
+
+	/* We want space for at least 10 args. */
+	args = mstack_new(2*objc+10);
+
+	/* Reserve space for 3 optional args. */
+	mstack_push(args, NULL);
+	mstack_push(args, NULL);
+	mstack_push(args, NULL);
+
+	/* Have some space for buffers too. */
+	bufs = mstack_new(objc);
+
+	/* And callbacks. */
+	cbacks = mstack_new(objc);
+
+	/* Parse arguments. */
+	syntax = cmd->syntax;
+	if (cmd->flags & SCRIPT_VAR_FRONT) {
+		skip = (objc-1) - cmd->nargs;
+		if (skip < 0) skip = 0;
+		syntax += skip;
+	}
+	else skip = 0;
+
+	for (i = skip+1; i < objc; i++) {
 		objptr = objv[i];
+
 		switch (*syntax++) {
 		case SCRIPT_STRING: { /* Null-terminated string. */
 			char *nullterm;
@@ -304,51 +364,45 @@
 				nullterm = (char *)malloc(len+1);
 				memcpy(nullterm, orig, len);
 				nullterm[len] = 0;
-				mstack_push(argstack->bufs, nullterm);
+				mstack_push(bufs, nullterm);
 			#else
 				nullterm = Tcl_GetStringFromObj(objptr, &len);
 			#endif
-
-			arg = (void *)nullterm;
+			mstack_push(args, nullterm);
 			break;
 		}
-		case SCRIPT_BYTES: { /* Byte-array (could be anything). */
+		case SCRIPT_BYTES: { /* Byte-array (string + length). */
+			void *bytes;
 			#ifdef USE_BYTE_ARRAYS
-			arg = (void *)Tcl_GetByteArrayFromObj(objptr, &len);
+			bytes = (void *)Tcl_GetByteArrayFromObj(objptr, &len);
 			#else
-			arg = (void *)Tcl_GetStringFromObj(objptr, &len);
+			bytes = (void *)Tcl_GetStringFromObj(objptr, &len);
 			#endif
+			mstack_push(args, bytes);
 			break;
 		}
 		case SCRIPT_INTEGER: { /* Integer. */
-			err = Tcl_GetIntFromObj(myinterp, objptr, (int *)&arg);
+			int intval;
+			err = Tcl_GetIntFromObj(myinterp, objptr, &intval);
+			mstack_push(args, (void *)intval);
 			break;
 		}
 		case SCRIPT_CALLBACK: { /* Callback. */
 			script_callback_t *cback; /* Callback struct */
 			my_callback_cd_t *cdata; /* Our client data */
-			char *name, *nullterm;
 
 			cback = (script_callback_t *)calloc(1, sizeof(*cback));
 			cdata = (my_callback_cd_t *)calloc(1, sizeof(*cdata));
 			cback->callback = (Function) my_tcl_callbacker;
 			cback->callback_data = (void *)cdata;
 			cback->delete = (Function) my_tcl_cb_delete;
-			#ifdef USE_BYTE_ARRAYS
-			name = (void *)Tcl_GetByteArrayFromObj(objptr, &len);
-			nullterm = (char *)malloc(len+1);
-			memcpy(nullterm, name, len);
-			nullterm[len] = 0;
-			#else
-			name = (char *)Tcl_GetStringFromObj(objptr, &len);
-			malloc_strcpy(nullterm, name);
-			#endif
-			cback->name = nullterm;
+			cback->name = (char *)Tcl_GetStringFromObj(objptr, &len);
 			cdata->myinterp = myinterp;
 			cdata->command = objptr;
 			Tcl_IncrRefCount(objptr);
 
-			arg = (void *)cback;
+			mstack_push(args, cback);
+			mstack_push(cbacks, cback);
 			break;
 		}
 		case SCRIPT_USER: { /* User. */
@@ -358,104 +412,67 @@
 			handle = Tcl_GetStringFromObj(objptr, NULL);
 			if (handle) u = get_user_by_handle(userlist, handle);
 			else u = NULL;
-
-			arg = (void *)u;
+			mstack_push(args, u);
 			break;
 		}
-		case 'l': { /* Length of previous string or byte-array. */
-			arg = (void *)len;
-			i--; /* Doesn't take up a Tcl object. */
+		case 'l': /* Length of previous string/byte-array. */
+			mstack_push(args, (void *)len);
+			i--; /* Doesn't take up a tcl object. */
 			break;
-		}
-		case '*': { /* Repeat last entry. */
-			if (*(syntax-2) == 'l') syntax -= 3;
-			else syntax -= 2;
-			i--; /* Doesn't take up a Tcl object. */
-			continue;
-		}
-		default: return(1);
+		default:
+			err = TCL_ERROR;
 		} /* End of switch */
 
-		if (err != TCL_OK) return(2);
-
-		mstack_push(argstack->args, arg);
-	}
-	return(0);
-}
-
-static int my_argument_cleanup(script_argstack_t *argstack)
-{
-	int i;
-
-	for (i = 0; i < argstack->bufs->len; i++) {
-		free((void *)argstack->bufs->stack[i]);
-	}
-	mstack_destroy(argstack->bufs);
-	mstack_destroy(argstack->args);
-	return(0);
-}
-
-static int my_command_handler(ClientData client_data, Tcl_Interp *myinterp, int objc, Tcl_Obj *CONST objv[])
-{
-	script_command_t *cmd = (script_command_t *)client_data;
-	script_var_t retval;
-	Tcl_Obj *tcl_retval = NULL;
-	script_argstack_t argstack; /* For my_argument_parser */
-	void **al; /* Argument list to pass to the callback*/
-	int my_err; /* Flag to indicate we should return a TCL_ERROR */
-
-	/* Check for proper number of args. */
-	if (cmd->nargs >= 0 && cmd->nargs != (objc-1)) {
-		Tcl_WrongNumArgs(myinterp, 1, objv, cmd->syntax_error);
-		return(TCL_ERROR);
+		if (err != TCL_OK) break;
 	}
 
-	/* Init argstack */
-	/* We want space for at least 5 args. */
-	argstack.args = mstack_new(2*objc+5);
-
-	/* The command's client data is the first arg. */
-	mstack_push(argstack.args, cmd->client_data);
-
-	/* Have some space for buffers too. */
-	argstack.bufs = mstack_new(objc);
-
-	/* Parse arguments. */
-	if (my_argument_parser(myinterp, objc, objv, cmd->syntax, &argstack)) {
-		my_argument_cleanup(&argstack);
+	if (err != TCL_OK) {
+		my_argument_cleanup(args, bufs, cbacks);
 		Tcl_WrongNumArgs(myinterp, 0, NULL, cmd->syntax_error);
 		return(TCL_ERROR);
 	}
 
 	memset(&retval, 0, sizeof(retval));
 
-	al = (void **)argstack.args->stack; /* Argument list shortcut name. */
-
-	/* If they don't want their client data, bump the pointer. */
-	if (!(cmd->flags & SCRIPT_WANTS_CD)) {
-		al++;
-		argstack.args->len--;
+	al = args->stack; /* Argument list shortcut name. */
+	nopts = 0;
+	if (cmd->flags & SCRIPT_PASS_COUNT) {
+		al[2-nopts] = args->len - 3;
+		nopts++;
+	}
+	if (cmd->flags & SCRIPT_PASS_RETVAL) {
+		al[2-nopts] = (int)&retval;
+		nopts++;
+	}
+	if (cmd->flags & SCRIPT_PASS_CDATA) {
+		al[2-nopts] = (int)cmd->client_data;
+		nopts++;
 	}
+	al += (3-nopts);
+	args->len -= (3-nopts);
 
-	if (cmd->flags & SCRIPT_COMPLEX) {
-		if (cmd->pass_array) cmd->callback(&retval, argstack.args->len, al);
-		else cmd->callback(&retval, al[0], al[1], al[2], al[3], al[4]);
+	if (cmd->flags & SCRIPT_PASS_ARRAY) {
+		simple_retval = cmd->callback(args->len, al);
 	}
 	else {
+		simple_retval = cmd->callback(al[0], al[1], al[2], al[3], al[4]);
+	}
+
+	if (!(cmd->flags & SCRIPT_PASS_RETVAL)) {
 		retval.type = cmd->retval_type;
 		retval.len = -1;
-		if (cmd->pass_array) retval.value = (void *)cmd->callback(argstack.args->len, al);
-		else retval.value = (void *)cmd->callback(al[0], al[1], al[2], al[3], al[4]);
+		retval.value = (void *)simple_retval;
 	}
 
-	my_err = retval.type & SCRIPT_ERROR;
+	err = retval.type & SCRIPT_ERROR;
 	tcl_retval = my_resolve_var(myinterp, &retval);
 
 	if (tcl_retval) Tcl_SetObjResult(myinterp, tcl_retval);
+	else Tcl_ResetResult(myinterp);
 
-	my_argument_cleanup(&argstack);
+	my_argument_cleanup(args, bufs, NULL);
 
-	if (my_err) return TCL_ERROR;
+	if (err) return TCL_ERROR;
 	return TCL_OK;
 }
 
Index: eggdrop1.7/src/script.c
diff -u eggdrop1.7/src/script.c:1.9 eggdrop1.7/src/script.c:1.10
--- eggdrop1.7/src/script.c:1.9	Tue Oct 23 03:47:51 2001
+++ eggdrop1.7/src/script.c	Wed Oct 24 05:08:03 2001
@@ -14,7 +14,7 @@
 int script_create_cmd_table(script_command_t *table);
 
 static script_command_t my_script_cmds[] = {
-	{"", "loadscript", script_load, NULL, 1, 0, "s", "filename", SCRIPT_INTEGER, 0},
+	{"", "loadscript", script_load, NULL, 1, "s", "filename", SCRIPT_INTEGER, 0},
 	{0}
 };
 
@@ -77,7 +77,7 @@
 	{"link int", my_link_int, 3},
 	{"link str", my_link_str, 3},
 	{"playback", my_playback, 2},
-	0
+	{0}
 };
 
 int script_init()
@@ -92,7 +92,7 @@
 	registry_lookup("script", "create cmd", &create_cmd, &create_cmd_h);
 	registry_lookup("script", "delete cmd", &delete_cmd, &delete_cmd_h);
 
-	script_create_cmd_table(&my_script_cmds);
+	script_create_cmd_table(my_script_cmds);
 
 	return(0);
 }
Index: eggdrop1.7/src/script_api.h
diff -u eggdrop1.7/src/script_api.h:1.6 eggdrop1.7/src/script_api.h:1.7
--- eggdrop1.7/src/script_api.h:1.6	Thu Oct 18 04:06:43 2001
+++ eggdrop1.7/src/script_api.h	Wed Oct 24 05:08:03 2001
@@ -22,8 +22,12 @@
 };
 
 /* Flags for commands. */
-#define SCRIPT_WANTS_CD	1
-#define SCRIPT_COMPLEX	2
+#define SCRIPT_PASS_CDATA	1
+#define SCRIPT_PASS_RETVAL	2
+#define SCRIPT_PASS_ARRAY	4
+#define SCRIPT_PASS_COUNT	8
+#define SCRIPT_VAR_ARGS	16
+#define SCRIPT_VAR_FRONT	32
 
 /* Flags for callbacks. */
 #define SCRIPT_CALLBACK_ONCE	1
@@ -81,7 +85,6 @@
 	Function callback;
 	void *client_data;
 	int nargs; /* Number of arguments the script wants. */
-	int pass_array; /* Want an array of stuff? */
 	char *syntax; /* Argument types. */
 	char *syntax_error; /* Error to print when called incorrectly. */
 	int retval_type; /* Limited return value type, for simple stuff. */
Index: eggdrop1.7/src/tcl.c
diff -u eggdrop1.7/src/tcl.c:1.51 eggdrop1.7/src/tcl.c:1.52
--- eggdrop1.7/src/tcl.c:1.51	Sat Oct 20 22:44:30 2001
+++ eggdrop1.7/src/tcl.c	Wed Oct 24 05:08:03 2001
@@ -4,7 +4,7 @@
  *   Tcl initialization
  *   getting and setting Tcl/eggdrop variables
  *
- * $Id: tcl.c,v 1.51 2001/10/21 03:44:30 stdarg Exp $
+ * $Id: tcl.c,v 1.52 2001/10/24 10:08:03 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -28,6 +28,8 @@
 #include <stdlib.h>		/* getenv()				*/
 #include <locale.h>		/* setlocale()				*/
 #include "main.h"
+#include "script_api.h"
+#include "script.h"
 
 /* Used for read/write to internal strings */
 typedef struct {
@@ -395,6 +397,7 @@
 }
 
 extern tcl_cmds tcluser_cmds[], tcldcc_cmds[], tclmisc_cmds[], tclmisc_objcmds[];
+extern script_simple_command_t script_dcc_cmds[];
 
 /* Not going through Tcl's crazy main() system (what on earth was he
  * smoking?!) so we gotta initialize the Tcl interpreter
@@ -449,6 +452,7 @@
   add_tcl_commands(tcldcc_cmds);
   add_tcl_commands(tclmisc_cmds);
   add_tcl_objcommands(tclmisc_objcmds);
+  script_create_simple_cmd_table(script_dcc_cmds);
 }
 
 void do_tcl(char *whatzit, char *script)
Index: eggdrop1.7/src/tcldcc.c
diff -u eggdrop1.7/src/tcldcc.c:1.38 eggdrop1.7/src/tcldcc.c:1.39
--- eggdrop1.7/src/tcldcc.c:1.38	Sun Oct 21 15:59:49 2001
+++ eggdrop1.7/src/tcldcc.c	Wed Oct 24 05:08:03 2001
@@ -2,7 +2,7 @@
  * tcldcc.c -- handles:
  *   Tcl stubs for the dcc commands
  *
- * $Id: tcldcc.c,v 1.38 2001/10/21 20:59:49 stdarg Exp $
+ * $Id: tcldcc.c,v 1.39 2001/10/24 10:08:03 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -26,6 +26,8 @@
 #include "main.h"
 #include "tandem.h"
 #include "modules.h"
+#include "script_api.h"
+#include "script.h"
 
 extern Tcl_Interp	*interp;
 extern tcl_timer_t	*timer,
@@ -45,18 +47,11 @@
 
 /***********************************************************************/
 
-static int tcl_putdcc STDVAR
+static int script_putdcc(int idx, char *text)
 {
-  int idx;
-
-  BADARGS(3, 3, " idx text");
-  idx = atoi(argv[1]);
-  if (idx < 0 ||  idx >= dcc_total || !dcc[idx].type) {
-    Tcl_AppendResult(irp, "invalid idx", NULL);
-    return TCL_ERROR;
-  }
-  dumplots(-(dcc[idx].sock), "", argv[2]);
-  return TCL_OK;
+  if (idx < 0 ||  idx >= dcc_total || !dcc[idx].type) return(1);
+  dumplots(-(dcc[idx].sock), "", text);
+  return(0);
 }
 
 /* Allows tcl scripts to send out raw data. Can be used for fast server
@@ -70,12 +65,10 @@
  * (added by drummer at sophia.jpte.hu)
  */
 
-static int tcl_putdccraw STDVAR
+static int script_putdccraw(int idx, int len, char *text)
 {
-  int i, idx;
+  int i;
 
-  BADARGS(4, 4, " idx size text");
-  idx = atoi(argv[1]);
   if (idx == -1) {
     /* -1 means search for the server's idx. */
     for (i = 0; i < dcc_total; i++) {
@@ -85,160 +78,94 @@
       }
     }
   }
-  if (idx < 0 || idx >= dcc_total || !dcc[idx].type) {
-    Tcl_AppendResult(irp, "invalid idx", NULL);
-    return TCL_ERROR;
-  }
-  tputs(idx, argv[3], atoi(argv[2]));
-  return TCL_OK;
+  if (idx < 0 || idx >= dcc_total || !dcc[idx].type) return(1);
+  tputs(dcc[idx].sock, text, len);
+  return(0);
 }
 
-static int tcl_dccsimul STDVAR
+static int script_dccsimul(int idx, char *cmd)
 {
-  BADARGS(3, 3, " idx command");
-  if (enable_simul) {
-    int idx = findidx(atoi(argv[1]));
+  int len;
+  if (!enable_simul) return(1);
+  if (idx < 0 || !dcc->type || !(dcc[idx].type->flags & DCT_SIMUL)
+    || !(dcc[idx].type->activity)) return(1);
 
-    if (idx >= 0 && (dcc[idx].type->flags & DCT_SIMUL)) {
-      int l = strlen(argv[2]);
+  len = strlen(cmd);
+  if (len > 510) len = 510;
 
-      if (l > 510) {
-	l = 510;
-	argv[2][510] = 0;	/* Restrict length of cmd */
-      }
-      if (dcc[idx].type && dcc[idx].type->activity) {
-	dcc[idx].type->activity(idx, argv[2], l);
-	return TCL_OK;
-      }
-    } else
-      Tcl_AppendResult(irp, "invalid idx", NULL);
-  } else
-    Tcl_AppendResult(irp, "simul disabled", NULL);
-  return TCL_ERROR;
+  dcc[idx].type->activity(idx, cmd, len);
+  return(0);
 }
 
-static int tcl_dccbroadcast STDVAR
+static int script_dccbroadcast(char *msg)
 {
-  char msg[401];
-
-  BADARGS(2, 2, " message");
-  strncpyz(msg, argv[1], sizeof msg);
   chatout("*** %s\n", msg);
   botnet_send_chat(-1, botnetnick, msg);
-  return TCL_OK;
+  return(0);
 }
 
-static int tcl_hand2idx STDVAR
+static int script_hand2idx(char *nick)
 {
   int i;
-  char s[11];
 
-  BADARGS(2, 2, " nickname");
-  for (i = 0; i < dcc_total; i++)
-    if ((dcc[i].type->flags & DCT_SIMUL) &&
-        !strcasecmp(argv[1], dcc[i].nick)) {
-      snprintf(s, sizeof s, "%ld", dcc[i].sock);
-      Tcl_AppendResult(irp, s, NULL);
-      return TCL_OK;
+  for (i = 0; i < dcc_total; i++) {
+    if ((dcc[i].type) && (dcc[i].type->flags & DCT_SIMUL) &&
+        !strcasecmp(nick, dcc[i].nick)) {
+      return(i);
     }
-  Tcl_AppendResult(irp, "-1", NULL);
-  return TCL_OK;
+  }
+  return(-1);
 }
 
-static int tcl_getchan STDVAR
+static int script_getchan(int idx)
 {
-  char s[7];
-  int idx;
-
-  BADARGS(2, 2, " idx");
-  idx = findidx(atoi(argv[1]));
-  if (idx < 0 ||
+  if (idx < 0 || !(dcc[idx].type) ||
       (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
-    Tcl_AppendResult(irp, "invalid idx", NULL);
-    return TCL_ERROR;
+    return(-2);
   }
   if (dcc[idx].type == &DCC_SCRIPT)
-    snprintf(s, sizeof s, "%d", dcc[idx].u.script->u.chat->channel);
+    return(dcc[idx].u.script->u.chat->channel);
   else
-    snprintf(s, sizeof s, "%d", dcc[idx].u.chat->channel);
-  Tcl_AppendResult(irp, s, NULL);
-  return TCL_OK;
+    return(dcc[idx].u.chat->channel);
 }
 
-static int tcl_setchan STDVAR
+static int script_setchan(int idx, int chan)
 {
-  int idx, chan;
-  module_entry *me;
+  int oldchan;
 
-  BADARGS(3, 3, " idx channel");
-  idx = findidx(atoi(argv[1]));
-  if (idx < 0 ||
+  if (idx < 0 || !(dcc[idx].type) ||
       (dcc[idx].type != &DCC_CHAT && dcc[idx].type != &DCC_SCRIPT)) {
-    Tcl_AppendResult(irp, "invalid idx", NULL);
-    return TCL_ERROR;
+    return(1);
   }
-  if (argv[2][0] < '0' || argv[2][0] > '9') {
-    if (!strcmp(argv[2], "-1") || !strcasecmp(argv[2], "off"))
-      chan = (-1);
-    else {
-      Tcl_SetVar(irp, "chan", argv[2], 0);
-      if (Tcl_VarEval(irp, "assoc ", "$chan", NULL) != TCL_OK ||
-	  !interp->result[0]) {
-	Tcl_AppendResult(irp, "channel name is invalid", NULL);
-	return TCL_ERROR;
-      }
-      chan = atoi(interp->result);
-    }
-  } else
-    chan = atoi(argv[2]);
+
   if ((chan < -1) || (chan > 199999)) {
-    Tcl_AppendResult(irp, "channel out of range; must be -1 thru 199999",
-		     NULL);
-    return TCL_ERROR;
+    return(1);
   }
-  if (dcc[idx].type == &DCC_SCRIPT)
+  if (dcc[idx].type == &DCC_SCRIPT) {
     dcc[idx].u.script->u.chat->channel = chan;
-  else {
-    int oldchan = dcc[idx].u.chat->channel;
-
-    if (dcc[idx].u.chat->channel >= 0) {
-      if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS))
-	botnet_send_part_idx(idx, "*script*");
-      check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
-		     dcc[idx].u.chat->channel);
-    }
-    dcc[idx].u.chat->channel = chan;
-    if (chan < GLOBAL_CHANS)
-      botnet_send_join_idx(idx, oldchan);
-    check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(idx),
-		   dcc[idx].sock, dcc[idx].host);
+    return(0);
   }
-  /* Console autosave. */
-  if ((me = module_find("console", 1, 1))) {
-    Function *func = me->funcs;
 
-    (func[CONSOLE_DOSTORE]) (idx);
+  oldchan = dcc[idx].u.chat->channel;
+
+  if (oldchan >= 0) {
+    if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS)) botnet_send_part_idx(idx, "*script*");
+    check_tcl_chpt(botnetnick, dcc[idx].nick, idx, oldchan);
   }
-  return TCL_OK;
+  dcc[idx].u.chat->channel = chan;
+  if (chan < GLOBAL_CHANS) botnet_send_join_idx(idx, oldchan);
+  check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(idx),
+	   idx, dcc[idx].host);
+  return(0);
 }
 
-static int tcl_dccputchan STDVAR
+static int script_dccputchan(int chan, char *msg)
 {
-  int chan;
-  char msg[401];
-
-  BADARGS(3, 3, " channel message");
-  chan = atoi(argv[1]);
-  if ((chan < 0) || (chan > 199999)) {
-    Tcl_AppendResult(irp, "channel out of range; must be 0 thru 199999",
-		     NULL);
-    return TCL_ERROR;
-  }
-  strncpyz(msg, argv[2], sizeof msg);
-  chanout_but(-1, chan, "*** %s\n", argv[2]);
-  botnet_send_chan(-1, botnetnick, NULL, chan, argv[2]);
-  check_tcl_bcst(botnetnick, chan, argv[2]);
-  return TCL_OK;
+  if ((chan < 0) || (chan > 199999)) return(1);
+  chanout_but(-1, chan, "*** %s\n", msg);
+  botnet_send_chan(-1, botnetnick, NULL, chan, msg);
+  check_tcl_bcst(botnetnick, chan, msg);
+  return(0);
 }
 
 static int tcl_console STDVAR
@@ -1021,17 +948,21 @@
   return TCL_OK;
 }
 
+script_simple_command_t script_dcc_cmds[] = {
+	{"", NULL, NULL, NULL, 0},
+	{"putdcc", script_putdcc, "is", "idx text", SCRIPT_INTEGER},
+	{"putdccraw", script_putdccraw, "iis", "idx len text", SCRIPT_INTEGER},
+	{"dccsimul", script_dccsimul, "is", "idx command", SCRIPT_INTEGER},
+	{"dccbroadcast", script_dccbroadcast, "s", "text", SCRIPT_INTEGER},
+	{"hand2idx", script_hand2idx, "s", "handle", SCRIPT_INTEGER},
+	{"getchan", script_getchan, "i", "idx", SCRIPT_INTEGER},
+	{"setchan", script_setchan, "ii", "idx chan", SCRIPT_INTEGER},
+	{"dccputchan", script_dccputchan, "is", "chan text", SCRIPT_INTEGER},
+	{0}
+};
+
 tcl_cmds tcldcc_cmds[] =
 {
-  {"putdcc",		tcl_putdcc},
-  {"putdccraw",		tcl_putdccraw},
-  {"putidx",		tcl_putdcc},
-  {"dccsimul",		tcl_dccsimul},
-  {"dccbroadcast",	tcl_dccbroadcast},
-  {"hand2idx",		tcl_hand2idx},
-  {"getchan",		tcl_getchan},
-  {"setchan",		tcl_setchan},
-  {"dccputchan",	tcl_dccputchan},
   {"console",		tcl_console},
   {"strip",		tcl_strip},
   {"echo",		tcl_echo},
Index: eggdrop1.7/src/tclhash.c
diff -u eggdrop1.7/src/tclhash.c:1.54 eggdrop1.7/src/tclhash.c:1.55
--- eggdrop1.7/src/tclhash.c:1.54	Sun Oct 21 01:02:48 2001
+++ eggdrop1.7/src/tclhash.c	Wed Oct 24 05:08:03 2001
@@ -7,7 +7,7 @@
  *   (non-Tcl) procedure lookups for msg/dcc/file commands
  *   (Tcl) binding internal procedures to msg/dcc/file commands
  *
- * $Id: tclhash.c,v 1.54 2001/10/21 06:02:48 stdarg Exp $
+ * $Id: tclhash.c,v 1.55 2001/10/24 10:08:03 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -61,7 +61,7 @@
 static char *global_filt_string; /* String for FILT binds to modify. */
 static script_str_t tclhash_script_strings[] = {
 	{"", "filt_string", &global_filt_string},
-	0
+	{0}
 };
 
 p_tcl_bind_list		bind_table_list;
@@ -163,7 +163,7 @@
 	{"", NULL, NULL, NULL, 0},
 	{"bind", script_bind, "sssc", "table flags mask command", SCRIPT_INTEGER},
 	{"unbind", script_unbind, "ssss", "table flags mask command", SCRIPT_INTEGER},
-	0
+	{0}
 };
 
 void binds_init(void)
@@ -950,10 +950,7 @@
 
 int check_tcl_note(const char *from, const char *to, const char *text)
 {
-  int	x;
-
-  check_bind(BT_note, to, NULL, from, to, text);
-  return (x == BIND_MATCHED || x == BIND_EXECUTED || x == BIND_EXEC_LOG);
+  return check_bind(BT_note, to, NULL, from, to, text);
 }
 
 void check_tcl_listen(const char *cmd, int idx)
@@ -972,7 +969,7 @@
 		    const char type, int sock, const char *host)
 {
   struct flag_record	fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
-  char			s[11], t[2], u[11];
+  char			s[11], t[2];
 
   t[0] = type;
   t[1] = 0;
----------------------- End of diff -----------------------



More information about the Changes mailing list