MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / Load

Method Load

src/openboardview/confparse.cpp:240–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240int Confparse::Load(const filesystem::path &filepath, bool save_default) {
241 ifstream file;
242 file.open(filepath, std::ios::in | std::ios::binary | std::ios::ate);
243 if (!file.is_open()) {
244 // std::cerr << "Error opening " << filepath.string() << ": " <<
245 // strerror(errno) << std::endl;
246 buffer_size = 0;
247 conf = NULL;
248 if (nested) return 1; // to prevent infinite recursion, we test the nested flag
249 if (save_default) { // Create file with default OBV configuration
250 return (SaveDefault(filepath));
251 } else { // Create empty file
252 ofstream file;
253 file.open(filepath, std::ios::out | std::ios::binary | std::ios::ate);
254 nested = true;
255 file.close();
256 return Load(filepath);
257 }
258 }
259
260 this->filepath = filepath;
261
262 if (conf) free(conf);
263
264 std::streampos sz = file.tellg();
265 buffer_size = sz;
266 conf = (char *)calloc(1, buffer_size + 1);
267 file.seekg(0, std::ios::beg);
268 file.read(conf, sz);
269 limit = conf + sz;
270 file.close();
271
272 if (file.gcount() != sz) {
273 std::cerr << "Did not read the right number of bytes from configuration file " << file.gcount() << " != " << sz << std::endl;
274 return 1;
275 }
276 // assert(file.gcount() == sz);
277 //
278 //
279
280 nested = false;
281
282 return 0;
283}
284
285char *Confparse::Parse(const char *key) {
286 char *p, *op;

Callers

nothing calls this directly

Calls 1

closeMethod · 0.80

Tested by

no test coverage detected