diff options
author | svntcreutz <svntcreutz@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-08-12 11:28:53 +0000 |
---|---|---|
committer | svntcreutz <svntcreutz@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-08-12 11:28:53 +0000 |
commit | 828c69e079537e00ae71dbce90f5e3f774de5163 (patch) | |
tree | 22d5f1321505283d9736fdf4fd85258093a99da8 | |
parent | 1519efb886a685c0c65f25d150ecf1c3c2bd8a26 (diff) | |
download | vdr-plugin-menuorg-828c69e079537e00ae71dbce90f5e3f774de5163.tar.gz vdr-plugin-menuorg-828c69e079537e00ae71dbce90f5e3f774de5163.tar.bz2 |
added plugin parameters for loading specified xml and dtd file
git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/submenu/trunk@5693 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f
-rw-r--r-- | src/menuorg.cpp | 45 | ||||
-rw-r--r-- | src/menuorg.h | 4 | ||||
-rw-r--r-- | src/xmlmenu.cpp | 13 | ||||
-rw-r--r-- | src/xmlmenu.h | 2 |
4 files changed, 49 insertions, 15 deletions
diff --git a/src/menuorg.cpp b/src/menuorg.cpp index 47b6476..4ffa928 100644 --- a/src/menuorg.cpp +++ b/src/menuorg.cpp @@ -25,10 +25,12 @@ #include <vdr/tools.h> #include <vdr/menuorgpatch.h> #include <vector> +#include <iostream> +#include <string> +#include <getopt.h> #include "version.h" #include "menuorg.h" #include "i18n.h" -#include <string> using namespace std; using namespace MenuOrgPatch; @@ -63,13 +65,43 @@ const char* MenuOrgPlugin::MainMenuEntry(void) const char *MenuOrgPlugin::CommandLineHelp(void) { - // Return a string that describes all known command line options. - return NULL; + return " -c FILE --config=FILE loads the specified xml file\n" + " (default: ConfigDir/plugins/menuorg.xml)\n" + " -s FILE --schema=FILE loads the specified schema file\n" + " (default: ConfigDir/plugins/menuorg.dtd)\n"; } bool MenuOrgPlugin::ProcessArgs(int argc, char *argv[]) { - // Implement command line argument processing here if applicable. + static struct option longOptions[] = + { + { "config", no_argument, NULL, 'c'}, + { "schema", no_argument, NULL, 's'}, + { NULL} + }; + + optind = 0; + opterr = 0; + + int optionChar; + int optionIndex = 0; + while ((optionChar = getopt_long(argc, argv, "c:s", longOptions, &optionIndex)) != -1) + { + switch (optionChar) + { + case 'c': + configFile = optarg; + break; + + case 's': + schemaFile = optarg; + break; + + default: + cerr << argv[0] << ": " << "invalid option " << argv[optind-1] << endl; + return false; + } + } return true; } @@ -77,9 +109,10 @@ bool MenuOrgPlugin::Initialize(void) { XmlMenu xmlMenu; - string configFile = (string) ConfigDirectory() + "/menuorg.xml"; + configFile = (string) ConfigDirectory() + "/menuorg.xml"; + schemaFile = (string) ConfigDirectory() + "/menuorg.dtd"; - MenuNode* menu = xmlMenu.LoadXmlMenu(configFile); + MenuNode* menu = xmlMenu.LoadXmlMenu(configFile, schemaFile); if (menu) { _subMenuProvider = new MainMenuItemsProvider(menu); diff --git a/src/menuorg.h b/src/menuorg.h index fb71ba5..1bea63e 100644 --- a/src/menuorg.h +++ b/src/menuorg.h @@ -25,13 +25,17 @@ #include <vdr/plugin.h> #include "mainmenuitemsprovider.h" +#include <string> +using namespace std; using namespace MenuOrgPatch; class MenuOrgPlugin : public cPlugin { private: MainMenuItemsProvider* _subMenuProvider; + string configFile; + string schemaFile; public: MenuOrgPlugin(void); diff --git a/src/xmlmenu.cpp b/src/xmlmenu.cpp index b7d4ae7..99581c1 100644 --- a/src/xmlmenu.cpp +++ b/src/xmlmenu.cpp @@ -32,22 +32,19 @@ using namespace xmlpp; using namespace std; -MenuNode* XmlMenu::LoadXmlMenu(string menuFileName) +MenuNode* XmlMenu::LoadXmlMenu(string menuFileName, string schemaFileName) { MenuNode* menuRoot = new MenuNode(); try { - DomParser parser; + dsyslog("loading menuorg config file from %s and schema from %s",menuFileName, schemaFileName); - //TODO: patch the xmlfile with the xsd definition for validate the schema - //parser.set_validate(); + DomParser parser; parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically. -// parser.parse_file(menuFileName); - parser.parse_file("/var/lib/vdr/plugins/menuorg.xml"); + parser.parse_file(menuFileName); - //DtdValidator validator( dtdFileName ); - DtdValidator validator( "/var/lib/vdr/plugins/menuorg.dtd" ); + DtdValidator validator(schemaFileName); Document *pDoc = parser.get_document(); validator.validate( pDoc ); diff --git a/src/xmlmenu.h b/src/xmlmenu.h index dbab536..f8da182 100644 --- a/src/xmlmenu.h +++ b/src/xmlmenu.h @@ -32,7 +32,7 @@ namespace xmlpp { class Element; } class XmlMenu { public: - MenuNode* LoadXmlMenu(std::string menuFileName); + MenuNode* LoadXmlMenu(std::string menuFileName, std::string schemaFileName); private: void ParseElement(const xmlpp::Element* a_node, MenuNode* menuNode); |