X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b2e465d6d32d2dc884f58b94acb7e35f671a87fe..95f45727964767f11534eb5347af3fc3a8a6e020:/ftparchive/override.cc diff --git a/ftparchive/override.cc b/ftparchive/override.cc index 93cc34e85..6f40bc865 100644 --- a/ftparchive/override.cc +++ b/ftparchive/override.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: override.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $ +// $Id: override.cc,v 1.4 2003/02/10 07:34:41 doogie Exp $ /* ###################################################################### Override @@ -10,12 +10,9 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "override.h" -#endif - #include "override.h" +#include #include #include @@ -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,12 +85,12 @@ 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; } *End = 0; - Itm.Section = Start; + Itm.FieldOverride["Section"] = Start; // Source override files only have the two columns if (Source == true) @@ -127,11 +124,123 @@ 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; } /*}}}*/ +// Override::ReadExtraOverride - Read the extra override file /*{{{*/ +// --------------------------------------------------------------------- +/* This parses the extra override file and reads it into the map */ +bool Override::ReadExtraOverride(string File,bool Source) +{ + if (File.empty() == true) + return true; + + FILE *F = fopen(File.c_str(),"r"); + if (F == 0) + return _error->Errno("fopen",_("Unable to open %s"),File.c_str()); + + char Line[500]; + unsigned long Counter = 0; + while (fgets(Line,sizeof(Line),F) != 0) + { + Counter++; + + // Silence + for (char *I = Line; *I != 0; I++) + if (*I == '#') + *I = 0; + + // Strip space leading up to the package name, skip blank lines + char *Pkg = Line; + for (; isspace(*Pkg) && *Pkg != 0;Pkg++); + if (Pkg == 0) + continue; + + // Find the package and zero.. + char *End = Pkg; + for (; isspace(*End) == 0 && *End != 0; End++); + if (*End == 0) + { + _error->Warning(_("Malformed override %s line %lu #1"),File.c_str(), + Counter); + continue; + } + *End = 0; + + // Find the field + for (End++; isspace(*End) != 0 && *End != 0; End++); + char *Field = End; + for (; isspace(*End) == 0 && *End != 0; End++); + if (*End == 0) + { + _error->Warning(_("Malformed override %s line %lu #2"),File.c_str(), + Counter); + continue; + } + *End = 0; + + // Find the field value + for (End++; isspace(*End) != 0 && *End != 0; End++); + char *Value = End; + for (; *End != 0; End++); + for (; isspace(*(End-1)) && End > Value; End--); + if (End == Value) + { + _error->Warning(_("Malformed override %s line %lu #3"),File.c_str(), + Counter); + continue; + } + *End = 0; + + Mapping[Pkg].FieldOverride[Field] = Value; + } + + if (ferror(F)) + _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::iterator I = Mapping.find(Package); + map::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::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