]> git.saurik.com Git - apt.git/blame - apt-pkg/indexfile.cc
* methods/http.cc:
[apt.git] / apt-pkg / indexfile.cc
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7db98ffc 3// $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
b2e465d6
AL
4/* ######################################################################
5
6 Index File - Abstraction for an index of archive/souce file.
7
8 ##################################################################### */
9 /*}}}*/
10// Include Files /*{{{*/
a52f938b 11#include <apt-pkg/configuration.h>
b2e465d6
AL
12#include <apt-pkg/indexfile.h>
13#include <apt-pkg/error.h>
a52f938b
OS
14
15#include <clocale>
4f333a8b 16#include <cstring>
b2e465d6
AL
17 /*}}}*/
18
19// Global list of Item supported
20static pkgIndexFile::Type *ItmList[10];
21pkgIndexFile::Type **pkgIndexFile::Type::GlobalList = ItmList;
22unsigned long pkgIndexFile::Type::GlobalListLen = 0;
23
24// Type::Type - Constructor /*{{{*/
25// ---------------------------------------------------------------------
26/* */
27pkgIndexFile::Type::Type()
28{
29 ItmList[GlobalListLen] = this;
30 GlobalListLen++;
31}
32 /*}}}*/
33// Type::GetType - Locate the type by name /*{{{*/
34// ---------------------------------------------------------------------
35/* */
36pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
37{
38 for (unsigned I = 0; I != GlobalListLen; I++)
39 if (strcmp(GlobalList[I]->Label,Type) == 0)
40 return GlobalList[I];
41 return 0;
42}
43 /*}}}*/
b2e465d6
AL
44// IndexFile::ArchiveInfo - Stub /*{{{*/
45// ---------------------------------------------------------------------
46/* */
47string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver) const
48{
49 return string();
50}
51 /*}}}*/
52// IndexFile::FindInCache - Stub /*{{{*/
53// ---------------------------------------------------------------------
54/* */
55pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
56{
57 return pkgCache::PkgFileIterator(Cache);
58}
59 /*}}}*/
60// IndexFile::SourceIndex - Stub /*{{{*/
61// ---------------------------------------------------------------------
62/* */
63string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &Record,
64 pkgSrcRecords::File const &File) const
65{
66 return string();
67}
68 /*}}}*/
770c32ec 69// IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
a52f938b
OS
70// ---------------------------------------------------------------------
71/* */
770c32ec 72bool pkgIndexFile::TranslationsAvailable()
a52f938b
OS
73{
74 const string Translation = _config->Find("APT::Acquire::Translation");
75
76 if (Translation.compare("none") != 0)
77 return CheckLanguageCode(LanguageCode().c_str());
78 else
79 return false;
80}
81 /*}}}*/
82// IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
83// ---------------------------------------------------------------------
84/* */
0430b189
MV
85/* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro,
86 de_DE.ISO8859-1, tig_ER
87 more in /etc/gdm/locale.conf
0430b189
MV
88*/
89
a52f938b
OS
90bool pkgIndexFile::CheckLanguageCode(const char *Lang)
91{
0d6c5e7d
MV
92 if (strlen(Lang) == 2 ||
93 strlen(Lang) == 3 ||
94 (strlen(Lang) > 3 && Lang[3] == '_') ||
95 (strlen(Lang) == 5 && Lang[2] == '_'))
96 return true;
a52f938b
OS
97
98 if (strcmp(Lang,"C") != 0)
99 _error->Warning("Wrong language code %s", Lang);
100
101 return false;
102}
103 /*}}}*/
104// IndexFile::LanguageCode - Return the Language Code /*{{{*/
105// ---------------------------------------------------------------------
770c32ec 106/* return the language code */
a52f938b
OS
107string pkgIndexFile::LanguageCode()
108{
109 const string Translation = _config->Find("APT::Acquire::Translation");
110
770c32ec
MV
111 if (Translation.compare("environment") == 0)
112 {
0430b189 113 string lang = std::setlocale(LC_MESSAGES,NULL);
770c32ec 114
770c32ec
MV
115 // we have a mapping of the language codes that contains all the language
116 // codes that need the country code as well
117 // (like pt_BR, pt_PT, sv_SE, zh_*, en_*)
0d6c5e7d
MV
118 const char *need_full_langcode[] = { "cs_",
119 "en_",
120 "pt_",
121 "sv_",
122 "zh_",
123 NULL };
bc36c37b 124 for(const char **s = need_full_langcode;*s != NULL; s++)
e0c4f063
MV
125 if(lang.find(*s) == 0)
126 return lang.substr(0,5);
127
0d6c5e7d
MV
128 if(lang.find("_") != lang.npos)
129 return lang.substr(0, lang.find("_"));
8f400769
MV
130 else if(lang.find(".") != lang.npos)
131 return lang.substr(0, lang.find("."));
0430b189
MV
132 else
133 return lang;
134 }
a52f938b
OS
135 else
136 return Translation;
137}
138 /*}}}*/