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.

185 lines
3.9 KiB

  1. // listref.c
  2. //
  3. // list database references
  4. //
  5. #include <string.h>
  6. #if defined(OS2)
  7. #define INCL_NOCOMMON
  8. #define INCL_DOSPROCESS
  9. #define INCL_DOSSEMAPHORES
  10. #define INCL_DOSFILEMGR
  11. #define INCL_DOSERRORS
  12. #define INCL_DOSMISC
  13. #include <os2.h>
  14. #else
  15. #include <windows.h>
  16. #endif
  17. #include <dos.h>
  18. #include "hungary.h"
  19. #include "bsc.h"
  20. #include "bscsup.h"
  21. #include <stdlib.h>
  22. // forward references
  23. //
  24. static VOID ListRefSym (ISYM isym, MBF mbf);
  25. static VOID ListRefUse (IINST iinst, WORD icol, WORD cuse);
  26. static VOID PutLine(VOID);
  27. static VOID ListRefTitle(LSZ lszType, LSZ lszUsers, MBF mbf);
  28. // static variables
  29. //
  30. static WORD MaxSymLen;
  31. static LPCH bufg;
  32. BOOL BSC_API
  33. ListRefs (MBF mbfReqd)
  34. // scan the database for items which would match the requirements
  35. // and emit their uses and used by lists
  36. //
  37. {
  38. static char szFunction[] = "FUNCTION";
  39. static char szVariable[] = "VARIABLE";
  40. static char szType[] = "TYPE";
  41. static char szMacro[] = "MACRO";
  42. static char szCalledBy[] = "CALLED BY LIST";
  43. static char szUsedBy[] = "USED BY LIST";
  44. bufg = LpvAllocCb(1024);
  45. // no memory.. no reference list
  46. if (!bufg) return FALSE;
  47. MaxSymLen = BSCMaxSymLen();
  48. if (mbfReqd & mbfFuncs) ListRefTitle(szFunction, szCalledBy, mbfFuncs);
  49. if (mbfReqd & mbfVars) ListRefTitle(szVariable, szUsedBy, mbfVars);
  50. if (mbfReqd & mbfMacros) ListRefTitle(szMacro, szUsedBy, mbfMacros);
  51. if (mbfReqd & mbfTypes) ListRefTitle(szType, szUsedBy, mbfTypes);
  52. FreeLpv(bufg);
  53. return TRUE;
  54. }
  55. static VOID
  56. ListRefTitle(LSZ lszType, LSZ lszUsers, MBF mbf)
  57. // format a title
  58. //
  59. {
  60. WORD i,l;
  61. ISYM isym, isymMac;
  62. isymMac = IsymMac();
  63. // format titles
  64. //
  65. strcpy (bufg, lszType);
  66. for (i=strlen(bufg); i < MaxSymLen+5; i++) bufg[i] = ' ';
  67. strcpy (bufg+i, lszUsers);
  68. PutLine();
  69. // underscore titles
  70. //
  71. l = strlen(lszType);
  72. for (i=0; i<l; i++) bufg[i] = '-';
  73. for (; i < MaxSymLen+5; i++) bufg[i] = ' ';
  74. l = i + strlen(lszUsers);
  75. for (; i<l; i++) bufg[i] = '-';
  76. bufg[i] = 0;
  77. PutLine();
  78. for (isym = 0; isym < isymMac; isym++)
  79. ListRefSym (isym, mbf);
  80. strcpy (bufg, " ");
  81. PutLine();
  82. }
  83. static VOID
  84. ListRefSym (ISYM isym, MBF mbf)
  85. // list all the references associated with this symbol
  86. {
  87. IINST iinst, iinstMac, iinstUby;
  88. IUBY iuby, iubyMac;
  89. WORD csym;
  90. WORD icol = MaxSymLen+5;
  91. WORD maxcol = 80 / (MaxSymLen+5)-1;
  92. WORD cnt;
  93. InstRangeOfSym(isym, &iinst, &iinstMac);
  94. for ( ;iinst < iinstMac ; iinst++) {
  95. if (!FInstFilter (iinst, mbf))
  96. continue;
  97. csym = 0;
  98. strcpy (bufg, " ");
  99. strcat (bufg, LszNameFrSym(isym));
  100. strcat (bufg, ": ");
  101. UbyRangeOfInst(iinst, &iuby, &iubyMac);
  102. for ( ;iuby < iubyMac; iuby++) {
  103. if (++csym > maxcol) {
  104. csym = 1;
  105. PutLine();
  106. }
  107. UbyInfo(iuby, &iinstUby, &cnt);
  108. ListRefUse (iinstUby, (WORD)(csym*icol), cnt);
  109. }
  110. }
  111. if (bufg[0]) PutLine();
  112. }
  113. static VOID
  114. ListRefUse (IINST iinst, WORD icol, WORD cuse)
  115. // dump information about the given prop in the location provided
  116. //
  117. {
  118. WORD i, len;
  119. ISYM isym;
  120. BOOL fVar;
  121. TYP typ;
  122. ATR atr;
  123. LSZ lsz;
  124. InstInfo(iinst, &isym, &typ, &atr);
  125. fVar = (typ > INST_TYP_LABEL);
  126. len = strlen(bufg);
  127. lsz = LszNameFrSym(isym);
  128. for (i=len; i<icol; i++) bufg[i] = ' ';
  129. bufg[icol] = 0;
  130. if (fVar) {
  131. if (cuse > 1)
  132. BSCSprintf(bufg+icol, "(%s)[%d] ", lsz, cuse);
  133. else
  134. BSCSprintf(bufg+icol, "(%s) ", lsz);
  135. }
  136. else {
  137. if (cuse > 1)
  138. BSCSprintf(bufg+icol, "%s[%d] ", lsz, cuse);
  139. else
  140. BSCSprintf(bufg+icol, "%s ", lsz);
  141. }
  142. }
  143. static VOID
  144. PutLine()
  145. // write out a single line from the buffer
  146. {
  147. BSCPrintf("%s\n", bufg);
  148. *bufg = 0;
  149. }