summaryrefslogtreecommitdiff
path: root/src/files.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-02-13 13:56:52 +0100
committerBardur Arantsson <bardur@scientician.net>2016-02-13 13:56:52 +0100
commit4d237a87eb76eb4c6bcc5d8cbf7544a8f3184f30 (patch)
tree5e87923522f444880a6be4239e162c16312408a4 /src/files.cc
parentf13c5091e4864e957c83a35621365c8b510b80ba (diff)
Reduce file-open/close boilerplate and simplify formatting
- We introduce a show_string() which will allow us to go without actually writing a file if we want to later. - Use cppformat to simplify the output formatting.
Diffstat (limited to 'src/files.cc')
-rw-r--r--src/files.cc25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/files.cc b/src/files.cc
index ab5421b5..be1e208a 100644
--- a/src/files.cc
+++ b/src/files.cc
@@ -54,7 +54,10 @@
#include "xtra1.hpp"
#include "z-rand.hpp"
+#include <boost/filesystem.hpp>
#include <memory>
+#include <iostream>
+#include <fstream>
#include <unordered_set>
/*
@@ -2784,7 +2787,7 @@ errr file_character(cptr name, bool_ full)
file_character_print_grid(fff, FALSE, FALSE);
/* Dump corruptions */
- dump_corruptions(fff, FALSE, TRUE);
+ fprintf(fff, "\n%s\n", dump_corruptions(false, true).c_str());
/* Dump skills */
dump_skills(fff);
@@ -2806,7 +2809,7 @@ errr file_character(cptr name, bool_ full)
if ((fates[i].fate) && (fates[i].know))
{
fprintf(fff, "\n\n [Fates]\n\n");
- dump_fates(fff);
+ fprintf(fff, "%s", dump_fates().c_str());
break;
}
}
@@ -3501,6 +3504,24 @@ static bool_ show_file_aux(cptr name, cptr what, int line)
return (TRUE);
}
+void show_string(const char *lines, const char *title, int line)
+{
+ // Temporary file
+ auto const file_name = boost::filesystem::unique_path().string();
+
+ // Open a new file
+ std::ofstream ofs(file_name);
+ ofs.exceptions(std::ofstream::failbit);
+ ofs << lines;
+ ofs.close();
+
+ // Display the file contents
+ show_file_aux(file_name.c_str(), title, line);
+
+ // Remove the file
+ fd_kill(file_name.c_str());
+}
+
void show_file(cptr name, cptr what, int line)
{
show_file_aux(name, what, line);