summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/initfile.h
blob: 0a39e9db41fe5bf36d8174eb723485d707e367b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 *  File:       initfile.h
 *  Summary:    Simple reading of init file.
 *  Written by: David Loewenstern
 */


#ifndef INITFILE_H
#define INITFILE_H

#include <string>
#include <cstdio>

#include "enum.h"

enum drop_mode_type
{
    DM_SINGLE,
    DM_MULTI
};

god_type str_to_god(std::string god);
int str_to_summon_type (const std::string &str);

std::string read_init_file(bool runscript = false);

void read_startup_prefs();
void read_options(FILE *f, bool runscript = false);
void read_options(const std::string &s, bool runscript = false,
                  bool clear_aliases = false);

void parse_option_line(const std::string &line, bool runscript = false);

void apply_ascii_display(bool ascii);

void get_system_environment(void);

struct system_environment
{
public:
    std::string crawl_name;
    std::string crawl_rc;
    std::string crawl_dir;

    std::vector<std::string> rcdirs;   // Directories to search for includes.

    std::string morgue_dir;
    std::string crawl_base;        // Directory from argv[0], may be used to
                                   // locate datafiles.
    std::string home;              // only used by MULTIUSER systems
    bool  board_with_nail;         // Easter Egg silliness

#ifdef DGL_SIMPLE_MESSAGING
    std::string messagefile;       // File containing messages from other users.
    bool have_messages;            // There are messages waiting to be read.
    unsigned  message_check_tick;
#endif

    std::string scorefile;
    std::vector<std::string> cmd_args;

    int map_gen_iters;

    std::string arena_teams;

    std::vector<std::string> extra_opts_first;
    std::vector<std::string> extra_opts_last;

public:
    void add_rcdir(const std::string &dir);
};

extern system_environment SysEnv;

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