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.

178 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. perfutil.c
  5. Abstract:
  6. This file defines some functions used by the routines in PerformanceDLL.
  7. Environment:
  8. User Mode Service
  9. Revision History:
  10. --*/
  11. //#include <windows.h>
  12. //#include <string.h>
  13. #include <perrepsr.h>
  14. #include "perfutil.h"
  15. // Global Data Definitions
  16. #define GLOBAL_STRING L"Global"
  17. #define FOREIGN_STRING L"Foreign"
  18. #define COSTLY_STRING L"Costly"
  19. #define NULL_STRING L"\0"
  20. // Test for delimiter, EOL and non-digit characters
  21. // used by IsNumberInUnicodeList routine
  22. #define DIGIT 1
  23. #define DELIMITER 2
  24. #define INVALID 3
  25. #define EvalThisChar(c,d) ( \
  26. (c == d) ? DELIMITER : \
  27. (c == 0) ? DELIMITER : \
  28. (c < (WCHAR) '0') ? INVALID : \
  29. (c > (WCHAR) '9') ? INVALID : \
  30. DIGIT)
  31. DWORD
  32. GetQueryType (
  33. IN LPWSTR lpValue
  34. )
  35. /*++
  36. Routine Description:
  37. Returns the type of query described in lpValue string so that the appropriate
  38. processing method may be used.
  39. Arguments:
  40. lpValue - string describing the query type
  41. Return Value:
  42. QUERY_GLOBAL - "Global" string
  43. QUERY_FOREIGN - "Foreign" string
  44. QUERY_COSTLY - "Costly" string
  45. QUERY_ITEMS - otherwise
  46. --*/
  47. {
  48. if ((lpValue == NULL) || (*lpValue == 0)) {
  49. return QUERY_GLOBAL;
  50. // Check for Global
  51. }else if (!wcscmp(lpValue, GLOBAL_STRING)) {
  52. return QUERY_GLOBAL;
  53. // Check for Foreign
  54. }else if (!wcscmp(lpValue, FOREIGN_STRING)) {
  55. return QUERY_FOREIGN;
  56. // Check for Costly
  57. }else if (!wcscmp(lpValue, COSTLY_STRING)) {
  58. return QUERY_COSTLY;
  59. }
  60. // If its not Global, nor Foreign and nor Costly, then it must be an Item list.
  61. return QUERY_ITEMS;
  62. }
  63. BOOL
  64. IsNumberInUnicodeList (
  65. IN DWORD dwNumber,
  66. IN LPWSTR lpwszUnicodeList
  67. )
  68. /*++
  69. Routine Description:
  70. Checks if an item (dwNumber) is a part of a list (lpwszUnicodeList).
  71. Arguments:
  72. dwNumber - Number to be found in the list
  73. lpwszUnicodeList - Null terminated, space delimited list of decimal numbers
  74. Return Value:
  75. TRUE - The number was found
  76. FALSE - The number was not found
  77. --*/
  78. {
  79. DWORD dwThisNumber;
  80. WCHAR *pwcThisChar, wcDelimiter;
  81. BOOL bValidNumber, bNewItem, bReturnValue;
  82. if (lpwszUnicodeList == 0) { // null pointer, # not found
  83. return FALSE;
  84. }
  85. pwcThisChar = lpwszUnicodeList;
  86. dwThisNumber = 0;
  87. wcDelimiter = (WCHAR)' ';
  88. bValidNumber = FALSE;
  89. bNewItem = TRUE;
  90. while (TRUE) {
  91. switch ( EvalThisChar (*pwcThisChar, wcDelimiter) ) {
  92. case DIGIT:
  93. // If this is the first digit after a delimiter,
  94. // then set flags to start computing a new number
  95. if (bNewItem) {
  96. bNewItem = FALSE;
  97. bValidNumber = TRUE;
  98. }
  99. if (bValidNumber) {
  100. dwThisNumber *= 10;
  101. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  102. }
  103. break;
  104. case DELIMITER:
  105. // A delimiter is either a delimiter character or an
  106. // end of string ('\0') if when the delimiter has been reached
  107. // a valid number was found, then compare it to the number from
  108. // the argument list. If this is the end of the string and no
  109. // match was found, then return.
  110. if (bValidNumber) {
  111. if (dwThisNumber == dwNumber) {
  112. return TRUE;
  113. }
  114. bValidNumber = FALSE;
  115. }
  116. if (*pwcThisChar == 0) {
  117. return FALSE;
  118. } else {
  119. bNewItem = TRUE;
  120. dwThisNumber = 0;
  121. }
  122. break;
  123. case INVALID:
  124. // If an invalid number was encountered, ignore all
  125. // characters upto the next delimiter and start fresh.
  126. // The invalid number is not compared.
  127. bValidNumber = FALSE;
  128. break;
  129. default: break;
  130. }
  131. pwcThisChar++;
  132. }
  133. }