]> icculus.org git repositories - mikachu/openbox.git/blob - src/main.cc
converted from LinkedList to STL vector and list
[mikachu/openbox.git] / 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                           "  -version\t\t\tdisplay version and exit.\n"
72                           "  -help\t\t\t\tdisplay this help text and exit.\n\n"),
73          __openbox_version);
74
75   // some people have requested that we print out compile options
76   // as well
77   fprintf(stdout,i18n->getMessage(mainSet, mainCompileOptions,
78                                   "Compile time options:\n"
79                                   "  Debugging:\t\t\t%s\n"
80                                   "  Interlacing:\t\t\t%s\n"
81                                   "  Shape:\t\t\t%s\n"
82                                   "  Slit:\t\t\t\t%s\n"
83                                   "  8bpp Ordered Dithering:\t%s\n"
84                                   "  Event Clobbering:\t\t%s\n\n"),
85 #ifdef    DEBUG
86           i18n->getMessage(CommonSet, CommonYes, "yes"),
87 #else // !DEBUG
88           i18n->getMessage(CommonSet, CommonNo, "no"),
89 #endif // DEBUG
90
91 #ifdef    INTERLACE
92           i18n->getMessage(CommonSet, CommonYes, "yes"),
93 #else // !INTERLACE
94           i18n->getMessage(CommonSet, CommonNo, "no"),
95 #endif // INTERLACE
96
97 #ifdef    SHAPE
98           i18n->getMessage(CommonSet, CommonYes, "yes"),
99 #else // !SHAPE
100           i18n->getMessage(CommonSet, CommonNo, "no"),
101 #endif // SHAPE
102
103 #ifdef    SLIT
104           i18n->getMessage(CommonSet, CommonYes, "yes"),
105 #else // !SLIT
106           i18n->getMessage(CommonSet, CommonNo, "no"),
107 #endif // SLIT
108
109 #ifdef    ORDEREDPSEUDO
110           i18n->getMessage(CommonSet, CommonYes, "yes"),
111 #else // !ORDEREDPSEUDO
112           i18n->getMessage(CommonSet, CommonNo, "no"),
113 #endif // ORDEREDPSEUDO
114
115 #ifndef   NOCLOBBER
116           i18n->getMessage(CommonSet, CommonYes, "yes")
117 #else // !NOCLOBBER
118           i18n->getMessage(CommonSet, CommonNo, "no")
119 #endif // NOCLOBBER
120           );
121
122   ::exit(exitval);
123 }
124
125 int main(int argc, char **argv) {
126   char *session_display = (char *) 0;
127   char *rc_file = (char *) 0;
128
129   NLSInit("openbox.cat");
130
131   for (int i = 1; i < argc; ++i) {
132     if (! strcmp(argv[i], "-rc")) {
133       // look for alternative rc file to use
134
135       if ((++i) >= argc) {
136         fprintf(stderr,
137                 i18n->getMessage(mainSet, mainRCRequiresArg,
138                                  "error: '-rc' requires and argument\n"));
139
140         ::exit(1);
141       }
142
143       rc_file = argv[i];
144     } else if (! strcmp(argv[i], "-display")) {
145       // check for -display option... to run on a display other than the one
146       // set by the environment variable DISPLAY
147
148       if ((++i) >= argc) {
149         fprintf(stderr,
150                 i18n->getMessage(mainSet, mainDISPLAYRequiresArg,
151                                  "error: '-display' requires an argument\n"));
152
153         ::exit(1);
154       }
155
156       session_display = argv[i];
157       char dtmp[MAXPATHLEN];
158       sprintf(dtmp, "DISPLAY=%s", session_display);
159
160       if (putenv(dtmp)) {
161         fprintf(stderr,
162                 i18n->
163                 getMessage(mainSet, mainWarnDisplaySet,
164                    "warning: couldn't set environment variable 'DISPLAY'\n"));
165         perror("putenv()");
166       }
167     } else if (! strcmp(argv[i], "-version")) {
168       // print current version string
169       printf("Openbox %s : (c) 1997 - 2000 Brad Hughes\n"
170              "\t\t\t  2001 - 2002 Sean 'Shaleh' Perry\n",
171              __openbox_version);
172
173       ::exit(0);
174     } else if (! strcmp(argv[i], "-help")) {
175       showHelp(0);
176     } else { // invalid command line option
177       showHelp(-1);
178     }
179   }
180
181 #ifdef    __EMX__
182   _chdir2(getenv("X11ROOT"));
183 #endif // __EMX__
184
185   Openbox openbox(argc, argv, session_display, rc_file);
186   openbox.eventLoop();
187
188   return(0);
189 }