]>
git.saurik.com Git - apt.git/blob - ftparchive/override.cc
1288ff133483c83fb9289520649bb26a12e6aa55
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 // Find the package and zero..
58 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
61 _error
->Warning(_("Malformed override %s line %llu #1"),File
.c_str(),
70 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
72 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
75 _error
->Warning(_("Malformed override %s line %llu #2"),File
.c_str(),
84 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
86 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
89 _error
->Warning(_("Malformed override %s line %llu #3"),File
.c_str(),
94 Itm
.FieldOverride
["Section"] = Start
;
96 // Source override files only have the two columns
104 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
108 for (; *End
!= 0 && (End
[0] != '=' || End
[1] != '>'); End
++);
109 if (*End
== 0 || strlen(End
) < 4)
112 Itm
.NewMaint
= _strstrip(Start
);
117 Itm
.OldMaint
= _strstrip(Start
);
120 Itm
.NewMaint
= _strstrip(End
);
128 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
133 // Override::ReadExtraOverride - Read the extra override file /*{{{*/
134 // ---------------------------------------------------------------------
135 /* This parses the extra override file and reads it into the map */
136 bool Override::ReadExtraOverride(string
const &File
,bool const &Source
)
138 if (File
.empty() == true)
141 FILE *F
= fopen(File
.c_str(),"r");
143 return _error
->Errno("fopen",_("Unable to open %s"),File
.c_str());
146 unsigned long long Counter
= 0;
147 while (fgets(Line
,sizeof(Line
),F
) != 0)
152 for (char *I
= Line
; *I
!= 0; I
++)
156 // Strip space leading up to the package name, skip blank lines
158 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
162 // Find the package and zero..
164 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
167 _error
->Warning(_("Malformed override %s line %llu #1"),File
.c_str(),
174 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
176 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
179 _error
->Warning(_("Malformed override %s line %llu #2"),File
.c_str(),
185 // Find the field value
186 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
188 for (; *End
!= 0; End
++);
189 for (; isspace(*(End
-1)) && End
> Value
; End
--);
192 _error
->Warning(_("Malformed override %s line %llu #3"),File
.c_str(),
198 Mapping
[Pkg
].FieldOverride
[Field
] = Value
;
202 _error
->Errno("fgets",_("Failed to read the override file %s"),File
.c_str());
208 // Override::GetItem - Get a architecture specific item /*{{{*/
209 // ---------------------------------------------------------------------
210 /* Returns a override item for the given package and the given architecture.
211 * Treats "all" special
213 Override::Item
* Override::GetItem(string
const &Package
, string
const &Architecture
)
215 map
<string
,Item
>::const_iterator I
= Mapping
.find(Package
);
216 map
<string
,Item
>::iterator J
= Mapping
.find(Package
+ "/" + Architecture
);
218 if (I
== Mapping
.end() && J
== Mapping
.end())
223 Item
*result
= new Item
;
224 if (I
== Mapping
.end()) *result
= J
->second
;
228 if (J
!= Mapping
.end())
230 Item
*R
= &J
->second
;
231 if (R
->Priority
!= "") result
->Priority
= R
->Priority
;
232 if (R
->OldMaint
!= "") result
->OldMaint
= R
->OldMaint
;
233 if (R
->NewMaint
!= "") result
->NewMaint
= R
->NewMaint
;
234 for (map
<string
,string
>::const_iterator foI
= R
->FieldOverride
.begin();
235 foI
!= R
->FieldOverride
.end(); ++foI
)
237 result
->FieldOverride
[foI
->first
] = foI
->second
;
245 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
246 // ---------------------------------------------------------------------
247 /* Returns the new maintainer string after evaluating the rewriting rule. If
248 there is a rule but it does not match then the empty string is returned,
249 also if there was no rewrite rule the empty string is returned. Failed
250 indicates if there was some kind of problem while rewriting. */
251 string
Override::Item::SwapMaint(string
const &Orig
,bool &Failed
)
256 if (NewMaint
.empty() == true)
262 /* James: ancient, eliminate it, however it is still being used in the main
263 override file. Thus it persists.*/
265 // Break OldMaint up into little bits on double slash boundaries.
266 string::const_iterator End
= OldMaint
.begin();
269 string::const_iterator Start
= End
;
270 for (; End
< OldMaint
.end() &&
271 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
272 End
[1] != '/' || End
[2] != '/'); ++End
);
273 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
276 if (End
>= OldMaint
.end())
279 // Skip the divider and white space
280 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); ++End
);
283 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)