]>
git.saurik.com Git - apt.git/blob - ftparchive/override.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: override.cc,v 1.3 2001/06/26 02:50:27 jgg Exp $
4 /* ######################################################################
8 Store the override file.
10 ##################################################################### */
12 // Include Files /*{{{*/
14 #pragma implementation "override.h"
19 #include <apt-pkg/strutl.h>
20 #include <apt-pkg/error.h>
27 // Override::ReadOverride - Read the override file /*{{{*/
28 // ---------------------------------------------------------------------
29 /* This parses the override file and reads it into the map */
30 bool Override::ReadOverride(string File
,bool Source
)
32 if (File
.empty() == true)
35 FILE *F
= fopen(File
.c_str(),"r");
37 return _error
->Errno("fopen","Unable to open %s",File
.c_str());
40 unsigned long Counter
= 0;
41 while (fgets(Line
,sizeof(Line
),F
) != 0)
47 for (char *I
= Line
; *I
!= 0; I
++)
51 // Strip space leading up to the package name, skip blank lines
53 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
57 // Find the package and zero..
60 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
63 _error
->Warning("Malformed override %s line %lu #1",File
.c_str(),
72 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
74 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
77 _error
->Warning("Malformed override %s line %lu #2",File
.c_str(),
86 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
88 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
91 _error
->Warning("Malformed override %s line %lu #3",File
.c_str(),
96 Itm
.FieldOverride
["Section"] = Start
;
98 // Source override files only have the two columns
106 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
110 for (; *End
!= 0 && (End
[0] != '=' || End
[1] != '>'); End
++);
111 if (*End
== 0 || strlen(End
) < 4)
114 Itm
.NewMaint
= _strstrip(Start
);
119 Itm
.OldMaint
= _strstrip(Start
);
122 Itm
.NewMaint
= _strstrip(End
);
130 _error
->Errno("fgets","Failed to read the override file %s",File
.c_str());
135 // Override::ReadExtraOverride - Read the extra override file /*{{{*/
136 // ---------------------------------------------------------------------
137 /* This parses the extra override file and reads it into the map */
138 bool Override::ReadExtraOverride(string File
,bool Source
)
140 if (File
.empty() == true)
143 FILE *F
= fopen(File
.c_str(),"r");
145 return _error
->Errno("fopen","Unable to open %s",File
.c_str());
148 unsigned long Counter
= 0;
149 while (fgets(Line
,sizeof(Line
),F
) != 0)
154 for (char *I
= Line
; *I
!= 0; I
++)
158 // Strip space leading up to the package name, skip blank lines
160 for (; isspace(*Pkg
) && *Pkg
!= 0;Pkg
++);
164 // Find the package and zero..
166 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
169 _error
->Warning("Malformed override %s line %lu #1",File
.c_str(),
176 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
178 for (; isspace(*End
) == 0 && *End
!= 0; End
++);
181 _error
->Warning("Malformed override %s line %lu #2",File
.c_str(),
187 // Find the field value
188 for (End
++; isspace(*End
) != 0 && *End
!= 0; End
++);
190 for (; *End
!= 0; End
++);
191 for (; isspace(*(End
-1)) && End
> Value
; End
--);
194 _error
->Warning("Malformed override %s line %lu #3",File
.c_str(),
200 Mapping
[Pkg
].FieldOverride
[Field
] = Value
;
204 _error
->Errno("fgets","Failed to read the override file %s",File
.c_str());
209 // Override::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
210 // ---------------------------------------------------------------------
211 /* Returns the new maintainer string after evaluating the rewriting rule. If
212 there is a rule but it does not match then the empty string is returned,
213 also if there was no rewrite rule the empty string is returned. Failed
214 indicates if there was some kind of problem while rewriting. */
215 string
Override::Item::SwapMaint(string Orig
,bool &Failed
)
220 if (NewMaint
.empty() == true)
226 /* James: ancient, eliminate it, however it is still being used in the main
227 override file. Thus it persists.*/
229 // Break OldMaint up into little bits on double slash boundaries.
230 string::iterator End
= OldMaint
.begin();
233 string::iterator Start
= End
;
234 for (; End
< OldMaint
.end() &&
235 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
236 End
[1] != '/' || End
[2] != '/'); End
++);
237 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
240 if (End
>= OldMaint
.end())
243 // Skip the divider and white space
244 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); End
++);
247 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)