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

Function change_inv_order

src/options.c:7465–7510  ·  view source on GitHub ↗

* Change the inventory order, using the given string as the new order. * Missing characters in the new order are filled in at the end from * the current inv_order, except for gold, which is forced to be first * if not explicitly present. * * This routine returns 1 unless there is a duplicate or bad char in * the string. * * Used by: optfn_packorder() * */

Source from the content-addressed store, hash-verified

7463 *
7464 */
7465staticfn int
7466change_inv_order(char *op)
7467{
7468 int oc_sym, num;
7469 char *sp, buf[QBUFSZ];
7470 int retval = 1;
7471
7472 num = 0;
7473 if (!strchr(op, GOLD_SYM))
7474 buf[num++] = COIN_CLASS;
7475
7476 for (sp = op; *sp; sp++) {
7477 boolean fail = FALSE;
7478 oc_sym = def_char_to_objclass(*sp);
7479 /* reject bad or duplicate entries */
7480 if (oc_sym == MAXOCLASSES) { /* not an object class char */
7481 config_error_add("Not an object class '%c'", *sp);
7482 retval = 0;
7483 fail = TRUE;
7484 } else if (!strchr(flags.inv_order, oc_sym)) {
7485 /* VENOM_CLASS, RANDOM_CLASS, and ILLOBJ_CLASS are excluded
7486 because they aren't in def_inv_order[] so don't make it
7487 into flags.inv_order, hence always fail this strchr() test */
7488 config_error_add("Object class '%c' not allowed", *sp);
7489 retval = 0;
7490 fail = TRUE;
7491 } else if (strchr(sp + 1, *sp)) {
7492 config_error_add("Duplicate object class '%c'", *sp);
7493 retval = 0;
7494 fail = TRUE;
7495 }
7496 /* retain good ones */
7497 if (!fail)
7498 buf[num++] = (char) oc_sym;
7499 }
7500 buf[num] = '\0';
7501
7502 /* fill in any omitted classes, using previous ordering */
7503 for (sp = flags.inv_order; *sp; sp++)
7504 if (!strchr(buf, *sp))
7505 (void) strkitten(&buf[num++], *sp);
7506 buf[MAXOCLASSES - 1] = '\0';
7507
7508 Strcpy(flags.inv_order, buf);
7509 return retval;
7510}
7511
7512
7513/*

Callers 1

optfn_packorderFunction · 0.85

Calls 3

def_char_to_objclassFunction · 0.85
config_error_addFunction · 0.85
strkittenFunction · 0.85

Tested by

no test coverage detected