configFile.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <string.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "Helper.h"
  5. #include "configFile.h"
  6. ConfigFile::ConfigFile(std::string filePath)
  7. {
  8. std::string config = FormatFileName(filePath);
  9. pFile = OpenFileAndWait(config.c_str(), "r");
  10. }
  11. ConfigFile::~ConfigFile()
  12. {
  13. fclose(pFile);
  14. }
  15. bool ConfigFile::isNewParagraph(std::string input)
  16. {
  17. if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '[')))
  18. {
  19. return true;
  20. }
  21. return false;
  22. }
  23. bool ConfigFile::GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof)
  24. {
  25. while (getNextLine(&aktparamgraph, disabled, eof) && !isNewParagraph(aktparamgraph));
  26. if (isNewParagraph(aktparamgraph))
  27. return true;
  28. return false;
  29. }
  30. bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof)
  31. {
  32. eof = false;
  33. char zw[1024];
  34. if (pFile == NULL)
  35. {
  36. *rt = "";
  37. return false;
  38. }
  39. fgets(zw, 1024, pFile);
  40. printf("%s", zw);
  41. if ((strlen(zw) == 0) && feof(pFile))
  42. {
  43. *rt = "";
  44. eof = true;
  45. return false;
  46. }
  47. *rt = zw;
  48. *rt = trim(*rt);
  49. while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
  50. {
  51. fgets(zw, 1024, pFile);
  52. printf("%s", zw);
  53. if (feof(pFile))
  54. {
  55. *rt = "";
  56. eof = true;
  57. return false;
  58. }
  59. *rt = zw;
  60. *rt = trim(*rt);
  61. }
  62. disabled = ((*rt)[0] == ';');
  63. return true;
  64. }
  65. std::vector<string> ConfigFile::ZerlegeZeile(std::string input, std::string delimiter)
  66. {
  67. std::vector<string> Output;
  68. // std::string delimiter = " =,";
  69. input = trim(input, delimiter);
  70. size_t pos = findDelimiterPos(input, delimiter);
  71. std::string token;
  72. while (pos != std::string::npos) {
  73. token = input.substr(0, pos);
  74. token = trim(token, delimiter);
  75. Output.push_back(token);
  76. input.erase(0, pos + 1);
  77. input = trim(input, delimiter);
  78. pos = findDelimiterPos(input, delimiter);
  79. }
  80. Output.push_back(input);
  81. return Output;
  82. }