MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / loadKeyNames

Function loadKeyNames

TheForceEngine/TFE_Input/input.cpp:389–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387 }
388
389 bool loadKeyNames(const char* path)
390 {
391 FileStream file;
392 if (!file.open(path, Stream::MODE_READ))
393 {
394 return false;
395 }
396
397 // Read the file into memory.
398 const size_t len = file.getSize();
399 char* contents = new char[len+1];
400 if (!contents)
401 {
402 file.close();
403 return false;
404 }
405 file.readBuffer(contents, (u32)len);
406 file.close();
407
408 TFE_Parser parser;
409 parser.init(contents, len);
410 parser.addCommentString(";");
411 parser.addCommentString("#");
412 parser.addCommentString("//");
413
414 size_t bufferPos = 0;
415 enum KeySection
416 {
417 Unknown = 0,
418 ControllerAxis,
419 ControllerButtons,
420 MouseAxis,
421 MouseButtons,
422 MouseWheelAxis,
423 Keyboard,
424 };
425
426 KeySection section = Unknown;
427 char** curList = nullptr;
428 while (bufferPos < len)
429 {
430 const char* line = parser.readLine(bufferPos);
431 if (!line) { break; }
432
433 TokenList tokens;
434 parser.tokenizeLine(line, tokens);
435 if (tokens.size() < 1) { continue; }
436 const char* item = tokens[0].c_str();
437
438 if (strcasecmp(item, "[ControllerAxis]") == 0)
439 {
440 section = ControllerAxis;
441 s_controllerAxisNames = new const char*[AXIS_COUNT];
442 curList = (char**)s_controllerAxisNames;
443 }
444 else if (strcasecmp(item, "[ControllerButtons]") == 0)
445 {
446 section = ControllerButtons;

Callers 1

mainFunction · 0.85

Calls 11

logWriteFunction · 0.85
addCommentStringMethod · 0.80
readLineMethod · 0.80
tokenizeLineMethod · 0.80
c_strMethod · 0.80
openMethod · 0.45
getSizeMethod · 0.45
closeMethod · 0.45
readBufferMethod · 0.45
initMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected