]> jfr.im git - irc/quakenet/newserv.git/blobdiff - parser/parser.c
Merge chanserv-live into default.
[irc/quakenet/newserv.git] / parser / parser.c
index d4b062b323ad6404e29e7383bcc7a29b7beecc75..2a8147616d3be08dfeda268673148f467363627a 100644 (file)
@@ -45,7 +45,14 @@ void destroycommandtree(CommandTree *ct) {
       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);
 }
 
@@ -79,7 +86,7 @@ int countcommandtree(CommandTree *ct) {
  * 
  * Returns 1 if bad chars were found
  */
-static int sanitisecommandname(char *cmdname, char *cmdbuf) {
+static int sanitisecommandname(const char *cmdname, char *cmdbuf) {
   int len,i;
 
   strncpy(cmdbuf,cmdname,MAX_COMMAND_LEN);
@@ -108,9 +115,8 @@ static int sanitisecommandname(char *cmdname, char *cmdbuf) {
  * 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;
-  int i;
   char cmdbuf[MAX_COMMAND_LEN];
 
   if (sanitisecommandname(cmdname, cmdbuf))
@@ -124,16 +130,8 @@ Command *addcommandhelptotree(CommandTree *ct, const char *cmdname, int level, i
   nc->handler=handler;
   nc->ext=NULL;
   nc->next=NULL;
-  if (help) {
-    int len=strlen(help);
-    nc->help=(char *)malloc(len+1);
-    if(nc->help) {
-      strncpy(nc->help, help, len);
-      nc->help[len] = '\0';
-    }
-  } 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 */
@@ -143,11 +141,12 @@ Command *addcommandhelptotree(CommandTree *ct, const char *cmdname, int level, i
   } else if (insertcommand(nc,ct,0)) {
     /* Erk, that didn't work.. */
     freesstring(nc->command);
-    if(nc->help)
-      free(nc->help);
     free(nc);
     return NULL;
   }
+
+  if (ext)
+    nc->ext=(void *)ext;
   
   return nc;
 }
@@ -237,8 +236,8 @@ int deletecommand(sstring *cmdname, CommandTree *ct, int depth, CommandHandler h
         c=*ch;
         (*ch)=(Command *)((*ch)->next);
         freesstring(c->command);
-        if(c->help)
-          free(c->help);
+        if(c->ext && c->destroyext)
+          (c->destroyext)(c->ext);
         free(c);
         return 0;
       }
@@ -256,8 +255,8 @@ int deletecommand(sstring *cmdname, CommandTree *ct, int depth, CommandHandler h
         c=*ch;
         (*ch)=(Command *)((*ch)->next);
         freesstring(c->command);
-        if(c->help)
-          free(c->help);
+        if(c->ext && c->destroyext)
+          (c->destroyext)(c->ext);
         free(c);
 
         /* We need to regenerate the final pointer if needed;