Skip to content

Commit

Permalink
fix: save history file on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hakan-demirli committed Jan 31, 2024
1 parent 820232e commit dd5dc06
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions kernel/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down

0 comments on commit dd5dc06

Please sign in to comment.