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

Function wipeout_text

src/engrave.c:119–183  ·  view source on GitHub ↗

degrade some of the characters in a string */

Source from the content-addressed store, hash-verified

117
118/* degrade some of the characters in a string */
119void
120wipeout_text(
121 char *engr, /* engraving text */
122 int cnt, /* number of chars to degrade */
123 unsigned seed) /* for semi-controlled randomization */
124{
125 char *s;
126 int i, j, nxt, use_rubout;
127 unsigned lth = (unsigned) strlen(engr);
128
129 if (lth && cnt > 0) {
130 while (cnt--) {
131 /* pick next character */
132 if (!seed) {
133 /* random */
134 nxt = rn2((int) lth);
135 use_rubout = rn2(4);
136 } else {
137 /* predictable; caller can reproduce the same sequence by
138 supplying the same arguments later, or a pseudo-random
139 sequence by varying any of them */
140 nxt = seed % lth;
141 seed *= 31, seed %= (BUFSZ - 1);
142 use_rubout = seed & 3;
143 }
144 s = &engr[nxt];
145 if (*s == ' ')
146 continue;
147
148 /* rub out unreadable & small punctuation marks */
149 if (strchr("?.,'`-|_", *s)) {
150 *s = ' ';
151 continue;
152 }
153
154 if (!use_rubout) {
155 i = SIZE(rubouts);
156 } else {
157 for (i = 0; i < SIZE(rubouts); i++)
158 if (*s == rubouts[i].wipefrom) {
159 unsigned ln = (unsigned) strlen(rubouts[i].wipeto);
160 /*
161 * Pick one of the substitutes at random.
162 */
163 if (!seed) {
164 j = rn2((int) ln);
165 } else {
166 seed *= 31, seed %= (BUFSZ - 1);
167 j = seed % ln;
168 }
169 *s = rubouts[i].wipeto[j];
170 break;
171 }
172 }
173
174 /* didn't pick rubout; use '?' for unreadable character */
175 if (i == SIZE(rubouts))
176 *s = '?';

Callers 5

do_onameFunction · 0.85
random_engravingFunction · 0.85
wipe_engr_atFunction · 0.85
dowriteFunction · 0.85
erode_obj_textFunction · 0.85

Calls 1

rn2Function · 0.85

Tested by

no test coverage detected