]>
git.saurik.com Git - apt.git/blob - ftparchive/override.cc
045a8b1132608f7263cee627ee5411b98b734b5f
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 /*{{{*/
16 #include <apt-pkg/strutl.h>
17 #include <apt-pkg/error.h>
24 // Override::ReadOverride - Read the override file /*{{{*/
25 // ---------------------------------------------------------------------
26 /* This parses the override file and reads it into the map */
27 bool Override::ReadOverride(string
const &File
,bool const &Source
)
29 if (File
.empty() == true)
32 FILE *F
= fopen(File
.c_str(),"r");
34 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
37 unsigned long Counter
= 0;
38 while (fgets(Line
,sizeof(Line
),F
) != 0)
44 for (char *I
= Line
; *I
!= 0; I
++)
48 // Strip space leading up to the package name, skip blank lines
50 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
54 // Find the package and zero..
57 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
60 _error
->Warning(_("Malformed override %s line %lu #1"),File
.c_str(),
69 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
71 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
74 _error
->Warning(_("Malformed override %s line %lu #2"),File
.c_str(),
83 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
85 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
88 _error
->Warning(_("Malformed override %s line %lu #3"),File
.c_str(),
93 Itm
.FieldOverride
["Section"] = Start
;
95 // Source override files only have the two columns
103 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
107 for (; *End
!= 0 && (End
[0] != '=' || End
[1] != '>'); End
++);
108 if (*End
== 0 || strlen(End
) < 4)
111 Itm
.NewMaint
= _strstrip(Start
);
116 Itm
.OldMaint
= _strstrip(Start
);
119 Itm
.NewMaint
= _strstrip(End
);
127 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
132 // Override::ReadExtraOverride - Read the extra override file /*{{{*/
133 // ---------------------------------------------------------------------
134 /* This parses the extra override file and reads it into the map */
135 bool Override::ReadExtraOverride(string
const &File
,bool const &Source
)
137 if (File
.empty() == true)
140 FILE *F
= fopen(File
.c_str(),"r");
142 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
145 unsigned long Counter
= 0;
146 while (fgets(Line
,sizeof(Line
),F
) != 0)
151 for (char *I
= Line
; *I
!= 0; I
++)
155 // Strip space leading up to the package name, skip blank lines
157 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
161 // Find the package and zero..
163 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
166 _error
->Warning(_("Malformed override %s line %lu #1"),File
.c_str(),
173 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
175 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
178 _error
->Warning(_("Malformed override %s line %lu #2"),File
.c_str(),
184 // Find the field value
185 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
187 for (; *End
!= 0; End
++);
188 for (; isspace(*(End
-1)) && End
> Value
; End
--);
191 _error
->Warning(_("Malformed override %s line %lu #3"),File
.c_str(),
197 Mapping
[Pkg
].FieldOverride
[Field
] = Value
;
201 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
207 // Override::GetItem - Get a architecture specific item /*{{{*/
208 // ---------------------------------------------------------------------
209 /* Returns a override item for the given package and the given architecture.
210 * Treats "all" special
212 Override::Item
* Override::GetItem(string
const &Package
, string
const &Architecture
)
214 map
<string
,Item
>::const_iterator I
= Mapping
.find(Package
);
215 map
<string
,Item
>::iterator J
= Mapping
.find(Package
+ "/" + Architecture
);
217 if (I
== Mapping
.end() && J
== Mapping
.end())
222 Item
*result
= new Item
;
223 if (I
== Mapping
.end()) *result
= J
->second
;
227 if (J
!= Mapping
.end())
229 Item
*R
= &J
->second
;
230 if (R
->Priority
!= "") result
->Priority
= R
->Priority
;
231 if (R
->OldMaint
!= "") result
->OldMaint
= R
->OldMaint
;
232 if (R
->NewMaint
!= "") result
->NewMaint
= R
->NewMaint
;
233 for (map
<string
,string
>::const_iterator foI
= R
->FieldOverride
.begin();
234 foI
!= R
->FieldOverride
.end(); foI
++)
236 result
->FieldOverride
[foI
->first
] = foI
->second
;
244 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
245 // ---------------------------------------------------------------------
246 /* Returns the new maintainer string after evaluating the rewriting rule. If
247 there is a rule but it does not match then the empty string is returned,
248 also if there was no rewrite rule the empty string is returned. Failed
249 indicates if there was some kind of problem while rewriting. */
250 string
Override::Item::SwapMaint(string
const &Orig
,bool &Failed
)
255 if (NewMaint
.empty() == true)
261 /* James: ancient, eliminate it, however it is still being used in the main
262 override file. Thus it persists.*/
264 // Break OldMaint up into little bits on double slash boundaries.
265 string::const_iterator End
= OldMaint
.begin();
268 string::const_iterator Start
= End
;
269 for (; End
< OldMaint
.end() &&
270 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
271 End
[1] != '/' || End
[2] != '/'); End
++);
272 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
275 if (End
>= OldMaint
.end())
278 // Skip the divider and white space
279 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); End
++);
282 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)