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