summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 16:39:29 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-17 16:39:29 +0000
commitffce63e01d8fa4f31edb1a04c6a45227483a4bb5 (patch)
tree66c9e1ca97745b6212b8c29de4954644dcc906ca /crawl-ref
parent6c2cab15790887b588f7ada12971df5b6f18ed48 (diff)
downloadcrawl-ref-ffce63e01d8fa4f31edb1a04c6a45227483a4bb5.tar.gz
crawl-ref-ffce63e01d8fa4f31edb1a04c6a45227483a4bb5.zip
Tweaked hiscores code to handle logfiles in addition to scorefiles.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@664 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/acr.cc5
-rw-r--r--crawl-ref/source/hiscores.cc96
-rw-r--r--crawl-ref/source/hiscores.h1
-rw-r--r--crawl-ref/source/initfile.cc2
4 files changed, 63 insertions, 41 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index f4608ac336..e95179ea0a 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -209,10 +209,9 @@ int main( int argc, char *argv[] )
// now parse the args again, looking for everything else.
parse_args( argc, argv, false );
- if (Options.sc_entries > 0)
+ if (Options.sc_entries != 0)
{
- printf( " Best Crawlers -" EOL );
- hiscores_print_list( Options.sc_entries, Options.sc_format );
+ hiscores_print_all( Options.sc_entries, Options.sc_format );
exit(0);
}
else
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index da3061564c..b67cc72876 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -192,23 +192,72 @@ void logfile_new_entry( const scorefile_entry &ne )
hs_close(logfile, "a", log_file_name());
}
+static void hiscores_print_entry(const scorefile_entry &se,
+ int index,
+ int format,
+ int (*pf)(const char *, ...))
+{
+ char buf[INFO_SIZE];
+ // print position (tracked implicitly by order score file)
+ snprintf( buf, sizeof buf, "%3d.", index + 1 );
+
+ pf("%s", buf);
+
+ std::string entry;
+ // format the entry
+ if (format == SCORE_TERSE)
+ {
+ entry = hiscores_format_single( se );
+ // truncate if we want short format
+ if (entry.length() > 75)
+ entry = entry.substr(0, 75);
+ }
+ else
+ {
+ entry = hiscores_format_single_long( se, (format == SCORE_VERBOSE) );
+ }
+
+ entry += EOL;
+ pf("%s", entry.c_str());
+}
+
+// Writes all entries in the scorefile to stdout in human-readable form.
+void hiscores_print_all(int display_count, int format)
+{
+ FILE *scores = hs_open("r", score_file_name());
+ if (scores == NULL)
+ {
+ // will only happen from command line
+ puts( "No scores." );
+ return;
+ }
+
+ for (int entry = 0; display_count <= 0 || entry < display_count; ++entry)
+ {
+ scorefile_entry se;
+ if (!hs_read(scores, se))
+ break;
+
+ hiscores_print_entry(se, entry, format, printf);
+ }
+
+ hs_close( scores, "r", score_file_name() );
+}
+
+// Displays high scores using curses. For output to the console, use
+// hiscores_print_all.
void hiscores_print_list( int display_count, int format )
{
FILE *scores;
int i, total_entries;
- bool use_printf = (Options.sc_entries > 0);
if (display_count <= 0)
- display_count = SCORE_FILE_ENTRIES;
+ return;
// open highscore file (reading)
scores = hs_open("r", score_file_name());
if (scores == NULL)
- {
- // will only happen from command line
- puts( "No high scores." );
return;
- }
// read highscore file
for (i = 0; i < SCORE_FILE_ENTRIES; i++)
@@ -221,8 +270,7 @@ void hiscores_print_list( int display_count, int format )
// close off
hs_close( scores, "r", score_file_name() );
- if (!use_printf)
- textcolor(LIGHTGREY);
+ textcolor(LIGHTGREY);
int start = (newest_entry > 10) ? newest_entry - 10: 0;
@@ -237,38 +285,12 @@ void hiscores_print_list( int display_count, int format )
for (i = start; i < finish && i < total_entries; i++)
{
// check for recently added entry
- if (i == newest_entry && !use_printf)
+ if (i == newest_entry)
textcolor(YELLOW);
- // print position (tracked implicitly by order score file)
- snprintf( info, INFO_SIZE, "%3d.", i + 1 );
- if (use_printf)
- printf("%s", info);
- else
- cprintf("%s", info);
-
- std::string entry;
- // format the entry
- if (format == SCORE_TERSE)
- {
- entry = hiscores_format_single( hs_list[i] );
- // truncate if we want short format
- if (entry.length() > 75)
- entry = entry.substr(0, 75);
- }
- else
- {
- entry = hiscores_format_single_long( hs_list[i],
- (format == SCORE_VERBOSE) );
- }
-
- entry += EOL;
- if(use_printf)
- printf("%s", entry.c_str());
- else
- cprintf("%s", entry.c_str());
+ hiscores_print_entry(hs_list[i], i, format, cprintf);
- if (i == newest_entry && !use_printf)
+ if (i == newest_entry)
textcolor(LIGHTGREY);
}
}
diff --git a/crawl-ref/source/hiscores.h b/crawl-ref/source/hiscores.h
index 39a524ab96..5332b42baf 100644
--- a/crawl-ref/source/hiscores.h
+++ b/crawl-ref/source/hiscores.h
@@ -29,6 +29,7 @@ void logfile_new_entry( const scorefile_entry &se );
* called from: acr ouch
* *********************************************************************** */
void hiscores_print_list( int display_count = -1, int format = SCORE_TERSE );
+void hiscores_print_all(int display_count = -1, int format = SCORE_TERSE);
// last updated 16feb2001 {gdl}
/* ***********************************************************************
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index b476f5558c..6705e3a084 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -2299,7 +2299,7 @@ bool parse_args( int argc, char **argv, bool rc_only )
case CLO_TSCORES:
case CLO_VSCORES:
if (!next_is_param)
- ecount = SCORE_FILE_ENTRIES; // default
+ ecount = -1; // default
else // optional number given
{
ecount = atoi(next_arg);