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