36 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
38 using namespace basis;
56 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
67 ini_configurator::~ini_configurator()
70 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
75 astring ini_configurator::name()
const {
return _ini_name->raw(); }
77 void ini_configurator::refresh()
79 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
86 void ini_configurator::name(
const astring &name)
90 bool use_appdir =
true;
93 if (_where == OS_DIRECTORY) use_appdir =
false;
94 if (_where == ALL_USERS_DIRECTORY) use_appdir =
false;
99 if (!_ini_name->had_directory()) {
103 *_ini_name =
filename(application_configuration::application_directory(),
104 _ini_name->basename());
105 }
else if (!use_appdir && (_where == ALL_USERS_DIRECTORY) ) {
109 +
"/" + application_configuration::software_product_name());
111 +
"/" + application_configuration::software_product_name(),
112 _ini_name->basename());
115 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
126 if (!section8.
good())
return;
134 if (line_found[0] !=
'[')
continue;
135 line_found.
zap(0, 0);
136 int close_brack_indy = line_found.
find(
']');
137 if (
negative(close_brack_indy))
continue;
138 line_found.
zap(close_brack_indy, line_found.
end());
144 bool ini_configurator::section_exists(
const astring §ion)
151 return _parser->section_exists(section);
155 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
156 void ini_configurator::read_ini_file()
158 #ifdef DEBUG_INI_CONFIGURATOR
163 bool open_ret = ini_file.
open(*_ini_name,
"rb");
164 #ifdef DEBUG_INI_CONFIGURATOR
165 if (!open_ret)
LOG(
astring(
"failed to open ini file: ") + *_ini_name);
166 if (!ini_file.
good())
LOG(
astring(
"ini file not good: ") + *_ini_name);
168 if (!open_ret || !ini_file.
good()) {
171 int file_size = ini_file.
length();
173 astring contents(
' ', file_size + 3);
174 int bytes_read = ini_file.
read((
abyte *)contents.observe(), file_size);
175 contents.zap(bytes_read + 1, contents.end());
176 _parser->reset(contents);
179 void ini_configurator::write_ini_file()
181 #ifdef DEBUG_INI_CONFIGURATOR
190 bool open_ret = ini_file.
open(*_ini_name,
"wb");
192 #ifdef DEBUG_INI_CONFIGURATOR
193 if (!open_ret)
LOG(
astring(
"failed to open ini file: ") + *_ini_name);
194 if (!ini_file.
good())
LOG(
astring(
"ini file not good: ") + *_ini_name);
196 if (!open_ret || !ini_file.
good())
return;
200 _parser->restate(text, _add_spaces);
205 bool ini_configurator::delete_section(
const astring §ion)
211 bool to_return = _parser->delete_section(section);
224 bool to_return = _parser->delete_entry(section, ent);
235 if (!to_store.
length())
return delete_entry(section, entry);
236 else if (!entry.
length())
return delete_section(section);
237 else if (!section.
length())
return false;
242 bool to_return = _parser->put(section, entry, to_store);
252 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
253 return _parser->get(section, entry, found);
257 get_profile_string(section, entry, ini_str_fake_default(),
259 found = from_unicode_temp(temp_buffer);
260 return !(ini_str_fake_default() == found);
267 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
268 return _parser->get_section(section, info);
274 int read_len = GetPrivateProfileSection(to_unicode_temp(section.
observe()),
275 low_buff,
buffer_size - 1, to_unicode_temp(name()));
276 if (!read_len)
return false;
278 low_buff[read_len] =
'\1';
279 low_buff[read_len + 1] =
'\0';
281 bool last_was_nil =
false;
284 for (
int i = 0; i < read_len; i++) {
285 if (!low_buff[i] && last_was_nil) {
289 }
else if (!low_buff[i]) {
292 }
else last_was_nil =
false;
296 astring buff = from_unicode_temp(low_buff);
297 int length = buff.
length();
301 info = parser.
table();
306 bool ini_configurator::put_section(
const astring §ion,
332 bool to_return = _parser->put_section(section, info);
Provides a dynamically resizable ASCII character string.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
void strip_white_spaces(how_to_strip way=FROM_BOTH_SIDES)
like strip_spaces, but includes tabs in the list to strip.
void shrink()
changes all occurrences of "to_replace" into "new_string".
int end() const
returns the index of the last (non-null) character in the string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
static astring get(const astring &variable_name)
looks up the "variable_name" in the current environment variables.
Provides a base class for configuration repositories.
Supports a configurator-based interface on text initialization files.
file_location_default
chooses where the ini file is located if no path to it is provided.
Parses strings in the fairly well-known INI file format.
Manages a bank of textual definitions of variables.
const structures::string_table & table() const
provides a constant peek at the string_table holding the values.
bool parse(const basis::astring &to_tokenize)
parses the string using our established sentinel characters.
Provides file managment services using the standard I/O support.
int write(const basis::abyte *buffer, int buffer_size)
writes "buffer_size" bytes into the file from "buffer".
int read(basis::abyte *buffer, int buffer_size)
reads "buffer_size" bytes from the file into "buffer".
size_t length()
returns the file's total length, in bytes.
bool good()
returns true if the file seems to be in the appropriate desired state.
bool open(const basis::astring &fname, const basis::astring &permissions)
opens a file with "fname" and "permissions" as in the constructor.
Provides operations commonly needed on file names.
An array of strings with some additional helpful methods.
Provides a symbol_table that holds strings as the content.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
unsigned char abyte
A fairly important unit which is seldom defined...
bool negative(const type &a)
negative returns true if "a" is less than zero.
const int MAXIMUM_LINE_INI_CONFIG
A platform independent way to obtain the timestamp of a file.
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC_CONST(type, func_name, parms)
this version returns a constant object instead.
string_array(1, math_list))) const char *addr_list[]
Support for unicode builds.
Aids in achievement of platform independence.