MCPcopy Create free account
hub / github.com/NetHack/NetHack / early_options

Function early_options

src/earlyarg.c:179–361  ·  view source on GitHub ↗

process some command line arguments before loading options */

Source from the content-addressed store, hash-verified

177
178/* process some command line arguments before loading options */
179void
180early_options(int *argc_p, char ***argv_p, char **hackdir_p)
181{
182 char **argv, *arg, *origarg;
183 int argc, oldargc, ndx = 0, consumed = 0;
184
185#ifdef ENHANCED_SYMBOLS
186 if (argcheck(*argc_p, *argv_p, ARG_DUMPGLYPHIDS) == 2)
187 opt_terminate();
188#endif
189
190 config_error_init(FALSE, "command line", FALSE);
191
192 /* treat "nethack ?" as a request for usage info; due to shell
193 processing, player likely has to use "nethack \?" or "nethack '?'"
194 [won't work if used as "nethack -dpath ?" or "nethack -d path ?"] */
195 if (*argc_p > 1 && !strcmp((*argv_p)[1], "?"))
196 opt_usage(*hackdir_p); /* doesn't return */
197
198 /*
199 * Both *argc_p and *argv_p account for the program name as (*argv_p)[0];
200 * local argc and argv implicitly discard that (by starting 'ndx' at 1).
201 * argcheck() doesn't mind, prscore() (via scores_only()) does (for the
202 * number of args it gets passed, not for the value of argv[0]).
203 */
204 for (ndx = 1; ndx < *argc_p; ndx += (consumed ? 0 : 1)) {
205 consumed = 0;
206 argc = *argc_p - ndx;
207 argv = *argv_p + ndx;
208
209 arg = origarg = argv[0];
210 /* skip any args intended for deferred options */
211 if (*arg != '-')
212 continue;
213 /* allow second dash if arg name is longer than one character */
214 if (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0'
215 && (arg[3] != '\0' && arg[3] != '=' && arg[3] != ':'))
216 ++arg;
217
218 switch (arg[1]) { /* char after leading dash */
219 case 'b':
220#ifdef CRASHREPORT
221 // --bidshow
222 if (argcheck(argc, argv, ARG_BIDSHOW) == 2) {
223 opt_terminate();
224 /*NOTREACHED*/
225 }
226#endif
227 break;
228 case 'd':
229 if (argcheck(argc, argv, ARG_DEBUG) == 1) {
230 consume_arg(ndx, argc_p, argv_p), consumed = 1;
231#ifndef NODUMPENUMS
232 } else if (argcheck(argc, argv, ARG_DUMPENUMS) == 2) {
233 opt_terminate();
234 /*NOTREACHED*/
235#endif
236 } else if (argcheck(argc, argv, ARG_DUMPMONGEN) == 2) {

Callers

nothing calls this directly

Calls 12

argcheckFunction · 0.85
config_error_initFunction · 0.85
opt_usageFunction · 0.85
consume_argFunction · 0.85
loptFunction · 0.85
consume_two_argsFunction · 0.85
dupstrFunction · 0.85
config_error_doneFunction · 0.85
scores_onlyFunction · 0.85
raw_printFunction · 0.85
opt_terminateFunction · 0.70
errorFunction · 0.50

Tested by

no test coverage detected