]>
git.saurik.com Git - apt.git/blob - ftparchive/override.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: override.cc,v 1.2 2001/02/20 07:03:18 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(),
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::Item::SwapMaint - Swap the maintainer field if necessary /*{{{*/
136 // ---------------------------------------------------------------------
137 /* Returns the new maintainer string after evaluating the rewriting rule. If
138 there is a rule but it does not match then the empty string is returned,
139 also if there was no rewrite rule the empty string is returned. Failed
140 indicates if there was some kind of problem while rewriting. */
141 string
Override::Item::SwapMaint(string Orig
,bool &Failed
)
146 if (NewMaint
.empty() == true)
152 /* James: ancient, eliminate it, however it is still being used in the main
153 override file. Thus it persists.*/
155 // Break OldMaint up into little bits on double slash boundaries.
156 string::iterator End
= OldMaint
.begin();
159 string::iterator Start
= End
;
160 for (; End
< OldMaint
.end() &&
161 (End
+ 3 >= OldMaint
.end() || End
[0] != ' ' ||
162 End
[1] != '/' || End
[2] != '/'); End
++);
163 if (stringcasecmp(Start
,End
,Orig
.begin(),Orig
.end()) == 0)
166 if (End
>= OldMaint
.end())
169 // Skip the divider and white space
170 for (; End
< OldMaint
.end() && (*End
== '/' || *End
== ' '); End
++);
173 if (stringcasecmp(OldMaint
.begin(),OldMaint
.end(),Orig
.begin(),Orig
.end()) == 0)