2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002 Clinton Ebadi
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
31 #include <sys/types.h>
43 option bot_options[] =
45 { "help", no_argument, 0, 'h' },
46 { "version", no_argument, 0, 'v' },
47 { "no-background", no_argument, 0, 'b'},
48 { "config-file", required_argument, 0, 'f'},
49 { "config-dir", required_argument, 0, 'd'},
50 { "config", required_argument, 0, 'c'},
51 { "sys-config", required_argument, 0, 's'},
52 { "user-config", required_argument, 0, 'u'},
53 { "debug", no_argument, 0, 'D' }
59 b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, "");
66 std::cerr << VERSION_STRING << std::endl
67 << COPYRIGHT_STRING << std::endl
68 << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
69 << "This is free software, and you are welcome to redistribute it\n"
70 << "under certain conditions; See the COPYING file for details.\n";
72 void print_short_help (const char *name)
74 std::cerr << "Usage: "
76 << " [--help] [--version] [--no-background]\n\t"
77 << "[--config-file file] [--config-dir dir] [--debug]\n\t"
78 << "[--config dir-under-configpath]\n\t"
79 << "[--sys-config dir-in-sysconfdir]\n\t"
80 << "[--user-config dir-userdir] [--debug]\n"
81 << "\n--help shows long help.\n";
84 void print_long_help (const char *name)
86 std::cerr << "Long Help for " << PACKAGE << std::endl;
88 "The manual (info bobot++) will contain the best information on general\n"
89 "usage of Bobot++. Here is a detailed summary of the command line\n"
90 "arguments: (in long arg short arg format). All args are optional.\n";
91 print_short_help (name);
93 "[--help][-h] Shows this help and exits\n"
94 "[--version][-v] Shows version information and exits\n"
95 "[--no-background][-b] Run bobot++ in the foreground\n"
96 "[--config-file file][-f] Use file instead of bot.conf\n"
97 "[--config-dir dir][-d] Use dir as dir to load config file from\n"
98 "[--config dir][-c] Search your config path (defaults to\n"
101 << "/.bobotpp/config/ and then\n"
103 " /etc/bobotpp/) for dir and\n"
104 " then loads your config data using dir\n"
105 "[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n"
106 " that the user dir is still searched first\n"
107 "[--user-config dir][-u] Looks for config in\n"
110 << "/.bobotpp/config/dir/.\n"
113 " the system dir is still searched after this if\n"
114 " dir is not found.\n"
115 "[--debug][-D] Makes Bobot++ print debugging info and run in\n"
119 << "The default configuration is read from\n"
121 << "/.bobotpp/config/default/ and then\n"
122 "/etc/bobotpp/default/ if the user config is not found.\n";
125 static void real_main(void* DONOTUSE, int argc, char **argv)
127 // FIXME: User directory
129 bool background = true;
130 String configFile = "bot.conf";
131 String cmd_directory = "";
132 String sys_directory = "/etc/bobotpp/";
133 String sys_subdir = "default";
134 String user_directory = String(getenv ("HOME")) + "/.bobotpp/config/";
135 String user_subdir = "default";
138 std::signal(SIGPIPE, SIG_IGN);
139 std::signal(SIGALRM, SIG_IGN);
140 std::signal(SIGHUP, sig_hup);
142 // We parse the command line options
143 while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0))
147 print_long_help (argv[0]);
161 cmd_directory = optarg;
165 user_subdir = optarg;
168 user_subdir = optarg;
177 print_short_help (argv[0]);
182 if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs")))
183 mkdir (String(getenv ("HOME")) + "/.bobotpp/logs",
188 if (!cmd_directory.length ())
190 if (chdir(user_directory + user_subdir) < 0)
191 if (chdir(sys_directory + sys_subdir) < 0)
193 std::cerr << "Dirs don't exist! Exiting\n";
194 std::exit (2); // no execution
198 if (chdir(cmd_directory) < 0)
200 std::perror("Error: ");
201 std::cerr << "Exiting...\n";
205 // std::cout << COPYRIGHT_STRING <<
206 // "\n"PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
207 // "This is free software, and you are welcome to redistribute it\n"
208 // "under certain conditions; See the COPYING file for details.\n";
211 // initialize the Parser
218 std::cout << "Could not run in the background. Exiting...\n";
224 std::cout << "Running in the background...\n";
233 b = new Bot(configFile, debug);
242 } // static functions and data
244 int main(int argc, char **argv) {
246 scm_boot_guile (argc, argv, real_main, 0);
248 real_main(0, argc, argv);