Module: sems Branch: master Commit: 364e708a5efb7fd205a2427f7ab9db7e71c12b15 URL: https://github.com/sems-server/sems/commit/364e708a5efb7fd205a2427f7ab9db7e71c12b15
Author: Juha Heinanen <[email protected]> Committer: Juha Heinanen <[email protected]> Date: 2015-10-03T17:02:52+03:00 apps/dsm: added support for including all diagrams in directory --- Modified: apps/dsm/DSMStateDiagramCollection.cpp Modified: doc/dsm/dsm_syntax.txt --- Diff: https://github.com/sems-server/sems/commit/364e708a5efb7fd205a2427f7ab9db7e71c12b15.diff Patch: https://github.com/sems-server/sems/commit/364e708a5efb7fd205a2427f7ab9db7e71c12b15.patch --- diff --git a/apps/dsm/DSMStateDiagramCollection.cpp b/apps/dsm/DSMStateDiagramCollection.cpp index 749d223..170edbc 100644 --- a/apps/dsm/DSMStateDiagramCollection.cpp +++ b/apps/dsm/DSMStateDiagramCollection.cpp @@ -30,6 +30,8 @@ #include <fstream> using std::ifstream; +#include <dirent.h> + DSMStateDiagramCollection::DSMStateDiagramCollection() { } @@ -74,10 +76,35 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n current_load_path = r.substr(0, ppos) + "/"; } else { current_load_path = load_path; - include_name = load_path+"/"+r; + include_name = load_path + r; + } + + struct stat status; + DIR *dp; + struct dirent *ep; + string include_dir_name; + if ((stat(include_name.c_str(), &status) == 0) && + (status.st_mode & S_IFDIR)) { + dp = opendir(include_name.c_str()); + if (dp != NULL) { + while ((ep = readdir(dp))) { + if (strncmp(ep->d_name, ".", 1) == 0) continue; + include_dir_name = include_name + "/" + std::string(ep->d_name); + if (!readFile(include_dir_name, std::string(ep->d_name), + current_load_path, s)) { + (void)closedir(dp); + return false; + } + } + (void) closedir(dp); + } else { + ERROR("could not open directory %s", include_name.c_str()); + return false; + } + } else { + if (!readFile(include_name, name, current_load_path, s)) + return false; } - if (!readFile(include_name, name, current_load_path, s)) - return false; continue; } diff --git a/doc/dsm/dsm_syntax.txt b/doc/dsm/dsm_syntax.txt index 5225379..19147dd 100644 --- a/doc/dsm/dsm_syntax.txt +++ b/doc/dsm/dsm_syntax.txt @@ -7,7 +7,10 @@ Syntax # also comment #include "script.dsm" +#include "script_dir" #include "/path/to/anotherscript.dsm" +#include "/path/to/script_dir" + import(mod_name); [initial] state name _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
