paniclog prefix (trunk only)

Extend the identifying information used to prefix paniclog entries
from version + date to version + date + time + userid + mode (where mode
is 'D' for wizard mode, 'X' for discover mode, and '-' for normal play).

     hacklib.c ended up getting more of a revision than I intended, but
the date/time handling routines now have less clutter.  I hope I didn't
break anything in the process.
This commit is contained in:
nethack.rankin
2006-10-10 05:47:04 +00:00
parent ab947c6b65
commit 35920f24d5
4 changed files with 65 additions and 36 deletions

View File

@@ -246,6 +246,7 @@ locking converts a hole into a trap door; striking does the opposite
add Malcolm Ryan's Statue Glyphs patch
lembas and cram never rot unless cursed
multiple squeaks for squeaky boards
include time, user ID, and play mode in paniclog entries
Platform- and/or Interface-Specific New Features

View File

@@ -818,11 +818,13 @@ E char *FDECL(strstri, (const char *,const char *));
#endif
E boolean FDECL(fuzzymatch, (const char *,const char *,const char *,BOOLEAN_P));
E void NDECL(setrandom);
E time_t NDECL(getnow);
E int NDECL(getyear);
#if 0
E char *FDECL(yymmdd, (time_t));
#endif
E long FDECL(yyyymmdd, (time_t));
E long FDECL(hhmmss, (time_t));
E int NDECL(phase_of_the_moon);
E boolean NDECL(friday_13th);
E int NDECL(night);

View File

@@ -927,10 +927,9 @@ create_savefile()
the default for non-privileged users, but for priv'd users the
file will be owned by the directory's owner instead of the user.
*/
# ifdef getuid /*(see vmsunix.c)*/
# undef getuid
# endif
# undef getuid
(void) chown(fq_save, getuid(), getgid());
# define getuid() vms_getuid()
# endif /* VMS && !SECURE */
#endif /* MICRO */
@@ -2776,8 +2775,14 @@ const char *reason; /* explanation */
program_state.in_paniclog = 1;
lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) {
(void) fprintf(lfile, "%s %08ld: %s %s\n",
version_string(buf), yyyymmdd((time_t)0L),
time_t now = getnow();
int uid = getuid();
char playmode = wizard ? 'D' : discover ? 'X' : '-';
(void) fprintf(lfile, "%s %08ld %06ld %d %c: %s %s\n",
version_string(buf),
yyyymmdd(now), hhmmss(now),
uid, playmode,
type, reason);
(void) fclose(lfile);
}

View File

@@ -37,9 +37,11 @@ NetHack, except that rounddiv may call panic().
char * strstri (const char *, const char *)
boolean fuzzymatch (const char *,const char *,const char *,boolean)
void setrandom (void)
time_t getnow (void)
int getyear (void)
char * yymmdd (time_t)
long yyyymmdd (time_t)
long hhmmss (time_t)
int phase_of_the_moon (void)
boolean friday_13th (void)
int night (void)
@@ -444,6 +446,19 @@ fuzzymatch(s1, s2, ignore_chars, caseblind)
* - determination of what files are "very old"
*/
/* TIME_type: type of the argument to time(); we actually use &(time_t) */
#if defined(BSD) && !defined(POSIX_TYPES)
# define TIME_type long *
#else
# define TIME_type time_t *
#endif
/* LOCALTIME_type: type of the argument to localtime() */
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || (defined(BSD) && !defined(POSIX_TYPES))
# define LOCALTIME_type long *
#else
# define LOCALTIME_type time_t *
#endif
#if defined(AMIGA) && !defined(AZTEC_C) && !defined(__SASC_60) && !defined(_DCC) && !defined(__GNUC__)
extern struct tm *FDECL(localtime,(time_t *));
#endif
@@ -452,46 +467,44 @@ STATIC_DCL struct tm *NDECL(getlt);
void
setrandom()
{
time_t now = getnow(); /* time((TYPE_type) 0) */
/* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing
*/
#ifdef RANDOM /* srandom() from sys/share/random.c */
srandom((unsigned int) time((time_t *)0));
srandom((unsigned int) now);
#else
# if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */
# if defined(BSD) && !defined(POSIX_TYPES)
# if defined(SUNOS4)
# if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
(void)
# endif
srandom((int) time((long *)0));
# else
srandom((int) time((time_t *)0));
# endif
srandom((int) now);
# else
# ifdef UNIX /* system srand48() */
srand48((long) time((time_t *)0));
srand48((long) now);
# else /* poor quality system routine */
srand((int) time((time_t *)0));
srand((int) now);
# endif
# endif
#endif
}
time_t
getnow()
{
time_t datetime = 0;
(void) time((TIME_type) &datetime);
return datetime;
}
STATIC_OVL struct tm *
getlt()
{
time_t date;
time_t date = getnow();
#if defined(BSD) && !defined(POSIX_TYPES)
(void) time((long *)(&date));
#else
(void) time(&date);
#endif
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || (defined(BSD) && !defined(POSIX_TYPES))
return(localtime((long *)(&date)));
#else
return(localtime(&date));
#endif
return localtime((LOCALTIME_type) &date);
}
int
@@ -501,7 +514,7 @@ getyear()
}
#if 0
/* This routine is no longer used since in 2000 it will yield "100mmdd". */
/* This routine is no longer used since in 20YY it yields "1YYmmdd". */
char *
yymmdd(date)
time_t date;
@@ -512,11 +525,7 @@ time_t date;
if (date == 0)
lt = getlt();
else
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || defined(BSD)
lt = localtime((long *)(&date));
#else
lt = localtime(&date);
#endif
lt = localtime((LOCALTIME_type) &date);
Sprintf(datestr, "%02d%02d%02d",
lt->tm_year, lt->tm_mon + 1, lt->tm_mday);
@@ -534,11 +543,7 @@ time_t date;
if (date == 0)
lt = getlt();
else
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || (defined(BSD) && !defined(POSIX_TYPES))
lt = localtime((long *)(&date));
#else
lt = localtime(&date);
#endif
lt = localtime((LOCALTIME_type) &date);
/* just in case somebody's localtime supplies (year % 100)
rather than the expected (year - 1900) */
@@ -553,6 +558,22 @@ time_t date;
return datenum;
}
long
hhmmss(date)
time_t date;
{
long timenum;
struct tm *lt;
if (date == 0)
lt = getlt();
else
lt = localtime((LOCALTIME_type) &date);
timenum = lt->tm_hour * 10000L + lt->tm_min * 100L + lt->tm_sec;
return timenum;
}
/*
* moon period = 29.53058 days ~= 30, year = 365.2422 days
* days moon phase advances on first day of year compared to preceding year