fix: save history file on windows

This commit is contained in:
hakan-demirli 2024-01-31 20:14:32 +03:00
parent 820232eaca
commit dd5dc06863
1 changed files with 21 additions and 13 deletions

View File

@ -245,26 +245,34 @@ int main(int argc, char **argv)
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
std::string state_dir;
if (getenv("XDG_STATE_HOME") == NULL || getenv("XDG_STATE_HOME")[0] == '\0') {
if (getenv("HOME") != NULL) {
state_dir = stringf("%s/.local/state", getenv("HOME"));
}else {
log("$HOME is empty. No history file will be created.");
}
} else {
state_dir = stringf("%s", getenv("XDG_STATE_HOME"));
}
#if defined(_WIN32)
if (getenv("HOMEDRIVE") != NULL && getenv("HOMEPATH") != NULL) {
state_dir = stringf("%s%s/.local/state", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
} else {
log("$HOMEDRIVE and/or $HOMEPATH is empty. No history file will be created.");
}
#else
if (getenv("XDG_STATE_HOME") == NULL || getenv("XDG_STATE_HOME")[0] == '\0') {
if (getenv("HOME") != NULL) {
state_dir = stringf("%s/.local/state", getenv("HOME"));
} else {
log("$HOME is empty. No history file will be created.");
}
} else {
state_dir = stringf("%s", getenv("XDG_STATE_HOME"));
}
#endif
if (!state_dir.empty()) {
std::string yosys_dir = state_dir + "/yosys";
create_directory(yosys_dir);
create_directory(yosys_dir);
yosys_history_file = yosys_dir + "/history";
read_history(yosys_history_file.c_str());
yosys_history_offset = where_history();
}else {
log("state_dir is empty. No history file will be created.");
}
} else {
log("state_dir is empty. No history file will be created.");
}
#endif
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help") || !strcmp(argv[1], "--help")))