From f8a77abfac6da12e2e11c43b4e6aa6e613ac0d4b Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Mon, 22 Aug 2016 15:05:57 +0200 Subject: Added glob support to all front-ends --- kernel/register.cc | 16 ++++++++++++---- kernel/yosys.cc | 25 +++++++++++++++++++++++++ kernel/yosys.h | 1 + 3 files changed, 38 insertions(+), 4 deletions(-) (limited to 'kernel') diff --git a/kernel/register.cc b/kernel/register.cc index 115880ed6..7a1d0b44b 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -382,7 +382,8 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector filenames = glob_filename(filename); + filename = filenames.front(); + if (GetSize(filenames) > 1) { + next_args.insert(next_args.end(), args.begin(), args.begin()+argidx); + next_args.insert(next_args.end(), filenames.begin()+1, filenames.end()); + } std::ifstream *ff = new std::ifstream; ff->open(filename.c_str()); if (ff->fail()) @@ -434,12 +441,13 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector # include # include +# include #else # include # include # include # include +# include #endif #include @@ -547,6 +549,29 @@ const char *create_prompt(RTLIL::Design *design, int recursion_counter) return buffer; } +std::vector glob_filename(const std::string &filename_pattern) +{ + std::vector results; + +#ifdef _WIN32 + results.push_back(filename_pattern); +#else + glob_t globbuf; + + int err = glob(filename_pattern.c_str(), 0, NULL, &globbuf); + + if(err == 0) { + for (size_t i = 0; i < globbuf.gl_pathc; i++) + results.push_back(globbuf.gl_pathv[i]); + globfree(&globbuf); + } else { + results.push_back(filename_pattern); + } +#endif + + return results; +} + void rewrite_filename(std::string &filename) { if (filename.substr(0, 1) == "\"" && filename.substr(GetSize(filename)-1) == "\"") diff --git a/kernel/yosys.h b/kernel/yosys.h index 0df750a13..aab6b5844 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -280,6 +280,7 @@ RTLIL::Design *yosys_get_design(); std::string proc_self_dirname(); std::string proc_share_dirname(); const char *create_prompt(RTLIL::Design *design, int recursion_counter); +std::vector glob_filename(const std::string &filename_pattern); void rewrite_filename(std::string &filename); void run_pass(std::string command, RTLIL::Design *design = nullptr); -- cgit v1.2.3