| 997 | } |
| 998 | |
| 999 | static char * |
| 1000 | padline(char *line, unsigned padlength) |
| 1001 | { |
| 1002 | /* |
| 1003 | * Rumor selection is accomplished by seeking to a random |
| 1004 | * position in the file, advancing to newline, and taking |
| 1005 | * the next line. Therefore, rumors which follow long-line |
| 1006 | * rumors are most likely to be chosen and rumors which |
| 1007 | * follow short-line rumors are least likely to be chosen. |
| 1008 | * We ameliorate the latter by padding the shortest lines, |
| 1009 | * increasing the chance of the random seek landing in them. |
| 1010 | * The core's get_rnd_text() handles long lines in a way |
| 1011 | * that results in even selection distribution. |
| 1012 | * |
| 1013 | * Random epitaphs, engravings, and hallucinatory monster |
| 1014 | * names are in the same boat. |
| 1015 | */ |
| 1016 | char *endp; |
| 1017 | unsigned len = (unsigned) strlen(line); /* includes newline */ |
| 1018 | |
| 1019 | if (len <= padlength) { |
| 1020 | endp = strchr(line, '\n'); /* fgetline() guarantees a newline even if |
| 1021 | * the input file's last line lacks one */ |
| 1022 | |
| 1023 | /* this is safe provided that padlength+1 is less than the allocation |
| 1024 | amount used in fgetline(); currently 144 (BUFSZ/2+16) */ |
| 1025 | while (len++ < padlength) { |
| 1026 | *endp++ = '_'; |
| 1027 | } |
| 1028 | *endp++ = '\n'; |
| 1029 | *endp = '\0'; |
| 1030 | } |
| 1031 | return line; |
| 1032 | } |
| 1033 | |
| 1034 | /* common code for do_rumors(). Return 0 on error. */ |
| 1035 | static unsigned long |
no outgoing calls
no test coverage detected