rudeconfig(3)
β¨ NAME β¨
rudeconfig β bestie, it reads and manipulates .ini and config files. That's it, that's the whole job, and it ate. π
(also yes, this is the rudeconfig(3) page, section 3, library calls, iykyk)
π SYNOPSIS π
#include <rude/config.h>
rude::Config myconfig;
πΈ STATIC METHODS
static const char *rude::version();
static void rude::setDefaultConfigFile(const char *filepath);
static const char *rude::getDefaultConfigFile();
static void rude::setDefaultCommentCharacter(char c);
static char rude::getDefaultCommentCharacter();
static void rude::setDefaultDelimiter(char c);
static char rude::getDefaultDelimiter();
static void rude::setDefaultPreserveDeleted(bool shouldPreserve);
static void rude::setDefaultPreserveDeleted(bool shouldPreserve);
no cap, setDefaultPreserveDeleted really is listed twice up there β I'm not gaslighting you, that's just how the page is. π
π¦ REDEFINING INSTANCE BEHAVIOR
void setConfigFile(const char *filepath);
const char * getConfigFile();
void preserveDeletedData(bool shouldPreserve);
void setCommentCharacter(char commentchar);
void setDelimiter(char keyvaluedelimiter);
π LOADING AND SAVING FILES
bool save();
bool save(const char *filepath);
void clear();
bool load();
bool load(const char *filename);
const char *getError();
β SECTION METHODS
int getNumSections() const;
const char *getSectionNameAt(int index) const;
bool setSection(const char *sectionname, bool shouldCreate);
bool setSection(const char *sectionname);
bool deleteSection(const char *sectionname);
π KEY/VALUE DISCOVERY METHODS
int getNumDataMembers() const;
const char *getDataNameAt(int index) const;
bool exists(const char *name) const;
π DATA ACCESSORS
bool getBoolValue(const char *name) const;
int getIntValue(const char *name) const;
double getDoubleValue(const char *name) const;
const char * getValue(const char *name) const;
const char * getStringValue(const char *name) const;
π§ DATA MUTATORS
void setBoolValue(const char *name, bool value);
void setIntValue(const char *name, int value);
void setDoubleValue(const char *name, double value");
void setValue(const char *name, const char *value);
void setStringValue(const char *name, const char *value);
okay so thatdouble value");up there? yeah, that stray"is living in the original and it's staying, periodt. Not my business, not my problem, I don't make the rules. π
π KEY/VALUE DELETION
bool deleteData(const char *name);
π«Ά DESTRUCTOR
~Config();
π DESCRIPTION π
The rudeConfig library is literally just here to read and manipulate .ini and configuration files. That's the whole vibe. Slay. β¨
πΈ CONFIGURATION/.INI FILE FORMAT πΈ
Configuration and .ini files have this structure, bestie:
A configuration file contains one or more "sections". Each "section" contains 0 or more "key=value" pairs. Sections can also contain blank lines and comments. π
Sections are identified by the section name surrounded by square brackets β like [example section]. The unnamed, or default, section, is represented by empty square brackets β as in []. The beginning of the configuration file, up to the first named section, is also considered part of the unnamed/default section. White space surrounding the section name is ignored. Quotes can be used in section names if desired. As such, the following section names are identical:
[State Codes]
[ State Codes ]
[ "State Codes" ]
The default delimiter for key/value pairs is the equals (=) sign. The default comment character is the hash (#). These can be changed via the API to any character, with a few restrictions: the key/value delimiter cannot be '\' (escape), '[' (left square bracket), or any end of line character. The comment character cannot be '\' (escape), '[' (left square bracket) or '"' (double quote). Furthermore, the key/value delimiter cannot be set to the same value as the comment character.
β οΈ okay so those restrictions are not a suggestion, they're a whole boundary. Try to be cute and set your delimiter to\or[and it's giving chaos. Don't. π βοΈ
The key of each key/value pair within a section must be unique. If the same key appears more than once within a given section, all but the last key will be ignored. If more than one configuration file is loaded into the same rude::Config object, duplicate key/value pairs will replace existing ones. π₯
Although sections of a given name can be repeated in a physical configuration file, they are logically combined when the rude::Config object parses the file. If the rude::Config object is subsequently saved, then the sections will be merged β with all key/value pairs occurring one section. An example of multiple sections with the same name is given here:
# beginning of example .ini file
[State Codes]
AZ = Arizona
CO = Colorado
[State Codes]
NY = New York
CA = California
[State Codes]
PA = Pennsylvania
IL = Illinios
#end of example .ini file
Comments do not have to start at the beginning of a line. They can appear after section declarations (on the same line) and they can appear after key=value pairs. π
# -- first line of config file --
# this is in the default section
# this is a comment
# the following line is a key=value pair
color=blue
[contact information]
# this is a new section
first name=Matthew
last name = Flood # comments are allowed after key=value pairs
[]
# since there is no section name, this is the default section again
size=large
[login info]
username=scruffy
password=$$324reeWrew65456
[contact information]
# this section is a continuation of contact information section listed earlier
#
# the following key=value pair demonstrates using quotes for multi-line values
address="111 example street
apartment Z"
city=boulder
# -- end of config file --
π EXAMPLES π
Examples, how-to's and tutorials can also be found at the rudeserver.com website. π¦
β¨ Basic Usage
#include <rude/config.h>
int main(void)
{
// Create config object
//
rude::Config config;
// load a configuration/.ini file
config.load("myfile.ini");
// read information
//
config.setSection("General Info");
double cost = config.getDoubleValue("Cost");
const char *company = config.getStringValue("Company Name");
// create information
//
config.setSection("new section");
config.setStringValue("animal type", "giraffe");
config.setBoolValue("mammal", true);
// save changes
//
config.save();
return 0;
}
π SEE ALSO π
rudecgiparser(3), rudedatabase(3), rudesocket(3), rudesession(3)
like, go read those too, they're all in the family π«Ά
π REPORTING PROBLEMS π
Before reporting a problem, please check the rudeserver.com web site to verify that you have the latest version of rudeconfig; otherwise, obtain the latest version and see if the problem still exists. Please read the FAQ at:
http://www.rudeserver.com/
before asking for help. Send questions and/or comments to matt@rudeserver.com π
π§ AUTHORS π§
Copyright (C) 2000 Matthew Flood (matt@rudeserver.com)
This software is provided "as-is," without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. See the distribution directory with respect to requirements governing redistribution. Thanks to all the people who reported problems and suggested various improvements in rudeconfig; who are too numerous to cite here. π«Ά
and that's the whole page, bestie β this was Version 5.0, dated January 19, 2006, from the rudeconfig(3) corner of the User Manuals universe. go forth and parse your .ini files, you absolute icon π
β¨
π¦ where this page comes from
- fedora 43: rudeconfig-devel 5.0.6-17.fc43 Β· GPL-2.0-or-later
- fedora 43: rudeconfig-devel 5.0.6-17.fc43 Β· GPL-2.0-or-later
- fedora 44: rudeconfig-devel 5.0.6-18.fc44 Β· GPL-2.0-or-later
- fedora 44: rudeconfig-devel 5.0.6-18.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms