[project @ 2005-06-28 10:08:45 by unknown_lamer]
[clinton/bobotpp.git] / source / BotInterp.C
index d678660..01ba996 100644 (file)
@@ -14,7 +14,7 @@
 
 // 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"
@@ -35,8 +35,8 @@ extern "C"
 BotInterp::BotInterp(Bot *b, String fn)
   : bot(b), counter(0)
 {
-  logPort = scm_open_file(Utils::string2SCM(fn),
-                          Utils::string2SCM("a"));
+  logPort = scm_open_file(Utils::str2scm (fn),
+                          Utils::str2scm ("a"));
   scm_gc_protect_object(logPort);
 }
 
@@ -52,13 +52,10 @@ BotInterp::LoadScript(String filename)
   Interp::LoadScript(bot, filename);
 }
 
-void
-BotInterp::ScriptLog(SCM throw_args)
+SCM
+BotInterp::ScriptLog()
 {
-  scm_display_error_message(SCM_CADR (throw_args),
-                            SCM_CADDR (throw_args),
-                            logPort);
-  scm_flush(logPort);
+  return logPort;
 }
 
 namespace
@@ -70,10 +67,11 @@ namespace
 }
 
 bool
-BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall) {
+BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall,
+                  String name) {
   if (scm_string_p(regex) == SCM_BOOL_F)
     return false;
-  String rx = Utils::scm2String(regex).toUpper();
+  String rx = Utils::to_upper (Utils::scm2str (regex));
   SCM r = scm_make_regexp(regex,
                           scm_listify (gh_lookup("regexp/icase"),
                                   SCM_UNDEFINED));
@@ -85,7 +83,7 @@ BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall) {
 
   for ( ; it != it2; ++it)
     // It exists, we replace it.
-    if ((*it)->regex_str == rx) {
+    if ((*it)->regex_str == rx && (*it)->name == name) {
       scm_gc_unprotect_object((*it)->function);
       scm_gc_unprotect_object (r);
       (*it)->function = function;
@@ -96,7 +94,7 @@ BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall) {
     }
   // It does not exist, we create it
   hooksMap[hooktype].push_back (new Hook(hooktype, rx, r, 
-                                        function, pri, fall));
+                                        function, pri, fall, name));
   hooksMap[hooktype].sort (hptr_lt);
   return true;
 }
@@ -112,14 +110,14 @@ BotInterp::RunHooks(int hooktype, String match, SCM args)
   wrapper_data wd;
   wd.args = args;
   for ( ; it != it2; ++it) {
-    if (scm_regexp_exec((*it)->regex, Utils::string2SCM(match),
+    if (scm_regexp_exec((*it)->regex, Utils::str2scm (match),
                         SCM_UNDEFINED, SCM_UNDEFINED) != SCM_BOOL_F)
       {
        wd.func = (*it)->function;
-       result = gh_catch(SCM_BOOL_T, 
-                         (scm_t_catch_body) scm_apply_wrapper,
-                         static_cast<void *> (&wd), 
-                         (scm_t_catch_handler) Interp::ErrorHandler, 0);
+       result = scm_internal_catch(SCM_BOOL_T, 
+                                   (scm_t_catch_body) lazy_apply_wrapper,
+                                   static_cast<void *> (&wd), 
+                                   (scm_t_catch_handler) empty_handler, 0);
        if (! (*it)->fallthru)
          break;
     }
@@ -162,15 +160,16 @@ BotInterp::RunTimers(int now)
   std::list<Timer *>::iterator it = timersList.begin();
   std::list<Timer *>::iterator it2 = timersList.end();
   std::list<Timer *>::iterator it3;
-  Timer *t;
+
   struct wrapper_data wd;
   wd.args = scm_listify (SCM_UNDEFINED);
 
   while (it != it2) {
     if ((*it)->when <= now) {
       wd.func = (*it)->function;
-      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) lazy_apply_wrapper, (void *)&wd,
+                    (scm_t_catch_handler) empty_handler, 0);
       scm_gc_unprotect_object(wd.func);
       it3 = it;
       ++it3;