[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Mon Oct 15 04:28:00 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-15 09:27:18 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     src/cmds.c src/egg_timer.c src/egg_timer.h src/main.c
     src/script.c src/script_api.h src/tcldcc.c
     src/mod/tclscript.mod/tclscript.c

Log message:

Updates to timer code.
Updates to tcl module.
Convenience functions for scripting.
Script journal for late scripting modules.
Got rid of anonymous union in script_var_t.

---------------------- diff included ----------------------
Index: eggdrop1.7/src/cmds.c
diff -u eggdrop1.7/src/cmds.c:1.72 eggdrop1.7/src/cmds.c:1.73
--- eggdrop1.7/src/cmds.c:1.72	Fri Oct 12 10:50:25 2001
+++ eggdrop1.7/src/cmds.c	Mon Oct 15 04:27:07 2001
@@ -3,7 +3,7 @@
  *   commands from a user via dcc
  *   (split in 2, this portion contains no-irc commands)
  *
- * $Id: cmds.c,v 1.72 2001/10/12 15:50:25 tothwolf Exp $
+ * $Id: cmds.c,v 1.73 2001/10/15 09:27:07 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -1064,8 +1064,6 @@
     make_userfile = 0;
   write_userfile(-1);
   putlog(LOG_MISC, "*", "%s", _("Restarting ..."));
-  wipe_timers(interp, &utimer);
-  wipe_timers(interp, &timer);
   do_restart = idx;
 }
 
Index: eggdrop1.7/src/egg_timer.c
diff -u eggdrop1.7/src/egg_timer.c:1.1 eggdrop1.7/src/egg_timer.c:1.2
--- eggdrop1.7/src/egg_timer.c:1.1	Sat Oct 13 07:00:22 2001
+++ eggdrop1.7/src/egg_timer.c	Mon Oct 15 04:27:08 2001
@@ -92,6 +92,17 @@
 	return(0);
 }
 
+int timer_destroy_all()
+{
+	egg_timer_t *timer;
+
+	for (timer = timer_list_head; timer; timer = timer->next) {
+		free(timer);
+	}
+	timer_list_head = NULL;
+	return(0);
+}
+
 int timer_get_shortest(egg_timeval_t *howlong)
 {
 	egg_timeval_t curtime;
Index: eggdrop1.7/src/egg_timer.h
diff -u eggdrop1.7/src/egg_timer.h:1.1 eggdrop1.7/src/egg_timer.h:1.2
--- eggdrop1.7/src/egg_timer.h:1.1	Sat Oct 13 07:00:22 2001
+++ eggdrop1.7/src/egg_timer.h	Mon Oct 15 04:27:08 2001
@@ -17,6 +17,7 @@
 int timer_get_time(egg_timeval_t *curtime);
 int timer_create_complex(egg_timeval_t *howlong, Function callback, void *client_data, int flags);
 int timer_destroy(int timer_id);
+int timer_destroy_all();
 int timer_get_shortest(egg_timeval_t *howlong);
 int timer_run();
 
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.85 eggdrop1.7/src/main.c:1.86
--- eggdrop1.7/src/main.c:1.85	Sun Oct 14 18:13:33 2001
+++ eggdrop1.7/src/main.c	Mon Oct 15 04:27:08 2001
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.85 2001/10/14 23:13:33 stdarg Exp $
+ * $Id: main.c,v 1.86 2001/10/15 09:27:08 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -1049,6 +1049,7 @@
 	call_hook(HOOK_LOADED);
       }
       do_restart = 0;
+      timer_destroy_all(); /* Destroy all timers. */
     }
   }
 }
Index: eggdrop1.7/src/mod/tclscript.mod/tclscript.c
diff -u eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.3 eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.4
--- eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.3	Sun Oct 14 18:13:34 2001
+++ eggdrop1.7/src/mod/tclscript.mod/tclscript.c	Mon Oct 15 04:27:08 2001
@@ -167,56 +167,50 @@
 	Tcl_Obj *result;
 
 	result = NULL;
-	if (v->type & SCRIPT_INTEGER) result = Tcl_NewIntObj(v->intval);
+	if (v->type & SCRIPT_INTEGER) result = Tcl_NewIntObj((int) v->value);
 	else if (v->type & SCRIPT_STRING) {
-		if (v->len == -1) v->len = strlen(v->str);
+		/* A normal string. */
+
+		if (v->len == -1) v->len = strlen((char *)v->value);
 		#ifdef USE_BYTE_ARRAYS
-			result = Tcl_NewByteArrayObj(v->str, v->len);
+			result = Tcl_NewByteArrayObj((char *)v->value, v->len);
 		#else
-			result = Tcl_NewStringObj(v->str, v->len);
+			result = Tcl_NewStringObj((char *)v->value, v->len);
 		#endif
-		if (!(v->type & SCRIPT_STATIC)) free(v->str);
+		if (!(v->type & SCRIPT_STATIC)) free((char *)v->value);
 	}
 	else if (v->type & SCRIPT_ARRAY) {
+		/* An array of script_var_t's (not pointers, actual struct). */
+		script_var_t *vararray;
 		int i;
 
+		vararray = (script_var_t *)v->value;
 		result = Tcl_NewListObj(0, NULL);
 		for (i = 0; i < v->len; i++) {
 			Tcl_Obj *item;
-			script_var_t *pv;
 
-			pv = v->ptrarray[i];
-			item = my_resolve_var(myinterp, pv);
+			item = my_resolve_var(myinterp, &vararray[i]);
 			if (item) Tcl_ListObjAppendElement(myinterp, result, item);
 		}
 	}
-	else if (v->type & SCRIPT_VARRAY) {
-		int i;
-
-		result = Tcl_NewListObj(0, NULL);
-		for (i = 0; i < v->len; i++) {
-			Tcl_Obj *item;
-
-			item = my_resolve_var(myinterp, &v->varray[i]);
-			if (item) Tcl_ListObjAppendElement(myinterp, result, item);
-		}
-		
-	}
 	else if (v->type & SCRIPT_POINTER) {
-		char str[15];
+		/* A pointer variable (will be represented as a hex string). */
+		char str[32];
 
-		sprintf(str, "%#x", v->ptr);
+		sprintf(str, "#%u", v->value);
 		result = Tcl_NewStringObj(str, -1);
 	}
 	else if (v->type & SCRIPT_USER) {
+		/* An eggdrop user record (struct userrec *). */
 		char *handle;
-		struct userrec *u = (struct userrec *)v->ptr;
+		struct userrec *u = (struct userrec *)v->value;
 
 		if (u) handle = u->handle;
 		else handle = "*";
 		result = Tcl_NewStringObj(handle, -1);
 	}
 	else {
+		/* Default: just pass a string with an error message. */
 		result = Tcl_NewStringObj("unsupported return type", -1);
 	}
 	if (!(v->flags & SCRIPT_STATIC)) free(v);
@@ -226,7 +220,7 @@
 static int my_argument_parser(Tcl_Interp *myinterp, int objc, Tcl_Obj *CONST objv[], char *syntax, script_argstack_t *argstack)
 {
 	Tcl_Obj *objptr;
-	int i, err = 0, len = 0, needs_free = 0;
+	int i, err = 0, len = 0;
 	void *arg;
 
 	for (i = 1; i < objc; i++) {
@@ -241,7 +235,7 @@
 				nullterm = (char *)malloc(len+1);
 				memcpy(nullterm, orig, len);
 				nullterm[len] = 0;
-				needs_free = 1;
+				mstack_push(argstack->bufs, nullterm);
 			#else
 				nullterm = Tcl_GetStringFromObj(objptr, &len);
 			#endif
@@ -304,10 +298,6 @@
 
 		if (err != TCL_OK) return(2);
 
-		if (needs_free) {
-			mstack_push(argstack->bufs, arg);
-			needs_free = 0;
-		}
 		mstack_push(argstack->args, arg);
 	}
 	return(0);
@@ -373,8 +363,8 @@
 	else {
 		retval.type = cmd->retval_type;
 		retval.len = -1;
-		if (cmd->pass_array) retval.intval = cmd->callback(&retval, argstack.args->len, al);
-		else retval.intval = cmd->callback(al[0], al[1], al[2], al[3], al[4]);
+		if (cmd->pass_array) retval.value = (void *)cmd->callback(&retval, argstack.args->len, al);
+		else retval.value = (void *)cmd->callback(al[0], al[1], al[2], al[3], al[4]);
 	}
 
 	my_err = retval.type & SCRIPT_ERROR;
@@ -403,10 +393,9 @@
 	0
 };
 
-/*
 static Function journal_table[] = {
 	(Function)1,
-	(Function)EV_MAX,
+	(Function)SCRIPT_EVENT_MAX,
 	my_load_script,
 	my_set_int,
 	my_set_str,
@@ -417,7 +406,6 @@
 	my_create_cmd,
 	my_delete_cmd
 };
-*/
 
 static Function journal_playback;
 static void *journal_playback_h;
@@ -440,8 +428,8 @@
 	/* interp = Tcl_CreateInterp(); */
 	ginterp = interp;
 	registry_add_simple_chains(my_functions);
-	registry_lookup("script", "journal playback", &journal_playback, &journal_playback_h);
-	/* if (journal_playback) journal_playback(journal_playback_h, journal_table); */
+	registry_lookup("script", "playback", &journal_playback, &journal_playback_h);
+	if (journal_playback) journal_playback(journal_playback_h, journal_table);
 
 	module_register("tclscript", tclscript_table, 1, 2);
 	if (!module_depend("tclscript", "eggdrop", 107, 0)) {
Index: eggdrop1.7/src/script.c
diff -u eggdrop1.7/src/script.c:1.2 eggdrop1.7/src/script.c:1.3
--- eggdrop1.7/src/script.c:1.2	Sun Oct 14 11:59:30 2001
+++ eggdrop1.7/src/script.c	Mon Oct 15 04:27:08 2001
@@ -1,18 +1,72 @@
+#include <stdio.h>
 typedef int (*Function)();
 #include "registry.h"
 #include "script_api.h"
+#include "egglib/mstack.h"
 
 static Function link_int, unlink_int, link_str, unlink_str, create_cmd, delete_cmd;
-void *link_int_h, *unlink_int_h, *link_str_h, *unlink_str_h, *create_cmd_h, *delete_cmd_h;
+static void *link_int_h, *unlink_int_h, *link_str_h, *unlink_str_h, *create_cmd_h, *delete_cmd_h;
+
+static mstack_t *script_events;
+
+typedef struct {
+	int type;
+	int arg1, arg2, arg3;
+} script_event_t;
+
+static void add_event(int type, int arg1, int arg2, int arg3)
+{
+	script_event_t *event = (script_event_t *)malloc(sizeof(*event));
+	event->type = type;
+	event->arg1 = arg1;
+	event->arg2 = arg2;
+	event->arg3 = arg3;
+}
+
+static int my_create_cmd(void *ignore, script_command_t *info)
+{
+	add_event(SCRIPT_EVENT_CREATE_CMD, (int) info, 0, 0);
+	return(0);
+}
+
+static int my_playback(void *ignore, Function *table)
+{
+	script_event_t *event;
+	int i, version, max;
+
+	version = (int) *table;
+	if (version != 1) return(0);
+	table++;
+
+	max = (int) *table;
+	table++;
+	for (i = 0; i < script_events->len; i++) {
+		event = (script_event_t *)script_events->stack[i];
+		if (event->type < max && table[event->type]) {
+			(table[event->type])(event->arg1, event->arg2, event->arg3);
+		}
+	}
+	return(0);
+}
+
+static registry_simple_chain_t my_functions[] = {
+	{"script", NULL, 0},
+	{"create cmd", my_create_cmd, 2},
+	{"playback", my_playback, 2},
+	0
+};
 
 int script_init()
 {
+	script_events = mstack_new(0);
+	registry_add_simple_chains(my_functions);
 	registry_lookup("script", "link int", &link_int, &link_int_h);
 	registry_lookup("script", "unlink int", &unlink_int, &unlink_int_h);
 	registry_lookup("script", "link str", &link_str, &link_str_h);
 	registry_lookup("script", "unlink str", &unlink_str, &unlink_str_h);
 	registry_lookup("script", "create cmd", &create_cmd, &create_cmd_h);
 	registry_lookup("script", "delete cmd", &delete_cmd, &delete_cmd_h);
+
 	return(0);
 }
 
Index: eggdrop1.7/src/script_api.h
diff -u eggdrop1.7/src/script_api.h:1.2 eggdrop1.7/src/script_api.h:1.3
--- eggdrop1.7/src/script_api.h:1.2	Sun Oct 14 11:59:30 2001
+++ eggdrop1.7/src/script_api.h	Mon Oct 15 04:27:08 2001
@@ -7,6 +7,20 @@
 #define SCRIPT_RETURN_INT(x) retval->type = SCRIPT_INTEGER, retval->intval = x
 #define SCRIPT_RETURN_STR(s) retval->type = SCRIPT_STRING, retval->str = s
 
+/* Script events that get recorded in the script journal. */
+enum {
+	SCRIPT_EVENT_LOAD_SCRIPT = 0,
+	SCRIPT_EVENT_SET_INT,
+	SCRIPT_EVENT_SET_STR,
+	SCRIPT_EVENT_LINK_INT,
+	SCRIPT_EVENT_UNLINK_INT,
+	SCRIPT_EVENT_LINK_STR,
+	SCRIPT_EVENT_UNLINK_STR,
+	SCRIPT_EVENT_CREATE_CMD,
+	SCRIPT_EVENT_DELETE_CMD,
+	SCRIPT_EVENT_MAX
+};
+
 /* Flags for commands. */
 #define SCRIPT_WANTS_CD	1
 #define SCRIPT_COMPLEX	2
@@ -38,19 +52,10 @@
 } script_callback_t;
 
 typedef struct script_var_b {
-	int type;
-	union {
-		int intval;
-		char *str;
-		unsigned char *bytes;
-		void *ptr;
-		void *list;
-		void **ptrarray;
-		struct script_var_b *varray;
-		struct script_var_b **vptrarray;
-	};
-	int len;
-	int flags;
+	int type;	/* Type of variable (int, str, etc). */
+	void *value;	/* Value (needs to be cast to right type). */
+	int len;	/* Length of string of array (when appropriate). */
+	int flags;	/* Not used right now. */
 } script_var_t;
 
 typedef struct script_int_b {
Index: eggdrop1.7/src/tcldcc.c
diff -u eggdrop1.7/src/tcldcc.c:1.34 eggdrop1.7/src/tcldcc.c:1.35
--- eggdrop1.7/src/tcldcc.c:1.34	Thu Oct 11 06:34:19 2001
+++ eggdrop1.7/src/tcldcc.c	Mon Oct 15 04:27:08 2001
@@ -2,7 +2,7 @@
  * tcldcc.c -- handles:
  *   Tcl stubs for the dcc commands
  *
- * $Id: tcldcc.c,v 1.34 2001/10/11 11:34:19 tothwolf Exp $
+ * $Id: tcldcc.c,v 1.35 2001/10/15 09:27:08 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -1018,8 +1018,6 @@
   }
   write_userfile(-1);
   putlog(LOG_MISC, "*", _("Restarting..."));
-  wipe_timers(interp, &utimer);
-  wipe_timers(interp, &timer);
   do_restart = -1;
   return TCL_OK;
 }
----------------------- End of diff -----------------------



More information about the Changes mailing list