You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.5 KiB

  1. #include <windows.h>
  2. #include <iostream>
  3. #include <set>
  4. #include "logger.hpp"
  5. #include "zcsv.hpp"
  6. using namespace iflytop;
  7. using namespace std;
  8. #define TAG "Main"
  9. #define TRY_INSERT_DEFALUT_VALUE(key, value) \
  10. if (zcsv->getData(key, i).empty() || zcsv->getData(key, i) == "NA") { \
  11. file << "define_attribute {p:" << PORT << "} {" << key << "} {" << value << "}" << endl; \
  12. }
  13. char projFileName_cstr[128] = {0};
  14. int domain(int argc, char const* argv[]) {
  15. // // 搜索当前文件夹,找到*.pds文件
  16. WIN32_FIND_DATAA FindFileData;
  17. HANDLE hFind = FindFirstFileA("*.pds", &FindFileData);
  18. if (hFind == INVALID_HANDLE_VALUE) {
  19. ZLOGE(TAG, "find file failed");
  20. return -1;
  21. }
  22. strcpy(projFileName_cstr, FindFileData.cFileName);
  23. FindClose(hFind);
  24. string projFileName = projFileName_cstr;
  25. string projectName;
  26. string pinCsvFileName;
  27. string fdcFileName;
  28. size_t pos = projFileName.find_last_of(".");
  29. if (pos == string::npos) {
  30. projectName = projFileName;
  31. } else {
  32. projectName = projFileName.substr(0, pos);
  33. }
  34. pinCsvFileName = projectName + ".csv";
  35. fdcFileName = projectName + ".fdc";
  36. ZLOGI(TAG, "fdc file:%s", fdcFileName.c_str());
  37. // 打开fdc文件,并逐行解析下面字符串,
  38. // 如下解析出如果是define_attribute,则 rowName:ex_clk, colName:PAP_IO_DIRECTION, data:INPUT
  39. // define_attribute {p:ex_clk} {PAP_IO_DIRECTION} {INPUT}
  40. shared_ptr<ZCSV> zcsv = make_shared<ZCSV>();
  41. fstream file(fdcFileName, ios::in);
  42. if (!file.is_open()) {
  43. ZLOGE(TAG, "open fdc file failed");
  44. return -1;
  45. }
  46. string line;
  47. while (getline(file, line)) {
  48. if (line.find("define_attribute") != string::npos) {
  49. string rowName;
  50. string colName;
  51. string data;
  52. size_t pos1 = line.find("{p:");
  53. size_t pos2 = line.find("}", pos1);
  54. rowName = line.substr(pos1 + 3, pos2 - pos1 - 3);
  55. pos1 = line.find("{", pos2);
  56. pos2 = line.find("}", pos1);
  57. colName = line.substr(pos1 + 1, pos2 - pos1 - 1);
  58. pos1 = line.find("{", pos2);
  59. pos2 = line.find("}", pos1);
  60. data = line.substr(pos1 + 1, pos2 - pos1 - 1);
  61. ZLOGI(TAG, "rowName:%s, colName:%s, data:%s", rowName.c_str(), colName.c_str(), data.c_str());
  62. zcsv->setData(rowName, colName, data);
  63. }
  64. }
  65. zcsv->setdata(0, 0, "PORT");
  66. zcsv->dumpCSV(pinCsvFileName);
  67. ZLOGI(TAG, "fdc2csv success...");
  68. return 0;
  69. }
  70. int main(int argc, char const* argv[]) {
  71. domain(argc, argv);
  72. Sleep(3000);
  73. }