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.

215 lines
4.6 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 <winperf.h>
  14. #include "perfutil.h"
  15. // Global Data Definitions
  16. WCHAR GLOBAL_STRING[] = L"Global";
  17. WCHAR FOREIGN_STRING[] = L"Foreign";
  18. WCHAR COSTLY_STRING[] = L"Costly";
  19. WCHAR 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. WCHAR *pwcArgChar, *pwcTypeChar;
  49. BOOL bFound;
  50. if (lpValue == 0) {
  51. return QUERY_GLOBAL;
  52. } else if (*lpValue == 0) {
  53. return QUERY_GLOBAL;
  54. }
  55. pwcArgChar = lpValue;
  56. pwcTypeChar = GLOBAL_STRING;
  57. bFound = TRUE;
  58. // Check for Global
  59. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  60. if (*pwcArgChar++ != *pwcTypeChar++) {
  61. bFound = FALSE;
  62. break;
  63. }
  64. }
  65. if (bFound == TRUE) {
  66. return QUERY_GLOBAL;
  67. }
  68. // Check for Foreign
  69. pwcArgChar = lpValue;
  70. pwcTypeChar = FOREIGN_STRING;
  71. bFound = TRUE;
  72. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  73. if (*pwcArgChar++ != *pwcTypeChar++) {
  74. bFound = FALSE;
  75. break;
  76. }
  77. }
  78. if (bFound == TRUE) {
  79. return QUERY_FOREIGN;
  80. }
  81. // Check for Costly
  82. pwcArgChar = lpValue;
  83. pwcTypeChar = COSTLY_STRING;
  84. bFound = TRUE;
  85. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  86. if (*pwcArgChar++ != *pwcTypeChar++) {
  87. bFound = FALSE;
  88. break;
  89. }
  90. }
  91. if (bFound == TRUE) {
  92. return QUERY_COSTLY;
  93. }
  94. // If its not Global, nor Foreign and nor Costly, then it must be an Item list.
  95. return QUERY_ITEMS;
  96. }
  97. BOOL
  98. IsNumberInUnicodeList (
  99. IN DWORD dwNumber,
  100. IN LPWSTR lpwszUnicodeList
  101. )
  102. /*++
  103. Routine Description:
  104. Checks if an item (dwNumber) is a part of a list (lpwszUnicodeList).
  105. Arguments:
  106. dwNumber - Number to be found in the list
  107. lpwszUnicodeList - Null terminated, space delimited list of decimal numbers
  108. Return Value:
  109. TRUE - The number was found
  110. FALSE - The number was not found
  111. --*/
  112. {
  113. DWORD dwThisNumber;
  114. WCHAR *pwcThisChar, wcDelimiter;
  115. BOOL bValidNumber, bNewItem, bReturnValue;
  116. if (lpwszUnicodeList == 0) { // null pointer, # not found
  117. return FALSE;
  118. }
  119. pwcThisChar = lpwszUnicodeList;
  120. dwThisNumber = 0;
  121. wcDelimiter = (WCHAR)' ';
  122. bValidNumber = FALSE;
  123. bNewItem = TRUE;
  124. while (TRUE) {
  125. switch ( EvalThisChar (*pwcThisChar, wcDelimiter) ) {
  126. case DIGIT:
  127. // If this is the first digit after a delimiter,
  128. // then set flags to start computing a new number
  129. if (bNewItem) {
  130. bNewItem = FALSE;
  131. bValidNumber = TRUE;
  132. }
  133. if (bValidNumber) {
  134. dwThisNumber *= 10;
  135. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  136. }
  137. break;
  138. case DELIMITER:
  139. // A delimiter is either a delimiter character or an
  140. // end of string ('\0') if when the delimiter has been reached
  141. // a valid number was found, then compare it to the number from
  142. // the argument list. If this is the end of the string and no
  143. // match was found, then return.
  144. if (bValidNumber) {
  145. if (dwThisNumber == dwNumber) {
  146. return TRUE;
  147. }
  148. bValidNumber = FALSE;
  149. }
  150. if (*pwcThisChar == 0) {
  151. return FALSE;
  152. } else {
  153. bNewItem = TRUE;
  154. dwThisNumber = 0;
  155. }
  156. break;
  157. case INVALID:
  158. // If an invalid number was encountered, ignore all
  159. // characters upto the next delimiter and start fresh.
  160. // The invalid number is not compared.
  161. bValidNumber = FALSE;
  162. break;
  163. default: break;
  164. }
  165. pwcThisChar++;
  166. }
  167. }