-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index 64a9c26..9a239a5 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp @@ -21,10 +21,2 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <iostream> -#include <fstream> -using namespace std; - #include "server.h" @@ -32,2 +24,5 @@ using namespace std; +#include <qfile.h> +#include <qtextstream.h> + #ifdef QWS @@ -75,3 +70,3 @@ void Server :: readStatusFile( QList<Destination> &destList ) if ( path.right( 1 ) != "/" ) - path += "/"; + path.append( "/" ); @@ -83,3 +78,4 @@ void Server :: readStatusFile( QList<Destination> &destList ) - packageFile = path + "usr/lib/ipkg/status"; + packageFile = path; + packageFile.append( "usr/lib/ipkg/status" ); readPackageFile( 0, false, installingToRoot, &( *dest ) ); @@ -90,3 +86,3 @@ void Server :: readStatusFile( QList<Destination> &destList ) { - cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; + //cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; packageFile = "/usr/lib/ipkg/status"; @@ -148,11 +144,11 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR { - ifstream in( packageFile ); - if ( !in.is_open() ) + QFile f( packageFile ); + if ( !f.open( IO_ReadOnly ) ) return; + QTextStream t( &f ); - char line[5001]; - char k[21]; - char v[5001]; + QString line; QString key; QString value; + int pos; @@ -163,17 +159,13 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR bool newPackage = true; - do + while ( !t.eof() ) { - in.getline( line, 5000 ); - if ( in.eof() ) - continue; - - k[0] = '\0'; - v[0] = '\0'; - - sscanf( line, "%[^:]: %[^\n]", k, v ); + line = t.readLine(); - key = k; - value = v; - key = key.stripWhiteSpace(); - value = value.stripWhiteSpace(); + pos = line.find( ':', 0 ); + if ( pos > -1 ) + key = line.mid( 0, pos ).stripWhiteSpace(); + else + key = QString::null; + value = line.mid( pos+1, line.length()-pos ).stripWhiteSpace(); + if ( key == "Package" && newPackage ) @@ -230,3 +222,3 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR } - else if ( key == "" ) + else if ( key == QString::null ) { @@ -234,5 +226,5 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR } - } while ( !in.eof() ); + } - in.close(); + f.close(); |