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.
40 option bot_options[] =
42 { "help", no_argument, 0, 'h' },
43 { "version", no_argument, 0, 'v' },
44 { "no-background", no_argument, 0, 'b'},
45 { "config-file", required_argument, 0, 'f'},
46 { "config-dir", required_argument, 0, 'd'},
47 { "config", required_argument, 0, 'c'},
48 { "sys-config", required_argument, 0, 's'},
49 { "user-config", required_argument, 0, 'u'},
50 { "debug", no_argument, 0, 'D' }
56 b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, "");
63 std::cerr << VERSION_STRING << std::endl
64 << COPYRIGHT_STRING << std::endl
65 << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
66 << "This is free software, and you are welcome to redistribute it\n"
67 << "under certain conditions; See the COPYING file for details.\n";
69 void print_short_help (const char *name)
71 std::cerr << "Usage: " << name << " [--help] [--version] [--no-background]\n\t"
72 << "[--config-file file] [--config-dir dir] [--debug]\n\t"
73 << "[--config dir-under-configpath]\n\t"
74 << "[--sys-config dir-in-sysconfdir]\n\t"
75 << "[--user-config dir-userdir] [--debug]\n"
76 << "\n--help shows long help.\n";
77 /* " -b Do not run in background.\n"
78 " -f file Use file as config file.\n"
79 " -d dir Use dir as current dir.\n"
80 " -c config Use config as config\n"
81 " -s config Use config as config (only search sysdir)\n"
82 " -u config Use config as config (only search userdir)\n"
83 " -D Debug mode (input/output printing and no background mode.\n";
87 void print_long_help (const char *name)
89 std::cerr << "Long Help for " << PACKAGE << std::endl;
91 "The manual (info bobot++) will contain the best information on general\n"
92 "usage of Bobot++. Here is a detailed summary of the command line\n"
93 "arguments: (in long arg short arg format). All args are optional.\n";
94 print_short_help (name);
96 "[--help][-h] Shows this help and exits\n"
97 "[--version][-v] Shows version information and exits\n"
98 "[--no-background][-b] Run bobot++ in the foreground\n"
99 "[--config-file file][-f] Use file instead of bot.conf\n"
100 "[--config-dir dir][-d] Use dir as dir to load config file from\n"
101 "[--config dir][-c] Search your config path (defaults to\n"
104 << "/.bobotpp/config/ and then\n"
106 " /etc/bobotpp/) for dir and\n"
107 " then loads your config data using dir\n"
108 "[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n"
109 " that the user dir is still searched first\n"
110 "[--user-config dir][-u] Looks for config in\n"
113 << "/.bobotpp/config/dir/.\n"
116 " the system dir is still searched after this if\n"
117 " dir is not found.\n"
118 "[--debug][-D] Makes Bobot++ print debugging info and run in\n"
122 << "The default configuration is read from\n"
124 << "/.bobotpp/config/default/ and then\n"
125 "/etc/bobotpp/default/ if the user config is not found.\n";
128 static void real_main(void* DONOTUSE, int argc, char **argv)
130 // FIXME: User directory
132 bool background = true;
133 String configFile = "bot.conf";
134 String cmd_directory = "";
135 String sys_directory = "/etc/bobotpp/";
136 String sys_subdir = "default";
137 String user_directory = String(getenv ("HOME")) + "/.bobotpp/config/";
138 String user_subdir = "default";
141 std::signal(SIGPIPE, SIG_IGN);
142 std::signal(SIGALRM, SIG_IGN);
143 std::signal(SIGHUP, sig_hup);
145 // We parse the command line options
146 while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0))
150 print_long_help (argv[0]);
164 cmd_directory = optarg;
168 user_subdir = optarg;
171 user_subdir = optarg;
180 print_short_help (argv[0]);
184 if (!cmd_directory.length ())
186 if (chdir(user_directory + user_subdir) < 0)
187 if (chdir(sys_directory + sys_subdir) < 0)
189 std::cerr << "Dirs don't exist! Exiting\n";
190 std::exit (2); // no execution
194 if (chdir(cmd_directory) < 0)
196 std::perror("Error: ");
197 std::cerr << "Exiting...\n";
201 // std::cout << COPYRIGHT_STRING <<
202 // "\n"PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
203 // "This is free software, and you are welcome to redistribute it\n"
204 // "under certain conditions; See the COPYING file for details.\n";
211 std::cout << "Could not run in the background. Exiting...\n";
217 std::cout << "Running in the background...\n";
226 b = new Bot(configFile, debug);
235 } // static functions and data
237 int main(int argc, char **argv) {
239 scm_boot_guile (argc, argv, real_main, 0);
241 real_main(0, argc, argv);