configFile.cpp 2.1 KB

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