]> Dogcows Code - chaz/openbox/blob - src/main.cc
3f67f157c6e3c055465c4caf882de9255c4e051c
[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 #ifdef HAVE_STDIO_H
36 # include <stdio.h>
37 #endif // HAVE_STDIO_H
38
39 #ifdef HAVE_STDLIB_H
40 # include <stdlib.h>
41 #endif // HAVE_STDLIB_H
42
43 #ifdef HAVE_STRING_H
44 # include <string.h>
45 #endif // HAVE_STRING_H
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 #include "openbox.h"
60 #include "i18n.h"
61
62 I18n i18n("openbox.cat");
63
64 static void showHelp(int exitval) {
65 // print program usage and command line options
66 printf(i18n(mainSet, mainUsage,
67 "Openbox %s : (c) 2002 - 2002 Ben Jansens\n"
68 "\t\t\t 2001 - 2002 Sean 'Shaleh' Perry\n\n"
69 "\t\t\t 1997 - 2000 Brad Hughes\n\n"
70 " -display <string>\t\tuse display connection.\n"
71 " -rc <string>\t\t\tuse alternate resource file.\n"
72 " -menu <string>\t\t\tuse alternate menu file.\n"
73 " -version\t\t\tdisplay version and exit.\n"
74 " -help\t\t\t\tdisplay this help text and exit.\n\n"),
75 __openbox_version);
76
77 // some people have requested that we print out compile options
78 // as well
79 fprintf(stdout,i18n(mainSet, mainCompileOptions,
80 "Compile time options:\n"
81 " Debugging:\t\t\t%s\n"
82 " Interlacing:\t\t\t%s\n"
83 " Shape:\t\t\t%s\n"
84 " Slit:\t\t\t\t%s\n"
85 " 8bpp Ordered Dithering:\t%s\n"
86 " Event Clobbering:\t\t%s\n\n"),
87 #ifdef DEBUG
88 i18n(CommonSet, CommonYes, "yes"),
89 #else // !DEBUG
90 i18n(CommonSet, CommonNo, "no"),
91 #endif // DEBUG
92
93 #ifdef INTERLACE
94 i18n(CommonSet, CommonYes, "yes"),
95 #else // !INTERLACE
96 i18n(CommonSet, CommonNo, "no"),
97 #endif // INTERLACE
98
99 #ifdef SHAPE
100 i18n(CommonSet, CommonYes, "yes"),
101 #else // !SHAPE
102 i18n(CommonSet, CommonNo, "no"),
103 #endif // SHAPE
104
105 #ifdef SLIT
106 i18n(CommonSet, CommonYes, "yes"),
107 #else // !SLIT
108 i18n(CommonSet, CommonNo, "no"),
109 #endif // SLIT
110
111 #ifdef ORDEREDPSEUDO
112 i18n(CommonSet, CommonYes, "yes"),
113 #else // !ORDEREDPSEUDO
114 i18n(CommonSet, CommonNo, "no"),
115 #endif // ORDEREDPSEUDO
116
117 #ifndef NOCLOBBER
118 i18n(CommonSet, CommonYes, "yes")
119 #else // !NOCLOBBER
120 i18n(CommonSet, CommonNo, "no")
121 #endif // NOCLOBBER
122 );
123
124 ::exit(exitval);
125 }
126
127 int main(int argc, char **argv) {
128 char *session_display = (char *) 0;
129 char *rc_file = (char *) 0;
130 char *menu_file = (char *) 0;
131
132 for (int i = 1; i < argc; ++i) {
133 if (! strcmp(argv[i], "-rc")) {
134 // look for alternative rc file to use
135
136 if ((++i) >= argc) {
137 fprintf(stderr,
138 i18n(mainSet, mainRCRequiresArg,
139 "error: '-rc' requires and argument\n"));
140
141 ::exit(1);
142 }
143
144 rc_file = argv[i];
145 } else if (! strcmp(argv[i], "-menu")) {
146 // look for alternative menu file to use
147
148 if ((++i) >= argc) {
149 fprintf(stderr,
150 i18n(mainSet, mainMENURequiresArg,
151 "error: '-menu' requires and argument\n"));
152
153 ::exit(1);
154 }
155
156 menu_file = argv[i];
157 } else if (! strcmp(argv[i], "-display")) {
158 // check for -display option... to run on a display other than the one
159 // set by the environment variable DISPLAY
160
161 if ((++i) >= argc) {
162 fprintf(stderr,
163 i18n(mainSet, mainDISPLAYRequiresArg,
164 "error: '-display' requires an argument\n"));
165
166 ::exit(1);
167 }
168
169 session_display = argv[i];
170 char dtmp[MAXPATHLEN];
171 sprintf(dtmp, "DISPLAY=%s", session_display);
172
173 if (putenv(dtmp)) {
174 fprintf(stderr,
175 i18n(mainSet, mainWarnDisplaySet,
176 "warning: couldn't set environment variable 'DISPLAY'\n"));
177 perror("putenv()");
178 }
179 } else if (! strcmp(argv[i], "-version")) {
180 // print current version string
181 printf("Openbox %s : (c) 1997 - 2000 Brad Hughes\n"
182 "\t\t\t 2001 - 2002 Sean 'Shaleh' Perry\n",
183 __openbox_version);
184
185 ::exit(0);
186 } else if (! strcmp(argv[i], "-help")) {
187 showHelp(0);
188 } else { // invalid command line option
189 showHelp(-1);
190 }
191 }
192
193 #ifdef __EMX__
194 _chdir2(getenv("X11ROOT"));
195 #endif // __EMX__
196
197 Openbox openbox(argc, argv, session_display, rc_file, menu_file);
198 openbox.eventLoop();
199
200 return(0);
201 }
This page took 0.040867 seconds and 4 git commands to generate.