MCPcopy Index your code
hub / github.com/NetHack/NetHack / process_options

Function process_options

sys/unix/unixmain.c:328–486  ·  view source on GitHub ↗

caveat: argv elements might be arbitrarily long */

Source from the content-addressed store, hash-verified

326
327/* caveat: argv elements might be arbitrarily long */
328static void
329process_options(int argc, char *argv[])
330{
331 char *arg, *origarg;
332 int i, l;
333
334 config_error_init(FALSE, "command line", FALSE);
335 /*
336 * Process options.
337 *
338 * We don't support "-xyz" as shortcut for "-x -y -z" and we only
339 * simulate longopts by allowing "--foo" for "-foo" when the user
340 * specifies at least 2 characters of leading substring for "foo".
341 * If "foo" takes a value, both "--foo=value" and "--foo value" work.
342 */
343 while (argc > 1 && argv[1][0] == '-') {
344 argv++;
345 argc--;
346 arg = origarg = argv[0];
347 /* allow second dash if arg is longer than one character */
348 if (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0'
349 /* "--a=b" violates the "--" ok when at least 2 chars long rule */
350 && (arg[3] != '\0' && arg[3] != '=' && arg[3] != ':'))
351 ++arg;
352 l = (int) strlen(arg);
353 if (l < 6 && !strncmp(arg, "-no-", 4))
354 l = 6;
355 else if (l < 4)
356 l = 4; /* must supply at least 4 chars to match "-XXXgraphics" */
357
358 switch (arg[1]) {
359 case 'D':
360 case 'd':
361 if ((arg[1] == 'D' && !arg[2]) || !strcmpi(arg, "-debug")) {
362 wizard = TRUE, discover = FALSE;
363 } else if (!strncmpi(arg, "-DECgraphics", l)) {
364 load_symset("DECGraphics", PRIMARYSET);
365 switch_symbols(TRUE);
366 } else {
367 config_error_add("Unknown option: %.60s", origarg);
368 }
369 break;
370 case 'X':
371 discover = TRUE, wizard = FALSE;
372 break;
373 case 'n':
374#ifdef NEWS
375 if (!arg[2] || !strcmp(arg, "-no-news")) {
376 iflags.news = FALSE;
377 break;
378 } else if (!strcmp(arg, "-news")) {
379 /* in case RC has !news, allow 'nethack -news' to override */
380 iflags.news = TRUE;
381 break;
382 }
383#endif
384 break;
385 case 'u':

Callers 1

mainFunction · 0.70

Calls 8

config_error_initFunction · 0.85
load_symsetFunction · 0.85
switch_symbolsFunction · 0.85
config_error_addFunction · 0.85
str2roleFunction · 0.85
str2raceFunction · 0.85
config_error_doneFunction · 0.85
strncmpiFunction · 0.50

Tested by

no test coverage detected