Author: mlandres
Date: Mon Apr 30 19:02:49 2007
New Revision: 5464
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5464&view=rev
Log:
backup bsic tag parser
Added:
trunk/libzypp/zypp/ProgressData.cc
trunk/libzypp/zypp/ProgressData.h
trunk/libzypp/zypp/parser/TagParser.cc
trunk/libzypp/zypp/parser/TagParser.h
trunk/libzypp/zypp/parser/susetags/
Modified:
trunk/libzypp/devel/devel.ma/Parse.cc
trunk/libzypp/zypp/CMakeLists.txt
trunk/libzypp/zypp/parser/tagfile/TagFileParser.cc
Modified: trunk/libzypp/devel/devel.ma/Parse.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/Parse.cc?rev=5464&r1=5463&r2=5464&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/Parse.cc (original)
+++ trunk/libzypp/devel/devel.ma/Parse.cc Mon Apr 30 19:02:49 2007
@@ -1,5 +1,3 @@
-#include <ctime>
-#include <iostream>
#include "Tools.h"
#include
@@ -23,16 +21,20 @@
#include "zypp/NameKindProxy.h"
#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/parser/tagfile/TagFileParser.h"
+#include "zypp/parser/TagParser.h"
using namespace std;
using namespace zypp;
using namespace zypp::ui;
using namespace zypp::functor;
+using zypp::parser::tagfile::TagFileParser;
+using zypp::parser::TagParser;
+
///////////////////////////////////////////////////////////////////
static const Pathname sysRoot( "/Local/ROOT" );
-static const Pathname sysRootAlt( "/Local/ALTERNATE/ROOTPATH" );
///////////////////////////////////////////////////////////////////
@@ -98,18 +100,6 @@
///////////////////////////////////////////////////////////////////
-struct PoolItemSelect
-{
- void operator()( const PoolItem & pi ) const
- {
- if ( pi->source().numericId() == 2 )
- pi.status().setTransact( true, ResStatus::USER );
- }
-};
-
-///////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////
-
struct AddResolvables
{
bool operator()( const Source_Ref & src ) const
@@ -121,80 +111,14 @@
///////////////////////////////////////////////////////////////////
-struct SetTransactValue
-{
- SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
- : _newVal( newVal_r )
- , _causer( causer_r )
- {}
-
- ResStatus::TransactValue _newVal;
- ResStatus::TransactByValue _causer;
-
- bool operator()( const PoolItem & pi ) const
- { return pi.status().setTransactValue( _newVal, _causer ); }
-};
-
-struct StatusReset : public SetTransactValue
-{
- StatusReset()
- : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
- {}
-};
-
-
-inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
-{
- if ( nkp.availableEmpty() ) {
- ERR << "No Item to select: " << nkp << endl;
- return false;
- ZYPP_THROW( Exception("No Item to select") );
- }
-
- if ( arch != Arch() )
- {
- typeof( nkp.availableBegin() ) it = nkp.availableBegin();
- for ( ; it != nkp.availableEnd(); ++it )
- {
- if ( (*it)->arch() == arch )
- return (*it).status().setTransact( true, ResStatus::USER );
- }
- }
-
- return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
-}
-
-void seltest( const NameKindProxy & nks )
-{
- SEC << nks << endl;
- PoolItem av( *nks.availableBegin() );
- SEC << av << endl;
- Pattern::constPtr pat( asKind<Pattern>(av.resolvable()) );
- SEC << pat << endl;
- WAR << pat->install_packages() << endl;
- MIL << pat->deps() << endl;
- MIL << pat->includes() << endl;
- MIL << pat->extends() << endl;
-}
-void showProd( const PoolItem & prod )
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
{
- Product::constPtr p( asKind<Product>(prod) );
- DBG << prod << endl;
- MIL << p << endl;
- MIL << p->distributionName() << endl;
- MIL << p->distributionEdition() << endl;
- MIL << p->installtime() << endl;
-}
+ str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+ return str;
-void doPkg( const PoolItem & pi )
-{
- Package::constPtr p( asKind<Package>(pi) );
- MIL << p << endl;
- DBG << p->keywords() << endl;
}
-///////////////////////////////////////////////////////////////////
/******************************************************************
**
** FUNCTION NAME : main
@@ -205,49 +129,56 @@
//zypp::base::LogControl::instance().logfile( "log.restrict" );
INT << "===[START]==========================================" << endl;
- ConvertDbReceive cr;
- cr.connect();
- MediaChangeReceive mr;
- mr.connect();
+ //Pathname p( "lmd/suse/setup/descr/packages" );
+ Pathname p( "packages" );
- Pathname root( sysRoot );
+ if ( 1 )
+ {
+ Pathname p( "packages" );
+ Measure x( p.basename() );
+ TagFileParser tp( (zypp::parser::ParserProgress::Ptr()) );
+ tp.parse( p );
+ }
+
+ if ( 1 ) {
+ Pathname p( "p" );
+ Measure x( p.basename() );
+ TagParser tp;
+ tp.parse( p );
+ }
if ( 1 ) {
- //zypp::base::LogControl::TmpLineWriter shutUp;
- SourceManager::sourceManager()->restore( root );
+ Pathname p( "p.gz" );
+ Measure x( p.basename() );
+ TagParser tp;
+ tp.parse( p );
+ }
+ if ( 1 ) {
+ Pathname p( "packages" );
+ Measure x( p.basename() );
+ TagParser tp;
+ tp.parse( p );
+ }
+ if ( 1 ) {
+ Pathname p( "packages.gz" );
+ Measure x( p.basename() );
+ TagParser tp;
+ tp.parse( p );
+ }
- if ( SourceManager::sourceManager()->allSources().empty() )
+ if ( 0 )
+ {
+ Measure x( "lmd.idx" );
+ std::ifstream fIndex( "lmd.idx" );
+ for( iostr::EachLine in( fIndex ); in; in.next() )
{
+ Measure x( *in );
+ std::ifstream fIn( (*in).c_str() );
+ for( iostr::EachLine l( fIn ); l; l.next() )
{
- zypp::base::LogControl::TmpLineWriter shutUp;
- Source_Ref src1( createSource( "dir:/dist/install/SLP/openSUSE-10.3-Build00300-DVD/i386/DVD1" ) );
- SourceManager::sourceManager()->addSource( src1 );
- SourceManager::sourceManager()->store( root, true );
+ ;
}
- dumpRange( USR << "Sources Created: ",
- SourceManager::sourceManager()->Source_begin(),
- SourceManager::sourceManager()->Source_end()
- ) << endl;
- } else {
- dumpRange( USR << "Sources Reloaded: ",
- SourceManager::sourceManager()->Source_begin(),
- SourceManager::sourceManager()->Source_end()
- ) << endl;
}
}
-
- std::for_each( SourceManager::sourceManager()->Source_begin(),
- SourceManager::sourceManager()->Source_end(),
- AddResolvables() );
-
- ResPool pool( getZYpp()->pool() );
- dumpRange( USR << "PackageKeywords: " << PackageKeyword::allSize(),
- PackageKeyword::allBegin(),
- PackageKeyword::allEnd() ) << endl;
-
- std::for_each( pool.byKindBegin<Package>(),
- pool.byKindEnd<Package>(),
- doPkg );
-
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
return 0;
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5464&r1=5463&r2=5464&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Mon Apr 30 19:02:49 2007
@@ -48,6 +48,7 @@
ProblemSolution.cc
Package.cc
Pathname.cc
+ ProgressData.cc
Source.cc
SourceFactory.cc
SourceManager.cc
@@ -132,6 +133,7 @@
Patch.h
PathInfo.h
Pathname.h
+ ProgressData.h
Pattern.h
PoolItem.h
ProblemSolution.h
@@ -406,12 +408,14 @@
)
SET( zypp_parser_SRCS
+ parser/TagParser.cc
parser/LibXMLHelper.cc
parser/SAXParser.cc
parser/XMLNodeIterator.cc
)
SET( zypp_parser_HEADERS
+ parser/TagParser.h
parser/LibXMLHelper.h
parser/ParserProgress.h
parser/SAXParser.h
Added: trunk/libzypp/zypp/ProgressData.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ProgressData.cc?rev=5464&view=auto
==============================================================================
--- trunk/libzypp/zypp/ProgressData.cc (added)
+++ trunk/libzypp/zypp/ProgressData.cc Mon Apr 30 19:02:49 2007
@@ -0,0 +1,99 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ProgressData.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/base/InputStream.h"
+#include "zypp/base/String.h"
+
+#include "zypp/ProgressData.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ProgressData::report
+ // METHOD TYPE : void
+ //
+ void ProgressData::report()
+ {
+ if ( hasRange() )
+ {
+ value_type newVal = _d->_val * 100;
+ newVal /= ( _d->_max - _d->_min );
+
+ if ( newVal - _d->_last_val > 5 || Date::now() - _d->_last_send > 1 || _d->_state == END )
+ {
+ DBG << str::form( "{%u|%s}(%d%%)",
+ numericId(), name().c_str(), newVal ) << endl;
+ _d->_last_val = newVal;
+ _d->_last_send = Date::now();
+ if ( _d->_state == INIT )
+ {
+ _d->_state = RUN;
+ }
+ }
+ }
+ else
+ {
+ if ( Date::now() - _d->_last_send > 1 || _d->_state == END )
+ {
+ DBG << str::form( "{%u|%s}(%d!)",
+ numericId(), name().c_str(), _d->_val ) << endl;
+ _d->_last_val = _d->_val;
+ _d->_last_send = Date::now();
+ if ( _d->_state == INIT )
+ {
+ _d->_state = RUN;
+ }
+ }
+ }
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const ProgressData & obj )
+ {
+ if ( obj.hasRange() )
+ {
+ return str << str::form( "{%u|%s}[%lld,%lld](%lld)",
+ obj.numericId(), obj.name().c_str(),
+ obj.min(), obj.max(), obj.val() );
+ }
+ return str << str::form( "{%u|%s}[-,-](%lld)",
+ obj.numericId(), obj.name().c_str(),
+ obj.val() );
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ ProgressData makeProgressData( const InputStream & input_r )
+ {
+ ProgressData ret;
+ ret.name( input_r.name() );
+ if ( input_r.size() > 0 )
+ ret.range( input_r.size() );
+ return ret;
+ }
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/ProgressData.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ProgressData.h?rev=5464&view=auto
==============================================================================
--- trunk/libzypp/zypp/ProgressData.h (added)
+++ trunk/libzypp/zypp/ProgressData.h Mon Apr 30 19:02:49 2007
@@ -0,0 +1,203 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/ProgressData.h
+ *
+*/
+#ifndef ZYPP_PROGRESSDATA_H
+#define ZYPP_PROGRESSDATA_H
+
+#include <iosfwd>
+#include <string>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/ProvideNumericId.h"
+
+#include "zypp/Date.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ProgressData
+ //
+ /** Maintain <tt>[min,max]</tt> and counter <tt>(value)</tt> for progress counting.
+ *
+ * This class should provide everything the producer of progress data
+ * needs. As a convention, a zero sizes range indicates that you are just
+ * able to send <em>'still alive'</em> triggers.
+ *
+ * The counter should be updated in reasonable intervals. Don't mind wheter
+ * the counter value actually increased or not. ProgressData will recognize
+ * your triggers and knows when to actually send notification to a consumer.
+ *
+ * Each ProgressData object provides a unique numeric id and you may assign
+ * it a name.
+ *
+ * \todo complete the progess sending.
+ */
+ class ProgressData : public base::ProvideNumericId
+ {
+ public:
+ typedef long long value_type;
+ enum State { INIT, RUN, END };
+
+ private:
+ class Data
+ {
+ public:
+ Data( value_type min_r, value_type max_r, value_type val_r )
+ : _state( INIT ), _min( min_r ), _max( max_r ), _val( val_r )
+ , _last_val( 0 ), _last_send( 0 )
+ {}
+
+ public:
+ State _state;
+ std::string _name;
+ value_type _min;
+ value_type _max;
+ value_type _val;
+
+ value_type _last_val;
+ Date _last_send;
+
+ private:
+ /** clone for RWCOW_pointer */
+ friend Data * rwcowClone<Data>( const Data * rhs );
+ Data * clone() const { return new Data( *this ); }
+ };
+
+ public:
+ /** Ctor no range <tt>[0,0](0)</tt>. */
+ ProgressData()
+ : _d( new Data( 0, 0, 0 ) )
+ {}
+
+ /** Ctor <tt>[0,max](0)</tt>. */
+ ProgressData( value_type max_r )
+ : _d( new Data( 0, max_r, 0 ) )
+ {}
+
+ /** Ctor <tt>[min,max](min)</tt>. */
+ ProgressData( value_type min_r, value_type max_r )
+ : _d( new Data( min_r, max_r, min_r ) )
+ {}
+
+ /** Ctor <tt>[min,max](val)</tt>. */
+ ProgressData( value_type min_r, value_type max_r, value_type val_r )
+ : _d( new Data( min_r, max_r, val_r ) )
+ {}
+
+ ~ProgressData()
+ {
+ if ( _d->_state == RUN )
+ {
+ _d->_state = END;
+ report();
+ }
+ }
+
+ public:
+ /** @return Current \c min value. */
+ value_type min() const
+ { return _d->_min; }
+
+ /** @return Current \c max value. */
+ value_type max() const
+ { return _d->_max; }
+
+ /** @return Current counter \c value. */
+ value_type val() const
+ { return _d->_val; }
+
+ /** @return Wheter <tt>[min,max]</tt> defines a nonempty range. */
+ bool hasRange() const
+ { return min() != max(); }
+
+ /** @return The counters name. */
+ const std::string & name() const
+ { return _d->_name; }
+
+ public:
+ /** Set new \c min value. */
+ void min( value_type min_r )
+ { _d->_min = min_r; }
+
+ /** Set new \c max value. */
+ void max( value_type max_r )
+ { _d->_max = max_r; }
+
+ /** Set no range <tt>[0,0]</tt>. */
+ void noRange()
+ { range( 0, 0 ); }
+
+ /** Set new <tt>[0,max]</tt>. */
+ void range( value_type max_r )
+ { range( 0, max_r ); }
+
+ /** Set new <tt>[min,max]</tt>. */
+ void range( value_type min_r, value_type max_r )
+ { min( min_r ); max( max_r ); }
+
+ public:
+ /** Set new counter \c value. */
+ void set( value_type val_r )
+ {
+ _d->_val = val_r;
+ report();
+ }
+
+ /** Increment counter \c value (default by 1). */
+ void incr( value_type val_r = 1 )
+ { set( val() + val_r ); }
+
+ /** Decrement counter \c value (default by 1). */
+ void decr( value_type val_r = 1 )
+ { set( val() - val_r ); }
+
+ /** Set counter value to current \c min value. */
+ void toMin()
+ { set( min() ); }
+
+ /** Set counter value to current \c max value (unless no range). */
+ void toMax()
+ { if ( hasRange() ) set( max() ); }
+
+ /** Leave counter value unchanged (still alive). */
+ void tick()
+ { set( val() ); }
+
+ public:
+ /** Set counter name. */
+ void name( const std::string & name_r )
+ { _d->_name = name_r; }
+
+ private:
+ /** Send report if necessary. */
+ void report();
+
+ /** Pointer to data. */
+ RWCOW_pointer<Data> _d;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates ProgressData Stream output */
+ std::ostream & operator<<( std::ostream & str, const ProgressData & obj );
+
+ ///////////////////////////////////////////////////////////////////
+
+ class InputStream;
+ /** \relates ProgressData Setup from \ref InputStream. */
+ ProgressData makeProgressData( const InputStream & input_r );
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_PROGRESSDATA_H
Added: trunk/libzypp/zypp/parser/TagParser.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/TagParser.cc?rev=5464&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/TagParser.cc (added)
+++ trunk/libzypp/zypp/parser/TagParser.cc Mon Apr 30 19:02:49 2007
@@ -0,0 +1,335 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/TagParser.cc
+ *
+*/
+#include <iostream>
+#include <sstream>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
+#include "zypp/base/IOStream.h"
+
+#include "zypp/parser/TagParser.h"
+#include "zypp/ProgressData.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : TagParser::Tag
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ std::string TagParser::Tag::asString() const
+ {
+ std::string ret( name );
+ if ( ! modifier.empty() )
+ ret += modifier;
+ return ret += ":";
+ }
+
+ std::ostream & operator<<( std::ostream & str, const TagParser::Tag & obj )
+ {
+ str << "@" << obj.lineNo << "{" << obj.name;
+ if ( ! obj.modifier.empty() )
+ str << '.' << obj.modifier;
+ return str << ":}(" << obj.dataStart << "|" << obj.dataLength << ")";
+ }
+
+ std::ostream & operator<<( std::ostream & str, const TagParser::SingleTag & obj )
+ {
+ str << "=" << static_cast( obj );
+ return str << "\"" << obj.value << "\"";
+ }
+
+ std::ostream & operator<<( std::ostream & str, const TagParser::MultiTag & obj )
+ {
+ str << "+" << static_cast( obj );
+ return str << "[" << obj.value.size() << "]";
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : TagParser
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : TagParser::TagParser
+ // METHOD TYPE : Ctor
+ //
+ TagParser::TagParser()
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : TagParser::~TagParser
+ // METHOD TYPE : Dtor
+ //
+ TagParser::~TagParser()
+ {}
+
+ void TagParser::beginParse()
+ {}
+ void TagParser::consume( const SingleTagPtr & tag_r )
+ {}
+ void TagParser::consume( const MultiTagPtr & tag_r )
+ {}
+ void TagParser::endParse()
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : TagParser::errPrefix
+ // METHOD TYPE : std::string
+ //
+ std::string TagParser::errPrefix( unsigned lineNo_r,
+ const std::string & msg_r ) const
+ {
+ return str::form( "%s:%u:%s: %s",
+ _inputname.c_str(),
+ lineNo_r,
+ "-",
+ msg_r.c_str() );
+ }
+
+ std::string TagParser::errPrefix( const SingleTagPtr & tag_r,
+ const std::string & msg_r ) const
+ {
+ return str::form( "%s:%u:=%s %s",
+ _inputname.c_str(),
+ tag_r->lineNo,
+ tag_r->asString().c_str(),
+ msg_r.c_str() );
+ }
+
+ std::string TagParser::errPrefix( const MultiTagPtr & tag_r,
+ const std::string & msg_r ) const
+ {
+ return str::form( "%s:%u:+%s %s",
+ _inputname.c_str(),
+ tag_r->lineNo,
+ tag_r->asString().c_str(),
+ msg_r.c_str() );
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+
+ /** Parse a tag <tt>NAME[.EXT]:</tt>from \a begin_r.
+ * If a tag was found, update \a tag_r and advance
+ * \a begin_r to point behind the \c :.
+ */
+ inline bool helperParseStartTag( TagParser::Tag & tag_r, const char *& begin_r )
+ {
+ const char * tsep = 0; // find ':'
+ const char * esep = 0; // remember last '.'
+ for ( const char * ch = begin_r; *ch; ++ch )
+ {
+ switch ( *ch )
+ {
+ case '.':
+ esep = ch; // remember
+ break;
+ case ':':
+ tsep = ch;
+ ch = 0; // done: found ':'
+ break;
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ ch = 0; // fail: no whitespace allowed in tag
+ break;
+ }
+ if ( ! ch )
+ break;
+ }
+
+ if ( ! tsep )
+ return false; // no tag found
+
+ // Update name and modifier
+ if ( esep )
+ {
+ std::string( begin_r, esep-begin_r ).swap( tag_r.name );
+ ++esep;
+ std::string( esep, tsep-esep ).swap( tag_r.modifier );
+ }
+ else
+ {
+ std::string( begin_r, tsep-begin_r ).swap( tag_r.name );
+ }
+
+ begin_r = tsep+1; // behind ':'
+ return true;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : TagParser::parse
+ // METHOD TYPE : void
+ //
+ void TagParser::parse( const InputStream & input_r )
+ {
+ MIL << "Start parsing " << input_r << endl;
+ _inputname = input_r.name();
+ beginParse();
+
+ ProgressData ticks( makeProgressData( input_r ) );
+ ticks.toMin();
+
+ iostr::EachLine line( input_r );
+ for( ; line; line.next() )
+ {
+ const char * cp = (*line).c_str();
+ switch ( *cp )
+ {
+ ///////////////////////////////////////////////////////////////////
+ case '=': // get single line data
+ {
+ SingleTagPtr tagP( new SingleTag( line.lineNo(), line.lineStart() ) );
+ SingleTag & tag( *tagP.get() );
+
+ const char * cp = (*line).c_str() + 1;
+ if ( helperParseStartTag( tag, cp ) )
+ {
+ while ( *cp == ' ' || *cp == '\t' )
+ ++cp;
+
+ tag.dataStart = tag.tagStart + cp - (*line).c_str();
+
+ if ( *cp ) // not at string end
+ {
+ const char * ep = (*line).c_str() + (*line).size();
+ do {
+ --ep;
+ } while ( *ep == ' ' || *ep == '\t' );
+ tag.dataLength = ep+1-cp;
+ std::string( cp, tag.dataLength ).swap( tag.value );
+ }
+
+ consume( tagP );
+ }
+ else
+ {
+ ZYPP_THROW( ParseException( errPrefix( line.lineNo(), "Orphan data: " + (*line) ) ) );
+ }
+ }
+ break;
+
+ ///////////////////////////////////////////////////////////////////
+ case '+': // get mulit line data
+ {
+ MultiTagPtr tagP( new MultiTag(line.lineNo(), line.lineStart() ) );
+ MultiTag & tag( *tagP.get() );
+
+ const char * cp = (*line).c_str() + 1;
+ if ( helperParseStartTag( tag, cp ) )
+ {
+ std::string endTag( "-" );
+ endTag += tag.name;
+ if ( ! tag.modifier.empty() )
+ {
+ endTag += ".";
+ endTag += tag.modifier;
+ }
+ endTag += ":";
+
+ line.next();
+ tag.dataStart = line.lineStart();
+
+ for( ; line; line.next() )
+ {
+ if ( str::hasPrefix( *line, endTag ) )
+ {
+ tag.dataLength = line.lineStart() - tag.dataStart;
+ break;
+ }
+ else
+ {
+ tag.value.push_back( *line );
+ }
+ }
+
+ if ( ! line )
+ {
+ ZYPP_THROW( ParseException( errPrefix( tagP, "Reached EOF while looking for end tag") ) );
+ }
+
+ consume( tagP );
+ }
+ else
+ {
+ ZYPP_THROW( ParseException( errPrefix( line.lineNo(), "Orphan data: " + (*line) ) ) );
+ }
+ }
+ break;
+
+ ///////////////////////////////////////////////////////////////////
+ default: // empty or comment
+ {
+ for ( const char * cp = (*line).c_str(); *cp; ++cp )
+ {
+ switch( *cp )
+ {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ break;
+
+ default:
+ if ( *cp != '#' )
+ {
+ ZYPP_THROW( ParseException( errPrefix( line.lineNo(), "Orphan data: " + (*line) ) ) );
+ }
+ cp = 0;
+ break;
+ }
+
+ if ( ! cp )
+ {
+ break;
+ }
+ }
+ }
+ break;
+ }
+
+ ticks.set( input_r.stream().tellg() );
+ }
+
+ ticks.toMax();
+
+ endParse();
+ _inputname.clear();
+ MIL << "Done parsing " << input_r << endl;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/parser/TagParser.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/TagParser.h?rev=5464&view=auto
==============================================================================
--- trunk/libzypp/zypp/parser/TagParser.h (added)
+++ trunk/libzypp/zypp/parser/TagParser.h Mon Apr 30 19:02:49 2007
@@ -0,0 +1,138 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/TagParser.h
+ *
+*/
+#ifndef ZYPP_PARSER_TAGPARSER_H
+#define ZYPP_PARSER_TAGPARSER_H
+
+#include <iosfwd>
+#include <string>
+#include <list>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/InputStream.h"
+
+#include "zypp/parser/tagfile/ParseException.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace parser
+ { /////////////////////////////////////////////////////////////////
+
+ using tagfile::ParseException;
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : TagParser
+ //
+ /** Basic SUSEtags parser.
+ * Will replace parser/tagfile/ and parser/taggedfile/ stuff.
+ */
+ class TagParser : private base::NonCopyable
+ {
+ public:
+
+ struct Tag
+ {
+ Tag( unsigned lineNo_r = 0, std::streamoff tagStart_r = -1 )
+ : lineNo( lineNo_r ), tagStart( tagStart_r ), dataStart( -1 ), dataLength( 0 )
+ {}
+ /** String <tt>"NAME[.MODIFIER]:"</tt>. */
+ std::string asString() const;
+
+ unsigned lineNo;
+ std::streamoff tagStart;
+ std::streamoff dataStart;
+ std::streamoff dataLength;
+
+ std::string name;
+ std::string modifier;
+ };
+
+ struct SingleTag : Tag
+ {
+ SingleTag( unsigned lineNo_r = 0, std::streamoff tagStart_r = -1 )
+ : Tag( lineNo_r, tagStart_r )
+ {}
+ std::string value;
+ };
+
+ struct MultiTag : Tag
+ {
+ MultiTag( unsigned lineNo_r = 0, std::streamoff tagStart_r = -1 )
+ : Tag( lineNo_r, tagStart_r )
+ {}
+ std::liststd::string value;
+ };
+
+ typedef shared_ptr<SingleTag> SingleTagPtr;
+ typedef shared_ptr<MultiTag> MultiTagPtr;
+
+ public:
+ /** Default ctor */
+ TagParser();
+ /** Dtor */
+ virtual ~TagParser();
+ /** Parse the stream.
+ * \throw ParseExcetion on errors. Invoke \ref consume
+ * for each tag. \ref consume might throw other exceptions
+ * as well.
+ */
+ void parse( const InputStream & imput_r );
+
+ public:
+ /** Called when start parsing. */
+ virtual void beginParse();
+ /** Called when a single-tag is found. */
+ virtual void consume( const SingleTagPtr & tag_r );
+ /** Called when a multi-tag is found. */
+ virtual void consume( const MultiTagPtr & tag_r );
+ /** Called when the parse is done. */
+ virtual void endParse();
+
+ public:
+ /** Prefix exception message with line and tag information. */
+ std::string errPrefix( unsigned lineNo_r,
+ const std::string & msg_r = std::string() ) const;
+ /** Prefix exception message with line and tag information. */
+ std::string errPrefix( const SingleTagPtr & tag_r,
+ const std::string & msg_r = std::string() ) const;
+ /** Prefix exception message with line and tag information. */
+ std::string errPrefix( const MultiTagPtr & tag_r,
+ const std::string & msg_r = std::string() ) const;
+ /** Name of the current InputStream. */
+ const std::string & inputname() const
+ { return _inputname; }
+
+ private:
+ std::string _inputname;
+ //ProgressData _ticks;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates TagParser::Tag Stream output. */
+ std::ostream & operator<<( std::ostream & str, const TagParser::Tag & obj );
+
+ /** \relates TagParser::SingleTag Stream output. */
+ std::ostream & operator<<( std::ostream & str, const TagParser::SingleTag & obj );
+
+ /** \relates TagParser::MultiTag Stream output. */
+ std::ostream & operator<<( std::ostream & str, const TagParser::MultiTag & obj );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace parser
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_PARSER_TAGPARSER_H
Modified: trunk/libzypp/zypp/parser/tagfile/TagFileParser.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/tagfile/TagFileParser.cc?rev=5464&r1=5463&r2=5464&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/tagfile/TagFileParser.cc (original)
+++ trunk/libzypp/zypp/parser/tagfile/TagFileParser.cc Mon Apr 30 19:02:49 2007
@@ -208,7 +208,7 @@
}
new_progress = (int)((((float)readed)/((float)_file_size))*100);
- if ( new_progress != previous_progress )
+ if ( _progress && new_progress != previous_progress )
_progress->progress( new_progress );
previous_progress = new_progress;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org