| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/parser/tagfile/Parser.cc
+/** \file zypp/parser/tagfile/ProductMetadataParser.cc
*
*/
#include <iostream>
#include <sstream>
#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
#include "zypp/base/Logger.h"
#include "zypp/base/PtrTypes.h"
#include "zypp/parser/tagfile/ProductMetadataParser.h"
+#include <boost/regex.hpp>
#include "zypp/parser/tagfile/Grammar.h"
-using std::endl;
+using namespace std;
using namespace boost;
+typedef find_iterator<string::iterator> string_find_iterator;
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
void ProductMetadataParser::parse( const Pathname & file_r, ProductEntry &entry_r )
{
std::ifstream file(file_r.asString().c_str());
- std::stringstream st;
- st << file;
- tokenizer<> tok(st.str());
- //for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
- // std::cout << *beg << std:endl;
- //}
+ std::string buffer;
+ while(!file.eof())
+ {
+ getline(file, buffer);
+ boost::regex e("^(([A-Z]+)(\\.([_A-Z0-9a-z]+)){0,1}) (.+)$");
+ boost::smatch what;
+ if(boost::regex_match(buffer, what, e, boost::match_extra))
+ {
+ if ( what.size() < 5 )
+ std::cout << "ups!!!!" << std::endl;
+
+ std::string key = what[2];
+ std::string value = what[5];
+ std::string modifier = what[4];
+ if(key == "PRODUCT")
+ entry_r.name = value;
+ else if(key == "VERSION")
+ entry_r.version = value;
+ else if(key == "DISTPRODUCT")
+ entry_r.dist = value;
+ else if(key == "DISTVERSION")
+ entry_r.dist_version = value;
+ else if(key == "BASEPRODUCT")
+ entry_r.base_product = value;
+ else if(key == "BASEVERSION")
+ entry_r.base_version = value;
+ else if(key == "YOUTYPE")
+ entry_r.you_type = value;
+ else if(key == "YOUPATH")
+ entry_r.you_path = value;
+ else if(key == "YOUURL")
+ entry_r.you_url = value;
+ else if(key == "VENDOR")
+ entry_r.vendor = value;
+ else if(key == "RELNOTESURL")
+ entry_r.release_notes_url = value;
+ else if(key == "ARCH")
+ parseLine( key, modifier, value, entry_r.arch);
+ else
+ DBG << "parse error" << std::endl;
+ }
+ else
+ {
+ std::cout << "** No Match found **\n";
+ }
+ //std::cout << "hola: [" << buffer << "]" << std::endl;
+ }
+ }
+
+ void ProductMetadataParser::parseLine( const string &key, const string &modif, const string &value, map< string, list<string> > &container)
+ {
+ std::string value_copy = value;
+ string_find_iterator it = make_find_iterator(value_copy, token_finder(is_space()));
+ if(it!=string_find_iterator())
+ {
+ DBG << "add element " << key << " " << modif << " [" << value << "]" << std::endl;
+ if( modif.size() == 0)
+ container["default"].push_back(value_copy);
+ else
+ container[modif].push_back(value_copy);
+ }
+ }
+ void ProductMetadataParser::parseLine( const string &key, const string &modif, const string &value, map< string, string > &container)
+ {
+ if( modif.size() == 0)
+ container["default"] = value;
+ else
+ container[modif] = value;
}
/////////////////////////////////////////////////////////////////
#include <iosfwd>
#include <set>
+#include <map>
+#include <list>
#include "zypp/parser/tagfile/Tags.h"
#include "zypp/parser/tagfile/ParseException.h"
struct ProductMetadataParser
{
struct ProductEntry {
- Pathname _dir;
- std::string _name;
+ Pathname dir;
+ std::string name;
+ std::string version;
+ std::string dist;
+ std::string dist_version;
+ std::string base_product;
+ std::string base_version;
+ std::string you_type;
+ std::string you_path;
+ std::string you_url;
+ std::string vendor;
+ std::string release_notes_url;
+ std::map< std::string, std::list<std::string> > arch;
+ std::string default_base;
+ std::string requires;
+ std::list<std::string> languages;
+ std::map< std::string, std::string > label;
+ std::string description_dir;
+ std::string data_dir;
+ std::list<std::string> flags;
+ std::string language;
+ std::string timezone;
ProductEntry( const Pathname & dir_r = "/", const std::string & name_r = std::string() ){
- _dir = dir_r;
- _name = name_r;
+ dir = dir_r;
+ name = name_r;
}
bool operator<( const ProductEntry & rhs ) const {
- return( _dir.asString() < rhs._dir.asString() );
+ return( dir.asString() < rhs.dir.asString() );
}
};
* \todo more doc on Ecaptions.
*/
void parse( const Pathname & file_r, ProductEntry &entry_r );
+ /* Parse a key.modifier (std::list of std::strings)
+ * the default modifier will get the modifier of default (LABEL.de, LABEL as LANGUAGE.default)
+ */
+ void parseLine( const std::string &key, const std::string &modifr, const std::string &value, std::map< std::string, std::list<std::string> > &container);
+ /*
+ * same as above, but the value is a single std::string
+ */
+ void parseLine( const std::string &key,const std::string &modif, const std::string &value, std::map< std::string, std::string > &container);
};
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_TAGFILE_ProductMetadataPPARSER_H
+//
+#endif // ZYPP_PARSER_TAGFILE_ProductMetadataPPARSER_H