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 | Threaded | Stat Zone Loading/Reset information >>
|
|
|
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 ] |
|
Re: ummm, all this just to call an ACMD from an ACMD? by Paolo "Razor" Greco (razor@tiscalinet.it) on Friday, September 29th @ 08:13:11 AM http:// |
Uhm i agree... BUT there are so many ACMD, and command_interpet is referenced only 2 o 3 times in the whole code. Many of the ACMDs in DarkMud (the italian one) are callable by forcing/ordering the mob, so i need a fail-safe wrapper. And, most important, i don't want to modify all the ACMDs =) Thank you for the reply, Paolo |
[ Reply to this comment ] |
|
Re: ummm, all this just to call an ACMD from an ACMD? by Matteo Ramazio (rama.rama@aruba.it) on Friday, September 29th @ 02:44:01 PM http:// |
In this way you must correct all the ACMD that call other ACMD. The other way is quicker if you have a lot ACMD. Bye |
[ Reply to this comment ] |
|
Re: ummm, all this just to call an ACMD from an ACMD? by Peter Ajamian (peter@pajamian.dhs.org) on Saturday, September 30th @ 12:40:32 AM http:// |
All you have to correct is the ACMD that you are currently writing (the one you want to call the other ACMD from and you'd have to do that anyways with this snippet (because you have to call the ACMD through the wrapper), how can the snippet possibly be quicker? Regards, Peter |
[ Reply to this comment ] |
|
Re: ummm, all this just to call an ACMD from an ACMD? by Peter Ajamian (peter@pajamian.dhs.org) on Saturday, September 30th @ 12:49:12 AM http:// |
Well, figure it this way, you would have to change every function that calls another ACMD by calling via the wrapper anyways, it is just as easy (even easier) to simply re-define the global buffers it uses than it is to implement a snippet like this. This goes for a force command, or anything, any command you have that calls any ACMD (weather directly or indirectly), it doesn't matter what kind of function it is that's doing the calling, you would either have to add one line in the defines (like I presented earlier) or you would have to change the line that calls the command interpreter so it calls the wrapper instead, either way you still have to change the function, and my way is safer, less bloated and easier. Regards, Peter |
[ Reply to this comment ] |