mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
config no longer uses stl
This commit is contained in:
parent
25ec379695
commit
2497456684
|
@ -1,17 +1,17 @@
|
||||||
#include <baselib/system.h>
|
#include <baselib/system.h>
|
||||||
|
#include <baselib/stream/file.h>
|
||||||
#include <fstream>
|
#include <baselib/stream/line.h>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
configuration config;
|
configuration config;
|
||||||
|
|
||||||
|
using namespace baselib;
|
||||||
|
|
||||||
void config_reset()
|
void config_reset()
|
||||||
{
|
{
|
||||||
#define MACRO_CONFIG_INT(name,def,min,max) config.name = def;
|
#define MACRO_CONFIG_INT(name,def,min,max) config.name = def;
|
||||||
|
@ -25,7 +25,7 @@ void config_reset()
|
||||||
|
|
||||||
void config_set(const char *line)
|
void config_set(const char *line)
|
||||||
{
|
{
|
||||||
char var_str[128];
|
char var_str[256];
|
||||||
char *val_str = strchr(line, '=');
|
char *val_str = strchr(line, '=');
|
||||||
if (val_str)
|
if (val_str)
|
||||||
{
|
{
|
||||||
|
@ -47,13 +47,15 @@ void config_load(const char *filename)
|
||||||
{
|
{
|
||||||
dbg_msg("config/load", "loading %s", filename);
|
dbg_msg("config/load", "loading %s", filename);
|
||||||
|
|
||||||
ifstream file(filename);
|
file_stream file;
|
||||||
string line;
|
|
||||||
|
|
||||||
if (file)
|
if (file.open_r(filename))
|
||||||
{
|
{
|
||||||
while (getline(file, line))
|
char *line;
|
||||||
config_set(line.c_str());
|
line_stream lstream(&file);
|
||||||
|
|
||||||
|
while ((line = lstream.get_line()))
|
||||||
|
config_set(line);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
@ -63,17 +65,21 @@ void config_save(const char *filename)
|
||||||
{
|
{
|
||||||
dbg_msg("config/save", "saving config to %s", filename);
|
dbg_msg("config/save", "saving config to %s", filename);
|
||||||
|
|
||||||
ofstream file(filename);
|
file_stream file;
|
||||||
|
|
||||||
#define MACRO_CONFIG_INT(name,def,min,max) { file << # name << '=' << config.name << endl; }
|
if (file.open_w(filename))
|
||||||
#define MACRO_CONFIG_STR(name,len,def) { file << # name << '=' << config.name << endl; }
|
{
|
||||||
|
|
||||||
|
#define MACRO_CONFIG_INT(name,def,min,max) { char str[256]; sprintf(str, "%s=%i", #name, config.name); file.write(str, strlen(str)); file.write("\n", 1); }
|
||||||
|
#define MACRO_CONFIG_STR(name,len,def) { file.write(#name, strlen(#name)); file.write("=", 1); file.write(config.name, strlen(config.name)); file.write("\n", 1); }
|
||||||
|
|
||||||
#include "config_variables.h"
|
#include "config_variables.h"
|
||||||
|
|
||||||
#undef MACRO_CONFIG_INT
|
#undef MACRO_CONFIG_INT
|
||||||
#undef MACRO_CONFIG_STR
|
#undef MACRO_CONFIG_STR
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MACRO_CONFIG_INT(name,def,min,max) int config_get_ ## name (configuration *c) { return c->name; }
|
#define MACRO_CONFIG_INT(name,def,min,max) int config_get_ ## name (configuration *c) { return c->name; }
|
||||||
|
|
Loading…
Reference in a new issue