00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INITFILE_H
00009 #define INITFILE_H
00010
00011 #include <string>
00012 #include <cstdio>
00013
00014 #include "enum.h"
00015
00016 enum drop_mode_type
00017 {
00018 DM_SINGLE,
00019 DM_MULTI,
00020 };
00021
00022 int str_to_summon_type (const std::string &str);
00023 std::string gametype_to_str(game_type type);
00024
00025 std::string read_init_file(bool runscript = false);
00026
00027 struct newgame_def;
00028 newgame_def read_startup_prefs();
00029
00030 void read_options(FILE *f, bool runscript = false);
00031 void read_options(const std::string &s, bool runscript = false,
00032 bool clear_aliases = false);
00033
00034 void parse_option_line(const std::string &line, bool runscript = false);
00035
00036 void apply_ascii_display(bool ascii);
00037
00038 void get_system_environment(void);
00039
00040 struct system_environment
00041 {
00042 public:
00043 std::string crawl_name;
00044 std::string crawl_rc;
00045 std::string crawl_dir;
00046
00047 std::vector<std::string> rcdirs;
00048
00049 std::string morgue_dir;
00050 std::string macro_dir;
00051 std::string crawl_base;
00052
00053 std::string crawl_exe;
00054 std::string home;
00055
00056 #ifdef DGL_SIMPLE_MESSAGING
00057 std::string messagefile;
00058 bool have_messages;
00059 unsigned message_check_tick;
00060 #endif
00061
00062 std::string scorefile;
00063 std::vector<std::string> cmd_args;
00064
00065 int map_gen_iters;
00066
00067 std::vector<std::string> extra_opts_first;
00068 std::vector<std::string> extra_opts_last;
00069
00070 public:
00071 void add_rcdir(const std::string &dir);
00072 };
00073
00074 extern system_environment SysEnv;
00075
00076 bool parse_args(int argc, char **argv, bool rc_only);
00077
00078 struct newgame_def;
00079 void write_newgame_options_file(const newgame_def& prefs);
00080
00081 void save_player_name(void);
00082
00083 std::string channel_to_str(int ch);
00084
00085 int str_to_channel(const std::string &);
00086
00087 class InitLineInput
00088 {
00089 public:
00090 virtual ~InitLineInput() { }
00091 virtual bool eof() = 0;
00092 virtual std::string getline() = 0;
00093 };
00094
00095 class FileLineInput : public InitLineInput
00096 {
00097 public:
00098 FileLineInput(FILE *f) : file(f) { }
00099
00100 bool eof()
00101 {
00102 return !file || feof(file);
00103 }
00104
00105 std::string getline()
00106 {
00107 char s[256] = "";
00108 if (!eof())
00109 fgets(s, sizeof s, file);
00110 return (s);
00111 }
00112 private:
00113 FILE *file;
00114 };
00115
00116 class StringLineInput : public InitLineInput
00117 {
00118 public:
00119 StringLineInput(const std::string &s) : str(s), pos(0) { }
00120
00121 bool eof()
00122 {
00123 return pos >= str.length();
00124 }
00125
00126 std::string getline()
00127 {
00128 if (eof())
00129 return "";
00130 std::string::size_type newl = str.find("\n", pos);
00131 if (newl == std::string::npos)
00132 newl = str.length();
00133 std::string line = str.substr(pos, newl - pos);
00134 pos = newl + 1;
00135 return line;
00136 }
00137 private:
00138 const std::string &str;
00139 std::string::size_type pos;
00140 };
00141
00142 #endif