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.

297 lines
6.8 KiB

  1. //
  2. // Copyright (c) Microsoft Corporation 1993-1995
  3. //
  4. // profile.c
  5. //
  6. // This file contains profile (.ini) routines.
  7. // Meant to be used in conjunction with common.c.
  8. //
  9. // History:
  10. // 08-06-93 ScottH Transferred from twin code
  11. // 05-05-95 ScottH Made generic from Briefcase code
  12. //
  13. #include "proj.h"
  14. #include "common.h"
  15. #ifndef NOPROFILE
  16. #pragma data_seg(DATASEG_READONLY)
  17. char const FAR c_szIniFile[] = SZ_DEBUGINI;
  18. char const FAR c_szIniSecDebugUI[] = SZ_DEBUGSECTION;
  19. char const FAR c_szZero[] = "0";
  20. char const FAR c_szIniKeyBreakFlags[] = "BreakFlags";
  21. char const FAR c_szIniKeyTraceFlags[] = "TraceFlags";
  22. char const FAR c_szIniKeyDumpFlags[] = "DumpFlags";
  23. #pragma data_seg()
  24. // Some of the .ini processing code was pimped from the sync engine.
  25. //
  26. typedef struct _INIKEYHEADER
  27. {
  28. LPCSTR pszSectionName;
  29. LPCSTR pszKeyName;
  30. LPCSTR pszDefaultRHS;
  31. } INIKEYHEADER;
  32. typedef struct _BOOLINIKEY
  33. {
  34. INIKEYHEADER ikh;
  35. LPUINT puStorage;
  36. DWORD dwFlag;
  37. } BOOLINIKEY;
  38. typedef struct _INTINIKEY
  39. {
  40. INIKEYHEADER ikh;
  41. LPUINT puStorage;
  42. } INTINIKEY;
  43. // Some of these macros taken from prefs.h in Pen project...
  44. //
  45. #define PutIniIntCmp(idsSection, idsKey, nNewValue, nSave) \
  46. if ((nNewValue) != (nSave)) PutIniInt(idsSection, idsKey, nNewValue)
  47. #define WritePrivateProfileInt(szApp, szKey, i, lpFileName) \
  48. {char sz[7]; \
  49. WritePrivateProfileString(szApp, szKey, SzFromInt(sz, i), lpFileName);}
  50. #ifdef SHARED_DLL
  51. #pragma data_seg(DATASEG_PERINSTANCE)
  52. #endif
  53. // Array of keys with Integer RHSs to be processed by ProcessIniFile()
  54. static INTINIKEY s_rgiik[] =
  55. {
  56. {
  57. { c_szIniSecDebugUI, c_szIniKeyTraceFlags, c_szZero },
  58. &g_dwTraceFlags
  59. },
  60. {
  61. { c_szIniSecDebugUI, c_szIniKeyDumpFlags, c_szZero },
  62. &g_dwDumpFlags
  63. },
  64. {
  65. { c_szIniSecDebugUI, c_szIniKeyBreakFlags, c_szZero },
  66. &g_dwBreakFlags
  67. },
  68. };
  69. // Array of keys with Boolean RHSs to be processed by ProcessIniFile()
  70. #if 0 // (use this as an example)
  71. static BOOLINIKEY s_rgbik[] =
  72. {
  73. {
  74. { c_szIniSecDebugUI, c_szIniKeyBreakOnOpen, c_szZero },
  75. &g_uBreakFlags,
  76. BF_ONOPEN
  77. },
  78. };
  79. #endif
  80. #ifdef SHARED_DLL
  81. #pragma data_seg()
  82. #endif
  83. /* Boolean TRUE strings used by IsIniYes() (comparison is case-insensitive) */
  84. static LPCSTR s_rgpszTrue[] =
  85. {
  86. "1",
  87. "On",
  88. "True",
  89. "Y",
  90. "Yes"
  91. };
  92. /* Boolean FALSE strings used by IsIniYes() (comparison is case-insensitive) */
  93. static LPCSTR s_rgpszFalse[] =
  94. {
  95. "0",
  96. "Off",
  97. "False",
  98. "N",
  99. "No"
  100. };
  101. /*----------------------------------------------------------
  102. Purpose: Determines whether a string corresponds to a boolean
  103. TRUE value.
  104. Returns: The boolean value (TRUE or FALSE)
  105. Cond: --
  106. */
  107. BOOL PRIVATE IsIniYes(
  108. LPCSTR psz)
  109. {
  110. int i;
  111. BOOL bNotFound = TRUE;
  112. BOOL bResult;
  113. ASSERT(psz);
  114. /* Is the value TRUE? */
  115. for (i = 0; i < ARRAY_ELEMENTS(s_rgpszTrue); i++)
  116. {
  117. if (IsSzEqual(psz, s_rgpszTrue[i]))
  118. {
  119. bResult = TRUE;
  120. bNotFound = FALSE;
  121. break;
  122. }
  123. }
  124. /* Is the value FALSE? */
  125. if (bNotFound)
  126. {
  127. for (i = 0; i < ARRAY_ELEMENTS(s_rgpszFalse); i++)
  128. {
  129. if (IsSzEqual(psz, s_rgpszFalse[i]))
  130. {
  131. bResult = FALSE;
  132. bNotFound = FALSE;
  133. break;
  134. }
  135. }
  136. /* Is the value a known string? */
  137. if (bNotFound)
  138. {
  139. /* No. Whine about it. */
  140. TRACE_MSG(TF_WARNING, "IsIniYes() called on unknown Boolean RHS '%s'.", psz);
  141. bResult = FALSE;
  142. }
  143. }
  144. return bResult;
  145. }
  146. #if 0 // (use this as an example)
  147. /*----------------------------------------------------------
  148. Purpose: Process keys with boolean RHSs.
  149. Returns: --
  150. Cond: --
  151. */
  152. void PRIVATE ProcessBooleans(void)
  153. {
  154. int i;
  155. for (i = 0; i < ARRAY_ELEMENTS(s_rgbik); i++)
  156. {
  157. DWORD dwcbKeyLen;
  158. char szRHS[MAX_BUF];
  159. BOOLINIKEY * pbik = &(s_rgbik[i]);
  160. LPCSTR lpcszRHS;
  161. /* Look for key. */
  162. dwcbKeyLen = GetPrivateProfileString(pbik->ikh.pszSectionName,
  163. pbik->ikh.pszKeyName, "", szRHS,
  164. sizeof(szRHS), c_szIniFile);
  165. if (dwcbKeyLen)
  166. lpcszRHS = szRHS;
  167. else
  168. lpcszRHS = pbik->ikh.pszDefaultRHS;
  169. if (IsIniYes(lpcszRHS))
  170. {
  171. if (IsFlagClear(*(pbik->puStorage), pbik->dwFlag))
  172. TRACE_MSG(TF_GENERAL, "ProcessIniFile(): %s set in %s![%s].",
  173. pbik->ikh.pszKeyName,
  174. c_szIniFile,
  175. pbik->ikh.pszSectionName);
  176. SetFlag(*(pbik->puStorage), pbik->dwFlag);
  177. }
  178. else
  179. {
  180. if (IsFlagSet(*(pbik->puStorage), pbik->dwFlag))
  181. TRACE_MSG(TF_GENERAL, "ProcessIniFile(): %s cleared in %s![%s].",
  182. pbik->ikh.pszKeyName,
  183. c_szIniFile,
  184. pbik->ikh.pszSectionName);
  185. ClearFlag(*(pbik->puStorage), pbik->dwFlag);
  186. }
  187. }
  188. }
  189. #endif
  190. /*----------------------------------------------------------
  191. Purpose: Process keys with integer RHSs.
  192. Returns: --
  193. Cond: --
  194. */
  195. void PRIVATE ProcessIntegers(void)
  196. {
  197. int i;
  198. for (i = 0; i < ARRAY_ELEMENTS(s_rgiik); i++)
  199. {
  200. DWORD dwcbKeyLen;
  201. char szRHS[MAX_BUF];
  202. INTINIKEY * piik = &(s_rgiik[i]);
  203. LPCSTR lpcszRHS;
  204. /* Look for key. */
  205. dwcbKeyLen = GetPrivateProfileString(piik->ikh.pszSectionName,
  206. piik->ikh.pszKeyName, "", szRHS,
  207. sizeof(szRHS), c_szIniFile);
  208. if (dwcbKeyLen)
  209. lpcszRHS = szRHS;
  210. else
  211. lpcszRHS = piik->ikh.pszDefaultRHS;
  212. *(piik->puStorage) = AnsiToInt(lpcszRHS);
  213. TRACE_MSG(TF_GENERAL, "ProcessIniFile(): %s set to %#04x.",
  214. piik->ikh.pszKeyName, *(piik->puStorage));
  215. }
  216. }
  217. /*----------------------------------------------------------
  218. Purpose: Process initialization file
  219. Returns: TRUE if initialization is successful
  220. Cond: --
  221. */
  222. BOOL PUBLIC ProcessIniFile(void)
  223. {
  224. BOOL bResult = TRUE;
  225. // Currently, all integer keys are for DEBUG use only.
  226. //
  227. ProcessIntegers();
  228. return bResult;
  229. }
  230. #endif // NOPROFILE