ManaPlus
Functions
commandline.h File Reference

(986a3bf)

#include "localconsts.h"

Go to the source code of this file.

Functions

void parseOptions (const int argc, char *const argv[])
 

Function Documentation

◆ parseOptions()

void parseOptions ( const int  argc,
char *const  argv[] 
)

Definition at line 137 of file commandline.cpp.

138 {
139  const char *const optstring = "hvud:U:P:Dc:p:y:l:L:C:s:t:T:a:r:e:V";
140 
141  const option long_options[] =
142  {
143  { "config-dir", required_argument, nullptr, 'C' },
144  { "data", required_argument, nullptr, 'd' },
145  { "default", no_argument, nullptr, 'D' },
146  { "password", required_argument, nullptr, 'P' },
147  { "character", required_argument, nullptr, 'c' },
148  { "help", no_argument, nullptr, 'h' },
149  { "localdata-dir", required_argument, nullptr, 'L' },
150  { "update-host", required_argument, nullptr, 'H' },
151  { "port", required_argument, nullptr, 'p' },
152  { "server", required_argument, nullptr, 's' },
153  { "skip-update", no_argument, nullptr, 'u' },
154  { "username", required_argument, nullptr, 'U' },
155  { "no-opengl", no_argument, nullptr, 'O' },
156  { "chat-log-dir", required_argument, nullptr, 'a' },
157  { "version", no_argument, nullptr, 'v' },
158  { "log-file", required_argument, nullptr, 'l' },
159  { "screenshot-dir", required_argument, nullptr, 'i' },
160  { "safemode", no_argument, nullptr, 'm' },
161  { "tests", no_argument, nullptr, 'T' },
162  { "test", required_argument, nullptr, 't' },
163  { "renderer", required_argument, nullptr, 'r' },
164  { "server-type", required_argument, nullptr, 'y' },
165  { "enable-ipc", no_argument, nullptr, 'I' },
166  { "hide-cursor", no_argument, nullptr, 'q' },
167  { "error", no_argument, nullptr, 'e' },
168  { "validate", no_argument, nullptr, 'V' },
169  { nullptr, 0, nullptr, 0 }
170  };
171 
172  Options &options = settings.options;
173 
174  while (optind < argc)
175  {
176  const int result = getopt_long(argc,
177  argv,
178  optstring,
179  long_options,
180  nullptr);
181 
182  if (result == -1)
183  break;
184 
185  switch (result)
186  {
187  case 'C':
188  options.configDir = optarg;
189  break;
190  case 'd':
191  options.dataPath = optarg;
192  break;
193  case 'D':
194  options.chooseDefault = true;
195  break;
196  case '?': // Unknown option
197  case ':': // Missing argument
198  case 'h':
199  options.printHelp = true;
200  break;
201  case 'H':
202  if (checkPath(optarg))
203  options.updateHost = optarg;
204  else
205  options.updateHost.clear();
206  break;
207  case 'c':
208  options.character = optarg;
209  break;
210  case 'P':
211  options.password = optarg;
212  break;
213  case 's':
214  options.serverName = optarg;
215  break;
216  case 'p':
217  options.serverPort = CAST_U16(atoi(optarg));
218  break;
219  case 'u':
220  options.skipUpdate = true;
221  break;
222  case 'U':
223  options.username = optarg;
224  break;
225  case 'v':
226  options.printVersion = true;
227  break;
228  case 'L':
229  options.localDataDir = optarg;
230  break;
231  case 'O':
232  options.noOpenGL = true;
233  break;
234  case 'l':
235  options.logFileName = std::string(optarg);
236  break;
237  case 'a':
238  options.chatLogDir = std::string(optarg);
239  break;
240  case 'i':
241  options.screenshotDir = optarg;
242  break;
243  case 'm':
244  options.safeMode = true;
245  break;
246  case 'T':
247  options.testMode = true;
248  options.test.clear();
249  break;
250  case 't':
251  options.testMode = true;
252  options.test = std::string(optarg);
253  break;
254  case 'r':
255  options.renderer = CAST_S32(atoi(optarg));
256  break;
257  case 'y':
258  options.serverType = optarg;
259  break;
260  case 'I':
261  options.ipc = true;
262  break;
263  case 'q':
264  options.hideCursor = true;
265  break;
266  case 'e':
267  options.error = true;
268  break;
269  case 'V':
270  options.validate = true;
271  break;
272  default:
273  break;
274  }
275  }
276 
277  // when there are still options left use the last
278  // one as branding file
279  if (optind < argc)
280  {
281  options.brandingPath = argv[optind];
282  }
283 
285  {
286  printHelp();
287  _exit(0);
288  }
289  else if (settings.options.printVersion)
290  {
291  printVersion();
292  _exit(0);
293  }
294 }
#define CAST_U16
Definition: cast.h:29
#define CAST_S32
Definition: cast.h:30
Options options
Definition: settings.h:130
static void printHelp()
Definition: commandline.cpp:41
static void printVersion()
bool checkPath(const std::string &path)
Definition: paths.cpp:121
Settings settings
Definition: settings.cpp:32
bool validate
Definition: options.h:103
bool printHelp
Definition: options.h:93
bool noOpenGL
Definition: options.h:97
std::string brandingPath
Definition: options.h:79
bool safeMode
Definition: options.h:98
std::string chatLogDir
Definition: options.h:84
std::string test
Definition: options.h:88
std::string screenshotDir
Definition: options.h:87
bool skipUpdate
Definition: options.h:95
bool chooseDefault
Definition: options.h:96
bool hideCursor
Definition: options.h:101
std::string updateHost
Definition: options.h:80
bool ipc
Definition: options.h:100
std::string configDir
Definition: options.h:85
uint16_t serverPort
Definition: options.h:92
std::string localDataDir
Definition: options.h:86
std::string character
Definition: options.h:78
bool error
Definition: options.h:102
std::string dataPath
Definition: options.h:81
bool printVersion
Definition: options.h:94
std::string logFileName
Definition: options.h:83
std::string password
Definition: options.h:77
int renderer
Definition: options.h:91
std::string serverType
Definition: options.h:90
bool testMode
Definition: options.h:99
std::string serverName
Definition: options.h:89
std::string username
Definition: options.h:76

References Options::brandingPath, CAST_S32, CAST_U16, Options::character, Options::chatLogDir, checkPath(), Options::chooseDefault, Options::configDir, Options::dataPath, Options::error, Options::hideCursor, Options::ipc, Options::localDataDir, Options::logFileName, Options::noOpenGL, Settings::options, Options::password, printHelp(), Options::printHelp, printVersion(), Options::printVersion, Options::renderer, Options::safeMode, Options::screenshotDir, Options::serverName, Options::serverPort, Options::serverType, settings, Options::skipUpdate, Options::test, Options::testMode, Options::updateHost, Options::username, and Options::validate.

Referenced by mainGui().