]> icculus.org git repositories - mikachu/openbox.git/blob - src/main.cc
gettext is ready to rock and roll
[mikachu/openbox.git] / src / main.cc
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2
3 #include "../version.h"
4
5 #ifdef    HAVE_CONFIG_H
6 #  include "../config.h"
7 #endif // HAVE_CONFIG_H
8
9 extern "C" {
10 #ifdef    HAVE_STDIO_H
11 #  include <stdio.h>
12 #endif // HAVE_STDIO_H
13
14 #ifdef HAVE_STDLIB_H
15 #  include <stdlib.h>
16 #endif // HAVE_STDLIB_H
17
18 #ifdef HAVE_STRING_H
19 #  include <string.h>
20 #endif // HAVE_STRING_H
21
22 #ifdef    HAVE_UNISTD_H
23 #include <sys/types.h>
24 #endif // HAVE_UNISTD_H
25
26 #ifdef    HAVE_SYS_PARAM_H
27 #  include <sys/param.h>
28 #endif // HAVE_SYS_PARAM_H
29 }
30
31 #include "gettext.h"
32 #define _(str) gettext(str)
33
34 #include <string>
35 using std::string;
36
37 #include "blackbox.hh"
38
39
40 static void showHelp(int exitval) {
41   // print program usage and command line options
42   printf(_("Openbox %s : (c) 2002 - 2002 Ben Jansens\n"),
43          OPENBOX_VERSION);
44   printf(_("  -display <string>  use display connection.\n\
45   -rc <string>       use alternate resource file.\n\
46   -menu <string>     use alternate menu file.\n\
47   -version           display version and exit.\n\
48   -help              display this help text and exit.\n\n"));
49
50   // some people have requested that we print out compile options
51   // as well
52   printf(_("Compile time options:\n\
53   Debugging:\t\t\t%s\n\
54   Shape:\t\t\t%s\n\
55   Xft:\t\t\t\t%s\n\
56   Xinerama:\t\t\t%s\n\
57   8bpp Ordered Dithering:\t%s\n\n"),
58 #ifdef    DEBUG
59          _("yes"),
60 #else // !DEBUG
61          _("no"),
62 #endif // DEBUG
63
64 #ifdef    SHAPE
65          _("yes"),
66 #else // !SHAPE
67          _("no"),
68 #endif // SHAPE
69
70 #ifdef    XFT
71          _("yes"),
72 #else // !XFT
73          _("no"),
74 #endif // XFT
75
76 #ifdef    XINERAMA
77          _("yes"),
78 #else // !XINERAMA
79          _("no"),
80 #endif // XINERAMA
81
82 #ifdef    ORDEREDPSEUDO
83          _("yes")
84 #else // !ORDEREDPSEUDO
85          _("no")
86 #endif // ORDEREDPSEUDO
87           );
88
89   ::exit(exitval);
90 }
91
92 int main(int argc, char **argv) {
93   char *session_display = (char *) 0;
94   char *rc_file = (char *) 0;
95   char *menu_file = (char *) 0;
96
97   // initialize the locale
98   setlocale(LC_ALL, "");
99   bindtextdomain(PACKAGE, LOCALEDIR);
100   textdomain(PACKAGE);
101   
102   for (int i = 1; i < argc; ++i) {
103     if (! strcmp(argv[i], "-rc")) {
104       // look for alternative rc file to use
105
106       if ((++i) >= argc) {
107         fprintf(stderr, _("error: '-rc' requires and argument\n"));
108
109         ::exit(1);
110       }
111
112       rc_file = argv[i];
113     } else if (! strcmp(argv[i], "-menu")) {
114       // look for alternative menu file to use
115
116       if ((++i) >= argc) {
117         fprintf(stderr, _("error: '-menu' requires and argument\n"));
118
119         ::exit(1);
120       }
121
122       menu_file = argv[i];
123     } else if (! strcmp(argv[i], "-display")) {
124       // check for -display option... to run on a display other than the one
125       // set by the environment variable DISPLAY
126
127       if ((++i) >= argc) {
128         fprintf(stderr, _("error: '-display' requires an argument\n"));
129
130         ::exit(1);
131       }
132
133       session_display = argv[i];
134       string dtmp = "DISPLAY=";
135       dtmp += session_display;
136
137       if (putenv(const_cast<char*>(dtmp.c_str()))) {
138         fprintf(stderr,
139                 _("warning: couldn't set environment variable 'DISPLAY'\n"));
140         perror("putenv()");
141       }
142     } else if (! strcmp(argv[i], "-version")) {
143       // print current version string
144       printf(_("Openbox %s : (c) 2002 - 2002 Ben Jansens\n"),
145              OPENBOX_VERSION);
146       printf("\n");
147
148       ::exit(0);
149     } else if (! strcmp(argv[i], "-help")) {
150       showHelp(0);
151     } else { // invalid command line option
152       showHelp(-1);
153     }
154   }
155
156 #ifdef    __EMX__
157   _chdir2(getenv("X11ROOT"));
158 #endif // __EMX__
159
160   Blackbox blackbox(argv, session_display, rc_file);
161   blackbox.eventLoop();
162
163   return(0);
164 }