Update all deprecated/discouraged Guile calls
[clinton/bobotpp.git] / source / Parser.C
index a262cd5..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
 
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <cstdlib>
 #include <sys/types.h>
 #include <netinet/in.h>
 
 #include "StringTokenizer.H"
 #include "Parser.H"
 #include "UserCommands.H"
+#include "Commands.H"
 #include "Macros.H"
 #include "Utils.H"
 #include "ShitList.H"
 
 typedef void (*fptr) (ServerConnection *, Person *, String);
-std::map < std::string, fptr, std::less < std::string > >Parser::functions;
+std::map < std::string, fptr, std::less < std::string > > Parser::functions;
 
 void
 Parser::init ()
@@ -78,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
@@ -356,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
@@ -379,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));
@@ -427,9 +430,9 @@ Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
          && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
        {
          // This is a part of the antispoof code
-         ch->getUser (n)->userkey = Utils::get_key ();
-         cnx->queue->sendCTCP (n, "PING",
-                               ch->getUser (n)->userkey + " " + c);
+         ch->getUser(n)->userkey = Utils::get_key ();
+         Commands::CTCP (cnx->bot, n, "PING", 
+                         ch->getUser(n)->userkey + " " + c);
        }
     }
 
@@ -449,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::
@@ -507,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
                                                            ()),
@@ -539,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::
@@ -586,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),
@@ -595,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),
@@ -612,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
@@ -652,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
@@ -712,8 +715,8 @@ Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
   StringTokenizer st (rest);
   String channel = st.next_token ();
 #ifdef USESCRIPTS
-  cnx->bot->botInterp->RunHooks (Hook::LEAVE, n + " " + channel,
-                                scm_listify (Utils::
+  cnx->bot->botInterp->RunHooks (Hook::PART, n + " " + channel,
+                                scm_list_n (Utils::
                                              str2scm (n),
                                              Utils::
                                              str2scm
@@ -721,7 +724,7 @@ Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
 #endif
   if (n.toLower () == cnx->bot->nickName.toLower ())
     {
-      cnx->bot->logLine (String ("Leaved channel ") + channel + ".");
+      cnx->bot->logLine (String ("Left channel ") + channel + ".");
       cnx->bot->channelList->delChannel (channel);
     }
   else
@@ -758,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),
@@ -784,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
                                                          ()),
@@ -818,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),
@@ -830,27 +833,36 @@ Parser::parseCTCP (ServerConnection * cnx,
                                              SCM_UNDEFINED));
 #endif
   if (command == "PING")
-    cnx->queue->sendCTCPReply (nick, "PING", rest);
+    {
+      Commands::CTCPReply (cnx->bot, nick, "PING", rest);
+    }
   else if (command == "VERSION")
-    cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+    {
+      Commands::CTCPReply (cnx->bot, nick, "VERSION", 
+                          cnx->bot->versionString);
+    }
   else if (command == "CLOCK")
     {
       time_t diff = time (NULL) - cnx->bot->startTime;
-      cnx->queue->sendCTCPReply (nick, "CLOCK",
-                                String ("elapsed time: ") +
-                                String ((long) (diff / 86400)) +
-                                "d" +
-                                String ((long) (diff % 86400) /
-                                        3600) + "h" +
-                                String ((long) (diff % 3600) / 60) +
-                                "m" + String ((long) (diff % 60)) + "s");
+      Commands::CTCPReply (cnx->bot, nick, "CLOCK",
+                          String ("elapsed time: ") +
+                          String ((long) (diff / 86400)) +
+                          "d" +
+                          String ((long) (diff % 86400) /
+                                  3600) + "h" +
+                          String ((long) (diff % 3600) / 60) +
+                          "m" + String ((long) (diff % 60)) + "s");
     }
   else if (command == "COMMAND")
-    cnx->queue->sendCTCPReply (nick,
-                              "COMMAND", String (cnx->bot->commandChar));
+    {
+      Commands::CTCPReply (cnx->bot, nick,
+                          "COMMAND", String (cnx->bot->commandChar));
+    }
   else if (command == "LAG")
-    cnx->queue->sendCTCPReply (nick, "LAG",
-                              String ((long) cnx->lag) + " second(s)");
+    {
+      Commands::CTCPReply (cnx->bot, nick, "LAG",
+                          String ((long) cnx->lag) + " second(s)");
+    }
   else if (command == "DCC")
     {
       StringTokenizer st2 (rest);
@@ -872,18 +884,11 @@ Parser::parseCTCP (ServerConnection * cnx,
   else if (command == "ACTION")
     {
       cnx->bot->botInterp->RunHooks (Hook::ACTION,
-                                    // FIXME: from->getAddress should
-                                    // be nick. MAYBE, depending on
-                                    // whether this could be
-                                    // considered a bug or a feature
-                                    // change to normalize
-                                    // hooks/action with the other
-                                    // hooks. Maybe a 3.0 change?
-                                    from->getAddress () + " " + to +
+                                    from->getNick () + " " + to +
                                     " " + rest,
-                                    scm_listify (Utils::
+                                    scm_list_n (Utils::
                                                  str2scm (from->
-                                                             getAddress
+                                                             getNick
                                                              ()),
                                                  Utils::
                                                  str2scm (to),
@@ -903,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
                                                            ()),
@@ -916,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
                                                            ()),
@@ -1017,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--;
     }
 
@@ -1034,15 +1039,17 @@ 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;
   wd.func = scmFunc;
   wd.args = args_list;
-  gh_catch (SCM_BOOL_T, (scm_t_catch_body) scm_apply_wrapper,
-           (void *) &wd, (scm_t_catch_handler) Interp::ErrorHandler, 0);
+  scm_internal_catch (SCM_BOOL_T,
+                     (scm_t_catch_body) Interp::LazyApplyWrapper, 
+                     (void *) &wd,
+                     (scm_t_catch_handler) Interp::EmptyHandler, 0);
 }
 #endif