[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Sat Oct 13 23:45:01 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-14 04:44:47 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     configure.in src/Makefile.am src/main.c src/modules.c src/tcl.c
     src/egglib/Makefile.am src/mod/Makefile.am src/mod/module.h

Added files:
     src/registry.c src/registry.h src/script.c src/script_api.h
     src/egglib/msprintf.c src/egglib/msprintf.h src/egglib/mstack.c
     src/egglib/mstack.h

Log message:

Added code for tclscript.mod
Made it compile correctly with configure et al (hopefully...)
Removed stuff for encodings from tcl.c
egglib/msprintf - like sprintf but mallocs a big enough buffer for you (no overruns, no truncated data)
egglib/mstack - simple stack structure (push, pop) that grows with malloc and is accessible in array form

---------------------- diff included ----------------------
Index: eggdrop1.7/configure.in
diff -u eggdrop1.7/configure.in:1.50 eggdrop1.7/configure.in:1.51
--- eggdrop1.7/configure.in:1.50	Sat Oct 13 16:36:58 2001
+++ eggdrop1.7/configure.in	Sat Oct 13 23:44:36 2001
@@ -147,6 +147,6 @@
 AC_SUBST(ac_aux_dir)
 
 # FIXME: module's Makefiles list will prolly become dynamic
-AC_OUTPUT([Makefile doc/Makefile scripts/Makefile src/Makefile src/compat/Makefile src/egglib/Makefile src/mod/Makefile src/adns/Makefile src/mod/Makefile intl/Makefile po/Makefile.in src/mod/assoc.mod/Makefile src/mod/blowfish.mod/Makefile src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/filesys.mod/Makefile src/mod/irc.mod/Makefile src/mod/notes.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/uptime.mod/Makefile src/mod/woobie.mod/Makefile])
+AC_OUTPUT([Makefile doc/Makefile scripts/Makefile src/Makefile src/compat/Makefile src/egglib/Makefile src/mod/Makefile src/adns/Makefile src/mod/Makefile intl/Makefile po/Makefile.in src/mod/assoc.mod/Makefile src/mod/blowfish.mod/Makefile src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/filesys.mod/Makefile src/mod/irc.mod/Makefile src/mod/notes.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/tclscript.mod/Makefile src/mod/transfer.mod/Makefile src/mod/uptime.mod/Makefile src/mod/woobie.mod/Makefile])
 
 EGG_MSG_CONFIGURE_END
Index: eggdrop1.7/src/Makefile.am
diff -u eggdrop1.7/src/Makefile.am:1.7 eggdrop1.7/src/Makefile.am:1.8
--- eggdrop1.7/src/Makefile.am:1.7	Sat Oct 13 16:36:59 2001
+++ eggdrop1.7/src/Makefile.am	Sat Oct 13 23:44:36 2001
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.7 2001/10/13 21:36:59 tothwolf Exp $
+# $Id: Makefile.am,v 1.8 2001/10/14 04:44:36 stdarg Exp $
 
 # FIXME: optionally allow a system wide install by ignoring the line below.
 bindir    = $(exec_prefix)
@@ -54,6 +54,11 @@
 		net.c \
 		patch.h \
 		proto.h \
+		registry.c \
+		registry.h \
+		script.c \
+		script.h \
+		script_api.h \
 		stat.h \
 		tandem.h \
 		tcl.c \
@@ -84,6 +89,7 @@
 		"-dlopen" mod/notes.mod/notes.la \
 		"-dlopen" mod/server.mod/server.la \
 		"-dlopen" mod/share.mod/share.la \
+		"-dlopen" mod/tclscript.mod/tclscript.la \
 		"-dlopen" mod/transfer.mod/transfer.la \
 		"-dlopen" mod/uptime.mod/uptime.la \
 		"-dlopen" mod/woobie.mod/woobie.la \
@@ -102,6 +108,7 @@
 			src/mod/notes.la \
 			src/mod/server.la \
 			src/mod/share.la \
+			src/mod/tclscript.la \
 			src/mod/transfer.la \
 			src/mod/uptime.la \
 			src/mod/woobie.la
Index: eggdrop1.7/src/egglib/Makefile.am
diff -u eggdrop1.7/src/egglib/Makefile.am:1.1 eggdrop1.7/src/egglib/Makefile.am:1.2
--- eggdrop1.7/src/egglib/Makefile.am:1.1	Tue Oct  9 20:20:10 2001
+++ eggdrop1.7/src/egglib/Makefile.am	Sat Oct 13 23:44:37 2001
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.1 2001/10/10 01:20:10 ite Exp $
+# $Id: Makefile.am,v 1.2 2001/10/14 04:44:37 stdarg Exp $
 
 ## libcompat is built as convenience library
 
@@ -8,11 +8,15 @@
 
 noinst_LTLIBRARIES = libegg.la
 libegg_la_SOURCES = avl.c \
-               avl.h \
-	       hash_table.c \
-	       hash_table.h \
-	       linked_list.c \
-	       linked_list.h \
-	       mempool.c \
-	       mempool.h
+		avl.h \
+		hash_table.c \
+		hash_table.h \
+		linked_list.c \
+		linked_list.h \
+		mempool.c \
+		mempool.h \
+		msprintf.c \
+		msprintf.h \
+		mstack.c \
+		mstack.h
 
Index: eggdrop1.7/src/egglib/msprintf.c
diff -u /dev/null eggdrop1.7/src/egglib/msprintf.c:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/egglib/msprintf.c	Sat Oct 13 23:44:37 2001
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdarg.h>
+
+char *msprintf(char *format, ...)
+{
+	va_list args;
+	char *output;
+	int n, len;
+
+	va_start(args, format);
+	output = (char *)malloc(128);
+	len = 127;
+	while ((n = vsnprintf(output, len, format, args)) < 0 || n >= len) {
+		len *= 2;
+		output = (char *)realloc(output, len+1);
+	}
+	return(output);
+}
Index: eggdrop1.7/src/egglib/msprintf.h
diff -u /dev/null eggdrop1.7/src/egglib/msprintf.h:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/egglib/msprintf.h	Sat Oct 13 23:44:37 2001
@@ -0,0 +1,6 @@
+#ifndef _MSPRINTF_H_
+#define _MSPRINTF_H_
+
+char *msprintf(char *format, ...);
+
+#endif
Index: eggdrop1.7/src/egglib/mstack.c
diff -u /dev/null eggdrop1.7/src/egglib/mstack.c:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/egglib/mstack.c	Sat Oct 13 23:44:37 2001
@@ -0,0 +1,54 @@
+/* Implement a stack based on malloc. */
+
+#include <stdio.h>
+#include "mstack.h"
+
+mstack_t *mstack_new(int initial_size)
+{
+	mstack_t *m;
+
+	if (initial_size <= 0) initial_size = 10;
+	m = (mstack_t *)malloc(sizeof(mstack_t) + sizeof(int) * initial_size);
+	m->len = 0;
+	m->max = initial_size;
+	m->stack = ((int *)m)+3;
+	return(m);
+}
+
+int mstack_destroy(mstack_t *m)
+{
+	if (m->stack != ((int *)m)+3) free(m->stack);
+	free(m);
+	return(0);
+}
+
+void *mstack_push(mstack_t *m, void *item)
+{
+	if (m->len == m->max) mstack_grow(m, 10);
+	m->stack[m->len] = (int) item;
+	m->len++;
+	return(item);
+}
+
+int mstack_pop(mstack_t *m, void **itemptr)
+{
+	if (m->len == 0) return(1);
+	m->len--;
+	*itemptr = (void *)m->stack[m->len];
+	return(0);
+}
+
+int mstack_grow(mstack_t *m, int nsteps)
+{
+	if (m->stack == ((int *)m)+3) {
+		int *newstack;
+
+		newstack = (int *)malloc(sizeof(int) * (m->max + nsteps));
+		memcpy(newstack, m->stack, sizeof(int) * m->max);
+		m->stack = newstack;
+	}
+	else m->stack = (int *)realloc(m->stack, sizeof(int) * (m->max + nsteps));
+
+	m->max += nsteps;
+	return(0);
+}
Index: eggdrop1.7/src/egglib/mstack.h
diff -u /dev/null eggdrop1.7/src/egglib/mstack.h:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/egglib/mstack.h	Sat Oct 13 23:44:37 2001
@@ -0,0 +1,16 @@
+#ifndef _MSTACK_H_
+#define _MSTACK_H_
+
+typedef struct mstack_b {
+	int len;
+	int max;
+	int *stack;
+} mstack_t;
+
+mstack_t *mstack_new(int initial_size);
+int mstack_destroy(mstack_t *m);
+void *mstack_push(mstack_t *m, void *item);
+int mstack_pop(mstack_t *m, void **itemptr);
+int mstack_grow(mstack_t *m, int nsteps);
+
+#endif
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.82 eggdrop1.7/src/main.c:1.83
--- eggdrop1.7/src/main.c:1.82	Sat Oct 13 07:00:22 2001
+++ eggdrop1.7/src/main.c	Sat Oct 13 23:44:36 2001
@@ -5,7 +5,7 @@
  *   command line arguments
  *   context and assert debugging
  *
- * $Id: main.c,v 1.82 2001/10/13 12:00:22 stdarg Exp $
+ * $Id: main.c,v 1.83 2001/10/14 04:44:36 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -638,6 +638,7 @@
 int init_dcc_max(), init_userent(), init_misc(), init_net(),
  init_modules(), init_tcl(int, char **);
 void botnet_init();
+void script_init();
 void init_binds();
 
 void patch(const char *str)
@@ -754,6 +755,7 @@
   if (((int) getuid() == 0) || ((int) geteuid() == 0))
     fatal(_("ERROR: Eggdrop will not run as root!"), 0);
 
+  script_init();
   init_binds();
   init_dcc_max();
   init_userent();
Index: eggdrop1.7/src/mod/Makefile.am
diff -u eggdrop1.7/src/mod/Makefile.am:1.1 eggdrop1.7/src/mod/Makefile.am:1.2
--- eggdrop1.7/src/mod/Makefile.am:1.1	Tue Oct  9 20:20:11 2001
+++ eggdrop1.7/src/mod/Makefile.am	Sat Oct 13 23:44:37 2001
@@ -1,6 +1,6 @@
-# $Id: Makefile.am,v 1.1 2001/10/10 01:20:11 ite Exp $
+# $Id: Makefile.am,v 1.2 2001/10/14 04:44:37 stdarg Exp $
 
 # FIXME: list will prolly become dinamic
-SUBDIRS = assoc.mod blowfish.mod channels.mod compress.mod console.mod ctcp.mod filesys.mod irc.mod notes.mod server.mod share.mod transfer.mod uptime.mod woobie.mod
+SUBDIRS = assoc.mod blowfish.mod channels.mod compress.mod console.mod ctcp.mod filesys.mod irc.mod notes.mod server.mod share.mod tclscript.mod transfer.mod uptime.mod woobie.mod
 
 MAINTAINERCLEANFILES = Makefile.in
Index: eggdrop1.7/src/mod/module.h
diff -u eggdrop1.7/src/mod/module.h:1.64 eggdrop1.7/src/mod/module.h:1.65
--- eggdrop1.7/src/mod/module.h:1.64	Sat Oct 13 10:55:33 2001
+++ eggdrop1.7/src/mod/module.h	Sat Oct 13 23:44:37 2001
@@ -1,7 +1,7 @@
 /*
  * module.h
  *
- * $Id: module.h,v 1.64 2001/10/13 15:55:33 tothwolf Exp $
+ * $Id: module.h,v 1.65 2001/10/14 04:44:37 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -32,6 +32,7 @@
 #include "src/main.h"
 #include "modvals.h"
 #include "src/tandem.h"
+#include "src/registry.h"
 
 /*
  * This file contains all the orrible stuff required to do the lookup
@@ -437,11 +438,15 @@
 #define kill_bot ((void (*)(char *, char *))global[273])
 #define quit_msg ((char *)(global[274]))
 #define add_bind_table2 ((bind_table_t *(*)(const char *, int, char *, int, int))global[275])
+/* 276 - 280 */
 #define del_bind_table2 ((void (*)(bind_table_t *))global[276])
 #define add_builtins2 ((void (*)(bind_table_t *, cmd_t *))global[277])
 #define rem_builtins2 ((void (*)(bind_table_t *, cmd_t *))global[278])
 #define find_bind_table2 ((bind_table_t *(*)(const char *))global[279])
 #define check_bind ((int (*)(bind_table_t *, const char *, struct flag_record *, ...))global[280])
+/* 281 - 285 */
+#define registry_lookup ((int (*)(const char *, const char *, Function *, void **))global[281])
+#define registry_add_simple_chains ((int (*)(registry_simple_chain_t *))global[282])
 
 /* This is for blowfish module, couldnt be bothered making a whole new .h
  * file for it ;)
Index: eggdrop1.7/src/modules.c
diff -u eggdrop1.7/src/modules.c:1.68 eggdrop1.7/src/modules.c:1.69
--- eggdrop1.7/src/modules.c:1.68	Sat Oct 13 10:55:33 2001
+++ eggdrop1.7/src/modules.c	Sat Oct 13 23:44:36 2001
@@ -4,7 +4,7 @@
  * 
  * by Darrin Smith (beldin at light.iinet.net.au)
  * 
- * $Id: modules.c,v 1.68 2001/10/13 15:55:33 tothwolf Exp $
+ * $Id: modules.c,v 1.69 2001/10/14 04:44:36 stdarg Exp $
  */
 /* 
  * Copyright (C) 1997  Robey Pointer
@@ -28,6 +28,7 @@
 #include "main.h"
 #include "modules.h"
 #include "tandem.h"
+#include "registry.h"
 #include <ctype.h>
 
 #include <ltdl.h>
@@ -517,7 +518,10 @@
   (Function) add_builtins2,
   (Function) rem_builtins2,
   (Function) find_bind_table2,
-  (Function) check_bind
+  (Function) check_bind,
+  /* 281 - 285 */
+  (Function) registry_lookup,
+  (Function) registry_add_simple_chains
 };
 
 void init_modules(void)
Index: eggdrop1.7/src/registry.c
diff -u /dev/null eggdrop1.7/src/registry.c:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/registry.c	Sat Oct 13 23:44:36 2001
@@ -0,0 +1,231 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "egglib/hash_table.h"
+typedef int (*Function)();
+#include "registry.h"
+
+typedef struct registry_internal_entry_b {
+	char *key;
+	Function callback;
+	void *client_data;
+	registry_entry_t **main; /* Pointer to the "main" function(s). */
+	int nmain;
+	registry_entry_t **chains; /* Chain functions. */
+	int nchains;
+	Function **listeners; /* Addresses of those who are using this entry. */
+	void ***listener_handles; /* Ditto. */
+	int nlisteners;
+} registry_internal_entry_t;
+
+static int update_listeners(registry_internal_entry_t *internal);
+static int arbitrator(registry_internal_entry_t *internal, ...);
+
+static hash_table_t *registry_table = NULL;
+
+int registry_add(registry_entry_t *entry)
+{
+	registry_internal_entry_t *internal;
+	char *key;
+
+	if (!registry_table) {
+		registry_table = hash_table_create(NULL, NULL, 13, 0);
+	}
+
+	key = (char *)malloc(strlen(entry->class)+strlen(entry->name)+4);
+	sprintf(key, "%s / %s", entry->class, entry->name);
+
+	/* Look up registry entry. */
+	if (hash_table_find(registry_table, key, &internal)) {
+		/* Doesn't exist yet, get a new one. */
+		internal = (registry_internal_entry_t *)malloc(sizeof(*internal));
+		memset(internal, 0, sizeof(*internal));
+		internal->key = key;
+		hash_table_insert(registry_table, key, internal);
+	}
+	else free(key);
+
+	if (entry->flags & REGISTRY_MAIN) {
+		internal->nmain++;
+		internal->main = (registry_entry_t **)realloc(internal->main, internal->nmain * sizeof(void *));
+		internal->main[internal->nmain-1] = entry;
+	}
+	else if (entry->flags & REGISTRY_CHAIN) {
+		internal->nchains++;
+		internal->chains = (registry_entry_t **)realloc(internal->chains, internal->nchains * sizeof(void *));
+		if (entry->flags & REGISTRY_PREPEND) {
+			memmove(internal->chains+1, internal->chains, sizeof(void *) * (internal->nchains-1));
+			internal->chains[0] = entry;
+		}
+		else {
+			internal->chains[internal->nchains-1] = entry;
+		}
+	}
+
+	update_listeners(internal);
+
+	return(0);
+}
+
+int registry_add_table(registry_entry_t *entries)
+{
+	while (entries->callback) {
+		registry_add(entries);
+		entries++;
+	}
+	return(0);
+}
+
+int registry_add_simple_chains(registry_simple_chain_t *entries)
+{
+	FILE *fp;
+	registry_entry_t *entry;
+	char *class;
+
+	/* First entry gives the class. */
+	class = entries->name;
+	entries++;
+	fp = fopen("blah", "w");
+	while (entries->name) {
+		entry = (registry_entry_t *)calloc(1, sizeof(*entry));
+		entry->class = class;
+		entry->name = entries->name;
+		entry->callback = entries->callback;
+		entry->nargs = entries->nargs;
+		entry->flags = REGISTRY_CHAIN;
+		fprintf(fp, "%s\n%s\n%d\n%d\n\n", entry->class, entry->name, entry->nargs, entry->flags);
+		registry_add(entry);
+		entries++;
+	}
+	return(0);
+}
+
+int registry_remove(registry_entry_t *entry)
+{
+	printf("registry_remove(%s, %s)\n", entry->class, entry->name);
+	return(0);
+}
+
+int registry_remove_table(registry_entry_t *entries)
+{
+	while (entries->callback) {
+		registry_remove(entries);
+		entries++;
+	}
+	return(0);
+}
+
+int registry_lookup(const char *class, const char *name, Function *funcptr, void **handleptr)
+{
+	registry_internal_entry_t *internal;
+	char *key;
+
+	key = (char *)malloc(strlen(class)+strlen(name)+4);
+	sprintf(key, "%s / %s", class, name);
+
+        if (!registry_table) {
+                registry_table = hash_table_create(NULL, NULL, 13, 0);
+        }
+
+	if (hash_table_find(registry_table, key, &internal)) {
+		/* Doesn't exist -- create it. */
+                internal = (registry_internal_entry_t *)malloc(sizeof(*internal));
+                memset(internal, 0, sizeof(*internal));
+                internal->key = key;
+                hash_table_insert(registry_table, key, internal);
+		internal->callback = (Function) arbitrator;
+		internal->client_data = (void *)internal;
+	}
+	else free(key);
+
+	*funcptr = internal->callback;
+	*handleptr = internal->client_data;
+
+	internal->nlisteners++;
+	internal->listeners = (Function **)realloc(internal->listeners, internal->nlisteners * sizeof(void *));
+	internal->listener_handles = (void ***)realloc(internal->listener_handles, internal->nlisteners * sizeof(void *));
+	internal->listeners[internal->nlisteners-1] = funcptr;
+	internal->listener_handles[internal->nlisteners-1] = handleptr;
+
+	return(0);
+}
+
+int registry_unlookup(const char *class, const char *name, Function *funcptr, void **handleptr)
+{
+/*
+	memmove(entry->listeners+i, entry->listeners+i+1, (entry->nlisteners-i-1) * sizeof(Function *));
+	entry->nlisteners--;
+	if (!entry->nlisteners) {
+		free(entry->listeners);
+		entry->listeners = NULL;
+	}
+*/
+	return(0);
+}
+
+static int update_listeners(registry_internal_entry_t *internal)
+{
+	registry_entry_t *entry;
+	int i;
+
+	if (internal->nmain != 0 && internal->nchains == 0) {
+		/* If there's just a main function, give them that. */
+		internal->callback = internal->main[internal->nmain-1]->callback;
+		internal->client_data = internal->main[internal->nmain-1]->client_data;
+	}
+	else {
+		/* Otherwise we use an arbitrator. */
+		internal->callback = (Function) arbitrator;
+		internal->client_data = (void *)internal;
+	}
+
+	for (i = 0; i < internal->nlisteners; i++) {
+		*(internal->listeners[i]) = internal->callback;
+		*(internal->listener_handles[i]) = internal->client_data;
+	}
+	return(0);
+}
+
+static int arbitrator(registry_internal_entry_t *internal, ...)
+{
+	registry_entry_t *entry;
+	int i, retval;
+	int *al = (int *)&internal;
+
+	/* Call chains backwards (first-in-last-out). */
+	for (i = internal->nchains-1; i >= 0; i--) {
+		entry = internal->chains[i];
+		entry->action = 0;
+		switch (entry->nargs) {
+			case 1: entry->callback(entry); break;
+			case 2: entry->callback(entry, al[1]); break;
+			case 3: entry->callback(entry, al[1], al[2]); break;
+			case 4: entry->callback(entry, al[1], al[2], al[3]); break;
+			case 5: entry->callback(entry, al[1], al[2], al[3], al[4]); break;
+			case 6: entry->callback(entry, al[1], al[2], al[3], al[4], al[5]); break;
+			case 7: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6]); break;
+			case 8: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7]); break;
+			case 9: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7], al[8]); break;
+			case 10: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7], al[8], al[9]);
+		}
+		if (entry->action & REGISTRY_HALT) break;
+	}
+
+	if (internal->nmain != 0) {
+		entry = internal->main[internal->nmain-1];
+		switch (entry->nargs) {
+			case 1: entry->callback(entry); break;
+			case 2: entry->callback(entry, al[1]); break;
+			case 3: entry->callback(entry, al[1], al[2]); break;
+			case 4: entry->callback(entry, al[1], al[2], al[3]); break;
+			case 5: entry->callback(entry, al[1], al[2], al[3], al[4]); break;
+			case 6: entry->callback(entry, al[1], al[2], al[3], al[4], al[5]); break;
+			case 7: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6]); break;
+			case 8: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7]); break;
+			case 9: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7], al[8]); break;
+			case 10: entry->callback(entry, al[1], al[2], al[3], al[4], al[5], al[6], al[7], al[8], al[9]);
+		}
+		return((int)entry->return_value);
+	}
+	return(0);
+}
Index: eggdrop1.7/src/registry.h
diff -u /dev/null eggdrop1.7/src/registry.h:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/registry.h	Sat Oct 13 23:44:36 2001
@@ -0,0 +1,42 @@
+#ifndef _REGISTRY_H_
+#define _REGISTRY_H_
+
+#define REGISTRY_DONT_CREATE	1
+#define REGISTRY_PREPEND	2
+#define REGISTRY_CHAIN		4
+#define REGISTRY_MAIN		8
+#define REGISTRY_DEFAULT	8
+
+#define REGISTRY_TEMP_LISTENER	1
+
+#define REGISTRY_HALT		1
+#define REGISTRY_SKIP_MAIN	2
+
+typedef struct registry_entry_b {
+	char *class;
+	char *name;
+	Function callback;
+	void *client_data;
+	int nargs;
+	int flags;
+	int action;
+	void *return_value;
+} registry_entry_t;
+
+typedef struct registry_simple_chain_b {
+	char *name;
+	Function callback;
+	int nargs;
+} registry_simple_chain_t;
+
+#ifndef MAKING_MODS
+int registry_add(registry_entry_t *entry);
+int registry_add_table(registry_entry_t *entries);
+int registry_add_simple_chains(registry_simple_chain_t *table);
+int registry_remove(registry_entry_t *entry);
+int registry_remove_table(registry_entry_t *entries);
+int registry_lookup(const char *class, const char *name, Function *funcptr, void **handeptr);
+int registry_unlookup(const char *class, const char *name, Function *funcptr, void **handleptr);
+#endif /* MAKING_MODS */
+
+#endif /* _REGISTRY_H_ */
Index: eggdrop1.7/src/script.c
diff -u /dev/null eggdrop1.7/src/script.c:1.1
--- /dev/null	Sat Oct 13 23:44:47 2001
+++ eggdrop1.7/src/script.c	Sat Oct 13 23:44:36 2001
@@ -0,0 +1,82 @@
+typedef int (*Function)();
+#include "registry.h"
+#include "script_api.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;
+
+int script_init()
+{
+	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);
+}
+
+int script_link_int_table(script_int_t *table)
+{
+	script_int_t *intval;
+
+	for (intval = table; intval->class && intval->name; intval++) {
+		link_int(link_int_h, intval, 0);
+	}
+	return(0);
+
+}
+
+int script_unlink_int_table(script_int_t *table)
+{
+	script_int_t *intval;
+
+	for (intval = table; intval->class && intval->name; intval++) {
+		unlink_int(unlink_int_h, intval);
+	}
+	return(0);
+
+}
+
+int script_link_str_table(script_str_t *table)
+{
+	script_str_t *str;
+
+	for (str = table; str->class && str->name; str++) {
+		link_str(link_str_h, str, 0);
+	}
+	return(0);
+
+}
+
+int script_unlink_str_table(script_str_t *table)
+{
+	script_str_t *str;
+
+	for (str = table; str->class && str->name; str++) {
+		unlink_str(unlink_str_h, str);
+	}
+	return(0);
+
+}
+
+int script_create_cmd_table(script_command_t *table)
+{
+	script_command_t *cmd;
+
+	for (cmd = table; cmd->class && cmd->name; cmd++) {
+		create_cmd(create_cmd_h, cmd);
+	}
+	return(0);
+}
+
+int script_delete_cmd_table(script_command_t *table)
+{
+
+	script_command_t *cmd;
+
+	for (cmd = table; cmd->class && cmd->name; cmd++) {
+		delete_cmd(delete_cmd_h, cmd);
+	}
+	return(0);
+}
Index: eggdrop1.7/src/script_api.h
diff -u /dev/null eggdrop1.7/src/script_api.h:1.1
--- /dev/null	Sat Oct 13 23:44:48 2001
+++ eggdrop1.7/src/script_api.h	Sat Oct 13 23:44:36 2001
@@ -0,0 +1,74 @@
+/* This file contains the stuff you need to use the scripting modules. */
+
+#ifndef _SCRIPT_API_H_
+#define _SCRIPT_API_H_
+
+/* How about some macros for setting return values? */
+#define SCRIPT_RETURN_INT(x) retval->type = SCRIPT_INTEGER, retval->intval = x
+#define SCRIPT_RETURN_STR(s) retval->type = SCRIPT_STRING, retval->str = s
+
+/* Flags for commands. */
+#define SCRIPT_WANTS_CD	1
+
+/* Flags for linked variables. */
+#define SCRIPT_READ_ONLY	1
+
+/* Flags for variables (check out struct script_var_t) */
+#define SCRIPT_STATIC	1
+#define SCRIPT_STRING	2
+#define SCRIPT_INTEGER	4
+#define SCRIPT_LIST	8
+#define SCRIPT_ARRAY	16
+#define SCRIPT_VARRAY	32
+#define SCRIPT_POINTER	64
+#define SCRIPT_CALLBACK	128
+#define SCRIPT_ERROR	256
+
+typedef struct script_callback_b {
+	int (*callback)();
+	void *callback_data;
+	int (*delete)();
+	void *delete_data;
+} 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;
+} script_var_t;
+
+typedef struct script_int_b {
+	char *class;
+	char *name;
+	int *ptr;
+} script_int_t;
+
+typedef struct script_str_b {
+	char *class;
+	char *name;
+	char **ptr;
+} script_str_t;
+
+typedef struct script_command_b {
+	char *class;
+	char *name;
+	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 flags;
+} script_command_t;
+
+#endif
Index: eggdrop1.7/src/tcl.c
diff -u eggdrop1.7/src/tcl.c:1.45 eggdrop1.7/src/tcl.c:1.46
--- eggdrop1.7/src/tcl.c:1.45	Fri Oct 12 10:50:26 2001
+++ eggdrop1.7/src/tcl.c	Sat Oct 13 23:44:36 2001
@@ -4,7 +4,7 @@
  *   Tcl initialization
  *   getting and setting Tcl/eggdrop variables
  *
- * $Id: tcl.c,v 1.45 2001/10/12 15:50:26 tothwolf Exp $
+ * $Id: tcl.c,v 1.46 2001/10/14 04:44:36 stdarg Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -479,11 +479,6 @@
  */
 void init_tcl(int argc, char **argv)
 {
-#if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 1) || (TCL_MAJOR_VERSION >= 9)
-  const char *encoding;
-  int i;
-  char *langEnv;
-#endif
 #ifndef HAVE_PRE7_5_TCL
   int j;
   char pver[1024] = "";
@@ -513,79 +508,6 @@
 
   /* Setup script library facility */
   Tcl_Init(interp);
-
-/* Code based on Tcl's TclpSetInitialEncodings() */
-#if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 1) || (TCL_MAJOR_VERSION >= 9)
-  /* Determine the current encoding from the LC_* or LANG environment
-   * variables.
-   */
-  langEnv = getenv("LC_ALL");
-  if (langEnv == NULL || langEnv[0] == '\0') {
-    langEnv = getenv("LC_CTYPE");
-  }
-  if (langEnv == NULL || langEnv[0] == '\0') {
-    langEnv = getenv("LANG");
-  }
-  if (langEnv == NULL || langEnv[0] == '\0') {
-    langEnv = NULL;
-  }
-
-  encoding = NULL;
-  if (langEnv != NULL) {
-    for (i = 0; localeTable[i].lang != NULL; i++)
-      if (strcmp(localeTable[i].lang, langEnv) == 0) {
-	encoding = localeTable[i].encoding;
-	break;
-      }
-
-    /* There was no mapping in the locale table.  If there is an
-     * encoding subfield, we can try to guess from that.
-     */
-    if (encoding == NULL) {
-      char *p;
-
-      for (p = langEnv; *p != '\0'; p++) {
-        if (*p == '.') {
-          p++;
-          break;
-        }
-      }
-      if (*p != '\0') {
-        Tcl_DString ds;
-        Tcl_DStringInit(&ds);
-        Tcl_DStringAppend(&ds, p, -1);
-
-        encoding = Tcl_DStringValue(&ds);
-        Tcl_UtfToLower(Tcl_DStringValue(&ds));
-        if (Tcl_SetSystemEncoding(NULL, encoding) == TCL_OK) {
-          Tcl_DStringFree(&ds);
-          goto resetPath;
-        }
-        Tcl_DStringFree(&ds);
-        encoding = NULL;
-      }
-    }
-  }
-
-  if (encoding == NULL) {
-    encoding = "iso8859-1";
-  }
-
-  Tcl_SetSystemEncoding(NULL, encoding);
-
-resetPath:
-
-  /* Initialize the C library's locale subsystem. */
-  setlocale(LC_CTYPE, "");
-
-  /* In case the initial locale is not "C", ensure that the numeric
-   * processing is done in "C" locale regardless. */
-  setlocale(LC_NUMERIC, "C");
-
-  /* Keep the iso8859-1 encoding preloaded.  The IO package uses it for
-   * gets on a binary channel. */
-  Tcl_GetEncoding(NULL, "iso8859-1");
-#endif
 
 #ifndef HAVE_PRE7_5_TCL
   /* Add eggdrop to Tcl's package list */
----------------------- End of diff -----------------------



More information about the Changes mailing list