summaryrefslogtreecommitdiff
path: root/server/src/macrolist.cc
diff options
context:
space:
mode:
authordeva <deva>2010-06-01 12:58:32 +0000
committerdeva <deva>2010-06-01 12:58:32 +0000
commit74a28aa7125be6a603128ad600c98c4882f3b5c2 (patch)
tree1a9e4ab74f29d5ff10f2701e4e112f4525c0dcec /server/src/macrolist.cc
parent9b9c1e2dd3e5807ff7714b378b03b9ba31f42df7 (diff)
From new_protocol branch.
Diffstat (limited to 'server/src/macrolist.cc')
-rw-r--r--server/src/macrolist.cc83
1 files changed, 21 insertions, 62 deletions
diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc
index b67f239..908de1e 100644
--- a/server/src/macrolist.cc
+++ b/server/src/macrolist.cc
@@ -27,80 +27,39 @@
*/
#include "macrolist.h"
-#include <sys/types.h>
-#include <dirent.h>
+#include <utility>
-#include "debug.h"
#include "macroheaderparser.h"
-static std::vector<std::string> listdir(std::string path)
-{
- std::vector<std::string> files;
-
- DIR* dir = opendir(path.c_str());
- if(!dir) {
- PRACRO_ERR(dump, "Could not open directory: %s\n", path.c_str());
- return files;
- }
-
- struct dirent *d;
- while((d = readdir(dir)) != 0) {
- //if(d->d_type == DT_DIR) {
- std::string name = d->d_name;
- if(name.length() >= 4 && name.substr(name.length() - 4) == ".xml")
- files.push_back(name);
- //}
- }
- closedir(dir);
+#include "debug.h"
- return files;
+MacroList::MacroList(std::string path)
+ : EntityList(path, "macro")
+{
+ rescan();
}
-MacroList::MacroList(std::string macropath)
+
+void MacroList::addFile(std::string file)
{
- this->macropath = macropath;
- std::vector<std::string> macros = listdir(macropath);
- std::vector<std::string>::iterator i = macros.begin();
- while(i != macros.end()) {
- MacroHeaderParser parser(macropath + "/" + *i);
- try {
- parser.parse();
- Macro *macro = parser.getMacro();
- (*this)[macro->attributes["name"]][VersionStr(macro->attributes["version"])] = *i;
- } catch(Exception &e) {
- PRACRO_WARN(macrolist, "Skipping %s: %s\n", i->c_str(), e.what());
- }
- i++;
+ if(file.substr(file.size() - 4) != ".xml") {
+ PRACRO_DEBUG(macrolist, "Skipping file: %s\n", file.c_str());
+ return;
}
- {
- iterator i = begin();
- while(i != end()) {
- MacroListItem::iterator j = i->second.begin();
- while(j != i->second.end()) {
- PRACRO_DEBUG(macrolist, "%s - v%s file: %s\n",
- i->first.c_str(),
- ((std::string)j->first).c_str(),
- j->second.c_str());
- j++;
- }
- i++;
- }
+ PRACRO_DEBUG(macrolist, "Adding file: %s\n", file.c_str());
+ MacroHeaderParser parser(file);
+ try {
+ parser.parse();
+ Macro *macro = parser.getMacro();
+ insertEntity(macro->attributes["name"],
+ macro->attributes["version"],
+ file);
+ } catch(Exception &e) {
+ PRACRO_WARN(macrolist, "Skipping %s: %s\n", file.c_str(), e.what());
}
}
-std::string MacroList::getLatestVersion(std::string macro) throw(Exception)
-{
- if(find(macro) == end()) throw Exception("Macro ["+macro+"] does not exist");
- MacroListItem mli = (*this)[macro];
- if(mli.size() == 0) return "";
- PRACRO_DEBUG(macrolist, "Search for %s - found %s v%s\n",
- macro.c_str(),
- (macropath + "/" + mli.begin()->second).c_str(),
- ((std::string)mli.begin()->first).c_str());
- return macropath + "/" + mli.begin()->second;
-}
-
#ifdef TEST_MACROLIST
#define MACRODIR "/home" // We assume this directory exists and does not contain any xml files!