10 FILE *
f = fopen(fName,
"r");
19 std::vector < char >paramName;
20 std::vector < char >paramValue;
21 bool sectionFill =
false;
22 bool paramFill =
false;
23 bool valueFill =
false;
24 bool checkSimple =
false;
25 bool isSimple =
false;
33 int readCount = fread(&leter,
sizeof(
char), 1, f);
44 sectionName.push_back(0);
49 if (!sectionFill && leter !=
' ')
51 sectionName.push_back(leter);
57 if (leter !=
' ' && leter !=
'\n')
61 paramName.push_back(leter);
66 paramName.push_back(0);
73 if (!valueFill && paramFill)
93 paramValue[paramValue.size() - 1] = 0;
94 paramValue.push_back(0);
95 createRecord(§ionName, ¶mName, ¶mValue);
102 paramValue.push_back(leter);
112 paramValue.push_back(0);
113 createRecord(§ionName, ¶mName, ¶mValue);
120 paramValue.push_back(leter);
128 if (paramValue.size() > 0)
130 paramValue.push_back(0);
132 createRecord(§ionName, ¶mName, ¶mValue);
140 for (
unsigned int i = 0; i < code.size(); i++)
149 for (
unsigned int i = 0; i < code.size(); i++)
151 printf(
"pair %s - %s\n", code[i], codeVal[i]);
157 const char *defValue)
159 char *findValue =
new char[strlen(sectionName) + strlen(paramName) + 1];
160 strcpy(findValue, sectionName);
161 strcat(findValue, paramName);
162 int index = getIndex(findValue);
166 value =
new char[strlen(defValue) + 1];
167 strcpy(value, defValue);
171 value =
new char[strlen(codeVal[index]) + 1];
172 strcpy(value, codeVal[index]);
181 char *findValue =
new char[strlen(sectionName) + strlen(paramName) + 1];
182 strcpy(findValue, sectionName);
183 strcat(findValue, paramName);
184 int index = getIndex(findValue);
192 value = atoi(codeVal[index]);
199 unsigned int &value,
unsigned int defValue)
201 char *findValue =
new char[strlen(sectionName) + strlen(paramName) + 1];
202 strcpy(findValue, sectionName);
203 strcat(findValue, paramName);
204 int index = getIndex(findValue);
212 value = (
unsigned int) atoi(codeVal[index]);
219 char *findValue =
new char[strlen (sectionName) + strlen (paramName) + 1];
220 strcpy (findValue, sectionName);
221 strcat (findValue, paramName);
222 int index = getIndex (findValue);
230 value = (u_int64_t)atoll (codeVal[index]);
238 char *findValue =
new char[strlen(sectionName) + strlen(paramName) + 1];
239 strcpy(findValue, sectionName);
240 strcat(findValue, paramName);
241 int index = getIndex(findValue);
249 value = atoi(codeVal[index]);
257 char *findValue =
new char[strlen(sectionName) + strlen(paramName) + 1];
258 strcpy(findValue, sectionName);
259 strcat(findValue, paramName);
260 int index = getIndex(findValue);
268 value = atof(codeVal[index]);
275 std::vector < char *>sectionParams;
276 sectionParams.clear();
279 for (
unsigned int i = 0; i < code.size(); i++)
281 if (findSection(code[i], sectionName, pos))
284 char *paramName =
new char[strlen(code[i])];
285 char *paramValue =
new char[strlen(codeVal[i]) + 1];
286 strcpy(paramValue, codeVal[i]);
287 strcpy(paramName, code[i] + pos);
288 sectionParams.push_back(paramName);
289 sectionParams.push_back(paramValue);
294 values1 =
new char *[size];
295 for (
unsigned int i = 0; i < sectionParams.size(); i += 2)
297 values1[i] =
new char[strlen(sectionParams[i]) + 1];
298 strcpy(values1[i], sectionParams[i]);
299 values1[i + 1] =
new char[strlen(sectionParams[i + 1]) + 1];
300 strcpy(values1[i + 1], sectionParams[i + 1]);
301 delete[]sectionParams[i];
302 delete[]sectionParams[i + 1];
313 void Config::createRecord(std::vector < char >*
sectionName,
314 std::vector < char >*paramName,
315 std::vector < char >*paramValue)
317 if (sectionName->size() && paramName->size() && paramValue->size())
319 char *
key =
new char[sectionName->size() + paramName->size() + 1];
320 char *value =
new char[paramValue->size() + 1];
321 strcpy(key, &(*sectionName)[0]);
322 strcat(key, &(*paramName)[0]);
323 strcpy(value, &(*paramValue)[0]);
325 codeVal.push_back(value);
331 int Config::getIndex(
char *value)
333 for (
unsigned int i = 0; i < code.size(); i++)
335 if (strcmp(code[i], value) == 0)
343 bool Config::findSection(
const char *codeValue,
const char *sectionName,
int &pos)
346 while (*(sectionName + pos))
348 if (codeValue[pos] == 0 || sectionName[pos] != codeValue[pos])