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.

285 lines
6.5 KiB

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