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