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.

324 lines
6.4 KiB

  1. /*
  2. * BSCdump - Browser Data Base (.BSC) Dumper
  3. * (C) 1988 By Microsoft
  4. *
  5. *
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #define LINT_ARGS
  10. #if defined(OS2)
  11. #define INCL_NOCOMMON
  12. #define INCL_DOSPROCESS
  13. #define INCL_DOSSEMAPHORES
  14. #define INCL_DOSFILEMGR
  15. #define INCL_DOSERRORS
  16. #define INCL_DOSMISC
  17. #include <os2.h>
  18. #else
  19. #include <windows.h>
  20. #endif
  21. #include <dos.h>
  22. #include "bscdump.h"
  23. #include "version.h"
  24. #include "hungary.h"
  25. #include "bsc.h"
  26. #include "bscsup.h"
  27. #include "sbrvers.h"
  28. // this is gross but I don't know where these are supposed to come from
  29. //
  30. #ifndef TRUE
  31. #define TRUE 1
  32. #define FALSE 0
  33. #endif
  34. #if defined (DEBUG)
  35. char fDEBUG = FALSE;
  36. #endif
  37. char *psymbol = NULL;
  38. char *OutlineFileName = NULL;
  39. char far * fname;
  40. extern char *strdup();
  41. void DumpRefsLsz(LSZ);
  42. void DumpDefsLsz(LSZ);
  43. void ListRdds(MBF);
  44. main (argc, argv)
  45. int argc;
  46. char *argv[];
  47. {
  48. unsigned char Cont;
  49. unsigned char fCalltree = FALSE;
  50. unsigned char fSymRefs = FALSE;
  51. unsigned char fSymDefs = FALSE;
  52. unsigned char fRevtree = FALSE;
  53. unsigned char fDumpStats = FALSE;
  54. unsigned char fRedundant = FALSE;
  55. MBF mbf = mbfNil, mbfRef = mbfNil, mbfRdd = mbfNil;
  56. char *s;
  57. --argc;
  58. ++argv;
  59. while (argc && ((**argv == '-') || (**argv == '-'))) {
  60. Cont = TRUE;
  61. while (Cont && *++*argv)
  62. switch (**argv) {
  63. case 'o':
  64. s = *argv+1;
  65. while (*s) {
  66. switch (*s) {
  67. case 'F': mbf |= mbfFuncs; break;
  68. case 'M': mbf |= mbfMacros; break;
  69. case 'V': mbf |= mbfVars; break;
  70. case 'T': mbf |= mbfTypes; break;
  71. }
  72. s++;
  73. }
  74. if (mbf == mbfNil) mbf = mbfAll;
  75. if (--argc == 0)
  76. Usage();
  77. OutlineFileName = *++argv;
  78. Cont = FALSE;
  79. break;
  80. case 'l':
  81. s = *argv+1;
  82. while (*s) {
  83. switch (*s) {
  84. case 'F': mbfRef |= mbfFuncs; break;
  85. case 'M': mbfRef |= mbfMacros; break;
  86. case 'V': mbfRef |= mbfVars; break;
  87. case 'T': mbfRef |= mbfTypes; break;
  88. }
  89. s++;
  90. }
  91. if (mbfRef == mbfNil) mbfRef = mbfAll;
  92. Cont = FALSE;
  93. break;
  94. case 'u':
  95. s = *argv+1;
  96. while (*s) {
  97. switch (*s) {
  98. case 'F': mbfRdd |= mbfFuncs; break;
  99. case 'M': mbfRdd |= mbfMacros; break;
  100. case 'V': mbfRdd |= mbfVars; break;
  101. case 'T': mbfRdd |= mbfTypes; break;
  102. }
  103. s++;
  104. }
  105. if (mbfRdd == mbfNil) mbfRdd = mbfAll;
  106. Cont = FALSE;
  107. break;
  108. case 't':
  109. if (--argc == 0) Usage();
  110. psymbol = *++argv;
  111. fCalltree = TRUE;
  112. Cont = FALSE;
  113. break;
  114. case 'r':
  115. if (--argc == 0) Usage();
  116. psymbol = *++argv;
  117. fSymRefs = TRUE;
  118. Cont = FALSE;
  119. break;
  120. case 'd':
  121. if (--argc == 0) Usage();
  122. psymbol = *++argv;
  123. fSymDefs = TRUE;
  124. Cont = FALSE;
  125. break;
  126. case 'b':
  127. if (--argc == 0) Usage();
  128. psymbol = *++argv;
  129. fRevtree = TRUE;
  130. Cont = FALSE;
  131. break;
  132. case 's':
  133. fDumpStats = TRUE;
  134. break;
  135. default:
  136. Usage();
  137. break;
  138. }
  139. --argc;
  140. ++argv;
  141. }
  142. if (argc < 1) {
  143. Usage();
  144. }
  145. fname = strdup(*argv++);
  146. if (!FOpenBSC(fname)) {
  147. BSCPrintf("BSCdump: cannot open database %s\n", fname);
  148. exit(4);
  149. }
  150. if (fDumpStats)
  151. StatsBSC();
  152. else if (fCalltree)
  153. FCallTreeLsz(psymbol);
  154. else if (fSymRefs)
  155. DumpRefsLsz(psymbol);
  156. else if (fSymDefs)
  157. DumpDefsLsz(psymbol);
  158. else if (fRevtree)
  159. FRevTreeLsz(psymbol);
  160. else if (OutlineFileName)
  161. FOutlineModuleLsz(OutlineFileName, mbf);
  162. else if (mbfRef)
  163. ListRefs(mbfRef);
  164. else if (mbfRdd)
  165. ListRdds(mbfRdd);
  166. else
  167. DumpBSC();
  168. CloseBSC();
  169. free (fname);
  170. }
  171. Usage()
  172. {
  173. BSCPrintf("Microsoft (R) BSCdump Utility ");
  174. BSCPrintf(VERS(rmj, rmm, rup));
  175. BSCPrintf(CPYRIGHT);
  176. BSCPrintf("Usage: bscdump [options] file.bsc\n\n");
  177. BSCPrintf(" -o[FVMT] <file> outline\n");
  178. BSCPrintf(" -l[FVMT] List References\n");
  179. BSCPrintf(" -u[FVMT] List Redundant definitions\n");
  180. BSCPrintf(" -t <sym> Calltree <sym>\n");
  181. BSCPrintf(" -b <sym> Backwards Calltree <sym>\n");
  182. BSCPrintf(" -s Emit BSC stats\n");
  183. BSCPrintf(" -r <sym> List all references to symbol\n");
  184. BSCPrintf(" -d <sym> List all definitions of symbol\n");
  185. exit(1);
  186. }
  187. void DumpDefsLsz(LSZ lszSym)
  188. {
  189. ISYM isym;
  190. IINST iinst, iinstMac;
  191. IDEF idef, idefMac;
  192. LSZ lsz;
  193. WORD line;
  194. isym = IsymFrLsz(lszSym);
  195. if (isym == isymNil) {
  196. BSCPrintf("unknown symbol %s\n", lszSym);
  197. return;
  198. }
  199. InstRangeOfSym(isym, &iinst, &iinstMac);
  200. for (;iinst < iinstMac; iinst++) {
  201. DefRangeOfInst(iinst, &idef, &idefMac);
  202. for ( ; idef < idefMac; idef++) {
  203. DefInfo(idef, &lsz, &line);
  204. BSCPrintf("%s %d\n", lsz, line);
  205. }
  206. }
  207. }
  208. void DumpRefsLsz(LSZ lszSym)
  209. {
  210. ISYM isym;
  211. IINST iinst, iinstMac;
  212. IREF iref, irefMac;
  213. LSZ lsz;
  214. WORD line;
  215. isym = IsymFrLsz(lszSym);
  216. if (isym == isymNil) {
  217. BSCPrintf("unknown symbol %s\n", lszSym);
  218. return;
  219. }
  220. InstRangeOfSym(isym, &iinst, &iinstMac);
  221. for (;iinst < iinstMac; iinst++) {
  222. RefRangeOfInst(iinst, &iref, &irefMac);
  223. for ( ; iref < irefMac; iref++) {
  224. RefInfo(iref, &lsz, &line);
  225. BSCPrintf("%s %d\n", lsz, line);
  226. }
  227. }
  228. }
  229. void ListRdds(MBF mbf)
  230. {
  231. ISYM isym, isymMac, isymname;
  232. IINST iinst, iinstMac;
  233. IUBY iubyFirst, iubyLast;
  234. LSZ lszsymname;
  235. TYP iinsttyp;
  236. ATR iinstattr;
  237. isymMac = IsymMac();
  238. for (isym = 0 ; isym < isymMac ; isym++)
  239. {
  240. lszsymname = LszNameFrSym(isym);
  241. InstRangeOfSym(isym,&iinst,&iinstMac);
  242. for ( ; iinst < iinstMac ; iinst++)
  243. {
  244. UbyRangeOfInst(iinst,&iubyFirst,&iubyLast);
  245. if (iubyFirst == iubyLast)
  246. {
  247. InstInfo(iinst,&isymname, &iinsttyp, &iinstattr);
  248. // iinstattr &= INST_TYPMASK;
  249. if (iinsttyp <= INST_TYP_LABEL && !!(mbf & mbfFuncs))
  250. BSCPrintf("Function not called : %s\n",lszsymname);
  251. else if
  252. ((iinsttyp <= INST_TYP_VARIABLE ||
  253. iinsttyp >= INST_TYP_SEGMENT ) && !!(mbf & mbfVars))
  254. BSCPrintf("Variable not used : %s\n",lszsymname);
  255. else if
  256. (iinsttyp <= INST_TYP_MACRO && !!(mbf & mbfMacros))
  257. BSCPrintf("Macro not referenced : %s\n",lszsymname);
  258. else if (!!(mbf & mbfTypes))
  259. BSCPrintf("Type not referenced : %s\n",lszsymname);
  260. }
  261. }
  262. }
  263. }