Leaked source code of windows server 2003
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.

100 lines
1.8 KiB

  1. /* Copyright (C) Microsoft Corporation, 1998. All rights reserved. */
  2. #include "precomp.h"
  3. #include "utils.h"
  4. LPSTR My_strdup ( LPCSTR pszSrc )
  5. {
  6. LPSTR pszDst = NULL;
  7. if (NULL != pszSrc)
  8. {
  9. UINT cch = ::strlen(pszSrc) + 1;
  10. if (NULL != (pszDst = new char[cch]))
  11. {
  12. ::CopyMemory(pszDst, pszSrc, cch);
  13. }
  14. }
  15. return pszDst;
  16. }
  17. const LPSTR c_apszKeywords[] =
  18. {
  19. "ANY",
  20. "AUTOMATIC",
  21. "BEGIN",
  22. "BIT",
  23. "BMPString",
  24. "BY",
  25. "CHOICE",
  26. "COMPONENT",
  27. "CONSTRAINED",
  28. "DEFINITIONS",
  29. "END",
  30. "FROM",
  31. "IDENTIFIER",
  32. "IMPORTS",
  33. "INTEGER",
  34. "IV8",
  35. "NULL",
  36. "OBJECT",
  37. "OCTET",
  38. "OPTIONAL",
  39. "SEQUENCE",
  40. "SIZE",
  41. "STRING",
  42. "SYNTAX",
  43. "TAGS",
  44. "WITH",
  45. };
  46. BOOL IsKeyword ( LPSTR pszSymbol )
  47. {
  48. return (BOOL) BinarySearch_Str(pszSymbol, &c_apszKeywords[0], ARRAY_SIZE(c_apszKeywords));
  49. }
  50. LPSTR BinarySearch_Str ( LPSTR pszKey, const LPSTR aKeyTbl[], UINT cKeys )
  51. {
  52. UINT lo = 0;
  53. UINT hi = cKeys - 1;
  54. UINT num = cKeys;
  55. UINT mid, half;
  56. int result;
  57. while (lo <= hi)
  58. {
  59. if (0 != (half = num >> 1))
  60. {
  61. mid = lo + ((num - 1) >> 1);
  62. if (0 == (result = ::strcmp(pszKey, aKeyTbl[mid])))
  63. {
  64. return aKeyTbl[mid];
  65. }
  66. else if (result < 0)
  67. {
  68. hi = mid - 1;
  69. num = (num - 1) >> 1;
  70. }
  71. else
  72. {
  73. lo = mid + 1;
  74. num = half;
  75. }
  76. }
  77. else if (num)
  78. {
  79. return (::strcmp(pszKey, aKeyTbl[lo]) ? NULL : aKeyTbl[lo]);
  80. }
  81. else
  82. {
  83. break;
  84. }
  85. }
  86. return NULL;
  87. }