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,1036 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 10/28/20 */
5
+ /* */
6
+ /* DEFMODULE UTILITY MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Provides routines for parsing module/construct */
11
+ /* names and searching through modules for specific */
12
+ /* constructs. */
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.30: Used genstrncpy instead of strncpy. */
23
+ /* */
24
+ /* Added const qualifiers to remove C++ */
25
+ /* deprecation warnings. */
26
+ /* */
27
+ /* 6.31: Used strstr function to find module separator. */
28
+ /* */
29
+ /* Disallowed use of extraneous module */
30
+ /* specifiers in a construct name. */
31
+ /* */
32
+ /* 6.32: Fixed embedded reset of error flags. */
33
+ /* */
34
+ /* 6.40: Added Env prefix to GetHaltExecution and */
35
+ /* SetHaltExecution functions. */
36
+ /* */
37
+ /* Pragma once and other inclusion changes. */
38
+ /* */
39
+ /* Added support for booleans with <stdbool.h>. */
40
+ /* */
41
+ /* Removed use of void pointers for specific */
42
+ /* data structures. */
43
+ /* */
44
+ /*************************************************************/
45
+
46
+ #include "setup.h"
47
+
48
+ #include "envrnmnt.h"
49
+ #include "cstrcpsr.h"
50
+ #include "memalloc.h"
51
+ #include "modulpsr.h"
52
+ #include "pprint.h"
53
+ #include "prntutil.h"
54
+ #include "router.h"
55
+ #include "sysdep.h"
56
+ #include "watch.h"
57
+
58
+ #include "modulutl.h"
59
+
60
+ /***************************************/
61
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
62
+ /***************************************/
63
+
64
+ static ConstructHeader *SearchImportedConstructModules(Environment *,CLIPSLexeme *,Defmodule *,
65
+ struct moduleItem *,CLIPSLexeme *,
66
+ unsigned int *,bool,Defmodule *);
67
+
68
+ /********************************************************************/
69
+ /* FindModuleSeparator: Finds the :: separator which delineates the */
70
+ /* boundary between a module name and a construct name. The value */
71
+ /* zero is returned if the separator is not found, otherwise the */
72
+ /* position of the second colon within the string is returned. */
73
+ /********************************************************************/
74
+ unsigned FindModuleSeparator(
75
+ const char *theString)
76
+ {
77
+ const char *sep;
78
+
79
+ sep = strstr(theString,"::");
80
+
81
+ if (sep == NULL)
82
+ { return 0; }
83
+
84
+ return ((unsigned) (sep - theString) + 1);
85
+ }
86
+
87
+ /*******************************************************************/
88
+ /* ExtractModuleName: Given the position of the :: separator and a */
89
+ /* module/construct name joined using the separator, returns a */
90
+ /* symbol reference to the module name (or NULL if a module name */
91
+ /* cannot be extracted). */
92
+ /*******************************************************************/
93
+ CLIPSLexeme *ExtractModuleName(
94
+ Environment *theEnv,
95
+ unsigned thePosition,
96
+ const char *theString)
97
+ {
98
+ char *newString;
99
+ CLIPSLexeme *returnValue;
100
+
101
+ /*=============================================*/
102
+ /* Return NULL if the :: is in a position such */
103
+ /* that a module name can't be extracted. */
104
+ /*=============================================*/
105
+
106
+ if (thePosition <= 1) return NULL;
107
+
108
+ /*==========================================*/
109
+ /* Allocate storage for a temporary string. */
110
+ /*==========================================*/
111
+
112
+ newString = (char *) gm2(theEnv,thePosition);
113
+
114
+ /*======================================================*/
115
+ /* Copy the entire module/construct name to the string. */
116
+ /*======================================================*/
117
+
118
+ genstrncpy(newString,theString,
119
+ (STD_SIZE) thePosition - 1);
120
+
121
+ /*========================================================*/
122
+ /* Place an end of string marker where the :: is located. */
123
+ /*========================================================*/
124
+
125
+ newString[thePosition-1] = EOS;
126
+
127
+ /*=====================================================*/
128
+ /* Add the module name (the truncated module/construct */
129
+ /* name) to the symbol table. */
130
+ /*=====================================================*/
131
+
132
+ returnValue = CreateSymbol(theEnv,newString);
133
+
134
+ /*=============================================*/
135
+ /* Return the storage of the temporary string. */
136
+ /*=============================================*/
137
+
138
+ rm(theEnv,newString,thePosition);
139
+
140
+ /*=============================================*/
141
+ /* Return a pointer to the module name symbol. */
142
+ /*=============================================*/
143
+
144
+ return returnValue;
145
+ }
146
+
147
+ /********************************************************************/
148
+ /* ExtractConstructName: Given the position of the :: separator and */
149
+ /* a module/construct name joined using the separator, returns a */
150
+ /* symbol reference to the construct name (or NULL if a construct */
151
+ /* name cannot be extracted). */
152
+ /********************************************************************/
153
+ CLIPSLexeme *ExtractConstructName(
154
+ Environment *theEnv,
155
+ unsigned thePosition,
156
+ const char *theString,
157
+ unsigned returnType)
158
+ {
159
+ size_t theLength;
160
+ char *newString;
161
+ CLIPSLexeme *returnValue;
162
+
163
+ /*======================================*/
164
+ /* Just return the string if it doesn't */
165
+ /* contain the :: symbol. */
166
+ /*======================================*/
167
+
168
+ if (thePosition == 0) return CreateSymbol(theEnv,theString);
169
+
170
+ /*=====================================*/
171
+ /* Determine the length of the string. */
172
+ /*=====================================*/
173
+
174
+ theLength = strlen(theString);
175
+
176
+ /*=================================================*/
177
+ /* Return NULL if the :: is at the very end of the */
178
+ /* string (and thus there is no construct name). */
179
+ /*=================================================*/
180
+
181
+ if (theLength <= (thePosition + 1)) return NULL;
182
+
183
+ /*====================================*/
184
+ /* Allocate a temporary string large */
185
+ /* enough to hold the construct name. */
186
+ /*====================================*/
187
+
188
+ newString = (char *) gm2(theEnv,theLength - thePosition);
189
+
190
+ /*================================================*/
191
+ /* Copy the construct name portion of the */
192
+ /* module/construct name to the temporary string. */
193
+ /*================================================*/
194
+
195
+ genstrncpy(newString,&theString[thePosition+1],
196
+ (STD_SIZE) theLength - thePosition);
197
+
198
+ /*=============================================*/
199
+ /* Add the construct name to the symbol table. */
200
+ /*=============================================*/
201
+
202
+ if (returnType == SYMBOL_TYPE)
203
+ { returnValue = CreateSymbol(theEnv,newString); }
204
+ else if (returnType == INSTANCE_NAME_TYPE)
205
+ { returnValue = CreateInstanceName(theEnv,newString); }
206
+ else
207
+ { returnValue = CreateString(theEnv,newString); }
208
+
209
+ /*=============================================*/
210
+ /* Return the storage of the temporary string. */
211
+ /*=============================================*/
212
+
213
+ rm(theEnv,newString,theLength - thePosition);
214
+
215
+ /*================================================*/
216
+ /* Return a pointer to the construct name symbol. */
217
+ /*================================================*/
218
+
219
+ return returnValue;
220
+ }
221
+
222
+ /****************************************************/
223
+ /* ExtractModuleAndConstructName: Extracts both the */
224
+ /* module and construct name from a string. Sets */
225
+ /* the current module to the specified module. */
226
+ /****************************************************/
227
+ const char *ExtractModuleAndConstructName(
228
+ Environment *theEnv,
229
+ const char *theName)
230
+ {
231
+ unsigned separatorPosition;
232
+ CLIPSLexeme *moduleName, *shortName;
233
+ Defmodule *theModule;
234
+
235
+ /*========================*/
236
+ /* Find the :: separator. */
237
+ /*========================*/
238
+
239
+ separatorPosition = FindModuleSeparator(theName);
240
+ if (! separatorPosition) return(theName);
241
+
242
+ /*==========================*/
243
+ /* Extract the module name. */
244
+ /*==========================*/
245
+
246
+ moduleName = ExtractModuleName(theEnv,separatorPosition,theName);
247
+ if (moduleName == NULL) return NULL;
248
+
249
+ /*====================================*/
250
+ /* Check to see if the module exists. */
251
+ /*====================================*/
252
+
253
+ theModule = FindDefmodule(theEnv,moduleName->contents);
254
+ if (theModule == NULL) return NULL;
255
+
256
+ /*============================*/
257
+ /* Change the current module. */
258
+ /*============================*/
259
+
260
+ SetCurrentModule(theEnv,theModule);
261
+
262
+ /*=============================*/
263
+ /* Extract the construct name. */
264
+ /*=============================*/
265
+
266
+ shortName = ExtractConstructName(theEnv,separatorPosition,theName,SYMBOL_TYPE);
267
+ if (shortName == NULL) return NULL;
268
+ return shortName->contents;
269
+ }
270
+
271
+ /************************************************************/
272
+ /* FindImportedConstruct: High level routine which searches */
273
+ /* a module and other modules from which it imports */
274
+ /* constructs for a specified construct. */
275
+ /************************************************************/
276
+ ConstructHeader *FindImportedConstruct(
277
+ Environment *theEnv,
278
+ const char *constructName,
279
+ Defmodule *matchModule,
280
+ const char *findName,
281
+ unsigned int *count,
282
+ bool searchCurrent,
283
+ Defmodule *notYetDefinedInModule)
284
+ {
285
+ ConstructHeader *rv;
286
+ struct moduleItem *theModuleItem;
287
+
288
+ /*=============================================*/
289
+ /* Set the number of references found to zero. */
290
+ /*=============================================*/
291
+
292
+ *count = 0;
293
+
294
+ /*===============================*/
295
+ /* The :: should not be included */
296
+ /* in the construct's name. */
297
+ /*===============================*/
298
+
299
+ if (FindModuleSeparator(findName)) return NULL;
300
+
301
+ /*=============================================*/
302
+ /* Remember the current module since we'll be */
303
+ /* changing it during the search and will want */
304
+ /* to restore it once the search is completed. */
305
+ /*=============================================*/
306
+
307
+ SaveCurrentModule(theEnv);
308
+
309
+ /*==========================================*/
310
+ /* Find the module related access functions */
311
+ /* for the construct type being sought. */
312
+ /*==========================================*/
313
+
314
+ if ((theModuleItem = FindModuleItem(theEnv,constructName)) == NULL)
315
+ {
316
+ RestoreCurrentModule(theEnv);
317
+ return NULL;
318
+ }
319
+
320
+ /*===========================================*/
321
+ /* If the construct type doesn't have a find */
322
+ /* function, then we can't look for it. */
323
+ /*===========================================*/
324
+
325
+ if (theModuleItem->findFunction == NULL)
326
+ {
327
+ RestoreCurrentModule(theEnv);
328
+ return NULL;
329
+ }
330
+
331
+ /*==================================*/
332
+ /* Initialize the search by marking */
333
+ /* all modules as unvisited. */
334
+ /*==================================*/
335
+
336
+ MarkModulesAsUnvisited(theEnv);
337
+
338
+ /*===========================*/
339
+ /* Search for the construct. */
340
+ /*===========================*/
341
+
342
+ rv = SearchImportedConstructModules(theEnv,CreateSymbol(theEnv,constructName),
343
+ matchModule,theModuleItem,
344
+ CreateSymbol(theEnv,findName),count,
345
+ searchCurrent,notYetDefinedInModule);
346
+
347
+ /*=============================*/
348
+ /* Restore the current module. */
349
+ /*=============================*/
350
+
351
+ RestoreCurrentModule(theEnv);
352
+
353
+ /*====================================*/
354
+ /* Return a pointer to the construct. */
355
+ /*====================================*/
356
+
357
+ return rv;
358
+ }
359
+
360
+ /*********************************************************/
361
+ /* AmbiguousReferenceErrorMessage: Error message printed */
362
+ /* when a reference to a specific construct can be */
363
+ /* imported from more than one module. */
364
+ /*********************************************************/
365
+ void AmbiguousReferenceErrorMessage(
366
+ Environment *theEnv,
367
+ const char *constructName,
368
+ const char *findName)
369
+ {
370
+ WriteString(theEnv,STDERR,"Ambiguous reference to ");
371
+ WriteString(theEnv,STDERR,constructName);
372
+ WriteString(theEnv,STDERR," ");
373
+ WriteString(theEnv,STDERR,findName);
374
+ WriteString(theEnv,STDERR,".\nIt is imported from more than one module.\n");
375
+ }
376
+
377
+ /****************************************************/
378
+ /* MarkModulesAsUnvisited: Used for initializing a */
379
+ /* search through the module heirarchies. Sets */
380
+ /* the visited flag of each module to false. */
381
+ /****************************************************/
382
+ void MarkModulesAsUnvisited(
383
+ Environment *theEnv)
384
+ {
385
+ Defmodule *theModule;
386
+
387
+ DefmoduleData(theEnv)->CurrentModule->visitedFlag = false;
388
+ for (theModule = GetNextDefmodule(theEnv,NULL);
389
+ theModule != NULL;
390
+ theModule = GetNextDefmodule(theEnv,theModule))
391
+ { theModule->visitedFlag = false; }
392
+ }
393
+
394
+ /***********************************************************/
395
+ /* SearchImportedConstructModules: Low level routine which */
396
+ /* searches a module and other modules from which it */
397
+ /* imports constructs for a specified construct. */
398
+ /***********************************************************/
399
+ static ConstructHeader *SearchImportedConstructModules(
400
+ Environment *theEnv,
401
+ CLIPSLexeme *constructType,
402
+ Defmodule *matchModule,
403
+ struct moduleItem *theModuleItem,
404
+ CLIPSLexeme *findName,
405
+ unsigned int *count,
406
+ bool searchCurrent,
407
+ Defmodule *notYetDefinedInModule)
408
+ {
409
+ Defmodule *theModule;
410
+ struct portItem *theImportList, *theExportList;
411
+ ConstructHeader *rv, *arv = NULL;
412
+ bool searchModule, exported;
413
+ Defmodule *currentModule;
414
+
415
+ /*=========================================*/
416
+ /* Start the search in the current module. */
417
+ /* If the current module has already been */
418
+ /* visited, then return. */
419
+ /*=========================================*/
420
+
421
+ currentModule = GetCurrentModule(theEnv);
422
+ if (currentModule->visitedFlag) return NULL;
423
+
424
+ /*=======================================================*/
425
+ /* The searchCurrent flag indicates whether the current */
426
+ /* module should be included in the search. In addition, */
427
+ /* if matchModule is non-NULL, the current module will */
428
+ /* only be searched if it is the specific module from */
429
+ /* which we want the construct imported. */
430
+ /*=======================================================*/
431
+
432
+ if ((searchCurrent) &&
433
+ ((matchModule == NULL) || (currentModule == matchModule)))
434
+ {
435
+ /*===============================================*/
436
+ /* Look for the construct in the current module. */
437
+ /*===============================================*/
438
+
439
+ rv = (*theModuleItem->findFunction)(theEnv,findName->contents);
440
+
441
+ /*========================================================*/
442
+ /* If we're in the process of defining the construct in */
443
+ /* the module we're searching then go ahead and increment */
444
+ /* the count indicating the number of modules in which */
445
+ /* the construct was found. */
446
+ /*========================================================*/
447
+
448
+ if (notYetDefinedInModule == currentModule)
449
+ {
450
+ (*count)++;
451
+ arv = rv;
452
+ }
453
+
454
+ /*=========================================================*/
455
+ /* Otherwise, if the construct is in the specified module, */
456
+ /* increment the count only if the construct actually */
457
+ /* belongs to the module. [Some constructs, like the COOL */
458
+ /* system classes, can be found in any module, but they */
459
+ /* actually belong to the MAIN module.] */
460
+ /*=========================================================*/
461
+
462
+ else if (rv != NULL)
463
+ {
464
+ if (rv->whichModule->theModule == currentModule)
465
+ { (*count)++; }
466
+ arv = rv;
467
+ }
468
+ }
469
+
470
+ /*=====================================*/
471
+ /* Mark the current module as visited. */
472
+ /*=====================================*/
473
+
474
+ currentModule->visitedFlag = true;
475
+
476
+ /*===================================*/
477
+ /* Search through all of the modules */
478
+ /* imported by the current module. */
479
+ /*===================================*/
480
+
481
+ theModule = GetCurrentModule(theEnv);
482
+ theImportList = theModule->importList;
483
+
484
+ while (theImportList != NULL)
485
+ {
486
+ /*===================================================*/
487
+ /* Determine if the module should be searched (based */
488
+ /* upon whether the entire module, all constructs of */
489
+ /* a specific type, or specifically named constructs */
490
+ /* are imported). */
491
+ /*===================================================*/
492
+
493
+ searchModule = false;
494
+ if ((theImportList->constructType == NULL) ||
495
+ (theImportList->constructType == constructType))
496
+ {
497
+ if ((theImportList->constructName == NULL) ||
498
+ (theImportList->constructName == findName))
499
+ { searchModule = true; }
500
+ }
501
+
502
+ /*=================================*/
503
+ /* Determine if the module exists. */
504
+ /*=================================*/
505
+
506
+ if (searchModule)
507
+ {
508
+ theModule = FindDefmodule(theEnv,theImportList->moduleName->contents);
509
+ if (theModule == NULL) searchModule = false;
510
+ }
511
+
512
+ /*=======================================================*/
513
+ /* Determine if the construct is exported by the module. */
514
+ /*=======================================================*/
515
+
516
+ if (searchModule)
517
+ {
518
+ exported = false;
519
+ theExportList = theModule->exportList;
520
+ while ((theExportList != NULL) && (! exported))
521
+ {
522
+ if ((theExportList->constructType == NULL) ||
523
+ (theExportList->constructType == constructType))
524
+ {
525
+ if ((theExportList->constructName == NULL) ||
526
+ (theExportList->constructName == findName))
527
+ { exported = true; }
528
+ }
529
+
530
+ theExportList = theExportList->next;
531
+ }
532
+
533
+ if (! exported) searchModule = false;
534
+ }
535
+
536
+ /*=================================*/
537
+ /* Search in the specified module. */
538
+ /*=================================*/
539
+
540
+ if (searchModule)
541
+ {
542
+ SetCurrentModule(theEnv,theModule);
543
+ if ((rv = SearchImportedConstructModules(theEnv,constructType,matchModule,
544
+ theModuleItem,findName,
545
+ count,true,
546
+ notYetDefinedInModule)) != NULL)
547
+ { arv = rv; }
548
+ }
549
+
550
+ /*====================================*/
551
+ /* Move on to the next imported item. */
552
+ /*====================================*/
553
+
554
+ theImportList = theImportList->next;
555
+ }
556
+
557
+ /*=========================*/
558
+ /* Return a pointer to the */
559
+ /* last construct found. */
560
+ /*=========================*/
561
+
562
+ return arv;
563
+ }
564
+
565
+ /**************************************************************/
566
+ /* ConstructExported: Returns true if the specified construct */
567
+ /* is exported from the specified module. */
568
+ /**************************************************************/
569
+ bool ConstructExported(
570
+ Environment *theEnv,
571
+ const char *constructTypeStr,
572
+ CLIPSLexeme *moduleName,
573
+ CLIPSLexeme *findName)
574
+ {
575
+ CLIPSLexeme *constructType;
576
+ Defmodule *theModule;
577
+ struct portItem *theExportList;
578
+
579
+ constructType = FindSymbolHN(theEnv,constructTypeStr,SYMBOL_BIT);
580
+ theModule = FindDefmodule(theEnv,moduleName->contents);
581
+
582
+ if ((constructType == NULL) || (theModule == NULL) || (findName == NULL))
583
+ { return false; }
584
+
585
+ theExportList = theModule->exportList;
586
+ while (theExportList != NULL)
587
+ {
588
+ if ((theExportList->constructType == NULL) ||
589
+ (theExportList->constructType == constructType))
590
+ {
591
+ if ((theExportList->constructName == NULL) ||
592
+ (theExportList->constructName == findName))
593
+ { return true; }
594
+ }
595
+
596
+ theExportList = theExportList->next;
597
+ }
598
+
599
+ return false;
600
+ }
601
+
602
+ /*********************************************************/
603
+ /* AllImportedModulesVisited: Returns true if all of the */
604
+ /* imported modules for a module have been visited. */
605
+ /*********************************************************/
606
+ bool AllImportedModulesVisited(
607
+ Environment *theEnv,
608
+ Defmodule *theModule)
609
+ {
610
+ struct portItem *theImportList;
611
+ Defmodule *theImportModule;
612
+
613
+ theImportList = theModule->importList;
614
+ while (theImportList != NULL)
615
+ {
616
+ theImportModule = FindDefmodule(theEnv,theImportList->moduleName->contents);
617
+
618
+ if (! theImportModule->visitedFlag) return false;
619
+
620
+ theImportList = theImportList->next;
621
+ }
622
+
623
+ return true;
624
+ }
625
+
626
+ /***************************************/
627
+ /* ListItemsDriver: Driver routine for */
628
+ /* listing items in a module. */
629
+ /***************************************/
630
+ void ListItemsDriver(
631
+ Environment *theEnv,
632
+ const char *logicalName,
633
+ Defmodule *theModule,
634
+ const char *singleName,
635
+ const char *pluralName,
636
+ GetNextItemFunction *nextFunction,
637
+ const char *(*nameFunction)(void *),
638
+ PrintItemFunction *printFunction,
639
+ bool (*doItFunction)(void *))
640
+ {
641
+ void *constructPtr;
642
+ const char *constructName;
643
+ unsigned long count = 0;
644
+ bool allModules = false;
645
+ bool doIt;
646
+
647
+ /*=====================================*/
648
+ /* If embedded, clear the error flags. */
649
+ /*=====================================*/
650
+
651
+ if (EvaluationData(theEnv)->CurrentExpression == NULL)
652
+ { ResetErrorFlags(theEnv); }
653
+
654
+ /*==========================*/
655
+ /* Save the current module. */
656
+ /*==========================*/
657
+
658
+ SaveCurrentModule(theEnv);
659
+
660
+ /*======================*/
661
+ /* Print out the items. */
662
+ /*======================*/
663
+
664
+ if (theModule == NULL)
665
+ {
666
+ theModule = GetNextDefmodule(theEnv,NULL);
667
+ allModules = true;
668
+ }
669
+
670
+ while (theModule != NULL)
671
+ {
672
+ if (allModules)
673
+ {
674
+ WriteString(theEnv,logicalName,DefmoduleName(theModule));
675
+ WriteString(theEnv,logicalName,":\n");
676
+ }
677
+
678
+ SetCurrentModule(theEnv,theModule);
679
+ constructPtr = (*nextFunction)(theEnv,NULL);
680
+ while (constructPtr != NULL)
681
+ {
682
+ if (EvaluationData(theEnv)->HaltExecution == true) return;
683
+
684
+ if (doItFunction == NULL) doIt = true;
685
+ else doIt = (*doItFunction)(constructPtr);
686
+
687
+ if (! doIt) {}
688
+ else if (nameFunction != NULL)
689
+ {
690
+ constructName = (*nameFunction)(constructPtr);
691
+ if (constructName != NULL)
692
+ {
693
+ if (allModules) WriteString(theEnv,logicalName," ");
694
+ WriteString(theEnv,logicalName,constructName);
695
+ WriteString(theEnv,logicalName,"\n");
696
+ }
697
+ }
698
+ else if (printFunction != NULL)
699
+ {
700
+ if (allModules) WriteString(theEnv,logicalName," ");
701
+ (*printFunction)(theEnv,logicalName,constructPtr);
702
+ WriteString(theEnv,logicalName,"\n");
703
+ }
704
+
705
+ constructPtr = (*nextFunction)(theEnv,constructPtr);
706
+ count++;
707
+ }
708
+
709
+ if (allModules) theModule = GetNextDefmodule(theEnv,theModule);
710
+ else theModule = NULL;
711
+ }
712
+
713
+ /*=================================================*/
714
+ /* Print the tally and restore the current module. */
715
+ /*=================================================*/
716
+
717
+ if (singleName != NULL) PrintTally(theEnv,logicalName,count,singleName,pluralName);
718
+
719
+ RestoreCurrentModule(theEnv);
720
+ }
721
+
722
+ /********************************************************/
723
+ /* DoForAllModules: Executes an action for all modules. */
724
+ /********************************************************/
725
+ long DoForAllModules(
726
+ Environment *theEnv,
727
+ void (*actionFunction)(Defmodule *,void *),
728
+ int interruptable,
729
+ void *userBuffer)
730
+ {
731
+ Defmodule *theModule;
732
+ long moduleCount = 0L;
733
+
734
+ /*==========================*/
735
+ /* Save the current module. */
736
+ /*==========================*/
737
+
738
+ SaveCurrentModule(theEnv);
739
+
740
+ /*==================================*/
741
+ /* Loop through all of the modules. */
742
+ /*==================================*/
743
+
744
+ for (theModule = GetNextDefmodule(theEnv,NULL);
745
+ theModule != NULL;
746
+ theModule = GetNextDefmodule(theEnv,theModule), moduleCount++)
747
+ {
748
+ SetCurrentModule(theEnv,theModule);
749
+
750
+ if ((interruptable) && GetHaltExecution(theEnv))
751
+ {
752
+ RestoreCurrentModule(theEnv);
753
+ return(-1L);
754
+ }
755
+
756
+ (*actionFunction)(theModule,userBuffer);
757
+ }
758
+
759
+ /*=============================*/
760
+ /* Restore the current module. */
761
+ /*=============================*/
762
+
763
+ RestoreCurrentModule(theEnv);
764
+
765
+ /*=========================================*/
766
+ /* Return the number of modules traversed. */
767
+ /*=========================================*/
768
+
769
+ return(moduleCount);
770
+ }
771
+
772
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
773
+
774
+ /****************************************/
775
+ /* RemoveConstructFromModule: Removes a */
776
+ /* construct from its module's list */
777
+ /****************************************/
778
+ void RemoveConstructFromModule(
779
+ Environment *theEnv,
780
+ ConstructHeader *theConstruct)
781
+ {
782
+ ConstructHeader *lastConstruct,*currentConstruct;
783
+
784
+ /*==============================*/
785
+ /* Find the specified construct */
786
+ /* in the module's list. */
787
+ /*==============================*/
788
+
789
+ lastConstruct = NULL;
790
+ currentConstruct = theConstruct->whichModule->firstItem;
791
+ while (currentConstruct != theConstruct)
792
+ {
793
+ lastConstruct = currentConstruct;
794
+ currentConstruct = currentConstruct->next;
795
+ }
796
+
797
+ /*========================================*/
798
+ /* If it wasn't there, something's wrong. */
799
+ /*========================================*/
800
+
801
+ if (currentConstruct == NULL)
802
+ {
803
+ SystemError(theEnv,"CSTRCPSR",1);
804
+ ExitRouter(theEnv,EXIT_FAILURE);
805
+ }
806
+
807
+ /*==========================*/
808
+ /* Remove it from the list. */
809
+ /*==========================*/
810
+
811
+ if (lastConstruct == NULL)
812
+ { theConstruct->whichModule->firstItem = theConstruct->next; }
813
+ else
814
+ { lastConstruct->next = theConstruct->next; }
815
+
816
+ /*=================================================*/
817
+ /* Update the pointer to the last item in the list */
818
+ /* if the construct just deleted was at the end. */
819
+ /*=================================================*/
820
+
821
+ if (theConstruct == theConstruct->whichModule->lastItem)
822
+ { theConstruct->whichModule->lastItem = lastConstruct; }
823
+ }
824
+
825
+ /*********************************************************/
826
+ /* GetConstructNameAndComment: Get the name and comment */
827
+ /* field of a construct. Returns name of the construct */
828
+ /* if no errors are detected, otherwise returns NULL. */
829
+ /*********************************************************/
830
+ CLIPSLexeme *GetConstructNameAndComment(
831
+ Environment *theEnv,
832
+ const char *readSource,
833
+ struct token *inputToken,
834
+ const char *constructName,
835
+ FindConstructFunction *findFunction,
836
+ DeleteConstructFunction *deleteFunction,
837
+ const char *constructSymbol,
838
+ bool fullMessageCR,
839
+ bool getComment,
840
+ bool moduleNameAllowed,
841
+ bool ignoreRedefinition)
842
+ {
843
+ #if (MAC_XCD) && (! DEBUGGING_FUNCTIONS)
844
+ #pragma unused(fullMessageCR)
845
+ #endif
846
+ CLIPSLexeme *name, *moduleName;
847
+ bool redefining = false;
848
+ ConstructHeader *theConstruct;
849
+ unsigned separatorPosition;
850
+ Defmodule *theModule;
851
+
852
+ /*==========================*/
853
+ /* Next token should be the */
854
+ /* name of the construct. */
855
+ /*==========================*/
856
+
857
+ GetToken(theEnv,readSource,inputToken);
858
+ if (inputToken->tknType != SYMBOL_TOKEN)
859
+ {
860
+ PrintErrorID(theEnv,"CSTRCPSR",2,true);
861
+ WriteString(theEnv,STDERR,"Missing name for ");
862
+ WriteString(theEnv,STDERR,constructName);
863
+ WriteString(theEnv,STDERR," construct.\n");
864
+ return NULL;
865
+ }
866
+
867
+ name = inputToken->lexemeValue;
868
+
869
+ /*===============================*/
870
+ /* Determine the current module. */
871
+ /*===============================*/
872
+
873
+ separatorPosition = FindModuleSeparator(name->contents);
874
+ if (separatorPosition)
875
+ {
876
+ if (moduleNameAllowed == false)
877
+ {
878
+ SyntaxErrorMessage(theEnv,"module specifier");
879
+ return NULL;
880
+ }
881
+
882
+ moduleName = ExtractModuleName(theEnv,separatorPosition,name->contents);
883
+ if (moduleName == NULL)
884
+ {
885
+ SyntaxErrorMessage(theEnv,"construct name");
886
+ return NULL;
887
+ }
888
+
889
+ theModule = FindDefmodule(theEnv,moduleName->contents);
890
+ if (theModule == NULL)
891
+ {
892
+ CantFindItemErrorMessage(theEnv,"defmodule",moduleName->contents,true);
893
+ return NULL;
894
+ }
895
+
896
+ SetCurrentModule(theEnv,theModule);
897
+ name = ExtractConstructName(theEnv,separatorPosition,name->contents,SYMBOL_TYPE);
898
+ if (name == NULL)
899
+ {
900
+ SyntaxErrorMessage(theEnv,"construct name");
901
+ return NULL;
902
+ }
903
+
904
+ if (FindModuleSeparator(name->contents) != 0)
905
+ {
906
+ SyntaxErrorMessage(theEnv,"module specifier");
907
+ return NULL;
908
+ }
909
+ }
910
+
911
+ /*=====================================================*/
912
+ /* If the module was not specified, record the current */
913
+ /* module name as part of the pretty-print form. */
914
+ /*=====================================================*/
915
+
916
+ else
917
+ {
918
+ theModule = GetCurrentModule(theEnv);
919
+ if (moduleNameAllowed)
920
+ {
921
+ PPBackup(theEnv);
922
+ SavePPBuffer(theEnv,DefmoduleName(theModule));
923
+ SavePPBuffer(theEnv,"::");
924
+ SavePPBuffer(theEnv,name->contents);
925
+ }
926
+ }
927
+
928
+ /*==================================================================*/
929
+ /* Check for import/export conflicts from the construct definition. */
930
+ /*==================================================================*/
931
+
932
+ #if DEFMODULE_CONSTRUCT
933
+ if (FindImportExportConflict(theEnv,constructName,theModule,name->contents))
934
+ {
935
+ ImportExportConflictMessage(theEnv,constructName,name->contents,NULL,NULL);
936
+ return NULL;
937
+ }
938
+ #endif
939
+
940
+ /*========================================================*/
941
+ /* Remove the construct if it is already in the knowledge */
942
+ /* base and we're not just checking syntax. */
943
+ /*========================================================*/
944
+
945
+ if ((findFunction != NULL) && (! ConstructData(theEnv)->CheckSyntaxMode))
946
+ {
947
+ theConstruct = (*findFunction)(theEnv,name->contents);
948
+ if (theConstruct != NULL)
949
+ {
950
+ redefining = true;
951
+ if (deleteFunction != NULL)
952
+ {
953
+ RetainLexeme(theEnv,name);
954
+ if ((*deleteFunction)(theConstruct,theEnv) == false)
955
+ {
956
+ PrintErrorID(theEnv,"CSTRCPSR",4,true);
957
+ WriteString(theEnv,STDERR,"Cannot redefine ");
958
+ WriteString(theEnv,STDERR,constructName);
959
+ WriteString(theEnv,STDERR," '");
960
+ WriteString(theEnv,STDERR,name->contents);
961
+ WriteString(theEnv,STDERR,"' while it is in use.\n");
962
+ ReleaseLexeme(theEnv,name);
963
+ return NULL;
964
+ }
965
+ ReleaseLexeme(theEnv,name);
966
+ }
967
+ }
968
+ }
969
+
970
+ /*=============================================*/
971
+ /* If compilations are being watched, indicate */
972
+ /* that a construct is being compiled. */
973
+ /*=============================================*/
974
+
975
+ #if DEBUGGING_FUNCTIONS
976
+ if ((GetWatchItem(theEnv,"compilations") == 1) &&
977
+ GetPrintWhileLoading(theEnv) && (! ConstructData(theEnv)->CheckSyntaxMode))
978
+ {
979
+ const char *outRouter = STDOUT;
980
+ if (redefining && (! ignoreRedefinition))
981
+ {
982
+ outRouter = STDWRN;
983
+ PrintWarningID(theEnv,"CSTRCPSR",1,true);
984
+ WriteString(theEnv,outRouter,"Redefining ");
985
+ }
986
+ else WriteString(theEnv,outRouter,"Defining ");
987
+
988
+ WriteString(theEnv,outRouter,constructName);
989
+ WriteString(theEnv,outRouter,": ");
990
+ WriteString(theEnv,outRouter,name->contents);
991
+
992
+ if (fullMessageCR) WriteString(theEnv,outRouter,"\n");
993
+ else WriteString(theEnv,outRouter," ");
994
+ }
995
+ else
996
+ #endif
997
+ {
998
+ if (GetPrintWhileLoading(theEnv) && (! ConstructData(theEnv)->CheckSyntaxMode))
999
+ { WriteString(theEnv,STDOUT,constructSymbol); }
1000
+ }
1001
+
1002
+ /*===============================*/
1003
+ /* Get the comment if it exists. */
1004
+ /*===============================*/
1005
+
1006
+ GetToken(theEnv,readSource,inputToken);
1007
+ if ((inputToken->tknType == STRING_TOKEN) && getComment)
1008
+ {
1009
+ PPBackup(theEnv);
1010
+ SavePPBuffer(theEnv," ");
1011
+ SavePPBuffer(theEnv,inputToken->printForm);
1012
+ GetToken(theEnv,readSource,inputToken);
1013
+ if (inputToken->tknType != RIGHT_PARENTHESIS_TOKEN)
1014
+ {
1015
+ PPBackup(theEnv);
1016
+ SavePPBuffer(theEnv,"\n ");
1017
+ SavePPBuffer(theEnv,inputToken->printForm);
1018
+ }
1019
+ }
1020
+ else if (inputToken->tknType != RIGHT_PARENTHESIS_TOKEN)
1021
+ {
1022
+ PPBackup(theEnv);
1023
+ SavePPBuffer(theEnv,"\n ");
1024
+ SavePPBuffer(theEnv,inputToken->printForm);
1025
+ }
1026
+
1027
+ /*===================================*/
1028
+ /* Return the name of the construct. */
1029
+ /*===================================*/
1030
+
1031
+ return(name);
1032
+ }
1033
+
1034
+ #endif /* (! RUN_TIME) && (! BLOAD_ONLY) */
1035
+
1036
+