]>
git.saurik.com Git - apt.git/blob - ftparchive/override.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: override.cc,v 1.4 2003/02/10 07:34:41 doogie Exp $
4 /* ######################################################################
8 Store the override file.
10 ##################################################################### */
12 // Include Files /*{{{*/
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/error.h>
25 // Override::ReadOverride - Read the override file /*{{{*/
26 // ---------------------------------------------------------------------
27 /* This parses the override file and reads it into the map */
28 bool Override::ReadOverride(string
const &File
,bool const &Source
)
30 if (File
.empty() == true)
33 FILE *F
= fopen(File
.c_str(),"r");
35 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
38 unsigned long long Counter
= 0;
39 while (fgets(Line
,sizeof(Line
),F
) != 0)
45 for (char *I
= Line
; *I
!= 0; I
++)
49 // Strip space leading up to the package name, skip blank lines
51 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
55 #define APT_FIND_NEXT_FIELD \
56 for (End++; isspace(*End) != 0 && *End != 0; ++End) \
59 for (; isspace(*End) == 0 && *End != 0; ++End) \
60 /* find end of word */ ;
62 #define APT_WARNING_MALFORMED_LINE(FIELD) \
65 _error->Warning(_("Malformed override %s line %llu (%s)"),File.c_str(), \
71 // Find the package and zero..
74 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
75 APT_WARNING_MALFORMED_LINE("pkgname");
82 APT_WARNING_MALFORMED_LINE("priority");
89 APT_WARNING_MALFORMED_LINE("section");
90 Itm
.FieldOverride
["Section"] = Start
;
92 // Source override files only have the two columns
100 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
104 for (; *End
!= 0 && (End
[0] != '=' || End
[1] != '>'); End
++);
105 if (*End
== 0 || strlen(End
) < 4)
108 Itm
.NewMaint
= _strstrip(Start
);
113 Itm
.OldMaint
= _strstrip(Start
);
116 Itm
.NewMaint
= _strstrip(End
);
124 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
129 // Override::ReadExtraOverride - Read the extra override file /*{{{*/
130 // ---------------------------------------------------------------------
131 /* This parses the extra override file and reads it into the map */
132 bool Override::ReadExtraOverride(string
const &File
,bool const &Source
)
134 if (File
.empty() == true)
137 FILE *F
= fopen(File
.c_str(),"r");
139 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
142 unsigned long long Counter
= 0;
143 while (fgets(Line
,sizeof(Line
),F
) != 0)
148 for (char *I
= Line
; *I
!= 0; I
++)
152 // Strip space leading up to the package name, skip blank lines
154 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
158 // Find the package and zero..
160 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
163 _error
->Warning(_("Malformed override %s line %llu #1"),File
.c_str(),
170 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
172 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
175 _error
->Warning(_("Malformed override %s line %llu #2"),File
.c_str(),
181 // Find the field value
182 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
184 for (; *End
!= 0; End
++);
185 for (; isspace(*(End
-1)) && End
> Value
; End
--);
188 _error
->Warning(_("Malformed override %s line %llu #3"),File
.c_str(),
194 Mapping
[Pkg
].FieldOverride
[Field
] = Value
;
198 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
204 // Override::GetItem - Get a architecture specific item /*{{{*/
205 // ---------------------------------------------------------------------
206 /* Returns a override item for the given package and the given architecture.
207 * Treats "all" special
209 Override::Item
* Override::GetItem(string
const &Package
, string
const &Architecture
)
211 map
<string
,Item
>::const_iterator I
= Mapping
.find(Package
);
212 map
<string
,Item
>::iterator J
= Mapping
.find(Package
+ "/" + Architecture
);
214 if (I
== Mapping
.end() && J
== Mapping
.end())
219 Item
*result
= new Item
;
220 if (I
== Mapping
.end()) *result
= J
->second
;
224 if (J
!= Mapping
.end())
226 Item
*R
= &J
->second
;
227 if (R
->Priority
!= "") result
->Priority
= R
->Priority
;
228 if (R
->OldMaint
!= "") result
->OldMaint
= R
->OldMaint
;
229 if (R
->NewMaint
!= "") result
->NewMaint
= R
->NewMaint
;
230 for (map
<string
,string
>::const_iterator foI
= R
->FieldOverride
.begin();
231 foI
!= R
->FieldOverride
.end(); ++foI
)
233 result
->FieldOverride
[foI
->first
] = foI
->second
;
241 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
242 // ---------------------------------------------------------------------
243 /* Returns the new maintainer string after evaluating the rewriting rule. If
244 there is a rule but it does not match then the empty string is returned,
245 also if there was no rewrite rule the empty string is returned. Failed
246 indicates if there was some kind of problem while rewriting. */
247 string
Override::Item::SwapMaint(string
const &Orig
,bool &Failed
)
252 if (NewMaint
.empty() == true)
258 /* James: ancient, eliminate it, however it is still being used in the main
259 override file. Thus it persists.*/
261 // Break OldMaint up into little bits on double slash boundaries.
262 string::const_iterator End
= OldMaint
.begin();
265 string::const_iterator Start
= End
;
266 for (; End
< OldMaint
.end() &&
267 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
268 End
[1] != '/' || End
[2] != '/'); ++End
);
269 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
272 if (End
>= OldMaint
.end())
275 // Skip the divider and white space
276 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); ++End
);
279 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)