]>
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 /*{{{*/
12 #pragma implementation "apt-pkg/indexfile.h"
15 #include <apt-pkg/configuration.h>
16 #include <apt-pkg/indexfile.h>
17 #include <apt-pkg/error.h>
22 // Global list of Item supported
23 static pkgIndexFile::Type
*ItmList
[10];
24 pkgIndexFile::Type
**pkgIndexFile::Type::GlobalList
= ItmList
;
25 unsigned long pkgIndexFile::Type::GlobalListLen
= 0;
27 // Type::Type - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
30 pkgIndexFile::Type::Type()
32 ItmList
[GlobalListLen
] = this;
36 // Type::GetType - Locate the type by name /*{{{*/
37 // ---------------------------------------------------------------------
39 pkgIndexFile::Type
*pkgIndexFile::Type::GetType(const char *Type
)
41 for (unsigned I
= 0; I
!= GlobalListLen
; I
++)
42 if (strcmp(GlobalList
[I
]->Label
,Type
) == 0)
48 // IndexFile::ArchiveInfo - Stub /*{{{*/
49 // ---------------------------------------------------------------------
51 string
pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver
) const
56 // IndexFile::FindInCache - Stub /*{{{*/
57 // ---------------------------------------------------------------------
59 pkgCache::PkgFileIterator
pkgIndexFile::FindInCache(pkgCache
&Cache
) const
61 return pkgCache::PkgFileIterator(Cache
);
64 // IndexFile::SourceIndex - Stub /*{{{*/
65 // ---------------------------------------------------------------------
67 string
pkgIndexFile::SourceInfo(pkgSrcRecords::Parser
const &Record
,
68 pkgSrcRecords::File
const &File
) const
73 // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
74 // ---------------------------------------------------------------------
76 bool pkgIndexFile::TranslationsAvailable()
78 const string Translation
= _config
->Find("APT::Acquire::Translation");
80 if (Translation
.compare("none") != 0)
81 return CheckLanguageCode(LanguageCode().c_str());
86 // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
87 // ---------------------------------------------------------------------
89 /* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro,
90 de_DE.ISO8859-1, tig_ER
91 more in /etc/gdm/locale.conf
94 bool pkgIndexFile::CheckLanguageCode(const char *Lang
)
96 if (strlen(Lang
) == 2 || (strlen(Lang
) == 5 && Lang
[2] == '_'))
99 if (strcmp(Lang
,"C") != 0)
100 _error
->Warning("Wrong language code %s", Lang
);
105 // IndexFile::LanguageCode - Return the Language Code /*{{{*/
106 // ---------------------------------------------------------------------
107 /* return the language code */
108 string
pkgIndexFile::LanguageCode()
110 const string Translation
= _config
->Find("APT::Acquire::Translation");
112 if (Translation
.compare("environment") == 0)
114 string lang
= std::setlocale(LC_MESSAGES
,NULL
);
116 // we have a mapping of the language codes that contains all the language
117 // codes that need the country code as well
118 // (like pt_BR, pt_PT, sv_SE, zh_*, en_*)
119 char *need_full_langcode
[] = { "pt","sv","zh","en", NULL
};
120 for(char **s
= need_full_langcode
;*s
!= NULL
; s
++)
121 if(lang
.find(*s
) == 0)
122 return lang
.substr(0,5);
125 return lang
.substr(0,2);