[cvslog] (2004-09-29 15:38:49 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Wed Sep 29 09:38:49 CST 2004


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2004-09-29 15:38:49 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/eggdrop/Makefile.am lib/eggdrop/eggdrop.c lib/eggdrop/help.c
     lib/eggdrop/help.h lib/eggdrop/xml.c lib/eggdrop/xml.h
     src/core_party.c src/main.c

Added files:
     modules/server/help/en_US/commands.xml

Log message:



---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/Makefile.am
diff -u eggdrop1.9/lib/eggdrop/Makefile.am:1.37 eggdrop1.9/lib/eggdrop/Makefile.am:1.38
--- eggdrop1.9/lib/eggdrop/Makefile.am:1.37	Sun Sep 26 04:42:08 2004
+++ eggdrop1.9/lib/eggdrop/Makefile.am	Wed Sep 29 10:38:39 2004
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.37 2004/09/26 09:42:08 stdarg Exp $
+# $Id: Makefile.am,v 1.38 2004/09/29 15:38:39 stdarg Exp $
 
 MAINTAINERCLEANFILES	= Makefile.in
 
@@ -21,6 +21,7 @@
 			config.c config.h \
 			eggdrop.c eggdrop.h \
 			dns.c dns.h \
+			help.c help.h \
 			ident.c ident.h \
 			module.c module.h \
 			net.c net.h \
Index: eggdrop1.9/lib/eggdrop/eggdrop.c
diff -u eggdrop1.9/lib/eggdrop/eggdrop.c:1.22 eggdrop1.9/lib/eggdrop/eggdrop.c:1.23
--- eggdrop1.9/lib/eggdrop/eggdrop.c:1.22	Sun Sep 26 04:42:09 2004
+++ eggdrop1.9/lib/eggdrop/eggdrop.c	Wed Sep 29 10:38:39 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: eggdrop.c,v 1.22 2004/09/26 09:42:09 stdarg Exp $";
+static const char rcsid[] = "$Id: eggdrop.c,v 1.23 2004/09/29 15:38:39 stdarg Exp $";
 #endif
 
 #include <stdlib.h>
@@ -42,6 +42,7 @@
 	script_init();
 	partyline_init();
 	module_init();
+	help_init();
 	BT_event = bind_table_add(BTN_EVENT, 1, "s", MATCH_MASK, BIND_STACKABLE);	/* DDD	*/
 	
 	return 1;
Index: eggdrop1.9/lib/eggdrop/help.c
diff -u eggdrop1.9/lib/eggdrop/help.c:1.16 eggdrop1.9/lib/eggdrop/help.c:1.17
--- eggdrop1.9/lib/eggdrop/help.c:1.16	Sun Jul 11 08:54:46 2004
+++ eggdrop1.9/lib/eggdrop/help.c	Wed Sep 29 10:38:39 2004
@@ -17,690 +17,229 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-/* XXX: Todo
- * XXX:   * 1.6: Output ordered by flags (Commands for Owners, Masters, ...)
- * XXX:   * 1.6: Help formatting (dunno how to support that and if its really needed)
- * XXX:   * Make help_path, help_lang_default, help_lang_fallback configurable
- */
- 
 #ifndef lint
-static const char rcsid[] = "$Id: help.c,v 1.16 2004/07/11 13:54:46 darko Exp $";
+static const char rcsid[] = "$Id: help.c,v 1.17 2004/09/29 15:38:39 stdarg Exp $";
 #endif
 
-#include <sys/types.h>
-#include <ctype.h>			/* toupper		*/
-#include <dirent.h>			/* opendir, closedir	*/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <eggdrop/eggdrop.h>
 
+static help_file_t **help_files = NULL;
+static int nhelp_files = 0;
 
-/* Hash table to associate help entry names with help entries. */
-static hash_table_t *entries = NULL;
-int nentries = 0;
-
-/* Hash table to associate help sections with help entries */
-static hash_table_t *sections = NULL;
-int nsections = 0;
+static help_section_t *sections = NULL;
+static int nsections = 0;
 
 /* XXX: make this configurable(just how?) */
-static char *help_path = "help/";
-static char *help_lang_default = "en_EN";
-static char *help_lang_fallback = "en_EN";
+static char *help_path = NULL;
+static char *help_lang_default = NULL;
+static char *help_lang_fallback = "en_US";
 
-static help_entry_t *help_load_entry(const char *module, const char *filename, xml_node_t *node);
-static void help_delete_entry(help_entry_t *entry);
-static help_section_t *help_load_section(help_section_t *section, const char *module, const char *filename, xml_node_t *node);
-static void help_delete_section(help_section_t *section);
-
-static int help_load_internal(const char *module, const char *filename);
-static int help_unload_internal(const char *module, const char *filename);
-
-typedef struct
-{
-	partymember_t	*member;
-	const char	*text;
-	int		 hits;
-} help_search_t;
-
-typedef struct
+int help_init()
 {
-	const char	*filename;
-	const char	*module;
-} help_unload_t;
-
-static void unload_entry(const char *name, help_entry_t **e, help_unload_t *ul);
-
-int help_init(void)
-{
-	/* unload all helps */
-
-	entries = hash_table_create(NULL, NULL, HELP_HASH_SIZE, 
-			HASH_TABLE_STRINGS);
-	sections = hash_table_create(NULL, NULL, HELP_HASH_SIZE,
-			HASH_TABLE_STRINGS);
-
-	bind_add_simple(BTN_LOAD_MODULE, NULL, "*", (Function)help_load_by_module);
-	bind_add_simple(BTN_UNLOAD_MODULE, NULL, "*", (Function)help_unload_by_module);
-
-	return 0;
+	help_path = strdup("help/");
+	help_lang_default = strdup("en_US");
+	return(0);
 }
 
-int help_shutdown(void)
+int help_shutdown()
 {
-        help_unload_t unload;
-
-        unload.module = NULL;
-        unload.filename = NULL;
-
-        hash_table_walk(entries,
-                (hash_table_node_func)unload_entry, &unload);
-
-	bind_rem_simple(BTN_LOAD_MODULE, NULL, "*", (Function)help_load_by_module);
-	bind_rem_simple(BTN_UNLOAD_MODULE, NULL, "*", (Function)help_unload_by_module);
-
-	hash_table_delete(entries);
-	hash_table_delete(sections);
-
-	return 0;
+	return(0);
 }
 
-int help_count_sections(void)
+int help_set_default_path(const char *path)
 {
-	return nsections;
+	str_redup(&help_path, path);
+	return(0);
 }
 
-int help_count_entries(void)
+int help_set_default_lang(const char *lang)
 {
-	return nentries;
+	str_redup(&help_lang_default, lang);
+	return(0);
 }
 
-int help_load_by_module(const char *mod)
+char *help_parse_syntax(xml_node_t *node)
 {
-	char buf[255];
-	int ret[3];
-
-	snprintf(buf, sizeof(buf), "%s.xml", mod);
-	ret[0] = help_load_internal(mod, buf);
-	
-	snprintf(buf, sizeof(buf), "%s-commands.xml", mod);
-	ret[1] = help_load_internal(mod, buf);
+	xml_node_t *arg;
+	char *name, *syntax, *args, *args2, *argname;
+	int optional;
 
-	snprintf(buf, sizeof(buf), "%s-variables.xml", mod);
-	ret[2] = help_load_internal(mod, buf);
-
-	if (ret[0] || ret[1] || ret[2]) 
-		putlog(LOG_MISC, "*", "Help loaded: %s", mod);
-		
-	return (ret[0] || ret[1] || ret[2]);
+	xml_node_get_vars(node, "sn", "name", &name, "args.arg", &arg);
+	args = strdup("");
+	for (; arg; arg = arg->next_sibling) {
+		xml_node_get_vars(arg, "si", "name", &argname, "optional", &optional);
+		if (!name) continue;
+		if (optional) args2 = egg_mprintf("%s [%s]", args, argname);
+		else args2 = egg_mprintf("%s <%s>", args, argname);
+		free(args);
+		args = args2;
+	}
+	syntax = egg_mprintf("%s%s", name, args);
+	free(args);
+	return(syntax);
 }
 
-int help_unload_by_module(const char *mod)
+help_summary_t *help_summarize_entry(xml_node_t *node)
 {
-	char buf[255];
-	int ret[3];
+	help_summary_t *entry;
+	char *name, *summary, *syntax;
+	int len;
 
-	snprintf(buf, sizeof(buf), "%s.xml", mod);
-	ret[0] = help_unload_internal(mod, buf);
-	
-	snprintf(buf, sizeof(buf), "%s-commands.xml", mod);
-	ret[1] = help_unload_internal(mod, buf);
+	xml_node_get_vars(node, "ss", "name", &name, "summary", &summary);
+	if (!name) return(NULL);
 
-	snprintf(buf, sizeof(buf), "%s-variables.xml", mod);
-	ret[2] = help_unload_internal(mod, buf);
+	syntax = help_parse_syntax(node);
 
-	if (ret[0] || ret[1] || ret[2]) 
-		putlog(LOG_MISC, "*", "Help unloaded: %s", mod);
-		
-	return (ret[0] || ret[1] || ret[2]);
+	/* Allocate everything at once since it's static. */
+	len = strlen(name) + strlen(syntax);
+	if (summary) len += strlen(summary);
+	entry = malloc(sizeof(*entry) + len + 3);
+	entry->name = ((char *)entry) + sizeof(*entry);
+	entry->syntax = entry->name + strlen(name)+1;
+	entry->summary = entry->syntax + strlen(syntax)+1;
+	strcpy(entry->name, name);
+	strcpy(entry->syntax, syntax);
+	if (summary) strcpy(entry->summary, summary);
+	else entry->summary[0] = 0;
+	free(syntax);
+	return(entry);
 }
 
-static void help_load_description(help_desc_t *desc, xml_node_t *parent)
+int help_parse_file(const char *fname)
 {
-	char *text;
-	char *ptr;
-	int indent = -1, i;
-
-	desc->lines = NULL;
-	desc->nlines = 0;
-
-	if (parent == NULL)
-		return;
-
-	text = (char *)xml_get_text_str(parent, NULL);
-	if (text == NULL || !*text)
-		return;
-
-	do {
-		if (indent == -1) {
-			for (indent = 0; (*text == ' ' || *text == '\t'); indent++)
-				text++;
-		} else {
-			for (i = 0; (*text == ' ' || *text == '\t') && i < indent; i++)
-				text++;
-		}
-		
-		/* I have those dual handlings of different line breaks... */
-		ptr = strchr(text, '\r');		
-		if (ptr == NULL)
-			ptr = strchr(text, '\n');
-		if (ptr != NULL)
-			text [(size_t)(ptr - text)] = '\0';
-
-		/* Skip empty first lines */
-		if (desc->nlines == 0 && strlen(text) == 0) {
-			indent = -1;
-		} else {	
-			desc->lines = realloc(desc->lines, 
-				(desc->nlines + 1) * sizeof(char *));
-			desc->lines[desc->nlines++] = strdup(text);
-		}
-
-		if (ptr == NULL)
-			break;
-
-		text +=(size_t)(ptr - text) + 1;
-		if (text [-1] == '\r' && text[0] == '\n')
-			text++;
-	} while(1);
-}
-
-static char *help_new_syntax(xml_node_t *node)
-{
-	xml_node_t *args, *arg;
-	char buf[255];
-	const char *name, *optional;
+	xml_node_t *root = xml_parse_file(fname);
+	xml_node_t *node;
+	char *secname;
+	help_summary_t *entry;
+	help_section_t *section;
 	int i;
-	size_t len;	
-	
-	args = xml_node_lookup(node, 0, "args", 0);
-	if (args == NULL)
-		return NULL;
-	
-	len = 0;	
-	memset(buf, 0, sizeof(buf));
-	
-	for (i = 0; i < args->nchildren; i++) {
-		arg = args->children[i];
-		if (0 != strcmp(arg->name, "arg"))
-			continue;
-			
-		name = xml_get_text_str(arg, NULL);
-		optional = xml_get_attr_str(arg, "optional", NULL);
 
-		if (*buf) {
-			strcat(buf + len, " "); len++;
-		}
-				
-		if (len + strlen(name) + 2 > sizeof(buf))
-			break;
-		
-		if (optional == NULL || (optional && 0 == strcmp(optional, "no")))
-			sprintf(buf + len, "<%s>", name);
-		else
-			sprintf(buf + len, "[%s]", name);
-			
-		len += strlen(name) + 2;
-	}
-	
-	return strdup(buf);
-}
-
-static help_entry_t *help_load_entry(const char *module, const char *filename, xml_node_t *node)
-{
-	help_entry_t *entry;
-	int i;
-	
-	entry = malloc(sizeof(help_entry_t));
-	memset(entry, 0, sizeof(help_entry_t));
-
-	str_redup(&entry->name, xml_get_attr_str(node, "name", NULL));
-	str_redup(&entry->flags, xml_get_attr_str(node, "flags", NULL));
-
-	entry->type = strdup(node->name);
-	entry->type[0] = toupper(entry->type[0]);
-	
-	entry->module = strdup(module);
-	entry->filename = strdup(filename);
-	
-	if (0 == strcmp(entry->type, "Command")) {
-		entry->ext.command.syntax = help_new_syntax(node);
-	} else if (0 == strcmp(entry->type, "Variable")) {
-		str_redup(&entry->ext.variable.path, xml_get_attr_str(node, "path", NULL));
-		str_redup(&entry->ext.variable.type, xml_get_attr_str(node, "type", NULL));		
-	
-	}
+	if (!root) return(-1);
 
-	help_load_description(&entry->desc, xml_node_lookup(node, 0, "description", 0, NULL));
+	xml_node_get_vars(root, "sn", "section", &secname, "help", &node);
+	if (!secname || !node) return(-1);
 
-	entry->seealso = NULL;
-	entry->nseealso = 0;
-	
-	for (i = 0; i < node->nchildren; i++) {
-		if (0 != strcmp(node->children[i]->name, "seealso"))
-			continue;
-
-		entry->seealso = realloc(entry->seealso, sizeof(char *) *
-					(entry->nseealso + 1));
-		entry->seealso [entry->nseealso++] = strdup(xml_get_text_str(node->children[i], NULL));
+	for (i = 0; i < nsections; i++) {
+		if (!strcasecmp(sections[i].name, secname)) break;
 	}
-
-	/* add to hash table */
-	hash_table_insert(entries, entry->name, entry);
-	
-	nentries++;
-	
-	return entry;
-}
-
-help_entry_t *help_lookup_entry(const char *name)
-{
-	help_entry_t *entry = NULL;
-	if (hash_table_find(entries, name, &entry) != 0)
-		return NULL;
-	return entry;
-}
-
-static void help_delete_entry(help_entry_t *entry)
-{
-	int i;
-
-	if (entry->name) free(entry->name);
-	if (entry->filename) free(entry->filename);
-	if (entry->flags) free(entry->flags);
-	if (entry->module) free(entry->module);
-
-	if (0 == strcmp(entry->type, "Command")) {
-		if (entry->ext.command.syntax) free(entry->ext.command.syntax);
-	} else if (0 == strcmp(entry->type, "Variable")) {	
-		if (entry->ext.variable.type) free(entry->ext.variable.type);
-		if (entry->ext.variable.path) free(entry->ext.variable.path);
+	if (i == nsections) {
+		sections = realloc(sections, sizeof(*sections) * (nsections+1));
+		sections[nsections].name = strdup(secname);
+		sections[nsections].entries = NULL;
+		sections[nsections].nentries = 0;
+		nsections++;
+	}
+	section = sections+i;
+
+	help_files = realloc(help_files, sizeof(*help_files) * (nhelp_files+1));
+	help_files[nhelp_files] = malloc(sizeof(**help_files));
+	help_files[nhelp_files]->name = strdup(fname);
+	help_files[nhelp_files]->ref = 0;
+
+	for (; node; node = node->next_sibling) {
+		entry = help_summarize_entry(node);
+		if (!entry) continue;
+		entry->file = help_files[nhelp_files];
+		help_files[nhelp_files]->ref++;
+		section->entries = realloc(section->entries, sizeof(entry) * (section->nentries+1));
+		section->entries[section->nentries] = entry;
+		section->nentries++;
 	}
-
-	if (entry->type) free(entry->type);
-	
-	for (i = 0; i < entry->nseealso; i++)
-		free(entry->seealso[i]);
-	if (entry->seealso) free(entry->seealso);
-
-	for (i = 0; i < entry->desc.nlines; i++)
-		free(entry->desc.lines[i]);
-	if (entry->desc.lines) free(entry->desc.lines);
-
-	free(entry);
-	
-	nentries--;
+	nhelp_files++;
+	return(0);
 }
 
-static void help_delete_section(help_section_t *section)
+help_summary_t *help_lookup_summary(const char *name)
 {
-	int i;
-	
-	for (i = 0; i < section->nentries; i++)
-		help_delete_entry(section->entries[i]);
-	if (section->entries) free(section->entries);
-
-        for (i = 0; i < section->desc.nlines; i++)
-                free(section->desc.lines[i]);
-        if (section->desc.lines) free(section->desc.lines);
-
-	free(section->name);
-	free(section);
-	
-	nsections--;	
-}
+	int i, j;
+	help_section_t *section;
 
-static help_section_t *help_load_section(help_section_t *section,
-			const char *module, const char *filename, xml_node_t *node)
-{
-	xml_node_t *child;
-	help_entry_t *entry;
-	int i;
-			
-	if (section == NULL) {
-		section = malloc(sizeof(help_section_t));
-		memset(section, 0, sizeof(help_section_t));
-		str_redup(&section->name, xml_get_attr_str(node, "name", NULL));
-	
-		section->nentries = 0;
-		section->entries = NULL;
-	
-		help_load_description(&section->desc, xml_node_lookup(node, 0, "description", 0, NULL));
-	
-		/* add to hash table */
-		hash_table_insert(sections, section->name, section);
-		
-		nsections++;		
-	}
-	
-	/* load entries */
-	for (i = 0; i < node->nchildren; i++) {
-		const char *name;
-	
-		/* we just want <command /> or <variable /> tags */
-		child = node->children[i];
-		if (0 != strcmp(child->name, "command")
-			&& 0 != strcmp(child->name, "variable"))
-			continue;	
-			
-		name = xml_get_attr_str(child, "name", NULL);
-		if (name == NULL)
-			continue;
-			
-		entry = help_lookup_entry(name);
-		if (entry != NULL) {
-			/* XXX: perhaps allow or overwrite multiple entries? */
-			putlog(LOG_MISC, "*", _("Duplicate help entry: '%s'."), name);	
-			continue;
+	for (i = 0; i < nsections; i++) {
+		section = sections+i;
+		for (j = 0; j < section->nentries; j++) {
+			if (!strcasecmp(section->entries[j]->name, name)) {
+					return(section->entries[j]);
+			}
 		}
-		
-		/* create entry */
-		entry = help_load_entry(module, filename, child);
-		if (entry == NULL)
-			continue;			
-
-
-		entry->section = section;
-		
-		/* add to section */
-		section->entries = realloc(section->entries, 
-					sizeof(help_entry_t *) *
-						(section->nentries + 1));
-		section->entries[section->nentries++] = entry;
 	}
-	
-	return section;
+	return(NULL);
 }
 
-help_section_t *help_lookup_section(const char *name)
+help_entry_t *help_lookup_entry(const char *name)
 {
-	help_section_t *section = NULL;
-	if (hash_table_find(sections, name, &section) != 0)
-		return NULL;
-	return section;
+	return(NULL);
 }
 
-static FILE *help_open_localized(char *buf, size_t size, const char *filename)
+static void localized_help_fname(char *buf, size_t size, const char *filename)
 {
 	char *lang;
 	char *pos;
-	FILE *fd;
 
 	lang = getenv("LANG");
-	if (lang != NULL) {
+	if (lang) {
+		lang = strdup(lang);
 		pos = strchr(lang, '.');
-		if (pos == NULL)
-			lang = help_lang_default;
-		else
-			lang[(pos - lang)] = '\0';
+		if (pos == NULL) {
+			free(lang);
+			lang = strdup(help_lang_default);
+		}
+		else *pos = 0;
 	} else {
-		lang = help_lang_default;
+		lang = strdup(help_lang_default);
 	}
 
-
 	snprintf(buf, size, "%s/%s/%s", help_path, lang, filename);
-
-	/* try to open it */
-	fd = fopen(buf, "r");
-	if (fd != NULL)
-		return fd;
-
-	/* no, try fallback variant */
-	if (strcmp(lang, help_lang_fallback) == 0)
-		return NULL;
-	snprintf(buf, size, "%s/%s/%s", help_path, help_lang_fallback, filename);
-
-	return fopen(buf, "r");
-}
-
-static int help_load_internal(const char *module, const char *filename)
-{
-	xml_node_t *doc, *root, *node;
-	char buf[255];
-	const char *name;
-	FILE *fd;
-	int i;
-	
-	/* load xml document */
-	fd = help_open_localized(buf, sizeof(buf), filename); 
-	if (fd == NULL)
-		return 0;
-	if (xml_load(fd, &doc, XML_NONE) != 0)
-		return 0;
-	fclose(fd);
-	
-	root = xml_root_element(doc);
-	for (i = 0; i < root->nchildren; i++) {
-
-		/* we just want <section /> tags */
-		node = root->children[i];
-		if (0 != strcmp(node->name, "section"))
-			continue;
-			
-		name = xml_get_attr_str(node, "name", NULL);
-		if (name == NULL)
-			continue;
-			
-		/* load section */
-		help_load_section(
-			help_lookup_section(name), module, buf, node);
-	}
-	
-	xml_node_delete(doc);
-
-	return 1;
-}
-
-int help_load(const char *filename)
-{
-	return help_load_internal(NULL, filename);
+	free(lang);
 }
 
-static void unload_entry(const char *name, help_entry_t **e, help_unload_t *ul)
+int help_load_by_module(const char *name)
 {
-	help_entry_t *entry = *e;
-	help_section_t *section = entry->section;
-	int i;
+	char fullname[256], buf[256];
 
-	if (ul->module != NULL || ul->filename != NULL) {
-		if (0 != strcmp(entry->module, ul->module)
-			&& 0 != strcmp(entry->filename, ul->filename))
-		{
-			return;
-		}
-	}
-	
-	/* Remove it from hash table */
-	hash_table_remove(entries, name, e);
-	
-	/* Remove it from section */
-	if (section->nentries > 1) {
-		for (i = 0; i < section->nentries; i++) {
-			if (section->entries[i] != entry)
-				continue;
-				
-			if (i == section->nentries - 1)
-				continue;
-				
-			
-			memmove(section->entries + i, section->entries + i + 1,
-					sizeof(help_section_t *) * 
-						(section->nentries - i - 1));
-							
-		}
-		section->entries = realloc(section->entries,
-					(sizeof(help_section_t *) *
-						(section->nentries - 1)));
-		section->nentries--;
-	} else if (section->nentries == 1) {
-		free(section->entries); section->entries = NULL;
-		section->nentries--;
+	snprintf(fullname, sizeof(fullname), "%s-commands.xml", name);
+	localized_help_fname(buf, sizeof(buf), fullname);
+	if (help_parse_file(buf)) {
+		snprintf(buf, sizeof(buf), "%s/%s/%s", help_path, help_lang_fallback, fullname);
+		help_parse_file(buf);
 	}
-	 
-	/* Delete entry */
-	help_delete_entry(entry);
-
-	/* Remove empty sections */
-	if (section->nentries == 0)
-		help_delete_section(section);		
+	return(0);
 }
 
-static int help_unload_internal(const char *module, const char *filename)
+help_search_t *help_search_new(const char *searchstr)
 {
-	help_unload_t unload;
-	
-	unload.module = module;
-	unload.filename = filename;
-
-	hash_table_walk(entries,
-		(hash_table_node_func)unload_entry, &unload);
+	help_search_t *search;
 
-	return 1;
+	search = calloc(1, sizeof(*search));
+	search->search = strdup(searchstr);
+	return(search);
 }
 
-
-int help_unload(const char *filename)
+int help_search_end(help_search_t *search)
 {
-	return help_unload_internal(NULL, filename);
+	free(search->search);
+	free(search);
+	return(0);
 }
 
-static void print_entry(const char *name, help_entry_t *entry, partymember_t *member)
+help_summary_t *help_search_result(help_search_t *search)
 {
-	int i;
-
-	/* Command */
-	if (0 == strcmp(entry->type, "Command")) {
-		partymember_printf(member, "%s: %s %s", entry->type, entry->name,
-			entry->ext.command.syntax);
-
-	/* Variable */
-	} else if (0 == strcmp(entry->type, "Variable")) {
-		partymember_printf(member, "%s: %s(%s)", entry->type, entry->name,
-			entry->ext.variable.path);
-		partymember_printf(member, ("  Type: %s"), entry->ext.variable.type);
-	}
-
-	if (entry->flags)
-                partymember_printf(member, _("  Flags required: %s"), entry->flags);
-
-	for (i = 0; i < entry->desc.nlines; i++) {
-		partymember_printf(member, "    %s", entry->desc.lines[i]);
-	}
-	for (i = 0; i < entry->nseealso; i++) {
-		partymember_printf(member, _("  See also: %s"), entry->seealso[i]);
-	}
-}
-
-static void print_section(const char *name, help_section_t **s, partymember_t *member)
-{
-	int i, j;
-	help_section_t *section = *s;
-	help_entry_t *entry;
-	char *names[4];
-
-	partymember_printf(member, _("%s:"), name);
-	for (i = 0; i < section->desc.nlines; i++) {
-		partymember_printf(member, "  %s", section->desc.lines[i]);
-	}
-
-	/* we want 4 entries in one row */
-	for (i = 0; i < section->nentries; ) {
-		names[0] = names[1] = names[2] = names[3] = "";
-
-		for (j = 0; j < 4 && i < section->nentries; ) {
-			entry = section->entries[i++];
-			names[j++] = entry->name;
-		}
-
-		partymember_printf(member,
-			"    %-16s %-16s %-16s %-16s",
-				names[0], names[1], names[2], names[3]);
-	}
-	partymember_printf(member, _(""));
-}
-
-static void search_entries(const char *name, help_entry_t **entry, help_search_t *search)
-{
-	if (wild_match(search->text, name) > 0) {
-		print_entry(name, *entry, search->member);
-		if ((*entry)->flags && *(*entry)->flags &&
-			!user_check_flags_str(search->member->user, NULL, (*entry)->flags))
-			partymember_printf(search->member, _("  NOTE: You do NOT have access to this command!\n"));
-		search->hits++;
-	}
-	else {
-		int i;
-
-		/* do a fulltext search */
-		for (i = 0; i <(*entry)->desc.nlines; i++) {
-			if (wild_match(search->text, (*entry)->desc.lines[i]) > 0) {
-				print_entry(name, *entry, search->member);
-				if ((*entry)->flags && *(*entry)->flags &&
-					!user_check_flags_str(search->member->user, NULL, (*entry)->flags))
-				partymember_printf(search->member, _("  NOTE: You do NOT have access to this command!\n"));
-				search->hits++;
-				return;
-			}
-		}
-	}
-}
-
-static int help_search(partymember_t *member, const char *text)
-{
-	help_search_t search;
-
-	search.member = member;
-	search.text = text;
-	search.hits = 0;
-
-	hash_table_walk(entries, (hash_table_node_func)search_entries, &search);
-
-	return (search.hits > 0);
-}
-
-int help_print_party(partymember_t *member, const char *args)
-{
-	help_entry_t *entry;
 	help_section_t *section;
+	help_summary_t *entry;
 
-	if (nentries == 0) {
-		partymember_printf(member, _("No help entries loaded."));
-		return BIND_RET_LOG;
-	}
+	if (search->cursection < 0 || search->curentry < 0 || !search->search) return(NULL);
 
-	/* if no args given just print out full help */
-	if (args == NULL || 0 == strcmp(args, "all")) {
-		hash_table_walk(sections,
-			(hash_table_node_func)print_section, member);
-		partymember_printf(member, _("You can get help on individual command or variable: '.help <entry>'."));
-		partymember_printf(member, _("If you only remember a part of the entrie's name you are"));
-		partymember_printf(member, _("searching for, just use wildcards(e.g. '.help *bot*') and"));
-		partymember_printf(member, _("all matching help texts will be displayed."));
-		return BIND_RET_LOG;
-	}
-
-	/* may be either a section or a entry, whatever comes first */
-	entry = help_lookup_entry(args);
-	if (entry != NULL) {
-		print_entry(entry->name, entry, member);
-        	if (entry->flags && *entry->flags && !user_check_flags_str(member->user, NULL, entry->flags))
-			partymember_printf(member, _("  NOTE: You do NOT have access to this command!"));
-		return BIND_RET_LOG;
-	}
-
-	section = help_lookup_section(args);
-	if (section != NULL) {
-		print_section(section->name, &section, member);
-		return BIND_RET_LOG;
-	}
-
-	/* try a wildmatch search */
-	if (!help_search(member, args)) {
-		partymember_printf(member, _("Fulltext search resulted in no entries for '%s'."),
-			args);
-		return BIND_RET_BREAK;
+	while (search->cursection < nsections) {
+		section = sections+search->cursection;
+		while (search->curentry < section->nentries) {
+			entry = section->entries[search->curentry++];
+			if (wild_match(search->search, entry->name)) return(entry);
+		}
+		search->cursection++;
+		search->curentry = 0;
 	}
-
-	return BIND_RET_LOG;
+	search->cursection = search->curentry = -1;
+	return(NULL);
 }
Index: eggdrop1.9/lib/eggdrop/help.h
diff -u eggdrop1.9/lib/eggdrop/help.h:1.3 eggdrop1.9/lib/eggdrop/help.h:1.4
--- eggdrop1.9/lib/eggdrop/help.h:1.3	Tue Jun 22 13:47:27 2004
+++ eggdrop1.9/lib/eggdrop/help.h	Wed Sep 29 10:38:39 2004
@@ -16,62 +16,41 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Id: help.h,v 1.3 2004/06/22 18:47:27 wingman Exp $
+ * $Id: help.h,v 1.4 2004/09/29 15:38:39 stdarg Exp $
  */
 
 #ifndef _EGG_HELP_H_
 #define _EGG_HELP_H_
 
-#define HELP_HASH_SIZE		50
+typedef struct {
+	char *name;
+	int ref;
+} help_file_t;
+
+typedef struct {
+	char *name;
+	char *syntax;
+	char *summary;
+	help_file_t *file;
+} help_summary_t;
+
+typedef struct {
+	char *name;
+	help_summary_t **entries;
+	int nentries;
+} help_section_t;
+
+typedef struct {
+	char *search;
+	int cursection;
+	int curentry;
+} help_search_t;
 
-typedef struct help_entry	help_entry_t;
-typedef struct help_section	help_section_t;
+int help_init();
+int help_shutdown();
 
-typedef struct
-{
-	char	**lines;		/* Lines of help data		*/
-	int	  nlines;		/* Number of help data lines 	*/
-} help_desc_t;
-
-struct help_section
-{
-	char 	 	 *name;		/* Section name			*/
-	help_desc_t	  desc;		/* Description			*/
-	help_entry_t	**entries;	/* Entries			*/
-	int	  	  nentries;	/* Number of entries		*/
-};
-
-struct help_entry
-{
-	char		 *type;		/* Entry type			*/
-	char		 *flags;	/* Entry flags			*/
-	char		 *module;	/* Source module		*/
-	char		 *filename;	/* Source file			*/
-	char  		 *name;		/* Entry name 			*/
-	help_section_t	 *section;	/* Entry section		*/
-	help_desc_t	  desc;		/* Description 			*/
-	char 		**seealso;	/* See also entries 		*/
-	int   		  nseealso;	/* Number of see also entries 	*/
-		
-	union
-	{
-		struct
-		{
-			char	*syntax;	/* Command syntax	*/
-		} command;
-		struct
-		{
-			char	 *type;		/* Variable type	*/
-			char	 *path;		/* Variable path	*/			
-		} variable;
-	} ext;
-};
-
-int help_init(void);
-int help_shutdown(void);
-
-int help_count_sections(void);
-int help_count_entries(void);
+int help_count_sections();
+int help_count_entries();
 
 int help_load(const char *filename);
 int help_unload(const char *filename);
@@ -79,9 +58,11 @@
 int help_load_by_module(const char *name);
 int help_unload_by_module(const char *name);
 
-help_entry_t *help_lookup_entry(const char *name);
+help_summary_t *help_lookup_summary(const char *name);
 help_section_t *help_lookup_section(const char *name);
 
-int help_print_party(partymember_t *member, const char *args);
+help_search_t *help_search_new(const char *searchstr);
+int help_search_end(help_search_t *search);
+help_summary_t *help_search_result(help_search_t *search);
 
 #endif /* !_EGG_HELP_H_ */
Index: eggdrop1.9/lib/eggdrop/xml.c
diff -u eggdrop1.9/lib/eggdrop/xml.c:1.20 eggdrop1.9/lib/eggdrop/xml.c:1.21
--- eggdrop1.9/lib/eggdrop/xml.c:1.20	Sun Sep 26 04:42:09 2004
+++ eggdrop1.9/lib/eggdrop/xml.c	Wed Sep 29 10:38:39 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: xml.c,v 1.20 2004/09/26 09:42:09 stdarg Exp $";
+static const char rcsid[] = "$Id: xml.c,v 1.21 2004/09/29 15:38:39 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -308,6 +308,35 @@
 	return(0);
 }
 
+int xml_node_get_vars(xml_node_t *node, const char *fmt, ...)
+{
+	va_list args;
+	char *name, **strptr;
+	int *intptr;
+	xml_node_t **nodeptr;
+
+	va_start(args, fmt);
+	while (*fmt) {
+		name = va_arg(args, char *);
+		switch (*fmt) {
+			case 's':
+				strptr = va_arg(args, char **);
+				xml_node_get_str(strptr, node, name, 0, 0);
+				break;
+			case 'i':
+				intptr = va_arg(args, int *);
+				xml_node_get_int(intptr, node, name, 0, 0);
+				break;
+			case 'n':
+				nodeptr = va_arg(args, xml_node_t **);
+				*nodeptr = xml_node_path_lookup(node, name, 0, 0);
+				break;
+		}
+		fmt++;
+	}
+	return(0);
+}
+
 xml_node_t *xml_root_element(xml_node_t *node)
 {
 	 if (node == NULL) return NULL;
Index: eggdrop1.9/lib/eggdrop/xml.h
diff -u eggdrop1.9/lib/eggdrop/xml.h:1.19 eggdrop1.9/lib/eggdrop/xml.h:1.20
--- eggdrop1.9/lib/eggdrop/xml.h:1.19	Sun Sep 26 04:42:09 2004
+++ eggdrop1.9/lib/eggdrop/xml.h	Wed Sep 29 10:38:39 2004
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Id: xml.h,v 1.19 2004/09/26 09:42:09 stdarg Exp $
+ * $Id: xml.h,v 1.20 2004/09/29 15:38:39 stdarg Exp $
  */
 
 #ifndef _EGG_XML_H_
@@ -88,6 +88,8 @@
 int xml_node_int(xml_node_t *node, int def);
 int xml_node_set_int(int value, xml_node_t *node, ...);
 
+int xml_node_get_vars(xml_node_t *node, const char *fmt, ...);
+
 xml_node_t *xml_node_new(void);
 void xml_node_free(xml_node_t *node);
 void xml_node_delete(xml_node_t *node);
Index: eggdrop1.9/modules/server/help/en_US/commands.xml
diff -u /dev/null eggdrop1.9/modules/server/help/en_US/commands.xml:1.1
--- /dev/null	Wed Sep 29 10:38:49 2004
+++ eggdrop1.9/modules/server/help/en_US/commands.xml	Wed Sep 29 10:38:39 2004
@@ -0,0 +1,29 @@
+<helpfile>
+	<section>commands</section>
+	<help>
+		<name>+server</name>
+		<summary>add a new server to the server list</summary>
+		<args>
+			<arg>
+				<name>hostname</name>
+				<desc>the host (or ip address) of the new server</desc>
+			</arg>
+			<arg>
+				<name>port</name>
+				<optional>1</optional>
+				<desc>the port of the new server</desc>
+			</arg>
+			<arg>
+				<name>pass</name>
+				<optional>1</optional>
+				<desc>the password to use for the new server</desc>
+			</arg>
+		</args>
+		<desc>This command ...</desc>
+		<seealso>
+			<see>-server</see>
+			<see>servers</see>
+			<see>jump</see>
+		</seealso>
+	</help>
+</helpfile>
Index: eggdrop1.9/src/core_party.c
diff -u eggdrop1.9/src/core_party.c:1.40 eggdrop1.9/src/core_party.c:1.41
--- eggdrop1.9/src/core_party.c:1.40	Sun Sep 26 04:42:09 2004
+++ eggdrop1.9/src/core_party.c	Wed Sep 29 10:38:39 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: core_party.c,v 1.40 2004/09/26 09:42:09 stdarg Exp $";
+static const char rcsid[] = "$Id: core_party.c,v 1.41 2004/09/29 15:38:39 stdarg Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -42,8 +42,35 @@
 #include "terminal.h"			/* TERMINAL_NICK				*/
 #include "main.h"			/* SHUTDOWN_*, core_shutdown, core_restart	*/
 
-/* from main.c */
-extern char pid_file[];
+static int party_help(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
+{
+	help_summary_t *entry;
+	help_search_t *search;
+	int hits = 0;
+
+	if (!text || !*text) {
+		partymember_printf(p, "Syntax: help <command|variable|*search*>");
+		return(0);
+	}
+	/* First try to look up an exact match. */
+	entry = help_lookup_summary(text);
+	if (entry) {
+		partymember_printf(p, "Full help! (not done)\n");
+		return(0);
+	}
+
+	/* No, do a search. */
+	search = help_search_new(text);
+	while ((entry = help_search_result(search))) {
+		partymember_printf(p, "%s - %s", entry->syntax, entry->summary);
+		hits++;
+	}
+	if (hits == 0) {
+		partymember_printf(p, "No help was found! Try more wildcards...");
+	}
+	help_search_end(search);
+	return(0);
+}
 
 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
@@ -468,11 +495,6 @@
 	return(0);
 }
 
-static int party_help(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
-{
-	return 0;
-}
-
 static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
 	putlog(LOG_MISC, "*", "%s: %s", nick, text);
@@ -763,6 +785,7 @@
 }
 
 static bind_list_t core_party_binds[] = {		/* Old flags requirement */
+	{NULL, "help", party_help},
 	{NULL, "join", party_join},		/* DDD	*/
 	{NULL, "whisper", party_whisper},	/* DDD	*/
 	{NULL, "newpass", party_newpass},	/* DDC	*/ /* -|- */
Index: eggdrop1.9/src/main.c
diff -u eggdrop1.9/src/main.c:1.184 eggdrop1.9/src/main.c:1.185
--- eggdrop1.9/src/main.c:1.184	Sun Sep 26 04:42:09 2004
+++ eggdrop1.9/src/main.c	Wed Sep 29 10:38:39 2004
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: main.c,v 1.184 2004/09/26 09:42:09 stdarg Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.185 2004/09/29 15:38:39 stdarg Exp $";
 #endif
 
 #if HAVE_CONFIG_H
@@ -597,8 +597,13 @@
 	//help_load_by_module ("core");
 
 	/* Put the module directory in the ltdl search path. */
-	if (core_config.module_path)
-		module_add_dir(core_config.module_path);
+	if (core_config.module_path) module_add_dir(core_config.module_path);
+
+	/* Initialize help system. */
+	if (core_config.help_path) {
+		help_set_default_path(core_config.help_path);
+		/* Load all help files here... */
+	}
 
 	/* Scan the autoload section of config. */
 	config_root = config_get_root("eggdrop");
@@ -606,6 +611,8 @@
 		name = NULL;
 		config_get_str(&name, entry, NULL);
 		module_load(name);
+		/* For now we'll just load these help files... */
+		help_load_by_module(name);
 	}
 	for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
 		name = NULL;
----------------------- End of diff -----------------------



More information about the Changes mailing list