diff options
author | Adam Borowski <kilobyte@angband.pl> | 2011-04-01 01:00:14 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2011-04-01 01:00:14 +0200 |
commit | 452ff385766f7f82e4ff92f319dd3a284795fd2e (patch) | |
tree | 35f3bfd02c4d16d05cda2126aaf82dd945690686 /crawl-ref/source/macro.cc | |
parent | 778a975c1cf474d6c585d2177956daff30cffc24 (diff) | |
parent | 5485922b1f7b6c4e369d0b885ccfbff0e6e0d850 (diff) | |
download | crawl-ref-452ff385766f7f82e4ff92f319dd3a284795fd2e.tar.gz crawl-ref-452ff385766f7f82e4ff92f319dd3a284795fd2e.zip |
Merge branch 'unicode'.
There are some issues left, like incorrect wrapping in some cases, but
we can fix them later.
Diffstat (limited to 'crawl-ref/source/macro.cc')
-rw-r--r-- | crawl-ref/source/macro.cc | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc index 991d282e46..ab5a4fe1d1 100644 --- a/crawl-ref/source/macro.cc +++ b/crawl-ref/source/macro.cc @@ -23,8 +23,6 @@ #include "macro.h" #include "state.h" -#include <iostream> -#include <fstream> #include <string> #include <sstream> #include <map> @@ -43,6 +41,8 @@ #include "message.h" #include "state.h" #include "stuff.h" +#include "syscalls.h" +#include "unicode.h" // for trim_string: #include "initfile.h" @@ -645,7 +645,7 @@ int macro_buf_get() return (key); } -static void write_map(std::ofstream &f, const macromap &mp, const char *key) +static void write_map(FILE *f, const macromap &mp, const char *key) { for (macromap::const_iterator i = mp.begin(); i != mp.end(); i++) { @@ -653,8 +653,8 @@ static void write_map(std::ofstream &f, const macromap &mp, const char *key) // macro struct for all used keyboard commands. if (i->second.size()) { - f << key << vtostr((*i).first) << std::endl - << "A:" << vtostr((*i).second) << std::endl << std::endl; + fprintf(f, "%s%s\nA:%s\n\n", OUTS(key), + OUTS(vtostr((*i).first)), OUTS(vtostr((*i).second))); } } } @@ -664,18 +664,21 @@ static void write_map(std::ofstream &f, const macromap &mp, const char *key) */ void macro_save() { - std::ofstream f; + FILE *f; const std::string macrofile = get_macro_file(); - f.open(macrofile.c_str()); + f = fopen_u(macrofile.c_str(), "w"); if (!f) { mprf(MSGCH_ERROR, "Couldn't open %s for writing!", macrofile.c_str()); return; } - f << "# " CRAWL " " << Version::Long() << " macro file" << std::endl - << "# WARNING: This file is entirely auto-generated." << std::endl - << std::endl << "# Key Mappings:" << std::endl; + fprintf(f, "# %s %s macro file\n" + "# WARNING: This file is entirely auto-generated.\n" + "\n" + "# Key Mappings:\n", + OUTS(CRAWL), // ok, localizing the game name is not likely + OUTS(Version::Long())); // nor the version string for (int mc = KMC_DEFAULT; mc < KMC_CONTEXT_COUNT; ++mc) { char buf[30] = "K:"; @@ -684,11 +687,11 @@ void macro_save() write_map(f, Keymaps[mc], buf); } - f << "# Command Macros:" << std::endl; + fprintf(f, "# Command Macros:\n"); write_map(f, Macros, "M:"); crawl_state.unsaved_macros = false; - f.close(); + fclose(f); } /* @@ -1010,13 +1013,14 @@ static void _read_macros_from(const char* filename) return; std::string s; - std::ifstream f(filename); + FileLineInput f(filename); keyseq key, action; bool keymap = false; KeymapContext keymc = KMC_DEFAULT; - while (f >> s) + while (!f.eof()) { + s = f.get_line(); trim_string(s); // remove white space from ends if (s[0] == '#') |