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.

165 lines
3.1 KiB

  1. //
  2. //
  3. // GETSBREC.C - Reads records from the .SBR file and stores the fields
  4. // in the appropriate r_.. buffers.
  5. //
  6. #include "sbrfdef.h"
  7. #include "..\mbrmake\mbrmake.h"
  8. // globals for communicating with clients
  9. BYTE near r_rectyp; // current record type
  10. BYTE near r_majv; // major version num
  11. BYTE near r_minv; // minor version num
  12. BYTE near r_lang; // source language
  13. BYTE near r_fcol; // read column #'s
  14. WORD near r_lineno; // current line number
  15. BYTE near r_column = 0; // def/ref column num
  16. WORD near r_ordinal; // symbol ordinal
  17. WORD near r_attrib; // symbol attribute
  18. char near r_bname[PATH_BUF]; // symbol or filename
  19. char near r_cwd[PATH_BUF]; // .sbr file working directory
  20. int near fhCur; // Current input handle
  21. #pragma intrinsic(memcpy)
  22. #pragma intrinsic(strcpy)
  23. #pragma intrinsic(strlen)
  24. #define MY_BUF_SIZE 16384
  25. static char sbrBuf[MY_BUF_SIZE + 1];
  26. static char *pchBuf;
  27. static int cchBuf;
  28. #define GetByte(X) \
  29. { \
  30. if (!cchBuf) { \
  31. cchBuf = read(fhCur, sbrBuf, MY_BUF_SIZE); \
  32. sbrBuf[cchBuf] = 0; \
  33. pchBuf = sbrBuf; \
  34. \
  35. if (cchBuf == 0) \
  36. SBRCorrupt("premature EOF"); \
  37. } \
  38. \
  39. cchBuf--; \
  40. (X) = (unsigned char)*pchBuf++; \
  41. }
  42. #define GetWord(X) \
  43. { \
  44. \
  45. GetByte(((char *)&(X))[0]); \
  46. GetByte(((char *)&(X))[1]); \
  47. }
  48. void
  49. GetStr(char *buf)
  50. // get null terminated string from current .sbr file
  51. //
  52. {
  53. register int l;
  54. for (;;) {
  55. // there is always a NULL after the real buffer
  56. l = strlen(pchBuf);
  57. if (l++ < cchBuf) {
  58. strcpy(buf, pchBuf);
  59. cchBuf -= l;
  60. pchBuf += l;
  61. return;
  62. }
  63. memcpy(buf, pchBuf, cchBuf);
  64. buf += cchBuf;
  65. cchBuf = read(fhCur, sbrBuf, MY_BUF_SIZE);
  66. sbrBuf[cchBuf] = 0;
  67. pchBuf = sbrBuf;
  68. if (cchBuf == 0)
  69. SBRCorrupt("premature EOF");
  70. }
  71. }
  72. BYTE
  73. GetSBRRec()
  74. // read the next record from the current .sbr file
  75. //
  76. {
  77. static fFoundHeader;
  78. BYTE col;
  79. // read rectype, check for EOF as we go
  80. if (!cchBuf) {
  81. cchBuf = read(fhCur, sbrBuf, MY_BUF_SIZE);
  82. sbrBuf[cchBuf] = 0;
  83. pchBuf = sbrBuf;
  84. if (cchBuf == 0) {
  85. fFoundHeader = 0; // this is in case we are reinitialized
  86. return S_EOF;
  87. }
  88. }
  89. cchBuf--;
  90. r_rectyp = (unsigned char)*pchBuf++;
  91. switch(r_rectyp) {
  92. case SBR_REC_HEADER:
  93. if (fFoundHeader)
  94. SBRCorrupt("Multiple Headers");
  95. fFoundHeader = 1;
  96. GetByte(r_majv);
  97. GetByte(r_minv);
  98. GetByte(r_lang);
  99. GetByte(r_fcol);
  100. if (r_majv != 1 || r_minv != 1)
  101. break;
  102. GetStr (r_cwd);
  103. break;
  104. case SBR_REC_MODULE:
  105. GetStr (r_bname);
  106. break;
  107. case SBR_REC_LINDEF:
  108. GetWord (r_lineno);
  109. if (r_lineno)
  110. r_lineno--;
  111. break;
  112. case SBR_REC_SYMDEF:
  113. GetWord (r_attrib);
  114. GetWord (r_ordinal);
  115. if (r_fcol) GetByte (col);
  116. GetStr (r_bname);
  117. break;
  118. case SBR_REC_OWNER:
  119. GetWord (r_ordinal);
  120. break;
  121. case SBR_REC_SYMREFUSE:
  122. case SBR_REC_SYMREFSET:
  123. GetWord (r_ordinal);
  124. if (r_fcol) GetByte (col);
  125. break;
  126. case SBR_REC_MACROBEG:
  127. case SBR_REC_MACROEND:
  128. case SBR_REC_BLKBEG:
  129. case SBR_REC_BLKEND:
  130. case SBR_REC_MODEND:
  131. break;
  132. }
  133. return (r_rectyp);
  134. }