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.

295 lines
6.9 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // .ini file support.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "pch.cpp"
  9. #pragma hdrstop
  10. #include "conio.hpp"
  11. #include "engine.hpp"
  12. #include "ini.hpp"
  13. #include "main.hpp"
  14. #define INI_SECTION_DEFAULT "dbgeng"
  15. static char *(g_Tokens[]) =
  16. {
  17. "debugchildren",
  18. "debugoutput",
  19. "stopfirst",
  20. "verboseoutput",
  21. "lazyload",
  22. "true",
  23. "false",
  24. "$u0",
  25. "$u1",
  26. "$u2",
  27. "$u3",
  28. "$u4",
  29. "$u5",
  30. "$u6",
  31. "$u7",
  32. "$u8",
  33. "$u9",
  34. "stoponprocessexit",
  35. "sxd",
  36. "sxe",
  37. "inifile",
  38. "setdll",
  39. "lines",
  40. "srcopt",
  41. "srcpath+"
  42. };
  43. int
  44. GetIniToken(
  45. PSTR* ppsz,
  46. PSTR limit
  47. )
  48. {
  49. PSTR psz = *ppsz;
  50. int token;
  51. while ((*psz == ' ' || *psz == '\t' || *psz == ':') &&
  52. *psz && psz < limit)
  53. {
  54. psz++;
  55. }
  56. if (psz >= limit)
  57. {
  58. return 0;
  59. }
  60. *ppsz = psz;
  61. while (*psz != ' ' && *psz != '\t' && *psz != ':' && *psz != '\n' &&
  62. *psz != '\r'&& *psz && psz < limit)
  63. {
  64. *psz = (char)tolower(*psz);
  65. psz++;
  66. }
  67. *psz = 0;
  68. if (**ppsz == '[')
  69. {
  70. return NTINI_END;
  71. }
  72. for (token = 1; token < NTINI_INVALID; token++)
  73. {
  74. if (!strcmp(*ppsz, g_Tokens[token-1]))
  75. {
  76. break;
  77. }
  78. }
  79. *ppsz = psz + 1;
  80. return token;
  81. }
  82. BOOL
  83. FindIniSection(FILE* File, PSTR Section)
  84. {
  85. char Ch, Tst;
  86. ULONG Index = 0;
  87. Ch = *Section;
  88. while (Ch && !feof(File))
  89. {
  90. Tst = (char)fgetc(File);
  91. if ((char)tolower(Ch) == (char)tolower(Tst))
  92. {
  93. Ch = Section[++Index];
  94. }
  95. else
  96. {
  97. Ch = Section[Index = 0];
  98. }
  99. }
  100. return Ch == 0;
  101. }
  102. void
  103. ReadIniFile(
  104. PULONG debugType
  105. )
  106. {
  107. FILE* file;
  108. char pszName[256];
  109. char rchBuf[_MAX_PATH];
  110. PSTR pszMark;
  111. PSTR pchCur;
  112. DWORD length;
  113. int index;
  114. int token, value;
  115. length = GetEnvironmentVariable(INI_DIR,
  116. pszName,
  117. sizeof(pszName) - sizeof(INI_FILE));
  118. if (length == 0)
  119. {
  120. return;
  121. }
  122. strcpy(pszName + length, INI_FILE);
  123. if (!(file = fopen(pszName, "r")))
  124. {
  125. return;
  126. }
  127. // Look for a section specific to this debugger first.
  128. if (!FindIniSection(file, g_DebuggerName))
  129. {
  130. // Didn't find a specific section, look for
  131. // the generic debugger settings section.
  132. rewind(file);
  133. if (!FindIniSection(file, INI_SECTION_DEFAULT))
  134. {
  135. fclose(file);
  136. return;
  137. }
  138. }
  139. // Now just read the lines in
  140. do
  141. {
  142. PSTR psz = rchBuf;
  143. if (!fgets(rchBuf, sizeof(rchBuf), file))
  144. {
  145. break;
  146. }
  147. for (index = 0; rchBuf[index] && rchBuf[index] > 26; index++)
  148. {
  149. ;
  150. }
  151. rchBuf[index] = 0;
  152. token = GetIniToken(&psz, rchBuf + sizeof(rchBuf));
  153. if (token >= NTINI_USERREG0 && token <= NTINI_USERREG9)
  154. {
  155. while ((*psz == ' ' || *psz == '\t' || *psz == ':') && *psz)
  156. {
  157. psz++;
  158. }
  159. if (*psz)
  160. {
  161. g_DbgControl->SetTextMacro(token - NTINI_USERREG0, psz);
  162. }
  163. continue;
  164. }
  165. switch (token)
  166. {
  167. case NTINI_SXD:
  168. case NTINI_SXE:
  169. ExecuteCmd("sx", *(psz - 2), ' ', psz);
  170. continue;
  171. case NTINI_INIFILE:
  172. g_InitialInputFile = (PSTR)calloc(1, strlen(psz) + 1);
  173. if (!g_InitialInputFile)
  174. {
  175. ErrorExit("%s: Input file memory allocation failed\n",
  176. g_DebuggerName);
  177. }
  178. strcpy(g_InitialInputFile, psz);
  179. continue;
  180. case NTINI_DEFAULTEXT:
  181. ULONG64 Handle;
  182. g_DbgControl->AddExtension(psz, DEBUG_EXTENSION_AT_ENGINE,
  183. &Handle);
  184. continue;
  185. case NTINI_SRCOPT:
  186. while ((*psz == ' ' || *psz == '\t' || *psz == ':') && *psz)
  187. {
  188. psz++;
  189. }
  190. ExecuteCmd("l+", 0, 0, psz);
  191. continue;
  192. case NTINI_SRCPATHA:
  193. ExecuteCmd(".srcpath+", 0, ' ', psz);
  194. continue;
  195. }
  196. value = GetIniToken(&psz, rchBuf + sizeof(rchBuf)) != NTINI_FALSE;
  197. switch (token)
  198. {
  199. case NTINI_STOPONPROCESSEXIT:
  200. if (value)
  201. {
  202. g_DbgControl->AddEngineOptions(DEBUG_ENGOPT_FINAL_BREAK);
  203. }
  204. else
  205. {
  206. g_DbgControl->RemoveEngineOptions(DEBUG_ENGOPT_FINAL_BREAK);
  207. }
  208. break;
  209. case NTINI_DEBUGCHILDREN:
  210. if (value)
  211. {
  212. *debugType = DEBUG_PROCESS;
  213. }
  214. break;
  215. case NTINI_DEBUGOUTPUT:
  216. if (value)
  217. {
  218. g_IoMode = IO_DEBUG;
  219. }
  220. else
  221. {
  222. g_IoMode = IO_CONSOLE;
  223. }
  224. break;
  225. case NTINI_STOPFIRST:
  226. if (value)
  227. {
  228. g_DbgControl->AddEngineOptions(DEBUG_ENGOPT_INITIAL_BREAK);
  229. }
  230. else
  231. {
  232. g_DbgControl->RemoveEngineOptions(DEBUG_ENGOPT_INITIAL_BREAK);
  233. }
  234. break;
  235. case NTINI_VERBOSEOUTPUT:
  236. ULONG OutMask;
  237. g_DbgClient->GetOutputMask(&OutMask);
  238. if (value)
  239. {
  240. OutMask |= DEBUG_OUTPUT_VERBOSE;
  241. }
  242. else
  243. {
  244. OutMask &= ~DEBUG_OUTPUT_VERBOSE;
  245. }
  246. g_DbgClient->SetOutputMask(OutMask);
  247. g_DbgControl->SetLogMask(OutMask);
  248. break;
  249. case NTINI_LAZYLOAD:
  250. if (value)
  251. {
  252. g_DbgSymbols->AddSymbolOptions(SYMOPT_DEFERRED_LOADS);
  253. }
  254. else
  255. {
  256. g_DbgSymbols->RemoveSymbolOptions(SYMOPT_DEFERRED_LOADS);
  257. }
  258. break;
  259. case NTINI_LINES:
  260. if (value)
  261. {
  262. g_DbgSymbols->AddSymbolOptions(SYMOPT_LOAD_LINES);
  263. }
  264. else
  265. {
  266. g_DbgSymbols->RemoveSymbolOptions(SYMOPT_LOAD_LINES);
  267. }
  268. break;
  269. }
  270. }
  271. while (token != NTINI_END);
  272. fclose(file);
  273. }