aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-05-16 00:46:41 (GMT)
committerfluxgen <fluxgen>2003-05-16 00:46:41 (GMT)
commitae5ce5e36856a934e370d85f312b0951c865ae50 (patch)
treecd4c8f351088fbe8774a4ef5c4ccbb892c1533c9 /src
parenteac7d2ac30fbce343ebf3f4fe6057c750e4e9460 (diff)
downloadfluxbox-ae5ce5e36856a934e370d85f312b0951c865ae50.zip
fluxbox-ae5ce5e36856a934e370d85f312b0951c865ae50.tar.bz2
fixed -log argument and did some cleaning
Diffstat (limited to 'src')
-rw-r--r--src/main.cc226
1 files changed, 125 insertions, 101 deletions
diff --git a/src/main.cc b/src/main.cc
index d0a17d7..b8b08af 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,8 +1,6 @@
1// main.cc for Fluxbox Window manager 1// main.cc for Fluxbox Window manager
2// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen(at)linuxmail.org) 2// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3// 3// and 2003 Simon Bowden (rathnor at users.sourceforge.net)
4// main.cc for Blackbox - an X11 Window manager
5// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6// 4//
7// Permission is hereby granted, free of charge, to any person obtaining a 5// Permission is hereby granted, free of charge, to any person obtaining a
8// copy of this software and associated documentation files (the "Software"), 6// copy of this software and associated documentation files (the "Software"),
@@ -16,20 +14,17 @@
16// 14//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
24 22
25// $Id: main.cc,v 1.16 2003/05/07 23:17:24 rathnor Exp $ 23// $Id: main.cc,v 1.17 2003/05/16 00:46:41 fluxgen Exp $
26
27
28 24
29#include "i18n.hh"
30#include "fluxbox.hh" 25#include "fluxbox.hh"
31 26#include "i18n.hh"
32#include "../version.h" 27#include "version.h"
33 28
34#ifdef HAVE_CONFIG_H 29#ifdef HAVE_CONFIG_H
35#include "config.h" 30#include "config.h"
@@ -43,28 +38,84 @@
43#include <cstdio> 38#include <cstdio>
44#include <cstdlib> 39#include <cstdlib>
45#include <cstring> 40#include <cstring>
46
47#ifdef HAVE_UNISTD_H
48#include <sys/types.h>
49#endif // HAVE_UNISTD_H
50
51#ifdef HAVE_SYS_PARAM_H
52#include <sys/param.h>
53#endif // HAVE_SYS_PARAM_H
54
55#include <iostream> 41#include <iostream>
42#include <fstream>
56#include <stdexcept> 43#include <stdexcept>
57#include <typeinfo> 44#include <typeinfo>
58 45
59using namespace std; 46using namespace std;
47void showInfo(ostream &ostr) {
48 ostr<<"Fluxbox version: "<<__fluxbox_version<<endl;
49 ostr<<"Compiled: "<<__DATE__<<" "<<__TIME__<<endl;
50 ostr<<"Compiler: ";
51#ifdef __GNUG__
52 ostr<<"GCC";
53#else
54 ostr<<"Unknown";
55#endif
56 ostr<<endl<<"Compiler version: "<<__VERSION__<<endl;
57
58 const char NOT[] = "-";
59 ostr<<"Compiled options ("<<NOT<<" => disabled): "<<endl<<
60#ifndef DEBUG
61 NOT<<
62#endif // DEBUG
63 "DEBUG"<<endl<<
64#ifndef SLIT
65 NOT<<
66#endif // SLIT
67 "SLIT"<<endl<<
68#ifndef HAVE_XPM
69 NOT<<
70#endif // HAVE_XPM
71 "XPM"<<endl<<
72#ifndef USE_GNOME
73 NOT<<
74#endif // USE_GNOME
75 "GNOME"<<endl<<
76#ifndef KDE
77 NOT<<
78#endif // KDE
79 "KDE"<<endl<<
80#ifndef USE_NEWWMSPEC
81 NOT<<
82#endif // USE_NEWWMSPEC
83 "EWMH"<<endl<<
84#ifndef REMEMBER
85 NOT<<
86#endif // REMEMBER
87 "REMEMBER"<<endl<<
88#ifndef SHAPE
89 NOT<<
90#endif // SHAPE
91 "SHAPE"<<endl<<
92#ifndef USE_XFT
93 NOT<<
94#endif // USE_XFT
95 "XFT"<<endl<<
96#ifndef USE_XMB
97 NOT<<
98#endif // USE_XMB
99 "XMB"<<endl<<
100#ifndef XINERAMA
101 NOT<<
102#endif // XINERAMA
103 "XINERAMA"<<endl<<
104#ifndef HAVE_XRENDER
105 NOT<<
106#endif // HAVE_XRENDER
107 "RENDER"<<endl<<
108 endl;
109}
60 110
61int main(int argc, char **argv) { 111int main(int argc, char **argv) {
62 112
63 char *session_display = 0; 113 std::string session_display;
64 char *rc_file = 0; 114 std::string rc_file;
115 std::string log_filename;
65 116
66 NLSInit("fluxbox.cat"); 117 NLSInit("fluxbox.cat");
67 I18n *i18n = I18n::instance(); 118 I18n &i18n = *I18n::instance();
68 119
69 int i; 120 int i;
70 for (i = 1; i < argc; ++i) { 121 for (i = 1; i < argc; ++i) {
@@ -73,8 +124,7 @@ int main(int argc, char **argv) {
73 124
74 if ((++i) >= argc) { 125 if ((++i) >= argc) {
75 fprintf(stderr, 126 fprintf(stderr,
76 i18n->getMessage( 127 i18n.getMessage(FBNLS::mainSet, FBNLS::mainRCRequiresArg,
77 FBNLS::mainSet, FBNLS::mainRCRequiresArg,
78 "error: '-rc' requires and argument\n")); 128 "error: '-rc' requires and argument\n"));
79 exit(1); 129 exit(1);
80 } 130 }
@@ -86,94 +136,46 @@ int main(int argc, char **argv) {
86 136
87 if ((++i) >= argc) { 137 if ((++i) >= argc) {
88 fprintf(stderr, 138 fprintf(stderr,
89 i18n->getMessage( 139 i18n.getMessage(FBNLS::mainSet, FBNLS::mainDISPLAYRequiresArg,
90 FBNLS::mainSet, FBNLS::mainDISPLAYRequiresArg,
91 "error: '-display' requires an argument\n")); 140 "error: '-display' requires an argument\n"));
92 exit(1); 141 exit(1);
93 } 142 }
94 143
95 session_display = argv[i]; 144 session_display = argv[i];
96 char dtmp[255]; 145 std::string display_env = "DISPLAY=" + session_display;
97 sprintf(dtmp, "DISPLAY=%s", session_display); 146 if (putenv(const_cast<char *>(display_env.c_str()))) {
98
99 if (putenv(dtmp)) {
100 fprintf(stderr, 147 fprintf(stderr,
101 i18n-> 148 i18n.
102 getMessage( 149 getMessage(FBNLS::mainSet, FBNLS::mainWarnDisplaySet,
103 FBNLS::mainSet, FBNLS::mainWarnDisplaySet,
104 "warning: couldn't set environment variable 'DISPLAY'\n")); 150 "warning: couldn't set environment variable 'DISPLAY'\n"));
105 perror("putenv()"); 151 perror("putenv()");
106 } 152 }
107 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { 153 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
108 // print current version string 154 // print current version string
109 printf("Fluxbox %s : (c) 2001-2003 Henrik Kinnunen \n\n", 155 cerr<<"Fluxbox "<<__fluxbox_version<<" : (c) 2001-2003 Henrik Kinnunen "<<endl<<endl;
110 __fluxbox_version);
111 exit(0); 156 exit(0);
157 } else if (strcmp(argv[i], "-log") == 0 ) {
158 if (i + 1 >= argc) {
159 cerr<<"error: '-log' need an argument"<<endl;
160 exit(1);
161 }
162 log_filename = argv[++i];
112 } else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) { 163 } else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
113 // print program usage and command line options 164 // print program usage and command line options
114 printf(i18n-> 165 printf(i18n.
115 getMessage( 166 getMessage(FBNLS::mainSet, FBNLS::mainUsage,
116 FBNLS::mainSet, FBNLS::mainUsage, 167 "Fluxbox %s : (c) %s Henrik Kinnunen\n"
117 "Fluxbox %s : (c) 2001-2003 Henrik Kinnunen\n\n" 168 "Website: http://www.fluxbox.org/ \n\n"
118 " -display <string>\t\tuse display connection.\n" 169 " -display <string>\t\tuse display connection.\n"
119 " -rc <string>\t\t\tuse alternate resource file.\n" 170 " -rc <string>\t\t\tuse alternate resource file.\n"
120 " -version\t\t\tdisplay version and exit.\n" 171 " -version\t\t\tdisplay version and exit.\n"
121 " -info\t\t\tdisplay some useful information.\n" 172 " -info\t\t\t\tdisplay some useful information.\n"
173 "\t-log <filename>\t\t\tlog output to file.\n"
122 " -help\t\t\t\tdisplay this help text and exit.\n\n"), 174 " -help\t\t\t\tdisplay this help text and exit.\n\n"),
123 __fluxbox_version); 175 __fluxbox_version, "2001-2003");
124 ::exit(0); 176 exit(0);
125 } else if (strcmp(argv[i], "-info") == 0 || strcmp(argv[i], "-i") == 0) { 177 } else if (strcmp(argv[i], "-info") == 0 || strcmp(argv[i], "-i") == 0) {
126#define NOT "-" 178 showInfo(cout);
127 cout<<"Compiled options ("<<NOT<<" => disabled): "<<endl<<
128#ifndef DEBUG
129 NOT<<
130#endif // DEBUG
131 "DEBUG"<<endl<<
132#ifndef SLIT
133 NOT<<
134#endif // SLIT
135 "SLIT"<<endl<<
136#ifndef HAVE_XPM
137 NOT<<
138#endif // HAVE_XPM
139 "XPM"<<endl<<
140#ifndef USE_GNOME
141 NOT<<
142#endif // USE_GNOME
143 "GNOME"<<endl<<
144#ifndef KDE
145 NOT<<
146#endif // KDE
147 "KDE"<<endl<<
148#ifndef USE_NEWWMSPEC
149 NOT<<
150#endif // USE_NEWWMSPEC
151 "EWMH"<<endl<<
152#ifndef REMEMBER
153 NOT<<
154#endif // REMEMBER
155 "REMEMBER"<<endl<<
156#ifndef SHAPE
157 NOT<<
158#endif // SHAPE
159 "SHAPE"<<endl<<
160#ifndef USE_XFT
161 NOT<<
162#endif // USE_XFT
163 "XFT"<<endl<<
164#ifndef USE_XMB
165 NOT<<
166#endif // USE_XMB
167 "XMB"<<endl<<
168#ifndef XINERAMA
169 NOT<<
170#endif // XINERAMA
171 "XINERAMA"<<endl<<
172#ifndef HAVE_XRENDER
173 NOT<<
174#endif // HAVE_XRENDER
175 "RENDER"<<endl<<
176 endl;
177 ::exit(0); 179 ::exit(0);
178 } 180 }
179 } 181 }
@@ -181,17 +183,35 @@ int main(int argc, char **argv) {
181#ifdef __EMX__ 183#ifdef __EMX__
182 _chdir2(getenv("X11ROOT")); 184 _chdir2(getenv("X11ROOT"));
183#endif // __EMX__ 185#endif // __EMX__
184 Fluxbox *fluxbox=0; 186 std::auto_ptr<Fluxbox> fluxbox;
185 int exitcode=EXIT_FAILURE; 187 int exitcode=EXIT_FAILURE;
188
189 streambuf *outbuf = 0;
190 streambuf *errbuf = 0;
191
192 ofstream log_file(log_filename.c_str());
193
194 // setup log file
195 if (log_file) {
196 cerr<<"Loggin to: "<<log_filename<<endl;
197 log_file<<"------------------------------------------"<<endl;
198 log_file<<"Logfile: "<<log_filename<<endl;
199 showInfo(log_file);
200 log_file<<"------------------------------------------"<<endl;
201 // setup log to use cout and cerr stream
202 outbuf = cout.rdbuf(log_file.rdbuf());
203 errbuf = cerr.rdbuf(log_file.rdbuf());
204 }
205
186 try { 206 try {
187 207
188 fluxbox = new Fluxbox(argc, argv, session_display, rc_file); 208 fluxbox.reset(new Fluxbox(argc, argv, session_display.c_str(), rc_file.c_str()));
189 fluxbox->eventLoop(); 209 fluxbox->eventLoop();
210
190 exitcode = EXIT_SUCCESS; 211 exitcode = EXIT_SUCCESS;
212
191 } catch (std::out_of_range &oor) { 213 } catch (std::out_of_range &oor) {
192 cerr<<"Fluxbox: Out of range: "<<oor.what()<<endl; 214 cerr<<"Fluxbox: Out of range: "<<oor.what()<<endl;
193 } catch (std::logic_error &le) {
194 cerr<<"Fluxbox: Logic error: "<<le.what()<<endl;
195 } catch (std::runtime_error &re) { 215 } catch (std::runtime_error &re) {
196 cerr<<"Fluxbox: Runtime error: "<<re.what()<<endl; 216 cerr<<"Fluxbox: Runtime error: "<<re.what()<<endl;
197 } catch (std::bad_cast &bc) { 217 } catch (std::bad_cast &bc) {
@@ -206,8 +226,12 @@ int main(int argc, char **argv) {
206 cerr<<"Fluxbox: Unknown error."<<endl; 226 cerr<<"Fluxbox: Unknown error."<<endl;
207 abort(); 227 abort();
208 } 228 }
209 229
210 if (fluxbox) 230 // restore cout and cin streams
211 delete fluxbox; 231 if (outbuf != 0)
232 cout.rdbuf(outbuf);
233 if (errbuf != 0)
234 cerr.rdbuf(errbuf);
235
212 return exitcode; 236 return exitcode;
213} 237}