]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Parser help is now an sstring.
authorChris Porter <redacted>
Mon, 18 Aug 2008 17:26:48 +0000 (18:26 +0100)
committerChris Porter <redacted>
Mon, 18 Aug 2008 17:26:48 +0000 (18:26 +0100)
control/control.c
noperserv/noperserv_hooks.c
parser/parser.c
parser/parser.h

index 6dd7a4125c7c7e0051cc6fc05f78be4e4973f5dd..76caa3efb98dec09b1ee4908a11249de0fab6276 100644 (file)
@@ -533,9 +533,9 @@ void controlnotice(nick *target, char *message, ... ) {
 
 void controlspecialrmmod(void *arg) {
   struct specialsched *a = (struct specialsched *)arg;
+  sstring *froo = a->modulename;
   
   a->schedule = NULL;
-  sstring *froo = a->modulename;
 
   rmmod(froo->content);
   freesstring(froo);
@@ -543,19 +543,20 @@ void controlspecialrmmod(void *arg) {
 
 void controlspecialreloadmod(void *arg) {
   struct specialsched *a = (struct specialsched *)arg;
+  sstring *froo = a->modulename;
 
   a->schedule = NULL;
-  sstring *froo = a->modulename;
 
   safereload(froo->content);
   freesstring(froo);
 }
 
 void controlhelp(nick *np, Command *cmd) {
-  char *cp = cmd->help, *sp = cp;
-  if(!cp || !*cp) {
+  sstring *scp = cmd->help;
+  if(!scp) {
     controlreply(np, "Sorry, no help for this command.");
   } else {
+    char *cp = scp->content, *sp = cp;
     int finished = 0;
     for(;;cp++) {
       if(*cp == '\0' || *cp == '\n') {
index adca6e65146eb975f5b14c41623358378e4904e0..efa1ae16802cc9ab295497508b3ee908e66eac24 100644 (file)
@@ -19,8 +19,8 @@
 struct storedhook {
   CommandHandler old;
   sstring *name;
-  char *oldhelp;
-  char *newhelp;
+  sstring *oldhelp;
+  sstring *newhelp;
   struct storedhook *next;
 } storedhook;
 
@@ -87,13 +87,12 @@ int noperserv_hook_command(char *command, CommandHandler newcommand, char *newhe
 
   newhook->old = fetchcommand->handler;
   if(newhelp) {
-    int len = strlen(newhelp) + 1;
-    newhook->newhelp = (char *)malloc(len);
+    newhook->newhelp = getsstring(newhelp, 512);
     if(!newhook->newhelp) {
       freesstring(newhook->name);
       free(newhook);
+      return 1;
     }
-    strlcpy(newhook->newhelp, newhelp, len);
     newhook->oldhelp = fetchcommand->help;
     fetchcommand->help = newhook->newhelp;
   } else {
@@ -117,7 +116,7 @@ void noperserv_unhook_all_commands(void) {
       fetchcommand->handler = ch->old;
       if(ch->newhelp) {
         fetchcommand->help = ch->oldhelp;
-        free(ch->newhelp);
+        freesstring(ch->newhelp);
       }
     }
     nh = ch->next;
index 76d9e3a4230266cd79bb918a062a2e05fe380821..f257a800aa9efe973db47ce73273aab486374876 100644 (file)
@@ -124,12 +124,7 @@ Command *addcommandhelptotree(CommandTree *ct, const char *cmdname, int level, i
   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';
-    }
+    nc->help=getsstring(help, 512);
   } else {
     nc->help=NULL;
   }
@@ -142,8 +137,7 @@ 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);
+    freesstring(nc->help);
     free(nc);
     return NULL;
   }
@@ -236,8 +230,7 @@ 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);
+        freesstring(c->help);
         free(c);
         return 0;
       }
@@ -255,8 +248,7 @@ 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);
+        freesstring(c->help);
         free(c);
 
         /* We need to regenerate the final pointer if needed;
index e98e577dc088c2c3b263e2494cdb3abc70753b1f..b7d83baab986a8a74620beeeeec1808a30ebae8c 100644 (file)
@@ -33,7 +33,7 @@ typedef int (*CommandHandler)(void *, int, char**);
  
 typedef struct Command {
   sstring        *command;       /* Name of the command/token/thing */
-  char           *help;          /* Help information, sorry splidge! */
+  sstring        *help;          /* Help information, sorry splidge! */
   int             level;         /* "level" required to use the command/token/thing */
   int             maxparams;     /* Maximum number of parameters for the command/token/thing */
   CommandHandler  handler;       /* Function to deal with the message */