Skip to content

Commit

Permalink
COMMON: Rename ConfigFile to INIFile.
Browse files Browse the repository at this point in the history
This clears up that 'ConfigFile' is actually a class handling only INI-files.
  • Loading branch information
Johannes Schickel committed Aug 8, 2013
1 parent 6e5c308 commit 63750d6
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion common/config-manager.h
Expand Up @@ -24,7 +24,7 @@
#define COMMON_CONFIG_MANAGER_H

#include "common/array.h"
//#include "common/config-file.h"
//#include "common/ini-file.h"
#include "common/hashmap.h"
#include "common/singleton.h"
#include "common/str.h"
Expand Down
60 changes: 30 additions & 30 deletions common/config-file.cpp → common/ini-file.cpp
Expand Up @@ -20,40 +20,40 @@
*
*/

#include "common/config-file.h"
#include "common/ini-file.h"
#include "common/file.h"
#include "common/savefile.h"
#include "common/system.h"
#include "common/textconsole.h"

namespace Common {

bool ConfigFile::isValidName(const String &name) {
bool INIFile::isValidName(const String &name) {
const char *p = name.c_str();
while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.'))
p++;
return *p == 0;
}

ConfigFile::ConfigFile() {
INIFile::INIFile() {
}

ConfigFile::~ConfigFile() {
INIFile::~INIFile() {
}

void ConfigFile::clear() {
void INIFile::clear() {
_sections.clear();
}

bool ConfigFile::loadFromFile(const String &filename) {
bool INIFile::loadFromFile(const String &filename) {
File file;
if (file.open(filename))
return loadFromStream(file);
else
return false;
}

bool ConfigFile::loadFromSaveFile(const char *filename) {
bool INIFile::loadFromSaveFile(const char *filename) {
assert(g_system);
SaveFileManager *saveFileMan = g_system->getSavefileManager();
SeekableReadStream *loadFile;
Expand All @@ -67,7 +67,7 @@ bool ConfigFile::loadFromSaveFile(const char *filename) {
return status;
}

bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
bool INIFile::loadFromStream(SeekableReadStream &stream) {
Section section;
KeyValue kv;
String comment;
Expand Down Expand Up @@ -112,9 +112,9 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
p++;

if (*p == '\0')
error("ConfigFile::loadFromStream: missing ] in line %d", lineno);
error("INIFile::loadFromStream: missing ] in line %d", lineno);
else if (*p != ']')
error("ConfigFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno);
error("INIFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno);

// Previous section is finished now, store it.
if (!section.name.empty())
Expand All @@ -140,7 +140,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {

// If no section has been set, this config file is invalid!
if (section.name.empty()) {
error("ConfigFile::loadFromStream: Key/value pair found outside a section in line %d", lineno);
error("INIFile::loadFromStream: Key/value pair found outside a section in line %d", lineno);
}

// Split string at '=' into 'key' and 'value'. First, find the "=" delimeter.
Expand Down Expand Up @@ -173,15 +173,15 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
return (!stream.err() || stream.eos());
}

bool ConfigFile::saveToFile(const String &filename) {
bool INIFile::saveToFile(const String &filename) {
DumpFile file;
if (file.open(filename))
return saveToStream(file);
else
return false;
}

bool ConfigFile::saveToSaveFile(const char *filename) {
bool INIFile::saveToSaveFile(const char *filename) {
assert(g_system);
SaveFileManager *saveFileMan = g_system->getSavefileManager();
WriteStream *saveFile;
Expand All @@ -195,7 +195,7 @@ bool ConfigFile::saveToSaveFile(const char *filename) {
return status;
}

bool ConfigFile::saveToStream(WriteStream &stream) {
bool INIFile::saveToStream(WriteStream &stream) {
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
// Write out the section comment, if any
if (! i->comment.empty()) {
Expand Down Expand Up @@ -226,7 +226,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) {
return !stream.err();
}

void ConfigFile::addSection(const String &section) {
void INIFile::addSection(const String &section) {
Section *s = getSection(section);
if (s)
return;
Expand All @@ -236,7 +236,7 @@ void ConfigFile::addSection(const String &section) {
_sections.push_back(newSection);
}

void ConfigFile::removeSection(const String &section) {
void INIFile::removeSection(const String &section) {
assert(isValidName(section));
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
if (section.equalsIgnoreCase(i->name)) {
Expand All @@ -246,13 +246,13 @@ void ConfigFile::removeSection(const String &section) {
}
}

bool ConfigFile::hasSection(const String &section) const {
bool INIFile::hasSection(const String &section) const {
assert(isValidName(section));
const Section *s = getSection(section);
return s != 0;
}

void ConfigFile::renameSection(const String &oldName, const String &newName) {
void INIFile::renameSection(const String &oldName, const String &newName) {
assert(isValidName(oldName));
assert(isValidName(newName));

Expand All @@ -262,7 +262,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) {
// HACK: For now we just print a warning, for more info see the TODO
// below.
if (ns)
warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str());
warning("INIFile::renameSection: Section name \"%s\" already used", newName.c_str());
else
os->name = newName;
}
Expand All @@ -274,7 +274,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) {
}


bool ConfigFile::hasKey(const String &key, const String &section) const {
bool INIFile::hasKey(const String &key, const String &section) const {
assert(isValidName(key));
assert(isValidName(section));

Expand All @@ -284,7 +284,7 @@ bool ConfigFile::hasKey(const String &key, const String &section) const {
return s->hasKey(key);
}

void ConfigFile::removeKey(const String &key, const String &section) {
void INIFile::removeKey(const String &key, const String &section) {
assert(isValidName(key));
assert(isValidName(section));

Expand All @@ -293,7 +293,7 @@ void ConfigFile::removeKey(const String &key, const String &section) {
s->removeKey(key);
}

bool ConfigFile::getKey(const String &key, const String &section, String &value) const {
bool INIFile::getKey(const String &key, const String &section, String &value) const {
assert(isValidName(key));
assert(isValidName(section));

Expand All @@ -307,7 +307,7 @@ bool ConfigFile::getKey(const String &key, const String &section, String &value)
return true;
}

void ConfigFile::setKey(const String &key, const String &section, const String &value) {
void INIFile::setKey(const String &key, const String &section, const String &value) {
assert(isValidName(key));
assert(isValidName(section));
// TODO: Verify that value is valid, too. In particular, it shouldn't
Expand All @@ -329,13 +329,13 @@ void ConfigFile::setKey(const String &key, const String &section, const String &
}
}

const ConfigFile::SectionKeyList ConfigFile::getKeys(const String &section) const {
const INIFile::SectionKeyList INIFile::getKeys(const String &section) const {
const Section *s = getSection(section);

return s->getKeys();
}

ConfigFile::Section *ConfigFile::getSection(const String &section) {
INIFile::Section *INIFile::getSection(const String &section) {
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
if (section.equalsIgnoreCase(i->name)) {
return &(*i);
Expand All @@ -344,7 +344,7 @@ ConfigFile::Section *ConfigFile::getSection(const String &section) {
return 0;
}

const ConfigFile::Section *ConfigFile::getSection(const String &section) const {
const INIFile::Section *INIFile::getSection(const String &section) const {
for (List<Section>::const_iterator i = _sections.begin(); i != _sections.end(); ++i) {
if (section.equalsIgnoreCase(i->name)) {
return &(*i);
Expand All @@ -353,11 +353,11 @@ const ConfigFile::Section *ConfigFile::getSection(const String &section) const {
return 0;
}

bool ConfigFile::Section::hasKey(const String &key) const {
bool INIFile::Section::hasKey(const String &key) const {
return getKey(key) != 0;
}

const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const {
const INIFile::KeyValue* INIFile::Section::getKey(const String &key) const {
for (List<KeyValue>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
if (key.equalsIgnoreCase(i->key)) {
return &(*i);
Expand All @@ -366,7 +366,7 @@ const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const
return 0;
}

void ConfigFile::Section::setKey(const String &key, const String &value) {
void INIFile::Section::setKey(const String &key, const String &value) {
for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) {
if (key.equalsIgnoreCase(i->key)) {
i->value = value;
Expand All @@ -380,7 +380,7 @@ void ConfigFile::Section::setKey(const String &key, const String &value) {
keys.push_back(newKV);
}

void ConfigFile::Section::removeKey(const String &key) {
void INIFile::Section::removeKey(const String &key) {
for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) {
if (key.equalsIgnoreCase(i->key)) {
keys.erase(i);
Expand Down
16 changes: 8 additions & 8 deletions common/config-file.h → common/ini-file.h
Expand Up @@ -20,8 +20,8 @@
*
*/

#ifndef COMMON_CONFIG_FILE_H
#define COMMON_CONFIG_FILE_H
#ifndef COMMON_INI_FILE_H
#define COMMON_INI_FILE_H

#include "common/hash-str.h"
#include "common/list.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ class WriteStream;
* If you need fast access to the game config, use higher level APIs, like the
* one provided by ConfigManager.
*/
class ConfigFile {
class INIFile {
public:
struct KeyValue {
String key;
Expand All @@ -60,12 +60,12 @@ class ConfigFile {

typedef List<KeyValue> SectionKeyList;

/** A section in a config file. I.e. corresponds to something like this:
/** A section in a ini file. I.e. corresponds to something like this:
* [mySection]
* key=value
*
* Comments are also stored, to keep users happy who like editing their
* config files manually.
* ini files manually.
*/
struct Section {
String name;
Expand All @@ -82,8 +82,8 @@ class ConfigFile {
typedef List<Section> SectionList;

public:
ConfigFile();
~ConfigFile();
INIFile();
~INIFile();

// TODO: Maybe add a copy constructor etc.?

Expand All @@ -95,7 +95,7 @@ class ConfigFile {
*/
static bool isValidName(const String &name);

/** Reset everything stored in this config file. */
/** Reset everything stored in this ini file. */
void clear();

bool loadFromFile(const String &filename);
Expand Down
2 changes: 1 addition & 1 deletion common/module.mk
Expand Up @@ -2,7 +2,6 @@ MODULE := common

MODULE_OBJS := \
archive.o \
config-file.o \
config-manager.o \
coroutines.o \
dcl.o \
Expand All @@ -15,6 +14,7 @@ MODULE_OBJS := \
gui_options.o \
hashmap.o \
iff_container.o \
ini-file.o \
installshield_cab.o \
language.o \
localization.o \
Expand Down
4 changes: 2 additions & 2 deletions engines/composer/composer.h
Expand Up @@ -23,7 +23,7 @@
#ifndef COMPOSER_H
#define COMPOSER_H

#include "common/config-file.h"
#include "common/ini-file.h"
#include "common/random.h"
#include "common/system.h"
#include "common/debug.h"
Expand Down Expand Up @@ -174,7 +174,7 @@ class ComposerEngine : public Engine {
Common::List<Sprite> _sprites;

uint _directoriesToStrip;
Common::ConfigFile _bookIni;
Common::INIFile _bookIni;
Common::String _bookGroup;
Common::List<Library> _libraries;
Common::Array<PendingPageChange> _pendingPageChanges;
Expand Down
4 changes: 2 additions & 2 deletions engines/gob/iniconfig.cpp
Expand Up @@ -73,7 +73,7 @@ bool INIConfig::getConfig(const Common::String &file, Config &config) {
}

bool INIConfig::openConfig(const Common::String &file, Config &config) {
config.config = new Common::ConfigFile();
config.config = new Common::INIFile();
config.created = false;

if (!config.config->loadFromFile(file)) {
Expand All @@ -89,7 +89,7 @@ bool INIConfig::openConfig(const Common::String &file, Config &config) {
}

bool INIConfig::createConfig(const Common::String &file, Config &config) {
config.config = new Common::ConfigFile();
config.config = new Common::INIFile();
config.created = true;

_configs.setVal(file, config);
Expand Down
4 changes: 2 additions & 2 deletions engines/gob/iniconfig.h
Expand Up @@ -24,7 +24,7 @@
#define GOB_INICONFIG_H

#include "common/str.h"
#include "common/config-file.h"
#include "common/ini-file.h"
#include "common/hashmap.h"

namespace Gob {
Expand All @@ -43,7 +43,7 @@ class INIConfig {

private:
struct Config {
Common::ConfigFile *config;
Common::INIFile *config;
bool created;
};

Expand Down
4 changes: 2 additions & 2 deletions engines/mohawk/livingbooks.cpp
Expand Up @@ -311,8 +311,8 @@ void MohawkEngine_LivingBooks::loadBookInfo(const Common::String &filename) {
// - fDebugWindow (always 0?)

if (_bookInfoFile.hasSection("Globals")) {
const Common::ConfigFile::SectionKeyList globals = _bookInfoFile.getKeys("Globals");
for (Common::ConfigFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
const Common::INIFile::SectionKeyList globals = _bookInfoFile.getKeys("Globals");
for (Common::INIFile::SectionKeyList::const_iterator i = globals.begin(); i != globals.end(); i++) {
Common::String command = Common::String::format("%s = %s", i->key.c_str(), i->value.c_str());
LBCode tempCode(this, 0);
uint offset = tempCode.parseCode(command);
Expand Down

0 comments on commit 63750d6

Please sign in to comment.