]> git.saurik.com Git - apt.git/blame - apt-pkg/indexfile.cc
* merged the apt--DoListUpdate branch, this provides a common interface
[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 /*}}}*/
44
b2e465d6
AL
45// IndexFile::ArchiveInfo - Stub /*{{{*/
46// ---------------------------------------------------------------------
47/* */
48string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver) const
49{
50 return string();
51}
52 /*}}}*/
53// IndexFile::FindInCache - Stub /*{{{*/
54// ---------------------------------------------------------------------
55/* */
56pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
57{
58 return pkgCache::PkgFileIterator(Cache);
59}
60 /*}}}*/
61// IndexFile::SourceIndex - Stub /*{{{*/
62// ---------------------------------------------------------------------
63/* */
64string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &Record,
65 pkgSrcRecords::File const &File) const
66{
67 return string();
68}
69 /*}}}*/
770c32ec 70// IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
a52f938b
OS
71// ---------------------------------------------------------------------
72/* */
770c32ec 73bool pkgIndexFile::TranslationsAvailable()
a52f938b
OS
74{
75 const string Translation = _config->Find("APT::Acquire::Translation");
76
77 if (Translation.compare("none") != 0)
78 return CheckLanguageCode(LanguageCode().c_str());
79 else
80 return false;
81}
82 /*}}}*/
83// IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
84// ---------------------------------------------------------------------
85/* */
0430b189
MV
86/* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro,
87 de_DE.ISO8859-1, tig_ER
88 more in /etc/gdm/locale.conf
0430b189
MV
89*/
90
a52f938b
OS
91bool pkgIndexFile::CheckLanguageCode(const char *Lang)
92{
93 if (strlen(Lang) == 2 || (strlen(Lang) == 5 && Lang[2] == '_'))
94 return true;
95
96 if (strcmp(Lang,"C") != 0)
97 _error->Warning("Wrong language code %s", Lang);
98
99 return false;
100}
101 /*}}}*/
102// IndexFile::LanguageCode - Return the Language Code /*{{{*/
103// ---------------------------------------------------------------------
770c32ec 104/* return the language code */
a52f938b
OS
105string pkgIndexFile::LanguageCode()
106{
107 const string Translation = _config->Find("APT::Acquire::Translation");
108
770c32ec
MV
109 if (Translation.compare("environment") == 0)
110 {
0430b189 111 string lang = std::setlocale(LC_MESSAGES,NULL);
770c32ec 112
770c32ec
MV
113 // we have a mapping of the language codes that contains all the language
114 // codes that need the country code as well
115 // (like pt_BR, pt_PT, sv_SE, zh_*, en_*)
bc36c37b
OS
116 const char *need_full_langcode[] = { "pt","sv","zh","en", NULL };
117 for(const char **s = need_full_langcode;*s != NULL; s++)
e0c4f063
MV
118 if(lang.find(*s) == 0)
119 return lang.substr(0,5);
120
0430b189
MV
121 if(lang.size() > 2)
122 return lang.substr(0,2);
123 else
124 return lang;
125 }
a52f938b
OS
126 else
127 return Translation;
128}
129 /*}}}*/