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

Function xprname

src/invent.c:2892–2954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2890}
2891
2892DISABLE_WARNING_FORMAT_NONLITERAL
2893
2894char *
2895xprname(
2896 struct obj *obj,
2897 const char *txt, /* text to print instead of obj */
2898 char let, /* inventory letter */
2899 boolean dot, /* append period; (dot && cost => Iu) */
2900 long cost, /* cost (for inventory of unpaid or expended items) */
2901 long quan) /* if non-0, print this quantity, not obj->quan */
2902{
2903 static char li[BUFSZ];
2904 char suffix[80]; /* plenty of room for count and hallucinatory currency */
2905 int sfxlen, txtlen; /* signed int for %*s formatting */
2906 const char *fmt;
2907 boolean use_invlet = (flags.invlet_constant && obj != NULL
2908 && let != CONTAINED_SYM && let != HANDS_SYM);
2909 long savequan = 0L;
2910
2911 if (quan && obj) {
2912 savequan = obj->quan;
2913 obj->quan = quan;
2914 }
2915 /*
2916 * If let is:
2917 * - Then obj == null and 'txt' refers to hands or fingers.
2918 * * Then obj == null and we are printing a total amount.
2919 * > Then the object is contained and doesn't have an inventory letter.
2920 */
2921 fmt = "%c - %.*s%s";
2922 if (!txt) {
2923 assert(obj != NULL);
2924 txt = doname(obj);
2925 }
2926 txtlen = (int) strlen(txt);
2927
2928 if (cost != 0L || let == '*') {
2929 /* if dot is true, we're doing Iu, otherwise Ix */
2930 if (dot && use_invlet)
2931 let = obj->invlet;
2932 Sprintf(suffix, "%c%6ld %.50s", iflags.menu_tab_sep ? '\t' : ' ',
2933 cost, currency(cost));
2934 if (!iflags.menu_tab_sep) {
2935 fmt = "%c - %-45.*s%s";
2936 if (txtlen < 45)
2937 txtlen = 45;
2938 }
2939 } else {
2940 /* ordinary inventory display or pickup message */
2941 if (use_invlet)
2942 let = obj->invlet;
2943 Strcpy(suffix, dot ? "." : "");
2944 }
2945 sfxlen = (int) strlen(suffix);
2946 if (txtlen > BUFSZ - 1 - (4 + sfxlen)) /* 4: "c - " prefix */
2947 txtlen = BUFSZ - 1 - (4 + sfxlen);
2948 Sprintf(li, fmt, let, txtlen, txt, suffix);
2949

Callers 7

drawWornMethod · 0.85
safeq_xprnameFunction · 0.85
safeq_shortxprnameFunction · 0.85
prinvFunction · 0.85
invent.cFile · 0.85
dounpaidFunction · 0.85
doinvbillFunction · 0.85

Calls 2

donameFunction · 0.85
currencyFunction · 0.85

Tested by

no test coverage detected