[NeoStats-Devel] [Commits] r2686 - in trunk: modules/perltest src

[email protected]
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Fish
Date: Tue Aug  2 20:38:37 2005
New Revision: 2686

Modified:
   trunk/modules/perltest/test.pl
   trunk/src/NeoStats.pm
   trunk/src/commands.c
   trunk/src/neostats.pm.h
   trunk/src/perl.c
Log:
helptext is now done... now just the easy command implementation and the XXX TODO's

Modified: trunk/modules/perltest/test.pl
==============================================================================
--- trunk/modules/perltest/test.pl	(original)
+++ trunk/modules/perltest/test.pl	Tue Aug  2 20:38:37 2005
@@ -338,13 +338,14 @@
 
 
 #	add a command
-	my $cmd;
-	$cmd = {
+	my @helptext = ('Test Command Help', 'Test', 'Testing Command Help is a nice command');
+	my $cmd = {
 		cmd => 'test',
 		minparams => '1',
 		ulevel => '0',
 		flags => '0',
 	};
+	$cmd->{helptext} = \@helptext;
 	NeoStats::AddCmd($bot, $cmd, 'cmd_cb_test');
 	$cmd = {
 		cmd => 'test2',
@@ -352,6 +353,7 @@
 		ulevel => '0',
 		flags => '0',
 	};
+	$cmd->{helptext} = \@helptext;
 	NeoStats::AddCmd($bot, $cmd, 'cmd_cb_test');
 	NeoStats::debug(NeoStats::DelCmd($bot, $cmd->{cmd}));
 	NeoStats::ChanAlert($bot, "Loaded up and ready to rock and role");

Modified: trunk/src/NeoStats.pm
==============================================================================
--- trunk/src/NeoStats.pm	(original)
+++ trunk/src/NeoStats.pm	Tue Aug  2 20:38:37 2005
@@ -220,14 +220,14 @@
       return NeoStats::NS_FAILURE;
     }    
     if ((!exists( $botcmd->{ulevel} )) || (!defined( $botcmd->{ulevel} ))) {
-      NeoStats::debug("Bot->{ulevel} not defined");
+      NeoStats::debug("Botinfo->{ulevel} not defined");
       return NeoStats::NS_FAILURE;
     }    
-#XXX TODO
-#    if ((!exists( $botcmd->{helptext} )) || (!defined( $botcmd->{helptext} ))) {
-#      NeoStats::debug("Botinfo->{host} not defined");
-#      return NeoStats::NS_FAILURE;
-#    }    
+    if ((!exists( $botcmd->{helptext} )) || (!defined( $botcmd->{helptext} ))) {
+      NeoStats::debug("Botinfo->{helptext} not defined");
+      return NeoStats::NS_FAILURE;
+    }    
+    #XXX Need to check size of the helptext array to make sure at least 2 lines 
     if ((!exists( $botcmd->{flags} )) || (!defined( $botcmd->{flags} ))) {
       NeoStats::debug("Botinfo->{flags} not defined");
       return NeoStats::NS_FAILURE;

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Tue Aug  2 20:38:37 2005
@@ -254,6 +254,9 @@
 	hnode_t *cmdnode;
 	
 	/* Find the command */
+	if (!bot_ptr->botcmds) {
+		return NULL;
+	}
 	cmdnode = hash_lookup( bot_ptr->botcmds, cmd );
 	if( cmdnode ) {
 		return hnode_get(cmdnode);
@@ -280,6 +283,8 @@
 		if (IS_PERL_MOD(cmd_ptr->modptr)) {
 			ns_free(cmd_ptr->cmd);
 			ns_free(cmd_ptr->moddata);
+			/* XXX is this correct on a array of strings? */
+			ns_free(cmd_ptr->helptext);
 		}
 #endif
 		return NS_SUCCESS;

Modified: trunk/src/neostats.pm.h
==============================================================================
--- trunk/src/neostats.pm.h	(original)
+++ trunk/src/neostats.pm.h	Tue Aug  2 20:38:37 2005
@@ -220,13 +220,13 @@
 "return NeoStats::NS_FAILURE;\n"
 "}    \n"
 "if ((!exists( $botcmd->{ulevel} )) || (!defined( $botcmd->{ulevel} ))) {\n"
-"NeoStats::debug(\"Bot->{ulevel} not defined\");\n"
+"NeoStats::debug(\"Botinfo->{ulevel} not defined\");\n"
+"return NeoStats::NS_FAILURE;\n"
+"}    \n"
+"if ((!exists( $botcmd->{helptext} )) || (!defined( $botcmd->{helptext} ))) {\n"
+"NeoStats::debug(\"Botinfo->{helptext} not defined\");\n"
 "return NeoStats::NS_FAILURE;\n"
 "}    \n"
-"\n"
-"\n"
-"\n"
-"\n"
 "\n"
 "if ((!exists( $botcmd->{flags} )) || (!defined( $botcmd->{flags} ))) {\n"
 "NeoStats::debug(\"Botinfo->{flags} not defined\");\n"

Modified: trunk/src/perl.c
==============================================================================
--- trunk/src/perl.c	(original)
+++ trunk/src/perl.c	Tue Aug  2 20:38:37 2005
@@ -418,20 +418,6 @@
 		mod->info->name = SvPV_nolen (ST (0));
 		mod->info->version = SvPV_nolen (ST (1));
 		mod->info->description = SvPV_nolen (ST (2));
-#if 0
-XXX TODO Credits and about 
-		name = SvPV_nolen (ST (0));
-		version = SvPV_nolen (ST (1));
-		desc = SvPV_nolen (ST (2));
-		mod->info->name = os_malloc(strlen(name)+1);
-		strlcpy((char *)mod->info->name, name, strlen(name)+1);
-
-		mod->info->description = os_malloc(strlen(desc)+1);
-		strlcpy((char *)mod->info->description, desc, strlen(desc)+1);
-
-		mod->info->version = os_malloc(strlen(version)+1);
-		strlcpy((char *)mod->info->version, version, strlen(version)+1);
-#endif		
 
 		XSRETURN_UV (PTR2UV (mod));
 
@@ -684,8 +670,10 @@
 	HV * rethash;
 	SV *ret;
 	SV *value;
+	AV *helptext;
 	bot_cmd *bc;
 	Bot *bot;
+	int i, j;
 	char *temp[] = { "Test Command", "Test Command Two", NULL};
 
 	dXSARGS;
@@ -704,18 +692,33 @@
 #endif
 		bc = ns_malloc(sizeof(bot_cmd));
 		value = *hv_fetch(rethash, "cmd", strlen("cmd"), FALSE);
-		bc->cmd = malloc(SvLEN(value)+1);
+		bc->cmd = ns_malloc(SvLEN(value)+1);
 		strlcpy((char *)bc->cmd, SvPV_nolen(value), SvLEN(value)+1);
 		value = *hv_fetch(rethash, "minparams", strlen("minparams"), FALSE);
 		bc->minparams = SvIV(value);
 		value = *hv_fetch(rethash, "ulevel", strlen("ulevel"), FALSE);
 		bc->ulevel = SvIV(value);
-#if 0
-/* XXX TODO */
+
 		value = *hv_fetch(rethash, "helptext", strlen("helptext"), FALSE);
-		strlcpy(bc->helptext, SvPV_nolen(value), MAXHOST);
-#endif
-		bc->helptext = temp;
+		/* make sure its a array */
+		if (SvTYPE(SvRV(value)) != SVt_PVAV) {
+			dlog(DEBUG1, "XS_NeoStats_AddCommand: Helptext field is not a array");
+			ns_free(bc->cmd);
+			ns_free(bc);
+			XSRETURN_EMPTY;
+		}
+		/* ok, lets setup the array */
+		helptext = (AV*)SvRV(value);
+		j = 0;
+		for (i =0; i <= av_len(helptext); i++) {
+			/* ok, try to follow me here:
+			 * we extract each member of the array (av_fetch)
+			 * and convert it to a string (SvPV_nolen)
+			 * then make a copy (malloc'ed) of it (strdup)
+			 * and put it on the end of the array of helptext strings (AddStringToList)!
+			 */
+			AddStringToList(&bc->helptext, strdup(SvPV_nolen(*av_fetch(helptext, i, FALSE))), &j);
+		}
 		value = *hv_fetch(rethash, "flags", strlen("flags"), FALSE);
 		bc->flags = SvIV(value);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.