Driver/Volkslogger: eliminate class VLA_SYS
[xcsoar.git] / src / CommandLine.cpp
blob2790cace40b360cf79005772e969ccd2ed463be7
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "CommandLine.hpp"
25 #include "Profile/Profile.hpp"
26 #include "OS/Args.hpp"
27 #include "OS/ConvertPathName.hpp"
28 #include "Hardware/Display.hpp"
29 #include "Simulator.hpp"
30 #include "LocalPath.hpp"
32 #ifdef WIN32
33 #include <windows.h> /* for AllocConsole() */
34 #endif
36 namespace CommandLine {
37 #if !defined(_WIN32_WCE)
38 unsigned width = 640, height = 480;
39 #endif
41 #ifdef HAVE_CMDLINE_FULLSCREEN
42 bool full_screen = false;
43 #endif
45 #ifdef HAVE_CMDLINE_RESIZABLE
46 bool resizable = false;
47 #endif
50 void
51 CommandLine::Parse(Args &args)
53 while (!args.IsEmpty()) {
54 const char *s = args.GetNext();
56 if (*s != '-') {
57 #ifdef _WIN32
58 continue;
59 #else
60 args.UsageError();
61 #endif
64 // Also accept "--" prefix for arguments. Usually used on UNIX for long options
65 if (s[1] == '-')
66 s++;
68 if (strncmp(s, "-profile=", 9) == 0) {
69 s += 9;
70 PathName convert(s);
71 Profile::SetFiles(convert);
72 } else if (strncmp(s, "-datapath=", 10) == 0) {
73 s += 10;
74 PathName convert(s);
75 SetPrimaryDataPath(convert);
77 #ifdef SIMULATOR_AVAILABLE
78 else if (strcmp(s, "-simulator") == 0) {
79 global_simulator_flag = true;
80 sim_set_in_cmd_line_flag = true;
82 else if (strcmp(s, "-fly") == 0) {
83 global_simulator_flag=false;
84 sim_set_in_cmd_line_flag=true;
86 #endif
87 #if !defined(_WIN32_WCE)
88 else if (isdigit(s[1])) {
89 char *p;
90 width = strtol(s+1, &p, 10);
91 if (*p != 'x' && *p != 'X')
92 args.UsageError();
93 s = p;
94 height = strtol(s+1, &p, 10);
96 else if (strcmp(s, "-portrait") == 0) {
97 width = 480;
98 height = 640;
100 else if (strcmp(s, "-square") == 0) {
101 width = 480;
102 height = 480;
104 else if (strcmp(s, "-small") == 0) {
105 width = 320;
106 height = 240;
108 #endif
109 #ifdef HAVE_CMDLINE_FULLSCREEN
110 else if (strcmp(s, "-fullscreen") == 0) {
111 full_screen = true;
113 #endif
114 #ifdef HAVE_CMDLINE_RESIZABLE
115 else if (strcmp(s, "-resizable") == 0) {
116 resizable = true;
118 #endif
119 #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__WINE__)
120 else if (strcmp(s, "-console") == 0) {
121 AllocConsole();
122 freopen("CONOUT$", "wb", stdout);
124 #endif
125 #if !defined(ANDROID) && !defined(_WIN32_WCE)
126 else if (strncmp(s, "-dpi=", 5) == 0) {
127 unsigned x_dpi, y_dpi;
128 char *p;
129 x_dpi = strtol(s+5, &p, 10);
130 if (*p == 'x' || *p == 'X') {
131 s = p;
132 y_dpi = strtol(s+1, &p, 10);
133 } else
134 y_dpi = x_dpi;
136 if (x_dpi < 32 || x_dpi > 512 || y_dpi < 32 || y_dpi > 512)
137 args.UsageError();
139 Display::SetDPI(x_dpi, y_dpi);
141 #endif
142 #ifndef _WIN32
143 else
144 args.UsageError();
145 #endif
148 #if !defined(_WIN32_WCE)
149 if (width < 240 || width > 4096 ||
150 height < 240 || height > 4096)
151 args.UsageError();
152 #endif