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

Function optfn_versinfo

src/options.c:4471–4534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4469}
4470
4471staticfn int
4472optfn_versinfo(
4473 int optidx, int req, boolean negated,
4474 char *opts, char *op)
4475{
4476 const char *optname = allopt[optidx].name;
4477 unsigned vi = flags.versinfo;
4478
4479 if (req == do_init) {
4480 return optn_ok;
4481 }
4482 if (req == do_set) {
4483 /* versinfo: what to include when 'showvers' displays version
4484 on status lines; bitmask with up to three bits:
4485 (1) x.y.z number, (2) program name, (4) git branch if available.
4486 If branch is requested but unavailable, status_version will
4487 treat 4 as 1.
4488 */
4489 boolean have_branch = (nomakedefs.git_branch
4490 && *nomakedefs.git_branch);
4491 int val, dflt = have_branch ? VI_BRANCH : VI_NUMBER;
4492
4493 if (negated) {
4494 bad_negation(allopt[optidx].name, TRUE);
4495 return optn_silenterr;
4496 }
4497 op = string_for_opt(opts, FALSE);
4498 if (op == empty_optstr) {
4499 config_error_add("'%s' requires a value; defaulting to %d",
4500 optname, dflt);
4501 return optn_silenterr;
4502 }
4503 val = atoi(op);
4504 if (!val || (val & ~7) != 0) {
4505 config_error_add("'%s' must be one of 1, 2, 4, or"
4506 " the sum of two or all three of those",
4507 optname);
4508 return optn_silenterr;
4509 }
4510 flags.versinfo = (unsigned) val;
4511 } else if (req == do_handler) {
4512 /* return handler_versinfo(); */
4513 (void) handler_versinfo();
4514 pline("'%s' %s %u.", optname,
4515 (flags.versinfo == vi) ? "not changed, still" : "changed to",
4516 flags.versinfo);
4517 } else if (req == get_val) {
4518 char vbuf[QBUFSZ];
4519 boolean g = (vi & VI_NAME) != 0,
4520 b = (vi & VI_BRANCH) != 0,
4521 n = (vi & VI_NUMBER) != 0;
4522
4523 Sprintf(opts, "%u: %s%s%s%s%s (%.99s)", flags.versinfo,
4524 g ? "name" : "", (b && g) ? "+" : "", b ? "branch" : "",
4525 (n && (b || g)) ? "+" : "", n ? "number" : "",
4526 status_version(vbuf, sizeof vbuf, FALSE));
4527 } else if (req == get_cnf_val) {
4528 Sprintf(opts, "%u", flags.versinfo);

Callers

nothing calls this directly

Calls 6

bad_negationFunction · 0.85
string_for_optFunction · 0.85
config_error_addFunction · 0.85
handler_versinfoFunction · 0.85
status_versionFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected