Added glob support to all front-ends
This commit is contained in:
parent
450f6f59b4
commit
f8a77abfac
3 changed files with 38 additions and 4 deletions
|
@ -382,7 +382,8 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
|
|||
bool called_with_fp = f != NULL;
|
||||
|
||||
next_args.clear();
|
||||
for (; argidx < args.size(); argidx++)
|
||||
|
||||
if (argidx < args.size())
|
||||
{
|
||||
std::string arg = args[argidx];
|
||||
|
||||
|
@ -419,6 +420,12 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
|
|||
f = new std::istringstream(last_here_document);
|
||||
} else {
|
||||
rewrite_filename(filename);
|
||||
vector<string> 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<s
|
|||
cmd_error(args, i, "Found option, expected arguments.");
|
||||
|
||||
if (argidx+1 < args.size()) {
|
||||
next_args.insert(next_args.begin(), args.begin(), args.begin()+argidx);
|
||||
next_args.insert(next_args.begin()+argidx, args.begin()+argidx+1, args.end());
|
||||
if (next_args.empty())
|
||||
next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
|
||||
next_args.insert(next_args.end(), args.begin()+argidx+1, args.end());
|
||||
args.erase(args.begin()+argidx+1, args.end());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (f == NULL)
|
||||
cmd_error(args, argidx, "No filename given.");
|
||||
|
||||
|
|
|
@ -37,11 +37,13 @@
|
|||
# include <unistd.h>
|
||||
# include <dirent.h>
|
||||
# include <sys/stat.h>
|
||||
# include <glob.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <dirent.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <glob.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -547,6 +549,29 @@ const char *create_prompt(RTLIL::Design *design, int recursion_counter)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
std::vector<std::string> glob_filename(const std::string &filename_pattern)
|
||||
{
|
||||
std::vector<std::string> 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) == "\"")
|
||||
|
|
|
@ -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<std::string> glob_filename(const std::string &filename_pattern);
|
||||
void rewrite_filename(std::string &filename);
|
||||
|
||||
void run_pass(std::string command, RTLIL::Design *design = nullptr);
|
||||
|
|
Loading…
Add table
Reference in a new issue