Remove String->const char* conversion operator in favor of c_str method
[clinton/bobotpp.git] / source / Main.C
index c79624a..8e187fe 100644 (file)
 
 // 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 <iostream>
+#include <string>
+
 #include <cstdio>
 #include <csignal>
 #include <cstdlib>
-#include <getopt.h>
+
 #include <dirent.h>
+#include <getopt.h>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <iostream>
-#include <string>
-
 #ifdef USESCRIPTS
 #include "Interp.H"
 #endif
 
 #include "Bot.H"
+#include "Parser.H"
+#include "UserList.H"
 
 namespace 
 {
@@ -52,6 +56,9 @@ namespace
       { "config", required_argument, 0, 'c'},
       { "sys-config", required_argument, 0, 's'},
       { "user-config", required_argument, 0, 'u'},
+#ifdef USESCRIPTS
+      { "debug-scripts", no_argument, 0, 'S' },
+#endif
       { "debug", no_argument, 0, 'D' }
     };
 
@@ -116,6 +123,9 @@ namespace
       "                            dir is not found.\n"
       "[--debug][-D]               Makes Bobot++ print debugging info and run in\n"
       "                            the foreground"
+#ifdef USESCRIPTS
+      "\n[--debug-scripts][-S]       Turns on Guile debugging evaluator"
+#endif
                << std::endl
                << std::endl
                << "The default configuration is read from\n"
@@ -137,13 +147,14 @@ namespace
       std::string (getenv ("HOME")) + "/.bobotpp/config/";
     String user_subdir = "default";
     bool debug = false;
+    bool script_debug = false;
 
     std::signal(SIGPIPE, SIG_IGN);
     std::signal(SIGALRM, SIG_IGN);
     std::signal(SIGHUP,  sig_hup);
 
     // We parse the command line options
-    while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0)) 
+    while ((opt = getopt_long (argc,argv,"vhbf:d:c:DS", bot_options, 0)) 
           != -1)
       {
        switch (opt)
@@ -178,6 +189,9 @@ namespace
          case 'D':
            debug = true;
            break;
+         case 'S':
+           script_debug = true;
+           break;
          default:
            print_short_help (argv[0]); 
            std::exit(1);
@@ -186,9 +200,9 @@ namespace
 
     DIR * temp;
     
-    if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs")))
+    if (! (temp = opendir ((String(getenv ("HOME")) + "/.bobotpp/logs").c_str ())))
       {
-       mkdir (String(getenv ("HOME")) + "/.bobotpp/logs",
+       mkdir ((String(getenv ("HOME")) + "/.bobotpp/logs").c_str (),
               S_IRWXU);
       }
     else
@@ -222,25 +236,32 @@ namespace
     // initialize the Parser
     Parser::init ();
 
-    if (!debug) {
-      if (background)
-       switch (fork()) {
-       case -1:
-         std::cout << "Could not run in the background. Exiting...\n";
-         perror("fork");
-         exit(1);
-       case 0:
+    if (!debug) 
+      {
+       if (background)
+         switch (fork()) 
+           {
+           case -1:
+             std::cout << "Could not run in the background. Exiting...\n";
+             perror("fork");
+             exit(1);
+           case 0:
          break;
-       default:
-         std::cout << "Running in the background...\n";
-         exit(0);
-       }
-    }
+           default:
+             std::cout << "Running in the background...\n";
+             exit(0);
+           }
+      }
 
 #ifdef USESCRIPTS
     Interp::Startup();
+    if (debug || script_debug)
+      {
+       scm_c_eval_string("(debug-enable 'debug)" 
+                          "(debug-enable 'backtrace)"
+                          "(read-enable 'positions)");
+      }
 #endif
-
     b = new Bot(configFile, debug);
     b->run();
     delete b;