From dd5dc06863d0e9fe76ff0d2f4cffbe9869bfa92f Mon Sep 17 00:00:00 2001 From: hakan-demirli Date: Wed, 31 Jan 2024 20:14:32 +0300 Subject: [PATCH] fix: save history file on windows --- kernel/driver.cc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/kernel/driver.cc b/kernel/driver.cc index 5f105ea03..a5201464d 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -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")))