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.

203 lines
5.0 KiB

  1. //
  2. // Prfutil.h
  3. //
  4. // Utility procedures from the VGACTRS code in the DDK
  5. //
  6. #include "windows.h"
  7. #include <winperf.h>
  8. #define DEFINE_STRING
  9. #include "prfutil.h"
  10. DWORD
  11. GetQueryType (
  12. IN LPWSTR lpValue
  13. )
  14. /*++
  15. GetQueryType
  16. returns the type of query described in the lpValue string so that
  17. the appropriate processing method may be used
  18. Arguments
  19. IN lpValue
  20. string passed to PerfRegQuery Value for processing
  21. Return Value
  22. QUERY_GLOBAL
  23. if lpValue == 0 (null pointer)
  24. lpValue == pointer to Null string
  25. lpValue == pointer to "Global" string
  26. QUERY_FOREIGN
  27. if lpValue == pointer to "Foriegn" string
  28. QUERY_COSTLY
  29. if lpValue == pointer to "Costly" string
  30. otherwise:
  31. QUERY_ITEMS
  32. --*/
  33. {
  34. TCHAR *pwcArgChar, *pwcTypeChar;
  35. BOOL bFound;
  36. if (lpValue == 0) {
  37. return QUERY_GLOBAL;
  38. } else if (*lpValue == 0) {
  39. return QUERY_GLOBAL;
  40. }
  41. // check for "Global" request
  42. pwcArgChar = lpValue;
  43. pwcTypeChar = GLOBAL_STRING;
  44. bFound = TRUE; // assume found until contradicted
  45. // check to the length of the shortest string
  46. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  47. if (*pwcArgChar++ != *pwcTypeChar++) {
  48. bFound = FALSE; // no match
  49. break; // bail out now
  50. }
  51. }
  52. if (bFound) return QUERY_GLOBAL;
  53. // check for "Foreign" request
  54. pwcArgChar = lpValue;
  55. pwcTypeChar = FOREIGN_STRING;
  56. bFound = TRUE; // assume found until contradicted
  57. // check to the length of the shortest string
  58. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  59. if (*pwcArgChar++ != *pwcTypeChar++) {
  60. bFound = FALSE; // no match
  61. break; // bail out now
  62. }
  63. }
  64. if (bFound) return QUERY_FOREIGN;
  65. // check for "Costly" request
  66. pwcArgChar = lpValue;
  67. pwcTypeChar = COSTLY_STRING;
  68. bFound = TRUE; // assume found until contradicted
  69. // check to the length of the shortest string
  70. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  71. if (*pwcArgChar++ != *pwcTypeChar++) {
  72. bFound = FALSE; // no match
  73. break; // bail out now
  74. }
  75. }
  76. if (bFound) return QUERY_COSTLY;
  77. // if not Global and not Foreign and not Costly,
  78. // then it must be an item list
  79. return QUERY_ITEMS;
  80. }
  81. BOOL
  82. IsNumberInUnicodeList (
  83. IN DWORD dwNumber,
  84. IN LPWSTR lpwszUnicodeList
  85. )
  86. /*++
  87. IsNumberInUnicodeList
  88. Arguments:
  89. IN dwNumber
  90. DWORD number to find in list
  91. IN lpwszUnicodeList
  92. Null terminated, Space delimited list of decimal numbers
  93. Return Value:
  94. TRUE:
  95. dwNumber was found in the list of unicode number strings
  96. FALSE:
  97. dwNumber was not found in the list.
  98. --*/
  99. {
  100. DWORD dwThisNumber;
  101. TCHAR *pwcThisChar;
  102. BOOL bValidNumber;
  103. BOOL bNewItem;
  104. TCHAR wcDelimiter; // could be an argument to be more flexible
  105. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not founde
  106. pwcThisChar = lpwszUnicodeList;
  107. dwThisNumber = 0;
  108. wcDelimiter = TEXT(' ');
  109. bValidNumber = FALSE;
  110. bNewItem = TRUE;
  111. while (TRUE) {
  112. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  113. case DIGIT:
  114. // if this is the first digit after a delimiter, then
  115. // set flags to start computing the new number
  116. if (bNewItem) {
  117. bNewItem = FALSE;
  118. bValidNumber = TRUE;
  119. }
  120. if (bValidNumber) {
  121. dwThisNumber *= 10;
  122. dwThisNumber += (*pwcThisChar - TEXT('0'));
  123. }
  124. break;
  125. case DELIMITER:
  126. // a delimter is either the delimiter character or the
  127. // end of the string ('\0') if when the delimiter has been
  128. // reached a valid number was found, then compare it to the
  129. // number from the argument list. if this is the end of the
  130. // string and no match was found, then return.
  131. //
  132. if (bValidNumber) {
  133. if (dwThisNumber == dwNumber) return TRUE;
  134. bValidNumber = FALSE;
  135. }
  136. if (*pwcThisChar == 0) {
  137. return FALSE;
  138. } else {
  139. bNewItem = TRUE;
  140. dwThisNumber = 0;
  141. }
  142. break;
  143. case INVALID:
  144. // if an invalid character was encountered, ignore all
  145. // characters up to the next delimiter and then start fresh.
  146. // the invalid number is not compared.
  147. bValidNumber = FALSE;
  148. break;
  149. default:
  150. break;
  151. }
  152. pwcThisChar++;
  153. }
  154. } // IsNumberInUnicodeList
  155.