]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexfile.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
4 /* ######################################################################
6 Index File - Abstraction for an index of archive/souce file.
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/configuration.h>
12 #include <apt-pkg/indexfile.h>
13 #include <apt-pkg/error.h>
19 // Global list of Item supported
20 static pkgIndexFile::Type
*ItmList
[10];
21 pkgIndexFile::Type
**pkgIndexFile::Type::GlobalList
= ItmList
;
22 unsigned long pkgIndexFile::Type::GlobalListLen
= 0;
24 // Type::Type - Constructor /*{{{*/
25 // ---------------------------------------------------------------------
27 pkgIndexFile::Type::Type()
29 ItmList
[GlobalListLen
] = this;
33 // Type::GetType - Locate the type by name /*{{{*/
34 // ---------------------------------------------------------------------
36 pkgIndexFile::Type
*pkgIndexFile::Type::GetType(const char *Type
)
38 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
39 if (strcmp(GlobalList
[I
]->Label
,Type
) == 0)
44 // IndexFile::ArchiveInfo - Stub /*{{{*/
45 // ---------------------------------------------------------------------
47 string
pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver
) const
52 // IndexFile::FindInCache - Stub /*{{{*/
53 // ---------------------------------------------------------------------
55 pkgCache::PkgFileIterator
pkgIndexFile::FindInCache(pkgCache
&Cache
) const
57 return pkgCache::PkgFileIterator(Cache
);
60 // IndexFile::SourceIndex - Stub /*{{{*/
61 // ---------------------------------------------------------------------
63 string
pkgIndexFile::SourceInfo(pkgSrcRecords::Parser
const &Record
,
64 pkgSrcRecords::File
const &File
) const
69 // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
70 // ---------------------------------------------------------------------
72 bool pkgIndexFile::TranslationsAvailable()
74 const string Translation
= _config
->Find("APT::Acquire::Translation");
76 if (Translation
.compare("none") != 0)
77 return CheckLanguageCode(LanguageCode().c_str());
82 // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
83 // ---------------------------------------------------------------------
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
90 bool pkgIndexFile::CheckLanguageCode(const char *Lang
)
92 if (strlen(Lang
) == 2 ||
94 (strlen(Lang
) > 3 && Lang
[3] == '_') ||
95 (strlen(Lang
) == 5 && Lang
[2] == '_'))
98 if (strcmp(Lang
,"C") != 0)
99 _error
->Warning("Wrong language code %s", Lang
);
104 // IndexFile::LanguageCode - Return the Language Code /*{{{*/
105 // ---------------------------------------------------------------------
106 /* return the language code */
107 string
pkgIndexFile::LanguageCode()
109 const string Translation
= _config
->Find("APT::Acquire::Translation");
111 if (Translation
.compare("environment") == 0)
113 string lang
= std::setlocale(LC_MESSAGES
,NULL
);
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_*)
118 const char *need_full_langcode
[] = { "cs_",
124 for(const char **s
= need_full_langcode
;*s
!= NULL
; s
++)
125 if(lang
.find(*s
) == 0)
126 return lang
.substr(0,5);
128 if(lang
.find("_") != lang
.npos
)
129 return lang
.substr(0, lang
.find("_"));