]>
git.saurik.com Git - apt-legacy.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 /*{{{*/
14 #pragma implementation "override.h"
20 #include <apt-pkg/strutl.h>
21 #include <apt-pkg/error.h>
28 // Override::ReadOverride - Read the override file /*{{{*/
29 // ---------------------------------------------------------------------
30 /* This parses the override file and reads it into the map */
31 bool Override::ReadOverride(string File
,bool Source
)
33 if (File
.empty() == true)
36 FILE *F
= fopen(File
.c_str(),"r");
38 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
41 unsigned long Counter
= 0;
42 while (fgets(Line
,sizeof(Line
),F
) != 0)
48 for (char *I
= Line
; *I
!= 0; I
++)
52 // Strip space leading up to the package name, skip blank lines
54 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
58 // Find the package and zero..
61 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
64 _error
->Warning(_("Malformed override %s line %lu #1"),File
.c_str(),
73 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
75 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
78 _error
->Warning(_("Malformed override %s line %lu #2"),File
.c_str(),
87 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
89 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
92 _error
->Warning(_("Malformed override %s line %lu #3"),File
.c_str(),
97 Itm
.FieldOverride
["Section"] = Start
;
99 // Source override files only have the two columns
107 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
111 for (; *End
!= 0 && (End
[0] != '=' || End
[1] != '>'); End
++);
112 if (*End
== 0 || strlen(End
) < 4)
115 Itm
.NewMaint
= _strstrip(Start
);
120 Itm
.OldMaint
= _strstrip(Start
);
123 Itm
.NewMaint
= _strstrip(End
);
131 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
136 // Override::ReadExtraOverride - Read the extra override file /*{{{*/
137 // ---------------------------------------------------------------------
138 /* This parses the extra override file and reads it into the map */
139 bool Override::ReadExtraOverride(string File
,bool Source
)
141 if (File
.empty() == true)
144 FILE *F
= fopen(File
.c_str(),"r");
146 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
149 unsigned long Counter
= 0;
150 while (fgets(Line
,sizeof(Line
),F
) != 0)
155 for (char *I
= Line
; *I
!= 0; I
++)
159 // Strip space leading up to the package name, skip blank lines
161 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
165 // Find the package and zero..
167 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
170 _error
->Warning(_("Malformed override %s line %lu #1"),File
.c_str(),
177 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
179 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
182 _error
->Warning(_("Malformed override %s line %lu #2"),File
.c_str(),
188 // Find the field value
189 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
191 for (; *End
!= 0; End
++);
192 for (; isspace(*(End
-1)) && End
> Value
; End
--);
195 _error
->Warning(_("Malformed override %s line %lu #3"),File
.c_str(),
201 Mapping
[Pkg
].FieldOverride
[Field
] = Value
;
205 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
211 // Override::GetItem - Get a architecture specific item /*{{{*/
212 // ---------------------------------------------------------------------
213 /* Returns a override item for the given package and the given architecture.
214 * Treats "all" special
216 Override::Item
* Override::GetItem(string Package
, string Architecture
)
218 map
<string
,Item
>::iterator I
= Mapping
.find(Package
);
219 map
<string
,Item
>::iterator J
= Mapping
.find(Package
+ "/" + Architecture
);
221 if (I
== Mapping
.end() && J
== Mapping
.end())
226 Item
*result
= new Item
;
227 if (I
== Mapping
.end()) *result
= J
->second
;
231 if (J
!= Mapping
.end())
233 Item
*R
= &J
->second
;
234 if (R
->Priority
!= "") result
->Priority
= R
->Priority
;
235 if (R
->OldMaint
!= "") result
->OldMaint
= R
->OldMaint
;
236 if (R
->NewMaint
!= "") result
->NewMaint
= R
->NewMaint
;
237 for (map
<string
,string
>::iterator foI
= R
->FieldOverride
.begin();
238 foI
!= R
->FieldOverride
.end(); foI
++)
240 result
->FieldOverride
[foI
->first
] = foI
->second
;
248 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
249 // ---------------------------------------------------------------------
250 /* Returns the new maintainer string after evaluating the rewriting rule. If
251 there is a rule but it does not match then the empty string is returned,
252 also if there was no rewrite rule the empty string is returned. Failed
253 indicates if there was some kind of problem while rewriting. */
254 string
Override::Item::SwapMaint(string Orig
,bool &Failed
)
259 if (NewMaint
.empty() == true)
265 /* James: ancient, eliminate it, however it is still being used in the main
266 override file. Thus it persists.*/
268 // Break OldMaint up into little bits on double slash boundaries.
269 string::iterator End
= OldMaint
.begin();
272 string::iterator Start
= End
;
273 for (; End
< OldMaint
.end() &&
274 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
275 End
[1] != '/' || End
[2] != '/'); End
++);
276 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
279 if (End
>= OldMaint
.end())
282 // Skip the divider and white space
283 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); End
++);
286 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)