don't include "cvs" in the version (not using cvs anymore :D)
[blackbox.git] / src / main.cc
blob1c01c2264ffb167abd7a0018912c4c590d53ecb4
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // main.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
25 // #define PRINT_SIZES
27 #if defined(PRINT_SIZES)
28 # include "Screen.hh"
29 # include "Slit.hh"
30 # include "Toolbar.hh"
31 # include "Window.hh"
32 #endif
34 #include "blackbox.hh"
35 #include "../version.h"
37 #include <stdio.h>
40 static void showHelp(int exitval) {
41 // print version - this should not be localized!
42 printf("Blackbox %s\n"
43 "Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry\n"
44 "Copyright (c) 1997 - 2000, 2002 - 2005 Bradley T Hughes\n",
45 __blackbox_version);
47 // print program usage and command line options
48 printf(" -display <string>\t\tuse display connection.\n"
49 " -single <string>\t\tmanage the default screen only\n"
50 " -rc <string>\t\t\tuse alternate resource file.\n"
51 " -version\t\t\tdisplay version and exit.\n"
52 " -help\t\t\t\tdisplay this help text and exit.\n\n");
54 // some people have requested that we print out compile options
55 // as well
56 printf("Compile time options:\n"
57 " Debugging:\t\t\t%s\n"
58 " Shape:\t\t\t%s\n"
59 " Xft:\t\t\t\t%s\n\n",
60 #ifdef DEBUG
61 "yes",
62 #else // !DEBUG
63 "no",
64 #endif // DEBUG
66 #ifdef SHAPE
67 "yes",
68 #else // !SHAPE
69 "no",
70 #endif // SHAPE
71 #ifdef XFT
72 "yes"
73 #else // !XFT
74 "no"
75 #endif // XFT
78 ::exit(exitval);
81 int main(int argc, char **argv) {
82 const char *dpy_name = 0;
83 std::string rc_file;
84 bool multi_head = true;
86 for (int i = 1; i < argc; ++i) {
87 if (! strcmp(argv[i], "-help")) {
88 showHelp(0);
89 } else if (! strcmp(argv[i], "-version")) {
90 // print current version string, this should not be localized!
91 printf("Blackbox %s\n"
92 "Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry\n"
93 "Copyright (c) 1997 - 2000, 2002 - 2005 Bradley T Hughes\n",
94 __blackbox_version);
96 ::exit(0);
97 } else if (! strcmp(argv[i], "-rc")) {
98 // look for alternative rc file to use
100 if ((++i) >= argc) {
101 fprintf(stderr, "error: '-rc' requires and argument\n");
102 ::exit(1);
105 rc_file = argv[i];
106 } else if (! strcmp(argv[i], "-display")) {
107 // check for -display option... to run on a display other than the one
108 // set by the environment variable DISPLAY
110 if ((++i) >= argc) {
111 fprintf(stderr, "error: '-display' requires an argument\n");
112 ::exit(1);
115 dpy_name = argv[i];
116 std::string dtmp = "DISPLAY=";
117 dtmp += dpy_name;
119 if (putenv(const_cast<char*>(dtmp.c_str()))) {
120 fprintf(stderr,
121 "warning: couldn't set environment variable 'DISPLAY'\n");
122 perror("putenv()");
124 } else if (! strcmp(argv[i], "-single")) {
125 multi_head = false;
126 } else { // invalid command line option
127 showHelp(-1);
131 #ifdef __EMX__
132 _chdir2(getenv("X11ROOT"));
133 #endif // __EMX__
135 if (rc_file.empty())
136 rc_file = "~/.blackboxrc";
137 rc_file = bt::expandTilde(rc_file);
139 #if defined(PRINT_SIZES)
140 printf("Blackbox : %4d bytes\n"
141 "BScreen : %4d bytes\n"
142 "BlackboxWindow: %4d bytes\n"
143 "Toolbar : %4d bytes\n"
144 "Slit : %4d bytes\n",
145 sizeof(Blackbox),
146 sizeof(BScreen),
147 sizeof(BlackboxWindow),
148 sizeof(Toolbar),
149 sizeof(Slit));
150 #endif
152 Blackbox blackbox(argv, dpy_name, rc_file, multi_head);
153 blackbox.run();
154 return 0;