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.

1738 lines
42 KiB

  1. /*
  2. readext.c Read Extract file.
  3. Copyright (c) 1989, Microsoft. All Rights Reserved.
  4. 10-09-89 Matt Saettler
  5. 10-11-89 Version 1.0
  6. 10-11-89 MHS New Extract codes
  7. ...
  8. 10-15-89 Completed Autodoc style comments.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <malloc.h>
  13. #include <string.h>
  14. #include <assert.h>
  15. #include <search.h>
  16. #include <io.h>
  17. #include <direct.h>
  18. #include <ctype.h>
  19. #include "types.h"
  20. #include "readext.h"
  21. #include "text.h"
  22. #include "docfmt.h"
  23. #include "process.h"
  24. #include "misc.h"
  25. #include "rtf.h"
  26. #include "errstr.h"
  27. int curFieldLevel=0;
  28. void getDocLevel(aBlock *pBlock, EXTFile *pExt);
  29. void getSrcLine(aBlock *pBlock, EXTFile *pExt);
  30. struct codes_struct Codes[]=
  31. {
  32. // Heading level stuff
  33. TG_BEGINBLOCK , T2_BEGINBLOCK , "BEGINBLOCK", 0,
  34. TG_ENDBLOCK , T2_ENDBLOCK , "ENDBLOCK", 0,
  35. TG_ENDBLOCK , T2_ENDCALLBACK , "ENDCALLBACK", 0,
  36. TG_DOCLEVEL , T2_DOCLEVEL , "DOCLEVEL", 0,
  37. TG_SRCLINE , T2_SRCLINE , "SRCLINE", 0,
  38. TG_BEGINHEAD , T2_BEGINHEAD , "BeginHead", 0,
  39. TG_EXTRACTID , T2_EXTRACTID , "ExtractID", 0,
  40. TG_EXTRACTVER , T2_EXTRACTVER , "ExtractVer", 0,
  41. TG_EXTRACTDATE , T2_EXTRACTDATE , "ExtractDate", 0,
  42. TG_ENDHEAD , T2_ENDHEAD , "EndHead", 0,
  43. TG_BEGINHEADER , T2_BEGINHEADER , "BeginHeader", 0,
  44. TG_ENDHEADER , T2_ENDHEADER , "EndHeader", 0,
  45. // API (function) block
  46. TG_TYPE , T2_FUNCTYPE , "ApiType", 0,
  47. TG_NAME , T2_FUNCNAME , "ApiName", 0,
  48. TG_DESC , T2_FUNCDESC , "ApiDesc", 0,
  49. TG_PARMTYPE , T2_PARMTYPE , "ApiParmType", 0,
  50. TG_PARMNAME , T2_PARMNAME , "ApiParmName", 0,
  51. TG_PARMDESC , T2_PARMDESC , "ApiParmDesc", 0,
  52. TG_FLAGNAME , T2_FLAGNAMEPARM , "ApiFlagNameParm", 0,
  53. TG_FLAGDESC , T2_FLAGDESCPARM , "ApiFlagDescParm", 0,
  54. TG_FLAGNAME , T2_FLAGNAMERTN , "ApiFlagNameRtn", 0,
  55. TG_FLAGDESC , T2_FLAGDESCRTN , "APIFlagDescRtn", 0,
  56. TG_RTNDESC , T2_RTNDESC , "ApiRtnDesc", 0,
  57. TG_COMMENT , T2_COMMENT , "ApiComment", 0,
  58. TG_XREF , T2_XREF , "ApiXref", 0,
  59. TG_USES , T2_USES , "ApiUses", 0,
  60. // callback block
  61. TG_TYPE , T2_CBTYPE , "CBTYPE", 0,
  62. TG_NAME , T2_CBNAME , "CBNAME", 0,
  63. TG_DESC , T2_CBDESC , "CBDESC", 0,
  64. TG_PARMTYPE , T2_CBPARMTYPE , "CBPARMTYPE", 0,
  65. TG_PARMNAME , T2_CBPARMNAME , "CBPARMNAME", 0,
  66. TG_PARMDESC , T2_CBPARMDESC , "CBPARMDESC", 0,
  67. TG_FLAGNAME , T2_CBFLAGNAMEPARM , "CBFLAGNAMEPARM", 0,
  68. TG_FLAGDESC , T2_CBFLAGDESCPARM , "CBFLAGDESCPARM", 0,
  69. TG_RTNDESC , T2_CBRTNDESC , "CBRTNDESC", 0,
  70. TG_FLAGNAME , T2_CBFLAGNAMERTN , "CBFLAGNAMERTN", 0,
  71. TG_FLAGDESC , T2_CBFLAGDESCRTN , "CBFLAGDESCRTN", 0,
  72. TG_COMMENT , T2_CBCOMMENT , "CBCOMMENT", 0,
  73. TG_XREF , T2_CBXREF , "CBXref", 0,
  74. TG_USES , T2_CBUSES , "CBUses", 0,
  75. TG_REGNAME , T2_CBREGNAME , "CBRegNAME", 0,
  76. TG_REGDESC , T2_CBREGDESC , "CBRegDESC", 0,
  77. TG_REGNAME , T2_CBFLAGNAMEREG , "CBFLAGNAMEReg", 0,
  78. TG_REGDESC , T2_CBFLAGDESCREG , "CBFLAGDESCReg", 0,
  79. #ifdef WARPAINT
  80. // Interrupt Block
  81. TG_TYPE , T2_INTTYPE , "INTTYPE", 0,
  82. TG_NAME , T2_INTNAME , "INTNAME", 0,
  83. TG_DESC , T2_INTDESC , "INTDESC", 0,
  84. //TG_PARMTYPE , T2_INTPARMTYPE , "INTPARMTYPE", 0,
  85. //TG_PARMNAME , T2_INTPARMNAME , "INTPARMNAME", 0,
  86. //TG_PARMDESC , T2_INTPARMDESC , "INTPARMDESC", 0,
  87. //TG_FLAGNAME , T2_INTFLAGNAMEPARM , "INTFLAGNAMEPARM", 0,
  88. //TG_FLAGDESC , T2_INTFLAGDESCPARM , "INTFLAGDESCPARM", 0,
  89. TG_RTNDESC , T2_INTRTNDESC , "INTRTNDESC", 0,
  90. TG_FLAGNAME , T2_INTFLAGNAMERTN , "INTFLAGNAMERTN", 0,
  91. TG_FLAGDESC , T2_INTFLAGDESCRTN , "INTFLAGDESCRTN", 0,
  92. TG_COMMENT , T2_INTCOMMENT , "INTCOMMENT", 0,
  93. TG_XREF , T2_INTXREF , "INTXref", 0,
  94. TG_USES , T2_INTUSES , "INTUses", 0,
  95. TG_REGNAME , T2_INTREGNAME , "INTRegNAME", 0,
  96. TG_REGDESC , T2_INTREGDESC , "INTRegDESC", 0,
  97. TG_FLAGNAME , T2_INTFLAGNAMEREGRTN , "INTFLAGNAMERegRtn", 0,
  98. TG_FLAGDESC , T2_INTFLAGDESCREGRTN , "IntFLAGDESCRegRtn", 0,
  99. TG_FLAGNAME , T2_INTFLAGNAMEREG , "INTFLAGNAMEReg", 0,
  100. TG_FLAGDESC , T2_INTFLAGDESCREG , "IntFLAGDESCReg", 0,
  101. #endif
  102. // Asm Block
  103. TG_TYPE , T2_ASMTYPE , "ASMTYPE", 0,
  104. TG_NAME , T2_ASMNAME , "ASMNAME", 0,
  105. TG_DESC , T2_ASMDESC , "ASMDESC", 0,
  106. TG_PARMTYPE , T2_ASMPARMTYPE , "ASMPARMTYPE", 0,
  107. TG_PARMNAME , T2_ASMPARMNAME , "ASMPARMNAME", 0,
  108. TG_PARMDESC , T2_ASMPARMDESC , "ASMPARMDESC", 0,
  109. TG_FLAGNAME , T2_ASMFLAGNAMEPARM , "ASMFLAGNAMEPARM", 0,
  110. TG_FLAGDESC , T2_ASMFLAGDESCPARM , "ASMFLAGDESCPARM", 0,
  111. TG_RTNDESC , T2_ASMRTNDESC , "ASMRTNDESC", 0,
  112. TG_FLAGNAME , T2_ASMFLAGNAMERTN , "ASMFLAGNAMERTN", 0,
  113. TG_FLAGDESC , T2_ASMFLAGDESCRTN , "ASMFLAGDESCRTN", 0,
  114. TG_COMMENT , T2_ASMCOMMENT , "ASMCOMMENT", 0,
  115. TG_XREF , T2_ASMXREF , "ASMXref", 0,
  116. TG_USES , T2_ASMUSES , "ASMUses", 0,
  117. TG_REGNAME , T2_ASMREGNAMERTN , "ASMRegNAMERtn", 0,
  118. TG_REGDESC , T2_ASMREGDESCRTN , "ASMRegDESCRtn", 0,
  119. TG_REGNAME , T2_ASMREGNAME , "ASMRegNAME", 0,
  120. TG_REGDESC , T2_ASMREGDESC , "ASMRegDESC", 0,
  121. TG_FLAGNAME , T2_ASMFLAGNAMEREGRTN , "ASMFLAGNAMERegRtn", 0,
  122. TG_FLAGDESC , T2_ASMFLAGDESCREGRTN , "AsmFLAGDESCRegRtn", 0,
  123. TG_FLAGNAME , T2_ASMFLAGNAMEREG , "ASMFLAGNAMEReg", 0,
  124. TG_FLAGDESC , T2_ASMFLAGDESCREG , "AsmFLAGDESCReg", 0,
  125. TG_COND , T2_ASMCOND , "AsmCond", 0,
  126. // Asm CallBack Block
  127. TG_TYPE , T2_ASMCBTYPE , "ASMCBTYPE", 0,
  128. TG_NAME , T2_ASMCBNAME , "ASMCBNAME", 0,
  129. TG_DESC , T2_ASMCBDESC , "ASMCBDESC", 0,
  130. TG_PARMTYPE , T2_ASMPARMTYPE , "ASMCBPARMTYPE", 0,
  131. TG_PARMNAME , T2_ASMCBPARMNAME , "ASMCBPARMNAME", 0,
  132. TG_PARMDESC , T2_ASMCBPARMDESC , "ASMCBPARMDESC", 0,
  133. TG_FLAGNAME , T2_ASMCBFLAGNAMEPARM , "ASMCBFLAGNAMEPARM", 0,
  134. TG_FLAGDESC , T2_ASMCBFLAGDESCPARM , "ASMCBFLAGDESCPARM", 0,
  135. TG_RTNDESC , T2_ASMCBRTNDESC , "ASMCBRTNDESC", 0,
  136. TG_FLAGNAME , T2_ASMCBFLAGNAMERTN , "ASMCBFLAGNAMERTN", 0,
  137. TG_FLAGDESC , T2_ASMCBFLAGDESCRTN , "ASMCBFLAGDESCRTN", 0,
  138. TG_COMMENT , T2_ASMCBCOMMENT , "ASMCBCOMMENT", 0,
  139. TG_XREF , T2_ASMCBXREF , "ASMCBXref", 0,
  140. TG_USES , T2_ASMCBUSES , "ASMCBUses", 0,
  141. TG_REGNAME , T2_ASMCBREGNAMERTN , "ASMCBRegNAMERtn", 0,
  142. TG_REGDESC , T2_ASMCBREGDESCRTN , "ASMCBRegDESCRtn", 0,
  143. TG_REGNAME , T2_ASMCBREGNAME , "ASMCBRegNAME", 0,
  144. TG_REGDESC , T2_ASMCBREGDESC , "ASMCBRegDESC", 0,
  145. TG_FLAGNAME , T2_ASMCBFLAGNAMEREGRTN, "ASMCBFLAGNAMERegRtn", 0,
  146. TG_FLAGDESC , T2_ASMCBFLAGDESCREGRTN, "AsmCBFLAGDESCRegRtn", 0,
  147. TG_FLAGNAME , T2_ASMCBFLAGNAMEREG , "ASMCBFLAGNAMEReg", 0,
  148. TG_FLAGDESC , T2_ASMCBFLAGDESCREG , "AsmCBFLAGDESCReg", 0,
  149. TG_COND , T2_ASMCBCOND , "AsmCBCond", 0,
  150. // Message Block
  151. TG_TYPE , T2_MSGTYPE , "MSGTYPE", 0,
  152. TG_NAME , T2_MSGNAME , "MSGNAME", 0,
  153. TG_DESC , T2_MSGDESC , "MSGDESC", 0,
  154. TG_PARMTYPE , T2_MSGPARMTYPE , "MSGPARMTYPE", 0,
  155. TG_PARMNAME , T2_MSGPARMNAME , "MSGPARMNAME", 0,
  156. TG_PARMDESC , T2_MSGPARMDESC , "MSGPARMDESC", 0,
  157. TG_FLAGNAME , T2_MSGFLAGNAMEPARM , "MSGFLAGNAMEPARM", 0,
  158. TG_FLAGDESC , T2_MSGFLAGDESCPARM , "MSGFLAGDESCPARM", 0,
  159. TG_RTNDESC , T2_MSGRTNDESC , "MSGRTNDESC", 0,
  160. TG_FLAGNAME , T2_MSGFLAGNAMERTN , "MSGFLAGNAMERTN", 0,
  161. TG_FLAGDESC , T2_MSGFLAGDESCRTN , "MSGFLAGDESCRTN", 0,
  162. TG_COMMENT , T2_MSGCOMMENT , "MSGCOMMENT", 0,
  163. TG_XREF , T2_MSGXREF , "MsgXref", 0,
  164. TG_USES , T2_MSGUSES , "MSGUses", 0,
  165. TG_REGNAME , T2_MSGREGNAME , "MsgRegNAME", 0,
  166. TG_REGDESC , T2_MSGREGDESC , "MsgRegDESC", 0,
  167. TG_FLAGNAME , T2_MSGFLAGNAMEREG , "MsgFLAGNAMEReg", 0,
  168. TG_FLAGDESC , T2_MSGFLAGDESCREG , "MsgFLAGDESCReg", 0,
  169. // Typedef struct Block
  170. TG_NAME , T2_STRUCTNAME , "STRUCTNAME", 0,
  171. TG_DESC , T2_STRUCTDESC , "STRUCTDESC", 0,
  172. TG_FIELDTYPE , T2_STRUCTFIELDTYPE , "STRUCTFIELDTYPE", 0,
  173. TG_FIELDNAME , T2_STRUCTFIELDNAME , "STRUCTFIELDNAME", 0,
  174. TG_FIELDDESC , T2_STRUCTFIELDDESC , "STRUCTFIELDDESC", 0,
  175. TG_FLAGNAME , T2_STRUCTFLAGNAME , "STRUCTFLAGNAME", 0,
  176. TG_FLAGDESC , T2_STRUCTFLAGDESC , "STRUCTFLAGDESC", 0,
  177. TG_NAME , T2_STRUCTSTRUCTNAME , "structstructName", 0,
  178. TG_DESC , T2_STRUCTSTRUCTDESC , "structstructDesc", 0,
  179. TG_ENDBLOCK , T2_STRUCTSTRUCTEND , "structstructEnd", 0,
  180. TG_NAME , T2_STRUCTUNIONNAME , "structunionName", 0,
  181. TG_DESC , T2_STRUCTUNIONDESC , "structunionDesc", 0,
  182. TG_ENDBLOCK , T2_STRUCTUNIONEND , "structunionEnd", 0,
  183. TG_OTHERTYPE , T2_STRUCTOTHERTYPE , "STRUCTOTHERTYPE", 0,
  184. TG_OTHERNAME , T2_STRUCTOTHERNAME , "STRUCTOTHERNAME", 0,
  185. TG_OTHERDESC , T2_STRUCTOTHERDESC , "structotherdesc", 0,
  186. TG_TAG , T2_STRUCTTAGNAME , "STRUCTTAGNAME", 0,
  187. TG_COMMENT , T2_STRUCTCOMMENT , "STRUCTCOMMENT", 0,
  188. TG_XREF , T2_STRUCTXREF , "STRUCTXref", 0,
  189. // Typedef union Block
  190. TG_NAME , T2_UNIONNAME , "UNIONNAME", 0,
  191. TG_DESC , T2_UNIONDESC , "UNIONDESC", 0,
  192. TG_FIELDTYPE , T2_UNIONFIELDTYPE , "UNIONFIELDTYPE", 0,
  193. TG_FIELDNAME , T2_UNIONFIELDNAME , "UNIONFIELDNAME", 0,
  194. TG_FIELDDESC , T2_UNIONFIELDDESC , "UNIONFIELDDESC", 0,
  195. TG_FLAGNAME , T2_UNIONFLAGNAME , "UNIONFLAGNAME", 0,
  196. TG_FLAGDESC , T2_UNIONFLAGDESC , "UNIONFLAGDESC", 0,
  197. TG_NAME , T2_UNIONSTRUCTNAME , "UNIONstructName", 0,
  198. TG_DESC , T2_UNIONSTRUCTDESC , "UNIONstructDesc", 0,
  199. TG_ENDBLOCK , T2_UNIONSTRUCTEND , "UNIONstructEnd", 0,
  200. TG_NAME , T2_UNIONUNIONNAME , "UNIONunionName", 0,
  201. TG_DESC , T2_UNIONUNIONDESC , "UNIONunionDesc", 0,
  202. TG_ENDBLOCK , T2_UNIONUNIONEND , "UNIONunionEnd", 0,
  203. TG_OTHERTYPE , T2_UNIONOTHERTYPE , "UNIONOTHERTYPE", 0,
  204. TG_OTHERNAME , T2_UNIONOTHERNAME , "UNIONOTHERNAME", 0,
  205. TG_OTHERDESC , T2_UNIONOTHERDESC , "UNIONOTHERDESC", 0,
  206. TG_TAG , T2_UNIONTAGNAME , "UNIONTAGNAME", 0,
  207. TG_COMMENT , T2_UNIONCOMMENT , "UNIONCOMMENT", 0,
  208. TG_XREF , T2_UNIONXREF , "UNIONXref", 0,
  209. // end marker
  210. 0 , 0 , 0, 0
  211. };
  212. /*
  213. * @doc INTERNAL READEXT
  214. *
  215. * @func char * | nextText | This updates the curlinepos for
  216. * the specified Extracted file.
  217. *
  218. * @parm EXTFile * | pExt | Specifies the Extracted structure.
  219. *
  220. */
  221. void nextText( EXTFile *pExt )
  222. {
  223. if( !pExt)
  224. return;
  225. while( (pExt->lineBuffer[pExt->curlinepos] != '\n') &&
  226. (pExt->lineBuffer[pExt->curlinepos] != '\0') &&
  227. (pExt->lineBuffer[pExt->curlinepos] != '\t') &&
  228. (pExt->lineBuffer[pExt->curlinepos] != ' ') )
  229. {
  230. pExt->curlinepos++;
  231. }
  232. while( (pExt->lineBuffer[pExt->curlinepos] != '\n') &&
  233. (pExt->lineBuffer[pExt->curlinepos] != '\0') &&
  234. ( (pExt->lineBuffer[pExt->curlinepos] == '\t') ||
  235. (pExt->lineBuffer[pExt->curlinepos] == ' ') ) )
  236. {
  237. pExt->curlinepos++;
  238. }
  239. }
  240. /*
  241. * @doc INTERNAL READEXT
  242. *
  243. * @func DWORD | getTag | This function finds the possible tag in the
  244. * lineBuffer.
  245. *
  246. * @rdesc The return value is the command of the tag in the line buffer.
  247. * It is NULL if the tag is not found.
  248. *
  249. * @flag loword | Uniquely identifies the tag.
  250. *
  251. * @flag TYPE(loword) | Type of the tag.
  252. *
  253. * @flag hiword | Group of the tag.
  254. *
  255. * @xref _getTag
  256. */
  257. DWORD getTag( EXTFile *pExt )
  258. {
  259. if(pExt->curtag)
  260. return(pExt->curtag);
  261. pExt->curlinepos=0;
  262. while( (pExt->lineBuffer[pExt->curlinepos] != '@') &&
  263. (pExt->lineBuffer[pExt->curlinepos] != '\n') &&
  264. (pExt->lineBuffer[pExt->curlinepos] != '\0') &&
  265. ( (pExt->lineBuffer[pExt->curlinepos] == '\t') ||
  266. (pExt->lineBuffer[pExt->curlinepos] == ' ') ) ) {
  267. pExt->curlinepos++;
  268. }
  269. if( pExt->lineBuffer[pExt->curlinepos] == '@' )
  270. {
  271. pExt->curlinepos++;
  272. pExt->curtag=_getTag(pExt);
  273. return(pExt->curtag);
  274. }
  275. else if( pExt->lineBuffer[pExt->curlinepos] == '\n' )
  276. {
  277. pExt->lineBuffer[pExt->curlinepos] = '\0';
  278. return( 0 );
  279. }
  280. else
  281. return( 0 );
  282. }
  283. /*
  284. * @doc INTERNAL READEXT
  285. *
  286. * @func DWORD | _getTag | This function returns the command value of the
  287. * tag on the buffer.
  288. *
  289. * @rdesc The return value is the command of the tag in the line buffer.
  290. * It is NULL if the tag is not found.
  291. *
  292. * @flag loword | Uniquely identifies the tag.
  293. *
  294. * @flag TYPE(loword) | Type of the tag.
  295. *
  296. * @flag hiword | Group of the tag.
  297. *
  298. */
  299. DWORD
  300. _getTag(EXTFile *pExt)
  301. {
  302. int cur_command;
  303. for(cur_command=0;Codes[cur_command].pchcommand != NULL; cur_command++)
  304. { /* we are still comparing a valid command... */
  305. if(strnicmp(pExt->lineBuffer+ pExt->curlinepos,Codes[cur_command].pchcommand,Codes[cur_command].size)==0)
  306. { /* we found a match */
  307. pExt->curlinepos+=Codes[cur_command].size;
  308. return( ( (DWORD)Codes[cur_command].icommand << 16L) +
  309. ( (DWORD)Codes[cur_command].igeneral) );
  310. }
  311. }
  312. /* didn't match any known tag */
  313. return(0);
  314. }
  315. /*
  316. * @doc INTERNAL READEXT
  317. *
  318. * @func int | initreadext | This function is used to initialize the
  319. * Read External functions. It must be called before any of the readext
  320. * functions are called.
  321. *
  322. * @rdesc This function returs TRUE if the initialization was successful.
  323. *
  324. */
  325. int
  326. initreadext()
  327. {
  328. int cur_command;
  329. for(cur_command=0;Codes[cur_command].pchcommand != NULL; cur_command++)
  330. { /* we are still comparing a valid command... */
  331. Codes[cur_command].size=strlen(Codes[cur_command].pchcommand);
  332. }
  333. /* INIT OK */
  334. return(TRUE);
  335. }
  336. /*
  337. * @doc INTERNAL READEXT
  338. *
  339. * @func int | processText | This function takes the text for the
  340. * already found tag. (starting at the given point) and puts it
  341. * into the specified place.
  342. *
  343. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  344. *
  345. * @parm aLine * | place | Specifies the place to store the text.
  346. *
  347. * @rdesc The return value is non zero if there was an error
  348. * while processing the file.
  349. */
  350. int processText( EXTFile *pExt, aLine **place )
  351. {
  352. int ok;
  353. aLine * line;
  354. if( place == NULL )
  355. {
  356. return( ST_ERROR );
  357. }
  358. /* if we have more text on line left place into
  359. aLine
  360. */
  361. if( pExt->lineBuffer[pExt->curlinepos])
  362. {
  363. line = lineMake( pExt->lineBuffer + pExt->curlinepos );
  364. if( line == NULL )
  365. {
  366. return( ST_MEMORY );
  367. }
  368. lineAdd( place, line );
  369. }
  370. /* get rest of text for this tag. */
  371. ok = getLine(pExt);
  372. while( ok && ( !getTag(pExt) ) )
  373. {
  374. line = lineMake( pExt->lineBuffer );
  375. if( line == NULL )
  376. {
  377. return( ST_MEMORY );
  378. }
  379. lineAdd( place, line );
  380. ok = getLine( pExt );
  381. }
  382. if( !ok )
  383. return( ST_ERROR_EOF );
  384. else
  385. return( 0 );
  386. }
  387. /*
  388. * @doc INTERNAL READEXT
  389. *
  390. * @func char * | getFlag | This function gets a list of Flag blocks
  391. * from the file. The flag blocks are stored in the list.
  392. *
  393. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  394. *
  395. * @parm aFlag * * | flag | Specifies the head of the list to place
  396. * the list of flags.
  397. *
  398. * @rdesc The return value is non zero if there was an error
  399. * while processing the file.
  400. */
  401. int getFlag( EXTFile *pExt, aFlag * * flag )
  402. {
  403. int rtn;
  404. int ok, nStatus;
  405. char * text;
  406. char * tag;
  407. int itag;
  408. int startType;
  409. DWORD dTag;
  410. aFlag *curFlag;
  411. aFlag *tFlag;
  412. if( flag == NULL )
  413. return( ST_ERROR );
  414. /* find begin of flag */
  415. itag=(int)getTag(pExt);
  416. startType=TYPE(itag);
  417. if( itag != TG_FLAGNAME )
  418. return( ST_BADOBJ );
  419. curFlag=flagAlloc();
  420. if( curFlag == NULL )
  421. return( ST_MEMORY );
  422. if(!*flag)
  423. *flag =curFlag;
  424. else
  425. {
  426. tFlag=*flag;
  427. while(tFlag->next)
  428. {
  429. tFlag=tFlag->next;
  430. }
  431. tFlag->next=curFlag;
  432. }
  433. nStatus = processText( pExt, &((curFlag)->name) );
  434. if( nStatus)
  435. return( nStatus );
  436. /* find desc of flag */
  437. itag=(int)getTag(pExt);
  438. if( itag == TG_FLAGDESC )
  439. {
  440. nStatus = processText( pExt, &((curFlag)->desc) );
  441. if( nStatus)
  442. return( nStatus );
  443. }
  444. return( 0 );
  445. }
  446. /*
  447. * @doc INTERNAL READEXT
  448. *
  449. * @func char * | getField | This function gets a list of Field blocks
  450. * from the file. The blocks are stored in the list.
  451. *
  452. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  453. *
  454. * @parm aField * * | field | Specifies the head of the list to place
  455. * the list of fields.
  456. *
  457. * @rdesc The return value is non zero if there was an error
  458. * while processing the file.
  459. */
  460. int getSUType( EXTFile *pExt, aField * * field )
  461. {
  462. int rtn;
  463. int ok, nStatus;
  464. // char * text;
  465. // char * tag;
  466. int itag;
  467. // int startType;
  468. DWORD dTag;
  469. aField *curfield;
  470. aField *tfield;
  471. aType *curtype;
  472. if( field == NULL )
  473. return( ST_ERROR );
  474. /* find begin of flag */
  475. itag=(int)getTag(pExt);
  476. // startType=TYPE(itag);
  477. if( itag != TG_FIELDTYPE )
  478. return( ST_BADOBJ );
  479. curfield=fieldAlloc();
  480. if( curfield == NULL )
  481. return( ST_MEMORY );
  482. if(!*field)
  483. *field =curfield;
  484. else
  485. {
  486. tfield=*field;
  487. while(tfield->next)
  488. {
  489. tfield=tfield->next;
  490. }
  491. tfield->next=curfield;
  492. }
  493. curfield->wType=FIELD_TYPE;
  494. curtype=typeAlloc();
  495. if(curtype == NULL)
  496. return (ST_MEMORY);
  497. curtype->level=curFieldLevel;
  498. curfield->ptr=(void *)curtype;
  499. nStatus = processText( pExt, &((curtype)->type) );
  500. if( nStatus)
  501. return( nStatus );
  502. /* find name of field */
  503. itag=(int)getTag(pExt);
  504. if( itag == TG_FIELDNAME )
  505. {
  506. nStatus = processText( pExt, &((curtype)->name) );
  507. if( nStatus)
  508. return( nStatus );
  509. }
  510. else
  511. return( ST_BADOBJ );
  512. /* find desc of field */
  513. itag=(int)getTag(pExt);
  514. if( itag == TG_FIELDDESC )
  515. {
  516. nStatus = processText( pExt, &((curtype)->desc) );
  517. if( nStatus)
  518. return( nStatus );
  519. }
  520. else
  521. return( ST_BADOBJ );
  522. /* process flags and other info */
  523. nStatus = 0;
  524. itag=(int)getTag(pExt);
  525. while( (nStatus == 0) &&
  526. ( itag == TG_FLAGNAME) )
  527. {
  528. nStatus = getFlag( pExt, &((curtype)->flag) );
  529. if( nStatus )
  530. return( nStatus );
  531. itag=(int)getTag(pExt);
  532. }
  533. return(nStatus);
  534. }
  535. /*
  536. * @doc INTERNAL READEXT
  537. *
  538. * @func char * | getReg | This function gets a list of register blocks
  539. * from the file.
  540. *
  541. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  542. *
  543. * @parm aReg ** | reg | Specifies the head of the list of reg blocks
  544. * to save.
  545. *
  546. * @rdesc The return value is non zero if there was an error
  547. * while processing the file.
  548. */
  549. int getReg( EXTFile *pExt, aReg * * reg )
  550. {
  551. int nStatus;
  552. aFlag * flag;
  553. aReg * curreg;
  554. int itag;
  555. int startType;
  556. assert(reg);
  557. assert(pExt);
  558. /* find name of parameter */
  559. itag=(int)getTag(pExt);
  560. startType=TYPE((DWORD)itag);
  561. if( itag != TG_REGNAME )
  562. {
  563. fprintf(errfp,"Error: Tag not regname at line %d in %s\n",
  564. pExt->curlineno,
  565. pExt->EXTFilename);
  566. return( ST_BADOBJ );
  567. }
  568. curreg = regAlloc();
  569. if( curreg == NULL )
  570. return( ST_MEMORY );
  571. regAdd(reg, curreg);
  572. // itag = (int)getTag(pExt);
  573. if( itag == TG_REGNAME)
  574. {
  575. nStatus = processText( pExt, &((curreg)->name) );
  576. if( nStatus )
  577. return( nStatus );
  578. }
  579. else
  580. assert(TRUE); // what are we doing here?
  581. /* find desc of parameter */
  582. itag = (int)getTag(pExt);
  583. if( itag == TG_REGDESC )
  584. {
  585. nStatus = processText( pExt, &((curreg)->desc) );
  586. if( nStatus )
  587. return( nStatus );
  588. }
  589. else
  590. fprintf(errfp,"Warning: Register without Description at line %d in %s\n",
  591. pExt->curlineno,
  592. pExt->EXTFilename);
  593. /* process flags and other info */
  594. nStatus = 0;
  595. itag=(int)getTag(pExt);
  596. while( (nStatus == 0) &&
  597. ( itag == TG_FLAGNAME) )
  598. {
  599. nStatus = getFlag( pExt, &((curreg)->flag) );
  600. if( nStatus )
  601. return( nStatus );
  602. itag=(int)getTag(pExt);
  603. }
  604. return(nStatus);
  605. }
  606. /*
  607. * @doc INTERNAL READEXT
  608. *
  609. * @func char * | getCond | This function gets a Conditional block
  610. * from the file.
  611. *
  612. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  613. *
  614. * @parm aCond ** | ppCond | Specifies the head of the list of Cond blocks
  615. * to save.
  616. *
  617. * @rdesc The return value is non zero if there was an error
  618. * while processing the file.
  619. */
  620. int getCond( EXTFile *pExt, aCond * * ppCond )
  621. {
  622. int nStatus;
  623. aFlag * flag;
  624. aCond * curcond;
  625. // aReg * curreg;
  626. int itag;
  627. int startType;
  628. assert(ppCond);
  629. assert(pExt);
  630. /* find name of parameter */
  631. itag=(int)getTag(pExt);
  632. startType=TYPE((DWORD)itag);
  633. if( itag != TG_COND )
  634. {
  635. fprintf(errfp,"Error: Tag not Cond at line %d in %s\n",
  636. pExt->curlineno,
  637. pExt->EXTFilename);
  638. return( ST_BADOBJ );
  639. }
  640. curcond= condAlloc();
  641. if( curcond == NULL )
  642. return( ST_MEMORY );
  643. condAdd(ppCond, curcond);
  644. // itag = (int)getTag(pExt);
  645. if( itag == TG_COND)
  646. {
  647. nextText( pExt );
  648. nStatus = processText( pExt, &((curcond)->desc) );
  649. if( nStatus )
  650. return( nStatus );
  651. }
  652. else
  653. assert(TRUE); // what are we doing here?
  654. /* process regs and other info */
  655. nStatus = 0;
  656. itag=(int)getTag(pExt);
  657. while( (nStatus == 0) &&
  658. ( itag == TG_REGNAME) )
  659. {
  660. nStatus = getReg( pExt, &((curcond)->regs) );
  661. if( nStatus )
  662. return( nStatus );
  663. itag=(int)getTag(pExt);
  664. }
  665. return(nStatus);
  666. }
  667. /*
  668. * @doc INTERNAL READEXT
  669. *
  670. * @func char * | getParm | This function gets a list of parameter blocks
  671. * from the file.
  672. *
  673. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  674. *
  675. * @parm aParm ** | parm | Specifies the head of the list.
  676. *
  677. * @rdesc The return value is non zero if there was an error
  678. * while processing the file.
  679. */
  680. int getParm( EXTFile *pExt, aParm * * parm )
  681. {
  682. int nStatus;
  683. aFlag * flag;
  684. aParm * curparm;
  685. int itag;
  686. int startType;
  687. assert(parm);
  688. assert(pExt);
  689. /* find name of parameter */
  690. itag=(int)getTag(pExt);
  691. startType=TYPE((DWORD)itag);
  692. if( itag != TG_PARMTYPE )
  693. return( ST_BADOBJ );
  694. curparm = parmAlloc();
  695. if( curparm == NULL )
  696. return( ST_MEMORY );
  697. parmAdd(parm, curparm);
  698. /* find type of parameter */
  699. if( itag == TG_PARMTYPE )
  700. {
  701. nStatus = processText( pExt, &((curparm)->type) );
  702. if( nStatus )
  703. return( nStatus );
  704. }
  705. itag = (int)getTag(pExt);
  706. if( itag == TG_PARMNAME)
  707. {
  708. nStatus = processText( pExt, &((curparm)->name) );
  709. if( nStatus )
  710. return( nStatus );
  711. }
  712. /* find desc of parameter */
  713. itag = (int)getTag(pExt);
  714. if( itag == TG_PARMDESC )
  715. {
  716. nStatus = processText( pExt, &((curparm)->desc) );
  717. if( nStatus )
  718. return( nStatus );
  719. }
  720. /* process flags and other info */
  721. nStatus = 0;
  722. itag=(int)getTag(pExt);
  723. while( (nStatus == 0) &&
  724. ( itag == TG_FLAGNAME) )
  725. {
  726. nStatus = getFlag( pExt, &((curparm)->flag) );
  727. if( nStatus )
  728. return( nStatus );
  729. itag=(int)getTag(pExt);
  730. }
  731. return(nStatus);
  732. }
  733. /*
  734. * @doc INTERNAL READEXT
  735. *
  736. * @func char * | getParm | This function gets a list of parameter blocks
  737. * from the file.
  738. *
  739. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  740. *
  741. * @parm aParm ** | parm | Specifies the head of the list.
  742. *
  743. * @rdesc The return value is non zero if there was an error
  744. * while processing the file.
  745. */
  746. int getOther( EXTFile *pExt, aOther * * other )
  747. {
  748. int nStatus;
  749. aOther * curother;
  750. int itag;
  751. int startType;
  752. assert(other);
  753. assert(pExt);
  754. /* find name of parameter */
  755. itag=(int)getTag(pExt);
  756. startType=TYPE((DWORD)itag);
  757. if( itag != TG_OTHERTYPE )
  758. return( ST_BADOBJ );
  759. curother = otherAlloc();
  760. if( curother == NULL )
  761. return( ST_MEMORY );
  762. otherAdd(other, curother);
  763. /* find type of other */
  764. nStatus = processText( pExt, &((curother)->type) );
  765. if( nStatus )
  766. return( nStatus );
  767. itag = (int)getTag(pExt);
  768. nStatus = processText( pExt, &((curother)->name) );
  769. if( nStatus )
  770. return( nStatus );
  771. /* find [optional] desc of other */
  772. itag = (int)getTag(pExt);
  773. if( itag == TG_OTHERDESC )
  774. {
  775. nStatus = processText( pExt, &((curother)->desc) );
  776. if( nStatus )
  777. return( nStatus );
  778. }
  779. return(nStatus);
  780. }
  781. /*
  782. * @doc INTERNAL READEXT
  783. *
  784. * @func char * | getSU | This function gets a list of SU blocks
  785. * from the file.
  786. *
  787. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  788. *
  789. * @parm aField * * | pField | Specifies the head of the list.
  790. *
  791. * @rdesc The return value is non zero if there was an error
  792. * while processing the file.
  793. */
  794. int getSU(EXTFile *pExt, aField **field)
  795. {
  796. int rtn;
  797. int ok, nStatus;
  798. // char * text;
  799. // char * tag;
  800. int itag;
  801. // int startType;
  802. DWORD dtag;
  803. aField *curfield;
  804. aField *tfield;
  805. aSU *curSU;
  806. int startType;
  807. if( field == NULL )
  808. return( ST_ERROR );
  809. curfield=fieldAlloc();
  810. if( curfield == NULL )
  811. return( ST_MEMORY );
  812. if(!*field)
  813. *field =curfield;
  814. else
  815. {
  816. tfield=*field;
  817. while(tfield->next)
  818. {
  819. tfield=tfield->next;
  820. }
  821. tfield->next=curfield;
  822. }
  823. /* find begin of SU block */
  824. dtag=getTag(pExt);
  825. // since struct and union prefixes are the same, we only need to
  826. // check for combo each ( ss, su, us, uu)
  827. if(HIWORD(dtag) == T2_UNIONUNIONNAME)
  828. curfield->wType=FIELD_UNION;
  829. else if(HIWORD(dtag) == T2_STRUCTSTRUCTNAME)
  830. curfield->wType=FIELD_STRUCT;
  831. else
  832. {
  833. fprintf(errfp, "Unrecognized block type in getSU().\n");
  834. fprintf(errfp,"Line %d. File %s\n",pExt->curlineno,pExt->EXTFilename);
  835. }
  836. curSU=SUAlloc();
  837. if(curSU == NULL)
  838. return (ST_MEMORY);
  839. curSU->level=curFieldLevel;
  840. curfield->ptr=(void *)curSU;
  841. nStatus = processText( pExt, &((curSU)->name) );
  842. if( nStatus)
  843. return( nStatus );
  844. /* find [optional] desc of SU */
  845. itag=(int)getTag(pExt);
  846. if( itag == TG_DESC )
  847. {
  848. nStatus = processText( pExt, &((curSU)->desc) );
  849. if( nStatus)
  850. return( nStatus );
  851. }
  852. /* process parms and other info */
  853. nStatus = 0;
  854. while( (nStatus == 0) )
  855. {
  856. itag=(int)getTag(pExt);
  857. if(itag==TG_ENDBLOCK)
  858. {
  859. // this is a nested thing, so eat ENDBLOCK
  860. getLine(pExt);
  861. break;
  862. }
  863. switch(itag)
  864. {
  865. case TG_FIELDTYPE:
  866. {
  867. nStatus = getSUType(pExt, &(curSU->field) );
  868. if( nStatus )
  869. return( nStatus );
  870. }
  871. break;
  872. case TG_NAME:
  873. {
  874. /* handles multiple parms */
  875. curFieldLevel++;
  876. nStatus = getSU(pExt, &(curSU->field) );
  877. curFieldLevel--;
  878. if( nStatus )
  879. return( nStatus );
  880. }
  881. break;
  882. default:
  883. fprintf(errfp,"Unrecognized Tag on line %d\n%s",
  884. pExt->curlineno,
  885. pExt->lineBuffer
  886. );
  887. nStatus = ST_BADOBJ;
  888. }
  889. }
  890. return( nStatus );
  891. }
  892. /*
  893. * @doc INTERNAL READEXT
  894. *
  895. * @func char * | getSUBlock | This function gets a list of SU blocks
  896. * from the file.
  897. *
  898. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  899. *
  900. * @parm aBlock * | pBlock | Specifies the head of the list.
  901. *
  902. * @rdesc The return value is non zero if there was an error
  903. * while processing the file.
  904. */
  905. int getSUBlock(EXTFile *pExt, aBlock *pBlock)
  906. {
  907. int ok, nStatus;
  908. int itag;
  909. DWORD dtag;
  910. int startType;
  911. int fendRtn;
  912. aBlock *pB2;
  913. /* find begin of function */
  914. dtag=getTag(pExt);
  915. startType=TYPE(dtag);
  916. if( HIWORD(dtag) == T2_STRUCTNAME )
  917. {
  918. pBlock->blockType=STRUCTBLOCK;
  919. }
  920. else if( HIWORD(dtag) == T2_UNIONNAME )
  921. {
  922. pBlock->blockType=UNIONBLOCK;
  923. }
  924. else
  925. {
  926. fprintf(errfp, "Unrecognized block type in getSUBlock().\n");
  927. fprintf(errfp,"Line %d. File %s\n",pExt->curlineno,pExt->EXTFilename);
  928. return( ST_BADOBJ );
  929. }
  930. /* find name of function */
  931. itag=(int)getTag(pExt);
  932. if( itag == TG_NAME )
  933. {
  934. nStatus = processText( pExt, &( pBlock->name) );
  935. if( nStatus )
  936. return( nStatus );
  937. if(verbose>1)
  938. fprintf(errfp, "%-30s",pBlock->name->text);
  939. }
  940. /* find description of function */
  941. itag=(int)getTag(pExt);
  942. if( itag == TG_DESC )
  943. {
  944. nStatus = processText( pExt, &( pBlock->desc) );
  945. if( nStatus )
  946. return( nStatus );
  947. }
  948. /* process parms and other info */
  949. nStatus = 0;
  950. while( (nStatus == 0) )
  951. {
  952. itag=(int)getTag(pExt);
  953. if(itag==TG_ENDBLOCK)
  954. break;
  955. switch(itag)
  956. {
  957. case TG_FIELDTYPE:
  958. {
  959. nStatus = getSUType(pExt, &(pBlock->field) );
  960. if( nStatus )
  961. return( nStatus );
  962. }
  963. break;
  964. case TG_NAME:
  965. {
  966. curFieldLevel++;
  967. /* handles multiple parms */
  968. nStatus = getSU(pExt, &(pBlock->field) );
  969. curFieldLevel--;
  970. if( nStatus )
  971. return( nStatus );
  972. }
  973. break;
  974. case TG_OTHERTYPE:
  975. {
  976. /* handles multiple parms */
  977. nStatus = getOther(pExt, &(pBlock->other) );
  978. if( nStatus )
  979. return( nStatus );
  980. }
  981. break;
  982. case TG_TAG:
  983. {
  984. nextText( pExt );
  985. nStatus = processText( pExt, &(pBlock->tagname) );
  986. if( nStatus )
  987. return( nStatus );
  988. }
  989. break;
  990. case TG_COMMENT:
  991. {
  992. nextText( pExt );
  993. nStatus = processText( pExt, &(pBlock->comment) );
  994. if( nStatus )
  995. return( nStatus );
  996. }
  997. break;
  998. case TG_XREF:
  999. {
  1000. nextText( pExt );
  1001. nStatus = processText( pExt, &(pBlock->xref) );
  1002. if( nStatus )
  1003. return( nStatus );
  1004. }
  1005. break;
  1006. default:
  1007. fprintf(errfp,"Unrecognized Tag on line %d\n%s",
  1008. pExt->curlineno,
  1009. pExt->lineBuffer
  1010. );
  1011. nStatus = ST_BADOBJ;
  1012. }
  1013. }
  1014. return( nStatus );
  1015. }
  1016. /*
  1017. * @doc INTERNAL READEXT
  1018. *
  1019. * @func char * | getFuncBlock | This function gets a list of function blocks
  1020. * from the file.
  1021. *
  1022. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  1023. *
  1024. * @parm aBlock * | pBlock | Specifies the head of the list.
  1025. *
  1026. * @rdesc The return value is non zero if there was an error
  1027. * while processing the file.
  1028. */
  1029. int getFuncBlock(EXTFile *pExt, aBlock *pBlock)
  1030. {
  1031. int ok, nStatus;
  1032. int itag;
  1033. DWORD dtag;
  1034. int startType;
  1035. int fendRtn;
  1036. aBlock *pB2;
  1037. /* find begin of function */
  1038. dtag=getTag(pExt);
  1039. startType=TYPE(dtag);
  1040. if( HIWORD(dtag) == T2_FUNCTYPE )
  1041. {
  1042. pBlock->blockType=FUNCTION;
  1043. }
  1044. else if( HIWORD(dtag) == T2_CBTYPE )
  1045. {
  1046. pBlock->blockType=CALLBACK;
  1047. }
  1048. else if( HIWORD(dtag) == T2_MSGNAME )
  1049. {
  1050. pBlock->blockType=MESSAGE;
  1051. }
  1052. #ifdef WARPAINT
  1053. else if( HIWORD(dtag) == T2_INTNAME )
  1054. {
  1055. pBlock->blockType=INTBLOCK;
  1056. }
  1057. #endif
  1058. else if( HIWORD(dtag) == T2_ASMNAME )
  1059. {
  1060. pBlock->blockType=MASMBLOCK;
  1061. }
  1062. else if( HIWORD(dtag) == T2_ASMCBNAME )
  1063. {
  1064. pBlock->blockType=MASMCBBLOCK;
  1065. }
  1066. else
  1067. {
  1068. fprintf(errfp, "Unrecognized block type in getFuncBlock().\n");
  1069. fprintf(errfp,"Line %d. File %s\n",pExt->curlineno,pExt->EXTFilename);
  1070. return( ST_BADOBJ );
  1071. }
  1072. /* find type of function */
  1073. itag=(int)getTag(pExt);
  1074. if( itag == TG_TYPE )
  1075. {
  1076. nStatus = processText( pExt, &( pBlock->type) );
  1077. if( nStatus )
  1078. return( nStatus );
  1079. }
  1080. /* find name of function */
  1081. itag=(int)getTag(pExt);
  1082. if( itag == TG_NAME )
  1083. {
  1084. nStatus = processText( pExt, &( pBlock->name) );
  1085. if( nStatus )
  1086. return( nStatus );
  1087. if(verbose>1)
  1088. fprintf(errfp, "%-30s",pBlock->name->text);
  1089. }
  1090. /* find description of function */
  1091. itag=(int)getTag(pExt);
  1092. if( itag == TG_DESC )
  1093. {
  1094. nStatus = processText( pExt, &( pBlock->desc) );
  1095. if( nStatus )
  1096. return( nStatus );
  1097. }
  1098. /* process parms and other info */
  1099. nStatus = 0;
  1100. while( (nStatus == 0) )
  1101. {
  1102. // itag=TYPE(getTag(pExt));
  1103. // if(itag != startType || itag == T2_TYPEBLOCK )
  1104. // break;
  1105. itag=(int)getTag(pExt);
  1106. if(itag==TG_ENDBLOCK)
  1107. break;
  1108. switch(itag)
  1109. {
  1110. case TG_REGNAME:
  1111. {
  1112. assert(!pBlock->rtndesc);
  1113. /* handles multiple regss */
  1114. nStatus = getReg(pExt, &(pBlock->reg) );
  1115. if( nStatus )
  1116. return( nStatus );
  1117. }
  1118. break;
  1119. case TG_PARMTYPE:
  1120. {
  1121. assert(!pBlock->rtndesc);
  1122. /* handles multiple parms */
  1123. nStatus = getParm(pExt, &(pBlock->parm) );
  1124. if( nStatus )
  1125. return( nStatus );
  1126. }
  1127. break;
  1128. case TG_RTNDESC:
  1129. {
  1130. /* does'nt handle multiple return desc */
  1131. // assert(!pBlock->rtndesc);
  1132. nextText( pExt );
  1133. nStatus = processText( pExt, &( pBlock->rtndesc) );
  1134. if( nStatus )
  1135. return( nStatus );
  1136. fendRtn=FALSE;
  1137. while(!fendRtn)
  1138. {
  1139. itag=(int)getTag(pExt);
  1140. switch(itag)
  1141. {
  1142. case TG_FLAGNAME:
  1143. /* handles multiple flags */
  1144. #if 0
  1145. if(pBlock->blockType==MASMBLOCK ||
  1146. pBlock->blockType == INTBLOCK
  1147. )
  1148. {
  1149. fprintf(errfp,"Warning: Return flags in return block. Not allowed in this block type.\n");
  1150. fprintf(errfp,"Line %d. File %s\n",pExt->curlineno,pExt->EXTFilename);
  1151. }
  1152. #endif
  1153. nStatus = getFlag( pExt, &(pBlock->rtnflag) );
  1154. if( nStatus )
  1155. return( nStatus );
  1156. break;
  1157. case TG_REGNAME:
  1158. /* handles multiple regss */
  1159. #if 0
  1160. if(pBlock->blockType==MASMBLOCK ||
  1161. pBlock->blockType == INTBLOCK
  1162. )
  1163. {
  1164. fprintf(errfp,"Warning: Register in return block. Not allowed in this block type.\n");
  1165. fprintf(errfp,"Line %d. File %s\n",pExt->curlineno,pExt->EXTFilename);
  1166. }
  1167. #endif
  1168. nStatus = getReg(pExt, &(pBlock->rtnreg) );
  1169. if( nStatus )
  1170. return( nStatus );
  1171. break;
  1172. default:
  1173. fendRtn=TRUE;
  1174. break;
  1175. } // switch
  1176. } // while
  1177. } // Return
  1178. break;
  1179. case TG_COMMENT:
  1180. {
  1181. nextText( pExt );
  1182. nStatus = processText( pExt, &(pBlock->comment) );
  1183. if( nStatus )
  1184. return( nStatus );
  1185. }
  1186. break;
  1187. case TG_COND:
  1188. {
  1189. nStatus = getCond( pExt, &(pBlock->cond) );
  1190. if( nStatus )
  1191. return( nStatus );
  1192. }
  1193. break;
  1194. case TG_USES:
  1195. {
  1196. nextText( pExt );
  1197. nStatus = processText( pExt, &(pBlock->uses) );
  1198. if( nStatus )
  1199. return( nStatus );
  1200. }
  1201. break;
  1202. case TG_XREF:
  1203. {
  1204. nextText( pExt );
  1205. nStatus = processText( pExt, &(pBlock->xref) );
  1206. if( nStatus )
  1207. return( nStatus );
  1208. }
  1209. break;
  1210. case TG_NAME:
  1211. case TG_TYPE:
  1212. {
  1213. /* check to make sure CB and not FUNC or MSG */
  1214. pB2=newBlock();
  1215. pB2->blockType=CALLBACK;
  1216. if(verbose>1) fprintf(errfp,"\nCallback: ");
  1217. nStatus = getFuncBlock( pExt , pB2);
  1218. if(!pBlock->cb) /* head */
  1219. pBlock->cb=pB2;
  1220. else
  1221. { /* insert at head */
  1222. pB2->next=pBlock->cb;
  1223. pBlock->cb=pB2;
  1224. }
  1225. if(nStatus )
  1226. return(nStatus);
  1227. /* eat end line */
  1228. getLine(pExt);
  1229. }
  1230. break;
  1231. default:
  1232. fprintf(errfp,"Unrecognized Tag on line %d\n%s",
  1233. pExt->curlineno,
  1234. pExt->lineBuffer
  1235. );
  1236. nStatus = ST_BADOBJ;
  1237. }
  1238. }
  1239. return( nStatus );
  1240. }
  1241. /*
  1242. * @doc INTERNAL READEXT
  1243. *
  1244. * @func aBlock * | newBlock | This function allocates a new Block
  1245. *
  1246. */
  1247. aBlock *
  1248. newBlock()
  1249. {
  1250. aBlock *pBlock;
  1251. pBlock=(aBlock *)clear_alloc(sizeof (aBlock));
  1252. return(pBlock);
  1253. }
  1254. #if 0
  1255. /*
  1256. * @doc INTERNAL READEXT
  1257. *
  1258. * @func aBlock * | newBlock | This function allocates a new Block
  1259. *
  1260. */
  1261. void
  1262. freeBlock(aBlock * pBlock)
  1263. {
  1264. assert(pBlock);
  1265. if(pBlock->srcfile)
  1266. my_free(pBlock->srcfile);
  1267. if(pBlock->doclevel)
  1268. lineDestroy(pBlock->doclevel);
  1269. if(pBlock->name)
  1270. lineDestroy(pBlock->name);
  1271. if(pBlock->type)
  1272. lineDestroy(pBlock->type);
  1273. if(pBlock->desc)
  1274. lineDestroy(pBlock->desc);
  1275. if(pBlock->parm)
  1276. parmDestroy(pBlock->parm);
  1277. if(pBlock->reg)
  1278. regDestroy(pBlock->reg);
  1279. if(pBlock->rtndesc)
  1280. lineDestroy(pBlock->rtndesc);
  1281. if(pBlock->rtnflag)
  1282. flagDestroy(pBlock->rtnflag);
  1283. if(pBlock->rtnreg)
  1284. regDestroy(pBlock->rtnreg);
  1285. if(pBlock->cond)
  1286. condDestroy(pBlock->cond);
  1287. if(pBlock->comment)
  1288. lineDestroy(pBlock->comment);
  1289. if(pBlock->cb)
  1290. freeBlock(pBlock->cb);
  1291. if(pBlock->xref)
  1292. lineDestroy(pBlock->xref);
  1293. if(pBlock->uses)
  1294. lineDestroy(pBlock->uses);
  1295. return;
  1296. }
  1297. #endif
  1298. /*
  1299. * @doc INTERNAL READEXT
  1300. *
  1301. * @func aBlock * | getBlock | This function gets a block of documentation
  1302. * from the file.
  1303. *
  1304. * @parm EXTFile * | pExt | Specifies the Extracted file to process.
  1305. *
  1306. * @rdesc The return value is the block from the file or NULL if an error
  1307. * occured while processing the file.
  1308. */
  1309. aBlock * getBlock(EXTFile * pExt)
  1310. {
  1311. int ok, nStatus;
  1312. int itag;
  1313. aBlock *pcurBlock;
  1314. /* find begin of block */
  1315. ok = TRUE;
  1316. while( ok && ((int)getTag(pExt) != TG_BEGINBLOCK ))
  1317. ok = getLine(pExt);
  1318. if( !ok )
  1319. return( NULL );
  1320. pcurBlock=newBlock();
  1321. /* get to next tag. */
  1322. ok = getLine(pExt );
  1323. while( ok && ( !getTag(pExt) ) )
  1324. ok = getLine( pExt );
  1325. if( !ok )
  1326. return( NULL );
  1327. itag=(int)getTag(pExt);
  1328. if(itag == TG_DOCLEVEL) /* set doclevel */
  1329. {
  1330. getDocLevel(pcurBlock, pExt);
  1331. itag=(int)getTag(pExt);
  1332. }
  1333. if(itag == TG_SRCLINE) /* set source file, line */
  1334. {
  1335. getSrcLine(pcurBlock, pExt);
  1336. itag=(int)getTag(pExt);
  1337. }
  1338. itag=HIWORD(getTag(pExt));
  1339. switch(itag)
  1340. {
  1341. case T2_STRUCTNAME:
  1342. case T2_UNIONNAME:
  1343. {
  1344. nStatus = getSUBlock(pExt, pcurBlock );
  1345. }
  1346. break;
  1347. case T2_FUNCTYPE:
  1348. case T2_FUNCNAME:
  1349. {
  1350. pcurBlock->blockType = FUNCTION;
  1351. nStatus = getFuncBlock(pExt, pcurBlock );
  1352. }
  1353. break;
  1354. case T2_MSGTYPE:
  1355. case T2_MSGNAME:
  1356. {
  1357. pcurBlock->blockType = MESSAGE;
  1358. nStatus = getFuncBlock(pExt, pcurBlock );
  1359. }
  1360. break;
  1361. #ifdef WARPAINT
  1362. case T2_INTTYPE:
  1363. case T2_INTNAME:
  1364. {
  1365. pcurBlock->blockType = INTBLOCK;
  1366. nStatus = getFuncBlock(pExt, pcurBlock );
  1367. }
  1368. break;
  1369. #endif
  1370. case T2_ASMTYPE:
  1371. case T2_ASMNAME:
  1372. {
  1373. pcurBlock->blockType = MASMBLOCK;
  1374. nStatus = getFuncBlock(pExt, pcurBlock );
  1375. }
  1376. break;
  1377. case T2_ASMCBTYPE:
  1378. case T2_ASMCBNAME:
  1379. {
  1380. pcurBlock->blockType = MASMCBBLOCK;
  1381. nStatus = getFuncBlock(pExt, pcurBlock );
  1382. }
  1383. break;
  1384. default:
  1385. {
  1386. fprintf(errfp,"Unrecognized Block Tag at line %d of %s\n",
  1387. pExt->curlineno,
  1388. pExt->EXTFilename);
  1389. pcurBlock->blockType = 0;
  1390. nStatus = ST_BADOBJ;
  1391. }
  1392. break;
  1393. }
  1394. /* eat text until end block */
  1395. ok = TRUE;
  1396. while( ok && ((int)getTag(pExt) != TG_ENDBLOCK ))
  1397. {
  1398. fprintf(errfp,"Warning: unexpected tags before end of block at line %d of %s\n",
  1399. pExt->curlineno,
  1400. pExt->EXTFilename);
  1401. ok = getLine(pExt);
  1402. }
  1403. /* read past end block */
  1404. ok = getLine(pExt);
  1405. if( nStatus == 0 )
  1406. {
  1407. ok = TRUE;
  1408. }
  1409. else if( nStatus == ST_BADOBJ )
  1410. {
  1411. error(WARN2, pExt->EXTFilename, pExt->curlineno );
  1412. nStatus = 0;
  1413. ok = TRUE;
  1414. }
  1415. else
  1416. return( NULL );
  1417. return(pcurBlock);
  1418. }
  1419. /*
  1420. * @doc INTERNAL READEXT
  1421. *
  1422. * @func void | getDocLevel | This function parses the DOCLEVEL extract tag
  1423. * and fills in the information in the block.
  1424. *
  1425. * @parm aBlock * | pBlock | Specifies the block.
  1426. *
  1427. * @parm EXTFile *| pExt | Specifies the Extracted file.
  1428. *
  1429. */
  1430. void getDocLevel(aBlock *pBlock, EXTFile *pExt)
  1431. {
  1432. aLine *pLine;
  1433. char *pch;
  1434. char *spch;
  1435. assert(pBlock);
  1436. assert(pExt);
  1437. pch=pExt->lineBuffer + pExt->curlinepos;
  1438. while(*pch)
  1439. {
  1440. while(isspace(*pch))
  1441. ++pch;
  1442. spch=pch;
  1443. while(*pch && !isspace(*pch))
  1444. ++pch;
  1445. if(*pch)
  1446. {
  1447. *pch='\0';
  1448. pLine=lineMake(spch);
  1449. if(pBlock->doclevel)
  1450. pLine->next=pBlock->doclevel;
  1451. pBlock->doclevel=pLine;
  1452. ++pch;
  1453. }
  1454. }
  1455. getLine(pExt);
  1456. }
  1457. /*
  1458. * @doc INTERNAL READEXT
  1459. *
  1460. * @func void | getSrcLine | This function parses the SRCLINE extract tag
  1461. * and fills in the information in the block.
  1462. *
  1463. * @parm aBlock * | pBlock | Specifies the block.
  1464. *
  1465. * @parm EXTFile *| pExt | Specifies the Extracted file.
  1466. *
  1467. */
  1468. void getSrcLine(aBlock *pBlock, EXTFile *pExt)
  1469. {
  1470. char *pch;
  1471. char *spch;
  1472. assert(pBlock);
  1473. assert(pExt);
  1474. pch=pExt->lineBuffer + pExt->curlinepos;
  1475. while(isspace(*pch))
  1476. ++pch;
  1477. spch=pch;
  1478. while(!isspace(*pch))
  1479. ++pch;
  1480. *pch='\0';
  1481. pBlock->srcfile=cp_alloc(spch);
  1482. ++pch;
  1483. while(isspace(*pch))
  1484. ++pch;
  1485. pBlock->srcline=atoi(pch);
  1486. getLine(pExt);
  1487. }