36#define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
56#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
70#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
79#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
90 bool use_appdir =
true;
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());
155#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
156void 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);
179void 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);
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__)
274 int read_len = GetPrivateProfileSection(to_unicode_temp(section.
observe()),
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();
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.
static basis::astring application_directory()
returns the directory name where this application is running from.
static const char * software_product_name()
This global function is available to the system at large for branding info.
Provides a base class for configuration repositories.
treatment_of_defaults behavior() const
observes the behavior chosen for the load() function.
Supports a configurator-based interface on text initialization files.
virtual bool section_exists(const basis::astring §ion)
returns true if the "section" was found in the file.
virtual bool delete_entry(const basis::astring §ion, const basis::astring &entry)
removes the entry specified by the "section" and "entry" name.
file_location_default
chooses where the ini file is located if no path to it is provided.
@ OS_DIRECTORY
config files live in operating system directory.
@ ALL_USERS_DIRECTORY
config files live in the "all users" account.
virtual ~ini_configurator()
virtual void sections(structures::string_array &list)
retrieves the section names into "list".
basis::astring name() const
observes the name of the file used for ini entries.
virtual bool get(const basis::astring §ion, const basis::astring &entry, basis::astring &found)
implements the configurator retrieval function.
virtual bool delete_section(const basis::astring §ion)
removes the entire "section" specified.
virtual bool put_section(const basis::astring §ion, const structures::string_table &info)
writes a table called "info" into the "section" in the INI file.
virtual bool get_section(const basis::astring §ion, structures::string_table &info)
reads the entire "section" into a table called "info".
virtual bool put(const basis::astring §ion, const basis::astring &entry, const basis::astring &to_store)
implements the configurator storage function.
void refresh()
useful mainly on unix/linux, where the file is parsed and held in memory.
Parses strings in the fairly well-known INI file format.
void reset(const basis::astring &to_parse)
drops any existing information and processes the string "to_parse".
bool restate(basis::astring &new_ini, bool add_spaces=false)
stores a cleaned version of the internal state into "new_ini".
virtual bool delete_entry(const basis::astring §ion, const basis::astring &entry)
removes the entry specified by the "section" and "entry" name.
virtual bool put(const basis::astring §ion, const basis::astring &entry, const basis::astring &to_store)
implements the configurator storage function.
virtual bool delete_section(const basis::astring §ion)
removes the entire "section" specified.
virtual bool get(const basis::astring §ion, const basis::astring &entry, basis::astring &found)
implements the configurator retrieval function.
virtual bool section_exists(const basis::astring §ion)
true if the "section" is presently in the table config.
virtual bool put_section(const basis::astring §ion, const structures::string_table &info)
writes a table called "info" into the "section" held here.
virtual bool get_section(const basis::astring §ion, structures::string_table &info)
reads the entire table held under "section" into a table called "info".
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.
static bool make_directory(const basis::astring &path)
returns true if the directory "path" could be created.
Provides operations commonly needed on file names.
bool had_directory() const
returns true if the name that we were given had a non-empty directory.
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
filename basename() const
returns the base of the filename; no directory.
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.
Support for unicode builds.
Aids in achievement of platform independence.