Code cleanup
[crawl.git] / crawl-ref / source / initfile.h
blobdf877577280e879a2792198ec6ba1703d8a5a560
1 /*
2 * File: initfile.h
3 * Summary: Simple reading of init file.
4 * Written by: David Loewenstern
5 */
8 #ifndef INITFILE_H
9 #define INITFILE_H
11 #include <string>
12 #include <cstdio>
14 #include "enum.h"
16 enum drop_mode_type
18 DM_SINGLE,
19 DM_MULTI,
22 int str_to_summon_type(const std::string &str);
23 std::string gametype_to_str(game_type type);
25 std::string read_init_file(bool runscript = false);
27 struct newgame_def;
28 newgame_def read_startup_prefs();
30 void read_options(FILE *f, bool runscript = false);
31 void read_options(const std::string &s, bool runscript = false,
32 bool clear_aliases = false);
34 void parse_option_line(const std::string &line, bool runscript = false);
36 void apply_ascii_display(bool ascii);
38 void get_system_environment(void);
40 struct system_environment
42 public:
43 std::string crawl_name;
44 std::string crawl_rc;
45 std::string crawl_dir;
47 std::vector<std::string> rcdirs; // Directories to search for includes.
49 std::string morgue_dir;
50 std::string macro_dir;
51 std::string crawl_base; // Directory from argv[0], may be used to
52 // locate datafiles.
53 std::string crawl_exe; // File from argv[0].
54 std::string home;
56 #ifdef DGL_SIMPLE_MESSAGING
57 std::string messagefile; // File containing messages from other users.
58 bool have_messages; // There are messages waiting to be read.
59 unsigned message_check_tick;
60 #endif
62 std::string scorefile;
63 std::vector<std::string> cmd_args;
65 int map_gen_iters;
67 std::vector<std::string> extra_opts_first;
68 std::vector<std::string> extra_opts_last;
70 public:
71 void add_rcdir(const std::string &dir);
74 extern system_environment SysEnv;
76 bool parse_args(int argc, char **argv, bool rc_only);
78 struct newgame_def;
79 void write_newgame_options_file(const newgame_def& prefs);
81 void save_player_name(void);
83 std::string channel_to_str(int ch);
85 int str_to_channel(const std::string &);
87 class InitLineInput
89 public:
90 virtual ~InitLineInput() { }
91 virtual bool eof() = 0;
92 virtual std::string getline() = 0;
95 class FileLineInput : public InitLineInput
97 public:
98 FileLineInput(FILE *f) : file(f) { }
100 bool eof()
102 return !file || feof(file);
105 std::string getline()
107 char s[256] = "";
108 if (!eof())
109 fgets(s, sizeof s, file);
110 return (s);
112 private:
113 FILE *file;
116 class StringLineInput : public InitLineInput
118 public:
119 StringLineInput(const std::string &s) : str(s), pos(0) { }
121 bool eof()
123 return pos >= str.length();
126 std::string getline()
128 if (eof())
129 return "";
130 std::string::size_type newl = str.find("\n", pos);
131 if (newl == std::string::npos)
132 newl = str.length();
133 std::string line = str.substr(pos, newl - pos);
134 pos = newl + 1;
135 return line;
137 private:
138 const std::string &str;
139 std::string::size_type pos;
142 #endif