Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
5.4 KiB

  1. // Copyright (C) Microsoft Corporation 1993-1997
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifdef DESCRIPTION
  6. The CTable class is used for storing strings or data which will be
  7. freed in one call when the destructor is called.
  8. #endif // DESCRIPTION
  9. #ifndef _CTABLE_INCLUDED
  10. #define _CTABLE_INCLUDED
  11. typedef struct {
  12. int cb;
  13. PCSTR pMem;
  14. } TABLE_FREED_MEMORY;
  15. const int OFF_FILENAME = 5; // offset to filename
  16. class CTable ;
  17. class CTable SI_COUNT(CTable)
  18. {
  19. public:
  20. CTable();
  21. CTable(int cbStrings); // cbStrings == maximum memory allocated for strings
  22. virtual ~CTable();
  23. const CTable& operator=(const CTable& tblSrc); // copy constructor
  24. UINT GetPosFromPtr(PCSTR psz);
  25. // Used for ALink -- adds index, hit number, and string
  26. void AddIndexHitString(UINT index, UINT hit, PCSTR pszString);
  27. UINT GetIndex(int pos) { ASSERT(pos > 0 && pos < endpos); return *(UINT*) ppszTable[pos]; };
  28. UINT GetHit(int pos) { ASSERT(pos > 0 && pos < endpos); return *(UINT*) (ppszTable[pos] + sizeof(UINT)); };
  29. PSTR GetIHPointer(int pos) { ASSERT(pos > 0 && pos < endpos); return (ppszTable[pos] + (sizeof(UINT) * 2)); };
  30. /*
  31. REVIEW: this is the complete set from ..\common\ctable.h. We use
  32. very few of these. Theoretically, this shouldn't have any impact
  33. on the size of WinHelp (linker should toss all non-used functions).
  34. One alternative would be to create a derived class from the
  35. ctable.h/ctable.cpp in the ..\common directory, and add the
  36. above functions to the derived class.
  37. */
  38. int AddData(int cb, const void* pdata);
  39. int AddIntAndString(int lVal, PCSTR psz);
  40. int AddString(PCSTR pszString);
  41. int AddString(PCWSTR pszString);
  42. int AddString(PCSTR pszStr1, PCSTR pszStr2);
  43. int AddString(HASH hash, PCSTR psz) {
  44. return AddIntAndString((int) hash, psz); };
  45. int CountStrings(void) const { return endpos - 1; }
  46. void Empty(void);
  47. void FreeMemory(PCSTR psz, int cb);
  48. BOOL GetIntAndString(int* plVal, PSTR pszDst);
  49. int GetInt(int pos) { return *(int *) ppszTable[pos]; }
  50. BOOL GetHashAndString(HASH* phash, PSTR pszDst) {
  51. return GetIntAndString((int*) phash, pszDst); };
  52. BOOL GetHashAndString(HASH* phash, PSTR pszDst, int pos) {
  53. SetPosition(pos);
  54. return GetIntAndString((int*) phash, pszDst); };
  55. PSTR GetHashStringPointer(int pos) { return ppszTable[pos] + sizeof(HASH); };
  56. PSTR GetPointer(int pos) const { return ppszTable[pos]; };
  57. int GetPosition(void) const { return curpos; }
  58. BOOL GetString(PSTR pszDst);
  59. BOOL GetString(PSTR pszDst, int pos) const;
  60. int IsPrimaryStringInTable(PCSTR pszString) const;
  61. int IsSecondaryStringInTable(PCSTR pszString) const;
  62. int IsStringInTable(PCSTR pszString) const;
  63. int IsStringInTable(HASH hash, PCSTR pszString) const;
  64. int IsCSStringInTable(PCSTR pszString) const;
  65. BOOL ReplaceString(PCSTR pszNewString, int pos);
  66. BOOL FASTCALL SetPosition(int pos = 1);
  67. virtual void SortTable(int sortoffset = 0);
  68. void FASTCALL SetSorting(LCID lcid, DWORD fsCompareI = 0, DWORD fsCompare = 0);
  69. void SortTablei(int sortoffset = 0);
  70. PSTR TableMalloc(int cb);
  71. void IncreaseTableBuffer(void);
  72. int IsHashInTable(HASH hash);
  73. __inline PCSTR* GetStringPointers() { return (PCSTR*) ppszTable; }
  74. /*
  75. * Use this for efficient memory allocation for strings that will not
  76. * be freed until the entire CIndex is freed.
  77. */
  78. __inline PCSTR StrDup(PCSTR psz) { return strcpy(TableMalloc((int)strlen(psz) + 1), psz); }
  79. // Warning! all variables must match hha\ctable.h
  80. PSTR pszBase;
  81. PSTR * ppszTable;
  82. int cbMaxBase;
  83. int cbMaxTable;
  84. int endpos;
  85. int maxpos;
  86. protected:
  87. int curpos;
  88. int CurOffset;
  89. int cbStrings;
  90. int cbPointers;
  91. int SortColumn;
  92. LCID lcid;
  93. DWORD fsCompareI;
  94. DWORD fsCompare;
  95. DWORD fsSortFlags;
  96. int m_sortoffset;
  97. TABLE_FREED_MEMORY* m_pFreed; // pointer to freed memory
  98. int m_cFreedMax; // number of allocated items
  99. int m_cFreedItems; // current number of freed items
  100. // following are used by sort
  101. PSTR pszTmp;
  102. int j, sTmp;
  103. void doSort(int left, int right);
  104. void doLcidSort(int left, int right);
  105. void doSorti(int left, int right);
  106. void InitializeTable();
  107. void Cleanup(void);
  108. };
  109. // retrieves only MBCS strings from the base CTable
  110. // and converts them to Unicode according to the codepage
  111. //
  112. class CWTable : private CTable
  113. {
  114. public:
  115. CWTable( UINT CodePage );
  116. CWTable( int cbStrings, UINT CodePage );
  117. virtual ~CWTable();
  118. // new methods that return Unicode buffers
  119. HRESULT GetStringW( int pos, WCHAR* pwsz, int cch );
  120. HRESULT GetHashStringW( int pos, WCHAR* pwsz, int cch );
  121. inline UINT GetCodePage() { return m_CodePage; }
  122. // stuff from CTable we want to give access to
  123. CTable::CountStrings;
  124. CTable::AddString;
  125. CTable::IsStringInTable;
  126. CTable::AddIntAndString;
  127. CTable::SetSorting;
  128. CTable::SortTable;
  129. CTable::GetInt;
  130. // stuff from CTable that returns the MBCS string--BEWARE!!!
  131. CTable::GetString;
  132. CTable::GetStringPointers;
  133. CTable::GetHashStringPointer;
  134. private:
  135. void _CWTable( UINT CodePage );
  136. UINT m_CodePage;
  137. };
  138. #endif // _CTABLE_INCLUDED