]>
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 /*{{{*/
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());
210 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
211 // ---------------------------------------------------------------------
212 /* Returns the new maintainer string after evaluating the rewriting rule. If
213 there is a rule but it does not match then the empty string is returned,
214 also if there was no rewrite rule the empty string is returned. Failed
215 indicates if there was some kind of problem while rewriting. */
216 string
Override::Item::SwapMaint(string Orig
,bool &Failed
)
221 if (NewMaint
.empty() == true)
227 /* James: ancient, eliminate it, however it is still being used in the main
228 override file. Thus it persists.*/
230 // Break OldMaint up into little bits on double slash boundaries.
231 string::iterator End
= OldMaint
.begin();
234 string::iterator Start
= End
;
235 for (; End
< OldMaint
.end() &&
236 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
237 End
[1] != '/' || End
[2] != '/'); End
++);
238 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
241 if (End
>= OldMaint
.end())
244 // Skip the divider and white space
245 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); End
++);
248 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)