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

Function livelog_add

src/files.c:3666–3706  ·  view source on GitHub ↗

Locks the live log file and writes 'buffer' * iff the ll_type matches sysopt.livelog mask. * lltype is included in LL entry for post-process filtering also. */

Source from the content-addressed store, hash-verified

3664 * lltype is included in LL entry for post-process filtering also.
3665 */
3666void
3667livelog_add(long ll_type, const char *str)
3668{
3669 FILE *livelogfile;
3670 time_t now;
3671 int gindx, aindx;
3672
3673 if (!(ll_type & sysopt.livelog))
3674 return;
3675
3676 if (lock_file(LIVELOGFILE, SCOREPREFIX, 10)) {
3677 if (!(livelogfile = fopen_datafile(LIVELOGFILE, "a", SCOREPREFIX))) {
3678 pline("Cannot open live log file!");
3679 unlock_file(LIVELOGFILE);
3680 return;
3681 }
3682
3683 now = getnow();
3684 gindx = flags.female ? 1 : 0;
3685 /* note on alignment designation:
3686 aligns[] uses [0] lawful, [1] neutral, [2] chaotic;
3687 u.ualign.type uses -1 chaotic, 0 neutral, 1 lawful;
3688 so subtracting from 1 converts from either to the other */
3689 aindx = 1 - u.ualign.type;
3690 /* format relies on STD C's implicit concatenation of
3691 adjacent string literals */
3692 (void) fprintf(livelogfile,
3693 "lltype=%ld" LLOG_SEP "name=%s" LLOG_SEP
3694 "role=%s" LLOG_SEP "race=%s" LLOG_SEP
3695 "gender=%s" LLOG_SEP "align=%s" LLOG_SEP
3696 "turns=%ld" LLOG_SEP "starttime=%ld" LLOG_SEP
3697 "curtime=%ld" LLOG_SEP "message=%s" LLOG_EOL,
3698 (ll_type & sysopt.livelog), svp.plname,
3699 gu.urole.filecode, gu.urace.filecode,
3700 genders[gindx].filecode, aligns[aindx].filecode,
3701 svm.moves, timet_to_seconds(ubirthday),
3702 timet_to_seconds(now), str);
3703 (void) fclose(livelogfile);
3704 unlock_file(LIVELOGFILE);
3705 }
3706}
3707#undef LLOG_SEP
3708#undef LLOG_EOL
3709

Callers 1

livelog_printfFunction · 0.85

Calls 7

unlock_fileFunction · 0.85
getnowFunction · 0.85
fprintfFunction · 0.85
timet_to_secondsFunction · 0.85
fcloseFunction · 0.85
fopen_datafileFunction · 0.70
plineFunction · 0.70

Tested by

no test coverage detected