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.
56 lines
1.7 KiB
56 lines
1.7 KiB
#include "util.h"
|
|
|
|
std::array<std::vector<std::string>, 5> read_csv(const std::string& filename) {
|
|
std::array<std::vector<std::string>, 5> array_vectors;
|
|
std::vector<std::string> vec_cmd_get;
|
|
std::vector<std::string> vec_cmd_set_true;
|
|
std::vector<std::string> vec_cmd_set_false;
|
|
std::vector<std::string> vec_option;
|
|
std::vector<std::string> vec_opcision;
|
|
std::ifstream file(filename);
|
|
std::string line;
|
|
char delimiter = ',';
|
|
getline(file, line);
|
|
while (std::getline(file, line)) {
|
|
std::stringstream stream(line);
|
|
std::string cmd_get;
|
|
std::string cmd_set_true;
|
|
std::string cmd_set_false;
|
|
std::string option;
|
|
std::string opcision;
|
|
getline(stream, cmd_get, delimiter);
|
|
getline(stream, cmd_set_true, delimiter);
|
|
getline(stream, cmd_set_false, delimiter);
|
|
getline(stream, option, delimiter);
|
|
getline(stream, opcision, delimiter);
|
|
vec_cmd_get.push_back(cmd_get);
|
|
vec_cmd_set_true.push_back(cmd_set_true);
|
|
vec_cmd_set_false.push_back(cmd_set_false);
|
|
vec_option.push_back(option);
|
|
vec_opcision.push_back(opcision);
|
|
}
|
|
array_vectors[0] = vec_cmd_get;
|
|
array_vectors[1] = vec_cmd_set_true;
|
|
array_vectors[2] = vec_cmd_set_false;
|
|
array_vectors[3] = vec_option;
|
|
array_vectors[4] = vec_opcision;
|
|
return array_vectors;
|
|
}
|
|
|
|
std::string call(std::string cmd) {
|
|
FILE *fp;
|
|
int status;
|
|
char path[PATH_MAX] = {0};
|
|
fp = popen(cmd.c_str(), "r");
|
|
if (fp == NULL) {
|
|
exit(1);
|
|
}
|
|
while (fgets(path, PATH_MAX, fp) != NULL) {
|
|
break;
|
|
}
|
|
status = pclose(fp);
|
|
if (status == -1) {
|
|
exit(1);
|
|
}
|
|
return path;
|
|
} |