Added glob support to all front-ends
authorClifford Wolf <clifford@clifford.at>
Mon, 22 Aug 2016 13:05:57 +0000 (15:05 +0200)
committerClifford Wolf <clifford@clifford.at>
Mon, 22 Aug 2016 13:05:57 +0000 (15:05 +0200)
kernel/register.cc
kernel/yosys.cc
kernel/yosys.h

index 115880ed6ba0dc69a7c11ab390fb08086b19a245..7a1d0b44b4ec839fa7b5004e43ae2c6662bead9b 100644 (file)
@@ -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.");
 
index 17f6847b5061491423b83cb3db12867fc6c1e1e6..08fee97419178fb900250bf10fb5aa92d5d1b0fe 100644 (file)
 #  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) == "\"")
index 0df750a134a6fd4d8acbff26006dd64292534ccf..aab6b584454fe57e17cb53a2a67fee73093769c6 100644 (file)
@@ -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);