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

Function append_str

src/pager.c:81–104  ·  view source on GitHub ↗

Append " or "+new_str to the end of buf if new_str doesn't already exist as a substring of buf. Return 1 if the string was appended, 0 otherwise. It is expected that buf is of size BUFSZ. */

Source from the content-addressed store, hash-verified

79 as a substring of buf. Return 1 if the string was appended, 0 otherwise.
80 It is expected that buf is of size BUFSZ. */
81staticfn int
82append_str(char *buf, const char *new_str)
83{
84 static const char sep[] = " or ";
85 size_t oldlen, space_left;
86
87 if (strstri(buf, new_str))
88 return 0; /* already present */
89
90 oldlen = strlen(buf);
91 if (oldlen >= BUFSZ - 1) {
92 if (oldlen > BUFSZ - 1)
93 impossible("append_str: 'buf' contains %lu characters.",
94 (unsigned long) oldlen);
95 return 0; /* no space available */
96 }
97
98 /* some space available, but not necessarily enough for full append */
99 space_left = BUFSZ - 1 - oldlen; /* space remaining in buf */
100 (void) strncat(buf, sep, space_left);
101 if (space_left > sizeof sep - 1)
102 (void) strncat(buf, new_str, space_left - (sizeof sep - 1));
103 return 1; /* something was appended, possibly just part of " or " */
104}
105
106/* shared by monster probing (via query_objlist!) as well as lookat() */
107char *

Callers 2

add_cmap_descrFunction · 0.85
do_screen_descriptionFunction · 0.85

Calls 2

strstriFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected