]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/aptconfiguration.cc
add more dpointer placeholders
[apt.git] / apt-pkg / aptconfiguration.cc
index f3f94dce3a6dc9760cbeb7709fa97f6c4b5a807c..52f54073cbc0288e582a8ced0f2ccec7cbc15b9d 100644 (file)
@@ -10,6 +10,7 @@
 // Include Files                                                       /*{{{*/
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/macros.h>
 #include <apt-pkg/strutl.h>
@@ -165,17 +166,6 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
        string const envShort = envLong.substr(0,lenShort);
        bool envLongIncluded = true;
 
-       // first cornercase: LANG=C, so we use only "en" Translation
-       if (envLong == "C") {
-               codes.push_back("en");
-               allCodes = codes;
-               allCodes.insert(allCodes.end(), builtin.begin(), builtin.end());
-               if (All == true)
-                       return allCodes;
-               else
-                       return codes;
-       }
-
        // to save the servers from unneeded queries, we only try also long codes
        // for languages it is realistic to have a long code translation fileā€¦
        // TODO: Improve translation acquire system to drop them dynamic
@@ -196,6 +186,9 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
        // it was undocumented and so it should be not very widthly used
        string const oldAcquire = _config->Find("APT::Acquire::Translation","");
        if (oldAcquire.empty() == false && oldAcquire != "environment") {
+               // TRANSLATORS: the two %s are APT configuration options
+               _error->Notice("Option '%s' is deprecated. Please use '%s' instead, see 'man 5 apt.conf' for details.",
+                               "APT::Acquire::Translation", "Acquire::Languages");
                if (oldAcquire != "none")
                        codes.push_back(oldAcquire);
                codes.push_back("en");
@@ -213,37 +206,41 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
        // It is very likely we will need to environment codes later,
        // so let us generate them now from LC_MESSAGES and LANGUAGE
        std::vector<string> environment;
-       // take care of LC_MESSAGES
-       if (envLongIncluded == false)
-               environment.push_back(envLong);
-       environment.push_back(envShort);
-       // take care of LANGUAGE
-       const char *language_env = getenv("LANGUAGE") == 0 ? "" : getenv("LANGUAGE");
-       string envLang = Locale == 0 ? language_env : *(Locale+1);
-       if (envLang.empty() == false) {
-               std::vector<string> env = ExplodeString(envLang,':');
-               short addedLangs = 0; // add a maximum of 3 fallbacks from the environment
-               for (std::vector<string>::const_iterator e = env.begin();
-                    e != env.end() && addedLangs < 3; ++e) {
-                       if (unlikely(e->empty() == true) || *e == "en")
-                               continue;
-                       if (*e == envLong || *e == envShort)
-                               continue;
-                       if (std::find(environment.begin(), environment.end(), *e) != environment.end())
-                               continue;
-                       if (e->find('_') != string::npos) {
-                               // Drop LongCodes here - ShortCodes are also included
-                               string const shorty = e->substr(0, e->find('_'));
-                               char const **n = needLong;
-                               for (; *n != NULL; ++n)
-                                       if (shorty == *n)
-                                               break;
-                               if (*n == NULL)
+       if (envShort != "C") {
+               // take care of LC_MESSAGES
+               if (envLongIncluded == false)
+                       environment.push_back(envLong);
+               environment.push_back(envShort);
+               // take care of LANGUAGE
+               const char *language_env = getenv("LANGUAGE") == 0 ? "" : getenv("LANGUAGE");
+               string envLang = Locale == 0 ? language_env : *(Locale+1);
+               if (envLang.empty() == false) {
+                       std::vector<string> env = VectorizeString(envLang,':');
+                       short addedLangs = 0; // add a maximum of 3 fallbacks from the environment
+                       for (std::vector<string>::const_iterator e = env.begin();
+                            e != env.end() && addedLangs < 3; ++e) {
+                               if (unlikely(e->empty() == true) || *e == "en")
                                        continue;
+                               if (*e == envLong || *e == envShort)
+                                       continue;
+                               if (std::find(environment.begin(), environment.end(), *e) != environment.end())
+                                       continue;
+                               if (e->find('_') != string::npos) {
+                                       // Drop LongCodes here - ShortCodes are also included
+                                       string const shorty = e->substr(0, e->find('_'));
+                                       char const **n = needLong;
+                                       for (; *n != NULL; ++n)
+                                               if (shorty == *n)
+                                                       break;
+                                       if (*n == NULL)
+                                               continue;
+                               }
+                               ++addedLangs;
+                               environment.push_back(*e);
                        }
-                       ++addedLangs;
-                       environment.push_back(*e);
                }
+       } else {
+               environment.push_back("en");
        }
 
        // Support settings like Acquire::Translation=none on the command line to
@@ -265,6 +262,16 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                        return codes;
        }
 
+       // cornercase: LANG=C, so we use only "en" Translation
+       if (envShort == "C") {
+               allCodes = codes = environment;
+               allCodes.insert(allCodes.end(), builtin.begin(), builtin.end());
+               if (All == true)
+                       return allCodes;
+               else
+                       return codes;
+       }
+
        std::vector<string> const lang = _config->FindVector("Acquire::Languages");
        // the default setting -> "environment, en"
        if (lang.empty() == true) {
@@ -319,4 +326,41 @@ std::vector<std::string> const Configuration::getLanguages(bool const &All,
                return codes;
 }
                                                                        /*}}}*/
+// getArchitectures - Return Vector of prefered Architectures          /*{{{*/
+std::vector<std::string> const Configuration::getArchitectures(bool const &Cached) {
+       using std::string;
+
+       std::vector<string> static archs;
+       if (likely(Cached == true) && archs.empty() == false)
+               return archs;
+
+       archs = _config->FindVector("APT::Architectures");
+       string const arch = _config->Find("APT::Architecture");
+       if (unlikely(arch.empty() == true))
+               return archs;
+
+       if (archs.empty() == true ||
+           std::find(archs.begin(), archs.end(), arch) == archs.end())
+               archs.push_back(arch);
+
+       // erase duplicates and empty strings
+       for (std::vector<string>::reverse_iterator a = archs.rbegin();
+            a != archs.rend(); ++a) {
+               if (a->empty() == true || std::find(a + 1, archs.rend(), *a) != archs.rend())
+                       archs.erase(a.base()-1);
+               if (a == archs.rend())
+                       break;
+       }
+
+       return archs;
+}
+                                                                       /*}}}*/
+// checkArchitecture - are we interested in the given Architecture?    /*{{{*/
+bool const Configuration::checkArchitecture(std::string const &Arch) {
+       if (Arch == "all")
+               return true;
+       std::vector<std::string> const archs = getArchitectures(true);
+       return (std::find(archs.begin(), archs.end(), Arch) != archs.end());
+}
+                                                                       /*}}}*/
 }