Author: aschnell
Date: Thu Mar 5 19:02:32 2009
New Revision: 55952
URL: http://svn.opensuse.org/viewcvs/yast?rev=55952&view=rev
Log:
- more powerful find function for AsciiFile
- some cleanup
Modified:
trunk/storage/libstorage/src/AppUtil.cc
trunk/storage/libstorage/src/AsciiFile.cc
trunk/storage/libstorage/src/AsciiFile.h
trunk/storage/libstorage/src/EtcFstab.cc
trunk/storage/libstorage/src/Storage.cc
Modified: trunk/storage/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.cc?rev=55952&r1=55951&r2=55952&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.cc (original)
+++ trunk/storage/libstorage/src/AppUtil.cc Thu Mar 5 19:02:32 2009
@@ -487,15 +487,13 @@
unsigned ret = 0;
AsciiFile file("/proc/devices");
- const std::vector<string>& lines = file.lines();
Regex rx("^" + Regex::ws + "([0-9]+)" + Regex::ws + string(driver) + "$");
- std::vector<string>::const_iterator it = find_if(lines.begin(), lines.end(), regex_matches(rx));
- if (it == lines.end())
- y2err("did not find " << driver << " in /proc/devices");
- else
+ if (file.find_if(regex_matches(rx)) >= 0)
rx.cap(1) >> ret;
+ else
+ y2err("did not find " << driver << " in /proc/devices");
y2mil("driver:" << driver << " ret:" << ret);
return ret;
Modified: trunk/storage/libstorage/src/AsciiFile.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AsciiFile.cc?rev=55952&r1=55951&r2=55952&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AsciiFile.cc (original)
+++ trunk/storage/libstorage/src/AsciiFile.cc Thu Mar 5 19:02:32 2009
@@ -314,57 +314,6 @@
return Lines_C[Idx_iv];
}
-int AsciiFile::find( Regex& Pat_Cv ) const
- {
- unsigned Idx_ii = 0;
- int Ret_ii = -1;
- while( Ret_ii<0 && Idx_ii0 && Pat_Ci[0]=='^';
-
- if( BeginOfLine_bi )
- {
- Pat_Ci.erase( 0, 1 );
- }
- while( Ret_ii<0 && Idx_iihttp://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AsciiFile.h?rev=55952&r1=55951&r2=55952&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AsciiFile.h (original)
+++ trunk/storage/libstorage/src/AsciiFile.h Thu Mar 5 19:02:32 2009
@@ -4,6 +4,7 @@
#include <string>
#include <vector>
+#include <algorithm>
namespace storage
@@ -49,8 +50,14 @@
const string& operator []( unsigned int Index_iv ) const;
string& operator []( unsigned int Index_iv );
- int find( const string& Pat_Cv ) const;
- int find( Regex& Pat_Cv ) const;
+ template <class Pred>
+ int find_if(Pred pred) const
+ {
+ vector<string>::const_iterator it = std::find_if(Lines_C.begin(), Lines_C.end(), pred);
+ if (it == Lines_C.end())
+ return -1;
+ return std::distance(Lines_C.begin(), it);
+ }
unsigned numLines() const { return Lines_C.size(); }
Modified: trunk/storage/libstorage/src/EtcFstab.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/EtcFstab.cc?rev=55952&r1=55951&r2=55952&view=diff
==============================================================================
--- trunk/storage/libstorage/src/EtcFstab.cc (original)
+++ trunk/storage/libstorage/src/EtcFstab.cc Thu Mar 5 19:02:32 2009
@@ -404,23 +404,22 @@
{
y2mil("device:" << e.dentry << " mp:" << e.mount << " fstab:" << fstab << " cryptotab:" << cryptotab);
AsciiFile* ret=NULL;
- Regex *fi = NULL;
+ string reg;
if( e.crypto )
{
if( cryptotab==NULL )
cryptotab = new AsciiFile( prefix + "/cryptotab" );
ret = cryptotab;
- fi = new Regex( "[ \t]" + e.dentry + "[ \t]" );
+ reg = "[ \t]" + e.dentry + "[ \t]";
}
else
{
if( fstab==NULL )
fstab = new AsciiFile( prefix + "/fstab" );
ret = fstab;
- fi = new Regex( "^[ \t]*" + e.dentry + "[ \t]" );
+ reg = "^[ \t]*" + e.dentry + "[ \t]";
}
- lineno = ret->find( *fi );
- delete fi;
+ lineno = ret->find_if(regex_matches(reg));
y2mil("fstab:" << fstab << " cryptotab:" << cryptotab << " lineno:" << lineno);
return( ret );
}
@@ -436,9 +435,7 @@
reg += "[ \t]+" + mount;
if( mount.length()>0 && mount[mount.length()-1] != '/' )
reg += "/";
- Regex *fi = new Regex( reg );
- int lineno = tab.find( *fi );
- delete fi;
+ int lineno = tab.find_if(regex_matches(reg));
y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno );
}
@@ -448,13 +445,11 @@
{
y2mil("dev:" << e.device);
string reg = "^[ \t]*[^ \t]+[ \t]+" + e.device + "[ \t]";
- Regex fi( reg );
- lineno = tab.find( fi );
+ lineno = tab.find_if(regex_matches(reg));
if( lineno<0 )
{
reg = "^[ \t]*" + e.dentry + "[ \t]";
- Regex fil( reg );
- lineno = tab.find( fil );
+ lineno = tab.find_if(regex_matches(reg));
}
y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno>=0 );
@@ -465,8 +460,7 @@
{
y2mil("dev:" << dev.c_str());
string reg = "^[ \t]*[^ \t]+[ \t]+" + dev + "[ \t]";
- Regex fi( reg );
- lineno = tab.find( fi );
+ lineno = tab.find_if(regex_matches(reg));
y2mil("reg:" << reg << " lineno:" << lineno);
return( lineno>=0 );
}
Modified: trunk/storage/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.cc?rev=55952&r1=55951&r2=55952&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Storage.cc (original)
+++ trunk/storage/libstorage/src/Storage.cc Thu Mar 5 19:02:32 2009
@@ -135,11 +135,10 @@
if( access( "/etc/sysconfig/storage", R_OK )==0 )
{
AsciiFile sc( "/etc/sysconfig/storage" );
- Regex r('^' + Regex::ws + "DEVICE_NAMES" + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
- int line = sc.find( r );
- if( line >= 0 )
+ Regex rx('^' + Regex::ws + "DEVICE_NAMES" + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
+ if (sc.find_if(regex_matches(rx)) >= 0)
{
- string val = boost::to_lower_copy(r.cap(2), locale::classic());
+ string val = boost::to_lower_copy(rx.cap(2), locale::classic());
if( val == "id" )
setDefaultMountBy( MOUNTBY_ID );
else if( val == "path" )
@@ -340,7 +339,7 @@
if( proc_arch == "ppc" )
{
AsciiFile cpu( "/proc/cpuinfo" );
- int l = cpu.find( "^machine\t" );
+ int l = cpu.find_if(string_starts_with("machine\t"));
y2mil("line:" << l);
if( l >= 0 )
{
@@ -805,21 +804,23 @@
}
}
+
void
Storage::detectFsDataTestMode( const string& file, const VolIterator& begin,
const VolIterator& end )
- {
+{
AsciiFile vd( file );
for( VolIterator i=begin; i!=end; ++i )
+ {
+ int pos = vd.find_if(string_starts_with(i->device() + " "));
+ if (pos >= 0)
{
- int pos = -1;
- if( (pos=vd.find( "^"+i->device()+" " ))>=0 )
- {
i->getTestmodeData( vd[pos] );
- }
- i->getFstabData( *fstab );
}
+ i->getFstabData( *fstab );
}
+}
+
void
Storage::logVolumes( const string& Dir )
@@ -4623,8 +4624,9 @@
}
-void Storage::logProcData( const string& l )
- {
+void
+Storage::logProcData( const string& l )
+{
y2mil( "begin:" << l );
ProcPart t;
AsciiFile md( "/proc/mdstat" );
@@ -4634,7 +4636,7 @@
for( unsigned i=0; i