]> Dogcows Code - chaz/openbox/blob - src/main.cc
testing whether i caused a bug with this code
[chaz/openbox] / src / main.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 // main.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #include "../version.h"
25
26 #ifdef HAVE_CONFIG_H
27 # include "../config.h"
28 #endif // HAVE_CONFIG_H
29
30 extern "C" {
31 #ifdef HAVE_STDIO_H
32 # include <stdio.h>
33 #endif // HAVE_STDIO_H
34
35 #ifdef HAVE_STDLIB_H
36 # include <stdlib.h>
37 #endif // HAVE_STDLIB_H
38
39 #ifdef HAVE_STRING_H
40 # include <string.h>
41 #endif // HAVE_STRING_H
42
43 #ifdef HAVE_UNISTD_H
44 #include <sys/types.h>
45 #endif // HAVE_UNISTD_H
46
47 #ifdef HAVE_SYS_PARAM_H
48 # include <sys/param.h>
49 #endif // HAVE_SYS_PARAM_H
50 }
51
52 #include <string>
53 using std::string;
54
55 #include "i18n.hh"
56 #include "blackbox.hh"
57
58
59 I18n i18n; // initialized in main
60
61 static void showHelp(int exitval) {
62 // print program usage and command line options
63 printf(i18n(mainSet, mainUsage,
64 "Openbox %s : (c) 2002 - 2002 Ben Jansens\n"
65 " 2001 - 2002 Sean 'Shaleh' Perry\n"
66 " 1997 - 2000, 2002 Brad Hughes\n\n"
67 " -display <string>\t\tuse display connection.\n"
68 " -rc <string>\t\t\tuse alternate resource file.\n"
69 " -menu <string>\t\tuse alternate menu file.\n"
70 " -version\t\t\tdisplay version and exit.\n"
71 " -help\t\t\t\tdisplay this help text and exit.\n\n"),
72 __openbox_version);
73
74 // some people have requested that we print out compile options
75 // as well
76 printf(i18n(mainSet, mainCompileOptions,
77 "Compile time options:\n"
78 " Debugging:\t\t\t%s\n"
79 " Shape:\t\t\t%s\n"
80 " Xft:\t\t\t\t%s\n"
81 " Xinerama:\t\t\t%s\n"
82 " 8bpp Ordered Dithering:\t%s\n\n"),
83 #ifdef DEBUG
84 i18n(CommonSet, CommonYes, "yes"),
85 #else // !DEBUG
86 i18n(CommonSet, CommonNo, "no"),
87 #endif // DEBUG
88
89 #ifdef SHAPE
90 i18n(CommonSet, CommonYes, "yes"),
91 #else // !SHAPE
92 i18n(CommonSet, CommonNo, "no"),
93 #endif // SHAPE
94
95 #ifdef XFT
96 i18n(CommonSet, CommonYes, "yes"),
97 #else // !XFT
98 i18n(CommonSet, CommonNo, "no"),
99 #endif // XFT
100
101 #ifdef XINERAMA
102 i18n(CommonSet, CommonYes, "yes"),
103 #else // !XINERAMA
104 i18n(CommonSet, CommonNo, "no"),
105 #endif // XINERAMA
106
107 #ifdef ORDEREDPSEUDO
108 i18n(CommonSet, CommonYes, "yes")
109 #else // !ORDEREDPSEUDO
110 i18n(CommonSet, CommonNo, "no")
111 #endif // ORDEREDPSEUDO
112 );
113
114 ::exit(exitval);
115 }
116
117 int main(int argc, char **argv) {
118 char *session_display = (char *) 0;
119 char *rc_file = (char *) 0;
120 char *menu_file = (char *) 0;
121
122 i18n.openCatalog("openbox.cat");
123
124 for (int i = 1; i < argc; ++i) {
125 if (! strcmp(argv[i], "-rc")) {
126 // look for alternative rc file to use
127
128 if ((++i) >= argc) {
129 fprintf(stderr,
130 i18n(mainSet, mainRCRequiresArg,
131 "error: '-rc' requires and argument\n"));
132
133 ::exit(1);
134 }
135
136 rc_file = argv[i];
137 } else if (! strcmp(argv[i], "-menu")) {
138 // look for alternative menu file to use
139
140 if ((++i) >= argc) {
141 fprintf(stderr,
142 i18n(mainSet, mainMENURequiresArg,
143 "error: '-menu' requires and argument\n"));
144
145 ::exit(1);
146 }
147
148 menu_file = argv[i];
149 } else if (! strcmp(argv[i], "-display")) {
150 // check for -display option... to run on a display other than the one
151 // set by the environment variable DISPLAY
152
153 if ((++i) >= argc) {
154 fprintf(stderr,
155 i18n(mainSet, mainDISPLAYRequiresArg,
156 "error: '-display' requires an argument\n"));
157
158 ::exit(1);
159 }
160
161 session_display = argv[i];
162 string dtmp = "DISPLAY=";
163 dtmp += session_display;
164
165 if (putenv(const_cast<char*>(dtmp.c_str()))) {
166 fprintf(stderr, i18n(mainSet, mainWarnDisplaySet,
167 "warning: couldn't set environment variable 'DISPLAY'\n"));
168 perror("putenv()");
169 }
170 } else if (! strcmp(argv[i], "-version")) {
171 // print current version string
172 printf("Openbox %s : (c) 2002 - 2002 Ben Jansens\n"
173 " 2001 - 2002 Sean 'Shaleh' Perry\n"
174 " 1997 - 2000, 2002 Brad Hughes\n\n",
175 __openbox_version);
176
177 ::exit(0);
178 } else if (! strcmp(argv[i], "-help")) {
179 showHelp(0);
180 } else { // invalid command line option
181 showHelp(-1);
182 }
183 }
184
185 #ifdef __EMX__
186 _chdir2(getenv("X11ROOT"));
187 #endif // __EMX__
188
189 Blackbox blackbox(argv, session_display, rc_file, menu_file);
190 blackbox.eventLoop();
191
192 return(0);
193 }
This page took 0.041265 seconds and 4 git commands to generate.