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.

324 lines
8.2 KiB

  1. // ############################################################################
  2. // Miscellaneous support routines
  3. #include "pch.hpp"
  4. #include "phbk.h"
  5. #define irgMaxSzs 5
  6. char szStrTable[irgMaxSzs][256];
  7. // ############################################################################
  8. LPSTR GetSz(WORD wszID)
  9. {
  10. static int iSzTable=0;
  11. LPSTR psz = (LPSTR)&szStrTable[iSzTable][0];
  12. iSzTable++;
  13. if (iSzTable >= irgMaxSzs)
  14. iSzTable = 0;
  15. if (!LoadString(g_hInstDll, wszID, psz, 256))
  16. {
  17. Dprintf("LoadString failed %d\n", (DWORD) wszID);
  18. *psz = 0;
  19. }
  20. return (psz);
  21. }
  22. // ############################################################################
  23. void SzCanonicalFromAE (LPSTR psz, PACCESSENTRY pAE, LPLINECOUNTRYENTRY pLCE)
  24. {
  25. if (NO_AREA_CODE == pAE->dwAreaCode)
  26. {
  27. wsprintf(psz, "+%ld %s", pLCE->dwCountryCode, pAE->szAccessNumber);
  28. }
  29. else
  30. {
  31. wsprintf(psz, "+%ld (%s) %s", pLCE->dwCountryCode, pAE->szAreaCode, pAE->szAccessNumber);
  32. }
  33. return;
  34. }
  35. // ############################################################################
  36. int MyStrcmp(LPVOID pv1, LPVOID pv2)
  37. {
  38. LPSTR pc1 = (LPSTR) pv1;
  39. LPSTR pc2 = (LPSTR) pv2;
  40. int iRC = 0;
  41. // loop while not pointed at the ending NULL character and no difference has been found
  42. while (*pc1 && *pc2 && !iRC)
  43. {
  44. iRC = (int)(*pc1 - *pc2);
  45. pc1++;
  46. pc2++;
  47. }
  48. // if we exited because we got to the end of one string before we found a difference
  49. // return -1 if pv1 is longer, else return the character pointed at by pv2. If pv2
  50. // is longer than pv1 then the value at pv2 will be greater than 0. If both strings
  51. // ended at the same time, then pv2 will point to 0.
  52. if (!iRC)
  53. {
  54. iRC = (*pc1) ? -1 : (*pc2);
  55. }
  56. return iRC;
  57. }
  58. // ############################################################################
  59. int __cdecl Compare950Entry(const void*pv1, const void*pv2)
  60. {
  61. return (((NPABLOCK *) pv1)->wAreaCode - ((NPABLOCK *) pv2)->wAreaCode);
  62. }
  63. // ############################################################################
  64. int __cdecl CompareIDLookUpElements(const void *e1, const void *e2)
  65. {
  66. if (((LPIDLOOKUPELEMENT)e1)->dwID > ((LPIDLOOKUPELEMENT)e2)->dwID)
  67. return 1;
  68. if (((LPIDLOOKUPELEMENT)e1)->dwID < ((LPIDLOOKUPELEMENT)e2)->dwID)
  69. return -1;
  70. return 0;
  71. }
  72. // ############################################################################
  73. int __cdecl CompareCntryNameLookUpElements(const void *e1, const void *e2)
  74. {
  75. LPCNTRYNAMELOOKUPELEMENT pCUE1 = (LPCNTRYNAMELOOKUPELEMENT)e1;
  76. LPCNTRYNAMELOOKUPELEMENT pCUE2 = (LPCNTRYNAMELOOKUPELEMENT)e2;
  77. #ifdef WIN16
  78. return lstrcmpi(pCUE1->psCountryName, pCUE2->psCountryName);
  79. #else
  80. return CompareString(LOCALE_USER_DEFAULT,0,pCUE1->psCountryName,
  81. pCUE1->dwNameSize,pCUE2->psCountryName,
  82. pCUE2->dwNameSize) - 2;
  83. // return CompareString(LOCALE_USER_DEFAULT,0,((LPCNTRYNAMELOOKUPELEMENT)*e1)->psCountryName,
  84. // ((LPCNTRYNAMELOOKUPELEMENT)*e1)->dwNameSize,((LPCNTRYNAMELOOKUPELEMENT)*e2)->psCountryName,
  85. // ((LPCNTRYNAMELOOKUPELEMENT)*e2)->dwNameSize) - 2;
  86. #endif
  87. }
  88. // ############################################################################
  89. int __cdecl CompareIdxLookUpElements(const void *e1, const void *e2)
  90. {
  91. if (((LPIDXLOOKUPELEMENT)e1)->dwIndex > ((LPIDXLOOKUPELEMENT)e2)->dwIndex)
  92. return 1;
  93. if (((LPIDXLOOKUPELEMENT)e1)->dwIndex < ((LPIDXLOOKUPELEMENT)e2)->dwIndex)
  94. return -1;
  95. return 0;
  96. }
  97. // ############################################################################
  98. int __cdecl CompareIdxLookUpElementsFileOrder(const void *pv1, const void *pv2)
  99. {
  100. PACCESSENTRY pae1, pae2;
  101. int iSort;
  102. pae1 = ((LPIDXLOOKUPELEMENT)pv1)->pAE;
  103. pae2 = ((LPIDXLOOKUPELEMENT)pv2)->pAE;
  104. // sort empty enteries to the end of the list
  105. if (!(pae1 && pae2))
  106. {
  107. return (pae1 ? -1 : (pae2 ? 1 : 0));
  108. }
  109. // country ASC, state ASC, city ASC, toll free DESC, flip DESC, con spd max DESC
  110. if (pae1->dwCountryID != pae2->dwCountryID)
  111. {
  112. return (int)(pae1->dwCountryID - pae2->dwCountryID);
  113. }
  114. if (pae1->wStateID != pae2->wStateID)
  115. {
  116. return (pae1->wStateID - pae2->wStateID);
  117. }
  118. iSort = MyStrcmp((LPVOID)pae1->szCity, (LPVOID)pae2->szCity);
  119. if (iSort)
  120. {
  121. return (iSort);
  122. }
  123. if (pae1->fType != pae2->fType)
  124. {
  125. return (pae2->fType - pae1->fType);
  126. }
  127. if (pae1->bFlipFactor != pae2->bFlipFactor)
  128. {
  129. return (pae2->bFlipFactor - pae1->bFlipFactor);
  130. }
  131. if (pae1->dwConnectSpeedMax != pae2->dwConnectSpeedMax)
  132. {
  133. return (int)(pae2->dwConnectSpeedMax - pae1->dwConnectSpeedMax);
  134. }
  135. return 0;
  136. }
  137. // ############################################################################
  138. //inline BOOL FSz2Dw(PCSTR pSz,DWORD *dw)
  139. BOOL FSz2Dw(LPCSTR pSz,DWORD far *dw)
  140. {
  141. DWORD val = 0;
  142. while (*pSz)
  143. {
  144. if (*pSz >= '0' && *pSz <= '9')
  145. {
  146. val *= 10;
  147. val += *pSz++ - '0';
  148. }
  149. else
  150. {
  151. return FALSE; //bad number
  152. }
  153. }
  154. *dw = val;
  155. return (TRUE);
  156. }
  157. // ############################################################################
  158. //inline BOOL FSz2W(PCSTR pSz,WORD *w)
  159. BOOL FSz2W(LPCSTR pSz,WORD far *w)
  160. {
  161. DWORD dw;
  162. if (FSz2Dw(pSz,&dw))
  163. {
  164. *w = (WORD)dw;
  165. return TRUE;
  166. }
  167. return FALSE;
  168. }
  169. // ############################################################################
  170. //inline BOOL FSz2B(PCSTR pSz,BYTE *pb)
  171. BOOL FSz2B(LPCSTR pSz,BYTE far *pb)
  172. {
  173. DWORD dw;
  174. if (FSz2Dw(pSz,&dw))
  175. {
  176. *pb = (BYTE)dw;
  177. return TRUE;
  178. }
  179. return FALSE;
  180. }
  181. // ############################################################################
  182. HRESULT ReleaseBold(HWND hwnd)
  183. {
  184. HFONT hfont = NULL;
  185. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  186. if (hfont) DeleteObject(hfont);
  187. return ERROR_SUCCESS;
  188. }
  189. // ############################################################################
  190. HRESULT MakeBold (HWND hwnd)
  191. {
  192. HRESULT hr = ERROR_SUCCESS;
  193. HFONT hfont = NULL;
  194. HFONT hnewfont = NULL;
  195. LOGFONT far * plogfont = NULL;
  196. if (!hwnd) goto MakeBoldExit;
  197. hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
  198. if (!hfont)
  199. {
  200. hr = GetLastError();
  201. goto MakeBoldExit;
  202. }
  203. plogfont = (LOGFONT far *)GlobalAlloc(GPTR,sizeof(LOGFONT));
  204. if (!plogfont)
  205. {
  206. hr = GetLastError();
  207. goto MakeBoldExit;
  208. }
  209. if (!GetObject(hfont,sizeof(LOGFONT),(LPVOID)plogfont))
  210. {
  211. hr = GetLastError();
  212. goto MakeBoldExit;
  213. }
  214. if (plogfont->lfHeight < 24)
  215. {
  216. plogfont->lfHeight = plogfont->lfHeight + (plogfont->lfHeight / 4);
  217. }
  218. plogfont->lfWeight = FW_BOLD;
  219. if (!(hnewfont = CreateFontIndirect(plogfont)))
  220. {
  221. hr = GetLastError();
  222. goto MakeBoldExit;
  223. }
  224. SendMessage(hwnd,WM_SETFONT,(WPARAM)hnewfont,MAKELPARAM(FALSE,0));
  225. GlobalFree(plogfont);
  226. plogfont = NULL;
  227. MakeBoldExit:
  228. //if (hfont) DeleteObject(hfont);
  229. // BUG:? Do I need to delete hnewfont at some time?
  230. return hr;
  231. }
  232. #if !defined(WIN16)
  233. //+----------------------------------------------------------------------------
  234. //
  235. // Function: DWGetWin32Platform
  236. //
  237. // Synopsis: Return a value to determine win32 platform
  238. //
  239. // Arguements: None
  240. //
  241. // Returns: platform enumeration (see GetVersionEx for details)
  242. //
  243. // History: 8/8/96 ChrisK Created
  244. //
  245. //-----------------------------------------------------------------------------
  246. DWORD DWGetWin32Platform()
  247. {
  248. OSVERSIONINFO osver;
  249. ZeroMemory(&osver,sizeof(osver));
  250. osver.dwOSVersionInfoSize = sizeof(osver);
  251. if (GetVersionEx(&osver))
  252. return osver.dwPlatformId;
  253. AssertSz(0,"GetVersionEx failed.\r\n");
  254. return 0;
  255. }
  256. //+----------------------------------------------------------------------------
  257. //
  258. // Function: DWGetWin32BuildNumber
  259. //
  260. // Synopsis: Return a value to determine win32 build
  261. //
  262. // Arguements: None
  263. //
  264. // Returns: build number
  265. //
  266. // History: 9/26/96 ChrisK Created
  267. //
  268. //-----------------------------------------------------------------------------
  269. DWORD DWGetWin32BuildNumber()
  270. {
  271. OSVERSIONINFO osver;
  272. ZeroMemory(&osver,sizeof(osver));
  273. osver.dwOSVersionInfoSize = sizeof(osver);
  274. if (GetVersionEx(&osver))
  275. // dwBuildNumber
  276. // Identifies the build number of the operating system in the low-order
  277. // word. (The high-order word contains the major and minor version numbers.)
  278. return (osver.dwBuildNumber & 0xFFFF);
  279. AssertSz(0,"GetVersionEx failed.\r\n");
  280. return 0;
  281. }
  282. #endif