indexfile.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
  4. /* ######################################################################
  5. Index File - Abstraction for an index of archive/souce file.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include<config.h>
  10. #include <apt-pkg/indexfile.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/aptconfiguration.h>
  13. #include <apt-pkg/pkgcache.h>
  14. #include <apt-pkg/cacheiterators.h>
  15. #include <apt-pkg/srcrecords.h>
  16. #include <apt-pkg/macros.h>
  17. #include <string>
  18. #include <vector>
  19. #include <clocale>
  20. #include <cstring>
  21. /*}}}*/
  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;
  26. // Type::Type - Constructor /*{{{*/
  27. // ---------------------------------------------------------------------
  28. /* */
  29. pkgIndexFile::Type::Type()
  30. {
  31. ItmList[GlobalListLen] = this;
  32. GlobalListLen++;
  33. Label = NULL;
  34. }
  35. /*}}}*/
  36. // Type::GetType - Locate the type by name /*{{{*/
  37. // ---------------------------------------------------------------------
  38. /* */
  39. pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
  40. {
  41. for (unsigned I = 0; I != GlobalListLen; I++)
  42. if (strcmp(GlobalList[I]->Label,Type) == 0)
  43. return GlobalList[I];
  44. return 0;
  45. }
  46. /*}}}*/
  47. // IndexFile::ArchiveInfo - Stub /*{{{*/
  48. // ---------------------------------------------------------------------
  49. /* */
  50. std::string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator /*Ver*/) const
  51. {
  52. return std::string();
  53. }
  54. /*}}}*/
  55. // IndexFile::FindInCache - Stub /*{{{*/
  56. // ---------------------------------------------------------------------
  57. /* */
  58. pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
  59. {
  60. return pkgCache::PkgFileIterator(Cache);
  61. }
  62. /*}}}*/
  63. // IndexFile::SourceIndex - Stub /*{{{*/
  64. // ---------------------------------------------------------------------
  65. /* */
  66. std::string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &/*Record*/,
  67. pkgSrcRecords::File const &/*File*/) const
  68. {
  69. return std::string();
  70. }
  71. /*}}}*/
  72. // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
  73. // ---------------------------------------------------------------------
  74. /* */
  75. bool pkgIndexFile::TranslationsAvailable() {
  76. return (APT::Configuration::getLanguages().empty() != true);
  77. }
  78. /*}}}*/
  79. // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
  80. // ---------------------------------------------------------------------
  81. /* No intern need for this method anymore as the check for correctness
  82. is already done in getLanguages(). Note also that this check is
  83. rather bad (doesn't take three character like ast into account).
  84. TODO: Remove method with next API break */
  85. APT_DEPRECATED bool pkgIndexFile::CheckLanguageCode(const char *Lang)
  86. {
  87. if (strlen(Lang) == 2 || (strlen(Lang) == 5 && Lang[2] == '_'))
  88. return true;
  89. if (strcmp(Lang,"C") != 0)
  90. _error->Warning("Wrong language code %s", Lang);
  91. return false;
  92. }
  93. /*}}}*/
  94. // IndexFile::LanguageCode - Return the Language Code /*{{{*/
  95. // ---------------------------------------------------------------------
  96. /* As we have now possibly more than one LanguageCode this method is
  97. supersided by a) private classmembers or b) getLanguages().
  98. TODO: Remove method with next API break */
  99. APT_DEPRECATED std::string pkgIndexFile::LanguageCode() {
  100. if (TranslationsAvailable() == false)
  101. return "";
  102. return APT::Configuration::getLanguages()[0];
  103. }
  104. /*}}}*/