summaryrefslogtreecommitdiff
path: root/icetime/icetime.cc
diff options
context:
space:
mode:
authorRuben Undheim <ruben.undheim@gmail.com>2018-12-05 08:24:49 +0100
committerRuben Undheim <ruben.undheim@gmail.com>2018-12-05 08:24:49 +0100
commit8cdaf84defddf5a7bd1c4551ece81b9d832e4595 (patch)
tree633fb613368bc4d1f26a63fc5142b4de3a9b6cc5 /icetime/icetime.cc
parente515d7ff6e4e71b3e5fe6b264427029f2e3c9e72 (diff)
parent8cbb9960214d27e06e6e69c57e77f4178dcfe36b (diff)
Merge tag 'upstream/0_20181109git9671b76'
Upstream version 0~20181109git9671b76
Diffstat (limited to 'icetime/icetime.cc')
-rw-r--r--icetime/icetime.cc35
1 files changed, 10 insertions, 25 deletions
diff --git a/icetime/icetime.cc b/icetime/icetime.cc
index 35ce99a..a5a27a0 100644
--- a/icetime/icetime.cc
+++ b/icetime/icetime.cc
@@ -38,6 +38,8 @@
#include <emscripten.h>
#endif
+std::string find_chipdb(std::string config_device);
+
// add this number of ns as estimate for clock distribution mismatch
#define GLOBAL_CLK_DIST_JITTER 0.1
@@ -322,35 +324,18 @@ void read_config()
void read_chipdb()
{
char buffer[1024];
+ std::string filepath = chipdbfile;
- if (!chipdbfile.empty()) {
- snprintf(buffer, 1024, "%s", chipdbfile.c_str());
- } else
- if (PREFIX[0] == '~' && PREFIX[1] == '/') {
- std::string homedir;
-#ifdef _WIN32
- if (getenv("USERPROFILE") != nullptr) {
- homedir += getenv("USERPROFILE");
- }
- else {
- if (getenv("HOMEDRIVE") != nullptr &&
- getenv("HOMEPATH") != nullptr) {
- homedir += getenv("HOMEDRIVE");
- homedir += getenv("HOMEPATH");
- }
- }
-#else
- homedir += getenv("HOME");
-#endif
- snprintf(buffer, 1024, "%s%s/share/" CHIPDB_SUBDIR "/chipdb-%s.txt", homedir.c_str(), PREFIX+1, config_device.c_str());
- } else {
- snprintf(buffer, 1024, PREFIX "/share/" CHIPDB_SUBDIR "/chipdb-%s.txt", config_device.c_str());
+ if (filepath.empty())
+ filepath = find_chipdb(config_device);
+ if (filepath.empty()) {
+ fprintf(stderr, "Can't find chipdb file for device %s\n", config_device.c_str());
+ exit(1);
}
- FILE *fdb = fopen(buffer, "r");
+ FILE *fdb = fopen(filepath.c_str(), "r");
if (fdb == nullptr) {
perror("Can't open chipdb file");
- fprintf(stderr, " %s\n", buffer);
exit(1);
}
@@ -1320,7 +1305,7 @@ std::string ecnetname_to_vlog(std::string ec_name)
} else {
return ec_name;
}
- } catch(std::invalid_argument e) { // Not numeric and stoi throws exception
+ } catch(std::invalid_argument &e) { // Not numeric and stoi throws exception
return ec_name;
}