safe_command_interpreter
Snippet Posted Saturday, September 23rd @ 12:48:24 PM, by Brandon Brown in the Utils dept.
Paolo "Razor" Greco writes, "I've coded a veeery simple (and maybe buggish, i can't compile on this PC) wrapper to command_interpreter, so it can be called from another ACMD. Please mail me if you find any bugs, and if you find this little snippet useful."
In stock Circlemud the standard buffers are global variables, so functions using them are non returning (it isn't safe to call an ACMD within another ACMD).
I've coded a veeery simple (and maybe buggish, i can't compile on this PC) wrapper to command_interpreter, so it can be called from another ACMD.
Please mail me if you find any bugs, and if you find this little snippet useful.
Greetings from Italy!

void safe_command_interpreter(struct char_data *ch, char *argument)
{
	char * nbuf, nbuf1, nbuf2, narg;
	
	//frozing the old buffers
	nbuf = (char *)malloc(strlen(buf)+1);
	nbuf = strcpy(buf);
	buf = '\n';
	
	nbuf1 = (char *)malloc(strlen(buf1)+1);
	nbuf1 = strcpy(buf1);
	buf1 = '\n';
	
	nbuf2 = (char *)malloc(strlen(buf2)+1);
	nbuf2 = strcpy(buf2);
	buf2 = '\n';
	
	narg = (char *)malloc(strlen(arg)+1);
	narg = strcpy(arg);
	arg = '\n';
	
	command_interpreter(struct char_data *ch, char *argument);

	//put the old buffers in the microwave oven	
	buf = strcpy(nbuf);
	free(nbuf);
	
	buf1 = strcpy(nbuf1);
	free(nbuf1);
	
	buf2 = strcpy(nbuf2);
	free(nbuf2);
		
	arg = strcpy(narg);
	free(narg);
}

<< FTP Uploads 2000//0/9/ | Reply | Flattened | Stat Zone Loading/Reset information >>

 


Related Links
  CircleMUD
Paolo "Razor" Greco
Related Articles
More by bbrown
 
 

Quick Links
 
The CircleMUD FAQ
The CircleMUD home page
Alex's Snippets
Wintermute Snippets
CircleMUD Bug Reporting or Help
CircleMUD List Archives
CircleMUD Resources
Death Gate's Scripts
(Author of C conversion)
Sammy's code site
Erwin S. Andreasen's page
(Author of mudFTP and other goodies)
Death's Gate Scripting site
Help for CircleMUD in Windows
The OasisOLC Maintenance Effort
George's Random Stuff
Imaginary Realities
MUD Dictionary
 
 


ummm, all this just to call an ACMD from an ACMD?
by Peter Ajamian (peter@pajamian.dhs.org) on Thursday, September 28th @ 12:04:53 AM
http://
Forgive me for a little bit of scepticism, but none of this is necessary.

If you have an ACMD that uses, for example, buf and buf1 (both global buffers), and you want to call another ACMD from inside that ACMD, the solution is easy...
At the top of the function simply add the following line...

char buf[MAX_STRING_LENGTH], buf1[MAX_STRING_LENGTH];

That's it, once you've done that you can safely call any other ACMD directly from that ACMD without fear of having the buffers clash. It's a simple, direct, easy solution that doesn't require all the mess that you are showing here.

Regards, Peter
[ Reply to this comment ]