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

Function read_rumors_file

util/makedefs.c:1035–1078  ·  view source on GitHub ↗

common code for do_rumors(). Return 0 on error. */

Source from the content-addressed store, hash-verified

1033
1034/* common code for do_rumors(). Return 0 on error. */
1035static unsigned long
1036read_rumors_file(
1037 const char *file_ext,
1038 int *rumor_count,
1039 long *rumor_size,
1040 unsigned long old_rumor_offset,
1041 unsigned padlength)
1042{
1043 char infile[MAXFNAMELEN], xbuf[BUFSZ];
1044 char *line;
1045 unsigned long rumor_offset;
1046
1047 Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
1048 Strcat(infile, file_ext);
1049 if (!(ifp = fopen(infile, RDTMODE))) {
1050 perror(infile);
1051 return 0L;
1052 }
1053 set_fgetline_context(infile, TRUE, FALSE);
1054
1055 /* copy the rumors */
1056 while ((line = fgetline(ifp)) != 0) {
1057 (void) padline(line, padlength); /* make shortest lines be longer */
1058
1059 (*rumor_count)++;
1060#if 0
1061 /*[if we forced binary output, this would be sufficient]*/
1062 *rumor_size += strlen(line); /* includes newline */
1063#endif
1064 (void) fputs(xcrypt(line, xbuf), tfp);
1065 free((genericptr_t) line);
1066 }
1067 /* record the current position; next rumors section will start here */
1068 rumor_offset = (unsigned long) ftell(tfp);
1069 Fclose(ifp); /* all done with rumors.file_ext */
1070
1071 /* the calculated value for *_rumor_count assumes that
1072 a single-byte line terminator is in use; for platforms
1073 which use two byte CR+LF, we need to override that value
1074 [it's much simpler to do so unconditionally, rendering
1075 the loop's accumulation above obsolete] */
1076 *rumor_size = (long) (rumor_offset - old_rumor_offset);
1077 return rumor_offset;
1078}
1079
1080static void
1081do_rnd_access_file(

Callers 1

do_rumorsFunction · 0.85

Calls 5

set_fgetline_contextFunction · 0.85
padlineFunction · 0.85
xcryptFunction · 0.85
ftellFunction · 0.85
fgetlineFunction · 0.70

Tested by

no test coverage detected