destroycommandtree((CommandTree *)ct->next[i]);
}
}
-
+
+ if(ct->cmd) {
+ if(ct->cmd->command)
+ freesstring(ct->cmd->command);
+ if(ct->cmd->ext && ct->cmd->destroyext)
+ (ct->cmd->destroyext)(ct->cmd->ext);
+ free(ct->cmd);
+ }
free(ct);
}
* installing it in the tree
*/
-Command *addcommandhelptotree(CommandTree *ct, const char *cmdname, int level, int maxparams, CommandHandler handler, const char *help) {
+Command *addcommandexttotree(CommandTree *ct, const char *cmdname, int level, int maxparams, CommandHandler handler, void *ext) {
Command *nc, *c;
char cmdbuf[MAX_COMMAND_LEN];
nc->handler=handler;
nc->ext=NULL;
nc->next=NULL;
- if (help) {
- nc->help=getsstring(help, 512);
- } else {
- nc->help=NULL;
- }
+ nc->calls=0;
+ nc->destroyext=NULL;
if ((c=findcommandintree(ct,cmdname,1))!=NULL) {
/* Found something already. Append our entry to the end */
} else if (insertcommand(nc,ct,0)) {
/* Erk, that didn't work.. */
freesstring(nc->command);
- freesstring(nc->help);
free(nc);
return NULL;
}
+
+ if (ext)
+ nc->ext=(void *)ext;
return nc;
}
c=*ch;
(*ch)=(Command *)((*ch)->next);
freesstring(c->command);
- freesstring(c->help);
+ if(c->ext && c->destroyext)
+ (c->destroyext)(c->ext);
free(c);
return 0;
}
c=*ch;
(*ch)=(Command *)((*ch)->next);
freesstring(c->command);
- freesstring(c->help);
+ if(c->ext && c->destroyext)
+ (c->destroyext)(c->ext);
free(c);
/* We need to regenerate the final pointer if needed;