merged -r1901..1911 from lp:~donkult/apt/sid
[ntk/apt.git] / ftparchive / override.cc
index 40047c5..6f40bc8 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: override.cc,v 1.3 2001/06/26 02:50:27 jgg Exp $
+// $Id: override.cc,v 1.4 2003/02/10 07:34:41 doogie Exp $
 /* ######################################################################
 
    Override
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "override.h"
-#endif
-
 #include "override.h"
     
+#include <apti18n.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
 
@@ -34,7 +31,7 @@ bool Override::ReadOverride(string File,bool Source)
    
    FILE *F = fopen(File.c_str(),"r");
    if (F == 0)
-      return _error->Errno("fopen","Unable to open %s",File.c_str());
+      return _error->Errno("fopen",_("Unable to open %s"),File.c_str());
    
    char Line[500];
    unsigned long Counter = 0;
@@ -60,7 +57,7 @@ bool Override::ReadOverride(string File,bool Source)
       for (; isspace(*End) == 0 && *End != 0; End++);
       if (*End == 0)
       {
-        _error->Warning("Malformed override %s line %lu #1",File.c_str(),
+        _error->Warning(_("Malformed override %s line %lu #1"),File.c_str(),
                         Counter);
         continue;
       }      
@@ -74,7 +71,7 @@ bool Override::ReadOverride(string File,bool Source)
         for (; isspace(*End) == 0 && *End != 0; End++);
         if (*End == 0)
         {
-           _error->Warning("Malformed override %s line %lu #2",File.c_str(),
+           _error->Warning(_("Malformed override %s line %lu #2"),File.c_str(),
                            Counter);
            continue;
         }
@@ -88,7 +85,7 @@ bool Override::ReadOverride(string File,bool Source)
       for (; isspace(*End) == 0 && *End != 0; End++);
       if (*End == 0)
       {
-        _error->Warning("Malformed override %s line %lu #3",File.c_str(),
+        _error->Warning(_("Malformed override %s line %lu #3"),File.c_str(),
                         Counter);
         continue;
       }      
@@ -127,7 +124,7 @@ bool Override::ReadOverride(string File,bool Source)
    }
 
    if (ferror(F))
-      _error->Errno("fgets","Failed to read the override file %s",File.c_str());
+      _error->Errno("fgets",_("Failed to read the override file %s"),File.c_str());
    fclose(F);
    return true;
 }
@@ -142,7 +139,7 @@ bool Override::ReadExtraOverride(string File,bool Source)
    
    FILE *F = fopen(File.c_str(),"r");
    if (F == 0)
-      return _error->Errno("fopen","Unable to open %s",File.c_str());
+      return _error->Errno("fopen",_("Unable to open %s"),File.c_str());
   
    char Line[500];
    unsigned long Counter = 0;
@@ -166,7 +163,7 @@ bool Override::ReadExtraOverride(string File,bool Source)
       for (; isspace(*End) == 0 && *End != 0; End++);
       if (*End == 0)
       {
-        _error->Warning("Malformed override %s line %lu #1",File.c_str(),
+        _error->Warning(_("Malformed override %s line %lu #1"),File.c_str(),
                         Counter);
         continue;
       }      
@@ -178,7 +175,7 @@ bool Override::ReadExtraOverride(string File,bool Source)
       for (; isspace(*End) == 0 && *End != 0; End++);
       if (*End == 0)
       {
-        _error->Warning("Malformed override %s line %lu #2",File.c_str(),
+        _error->Warning(_("Malformed override %s line %lu #2"),File.c_str(),
                         Counter);
         continue;
       }
@@ -191,7 +188,7 @@ bool Override::ReadExtraOverride(string File,bool Source)
       for (; isspace(*(End-1)) && End > Value; End--);
       if (End == Value)
       {
-        _error->Warning("Malformed override %s line %lu #3",File.c_str(),
+        _error->Warning(_("Malformed override %s line %lu #3"),File.c_str(),
                         Counter);
         continue;
       }      
@@ -201,11 +198,49 @@ bool Override::ReadExtraOverride(string File,bool Source)
    }
 
    if (ferror(F))
-      _error->Errno("fgets","Failed to read the override file %s",File.c_str());
+      _error->Errno("fgets",_("Failed to read the override file %s"),File.c_str());
    fclose(F);
    return true;
 }
                                                                        /*}}}*/
+
+// Override::GetItem - Get a architecture specific item        /*{{{*/
+// ---------------------------------------------------------------------
+/* Returns a override item for the given package and the given architecture.
+ * Treats "all" special
+ */
+Override::Item* Override::GetItem(string Package, string Architecture)
+{
+   map<string,Item>::iterator I = Mapping.find(Package);
+   map<string,Item>::iterator J = Mapping.find(Package + "/" + Architecture);
+
+   if (I == Mapping.end() && J == Mapping.end())
+   {
+      return 0;
+   }
+
+   Item *result = new Item;
+   if (I == Mapping.end()) *result = J->second;
+   else
+   {
+      *result = I->second;
+      if (J != Mapping.end())
+      {
+        Item *R = &J->second;
+        if (R->Priority != "") result->Priority = R->Priority;
+        if (R->OldMaint != "") result->OldMaint = R->OldMaint;
+        if (R->NewMaint != "") result->NewMaint = R->NewMaint;
+        for (map<string,string>::iterator foI = R->FieldOverride.begin();
+             foI != R->FieldOverride.end(); foI++)
+         {
+           result->FieldOverride[foI->first] = foI->second;
+        }
+      } 
+   } 
+   return result;
+};
+
+
 // Override::Item::SwapMaint - Swap the maintainer field if necessary  /*{{{*/
 // ---------------------------------------------------------------------
 /* Returns the new maintainer string after evaluating the rewriting rule. If