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.

431 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. mbrqry.c
  5. Abstract:
  6. This file contains the functions that perform the queries to the
  7. database. These functions are called by the top-level functions
  8. which implement the browser commands (see mbrdlg.c).
  9. Author:
  10. Ramon Juan San Andres (ramonsa) 07-Nov-1990
  11. Revision History:
  12. --*/
  13. #include "mbr.h"
  14. // INST_MATCHES_CRITERIA
  15. //
  16. // This macro is used to find out if an instance matches the
  17. // current MBF criteria.
  18. //
  19. #define INST_MATCHES_CRITERIA(Iinst) FInstFilter(Iinst, BscMbf)
  20. //
  21. // Static variables reflect the current state of
  22. // Definition/Reference queries.
  23. //
  24. static IREF LastiRef; // Last reference index
  25. static IREF iRefMin, iRefMax; // Current reference index range
  26. static IDEF LastiDef; // Last definition index
  27. static IDEF iDefMin, iDefMax; // Current definition index range
  28. static IINST LastIinst; // Last instance index
  29. static IINST IinstMin, IinstMax; // Current instance index range
  30. static DEFREF LastQueryType; // last query type:
  31. // Q_DEFINITION or
  32. // Q_REFERENCE
  33. static buffer LastSymbol; // Last symbol queried.
  34. /**************************************************************************/
  35. void
  36. pascal
  37. InitDefRef(
  38. IN DEFREF QueryType,
  39. IN char *Symbol
  40. )
  41. /*++
  42. Routine Description:
  43. Initializes the query state, this must be done before querying for
  44. the first definition/reference of a symbol.
  45. After calling this function, the first definition/reference must be
  46. obtained by calling the NextDefRef function.
  47. Arguments:
  48. QueryType - Type of query (Q_DEFINITION or Q_REFERENCE).
  49. Symbol - Symbol name.
  50. Return Value:
  51. None.
  52. --*/
  53. {
  54. ISYM Isym;
  55. LastQueryType = QueryType;
  56. strcpy(LastSymbol, Symbol);
  57. Isym = IsymFrLsz(Symbol);
  58. InstRangeOfSym(Isym, &IinstMin, &IinstMax);
  59. LastIinst = IinstMin;
  60. if (QueryType == Q_DEFINITION) {
  61. DefRangeOfInst(LastIinst, &iDefMin, &iDefMax);
  62. LastiDef = iDefMin - 1;
  63. } else {
  64. RefRangeOfInst(LastIinst, &iRefMin, &iRefMax);
  65. LastiRef = iRefMin - 1;
  66. }
  67. }
  68. /**************************************************************************/
  69. void
  70. GotoDefRef (
  71. void
  72. )
  73. /*++
  74. Routine Description:
  75. Makes the file containing the current definition/reference the
  76. current file and positions the cursor in the line where the
  77. definition/reference takes place.
  78. The state of the query (current instance and definition/reference
  79. indexes) must be set before calling this function.
  80. Arguments:
  81. None.
  82. Return Value:
  83. None.
  84. --*/
  85. {
  86. char *pName = NULL;
  87. WORD Line = 0;
  88. PFILE pFile;
  89. char szFullName[MAX_PATH];
  90. szFullName[0] = '\0';
  91. if (LastQueryType == Q_DEFINITION) {
  92. DefInfo(LastiDef, &pName, &Line);
  93. } else {
  94. RefInfo(LastiRef, &pName, &Line);
  95. }
  96. if (BscInUse && pName) {
  97. if (rootpath(pName, szFullName)) {
  98. strcpy(szFullName, pName);
  99. }
  100. pFile = FileNameToHandle(szFullName,NULL);
  101. if (!pFile) {
  102. pFile = AddFile(szFullName);
  103. if (!FileRead(szFullName, pFile)) {
  104. RemoveFile(pFile);
  105. pFile = NULL;
  106. }
  107. }
  108. if (!pFile) {
  109. errstat(MBRERR_NOSUCHFILE, szFullName);
  110. return;
  111. }
  112. pFileToTop(pFile);
  113. MoveCur(0,Line);
  114. GetLine(Line, buf, pFile);
  115. MoveToSymbol(Line, buf, LastSymbol);
  116. }
  117. }
  118. /**************************************************************************/
  119. void
  120. pascal
  121. MoveToSymbol(
  122. IN LINE Line,
  123. IN char *Buf,
  124. IN char *Symbol
  125. )
  126. /*++
  127. Routine Description:
  128. Moves the cursor to the first occurance of a symbol within
  129. a line. It is case-sensitive.
  130. Arguments:
  131. Line - Line number
  132. Buf - Contents of the line
  133. Symbol - Symbol to look for.
  134. Return Value:
  135. None.
  136. --*/
  137. {
  138. // First Symbol within Buf
  139. //
  140. char *p = Buf;
  141. char *q = Symbol;
  142. char *Mark;
  143. while (*p) {
  144. //
  145. // Look for first character
  146. //
  147. if (*p == *q) {
  148. Mark = p;
  149. //
  150. // compare rest
  151. //
  152. while (*p && *q && *p == *q) {
  153. p++;
  154. q++;
  155. }
  156. if (*q) {
  157. q = Symbol;
  158. p = Mark+1;
  159. } else {
  160. break;
  161. }
  162. } else {
  163. p++;
  164. }
  165. }
  166. if (!*q) {
  167. MoveCur((COL)(Mark-Buf), Line);
  168. }
  169. }
  170. /**************************************************************************/
  171. void
  172. NextDefRef (
  173. void
  174. )
  175. /*++
  176. Routine Description:
  177. Displays next definition or reference of a symbol.
  178. Arguments:
  179. None
  180. Return Value:
  181. None.
  182. --*/
  183. {
  184. IINST Iinst;
  185. // For locating the next def/ref we do the following:
  186. //
  187. // 1.- If the def/ref index is within the current range, we just
  188. // increment it.
  189. // 2.- Otherwise we look for the next instance that matches the
  190. // MBF criteria, and set the def/ref index to the min value of
  191. // the def/ref range for that instance.
  192. // 3.- If no next instance is found, we display an error message
  193. //
  194. if (LastQueryType == Q_DEFINITION) {
  195. if (LastiDef == iDefMax-1) {
  196. Iinst = LastIinst;
  197. do {
  198. LastIinst++;
  199. } while ((LastIinst < IinstMax) &&
  200. (!INST_MATCHES_CRITERIA(LastIinst)));
  201. if (LastIinst == IinstMax ) {
  202. LastIinst = Iinst;
  203. errstat(MBRERR_LAST_DEF, "");
  204. return;
  205. } else {
  206. DefRangeOfInst(LastIinst, &iDefMin, &iDefMax);
  207. LastiDef = iDefMin;
  208. }
  209. } else {
  210. LastiDef++;
  211. }
  212. } else {
  213. if (LastiRef == iRefMax-1) {
  214. Iinst = LastIinst;
  215. do {
  216. LastIinst++;
  217. } while ((LastIinst < IinstMax) &&
  218. (!INST_MATCHES_CRITERIA(LastIinst)));
  219. if (LastIinst == IinstMax) {
  220. LastIinst = Iinst;
  221. errstat(MBRERR_LAST_REF, "");
  222. return;
  223. } else {
  224. RefRangeOfInst(LastIinst, &iRefMin, &iRefMax);
  225. LastiRef = iRefMin;
  226. }
  227. } else {
  228. LastiRef++;
  229. }
  230. }
  231. GotoDefRef();
  232. }
  233. /**************************************************************************/
  234. void
  235. PrevDefRef (
  236. void
  237. )
  238. /*++
  239. Routine Description:
  240. Displays the previous definition or reference of a symbol.
  241. Arguments:
  242. None
  243. Return Value:
  244. None.
  245. --*/
  246. {
  247. IINST Iinst;
  248. BOOL Match;
  249. // For locating the previous def/ref we do the following:
  250. //
  251. // 1.- if the def/ref index is within the current range, we
  252. // just decrement it.
  253. // 2.- Otherwise we look for the most previous instance that
  254. // matches the MBF criteria, and set the def/ref index to
  255. // the maximum value within the def/ref range for that
  256. // instance.
  257. // 3.- If not such instance exist, we display an error message.
  258. //
  259. if (LastQueryType == Q_DEFINITION) {
  260. if (LastiDef == iDefMin) {
  261. if (LastIinst == IinstMin) {
  262. errstat(MBRERR_FIRST_DEF, "");
  263. return;
  264. }
  265. Iinst = LastIinst;
  266. do {
  267. Iinst--;
  268. } while ((LastIinst > IinstMin) &&
  269. (!(Match = INST_MATCHES_CRITERIA(LastIinst))));
  270. if (!Match) {
  271. LastIinst = Iinst;
  272. errstat(MBRERR_FIRST_DEF, "");
  273. return;
  274. } else {
  275. DefRangeOfInst(LastIinst, &iDefMin, &iDefMax);
  276. LastiDef = iDefMax - 1;
  277. }
  278. } else {
  279. LastiDef--;
  280. }
  281. } else {
  282. if (LastiRef == iRefMin) {
  283. if (LastIinst == IinstMin) {
  284. errstat(MBRERR_FIRST_REF, "");
  285. return;
  286. }
  287. Iinst = LastIinst;
  288. do {
  289. Iinst--;
  290. } while ((LastIinst > IinstMin) &&
  291. (!(Match = INST_MATCHES_CRITERIA(LastIinst))));
  292. if (!Match) {
  293. LastIinst = Iinst;
  294. errstat(MBRERR_FIRST_REF, "");
  295. return;
  296. } else {
  297. RefRangeOfInst(LastIinst, &iRefMin, &iRefMax);
  298. LastiRef = iRefMax - 1;
  299. }
  300. } else {
  301. LastiRef--;
  302. }
  303. }
  304. GotoDefRef();
  305. }