replace_dofun.c
snippets · 1.2 KB · 2010-03-30
replace_dofun: a short, effective do_function replacement that avoids sprintf before launching commands.
Download « Back to the snippets list
// * do_function replacement, Okay, small, but effective. I got tired of * //
// * having to sprintf something before launching it to a function or * //
// * into the do_function command, so i wrote up this formated version of * //
// * the do_function function. * //
// * This will require stdarg.h i believe, so ensure it is included at * //
// * the top of interp.c when you replace do_function * //
// * Enjoy :) -- Dazzle of Sandstorm: The Mages Sanctuary * //
// * in interp.h, replace the call to do_function with this one.* //
void do_function args((CHAR_DATA *ch, DO_FUN *do_fun, char *argument, ...));
// *In interp.c replace do_function with this one. And enjoy.* //
// *This will allow you todo do_function(ch, &do_yell, "%s, get your ass over here",victim->name); or whatever.* //
void do_function (CHAR_DATA *ch, DO_FUN *do_fun, char *argument, ...)
{
char command_string[MSL];
va_list args;
int length = 0;
va_start(args, argument);
length += vsprintf(command_string, argument, args);
va_end(args);
/* dispatch the command */
(*do_fun) (ch, command_string);
return;
}