Factor out sorted list insertion into utility function
[clinton/bobotpp.git] / source / Parser.C
index 1dd60cb..021ebf2 100644 (file)
@@ -1,6 +1,6 @@
 // Parser.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002,2003,2005 Clinton Ebadi
+// Copyright (C) 2002,2003,2005,2008 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 #include "config.h"
 #endif
 
+#include <cstdlib>
 #include <sys/types.h>
 #include <netinet/in.h>
 
@@ -80,7 +81,7 @@ Parser::parseLine (ServerConnection * cnx, String line)
   Person *from = 0;
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::RAW, line,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (line),
                                              SCM_UNDEFINED));
 #endif
@@ -358,7 +359,7 @@ Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::INVITE,
                                 nick + " " + channel,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (nick),
                                              Utils::
                                              str2scm
@@ -381,7 +382,7 @@ Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
   bool joinAndMode = false;
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (n),
                                              Utils::
                                              str2scm (c), SCM_UNDEFINED));
@@ -451,7 +452,7 @@ Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
                                 target + " " +
                                 from->getNick () + " " +
                                 channel + " " + reason,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm
                                              (target),
                                              Utils::
@@ -509,7 +510,7 @@ Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
     cnx->bot->botInterp->RunHooks (Hook::MODE,
                                   from->getNick () + " " + ch +
                                   " " + modes,
-                                  scm_listify (Utils::
+                                  scm_list_n (Utils::
                                                str2scm (from->
                                                            getNick
                                                            ()),
@@ -541,7 +542,7 @@ Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
                                 on_orig + " " + nn,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm
                                              (on_orig),
                                              Utils::
@@ -588,7 +589,7 @@ Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
       if (Utils::channel_p (to))
        cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
                                       nick + " " + to + " " + rest,
-                                      scm_listify (Utils::
+                                      scm_list_n (Utils::
                                                    str2scm (nick),
                                                    Utils::
                                                    str2scm (to),
@@ -597,7 +598,7 @@ Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
                                                    SCM_UNDEFINED));
       else
        cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
-                                      scm_listify (Utils::
+                                      scm_list_n (Utils::
                                                    str2scm (nick),
                                                    Utils::
                                                    str2scm (rest),
@@ -614,7 +615,7 @@ Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
   cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
                                 nick + " " + command + " " +
                                 rest,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (nick),
                                              Utils::
                                              str2scm
@@ -654,7 +655,7 @@ Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
        {
 #ifdef USESCRIPTS
          cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
-                                        scm_listify (Utils::
+                                        scm_list_n (Utils::
                                                      str2scm (nick),
                                                      SCM_UNDEFINED));
 #endif
@@ -715,7 +716,7 @@ Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
   String channel = st.next_token ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (n),
                                              Utils::
                                              str2scm
@@ -760,7 +761,7 @@ Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
   String n = from->getNick ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (n),
                                              Utils::
                                              str2scm (rest),
@@ -786,7 +787,7 @@ Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
   cnx->bot->botInterp->RunHooks (Hook::TOPIC,
                                 from->getNick () + " " +
                                 channel + " " + newTopic,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (from->
                                                          getNick
                                                          ()),
@@ -820,7 +821,7 @@ Parser::parseCTCP (ServerConnection * cnx,
   cnx->bot->botInterp->RunHooks (Hook::CTCP,
                                 nick + " " + to + " " +
                                 command + " " + rest,
-                                scm_listify (Utils::
+                                scm_list_n (Utils::
                                              str2scm (nick),
                                              Utils::
                                              str2scm (to),
@@ -885,7 +886,7 @@ Parser::parseCTCP (ServerConnection * cnx,
       cnx->bot->botInterp->RunHooks (Hook::ACTION,
                                     from->getNick () + " " + to +
                                     " " + rest,
-                                    scm_listify (Utils::
+                                    scm_list_n (Utils::
                                                  str2scm (from->
                                                              getNick
                                                              ()),
@@ -907,7 +908,7 @@ Parser::parseMessage (ServerConnection * cnx,
     cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
                                   from->getNick () + " " + to +
                                   " " + parameters,
-                                  scm_listify (Utils::
+                                  scm_list_n (Utils::
                                                str2scm (from->
                                                            getNick
                                                            ()),
@@ -920,7 +921,7 @@ Parser::parseMessage (ServerConnection * cnx,
     cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
                                   from->getNick () + " " +
                                   parameters,
-                                  scm_listify (Utils::
+                                  scm_list_n (Utils::
                                                str2scm (from->
                                                            getNick
                                                            ()),
@@ -1021,13 +1022,13 @@ Parser::parseScriptFunction (ServerConnection * cnx,
                             SCM scmFunc, int argsCount, String parameters)
 {
   String param;
-  SCM args_list = scm_listify (SCM_UNDEFINED);
+  SCM args_list = scm_list_n (SCM_UNDEFINED);
   if (needsChannelName)
     {
-      args_list = gh_append2 (args_list,
-                             scm_listify (Utils::
-                                          str2scm (channel),
-                                          SCM_UNDEFINED));
+      args_list = scm_append (scm_list_2 (args_list,
+                                         scm_list_n (Utils::
+                                                     str2scm (channel),
+                                                     SCM_UNDEFINED)));
       argsCount--;
     }
 
@@ -1038,9 +1039,9 @@ Parser::parseScriptFunction (ServerConnection * cnx,
        param = st.rest ();
       else
        param = st.next_token ();
-      args_list = gh_append2 (args_list,
-                             scm_listify (Utils::str2scm (param),
-                                          SCM_UNDEFINED));
+      args_list = scm_append (scm_list_2 (args_list,
+                                         scm_list_n (Utils::str2scm (param),
+                                                     SCM_UNDEFINED)));
     }
 
   struct wrapper_data wd;