[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdegraphics/kfile-plugins/ps
From:       Luís Pedro Coelho <luis () luispedro ! org>
Date:       2004-03-05 1:29:20
Message-ID: 20040305012920.D1119995A () office ! kde ! org
[Download RAW message or body]

CVS commit by luis_pedro: 

Fix bug 75861 (will backport to BRANCH and close):
	The return value of scanData must be checked.

Also, exit early if we already have the information we want.


  M +24 -20    kfile_ps.cpp   1.11
  M +2 -2      kfile_ps.h   1.5


--- kdegraphics/kfile-plugins/ps/kfile_ps.cpp  #1.10:1.11
@@ -53,9 +53,9 @@ bool KPSPlugin::readInfo( KFileMetaInfo&
     _info = info;
     _group = appendGroup(info, "General");
-    _dsc = new KDSC;
     _endComments = false;
-    _setData = false;
-    _dsc->setCommentHandler( this );
+    _setData = 0;
 
+    _dsc = new KDSC;
+    _dsc->setCommentHandler( this );
     FILE* fp = fopen( QFile::encodeName( info.path() ), "r" );
     if( fp == 0 )
@@ -64,8 +64,7 @@ bool KPSPlugin::readInfo( KFileMetaInfo&
     char buf[4096];
     int count;
-    while( ( count = fread( buf, sizeof(char), 4096, fp ) ) != 0
-        && !_endComments )
-    {
-        _dsc->scanData( buf, count );
+    while( ( count = fread( buf, sizeof(char), sizeof( buf ), fp ) ) ) {
+            if ( !_dsc->scanData( buf, count ) ) break;
+            if ( _endComments || _setData == 5 ) break; // Change if new item scanned
     }
     fclose( fp );
@@ -74,37 +72,42 @@ bool KPSPlugin::readInfo( KFileMetaInfo&
     _dsc = 0;
     
-    return _setData;
+    return _setData > 0;
 }  
 
 void KPSPlugin::comment( Name name )
 {
-    int pages;
-
     switch( name )
     {
     case Title:
         appendItem(_group, "Title", _dsc->dsc_title());
-        _setData = true;
+        ++_setData;
     break;
     case Creator:
         appendItem(_group, "Creator", _dsc->dsc_creator());
-        _setData = true;
+        ++_setData;
     break;
     case CreationDate:
         appendItem(_group, "CreationDate", _dsc->dsc_date());
-        _setData = true;
+        ++_setData;
     break;
     case For:
         appendItem(_group, "For", _dsc->dsc_for());
-        _setData = true;
+        ++_setData;
     break;
-    case Pages:
-        pages = _dsc->page_pages();
+    case Pages: {
+        int pages = _dsc->page_pages();
         if (pages)
         {
             appendItem(_group, "Pages", pages);
-            _setData = true;
+            ++_setData;
+        }
         }
     break;
+    
+    // Right now we watch for 5 elements:
+    //  Title, Creator, CreationDate, For, Pages
+    //
+    // If you add another one(s), please update the 5 in "_setData == 5" above
+    //
     case EndComments: _endComments = true;
     default: ; // Ignore

--- kdegraphics/kfile-plugins/ps/kfile_ps.h  #1.4:1.5
@@ -44,5 +44,5 @@ private:
     KDSC* _dsc;
     bool _endComments;
-    bool _setData;
+    int _setData;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic