1 /** 2 * @file 3 * @brief Simple reading of init file. 4 **/ 5 6 #pragma once 7 8 #include <cstdio> 9 #include <string> 10 #include <vector> 11 12 #include "enum.h" 13 #include "game-type.h" 14 #include "item-prop-enum.h" 15 #include "job-type.h" 16 #include "unicode.h" 17 18 using std::vector; 19 20 int str_to_summon_type(const string &str); 21 string gametype_to_str(game_type type); 22 23 job_type str_to_job(const string &str); 24 25 string find_crawlrc(); 26 void read_init_file(bool runscript = false); 27 28 struct newgame_def; 29 newgame_def read_startup_prefs(); 30 31 void read_options(const string &s, bool runscript = false, 32 bool clear_aliases = false); 33 34 void get_system_environment(); 35 36 class depth_ranges; 37 38 struct system_environment 39 { 40 public: 41 string crawl_name; 42 string crawl_rc; 43 string crawl_dir; 44 45 vector<string> rcdirs; // Directories to search for includes. 46 47 string morgue_dir; 48 string macro_dir; 49 string crawl_base; // Directory from argv[0], may be used to 50 // locate datafiles. 51 string crawl_exe; // File from argv[0]. 52 string home; 53 54 #ifdef DGL_SIMPLE_MESSAGING 55 string messagefile; // File containing messages from other users. 56 bool have_messages; // There are messages waiting to be read. 57 unsigned message_check_tick; 58 #endif 59 60 string scorefile; 61 vector<string> cmd_args; 62 63 int map_gen_iters; 64 unique_ptr<depth_ranges> map_gen_range; 65 66 vector<string> extra_opts_first; 67 vector<string> extra_opts_last; 68 69 public: 70 void add_rcdir(const string &dir); 71 }; 72 73 extern system_environment SysEnv; 74 75 bool parse_args(int argc, char **argv, bool rc_only); 76 77 struct newgame_def; 78 void write_newgame_options_file(const newgame_def& prefs); 79 80 void save_player_name(); 81 void save_seed_pref(); 82 83 string channel_to_str(int ch); 84 85 int str_to_channel(const string &); 86 weapon_type str_to_weapon(const string &str); 87 88 class StringLineInput : public LineInput 89 { 90 public: StringLineInput(const string & s)91 StringLineInput(const string &s) : str(s), pos(0) { } 92 eof()93 bool eof() override 94 { 95 return pos >= str.length(); 96 } 97 get_line()98 string get_line() override 99 { 100 if (eof()) 101 return ""; 102 string::size_type newl = str.find("\n", pos); 103 if (newl == string::npos) 104 newl = str.length(); 105 string line = str.substr(pos, newl - pos); 106 pos = newl + 1; 107 return line; 108 } 109 private: 110 const string &str; 111 string::size_type pos; 112 }; 113