1 #include <drift/dslcore.h>
2 #include <drift/config.h>
3 #include <drift/config2.h>
4 #include <drift/GenLib.h>
11 bool long_comment =
false;
12 char buf[256] = { 0 };
14 const char * config = *pconfig;
15 while (*config != 0) {
16 const char * eol = strchr(config,
'\n');
18 size_t len = eol - config + 1;
23 config += strlen(config);
27 if (strlen(buf) < 3) {
33 while (strstr(buf,
" ")) {
40 if (!strcmp(buf,
"*/")) {
46 if (!strncmp(buf,
"/*", 2)) {
51 if (strnicmp(buf,
"#include ", 9) == 0) {
56 char *q = strchr(p,
'\"');
61 const char * tmpc = data.c_str();
64 printf(
"ERROR: Error loading #included file '%s'\n", p);
68 printf(
"ERROR: Error reading #included file '%s'\n", p);
72 printf(
"ERROR: Syntax is #include \"filename\"\n");
76 printf(
"ERROR: Syntax is #include \"filename\"\n");
82 if (buf[0] ==
'#' || !strncmp(buf,
"//", 2)) {
86 if (buf[0] ==
'[' && buf[strlen(buf)-1] ==
']') {
87 buf[strlen(buf) - 1] = 0;
90 sub = parent->FindOrAddSection(&buf[1]);
92 sub = FindOrAddSection(&buf[1]);
95 printf(
"ERROR: Error finding or creating section '%s'\n", &buf[1]);
104 char * value = strchr(buf,
'=');
111 if (buf[0] && value[0]) {
112 auto x = values.find(buf);
113 if (x != values.end()) {
114 x->second->ParseString(value);
117 tmpv->ParseString(value);
123 printf(
"Unrecognized line at %s:%zu -> %s\n", fn, line, buf);
131 void ConfigINI::writeSection(stringstream& sstr,
int level,
bool single)
const {
132 sstr <<
"[" << name <<
"]\n";
134 for (
auto& x : values) {
135 sstr << x.first <<
" = " << x.second->AsString() <<
"\n";
141 ConfigINI * ConfigINI::FindOrAddSection(
const string& name) {
142 auto sec = GetSection(name);
virtual bool loadFromString(const char **config, size_t &line, const char *fn)
DSL_API size_t DSL_CC strlcpy(char *dst, const char *src, size_t siz)
DSL_API_CLASS int DSL_CC str_replaceA(char *Str, size_t BufSize, const char *FindStr, const char *ReplStr)
Simple string replacement.
DSL_API char *DSL_CC strtrim(char *buf, const char *trim="\r\n\t ", uint8 sides=TRIM_BOTH)
DSL_API_CLASS bool DSL_CC file_get_contents(const string &fn, vector< uint8 > &data, int64 maxSize=INT32_MAX)