mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +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 <fstream>
|
||||
#include <iostream>
|
||||
#include <baselib/stream/file.h>
|
||||
#include <baselib/stream/line.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
configuration config;
|
||||
|
||||
using namespace baselib;
|
||||
|
||||
void config_reset()
|
||||
{
|
||||
#define MACRO_CONFIG_INT(name,def,min,max) config.name = def;
|
||||
|
@ -25,7 +25,7 @@ void config_reset()
|
|||
|
||||
void config_set(const char *line)
|
||||
{
|
||||
char var_str[128];
|
||||
char var_str[256];
|
||||
char *val_str = strchr(line, '=');
|
||||
if (val_str)
|
||||
{
|
||||
|
@ -47,13 +47,15 @@ void config_load(const char *filename)
|
|||
{
|
||||
dbg_msg("config/load", "loading %s", filename);
|
||||
|
||||
ifstream file(filename);
|
||||
string line;
|
||||
file_stream file;
|
||||
|
||||
if (file)
|
||||
if (file.open_r(filename))
|
||||
{
|
||||
while (getline(file, line))
|
||||
config_set(line.c_str());
|
||||
char *line;
|
||||
line_stream lstream(&file);
|
||||
|
||||
while ((line = lstream.get_line()))
|
||||
config_set(line);
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
@ -63,17 +65,21 @@ void config_save(const char *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; }
|
||||
#define MACRO_CONFIG_STR(name,len,def) { file << # name << '=' << config.name << endl; }
|
||||
if (file.open_w(filename))
|
||||
{
|
||||
|
||||
#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_STR
|
||||
#undef MACRO_CONFIG_INT
|
||||
#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; }
|
||||
|
|
Loading…
Reference in a new issue