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

Function readobjnam

src/objnam.c:4909–5400  ·  view source on GitHub ↗

* Return something wished for. Specifying a null pointer for * the user request string results in a random object. Otherwise, * if asking explicitly for "nothing" (or "nil") return no_wish; * if not an object return &hands_obj; if an error (no matching object), * return null. */

Source from the content-addressed store, hash-verified

4907 * return null.
4908 */
4909struct obj *
4910readobjnam(char *bp, struct obj *no_wish)
4911{
4912 struct _readobjnam_data d;
4913
4914 readobjnam_init(bp, &d);
4915 if (!bp)
4916 goto any;
4917
4918 /* first, remove extra whitespace they may have typed */
4919 (void) mungspaces(bp);
4920 /* allow wishing for "nothing" to preserve wishless conduct...
4921 [now requires "wand of nothing" if that's what was really wanted] */
4922 if (!strcmpi(bp, "nothing") || !strcmpi(bp, "nil")
4923 || !strcmpi(bp, "none"))
4924 return no_wish;
4925 /* save the [nearly] unmodified choice string */
4926 Strcpy(d.fruitbuf, bp);
4927
4928 if (readobjnam_preparse(&d))
4929 goto any;
4930
4931 if (!d.cnt)
4932 d.cnt = 1; /* will be changed to 2 if makesingular() changes string */
4933
4934 readobjnam_parse_charges(&d);
4935
4936 switch (readobjnam_postparse1(&d)) {
4937 default:
4938 case 0: break;
4939 case 1: goto srch;
4940 case 2: goto typfnd;
4941 case 3: return d.otmp;
4942 case 4: goto any;
4943 case 5: goto wiztrap;
4944 }
4945
4946 retry:
4947 switch (readobjnam_postparse2(&d)) {
4948 default:
4949 case 0: break;
4950 case 1: goto srch;
4951 case 2: goto typfnd;
4952 case 3: return d.otmp;
4953 case 4: goto any;
4954 case 5: goto wiztrap;
4955 }
4956
4957 srch:
4958 switch (readobjnam_postparse3(&d)) {
4959 default:
4960 case 0: break;
4961 case 1: goto srch;
4962 case 2: goto typfnd;
4963 case 3: return d.otmp;
4964 case 4: goto any;
4965 case 5: goto wiztrap;
4966 case 6: goto retry;

Callers 3

l_obj_new_readobjnamFunction · 0.85
proc_wizkit_lineFunction · 0.85
makewishFunction · 0.85

Calls 15

readobjnam_initFunction · 0.85
mungspacesFunction · 0.85
readobjnam_preparseFunction · 0.85
readobjnam_parse_chargesFunction · 0.85
readobjnam_postparse1Function · 0.85
readobjnam_postparse2Function · 0.85
readobjnam_postparse3Function · 0.85
wizterrainwishFunction · 0.85
rnd_otyp_by_wpnskillFunction · 0.85
rn2Function · 0.85
rnd_classFunction · 0.85
mksobjFunction · 0.85

Tested by

no test coverage detected