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.

153 lines
4.4 KiB

  1. /******************************************************************************
  2. * Utility file for guid and other support.
  3. *****************************************************************************/
  4. /******************************************************************************
  5. includes
  6. ******************************************************************************/
  7. #include "precomp.hxx"
  8. /******************************************************************************
  9. defines and prototypes
  10. ******************************************************************************/
  11. /******************************************************************************
  12. Da Code
  13. ******************************************************************************/
  14. char *
  15. StringToULong(
  16. char * pString,
  17. unsigned long * pNumber )
  18. {
  19. unsigned long Number = 0;
  20. int Count;
  21. // There will be 8 characters int a string that converts into a long.
  22. for( Count = 0; (Count < 8) && pString && *pString ; ++Count, ++pString )
  23. {
  24. if( (*pString >= '0') && (*pString <= '9' ) )
  25. {
  26. Number = (Number << 4) + (*pString -'0');
  27. }
  28. else if( (*pString >='A') && (*pString <= 'F'))
  29. {
  30. Number = (Number << 4) + (*pString - 'A') + 10;
  31. }
  32. else if( (*pString >='a') && (*pString <= 'f'))
  33. {
  34. Number = (Number << 4) + (*pString - 'a') + 10;
  35. }
  36. }
  37. *pNumber = Number;
  38. return pString;
  39. }
  40. char *
  41. StringToUShort(
  42. char * pString,
  43. unsigned short * pNumber )
  44. {
  45. unsigned short Number = 0;
  46. int Count;
  47. // There will be 4 characters int a string that converts into a short.
  48. for( Count = 0; (Count < 4) && pString ; ++Count, ++pString )
  49. {
  50. if( (*pString >= '0') && (*pString <= '9' ) )
  51. {
  52. Number = (Number << 4) + (*pString -'0');
  53. }
  54. else if( (*pString >='A') && (*pString <= 'F'))
  55. {
  56. Number = (Number << 4) + (*pString - 'A') + 10;
  57. }
  58. else if( (*pString >='a') && (*pString <= 'f'))
  59. {
  60. Number = (Number << 4) + (*pString - 'a') + 10;
  61. }
  62. }
  63. *pNumber = Number;
  64. return pString;
  65. }
  66. char *
  67. StringToUChar(
  68. char * pString,
  69. unsigned char * pNumber )
  70. {
  71. unsigned char Number = 0;
  72. int Count;
  73. // There will be 2 characters int a string that converts into a char.
  74. for( Count = 0; (Count < 2) && pString ; ++Count, ++pString )
  75. {
  76. if( (*pString >= '0') && (*pString <= '9' ) )
  77. {
  78. Number = (Number << 4) + (*pString -'0');
  79. }
  80. else if( (*pString >='A') && (*pString <= 'F'))
  81. {
  82. Number = (Number << 4) + (*pString - 'A') + 10;
  83. }
  84. else if( (*pString >='a') && (*pString <= 'f'))
  85. {
  86. Number = (Number << 4) + (*pString - 'a') + 10;
  87. }
  88. }
  89. *pNumber = Number;
  90. return pString;
  91. }
  92. char *
  93. StringToCLSID(
  94. char * pString,
  95. CLSID * pClsid )
  96. {
  97. pString = StringToULong( pString, &pClsid->Data1 );
  98. pString++; // skip -
  99. pString = StringToUShort( pString, &pClsid->Data2 );
  100. pString++; // skip -
  101. pString = StringToUShort( pString, &pClsid->Data3 );
  102. pString++; // skip -
  103. pString = StringToUChar( pString, &pClsid->Data4[0] );
  104. pString = StringToUChar( pString, &pClsid->Data4[1] );
  105. pString++; // skip -
  106. pString = StringToUChar( pString, &pClsid->Data4[2] );
  107. pString = StringToUChar( pString, &pClsid->Data4[3] );
  108. pString = StringToUChar( pString, &pClsid->Data4[4] );
  109. pString = StringToUChar( pString, &pClsid->Data4[5] );
  110. pString = StringToUChar( pString, &pClsid->Data4[6] );
  111. pString = StringToUChar( pString, &pClsid->Data4[7] );
  112. return pString;
  113. }
  114. void
  115. CLSIDToString(
  116. CLSID * pClsid,
  117. char * pString )
  118. {
  119. sprintf( pString,
  120. "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
  121. pClsid->Data1,
  122. pClsid->Data2,
  123. pClsid->Data3,
  124. pClsid->Data4[0],
  125. pClsid->Data4[1],
  126. pClsid->Data4[2],
  127. pClsid->Data4[3],
  128. pClsid->Data4[4],
  129. pClsid->Data4[5],
  130. pClsid->Data4[6],
  131. pClsid->Data4[7] );
  132. }