aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/main.cc b/src/main.cc
index d65212b..dc42b27 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -182,14 +182,15 @@ static void showInfo(ostream &ostr) {
182 endl; 182 endl;
183} 183}
184 184
185int main(int argc, char **argv) { 185struct Options {
186 std::string session_display;
187 std::string rc_file;
188 std::string log_filename;
189 bool xsync;
190};
186 191
187 string session_display(""); 192static void parseOptions(int argc, char** argv, Options& opts) {
188 string rc_file;
189 string log_filename;
190 bool xsync = false;
191 193
192 FbTk::NLSInit("fluxbox.cat");
193 _FB_USES_NLS; 194 _FB_USES_NLS;
194 195
195 int i; 196 int i;
@@ -204,7 +205,7 @@ int main(int argc, char **argv) {
204 exit(EXIT_FAILURE); 205 exit(EXIT_FAILURE);
205 } 206 }
206 207
207 rc_file = argv[i]; 208 opts.rc_file = argv[i];
208 } else if (arg == "-display" || arg == "--display") { 209 } else if (arg == "-display" || arg == "--display") {
209 // check for -display option... to run on a display other than the one 210 // check for -display option... to run on a display other than the one
210 // set by the environment variable DISPLAY 211 // set by the environment variable DISPLAY
@@ -216,8 +217,8 @@ int main(int argc, char **argv) {
216 exit(EXIT_FAILURE); 217 exit(EXIT_FAILURE);
217 } 218 }
218 219
219 session_display = argv[i]; 220 opts.session_display = argv[i];
220 string display_env = "DISPLAY=" + session_display; 221 string display_env = "DISPLAY=" + opts.session_display;
221 if (putenv(const_cast<char *>(display_env.c_str()))) { 222 if (putenv(const_cast<char *>(display_env.c_str()))) {
222 cerr<<_FB_CONSOLETEXT(main, WarnDisplayEnv, 223 cerr<<_FB_CONSOLETEXT(main, WarnDisplayEnv,
223 "warning: couldn't set environment variable 'DISPLAY'", 224 "warning: couldn't set environment variable 'DISPLAY'",
@@ -226,16 +227,16 @@ int main(int argc, char **argv) {
226 } 227 }
227 } else if (arg == "-version" || arg == "-v" || arg == "--version") { 228 } else if (arg == "-version" || arg == "-v" || arg == "--version") {
228 // print current version string 229 // print current version string
229 cout << "Fluxbox " << __fluxbox_version << " : (c) 2001-2008 Fluxbox Team " << endl << endl; 230 cout << "Fluxbox " << __fluxbox_version << " : (c) 2001-2010 Fluxbox Team " << endl << endl;
230 exit(EXIT_SUCCESS); 231 exit(EXIT_SUCCESS);
231 } else if (arg == "-log" || arg == "--log") { 232 } else if (arg == "-log" || arg == "--log") {
232 if (++i >= argc) { 233 if (++i >= argc) {
233 cerr<<_FB_CONSOLETEXT(main, LOGRequiresArg, "error: '-log' needs an argument", "")<<endl; 234 cerr<<_FB_CONSOLETEXT(main, LOGRequiresArg, "error: '-log' needs an argument", "")<<endl;
234 exit(EXIT_FAILURE); 235 exit(EXIT_FAILURE);
235 } 236 }
236 log_filename = argv[i]; 237 opts.log_filename = argv[i];
237 } else if (arg == "-sync" || arg == "--sync") { 238 } else if (arg == "-sync" || arg == "--sync") {
238 xsync = true; 239 opts.xsync = true;
239 } else if (arg == "-help" || arg == "-h" || arg == "--help") { 240 } else if (arg == "-help" || arg == "-h" || arg == "--help") {
240 // print program usage and command line options 241 // print program usage and command line options
241 printf(_FB_CONSOLETEXT(main, Usage, 242 printf(_FB_CONSOLETEXT(main, Usage,
@@ -252,7 +253,7 @@ int main(int argc, char **argv) {
252 "-help\t\t\t\tdisplay this help text and exit.\n\n", 253 "-help\t\t\t\tdisplay this help text and exit.\n\n",
253 254
254 "Main usage string. Please lay it out nicely. There is one %s that is given the version").c_str(), 255 "Main usage string. Please lay it out nicely. There is one %s that is given the version").c_str(),
255 __fluxbox_version, "2001-2008"); 256 __fluxbox_version, "2001-2010");
256 exit(EXIT_SUCCESS); 257 exit(EXIT_SUCCESS);
257 } else if (arg == "-info" || arg == "-i" || arg == "--info") { 258 } else if (arg == "-info" || arg == "-i" || arg == "--info") {
258 showInfo(cout); 259 showInfo(cout);
@@ -268,23 +269,34 @@ int main(int argc, char **argv) {
268 FbTk::ThemeManager::instance().setVerbose(true); 269 FbTk::ThemeManager::instance().setVerbose(true);
269 } 270 }
270 } 271 }
272}
273
274
275
276int main(int argc, char **argv) {
277
278 FbTk::NLSInit("fluxbox.cat");
279
280 Options opts;
281 parseOptions(argc, argv, opts);
271 282
272#ifdef __EMX__ 283#ifdef __EMX__
273 _chdir2(getenv("X11ROOT")); 284 _chdir2(getenv("X11ROOT"));
274#endif // __EMX__ 285#endif // __EMX__
275 auto_ptr<Fluxbox> fluxbox; 286 auto_ptr<Fluxbox> fluxbox;
276 int exitcode=EXIT_FAILURE;
277 287
278 streambuf *outbuf = 0; 288 streambuf *outbuf = 0;
279 streambuf *errbuf = 0; 289 streambuf *errbuf = 0;
280 290
281 ofstream log_file(log_filename.c_str()); 291 ofstream log_file(opts.log_filename.c_str());
292
293 _FB_USES_NLS;
282 294
283 // setup log file 295 // setup log file
284 if (log_file) { 296 if (log_file.is_open()) {
285 cerr<<_FB_CONSOLETEXT(main, LoggingTo, "Logging to", "Logging to a file")<<": "<<log_filename<<endl; 297 cerr<<_FB_CONSOLETEXT(main, LoggingTo, "Logging to", "Logging to a file")<<": "<<opts.log_filename<<endl;
286 log_file<<"------------------------------------------"<<endl; 298 log_file<<"------------------------------------------"<<endl;
287 log_file<<_FB_CONSOLETEXT(main, LogFile, "Log File", "")<<": "<<log_filename<<endl; 299 log_file<<_FB_CONSOLETEXT(main, LogFile, "Log File", "")<<": "<<opts.log_filename<<endl;
288 showInfo(log_file); 300 showInfo(log_file);
289 log_file<<"------------------------------------------"<<endl; 301 log_file<<"------------------------------------------"<<endl;
290 // setup log to use cout and cerr stream 302 // setup log to use cout and cerr stream
@@ -292,10 +304,14 @@ int main(int argc, char **argv) {
292 errbuf = cerr.rdbuf(log_file.rdbuf()); 304 errbuf = cerr.rdbuf(log_file.rdbuf());
293 } 305 }
294 306
307 int exitcode = EXIT_FAILURE;
308
295 try { 309 try {
296 310
297 fluxbox.reset(new Fluxbox(argc, argv, session_display.c_str(), 311 fluxbox.reset(new Fluxbox(argc, argv,
298 rc_file.c_str(), xsync)); 312 opts.session_display.c_str(),
313 opts.rc_file.c_str(),
314 opts.xsync));
299 fluxbox->eventLoop(); 315 fluxbox->eventLoop();
300 316
301 exitcode = EXIT_SUCCESS; 317 exitcode = EXIT_SUCCESS;