From 9b09694770ae4724f3f264603b8ba7ff3865b06a Mon Sep 17 00:00:00 2001 From: haranp Date: Tue, 15 May 2007 07:27:59 +0000 Subject: Made make_time_string() return std::string, not char*. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1474 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 7 +++---- crawl-ref/source/chardump.cc | 6 +----- crawl-ref/source/hiscores.cc | 7 ++----- crawl-ref/source/output.cc | 10 ++-------- crawl-ref/source/stuff.cc | 22 ++++++++++++---------- crawl-ref/source/stuff.h | 2 +- 6 files changed, 21 insertions(+), 33 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 05de6baea4..9ba81631f8 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1016,10 +1016,9 @@ static void experience_check() if (you.real_time != -1) { const time_t curr = you.real_time + (time(NULL) - you.start_time); - char buff[200]; - - mprf("Play time: %s (%ld turns)", - make_time_string(curr, buff, sizeof buff), you.num_turns ); + msg::stream << "Play time: " << make_time_string(curr) + << " (" << you.num_turns << " turns)" + << std::endl; } #ifdef DEBUG_DIAGNOSTICS if (wearing_amulet(AMU_THE_GOURMAND)) diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index a5a6b497c5..9f807ede2b 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -375,12 +375,8 @@ static void dump_stats( std::string & text ) if (you.real_time != -1) { const time_t curr = you.real_time + (time(NULL) - you.start_time); - char buff[200]; - - make_time_string( curr, buff, sizeof(buff) ); - text += "Play time: "; - text += buff; + text += make_time_string(curr); text += " Number of turns: "; itoa( you.num_turns, st_prn, 10 ); diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc index 30f1928da9..ca0136afcb 100644 --- a/crawl-ref/source/hiscores.cc +++ b/crawl-ref/source/hiscores.cc @@ -1161,7 +1161,6 @@ std::string scorefile_entry::game_time(death_desc_verbosity verbosity) const { char username[80] = "The"; char scratch[INFO_SIZE]; - char tmp[80]; #ifdef MULTIUSER if (uid > 0) @@ -1175,11 +1174,9 @@ std::string scorefile_entry::game_time(death_desc_verbosity verbosity) const } } #endif - - make_time_string( real_time, tmp, sizeof(tmp) ); - snprintf( scratch, INFO_SIZE, "%s game lasted %s (%ld turns).", - username, tmp, num_turns ); + username, make_time_string(real_time).c_str(), + num_turns ); line += scratch; line += hiscore_newline_string(); diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index f1948b024a..f113605a5b 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -806,13 +806,10 @@ std::vector get_full_detail(bool calc_unid) if (you.real_time != -1) { const time_t curr = you.real_time + (time(NULL) - you.start_time); - char buff[200]; - make_time_string( curr, buff, sizeof(buff), true ); - snprintf(buf, sizeof buf, "Play time : %10s\n" "Turns : %10ld\n", - buff, you.num_turns ); + make_time_string(curr).c_str(), you.num_turns ); cols.add_formatted(0, buf, true); } @@ -1010,12 +1007,9 @@ void print_overview_screen() if (you.real_time != -1) { const time_t curr = you.real_time + (time(NULL) - you.start_time); - char buff[200]; - make_time_string( curr, buff, sizeof(buff), true ); - snprintf(time_turns, sizeof time_turns, " Turns: %ld, Time: %s", - you.num_turns, buff ); + you.num_turns, make_time_string(curr, true).c_str() ); } int linelength = strlen(you.your_name) + strlen(title) diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index 4c5d1ff876..6f2f5593b7 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -21,6 +21,9 @@ #include "stuff.h" #include "view.h" +#include +#include + #include #include #include @@ -65,29 +68,28 @@ #include "view.h" // Crude, but functional. -char *const make_time_string( time_t abs_time, char *const buff, int buff_size, - bool terse ) +std::string make_time_string( time_t abs_time, bool terse ) { const int days = abs_time / 86400; const int hours = (abs_time % 86400) / 3600; const int mins = (abs_time % 3600) / 60; const int secs = abs_time % 60; - char day_buff[32]; + std::ostringstream buff; + buff << std::setfill('0'); if (days > 0) { if (terse) - snprintf(day_buff, sizeof day_buff, "%d, ", days); + buff << days << ", "; else - snprintf( day_buff, sizeof(day_buff), "%d day%s, ", - days, (days > 1) ? "s" : "" ); + buff << days << (days > 1 ? " days" : "day"); } - snprintf( buff, buff_size, "%s%02d:%02d:%02d", - (days > 0) ? day_buff : "", hours, mins, secs ); - - return (buff); + buff << std::setw(2) << hours << ':' + << std::setw(2) << mins << ':' + << std::setw(2) << secs; + return buff.str(); } void set_redraw_status( unsigned long flags ) diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h index 82b8727b7a..c3c043af8d 100644 --- a/crawl-ref/source/stuff.h +++ b/crawl-ref/source/stuff.h @@ -18,7 +18,7 @@ #include "externs.h" -char *const make_time_string(time_t abs_time, char *const buff, int buff_size, bool terse = false); +std::string make_time_string(time_t abs_time, bool terse = false); void set_redraw_status( unsigned long flags ); void tag_followers( void ); void untag_followers( void ); -- cgit v1.2.3-54-g00ecf