summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-15 08:01:50 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-15 08:01:50 +0000
commit1328bd509fa25da1301d4ff6f4b6e9f2a630730e (patch)
tree74d1ad16087ec806286cf79692d870816becc7f3
parent03b3a2e419e1a6c9dd44211756abd47331fe0880 (diff)
downloadcrawl-ref-1328bd509fa25da1301d4ff6f4b6e9f2a630730e.tar.gz
crawl-ref-1328bd509fa25da1301d4ff6f4b6e9f2a630730e.zip
sartak's logfile patch and -scorefile option.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.1.6@635 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/acr.cc13
-rw-r--r--crawl-ref/source/externs.h2
-rw-r--r--crawl-ref/source/hiscores.cc68
-rw-r--r--crawl-ref/source/hiscores.h6
-rw-r--r--crawl-ref/source/initfile.cc76
-rw-r--r--crawl-ref/source/ouch.cc2
6 files changed, 114 insertions, 53 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 6be9c94139..6ad2f070b8 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -210,9 +210,10 @@ int main( int argc, char *argv[] )
puts("environment options (CRAWL_NAME, CRAWL_PIZZA, CRAWL_DIR, CRAWL_RC).");
puts("");
puts("Highscore list options: (Can now be redirected to more, etc)");
- puts(" -scores [N] highscore list");
- puts(" -tscores [N] terse highscore list");
- puts(" -vscores [N] verbose highscore list");
+ puts(" -scores [N] highscore list");
+ puts(" -tscores [N] terse highscore list");
+ puts(" -vscores [N] verbose highscore list");
+ puts(" -scorefile <filename> scorefile to report on");
exit(1);
}
@@ -231,6 +232,12 @@ int main( int argc, char *argv[] )
hiscores_print_list( Options.sc_entries, Options.sc_format );
exit(0);
}
+ else
+ {
+ // Don't allow scorefile override for actual gameplay, only for
+ // score listings.
+ SysEnv.scorefile.clear();
+ }
init_io();
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index dced0b42aa..b28786f966 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -659,7 +659,7 @@ struct system_environment
char *home; // only used by MULTIUSER systems
bool board_with_nail; // Easter Egg silliness
- std::string crawl_executable_path; // path to crawl from argv[0]
+ std::string scorefile;
};
extern system_environment SysEnv;
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 1e5fafe507..8ebe79f1c6 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -64,8 +64,9 @@ static scorefile_entry hs_list[SCORE_FILE_ENTRIES];
// highscore printing (always -1 when run from command line).
static int newest_entry = -1;
-static FILE *hs_open(const char *mode);
-static void hs_close(FILE *handle, const char *mode);
+static FILE *hs_open(const char *mode, const std::string &filename);
+static void hs_close(FILE *handle, const char *mode,
+ const std::string &filename);
static bool hs_read(FILE *scores, scorefile_entry &dest);
static void hs_parse_numeric(char *inbuf, scorefile_entry &dest);
static void hs_parse_string(char *inbuf, scorefile_entry &dest);
@@ -89,6 +90,19 @@ static bool lock_file_handle( FILE *handle, int type );
static bool unlock_file_handle( FILE *handle );
#endif // USE_FILE_LOCKING
+std::string score_file_name()
+{
+ if (!SysEnv.scorefile.empty())
+ return (SysEnv.scorefile);
+
+ return (Options.save_dir + "scores");
+}
+
+std::string log_file_name()
+{
+ return (Options.save_dir + "logfile");
+}
+
void hiscores_new_entry( const scorefile_entry &ne )
{
FILE *scores;
@@ -96,7 +110,7 @@ void hiscores_new_entry( const scorefile_entry &ne )
bool inserted = false;
// open highscore file (reading) -- note that NULL is not fatal!
- scores = hs_open("r");
+ scores = hs_open("r", score_file_name());
for (i = 0; i < SCORE_FILE_ENTRIES; ++i)
hs_list[i].reset();
@@ -139,10 +153,10 @@ void hiscores_new_entry( const scorefile_entry &ne )
total_entries = i;
// close so we can re-open for writing
- hs_close(scores,"r");
+ hs_close(scores,"r", score_file_name());
// open highscore file (writing) -- NULL *is* fatal here.
- scores = hs_open("w");
+ scores = hs_open("w", score_file_name());
if (scores == NULL)
{
perror("Entry not added - failure opening score file for writing.");
@@ -156,7 +170,26 @@ void hiscores_new_entry( const scorefile_entry &ne )
}
// close scorefile.
- hs_close(scores, "w");
+ hs_close(scores, "w", score_file_name());
+}
+
+void logfile_new_entry( const scorefile_entry &ne )
+{
+ FILE *logfile;
+ scorefile_entry le = ne;
+
+ // open logfile (appending) -- NULL *is* fatal here.
+ logfile = hs_open("a", log_file_name());
+ if (logfile == NULL)
+ {
+ perror("Entry not added - failure opening logfile for appending.");
+ return;
+ }
+
+ hs_write(logfile, le);
+
+ // close logfile.
+ hs_close(logfile, "a", log_file_name());
}
void hiscores_print_list( int display_count, int format )
@@ -169,7 +202,7 @@ void hiscores_print_list( int display_count, int format )
display_count = SCORE_FILE_ENTRIES;
// open highscore file (reading)
- scores = hs_open("r");
+ scores = hs_open("r", score_file_name());
if (scores == NULL)
{
// will only happen from command line
@@ -186,7 +219,7 @@ void hiscores_print_list( int display_count, int format )
total_entries = i;
// close off
- hs_close( scores, "r" );
+ hs_close( scores, "r", score_file_name() );
if (!use_printf)
textcolor(LIGHTGREY);
@@ -383,9 +416,8 @@ static bool unlock_file_handle( FILE *handle )
-FILE *hs_open( const char *mode )
+FILE *hs_open( const char *mode, const std::string &scores )
{
- std::string scores = Options.save_dir + "scores";
FILE *handle = fopen(scores.c_str(), mode);
#ifdef SHARED_FILES_CHMOD_PUBLIC
chmod(scores.c_str(), SHARED_FILES_CHMOD_PUBLIC);
@@ -393,7 +425,7 @@ FILE *hs_open( const char *mode )
#ifdef USE_FILE_LOCKING
int locktype = F_RDLCK;
- if (stricmp(mode, "w") == 0)
+ if (stricmp(mode, "r"))
locktype = F_WRLCK;
if (handle && !lock_file_handle( handle, locktype ))
@@ -406,7 +438,7 @@ FILE *hs_open( const char *mode )
return handle;
}
-void hs_close( FILE *handle, const char *mode )
+void hs_close( FILE *handle, const char *mode, const std::string &scores )
{
UNUSED( mode );
@@ -422,10 +454,7 @@ void hs_close( FILE *handle, const char *mode )
#ifdef SHARED_FILES_CHMOD_PUBLIC
if (stricmp(mode, "w") == 0)
- {
- std::string scores = Options.save_dir + "scores";
chmod(scores.c_str(), SHARED_FILES_CHMOD_PUBLIC);
- }
#endif
}
@@ -1346,9 +1375,12 @@ std::string scorefile_entry::game_time(death_desc_verbosity verbosity) const
if (uid > 0)
{
struct passwd *pw_entry = getpwuid( uid );
- strncpy( username, pw_entry->pw_name, sizeof(username) );
- strncat( username, "'s", sizeof(username) );
- username[0] = toupper( username[0] );
+ if (pw_entry)
+ {
+ strncpy( username, pw_entry->pw_name, sizeof(username) );
+ strncat( username, "'s", sizeof(username) );
+ username[0] = toupper( username[0] );
+ }
}
#endif
diff --git a/crawl-ref/source/hiscores.h b/crawl-ref/source/hiscores.h
index f8d7841fe7..39a524ab96 100644
--- a/crawl-ref/source/hiscores.h
+++ b/crawl-ref/source/hiscores.h
@@ -18,6 +18,12 @@
* *********************************************************************** */
void hiscores_new_entry( const scorefile_entry &se );
+// last updated 02dec2006 {smm}
+/* ***********************************************************************
+ * called from: ouch
+ * *********************************************************************** */
+void logfile_new_entry( const scorefile_entry &se );
+
// last updated 16feb2001 {gdl}
/* ***********************************************************************
* called from: acr ouch
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 6b3559c7a3..e67bd2bbdb 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -1971,26 +1971,32 @@ void get_system_environment(void)
// parse args, filling in Options and game environment as we go.
// returns true if no unknown or malformed arguments were found.
+// Keep this in sync with the option names.
+enum commandline_option_type {
+ CLO_SCORES,
+ CLO_NAME,
+ CLO_RACE,
+ CLO_CLASS,
+ CLO_PIZZA,
+ CLO_PLAIN,
+ CLO_DIR,
+ CLO_RC,
+ CLO_TSCORES,
+ CLO_VSCORES,
+ CLO_SCOREFILE,
+
+ CLO_NOPS
+};
+
static const char *cmd_ops[] = { "scores", "name", "race", "class",
"pizza", "plain", "dir", "rc", "tscores",
- "vscores" };
+ "vscores", "scorefile" };
-const int num_cmd_ops = 10;
+const int num_cmd_ops = CLO_NOPS;
bool arg_seen[num_cmd_ops];
-static void set_crawl_path(const std::string &path)
-{
- const std::string::size_type slash = path.rfind(FILE_SEPARATOR);
- SysEnv.crawl_executable_path =
- slash != std::string::npos? path.substr(0, slash + 1)
- : std::string("");
-}
-
bool parse_args( int argc, char **argv, bool rc_only )
{
- if (argc >= 1)
- set_crawl_path(argv[0]);
-
if (argc < 2) // no args!
return (true);
@@ -2016,9 +2022,9 @@ bool parse_args( int argc, char **argv, bool rc_only )
nextUsed = false;
- // arg MUST begin with '-' or '/'
+ // arg MUST begin with '-'
char c = arg[0];
- if (c != '-' && c != '/')
+ if (c != '-')
return (false);
// look for match (now we also except --scores)
@@ -2048,16 +2054,16 @@ bool parse_args( int argc, char **argv, bool rc_only )
bool next_is_param = false;
if (next_arg != NULL)
{
- if (next_arg[0] != '-' && next_arg[0] != '/')
+ if (next_arg[0] != '-')
next_is_param = true;
}
//.take action according to the cmd chosen
switch(o)
{
- case 0: // scores
- case 8: // tscores
- case 9: // vscores
+ case CLO_SCORES:
+ case CLO_TSCORES:
+ case CLO_VSCORES:
if (!next_is_param)
ecount = SCORE_FILE_ENTRIES; // default
else // optional number given
@@ -2076,26 +2082,34 @@ bool parse_args( int argc, char **argv, bool rc_only )
{
Options.sc_entries = ecount;
- if (o == 8)
+ if (o == CLO_TSCORES)
Options.sc_format = SCORE_TERSE;
- else if (o == 9)
+ else if (o == CLO_VSCORES)
Options.sc_format = SCORE_VERBOSE;
-
}
break;
- case 1: // name
+ case CLO_SCOREFILE:
+ if (!next_is_param) {
+ fprintf(stderr, "No parameter to -scorefile, %s\n",
+ next_arg? next_arg : "");
+ return (false);
+ }
+ if (!rc_only)
+ SysEnv.scorefile = next_arg;
+ nextUsed = true;
+ break;
+
+ case CLO_NAME:
if (!next_is_param)
return (false);
-
if (!rc_only)
Options.player_name = next_arg;
-
nextUsed = true;
break;
- case 2: // race
- case 3: // class
+ case CLO_RACE:
+ case CLO_CLASS:
if (!next_is_param)
return (false);
@@ -2113,7 +2127,7 @@ bool parse_args( int argc, char **argv, bool rc_only )
nextUsed = true;
break;
- case 4: // pizza
+ case CLO_PIZZA:
if (!next_is_param)
return (false);
@@ -2123,7 +2137,7 @@ bool parse_args( int argc, char **argv, bool rc_only )
nextUsed = true;
break;
- case 5: // plain
+ case CLO_PLAIN:
if (next_is_param)
return (false);
@@ -2134,7 +2148,7 @@ bool parse_args( int argc, char **argv, bool rc_only )
}
break;
- case 6: // dir
+ case CLO_DIR:
// ALWAYS PARSE
if (!next_is_param)
return (false);
@@ -2143,7 +2157,7 @@ bool parse_args( int argc, char **argv, bool rc_only )
nextUsed = true;
break;
- case 7:
+ case CLO_RC:
// ALWAYS PARSE
if (!next_is_param)
return (false);
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index f73f3c20da..433acb8ce6 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -785,6 +785,7 @@ void ouch( int dam, int death_source, char death_type, const char *aux )
#ifdef SCORE_WIZARD_CHARACTERS
// add this highscore to the score file.
hiscores_new_entry(se);
+ logfile_new_entry(se);
#else
// only add non-wizards to the score file.
@@ -792,6 +793,7 @@ void ouch( int dam, int death_source, char death_type, const char *aux )
if (!you.wizard)
{
hiscores_new_entry(se);
+ logfile_new_entry(se);
if (death_type != KILLED_BY_LEAVING && death_type != KILLED_BY_WINNING)
save_ghost();