clipsruby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clipsruby/agenda.c +1373 -0
  3. data/ext/clipsruby/agenda.h +169 -0
  4. data/ext/clipsruby/analysis.c +1142 -0
  5. data/ext/clipsruby/analysis.h +61 -0
  6. data/ext/clipsruby/argacces.c +526 -0
  7. data/ext/clipsruby/argacces.h +77 -0
  8. data/ext/clipsruby/bload.c +884 -0
  9. data/ext/clipsruby/bload.h +94 -0
  10. data/ext/clipsruby/bmathfun.c +557 -0
  11. data/ext/clipsruby/bmathfun.h +66 -0
  12. data/ext/clipsruby/bsave.c +634 -0
  13. data/ext/clipsruby/bsave.h +130 -0
  14. data/ext/clipsruby/classcom.c +976 -0
  15. data/ext/clipsruby/classcom.h +115 -0
  16. data/ext/clipsruby/classexm.c +1376 -0
  17. data/ext/clipsruby/classexm.h +97 -0
  18. data/ext/clipsruby/classfun.c +1392 -0
  19. data/ext/clipsruby/classfun.h +164 -0
  20. data/ext/clipsruby/classinf.c +1245 -0
  21. data/ext/clipsruby/classinf.h +94 -0
  22. data/ext/clipsruby/classini.c +843 -0
  23. data/ext/clipsruby/classini.h +75 -0
  24. data/ext/clipsruby/classpsr.c +957 -0
  25. data/ext/clipsruby/classpsr.h +73 -0
  26. data/ext/clipsruby/clips.h +133 -0
  27. data/ext/clipsruby/clipsruby.c +619 -0
  28. data/ext/clipsruby/clsltpsr.c +931 -0
  29. data/ext/clipsruby/clsltpsr.h +72 -0
  30. data/ext/clipsruby/commline.c +1217 -0
  31. data/ext/clipsruby/commline.h +131 -0
  32. data/ext/clipsruby/conscomp.c +1593 -0
  33. data/ext/clipsruby/conscomp.h +150 -0
  34. data/ext/clipsruby/constant.h +264 -0
  35. data/ext/clipsruby/constrct.c +1090 -0
  36. data/ext/clipsruby/constrct.h +216 -0
  37. data/ext/clipsruby/constrnt.c +554 -0
  38. data/ext/clipsruby/constrnt.h +132 -0
  39. data/ext/clipsruby/crstrtgy.c +1088 -0
  40. data/ext/clipsruby/crstrtgy.h +85 -0
  41. data/ext/clipsruby/cstrcbin.c +185 -0
  42. data/ext/clipsruby/cstrcbin.h +61 -0
  43. data/ext/clipsruby/cstrccmp.h +43 -0
  44. data/ext/clipsruby/cstrccom.c +1791 -0
  45. data/ext/clipsruby/cstrccom.h +115 -0
  46. data/ext/clipsruby/cstrcpsr.c +835 -0
  47. data/ext/clipsruby/cstrcpsr.h +97 -0
  48. data/ext/clipsruby/cstrnbin.c +282 -0
  49. data/ext/clipsruby/cstrnbin.h +55 -0
  50. data/ext/clipsruby/cstrnchk.c +826 -0
  51. data/ext/clipsruby/cstrnchk.h +91 -0
  52. data/ext/clipsruby/cstrncmp.c +238 -0
  53. data/ext/clipsruby/cstrncmp.h +57 -0
  54. data/ext/clipsruby/cstrnops.c +1176 -0
  55. data/ext/clipsruby/cstrnops.h +47 -0
  56. data/ext/clipsruby/cstrnpsr.c +1394 -0
  57. data/ext/clipsruby/cstrnpsr.h +88 -0
  58. data/ext/clipsruby/cstrnutl.c +564 -0
  59. data/ext/clipsruby/cstrnutl.h +54 -0
  60. data/ext/clipsruby/default.c +454 -0
  61. data/ext/clipsruby/default.h +57 -0
  62. data/ext/clipsruby/defins.c +971 -0
  63. data/ext/clipsruby/defins.h +127 -0
  64. data/ext/clipsruby/developr.c +677 -0
  65. data/ext/clipsruby/developr.h +69 -0
  66. data/ext/clipsruby/dffctbin.c +477 -0
  67. data/ext/clipsruby/dffctbin.h +76 -0
  68. data/ext/clipsruby/dffctbsc.c +308 -0
  69. data/ext/clipsruby/dffctbsc.h +72 -0
  70. data/ext/clipsruby/dffctcmp.c +297 -0
  71. data/ext/clipsruby/dffctcmp.h +44 -0
  72. data/ext/clipsruby/dffctdef.c +364 -0
  73. data/ext/clipsruby/dffctdef.h +104 -0
  74. data/ext/clipsruby/dffctpsr.c +179 -0
  75. data/ext/clipsruby/dffctpsr.h +49 -0
  76. data/ext/clipsruby/dffnxbin.c +520 -0
  77. data/ext/clipsruby/dffnxbin.h +67 -0
  78. data/ext/clipsruby/dffnxcmp.c +378 -0
  79. data/ext/clipsruby/dffnxcmp.h +54 -0
  80. data/ext/clipsruby/dffnxexe.c +241 -0
  81. data/ext/clipsruby/dffnxexe.h +58 -0
  82. data/ext/clipsruby/dffnxfun.c +1192 -0
  83. data/ext/clipsruby/dffnxfun.h +155 -0
  84. data/ext/clipsruby/dffnxpsr.c +514 -0
  85. data/ext/clipsruby/dffnxpsr.h +57 -0
  86. data/ext/clipsruby/dfinsbin.c +509 -0
  87. data/ext/clipsruby/dfinsbin.h +66 -0
  88. data/ext/clipsruby/dfinscmp.c +345 -0
  89. data/ext/clipsruby/dfinscmp.h +48 -0
  90. data/ext/clipsruby/drive.c +1191 -0
  91. data/ext/clipsruby/drive.h +65 -0
  92. data/ext/clipsruby/emathfun.c +1213 -0
  93. data/ext/clipsruby/emathfun.h +99 -0
  94. data/ext/clipsruby/engine.c +1568 -0
  95. data/ext/clipsruby/engine.h +203 -0
  96. data/ext/clipsruby/entities.h +276 -0
  97. data/ext/clipsruby/envrnbld.c +514 -0
  98. data/ext/clipsruby/envrnbld.h +40 -0
  99. data/ext/clipsruby/envrnmnt.c +257 -0
  100. data/ext/clipsruby/envrnmnt.h +112 -0
  101. data/ext/clipsruby/evaluatn.c +1736 -0
  102. data/ext/clipsruby/evaluatn.h +211 -0
  103. data/ext/clipsruby/expressn.c +494 -0
  104. data/ext/clipsruby/expressn.h +154 -0
  105. data/ext/clipsruby/exprnbin.c +538 -0
  106. data/ext/clipsruby/exprnbin.h +60 -0
  107. data/ext/clipsruby/exprnops.c +564 -0
  108. data/ext/clipsruby/exprnops.h +67 -0
  109. data/ext/clipsruby/exprnpsr.c +1112 -0
  110. data/ext/clipsruby/exprnpsr.h +98 -0
  111. data/ext/clipsruby/extconf.rb +2 -0
  112. data/ext/clipsruby/extnfunc.c +1015 -0
  113. data/ext/clipsruby/extnfunc.h +157 -0
  114. data/ext/clipsruby/factbin.c +447 -0
  115. data/ext/clipsruby/factbin.h +56 -0
  116. data/ext/clipsruby/factbld.c +1035 -0
  117. data/ext/clipsruby/factbld.h +63 -0
  118. data/ext/clipsruby/factcmp.c +386 -0
  119. data/ext/clipsruby/factcmp.h +46 -0
  120. data/ext/clipsruby/factcom.c +759 -0
  121. data/ext/clipsruby/factcom.h +80 -0
  122. data/ext/clipsruby/factfile.c +1761 -0
  123. data/ext/clipsruby/factfile.h +54 -0
  124. data/ext/clipsruby/factfun.c +682 -0
  125. data/ext/clipsruby/factfun.h +77 -0
  126. data/ext/clipsruby/factgen.c +1305 -0
  127. data/ext/clipsruby/factgen.h +229 -0
  128. data/ext/clipsruby/facthsh.c +438 -0
  129. data/ext/clipsruby/facthsh.h +81 -0
  130. data/ext/clipsruby/factlhs.c +250 -0
  131. data/ext/clipsruby/factlhs.h +54 -0
  132. data/ext/clipsruby/factmch.c +905 -0
  133. data/ext/clipsruby/factmch.h +68 -0
  134. data/ext/clipsruby/factmngr.c +3373 -0
  135. data/ext/clipsruby/factmngr.h +325 -0
  136. data/ext/clipsruby/factprt.c +498 -0
  137. data/ext/clipsruby/factprt.h +60 -0
  138. data/ext/clipsruby/factqpsr.c +796 -0
  139. data/ext/clipsruby/factqpsr.h +61 -0
  140. data/ext/clipsruby/factqury.c +1267 -0
  141. data/ext/clipsruby/factqury.h +112 -0
  142. data/ext/clipsruby/factrete.c +978 -0
  143. data/ext/clipsruby/factrete.h +70 -0
  144. data/ext/clipsruby/factrhs.c +667 -0
  145. data/ext/clipsruby/factrhs.h +55 -0
  146. data/ext/clipsruby/filecom.c +353 -0
  147. data/ext/clipsruby/filecom.h +137 -0
  148. data/ext/clipsruby/filertr.c +481 -0
  149. data/ext/clipsruby/filertr.h +94 -0
  150. data/ext/clipsruby/fileutil.c +1020 -0
  151. data/ext/clipsruby/fileutil.h +50 -0
  152. data/ext/clipsruby/generate.c +1079 -0
  153. data/ext/clipsruby/generate.h +57 -0
  154. data/ext/clipsruby/genrcbin.c +902 -0
  155. data/ext/clipsruby/genrcbin.h +69 -0
  156. data/ext/clipsruby/genrccmp.c +640 -0
  157. data/ext/clipsruby/genrccmp.h +59 -0
  158. data/ext/clipsruby/genrccom.c +2017 -0
  159. data/ext/clipsruby/genrccom.h +119 -0
  160. data/ext/clipsruby/genrcexe.c +737 -0
  161. data/ext/clipsruby/genrcexe.h +73 -0
  162. data/ext/clipsruby/genrcfun.c +890 -0
  163. data/ext/clipsruby/genrcfun.h +185 -0
  164. data/ext/clipsruby/genrcpsr.c +1618 -0
  165. data/ext/clipsruby/genrcpsr.h +80 -0
  166. data/ext/clipsruby/globlbin.c +458 -0
  167. data/ext/clipsruby/globlbin.h +71 -0
  168. data/ext/clipsruby/globlbsc.c +361 -0
  169. data/ext/clipsruby/globlbsc.h +83 -0
  170. data/ext/clipsruby/globlcmp.c +330 -0
  171. data/ext/clipsruby/globlcmp.h +52 -0
  172. data/ext/clipsruby/globlcom.c +289 -0
  173. data/ext/clipsruby/globlcom.h +63 -0
  174. data/ext/clipsruby/globldef.c +1087 -0
  175. data/ext/clipsruby/globldef.h +151 -0
  176. data/ext/clipsruby/globlpsr.c +530 -0
  177. data/ext/clipsruby/globlpsr.h +59 -0
  178. data/ext/clipsruby/immthpsr.c +431 -0
  179. data/ext/clipsruby/immthpsr.h +55 -0
  180. data/ext/clipsruby/incrrset.c +530 -0
  181. data/ext/clipsruby/incrrset.h +73 -0
  182. data/ext/clipsruby/inherpsr.c +850 -0
  183. data/ext/clipsruby/inherpsr.h +52 -0
  184. data/ext/clipsruby/inscom.c +2076 -0
  185. data/ext/clipsruby/inscom.h +182 -0
  186. data/ext/clipsruby/insfile.c +1764 -0
  187. data/ext/clipsruby/insfile.h +96 -0
  188. data/ext/clipsruby/insfun.c +1451 -0
  189. data/ext/clipsruby/insfun.h +134 -0
  190. data/ext/clipsruby/insmngr.c +2550 -0
  191. data/ext/clipsruby/insmngr.h +125 -0
  192. data/ext/clipsruby/insmoddp.c +1041 -0
  193. data/ext/clipsruby/insmoddp.h +91 -0
  194. data/ext/clipsruby/insmult.c +804 -0
  195. data/ext/clipsruby/insmult.h +62 -0
  196. data/ext/clipsruby/inspsr.c +602 -0
  197. data/ext/clipsruby/inspsr.h +60 -0
  198. data/ext/clipsruby/insquery.c +1278 -0
  199. data/ext/clipsruby/insquery.h +115 -0
  200. data/ext/clipsruby/insqypsr.c +729 -0
  201. data/ext/clipsruby/insqypsr.h +63 -0
  202. data/ext/clipsruby/iofun.c +2045 -0
  203. data/ext/clipsruby/iofun.h +116 -0
  204. data/ext/clipsruby/lgcldpnd.c +644 -0
  205. data/ext/clipsruby/lgcldpnd.h +75 -0
  206. data/ext/clipsruby/main.c +112 -0
  207. data/ext/clipsruby/match.h +142 -0
  208. data/ext/clipsruby/memalloc.c +481 -0
  209. data/ext/clipsruby/memalloc.h +197 -0
  210. data/ext/clipsruby/miscfun.c +1801 -0
  211. data/ext/clipsruby/miscfun.h +132 -0
  212. data/ext/clipsruby/modulbin.c +607 -0
  213. data/ext/clipsruby/modulbin.h +84 -0
  214. data/ext/clipsruby/modulbsc.c +347 -0
  215. data/ext/clipsruby/modulbsc.h +67 -0
  216. data/ext/clipsruby/modulcmp.c +499 -0
  217. data/ext/clipsruby/modulcmp.h +54 -0
  218. data/ext/clipsruby/moduldef.c +817 -0
  219. data/ext/clipsruby/moduldef.h +271 -0
  220. data/ext/clipsruby/modulpsr.c +1150 -0
  221. data/ext/clipsruby/modulpsr.h +69 -0
  222. data/ext/clipsruby/modulutl.c +1036 -0
  223. data/ext/clipsruby/modulutl.h +84 -0
  224. data/ext/clipsruby/msgcom.c +1221 -0
  225. data/ext/clipsruby/msgcom.h +125 -0
  226. data/ext/clipsruby/msgfun.c +1076 -0
  227. data/ext/clipsruby/msgfun.h +118 -0
  228. data/ext/clipsruby/msgpass.c +1441 -0
  229. data/ext/clipsruby/msgpass.h +103 -0
  230. data/ext/clipsruby/msgpsr.c +698 -0
  231. data/ext/clipsruby/msgpsr.h +73 -0
  232. data/ext/clipsruby/multifld.c +1404 -0
  233. data/ext/clipsruby/multifld.h +130 -0
  234. data/ext/clipsruby/multifun.c +2182 -0
  235. data/ext/clipsruby/multifun.h +102 -0
  236. data/ext/clipsruby/network.h +142 -0
  237. data/ext/clipsruby/objbin.c +1522 -0
  238. data/ext/clipsruby/objbin.h +79 -0
  239. data/ext/clipsruby/objcmp.c +1507 -0
  240. data/ext/clipsruby/objcmp.h +71 -0
  241. data/ext/clipsruby/object.h +260 -0
  242. data/ext/clipsruby/objrtbin.c +701 -0
  243. data/ext/clipsruby/objrtbin.h +79 -0
  244. data/ext/clipsruby/objrtbld.c +2393 -0
  245. data/ext/clipsruby/objrtbld.h +66 -0
  246. data/ext/clipsruby/objrtcmp.c +734 -0
  247. data/ext/clipsruby/objrtcmp.h +66 -0
  248. data/ext/clipsruby/objrtfnx.c +1330 -0
  249. data/ext/clipsruby/objrtfnx.h +222 -0
  250. data/ext/clipsruby/objrtgen.c +736 -0
  251. data/ext/clipsruby/objrtgen.h +63 -0
  252. data/ext/clipsruby/objrtmch.c +1524 -0
  253. data/ext/clipsruby/objrtmch.h +160 -0
  254. data/ext/clipsruby/parsefun.c +415 -0
  255. data/ext/clipsruby/parsefun.h +67 -0
  256. data/ext/clipsruby/pattern.c +1265 -0
  257. data/ext/clipsruby/pattern.h +163 -0
  258. data/ext/clipsruby/pprint.c +328 -0
  259. data/ext/clipsruby/pprint.h +79 -0
  260. data/ext/clipsruby/prccode.c +1478 -0
  261. data/ext/clipsruby/prccode.h +145 -0
  262. data/ext/clipsruby/prcdrfun.c +640 -0
  263. data/ext/clipsruby/prcdrfun.h +95 -0
  264. data/ext/clipsruby/prcdrpsr.c +1068 -0
  265. data/ext/clipsruby/prcdrpsr.h +79 -0
  266. data/ext/clipsruby/prdctfun.c +869 -0
  267. data/ext/clipsruby/prdctfun.h +77 -0
  268. data/ext/clipsruby/prntutil.c +878 -0
  269. data/ext/clipsruby/prntutil.h +125 -0
  270. data/ext/clipsruby/proflfun.c +827 -0
  271. data/ext/clipsruby/proflfun.h +118 -0
  272. data/ext/clipsruby/reorder.c +2082 -0
  273. data/ext/clipsruby/reorder.h +172 -0
  274. data/ext/clipsruby/reteutil.c +1732 -0
  275. data/ext/clipsruby/reteutil.h +111 -0
  276. data/ext/clipsruby/retract.c +710 -0
  277. data/ext/clipsruby/retract.h +74 -0
  278. data/ext/clipsruby/router.c +737 -0
  279. data/ext/clipsruby/router.h +147 -0
  280. data/ext/clipsruby/rulebin.c +1136 -0
  281. data/ext/clipsruby/rulebin.h +153 -0
  282. data/ext/clipsruby/rulebld.c +1328 -0
  283. data/ext/clipsruby/rulebld.h +62 -0
  284. data/ext/clipsruby/rulebsc.c +517 -0
  285. data/ext/clipsruby/rulebsc.h +91 -0
  286. data/ext/clipsruby/rulecmp.c +733 -0
  287. data/ext/clipsruby/rulecmp.h +63 -0
  288. data/ext/clipsruby/rulecom.c +1583 -0
  289. data/ext/clipsruby/rulecom.h +116 -0
  290. data/ext/clipsruby/rulecstr.c +892 -0
  291. data/ext/clipsruby/rulecstr.h +53 -0
  292. data/ext/clipsruby/ruledef.c +559 -0
  293. data/ext/clipsruby/ruledef.h +179 -0
  294. data/ext/clipsruby/ruledlt.c +599 -0
  295. data/ext/clipsruby/ruledlt.h +58 -0
  296. data/ext/clipsruby/rulelhs.c +1216 -0
  297. data/ext/clipsruby/rulelhs.h +52 -0
  298. data/ext/clipsruby/rulepsr.c +1073 -0
  299. data/ext/clipsruby/rulepsr.h +61 -0
  300. data/ext/clipsruby/scanner.c +856 -0
  301. data/ext/clipsruby/scanner.h +112 -0
  302. data/ext/clipsruby/setup.h +488 -0
  303. data/ext/clipsruby/sortfun.c +433 -0
  304. data/ext/clipsruby/sortfun.h +55 -0
  305. data/ext/clipsruby/strngfun.c +1173 -0
  306. data/ext/clipsruby/strngfun.h +96 -0
  307. data/ext/clipsruby/strngrtr.c +523 -0
  308. data/ext/clipsruby/strngrtr.h +97 -0
  309. data/ext/clipsruby/symblbin.c +648 -0
  310. data/ext/clipsruby/symblbin.h +64 -0
  311. data/ext/clipsruby/symblcmp.c +893 -0
  312. data/ext/clipsruby/symblcmp.h +61 -0
  313. data/ext/clipsruby/symbol.c +1961 -0
  314. data/ext/clipsruby/symbol.h +243 -0
  315. data/ext/clipsruby/sysdep.c +894 -0
  316. data/ext/clipsruby/sysdep.h +164 -0
  317. data/ext/clipsruby/textpro.c +1388 -0
  318. data/ext/clipsruby/textpro.h +77 -0
  319. data/ext/clipsruby/tmpltbin.c +609 -0
  320. data/ext/clipsruby/tmpltbin.h +108 -0
  321. data/ext/clipsruby/tmpltbsc.c +327 -0
  322. data/ext/clipsruby/tmpltbsc.h +87 -0
  323. data/ext/clipsruby/tmpltcmp.c +450 -0
  324. data/ext/clipsruby/tmpltcmp.h +57 -0
  325. data/ext/clipsruby/tmpltdef.c +584 -0
  326. data/ext/clipsruby/tmpltdef.h +155 -0
  327. data/ext/clipsruby/tmpltfun.c +2477 -0
  328. data/ext/clipsruby/tmpltfun.h +122 -0
  329. data/ext/clipsruby/tmpltlhs.c +379 -0
  330. data/ext/clipsruby/tmpltlhs.h +50 -0
  331. data/ext/clipsruby/tmpltpsr.c +819 -0
  332. data/ext/clipsruby/tmpltpsr.h +59 -0
  333. data/ext/clipsruby/tmpltrhs.c +595 -0
  334. data/ext/clipsruby/tmpltrhs.h +55 -0
  335. data/ext/clipsruby/tmpltutl.c +637 -0
  336. data/ext/clipsruby/tmpltutl.h +82 -0
  337. data/ext/clipsruby/userdata.c +156 -0
  338. data/ext/clipsruby/userdata.h +72 -0
  339. data/ext/clipsruby/userfunctions.c +70 -0
  340. data/ext/clipsruby/usrsetup.h +7 -0
  341. data/ext/clipsruby/utility.c +1594 -0
  342. data/ext/clipsruby/utility.h +250 -0
  343. data/ext/clipsruby/watch.c +865 -0
  344. data/ext/clipsruby/watch.h +124 -0
  345. data/lib/clipsruby.rb +1 -0
  346. metadata +388 -0
@@ -0,0 +1,817 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 10/01/16 */
5
+ /* */
6
+ /* DEFMODULE MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Defines basic defmodule primitive functions such */
11
+ /* as allocating and deallocating, traversing, and finding */
12
+ /* defmodule data structures. */
13
+ /* */
14
+ /* Principal Programmer(s): */
15
+ /* Gary D. Riley */
16
+ /* */
17
+ /* Contributing Programmer(s): */
18
+ /* Brian L. Dantes */
19
+ /* */
20
+ /* Revision History: */
21
+ /* */
22
+ /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
23
+ /* */
24
+ /* Corrected compilation errors for files */
25
+ /* generated by constructs-to-c. DR0861 */
26
+ /* */
27
+ /* 6.24: Renamed BOOLEAN macro type to intBool. */
28
+ /* */
29
+ /* 6.30: Changed integer type/precision. */
30
+ /* */
31
+ /* Removed conditional code for unsupported */
32
+ /* compilers/operating systems (IBM_MCW, */
33
+ /* MAC_MCW, and IBM_TBC). */
34
+ /* */
35
+ /* Added const qualifiers to remove C++ */
36
+ /* deprecation warnings. */
37
+ /* */
38
+ /* Converted API macros to function calls. */
39
+ /* */
40
+ /* 6.40: Pragma once and other inclusion changes. */
41
+ /* */
42
+ /* Added support for booleans with <stdbool.h>. */
43
+ /* */
44
+ /* Removed use of void pointers for specific */
45
+ /* data structures. */
46
+ /* */
47
+ /* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
48
+ /* */
49
+ /* Callbacks must be environment aware. */
50
+ /* */
51
+ /* UDF redesign. */
52
+ /* */
53
+ /*************************************************************/
54
+
55
+ #include "setup.h"
56
+
57
+ #include <stdio.h>
58
+ #include <string.h>
59
+
60
+ #include "argacces.h"
61
+ #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE
62
+ #include "bload.h"
63
+ #include "modulbin.h"
64
+ #endif
65
+ #include "constant.h"
66
+ #include "constrct.h"
67
+ #include "envrnmnt.h"
68
+ #include "extnfunc.h"
69
+ #include "memalloc.h"
70
+ #include "modulbsc.h"
71
+ #include "modulcmp.h"
72
+ #include "modulpsr.h"
73
+ #include "prntutil.h"
74
+ #include "router.h"
75
+ #include "utility.h"
76
+
77
+ #include "moduldef.h"
78
+
79
+ /***************************************/
80
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
81
+ /***************************************/
82
+
83
+ #if (! RUN_TIME)
84
+ static void ReturnDefmodule(Environment *,Defmodule *,bool);
85
+ #endif
86
+ static void DeallocateDefmoduleData(Environment *);
87
+
88
+ /************************************************/
89
+ /* AllocateDefmoduleGlobals: Initializes global */
90
+ /* variables used by the defmodule construct. */
91
+ /************************************************/
92
+ void AllocateDefmoduleGlobals(
93
+ Environment *theEnv)
94
+ {
95
+ AllocateEnvironmentData(theEnv,DEFMODULE_DATA,sizeof(struct defmoduleData),NULL);
96
+ AddEnvironmentCleanupFunction(theEnv,"defmodules",DeallocateDefmoduleData,-1000);
97
+ DefmoduleData(theEnv)->CallModuleChangeFunctions = true;
98
+ DefmoduleData(theEnv)->MainModuleRedefinable = true;
99
+ }
100
+
101
+ /****************************************************/
102
+ /* DeallocateDefmoduleData: Deallocates environment */
103
+ /* data for the defmodule construct. */
104
+ /****************************************************/
105
+ static void DeallocateDefmoduleData(
106
+ Environment *theEnv)
107
+ {
108
+ struct moduleStackItem *tmpMSPtr, *nextMSPtr;
109
+ struct moduleItem *tmpMIPtr, *nextMIPtr;
110
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
111
+ Defmodule *tmpDMPtr, *nextDMPtr;
112
+ struct portConstructItem *tmpPCPtr, *nextPCPtr;
113
+ #endif
114
+ #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
115
+ unsigned int i;
116
+ size_t space;
117
+ #endif
118
+
119
+ #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
120
+ for (i = 0; i < DefmoduleData(theEnv)->BNumberOfDefmodules; i++)
121
+ {
122
+ if (DefmoduleData(theEnv)->DefmoduleArray[i].itemsArray != NULL)
123
+ {
124
+ rm(theEnv,DefmoduleData(theEnv)->DefmoduleArray[i].itemsArray,
125
+ sizeof(void *) * GetNumberOfModuleItems(theEnv));
126
+ }
127
+ }
128
+
129
+ space = DefmoduleData(theEnv)->BNumberOfDefmodules * sizeof(Defmodule);
130
+ if (space != 0)
131
+ {
132
+ genfree(theEnv,DefmoduleData(theEnv)->DefmoduleArray,space);
133
+ DefmoduleData(theEnv)->ListOfDefmodules = NULL;
134
+ }
135
+
136
+ space = DefmoduleData(theEnv)->NumberOfPortItems * sizeof(struct portItem);
137
+ if (space != 0) genfree(theEnv,DefmoduleData(theEnv)->PortItemArray,space);
138
+ #endif
139
+
140
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
141
+ tmpDMPtr = DefmoduleData(theEnv)->ListOfDefmodules;
142
+ while (tmpDMPtr != NULL)
143
+ {
144
+ nextDMPtr = (Defmodule *) tmpDMPtr->header.next;
145
+ ReturnDefmodule(theEnv,tmpDMPtr,true);
146
+ tmpDMPtr = nextDMPtr;
147
+ }
148
+
149
+ tmpPCPtr = DefmoduleData(theEnv)->ListOfPortConstructItems;
150
+ while (tmpPCPtr != NULL)
151
+ {
152
+ nextPCPtr = tmpPCPtr->next;
153
+ rtn_struct(theEnv,portConstructItem,tmpPCPtr);
154
+ tmpPCPtr = nextPCPtr;
155
+ }
156
+ #endif
157
+
158
+ tmpMSPtr = DefmoduleData(theEnv)->ModuleStack;
159
+ while (tmpMSPtr != NULL)
160
+ {
161
+ nextMSPtr = tmpMSPtr->next;
162
+ rtn_struct(theEnv,moduleStackItem,tmpMSPtr);
163
+ tmpMSPtr = nextMSPtr;
164
+ }
165
+
166
+ tmpMIPtr = DefmoduleData(theEnv)->ListOfModuleItems;
167
+ while (tmpMIPtr != NULL)
168
+ {
169
+ nextMIPtr = tmpMIPtr->next;
170
+ rtn_struct(theEnv,moduleItem,tmpMIPtr);
171
+ tmpMIPtr = nextMIPtr;
172
+ }
173
+
174
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
175
+ DeallocateVoidCallList(theEnv,DefmoduleData(theEnv)->AfterModuleDefinedFunctions);
176
+ #endif
177
+ DeallocateVoidCallList(theEnv,DefmoduleData(theEnv)->AfterModuleChangeFunctions);
178
+ }
179
+
180
+ /**************************************************************/
181
+ /* InitializeDefmodules: Initializes the defmodule construct. */
182
+ /**************************************************************/
183
+ void InitializeDefmodules(
184
+ Environment *theEnv)
185
+ {
186
+ DefmoduleBasicCommands(theEnv);
187
+
188
+ #if (! RUN_TIME)
189
+ CreateMainModule(theEnv,NULL);
190
+ #endif
191
+
192
+ #if DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY)
193
+ AddConstruct(theEnv,"defmodule","defmodules",ParseDefmodule,NULL,NULL,NULL,NULL,
194
+ NULL,NULL,NULL,NULL,NULL);
195
+ #endif
196
+
197
+ #if (! RUN_TIME) && DEFMODULE_CONSTRUCT
198
+ AddUDF(theEnv,"get-current-module","y",0,0,NULL,GetCurrentModuleCommand,"GetCurrentModuleCommand",NULL);
199
+
200
+ AddUDF(theEnv,"set-current-module","y",1,1,"y",SetCurrentModuleCommand,"SetCurrentModuleCommand",NULL);
201
+ #endif
202
+ }
203
+
204
+ /******************************************************/
205
+ /* RegisterModuleItem: Called to register a construct */
206
+ /* which can be placed within a module. */
207
+ /******************************************************/
208
+ unsigned RegisterModuleItem(
209
+ Environment *theEnv,
210
+ const char *theItem,
211
+ AllocateModuleFunction *allocateFunction,
212
+ FreeModuleFunction *freeFunction,
213
+ void *(*bloadModuleReference)(Environment *,unsigned long),
214
+ void (*constructsToCModuleReference)(Environment *,FILE *,unsigned long,unsigned int,unsigned int),
215
+ FindConstructFunction *findFunction)
216
+ {
217
+ struct moduleItem *newModuleItem;
218
+
219
+ newModuleItem = get_struct(theEnv,moduleItem);
220
+ newModuleItem->name = theItem;
221
+ newModuleItem->allocateFunction = allocateFunction;
222
+ newModuleItem->freeFunction = freeFunction;
223
+ newModuleItem->bloadModuleReference = bloadModuleReference;
224
+ newModuleItem->constructsToCModuleReference = constructsToCModuleReference;
225
+ newModuleItem->findFunction = findFunction;
226
+ newModuleItem->moduleIndex = DefmoduleData(theEnv)->NumberOfModuleItems++;
227
+ newModuleItem->next = NULL;
228
+
229
+ if (DefmoduleData(theEnv)->LastModuleItem == NULL)
230
+ {
231
+ DefmoduleData(theEnv)->ListOfModuleItems = newModuleItem;
232
+ DefmoduleData(theEnv)->LastModuleItem = newModuleItem;
233
+ }
234
+ else
235
+ {
236
+ DefmoduleData(theEnv)->LastModuleItem->next = newModuleItem;
237
+ DefmoduleData(theEnv)->LastModuleItem = newModuleItem;
238
+ }
239
+
240
+ return newModuleItem->moduleIndex;
241
+ }
242
+
243
+ /***********************************************************/
244
+ /* GetListOfModuleItems: Returns the list of module items. */
245
+ /***********************************************************/
246
+ struct moduleItem *GetListOfModuleItems(
247
+ Environment *theEnv)
248
+ {
249
+ return (DefmoduleData(theEnv)->ListOfModuleItems);
250
+ }
251
+
252
+ /***************************************************************/
253
+ /* GetNumberOfModuleItems: Returns the number of module items. */
254
+ /***************************************************************/
255
+ unsigned GetNumberOfModuleItems(
256
+ Environment *theEnv)
257
+ {
258
+ return DefmoduleData(theEnv)->NumberOfModuleItems;
259
+ }
260
+
261
+ /********************************************************/
262
+ /* FindModuleItem: Finds the module item data structure */
263
+ /* corresponding to the specified name. */
264
+ /********************************************************/
265
+ struct moduleItem *FindModuleItem(
266
+ Environment *theEnv,
267
+ const char *theName)
268
+ {
269
+ struct moduleItem *theModuleItem;
270
+
271
+ for (theModuleItem = DefmoduleData(theEnv)->ListOfModuleItems;
272
+ theModuleItem != NULL;
273
+ theModuleItem = theModuleItem->next)
274
+ { if (strcmp(theModuleItem->name,theName) == 0) return(theModuleItem); }
275
+
276
+ return NULL;
277
+ }
278
+
279
+ /***************************************/
280
+ /* GetCurrentModule: Returns a pointer */
281
+ /* to the current module. */
282
+ /***************************************/
283
+ Defmodule *GetCurrentModule(
284
+ Environment *theEnv)
285
+ {
286
+ return DefmoduleData(theEnv)->CurrentModule;
287
+ }
288
+
289
+ /***********************************************************/
290
+ /* SetCurrentModule: Sets the value of the current module. */
291
+ /***********************************************************/
292
+ Defmodule *SetCurrentModule(
293
+ Environment *theEnv,
294
+ Defmodule *newModule)
295
+ {
296
+ struct voidCallFunctionItem *changeFunctions;
297
+ Defmodule *oldModule;
298
+
299
+ /*=============================================*/
300
+ /* Change the current module to the specified */
301
+ /* module and save the previous current module */
302
+ /* for the return value. */
303
+ /*=============================================*/
304
+
305
+ oldModule = DefmoduleData(theEnv)->CurrentModule;
306
+ DefmoduleData(theEnv)->CurrentModule = newModule;
307
+
308
+ /*==========================================================*/
309
+ /* Call the list of registered functions that need to know */
310
+ /* when the module has changed. The module change functions */
311
+ /* should only be called if this is a "real" module change. */
312
+ /* Many routines temporarily change the module to look for */
313
+ /* constructs, etc. The SaveCurrentModule function will */
314
+ /* disable the change functions from being called. */
315
+ /*==========================================================*/
316
+
317
+ if (DefmoduleData(theEnv)->CallModuleChangeFunctions)
318
+ {
319
+ DefmoduleData(theEnv)->ModuleChangeIndex++;
320
+ changeFunctions = DefmoduleData(theEnv)->AfterModuleChangeFunctions;
321
+ while (changeFunctions != NULL)
322
+ {
323
+ (*changeFunctions->func)(theEnv,changeFunctions->context);
324
+ changeFunctions = changeFunctions->next;
325
+ }
326
+ }
327
+
328
+ /*=====================================*/
329
+ /* Return the previous current module. */
330
+ /*=====================================*/
331
+
332
+ return oldModule;
333
+ }
334
+
335
+ /********************************************************/
336
+ /* SaveCurrentModule: Saves current module on stack and */
337
+ /* prevents SetCurrentModule() from calling change */
338
+ /* functions */
339
+ /********************************************************/
340
+ void SaveCurrentModule(
341
+ Environment *theEnv)
342
+ {
343
+ ModuleStackItem *tmp;
344
+
345
+ tmp = get_struct(theEnv,moduleStackItem);
346
+ tmp->changeFlag = DefmoduleData(theEnv)->CallModuleChangeFunctions;
347
+ DefmoduleData(theEnv)->CallModuleChangeFunctions = false;
348
+ tmp->theModule = DefmoduleData(theEnv)->CurrentModule;
349
+ tmp->next = DefmoduleData(theEnv)->ModuleStack;
350
+ DefmoduleData(theEnv)->ModuleStack = tmp;
351
+ }
352
+
353
+ /**********************************************************/
354
+ /* RestoreCurrentModule: Restores saved module and resets */
355
+ /* ability of SetCurrentModule() to call changed */
356
+ /* functions to previous state */
357
+ /**********************************************************/
358
+ void RestoreCurrentModule(
359
+ Environment *theEnv)
360
+ {
361
+ ModuleStackItem *tmp;
362
+
363
+ tmp = DefmoduleData(theEnv)->ModuleStack;
364
+ DefmoduleData(theEnv)->ModuleStack = tmp->next;
365
+ DefmoduleData(theEnv)->CallModuleChangeFunctions = tmp->changeFlag;
366
+ DefmoduleData(theEnv)->CurrentModule = tmp->theModule;
367
+ rtn_struct(theEnv,moduleStackItem,tmp);
368
+ }
369
+
370
+ /*************************************************************/
371
+ /* GetModuleItem: Returns the data pointer for the specified */
372
+ /* module item in the specified module. If no module is */
373
+ /* indicated, then the module item for the current module */
374
+ /* is returned. */
375
+ /*************************************************************/
376
+ void *GetModuleItem(
377
+ Environment *theEnv,
378
+ Defmodule *theModule,
379
+ unsigned moduleItemIndex)
380
+ {
381
+ if (theModule == NULL)
382
+ {
383
+ if (DefmoduleData(theEnv)->CurrentModule == NULL) return NULL;
384
+ theModule = DefmoduleData(theEnv)->CurrentModule;
385
+ }
386
+
387
+ if (theModule->itemsArray == NULL) return (NULL);
388
+
389
+ return ((void *) theModule->itemsArray[moduleItemIndex]);
390
+ }
391
+
392
+ /************************************************************/
393
+ /* SetModuleItem: Sets the data pointer for the specified */
394
+ /* module item in the specified module. If no module is */
395
+ /* indicated, then the module item for the current module */
396
+ /* is returned. */
397
+ /************************************************************/
398
+ void SetModuleItem(
399
+ Environment *theEnv,
400
+ Defmodule *theModule,
401
+ unsigned moduleItemIndex,
402
+ void *newValue)
403
+ {
404
+ if (theModule == NULL)
405
+ {
406
+ if (DefmoduleData(theEnv)->CurrentModule == NULL) return;
407
+ theModule = DefmoduleData(theEnv)->CurrentModule;
408
+ }
409
+
410
+ if (theModule->itemsArray == NULL) return;
411
+ theModule->itemsArray[moduleItemIndex] = (struct defmoduleItemHeader *) newValue;
412
+ }
413
+
414
+ /******************************************************/
415
+ /* CreateMainModule: Creates the default MAIN module. */
416
+ /******************************************************/
417
+ void CreateMainModule(
418
+ Environment *theEnv,
419
+ void *context)
420
+ {
421
+ Defmodule *newDefmodule;
422
+ struct moduleItem *theItem;
423
+ unsigned int i;
424
+ struct defmoduleItemHeader *theHeader;
425
+
426
+ /*=======================================*/
427
+ /* Allocate the defmodule data structure */
428
+ /* and name it the MAIN module. */
429
+ /*=======================================*/
430
+
431
+ newDefmodule = get_struct(theEnv,defmodule);
432
+ newDefmodule->header.name = CreateSymbol(theEnv,"MAIN");
433
+ IncrementLexemeCount(newDefmodule->header.name);
434
+ newDefmodule->header.whichModule = NULL;
435
+ newDefmodule->header.next = NULL;
436
+ newDefmodule->header.ppForm = NULL;
437
+ newDefmodule->importList = NULL;
438
+ newDefmodule->exportList = NULL;
439
+ newDefmodule->header.bsaveID = 0L;
440
+ newDefmodule->header.usrData = NULL;
441
+ newDefmodule->header.constructType = DEFMODULE;
442
+ newDefmodule->header.env = theEnv;
443
+
444
+ /*==================================*/
445
+ /* Initialize the array for storing */
446
+ /* the module's construct lists. */
447
+ /*==================================*/
448
+
449
+ if (DefmoduleData(theEnv)->NumberOfModuleItems == 0) newDefmodule->itemsArray = NULL;
450
+ else
451
+ {
452
+ newDefmodule->itemsArray = (struct defmoduleItemHeader **)
453
+ gm2(theEnv,sizeof(void *) * DefmoduleData(theEnv)->NumberOfModuleItems);
454
+ for (i = 0, theItem = DefmoduleData(theEnv)->ListOfModuleItems;
455
+ (i < DefmoduleData(theEnv)->NumberOfModuleItems) && (theItem != NULL);
456
+ i++, theItem = theItem->next)
457
+ {
458
+ if (theItem->allocateFunction == NULL)
459
+ { newDefmodule->itemsArray[i] = NULL; }
460
+ else
461
+ {
462
+ newDefmodule->itemsArray[i] = (struct defmoduleItemHeader *)
463
+ (*theItem->allocateFunction)(theEnv);
464
+ theHeader = (struct defmoduleItemHeader *) newDefmodule->itemsArray[i];
465
+ theHeader->theModule = newDefmodule;
466
+ theHeader->firstItem = NULL;
467
+ theHeader->lastItem = NULL;
468
+ }
469
+ }
470
+ }
471
+
472
+ /*=======================================*/
473
+ /* Add the module to the list of modules */
474
+ /* and make it the current module. */
475
+ /*=======================================*/
476
+
477
+ #if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT
478
+ SetNumberOfDefmodules(theEnv,1);
479
+ #endif
480
+
481
+ DefmoduleData(theEnv)->LastDefmodule = newDefmodule;
482
+ DefmoduleData(theEnv)->ListOfDefmodules = newDefmodule;
483
+ SetCurrentModule(theEnv,newDefmodule);
484
+ }
485
+
486
+ /*********************************************************************/
487
+ /* SetListOfDefmodules: Sets the list of defmodules to the specified */
488
+ /* value. Normally used when initializing a run-time module or */
489
+ /* when bloading a binary file to install the list of defmodules. */
490
+ /*********************************************************************/
491
+ void SetListOfDefmodules(
492
+ Environment *theEnv,
493
+ Defmodule *defmodulePtr)
494
+ {
495
+ DefmoduleData(theEnv)->ListOfDefmodules = defmodulePtr;
496
+ DefmoduleData(theEnv)->LastDefmodule = DefmoduleData(theEnv)->ListOfDefmodules;
497
+
498
+ if (DefmoduleData(theEnv)->LastDefmodule == NULL) return;
499
+ DefmoduleData(theEnv)->LastDefmodule->header.env = theEnv;
500
+
501
+ while (DefmoduleData(theEnv)->LastDefmodule->header.next != NULL)
502
+ {
503
+ DefmoduleData(theEnv)->LastDefmodule = (Defmodule *) DefmoduleData(theEnv)->LastDefmodule->header.next;
504
+ DefmoduleData(theEnv)->LastDefmodule->header.env = theEnv;
505
+ }
506
+ }
507
+
508
+ /*******************************************************************/
509
+ /* GetNextDefmodule: If passed a NULL pointer, returns the first */
510
+ /* defmodule in the ListOfDefmodules. Otherwise returns the next */
511
+ /* defmodule following the defmodule passed as an argument. */
512
+ /*******************************************************************/
513
+ Defmodule *GetNextDefmodule(
514
+ Environment *theEnv,
515
+ Defmodule *defmodulePtr)
516
+ {
517
+ if (defmodulePtr == NULL)
518
+ { return DefmoduleData(theEnv)->ListOfDefmodules; }
519
+ else
520
+ { return (Defmodule *) defmodulePtr->header.next; }
521
+ }
522
+
523
+ /***********************************/
524
+ /* DefmoduleName: Returns the name */
525
+ /* of the specified defmodule. */
526
+ /***********************************/
527
+ const char *DefmoduleName(
528
+ Defmodule *defmodulePtr)
529
+ {
530
+ return defmodulePtr->header.name->contents;
531
+ }
532
+
533
+ /************************************************/
534
+ /* DefmodulePPForm: Returns the pretty print */
535
+ /* representation of the specified defmodule. */
536
+ /************************************************/
537
+ const char *DefmodulePPForm(
538
+ Defmodule *defmodulePtr)
539
+ {
540
+ return defmodulePtr->header.ppForm;
541
+ }
542
+
543
+ #if (! RUN_TIME)
544
+
545
+ /***********************************************/
546
+ /* RemoveAllDefmodules: Removes all defmodules */
547
+ /* from the current environment. */
548
+ /***********************************************/
549
+ void RemoveAllDefmodules(
550
+ Environment *theEnv,
551
+ void *context)
552
+ {
553
+ Defmodule *nextDefmodule;
554
+
555
+ while (DefmoduleData(theEnv)->ListOfDefmodules != NULL)
556
+ {
557
+ nextDefmodule = (Defmodule *) DefmoduleData(theEnv)->ListOfDefmodules->header.next;
558
+ ReturnDefmodule(theEnv,DefmoduleData(theEnv)->ListOfDefmodules,false);
559
+ DefmoduleData(theEnv)->ListOfDefmodules = nextDefmodule;
560
+ }
561
+
562
+ DefmoduleData(theEnv)->CurrentModule = NULL;
563
+ DefmoduleData(theEnv)->LastDefmodule = NULL;
564
+ }
565
+
566
+ /************************************************************/
567
+ /* ReturnDefmodule: Returns the data structures associated */
568
+ /* with a defmodule construct to the pool of free memory. */
569
+ /************************************************************/
570
+ static void ReturnDefmodule(
571
+ Environment *theEnv,
572
+ Defmodule *theDefmodule,
573
+ bool environmentClear)
574
+ {
575
+ unsigned int i;
576
+ struct moduleItem *theItem;
577
+ struct portItem *theSpec, *nextSpec;
578
+
579
+ /*=====================================================*/
580
+ /* Set the current module to the module being deleted. */
581
+ /*=====================================================*/
582
+
583
+ if (theDefmodule == NULL) return;
584
+
585
+ if (! environmentClear)
586
+ { SetCurrentModule(theEnv,theDefmodule); }
587
+
588
+ /*============================================*/
589
+ /* Call the free functions for the constructs */
590
+ /* belonging to this module. */
591
+ /*============================================*/
592
+
593
+ if (theDefmodule->itemsArray != NULL)
594
+ {
595
+ if (! environmentClear)
596
+ {
597
+ for (i = 0, theItem = DefmoduleData(theEnv)->ListOfModuleItems;
598
+ (i < DefmoduleData(theEnv)->NumberOfModuleItems) && (theItem != NULL);
599
+ i++, theItem = theItem->next)
600
+ {
601
+ if (theItem->freeFunction != NULL)
602
+ { (*theItem->freeFunction)(theEnv,theDefmodule->itemsArray[i]); }
603
+ }
604
+ }
605
+
606
+ rm(theEnv,theDefmodule->itemsArray,sizeof(void *) * DefmoduleData(theEnv)->NumberOfModuleItems);
607
+ }
608
+
609
+ /*======================================================*/
610
+ /* Decrement the symbol count for the defmodule's name. */
611
+ /*======================================================*/
612
+
613
+ if (! environmentClear)
614
+ { ReleaseLexeme(theEnv,theDefmodule->header.name); }
615
+
616
+ /*====================================*/
617
+ /* Free the items in the import list. */
618
+ /*====================================*/
619
+
620
+ theSpec = theDefmodule->importList;
621
+ while (theSpec != NULL)
622
+ {
623
+ nextSpec = theSpec->next;
624
+ if (! environmentClear)
625
+ {
626
+ if (theSpec->moduleName != NULL) ReleaseLexeme(theEnv,theSpec->moduleName);
627
+ if (theSpec->constructType != NULL) ReleaseLexeme(theEnv,theSpec->constructType);
628
+ if (theSpec->constructName != NULL) ReleaseLexeme(theEnv,theSpec->constructName);
629
+ }
630
+ rtn_struct(theEnv,portItem,theSpec);
631
+ theSpec = nextSpec;
632
+ }
633
+
634
+ /*====================================*/
635
+ /* Free the items in the export list. */
636
+ /*====================================*/
637
+
638
+ theSpec = theDefmodule->exportList;
639
+ while (theSpec != NULL)
640
+ {
641
+ nextSpec = theSpec->next;
642
+ if (! environmentClear)
643
+ {
644
+ if (theSpec->moduleName != NULL) ReleaseLexeme(theEnv,theSpec->moduleName);
645
+ if (theSpec->constructType != NULL) ReleaseLexeme(theEnv,theSpec->constructType);
646
+ if (theSpec->constructName != NULL) ReleaseLexeme(theEnv,theSpec->constructName);
647
+ }
648
+ rtn_struct(theEnv,portItem,theSpec);
649
+ theSpec = nextSpec;
650
+ }
651
+
652
+ /*=========================================*/
653
+ /* Free the defmodule pretty print string. */
654
+ /*=========================================*/
655
+
656
+ if (theDefmodule->header.ppForm != NULL)
657
+ {
658
+ rm(theEnv,(void *) theDefmodule->header.ppForm,
659
+ sizeof(char) * (strlen(theDefmodule->header.ppForm) + 1));
660
+ }
661
+
662
+ /*=======================*/
663
+ /* Return the user data. */
664
+ /*=======================*/
665
+
666
+ ClearUserDataList(theEnv,theDefmodule->header.usrData);
667
+
668
+ /*======================================*/
669
+ /* Return the defmodule data structure. */
670
+ /*======================================*/
671
+
672
+ rtn_struct(theEnv,defmodule,theDefmodule);
673
+ }
674
+
675
+ #endif /* (! RUN_TIME) */
676
+
677
+ /************************************************/
678
+ /* FindDefmodule: Searches for a defmodule in */
679
+ /* the list of defmodules. Returns a pointer */
680
+ /* to the defmodule if found, otherwise NULL. */
681
+ /************************************************/
682
+ Defmodule *FindDefmodule(
683
+ Environment *theEnv,
684
+ const char *defmoduleName)
685
+ {
686
+ Defmodule *defmodulePtr;
687
+ CLIPSLexeme *findValue;
688
+
689
+ if ((findValue = FindSymbolHN(theEnv,defmoduleName,SYMBOL_BIT)) == NULL) return NULL;
690
+
691
+ defmodulePtr = DefmoduleData(theEnv)->ListOfDefmodules;
692
+ while (defmodulePtr != NULL)
693
+ {
694
+ if (defmodulePtr->header.name == findValue)
695
+ { return defmodulePtr; }
696
+
697
+ defmodulePtr = (Defmodule *) defmodulePtr->header.next;
698
+ }
699
+
700
+ return NULL;
701
+ }
702
+
703
+ /*************************************************/
704
+ /* GetCurrentModuleCommand: H/L access routine */
705
+ /* for the get-current-module command. */
706
+ /*************************************************/
707
+ void GetCurrentModuleCommand(
708
+ Environment *theEnv,
709
+ UDFContext *context,
710
+ UDFValue *returnValue)
711
+ {
712
+ Defmodule *theModule;
713
+
714
+ theModule = GetCurrentModule(theEnv);
715
+
716
+ if (theModule == NULL)
717
+ {
718
+ returnValue->lexemeValue = FalseSymbol(theEnv);
719
+ return;
720
+ }
721
+
722
+ returnValue->value = theModule->header.name;
723
+ }
724
+
725
+ /*************************************************/
726
+ /* SetCurrentModuleCommand: H/L access routine */
727
+ /* for the set-current-module command. */
728
+ /*************************************************/
729
+ void SetCurrentModuleCommand(
730
+ Environment *theEnv,
731
+ UDFContext *context,
732
+ UDFValue *returnValue)
733
+ {
734
+ UDFValue theArg;
735
+ const char *argument;
736
+ Defmodule *theModule;
737
+ CLIPSLexeme *oldModuleName;
738
+
739
+ /*=======================*/
740
+ /* Set the return value. */
741
+ /*=======================*/
742
+
743
+ theModule = GetCurrentModule(theEnv);
744
+ if (theModule == NULL)
745
+ {
746
+ returnValue->lexemeValue = FalseSymbol(theEnv);
747
+ return;
748
+ }
749
+
750
+ oldModuleName = theModule->header.name;
751
+ returnValue->value = oldModuleName;
752
+
753
+ /*=====================================================*/
754
+ /* Check for the correct number and type of arguments. */
755
+ /*=====================================================*/
756
+
757
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg))
758
+ { return; }
759
+
760
+ argument = theArg.lexemeValue->contents;
761
+
762
+ /*================================================*/
763
+ /* Set the current module to the specified value. */
764
+ /*================================================*/
765
+
766
+ theModule = FindDefmodule(theEnv,argument);
767
+
768
+ if (theModule == NULL)
769
+ {
770
+ CantFindItemErrorMessage(theEnv,"defmodule",argument,true);
771
+ return;
772
+ }
773
+
774
+ SetCurrentModule(theEnv,theModule);
775
+ }
776
+
777
+ /*************************************************/
778
+ /* AddAfterModuleChangeFunction: Adds a function */
779
+ /* to the list of functions to be called after */
780
+ /* a module change occurs. */
781
+ /*************************************************/
782
+ void AddAfterModuleChangeFunction(
783
+ Environment *theEnv,
784
+ const char *name,
785
+ VoidCallFunction *func,
786
+ int priority,
787
+ void *context)
788
+ {
789
+ DefmoduleData(theEnv)->AfterModuleChangeFunctions =
790
+ AddVoidFunctionToCallList(theEnv,name,priority,func,DefmoduleData(theEnv)->AfterModuleChangeFunctions,context);
791
+ }
792
+
793
+ /************************************************/
794
+ /* IllegalModuleSpecifierMessage: Error message */
795
+ /* for the illegal use of a module specifier. */
796
+ /************************************************/
797
+ void IllegalModuleSpecifierMessage(
798
+ Environment *theEnv)
799
+ {
800
+ PrintErrorID(theEnv,"MODULDEF",1,true);
801
+ WriteString(theEnv,STDERR,"Illegal use of the module specifier.\n");
802
+ }
803
+
804
+ /*********************************************/
805
+ /* GetNumberOfDefmodules: Returns the number */
806
+ /* of defmodules currently defined. */
807
+ /*********************************************/
808
+ unsigned short GetNumberOfDefmodules(
809
+ Environment *theEnv)
810
+ {
811
+ #if DEFMODULE_CONSTRUCT && (! RUN_TIME) && (! BLOAD_ONLY)
812
+ return DefmoduleData(theEnv)->NumberOfDefmodules;
813
+ #else
814
+ return 1;
815
+ #endif
816
+ }
817
+