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.

338 lines
7.4 KiB

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