diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-08-02 12:54:15 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-08-02 12:54:15 +0000 |
commit | d5e5340c3926d1cf97f6cba151ffaecb20bfb35f (patch) | |
tree | d1faf7d5b27df8f3c523a8dd33357804118e62b1 /trunk/source/initfile.h | |
parent | 7b2204d69f21d7075e4666ee032d7a129081bc4b (diff) | |
download | crawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.tar.gz crawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.zip |
Integrated travel patch as of 20060727
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'trunk/source/initfile.h')
-rw-r--r-- | trunk/source/initfile.h | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/trunk/source/initfile.h b/trunk/source/initfile.h index 6b641eb523..d5860fdd77 100644 --- a/trunk/source/initfile.h +++ b/trunk/source/initfile.h @@ -13,6 +13,7 @@ #define INITFILE_H #include <string> +#include <cstdio> std::string & trim_string( std::string &str ); @@ -20,8 +21,13 @@ std::string & trim_string( std::string &str ); /* *********************************************************************** * called from: acr * *********************************************************************** */ -void read_init_file(void); +void read_init_file(bool runscript = false); +void read_options(FILE *f, bool runscript = false); + +void read_options(const std::string &s, bool runscript = false); + +void parse_option_line(const std::string &line, bool runscript = false); // last updated 12may2000 {dlb} /* *********************************************************************** @@ -36,5 +42,60 @@ void get_system_environment(void); * *********************************************************************** */ bool parse_args(int argc, char **argv, bool rc_only); +void write_newgame_options_file(void); + +void save_player_name(void); + +std::string channel_to_str(int ch); + +int str_to_channel(const std::string &); + +class InitLineInput { +public: + virtual ~InitLineInput() { } + virtual bool eof() = 0; + virtual std::string getline() = 0; +}; + +class FileLineInput : public InitLineInput { +public: + FileLineInput(FILE *f) : file(f) { } + + bool eof() { + return !file || feof(file); + } + + std::string getline() { + char s[256] = ""; + if (!eof()) + fgets(s, sizeof s, file); + return (s); + } +private: + FILE *file; +}; + +class StringLineInput : public InitLineInput { +public: + StringLineInput(const std::string &s) : str(s), pos(0) { } + + bool eof() { + return pos >= str.length(); + } + + std::string getline() { + if (eof()) + return ""; + std::string::size_type newl = str.find("\n", pos); + if (newl == std::string::npos) + newl = str.length(); + std::string line = str.substr(pos, newl - pos); + pos = newl + 1; + return line; + } +private: + const std::string &str; + std::string::size_type pos; +}; #endif |