aboutsummaryrefslogtreecommitdiff
path: root/src/cli_options.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli_options.cc')
-rw-r--r--src/cli_options.cc158
1 files changed, 158 insertions, 0 deletions
diff --git a/src/cli_options.cc b/src/cli_options.cc
new file mode 100644
index 0000000..1455ea1
--- /dev/null
+++ b/src/cli_options.cc
@@ -0,0 +1,158 @@
1// cli_options.cc for Fluxbox Window Manager
2// Copyright (c) 2014 - Mathias Gumz <akira at fluxbox.org>
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#include "cli.hh"
23#include "version.h"
24#include "defaults.hh"
25#include "Debug.hh"
26
27#include "FbTk/App.hh"
28#include "FbTk/FileUtil.hh"
29#include "FbTk/StringUtil.hh"
30#include "FbTk/Theme.hh"
31#include "FbTk/I18n.hh"
32#include "FbTk/Command.hh"
33#include "FbTk/CommandParser.hh"
34
35#ifdef HAVE_CONFIG_H
36#include "config.h"
37#endif // HAVE_CONFIG_H
38
39#ifdef HAVE_CSTDLIB
40 #include <cstdlib>
41#else
42 #include <stdlib.h>
43#endif
44
45#ifdef HAVE_CSTRING
46 #include <cstring>
47#else
48 #include <string.h>
49#endif
50
51#include <iostream>
52
53using std::cerr;
54using std::cout;
55using std::endl;
56using std::string;
57
58FluxboxCli::Options::Options() : xsync(false) {
59
60 const char* env = getenv("DISPLAY");
61 if (env && strlen(env) > 0) {
62 session_display.assign(env);
63 }
64
65 string fname = std::string("~/.") + realProgramName("fluxbox");
66 rc_path = FbTk::StringUtil::expandFilename(fname);
67
68 if (!rc_path.empty()) {
69 rc_file = rc_path + "/init";
70 }
71}
72
73int FluxboxCli::Options::parse(int argc, char** argv) {
74
75 _FB_USES_NLS;
76
77 int i;
78 for (i = 1; i < argc; ++i) {
79 string arg(argv[i]);
80 if (arg == "-rc" || arg == "--rc") {
81 // look for alternative rc file to use
82
83 if ((++i) >= argc) {
84 cerr<<_FB_CONSOLETEXT(main, RCRequiresArg,
85 "error: '-rc' requires an argument",
86 "the -rc option requires a file argument")<<endl;
87 return EXIT_FAILURE;
88 }
89
90 this->rc_file = argv[i];
91
92 } else if (arg == "-display" || arg == "--display") {
93 // check for -display option... to run on a display other than the one
94 // set by the environment variable DISPLAY
95
96 if ((++i) >= argc) {
97 cerr<<_FB_CONSOLETEXT(main, DISPLAYRequiresArg,
98 "error: '-display' requires an argument",
99 "")<<endl;
100 return EXIT_FAILURE;
101 }
102
103 this->session_display = argv[i];
104 if (!FbTk::App::setenv("DISPLAY", argv[i])) {
105 cerr<<_FB_CONSOLETEXT(main, WarnDisplayEnv,
106 "warning: couldn't set environment variable 'DISPLAY'",
107 "")<<endl;
108 perror("putenv()");
109 }
110 } else if (arg == "-version" || arg == "-v" || arg == "--version") {
111 // print current version string
112 cout << "Fluxbox " << __fluxbox_version << " : (c) 2001-2014 Fluxbox Team "
113 << endl << endl;
114 return EXIT_SUCCESS;
115 } else if (arg == "-log" || arg == "--log") {
116 if (++i >= argc) {
117 cerr<<_FB_CONSOLETEXT(main, LOGRequiresArg,
118 "error: '-log' needs an argument", "")<<endl;
119 return EXIT_FAILURE;
120 }
121 this->log_filename = argv[i];
122 } else if (arg == "-sync" || arg == "--sync") {
123 this->xsync = true;
124 } else if (arg == "-help" || arg == "-h" || arg == "--help") {
125 // print program usage and command line options
126 printf(_FB_CONSOLETEXT(main, Usage,
127 "Fluxbox %s : (c) %s Fluxbox Team\n"
128 "Website: http://www.fluxbox.org/\n\n"
129 "-display <string>\t\tuse display connection.\n"
130 "-screen <all|int,int,int>\trun on specified screens only.\n"
131 "-rc <string>\t\t\tuse alternate resource file.\n"
132 "-version\t\t\tdisplay version and exit.\n"
133 "-info\t\t\t\tdisplay some useful information.\n"
134 "-list-commands\t\t\tlist all valid key commands.\n"
135 "-sync\t\t\t\tsynchronize with X server for debugging.\n"
136 "-log <filename>\t\t\tlog output to file.\n"
137 "-help\t\t\t\tdisplay this help text and exit.\n\n",
138
139 "Main usage string. Please lay it out nicely. There is one %s that is given the version").c_str(),
140 __fluxbox_version, "2001-2014");
141 return EXIT_SUCCESS;
142 } else if (arg == "-info" || arg == "-i" || arg == "--info") {
143 FluxboxCli::showInfo(cout);
144 return EXIT_SUCCESS;
145 } else if (arg == "-list-commands" || arg == "--list-commands") {
146 FbTk::CommandParser<void>::CreatorMap cmap = FbTk::CommandParser<void>::instance().creatorMap();
147 FbTk::CommandParser<void>::CreatorMap::const_iterator it = cmap.begin();
148 const FbTk::CommandParser<void>::CreatorMap::const_iterator it_end = cmap.end();
149 for (; it != it_end; ++it)
150 cout << it->first << endl;
151 return EXIT_SUCCESS;
152 } else if (arg == "-verbose" || arg == "--verbose") {
153 FbTk::ThemeManager::instance().setVerbose(true);
154 }
155 }
156 return -1;
157}
158