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
+1
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 add Malcolm Ryan's Statue Glyphs patch
lembas and cram never rot unless cursed lembas and cram never rot unless cursed
multiple squeaks for squeaky boards multiple squeaks for squeaky boards
include time, user ID, and play mode in paniclog entries
Platform- and/or Interface-Specific New Features Platform- and/or Interface-Specific New Features
+2
View File
@@ -818,11 +818,13 @@ E char *FDECL(strstri, (const char *,const char *));
#endif #endif
E boolean FDECL(fuzzymatch, (const char *,const char *,const char *,BOOLEAN_P)); E boolean FDECL(fuzzymatch, (const char *,const char *,const char *,BOOLEAN_P));
E void NDECL(setrandom); E void NDECL(setrandom);
E time_t NDECL(getnow);
E int NDECL(getyear); E int NDECL(getyear);
#if 0 #if 0
E char *FDECL(yymmdd, (time_t)); E char *FDECL(yymmdd, (time_t));
#endif #endif
E long FDECL(yyyymmdd, (time_t)); E long FDECL(yyyymmdd, (time_t));
E long FDECL(hhmmss, (time_t));
E int NDECL(phase_of_the_moon); E int NDECL(phase_of_the_moon);
E boolean NDECL(friday_13th); E boolean NDECL(friday_13th);
E int NDECL(night); E int NDECL(night);
+10 -5
View File
@@ -927,10 +927,9 @@ create_savefile()
the default for non-privileged users, but for priv'd users the 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. file will be owned by the directory's owner instead of the user.
*/ */
# ifdef getuid /*(see vmsunix.c)*/ # undef getuid
# undef getuid
# endif
(void) chown(fq_save, getuid(), getgid()); (void) chown(fq_save, getuid(), getgid());
# define getuid() vms_getuid()
# endif /* VMS && !SECURE */ # endif /* VMS && !SECURE */
#endif /* MICRO */ #endif /* MICRO */
@@ -2776,8 +2775,14 @@ const char *reason; /* explanation */
program_state.in_paniclog = 1; program_state.in_paniclog = 1;
lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX); lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) { if (lfile) {
(void) fprintf(lfile, "%s %08ld: %s %s\n", time_t now = getnow();
version_string(buf), yyyymmdd((time_t)0L), 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); type, reason);
(void) fclose(lfile); (void) fclose(lfile);
} }
+52 -31
View File
@@ -37,9 +37,11 @@ NetHack, except that rounddiv may call panic().
char * strstri (const char *, const char *) char * strstri (const char *, const char *)
boolean fuzzymatch (const char *,const char *,const char *,boolean) boolean fuzzymatch (const char *,const char *,const char *,boolean)
void setrandom (void) void setrandom (void)
time_t getnow (void)
int getyear (void) int getyear (void)
char * yymmdd (time_t) char * yymmdd (time_t)
long yyyymmdd (time_t) long yyyymmdd (time_t)
long hhmmss (time_t)
int phase_of_the_moon (void) int phase_of_the_moon (void)
boolean friday_13th (void) boolean friday_13th (void)
int night (void) int night (void)
@@ -444,6 +446,19 @@ fuzzymatch(s1, s2, ignore_chars, caseblind)
* - determination of what files are "very old" * - 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__) #if defined(AMIGA) && !defined(AZTEC_C) && !defined(__SASC_60) && !defined(_DCC) && !defined(__GNUC__)
extern struct tm *FDECL(localtime,(time_t *)); extern struct tm *FDECL(localtime,(time_t *));
#endif #endif
@@ -452,46 +467,44 @@ STATIC_DCL struct tm *NDECL(getlt);
void void
setrandom() setrandom()
{ {
time_t now = getnow(); /* time((TYPE_type) 0) */
/* the types are different enough here that sweeping the different /* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing * routine names into one via #defines is even more confusing
*/ */
#ifdef RANDOM /* srandom() from sys/share/random.c */ #ifdef RANDOM /* srandom() from sys/share/random.c */
srandom((unsigned int) time((time_t *)0)); srandom((unsigned int) now);
#else #else
# if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */ # if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) /* system srandom() */
# if defined(BSD) && !defined(POSIX_TYPES) # if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
# if defined(SUNOS4)
(void) (void)
# endif
srandom((int) time((long *)0));
# else
srandom((int) time((time_t *)0));
# endif # endif
srandom((int) now);
# else # else
# ifdef UNIX /* system srand48() */ # ifdef UNIX /* system srand48() */
srand48((long) time((time_t *)0)); srand48((long) now);
# else /* poor quality system routine */ # else /* poor quality system routine */
srand((int) time((time_t *)0)); srand((int) now);
# endif # endif
# endif # endif
#endif #endif
} }
time_t
getnow()
{
time_t datetime = 0;
(void) time((TIME_type) &datetime);
return datetime;
}
STATIC_OVL struct tm * STATIC_OVL struct tm *
getlt() getlt()
{ {
time_t date; time_t date = getnow();
#if defined(BSD) && !defined(POSIX_TYPES) return localtime((LOCALTIME_type) &date);
(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
} }
int int
@@ -501,7 +514,7 @@ getyear()
} }
#if 0 #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 * char *
yymmdd(date) yymmdd(date)
time_t date; time_t date;
@@ -512,11 +525,7 @@ time_t date;
if (date == 0) if (date == 0)
lt = getlt(); lt = getlt();
else else
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || defined(BSD) lt = localtime((LOCALTIME_type) &date);
lt = localtime((long *)(&date));
#else
lt = localtime(&date);
#endif
Sprintf(datestr, "%02d%02d%02d", Sprintf(datestr, "%02d%02d%02d",
lt->tm_year, lt->tm_mon + 1, lt->tm_mday); lt->tm_year, lt->tm_mon + 1, lt->tm_mday);
@@ -534,11 +543,7 @@ time_t date;
if (date == 0) if (date == 0)
lt = getlt(); lt = getlt();
else else
#if (defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))) || (defined(BSD) && !defined(POSIX_TYPES)) lt = localtime((LOCALTIME_type) &date);
lt = localtime((long *)(&date));
#else
lt = localtime(&date);
#endif
/* just in case somebody's localtime supplies (year % 100) /* just in case somebody's localtime supplies (year % 100)
rather than the expected (year - 1900) */ rather than the expected (year - 1900) */
@@ -553,6 +558,22 @@ time_t date;
return datenum; 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 * moon period = 29.53058 days ~= 30, year = 365.2422 days
* days moon phase advances on first day of year compared to preceding year * days moon phase advances on first day of year compared to preceding year