blob: 8be4ffad197245f74fcf5ff8a1faf3d7da8f68ed (
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
|
/*
* File: initfile.h
* Summary: Simple reading of init file.
* Written by: David Loewenstern
*
* Change History (most recent first):
*
* <1> 6/9/99 DML Created
*/
#ifndef INITFILE_H
#define INITFILE_H
#include <string>
#include <cstdio>
std::string & trim_string( std::string &str );
// last updated 12may2000 {dlb}
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
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);
void apply_ascii_display(bool ascii);
// last updated 12may2000 {dlb}
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
void get_system_environment(void);
// last updated 16feb2001 {gdl}
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
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
|