configFile.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. fgets(zw, 1024, pFile);
  41. printf("%s", zw);
  42. if ((strlen(zw) == 0) && feof(pFile))
  43. {
  44. *rt = "";
  45. eof = true;
  46. return false;
  47. }
  48. *rt = zw;
  49. *rt = trim(*rt);
  50. while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
  51. {
  52. fgets(zw, 1024, pFile);
  53. printf("%s", zw);
  54. if (feof(pFile))
  55. {
  56. *rt = "";
  57. eof = true;
  58. return false;
  59. }
  60. *rt = zw;
  61. *rt = trim(*rt);
  62. }
  63. disabled = ((*rt)[0] == ';');
  64. return true;
  65. }
  66. std::vector<string> ConfigFile::ZerlegeZeile(std::string input, std::string delimiter)
  67. {
  68. std::vector<string> Output;
  69. // std::string delimiter = " =,";
  70. input = trim(input, delimiter);
  71. size_t pos = findDelimiterPos(input, delimiter);
  72. std::string token;
  73. while (pos != std::string::npos) {
  74. token = input.substr(0, pos);
  75. token = trim(token, delimiter);
  76. Output.push_back(token);
  77. input.erase(0, pos + 1);
  78. input = trim(input, delimiter);
  79. pos = findDelimiterPos(input, delimiter);
  80. }
  81. Output.push_back(input);
  82. return Output;
  83. }