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,1015 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 02/19/20 */
5
+ /* */
6
+ /* EXTERNAL FUNCTION MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Routines for adding new user or system defined */
11
+ /* functions. */
12
+ /* */
13
+ /* Principal Programmer(s): */
14
+ /* Gary D. Riley */
15
+ /* */
16
+ /* Contributing Programmer(s): */
17
+ /* Brian L. Dantes */
18
+ /* */
19
+ /* Revision History: */
20
+ /* */
21
+ /* 6.24: Corrected code to remove run-time program */
22
+ /* compiler warning. */
23
+ /* */
24
+ /* 6.30: Added support for passing context information */
25
+ /* to user defined functions. */
26
+ /* */
27
+ /* Support for long long integers. */
28
+ /* */
29
+ /* Added const qualifiers to remove C++ */
30
+ /* deprecation warnings. */
31
+ /* */
32
+ /* Converted API macros to function calls. */
33
+ /* */
34
+ /* 6.40: Changed restrictions from char * to */
35
+ /* CLIPSLexeme * to support strings */
36
+ /* originating from sources that are not */
37
+ /* statically allocated. */
38
+ /* */
39
+ /* Pragma once and other inclusion changes. */
40
+ /* */
41
+ /* Added support for booleans with <stdbool.h>. */
42
+ /* */
43
+ /* Removed use of void pointers for specific */
44
+ /* data structures. */
45
+ /* */
46
+ /* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
47
+ /* */
48
+ /* Callbacks must be environment aware. */
49
+ /* */
50
+ /* UDF redesign. */
51
+ /* */
52
+ /* Eval support for run time and bload only. */
53
+ /* */
54
+ /*************************************************************/
55
+
56
+ #include "setup.h"
57
+
58
+ #include <ctype.h>
59
+ #include <stdlib.h>
60
+
61
+ #include "argacces.h"
62
+ #include "constant.h"
63
+ #include "envrnmnt.h"
64
+ #include "exprnpsr.h"
65
+ #include "factmngr.h"
66
+ #include "memalloc.h"
67
+ #include "router.h"
68
+
69
+ #if OBJECT_SYSTEM
70
+ #include "inscom.h"
71
+ #endif
72
+
73
+ #include "extnfunc.h"
74
+
75
+ /***************************************/
76
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
77
+ /***************************************/
78
+
79
+ static void AddHashFunction(Environment *,struct functionDefinition *);
80
+ static void InitializeFunctionHashTable(Environment *);
81
+ static void DeallocateExternalFunctionData(Environment *);
82
+ #if (! RUN_TIME)
83
+ static bool RemoveHashFunction(Environment *,struct functionDefinition *);
84
+ static AddUDFError DefineFunction(Environment *,const char *,unsigned,void (*)(Environment *,UDFContext *,UDFValue *),
85
+ const char *,unsigned short,unsigned short,const char *,void *);
86
+ #endif
87
+ static void PrintType(Environment *,const char *,int,int *,const char *);
88
+ static void AssignErrorValue(UDFContext *);
89
+
90
+ /*********************************************************/
91
+ /* InitializeExternalFunctionData: Allocates environment */
92
+ /* data for external functions. */
93
+ /*********************************************************/
94
+ void InitializeExternalFunctionData(
95
+ Environment *theEnv)
96
+ {
97
+ AllocateEnvironmentData(theEnv,EXTERNAL_FUNCTION_DATA,sizeof(struct externalFunctionData),DeallocateExternalFunctionData);
98
+ }
99
+
100
+ /***********************************************************/
101
+ /* DeallocateExternalFunctionData: Deallocates environment */
102
+ /* data for external functions. */
103
+ /***********************************************************/
104
+ static void DeallocateExternalFunctionData(
105
+ Environment *theEnv)
106
+ {
107
+ struct FunctionHash *fhPtr, *nextFHPtr;
108
+ int i;
109
+
110
+ #if ! RUN_TIME
111
+ struct functionDefinition *tmpPtr, *nextPtr;
112
+
113
+ tmpPtr = ExternalFunctionData(theEnv)->ListOfFunctions;
114
+ while (tmpPtr != NULL)
115
+ {
116
+ nextPtr = tmpPtr->next;
117
+ rtn_struct(theEnv,functionDefinition,tmpPtr);
118
+ tmpPtr = nextPtr;
119
+ }
120
+ #endif
121
+
122
+ if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL)
123
+ { return; }
124
+
125
+ for (i = 0; i < SIZE_FUNCTION_HASH; i++)
126
+ {
127
+ fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[i];
128
+ while (fhPtr != NULL)
129
+ {
130
+ nextFHPtr = fhPtr->next;
131
+ rtn_struct(theEnv,FunctionHash,fhPtr);
132
+ fhPtr = nextFHPtr;
133
+ }
134
+ }
135
+
136
+ genfree(theEnv,ExternalFunctionData(theEnv)->FunctionHashtable,
137
+ sizeof (struct FunctionHash *) * SIZE_FUNCTION_HASH);
138
+ }
139
+
140
+ #if (! RUN_TIME)
141
+
142
+ /****************************************************/
143
+ /* AddUDF: Used to define a system or user external */
144
+ /* function so that the KB can access it. */
145
+ /****************************************************/
146
+ AddUDFError AddUDF(
147
+ Environment *theEnv,
148
+ const char *clipsFunctionName,
149
+ const char *returnTypes,
150
+ unsigned short minArgs,
151
+ unsigned short maxArgs,
152
+ const char *argumentTypes,
153
+ UserDefinedFunction *cFunctionPointer,
154
+ const char *cFunctionName,
155
+ void *context)
156
+ {
157
+ unsigned returnTypeBits;
158
+ size_t i;
159
+ const char *validTypeChars = "bdefilmnsyv*;";
160
+
161
+ if ((minArgs != UNBOUNDED) && (minArgs > maxArgs))
162
+ { return AUE_MIN_EXCEEDS_MAX_ERROR; }
163
+
164
+ if (argumentTypes != NULL)
165
+ {
166
+ for (i = 0; argumentTypes[i] != EOS; i++)
167
+ {
168
+ if (strchr(validTypeChars,argumentTypes[i]) == NULL)
169
+ { return AUE_INVALID_ARGUMENT_TYPE_ERROR; }
170
+ }
171
+ }
172
+
173
+ if (returnTypes != NULL)
174
+ {
175
+ for (i = 0; returnTypes[i] != EOS; i++)
176
+ {
177
+ if (strchr(validTypeChars,returnTypes[i]) == NULL)
178
+ { return AUE_INVALID_RETURN_TYPE_ERROR; }
179
+ }
180
+
181
+ PopulateRestriction(theEnv,&returnTypeBits,ANY_TYPE_BITS,returnTypes,0);
182
+ }
183
+ else
184
+ { returnTypeBits = ANY_TYPE_BITS; }
185
+
186
+ return DefineFunction(theEnv,clipsFunctionName,returnTypeBits,cFunctionPointer,
187
+ cFunctionName,minArgs,maxArgs,argumentTypes,context);
188
+ }
189
+
190
+ /*************************************************************/
191
+ /* DefineFunction: Used to define a system or user external */
192
+ /* function so that the KB can access it. Allows argument */
193
+ /* restrictions to be attached to the function. */
194
+ /*************************************************************/
195
+ static AddUDFError DefineFunction(
196
+ Environment *theEnv,
197
+ const char *name,
198
+ unsigned returnTypeBits,
199
+ void (*pointer)(Environment *,UDFContext *,UDFValue *),
200
+ const char *actualName,
201
+ unsigned short minArgs,
202
+ unsigned short maxArgs,
203
+ const char *restrictions,
204
+ void *context)
205
+ {
206
+ struct functionDefinition *newFunction;
207
+
208
+ newFunction = FindFunction(theEnv,name);
209
+ if (newFunction != NULL)
210
+ { return AUE_FUNCTION_NAME_IN_USE_ERROR; }
211
+
212
+ newFunction = get_struct(theEnv,functionDefinition);
213
+ newFunction->callFunctionName = CreateSymbol(theEnv,name);
214
+ IncrementLexemeCount(newFunction->callFunctionName);
215
+ newFunction->next = GetFunctionList(theEnv);
216
+ ExternalFunctionData(theEnv)->ListOfFunctions = newFunction;
217
+ AddHashFunction(theEnv,newFunction);
218
+
219
+ newFunction->unknownReturnValueType = returnTypeBits;
220
+ newFunction->functionPointer = pointer;
221
+ newFunction->actualFunctionName = actualName;
222
+
223
+ newFunction->minArgs = minArgs;
224
+ newFunction->maxArgs = maxArgs;
225
+
226
+ if (restrictions == NULL)
227
+ { newFunction->restrictions = NULL; }
228
+ else
229
+ {
230
+ newFunction->restrictions = CreateString(theEnv,restrictions);
231
+ IncrementLexemeCount(newFunction->restrictions);
232
+ }
233
+
234
+ newFunction->parser = NULL;
235
+ newFunction->overloadable = true;
236
+ newFunction->sequenceuseok = true;
237
+ newFunction->usrData = NULL;
238
+ newFunction->context = context;
239
+
240
+ return AUE_NO_ERROR;
241
+ }
242
+
243
+ /********************************************/
244
+ /* RemoveUDF: Used to remove a function */
245
+ /* definition from the list of functions. */
246
+ /********************************************/
247
+ bool RemoveUDF(
248
+ Environment *theEnv,
249
+ const char *functionName)
250
+ {
251
+ CLIPSLexeme *findValue;
252
+ struct functionDefinition *fPtr, *lastPtr = NULL;
253
+
254
+ findValue = FindSymbolHN(theEnv,functionName,SYMBOL_BIT);
255
+
256
+ for (fPtr = ExternalFunctionData(theEnv)->ListOfFunctions;
257
+ fPtr != NULL;
258
+ fPtr = fPtr->next)
259
+ {
260
+ if (fPtr->callFunctionName == findValue)
261
+ {
262
+ ReleaseLexeme(theEnv,fPtr->callFunctionName);
263
+ RemoveHashFunction(theEnv,fPtr);
264
+
265
+ if (lastPtr == NULL)
266
+ { ExternalFunctionData(theEnv)->ListOfFunctions = fPtr->next; }
267
+ else
268
+ { lastPtr->next = fPtr->next; }
269
+
270
+ if (fPtr->restrictions != NULL)
271
+ { ReleaseLexeme(theEnv,fPtr->restrictions); }
272
+ ClearUserDataList(theEnv,fPtr->usrData);
273
+ rtn_struct(theEnv,functionDefinition,fPtr);
274
+ return true;
275
+ }
276
+
277
+ lastPtr = fPtr;
278
+ }
279
+
280
+ return false;
281
+ }
282
+
283
+ /******************************************/
284
+ /* RemoveHashFunction: Removes a function */
285
+ /* from the function hash table. */
286
+ /******************************************/
287
+ static bool RemoveHashFunction(
288
+ Environment *theEnv,
289
+ struct functionDefinition *fdPtr)
290
+ {
291
+ struct FunctionHash *fhPtr, *lastPtr = NULL;
292
+ size_t hashValue;
293
+
294
+ hashValue = HashSymbol(fdPtr->callFunctionName->contents,SIZE_FUNCTION_HASH);
295
+
296
+ for (fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue];
297
+ fhPtr != NULL;
298
+ fhPtr = fhPtr->next)
299
+ {
300
+ if (fhPtr->fdPtr == fdPtr)
301
+ {
302
+ if (lastPtr == NULL)
303
+ { ExternalFunctionData(theEnv)->FunctionHashtable[hashValue] = fhPtr->next; }
304
+ else
305
+ { lastPtr->next = fhPtr->next; }
306
+
307
+ rtn_struct(theEnv,FunctionHash,fhPtr);
308
+ return true;
309
+ }
310
+
311
+ lastPtr = fhPtr;
312
+ }
313
+
314
+ return false;
315
+ }
316
+
317
+ #endif
318
+
319
+ /***************************************************************************/
320
+ /* AddFunctionParser: Associates a specialized expression parsing function */
321
+ /* with the function entry for a function which was defined using */
322
+ /* DefineFunction. When this function is parsed, the specialized parsing */
323
+ /* function will be called to parse the arguments of the function. Only */
324
+ /* user and system defined functions can have specialized parsing */
325
+ /* routines. Generic functions and deffunctions can not have specialized */
326
+ /* parsing routines. */
327
+ /***************************************************************************/
328
+ bool AddFunctionParser(
329
+ Environment *theEnv,
330
+ const char *functionName,
331
+ struct expr *(*fpPtr)(Environment *,struct expr *,const char *))
332
+ {
333
+ struct functionDefinition *fdPtr;
334
+
335
+ fdPtr = FindFunction(theEnv,functionName);
336
+ if (fdPtr == NULL)
337
+ {
338
+ WriteString(theEnv,STDERR,"Function parsers can only be added for existing functions.\n");
339
+ return false;
340
+ }
341
+
342
+ fdPtr->parser = fpPtr;
343
+ fdPtr->overloadable = false;
344
+
345
+ return true;
346
+ }
347
+
348
+ #if (! RUN_TIME)
349
+
350
+ /*********************************************************************/
351
+ /* RemoveFunctionParser: Removes a specialized expression parsing */
352
+ /* function (if it exists) from the function entry for a function. */
353
+ /*********************************************************************/
354
+ bool RemoveFunctionParser(
355
+ Environment *theEnv,
356
+ const char *functionName)
357
+ {
358
+ struct functionDefinition *fdPtr;
359
+
360
+ fdPtr = FindFunction(theEnv,functionName);
361
+ if (fdPtr == NULL)
362
+ {
363
+ WriteString(theEnv,STDERR,"Function parsers can only be removed from existing functions.\n");
364
+ return false;
365
+ }
366
+
367
+ fdPtr->parser = NULL;
368
+
369
+ return true;
370
+ }
371
+
372
+ /*****************************************************************/
373
+ /* FuncSeqOvlFlags: Makes a system function overloadable or not, */
374
+ /* i.e. can the function be a method for a generic function. */
375
+ /*****************************************************************/
376
+ bool FuncSeqOvlFlags(
377
+ Environment *theEnv,
378
+ const char *functionName,
379
+ bool seqp,
380
+ bool ovlp)
381
+ {
382
+ struct functionDefinition *fdPtr;
383
+
384
+ fdPtr = FindFunction(theEnv,functionName);
385
+ if (fdPtr == NULL)
386
+ {
387
+ WriteString(theEnv,STDERR,"Only existing functions can be marked as using sequence expansion arguments/overloadable or not.\n");
388
+ return false;
389
+ }
390
+
391
+ fdPtr->sequenceuseok = (seqp ? true : false);
392
+ fdPtr->overloadable = (ovlp ? true : false);
393
+
394
+ return true;
395
+ }
396
+
397
+ #endif
398
+
399
+ /***********************************************/
400
+ /* GetNthRestriction: Returns the restriction */
401
+ /* type for the nth parameter of a function. */
402
+ /***********************************************/
403
+ unsigned GetNthRestriction(
404
+ Environment *theEnv,
405
+ struct functionDefinition *theFunction,
406
+ unsigned int position)
407
+ {
408
+ unsigned rv, df;
409
+ const char *restrictions;
410
+
411
+ if (theFunction == NULL) return(ANY_TYPE_BITS);
412
+
413
+ if (theFunction->restrictions == NULL) return(ANY_TYPE_BITS);
414
+ restrictions = theFunction->restrictions->contents;
415
+
416
+ PopulateRestriction(theEnv,&df,ANY_TYPE_BITS,restrictions,0);
417
+ PopulateRestriction(theEnv,&rv,df,restrictions,position);
418
+
419
+ return rv;
420
+ }
421
+
422
+ /*************************************************/
423
+ /* GetFunctionList: Returns the ListOfFunctions. */
424
+ /*************************************************/
425
+ struct functionDefinition *GetFunctionList(
426
+ Environment *theEnv)
427
+ {
428
+ return(ExternalFunctionData(theEnv)->ListOfFunctions);
429
+ }
430
+
431
+ /**************************************************************/
432
+ /* InstallFunctionList: Sets the ListOfFunctions and adds all */
433
+ /* the function entries to the FunctionHashTable. */
434
+ /**************************************************************/
435
+ void InstallFunctionList(
436
+ Environment *theEnv,
437
+ struct functionDefinition *value)
438
+ {
439
+ int i;
440
+ struct FunctionHash *fhPtr, *nextPtr;
441
+
442
+ if (ExternalFunctionData(theEnv)->FunctionHashtable != NULL)
443
+ {
444
+ for (i = 0; i < SIZE_FUNCTION_HASH; i++)
445
+ {
446
+ fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[i];
447
+ while (fhPtr != NULL)
448
+ {
449
+ nextPtr = fhPtr->next;
450
+ rtn_struct(theEnv,FunctionHash,fhPtr);
451
+ fhPtr = nextPtr;
452
+ }
453
+ ExternalFunctionData(theEnv)->FunctionHashtable[i] = NULL;
454
+ }
455
+ }
456
+
457
+ ExternalFunctionData(theEnv)->ListOfFunctions = value;
458
+
459
+ while (value != NULL)
460
+ {
461
+ AddHashFunction(theEnv,value);
462
+ value = value->next;
463
+ }
464
+ }
465
+
466
+ /********************************************************/
467
+ /* FindFunction: Returns a pointer to the corresponding */
468
+ /* functionDefinition structure if a function name is */
469
+ /* in the function list, otherwise returns NULL. */
470
+ /********************************************************/
471
+ struct functionDefinition *FindFunction(
472
+ Environment *theEnv,
473
+ const char *functionName)
474
+ {
475
+ struct FunctionHash *fhPtr;
476
+ size_t hashValue;
477
+ CLIPSLexeme *findValue;
478
+
479
+ if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) return NULL;
480
+
481
+ hashValue = HashSymbol(functionName,SIZE_FUNCTION_HASH);
482
+
483
+ findValue = FindSymbolHN(theEnv,functionName,SYMBOL_BIT);
484
+
485
+ for (fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue];
486
+ fhPtr != NULL;
487
+ fhPtr = fhPtr->next)
488
+ {
489
+ if (fhPtr->fdPtr->callFunctionName == findValue)
490
+ { return(fhPtr->fdPtr); }
491
+ }
492
+
493
+ return NULL;
494
+ }
495
+
496
+ /********************************************************/
497
+ /* GetUDFContext: Returns the context associated a UDF. */
498
+ /********************************************************/
499
+ void *GetUDFContext(
500
+ Environment *theEnv,
501
+ const char *functionName)
502
+ {
503
+ struct FunctionHash *fhPtr;
504
+ size_t hashValue;
505
+ CLIPSLexeme *findValue;
506
+
507
+ if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) return NULL;
508
+
509
+ hashValue = HashSymbol(functionName,SIZE_FUNCTION_HASH);
510
+
511
+ findValue = FindSymbolHN(theEnv,functionName,SYMBOL_BIT);
512
+
513
+ for (fhPtr = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue];
514
+ fhPtr != NULL;
515
+ fhPtr = fhPtr->next)
516
+ {
517
+ if (fhPtr->fdPtr->callFunctionName == findValue)
518
+ { return fhPtr->fdPtr->context; }
519
+ }
520
+
521
+ return NULL;
522
+ }
523
+
524
+ /*********************************************************/
525
+ /* InitializeFunctionHashTable: Purpose is to initialize */
526
+ /* the function hash table to NULL. */
527
+ /*********************************************************/
528
+ static void InitializeFunctionHashTable(
529
+ Environment *theEnv)
530
+ {
531
+ int i;
532
+
533
+ ExternalFunctionData(theEnv)->FunctionHashtable = (struct FunctionHash **)
534
+ gm2(theEnv,sizeof (struct FunctionHash *) *
535
+ SIZE_FUNCTION_HASH);
536
+
537
+ for (i = 0; i < SIZE_FUNCTION_HASH; i++) ExternalFunctionData(theEnv)->FunctionHashtable[i] = NULL;
538
+ }
539
+
540
+ /****************************************************************/
541
+ /* AddHashFunction: Adds a function to the function hash table. */
542
+ /****************************************************************/
543
+ static void AddHashFunction(
544
+ Environment *theEnv,
545
+ struct functionDefinition *fdPtr)
546
+ {
547
+ struct FunctionHash *newhash, *temp;
548
+ size_t hashValue;
549
+
550
+ if (ExternalFunctionData(theEnv)->FunctionHashtable == NULL) InitializeFunctionHashTable(theEnv);
551
+
552
+ newhash = get_struct(theEnv,FunctionHash);
553
+ newhash->fdPtr = fdPtr;
554
+
555
+ hashValue = HashSymbol(fdPtr->callFunctionName->contents,SIZE_FUNCTION_HASH);
556
+
557
+ temp = ExternalFunctionData(theEnv)->FunctionHashtable[hashValue];
558
+ ExternalFunctionData(theEnv)->FunctionHashtable[hashValue] = newhash;
559
+ newhash->next = temp;
560
+ }
561
+
562
+ /*************************************************/
563
+ /* GetMinimumArgs: Returns the minimum number of */
564
+ /* arguments expected by an external function. */
565
+ /*************************************************/
566
+ int GetMinimumArgs(
567
+ struct functionDefinition *theFunction)
568
+ {
569
+ return theFunction->minArgs;
570
+ }
571
+
572
+ /*************************************************/
573
+ /* GetMaximumArgs: Returns the maximum number of */
574
+ /* arguments expected by an external function. */
575
+ /*************************************************/
576
+ int GetMaximumArgs(
577
+ struct functionDefinition *theFunction)
578
+ {
579
+ return theFunction->maxArgs;
580
+ }
581
+
582
+ /********************/
583
+ /* AssignErrorValue */
584
+ /********************/
585
+ void AssignErrorValue(
586
+ UDFContext *context)
587
+ {
588
+ if (context->theFunction->unknownReturnValueType & BOOLEAN_BIT)
589
+ { context->returnValue->lexemeValue = context->environment->FalseSymbol; }
590
+ else if (context->theFunction->unknownReturnValueType & STRING_BIT)
591
+ { context->returnValue->lexemeValue = CreateString(context->environment,""); }
592
+ else if (context->theFunction->unknownReturnValueType & SYMBOL_BIT)
593
+ { context->returnValue->lexemeValue = CreateSymbol(context->environment,"nil"); }
594
+ else if (context->theFunction->unknownReturnValueType & INTEGER_BIT)
595
+ { context->returnValue->integerValue = CreateInteger(context->environment,0); }
596
+ else if (context->theFunction->unknownReturnValueType & FLOAT_BIT)
597
+ { context->returnValue->floatValue = CreateFloat(context->environment,0.0); }
598
+ else if (context->theFunction->unknownReturnValueType & MULTIFIELD_BIT)
599
+ { SetMultifieldErrorValue(context->environment,context->returnValue); }
600
+ else if (context->theFunction->unknownReturnValueType & INSTANCE_NAME_BIT)
601
+ { context->returnValue->lexemeValue = CreateInstanceName(context->environment,"nil"); }
602
+ else if (context->theFunction->unknownReturnValueType & FACT_ADDRESS_BIT)
603
+ { context->returnValue->factValue = &FactData(context->environment)->DummyFact; }
604
+ #if OBJECT_SYSTEM
605
+ else if (context->theFunction->unknownReturnValueType & INSTANCE_ADDRESS_BIT)
606
+ { context->returnValue->value = &InstanceData(context->environment)->DummyInstance; }
607
+ #endif
608
+ else if (context->theFunction->unknownReturnValueType & EXTERNAL_ADDRESS_BIT)
609
+ { context->returnValue->value = CreateExternalAddress(context->environment,NULL,0); }
610
+ else
611
+ { context->returnValue->value = context->environment->VoidConstant; }
612
+ }
613
+
614
+ /*********************/
615
+ /* UDFArgumentCount: */
616
+ /*********************/
617
+ unsigned int UDFArgumentCount(
618
+ UDFContext *context)
619
+ {
620
+ unsigned int count = 0;
621
+ struct expr *argPtr;
622
+
623
+ for (argPtr = EvaluationData(context->environment)->CurrentExpression->argList;
624
+ argPtr != NULL;
625
+ argPtr = argPtr->nextArg)
626
+ { count++; }
627
+
628
+ return count;
629
+ }
630
+
631
+ /*********************/
632
+ /* UDFFirstArgument: */
633
+ /*********************/
634
+ bool UDFFirstArgument(
635
+ UDFContext *context,
636
+ unsigned expectedType,
637
+ UDFValue *returnValue)
638
+ {
639
+ context->lastArg = EvaluationData(context->environment)->CurrentExpression->argList;
640
+ context->lastPosition = 1;
641
+ return UDFNextArgument(context,expectedType,returnValue);
642
+ }
643
+
644
+ /********************/
645
+ /* UDFNextArgument: */
646
+ /********************/
647
+ bool UDFNextArgument(
648
+ UDFContext *context,
649
+ unsigned expectedType,
650
+ UDFValue *returnValue)
651
+ {
652
+ struct expr *argPtr = context->lastArg;
653
+ unsigned int argumentPosition = context->lastPosition;
654
+ Environment *theEnv = context->environment;
655
+
656
+ if (argPtr == NULL)
657
+ {
658
+ SetHaltExecution(theEnv,true);
659
+ SetEvaluationError(theEnv,true);
660
+ return false;
661
+ }
662
+
663
+ context->lastPosition++;
664
+ context->lastArg = context->lastArg->nextArg;
665
+
666
+ switch (argPtr->type)
667
+ {
668
+ case INTEGER_TYPE:
669
+ returnValue->value = argPtr->value;
670
+ if (expectedType & INTEGER_BIT) return true;
671
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
672
+ PrintTypesString(theEnv,STDERR,expectedType,true);
673
+ SetHaltExecution(theEnv,true);
674
+ SetEvaluationError(theEnv,true);
675
+ AssignErrorValue(context);
676
+ return false;
677
+ break;
678
+
679
+ case FLOAT_TYPE:
680
+ returnValue->value = argPtr->value;
681
+ if (expectedType & FLOAT_BIT) return true;
682
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
683
+ PrintTypesString(theEnv,STDERR,expectedType,true);
684
+ SetHaltExecution(theEnv,true);
685
+ SetEvaluationError(theEnv,true);
686
+ AssignErrorValue(context);
687
+ return false;
688
+ break;
689
+
690
+ case SYMBOL_TYPE:
691
+ returnValue->value = argPtr->value;
692
+ if (expectedType & SYMBOL_BIT) return true;
693
+ if (expectedType & BOOLEAN_BIT)
694
+ {
695
+ if ((returnValue->lexemeValue == FalseSymbol(theEnv)) ||
696
+ (returnValue->lexemeValue == TrueSymbol(theEnv)))
697
+ { return true; }
698
+ }
699
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
700
+ PrintTypesString(theEnv,STDERR,expectedType,true);
701
+ SetHaltExecution(theEnv,true);
702
+ SetEvaluationError(theEnv,true);
703
+ AssignErrorValue(context);
704
+ return false;
705
+ break;
706
+
707
+ case STRING_TYPE:
708
+ returnValue->value = argPtr->value;
709
+ if (expectedType & STRING_BIT) return true;
710
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
711
+ PrintTypesString(theEnv,STDERR,expectedType,true);
712
+ SetHaltExecution(theEnv,true);
713
+ SetEvaluationError(theEnv,true);
714
+ AssignErrorValue(context);
715
+ return false;
716
+ break;
717
+
718
+ case INSTANCE_NAME_TYPE:
719
+ returnValue->value = argPtr->value;
720
+ if (expectedType & INSTANCE_NAME_BIT) return true;
721
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
722
+ PrintTypesString(theEnv,STDERR,expectedType,true);
723
+ SetHaltExecution(theEnv,true);
724
+ SetEvaluationError(theEnv,true);
725
+ AssignErrorValue(context);
726
+ return false;
727
+ break;
728
+ }
729
+
730
+ EvaluateExpression(theEnv,argPtr,returnValue);
731
+
732
+ switch (returnValue->header->type)
733
+ {
734
+ case VOID_TYPE:
735
+ if (expectedType & VOID_BIT)
736
+ {
737
+ if (EvaluationData(theEnv)->EvaluationError)
738
+ {
739
+ AssignErrorValue(context);
740
+ return false;
741
+ }
742
+ else return true;
743
+ }
744
+ break;
745
+
746
+ case INTEGER_TYPE:
747
+ if (expectedType & INTEGER_BIT)
748
+ {
749
+ if (EvaluationData(theEnv)->EvaluationError)
750
+ {
751
+ AssignErrorValue(context);
752
+ return false;
753
+ }
754
+ else return true;
755
+ }
756
+ break;
757
+
758
+ case FLOAT_TYPE:
759
+ if (expectedType & FLOAT_BIT)
760
+ {
761
+ if (EvaluationData(theEnv)->EvaluationError)
762
+ {
763
+ AssignErrorValue(context);
764
+ return false;
765
+ }
766
+ else return true;
767
+ }
768
+ break;
769
+
770
+ case SYMBOL_TYPE:
771
+ if (expectedType & SYMBOL_BIT)
772
+ {
773
+ if (EvaluationData(theEnv)->EvaluationError)
774
+ {
775
+ AssignErrorValue(context);
776
+ return false;
777
+ }
778
+ else return true;
779
+ }
780
+
781
+ if (expectedType & BOOLEAN_BIT)
782
+ {
783
+ if (EvaluationData(theEnv)->EvaluationError)
784
+ {
785
+ AssignErrorValue(context);
786
+ return false;
787
+ }
788
+ else if ((returnValue->lexemeValue == FalseSymbol(theEnv)) ||
789
+ (returnValue->lexemeValue == TrueSymbol(theEnv)))
790
+ { return true; }
791
+ }
792
+
793
+ break;
794
+
795
+ case STRING_TYPE:
796
+ if (expectedType & STRING_BIT)
797
+ {
798
+ if (EvaluationData(theEnv)->EvaluationError)
799
+ {
800
+ AssignErrorValue(context);
801
+ return false;
802
+ }
803
+ else return true;
804
+ }
805
+ break;
806
+
807
+ case INSTANCE_NAME_TYPE:
808
+ if (expectedType & INSTANCE_NAME_BIT)
809
+ {
810
+ if (EvaluationData(theEnv)->EvaluationError)
811
+ {
812
+ AssignErrorValue(context);
813
+ return false;
814
+ }
815
+ else return true;
816
+ }
817
+ break;
818
+
819
+ case EXTERNAL_ADDRESS_TYPE:
820
+ if (expectedType & EXTERNAL_ADDRESS_BIT)
821
+ {
822
+ if (EvaluationData(theEnv)->EvaluationError)
823
+ {
824
+ AssignErrorValue(context);
825
+ return false;
826
+ }
827
+ else return true;
828
+ }
829
+ break;
830
+
831
+ case FACT_ADDRESS_TYPE:
832
+ if (expectedType & FACT_ADDRESS_BIT)
833
+ {
834
+ if (EvaluationData(theEnv)->EvaluationError)
835
+ {
836
+ AssignErrorValue(context);
837
+ return false;
838
+ }
839
+ else return true;
840
+ }
841
+ break;
842
+
843
+ case INSTANCE_ADDRESS_TYPE:
844
+ if (expectedType & INSTANCE_ADDRESS_BIT)
845
+ {
846
+ if (EvaluationData(theEnv)->EvaluationError)
847
+ {
848
+ AssignErrorValue(context);
849
+ return false;
850
+ }
851
+ else return true;
852
+ }
853
+ break;
854
+
855
+ case MULTIFIELD_TYPE:
856
+ if (expectedType & MULTIFIELD_BIT)
857
+ {
858
+ if (EvaluationData(theEnv)->EvaluationError)
859
+ {
860
+ AssignErrorValue(context);
861
+ return false;
862
+ }
863
+ else return true;
864
+ }
865
+ break;
866
+ }
867
+
868
+ ExpectedTypeError0(theEnv,UDFContextFunctionName(context),argumentPosition);
869
+ PrintTypesString(theEnv,STDERR,expectedType,true);
870
+
871
+ SetHaltExecution(theEnv,true);
872
+ SetEvaluationError(theEnv,true);
873
+ AssignErrorValue(context);
874
+
875
+ return false;
876
+ }
877
+
878
+ /*******************/
879
+ /* UDFNthArgument: */
880
+ /*******************/
881
+ bool UDFNthArgument(
882
+ UDFContext *context,
883
+ unsigned int argumentPosition,
884
+ unsigned expectedType,
885
+ UDFValue *returnValue)
886
+ {
887
+ if (argumentPosition < context->lastPosition)
888
+ {
889
+ context->lastArg = EvaluationData(context->environment)->CurrentExpression->argList;
890
+ context->lastPosition = 1;
891
+ }
892
+
893
+ for ( ; (context->lastArg != NULL) && (context->lastPosition < argumentPosition) ;
894
+ context->lastArg = context->lastArg->nextArg)
895
+ { context->lastPosition++; }
896
+
897
+ return UDFNextArgument(context,expectedType,returnValue);
898
+ }
899
+
900
+ /******************************/
901
+ /* UDFInvalidArgumentMessage: */
902
+ /******************************/
903
+ void UDFInvalidArgumentMessage(
904
+ UDFContext *context,
905
+ const char *typeString)
906
+ {
907
+ ExpectedTypeError1(context->environment,
908
+ UDFContextFunctionName(context),
909
+ context->lastPosition-1,typeString);
910
+ }
911
+
912
+ /******************/
913
+ /* UDFThrowError: */
914
+ /******************/
915
+ void UDFThrowError(
916
+ UDFContext *context)
917
+ {
918
+ Environment *theEnv = context->environment;
919
+
920
+ SetHaltExecution(theEnv,true);
921
+ SetEvaluationError(theEnv,true);
922
+ }
923
+
924
+ /***************************/
925
+ /* UDFContextFunctionName: */
926
+ /***************************/
927
+ const char *UDFContextFunctionName(
928
+ UDFContext *context)
929
+ {
930
+ return context->theFunction->callFunctionName->contents;
931
+ }
932
+
933
+ /**************/
934
+ /* PrintType: */
935
+ /**************/
936
+ static void PrintType(
937
+ Environment *theEnv,
938
+ const char *logicalName,
939
+ int typeCount,
940
+ int *typesPrinted,
941
+ const char *typeName)
942
+ {
943
+ if (*typesPrinted == 0)
944
+ {
945
+ WriteString(theEnv,logicalName,typeName);
946
+ (*typesPrinted)++;
947
+ return;
948
+ }
949
+
950
+ if (typeCount == 2)
951
+ { WriteString(theEnv,logicalName," or "); }
952
+ else if (((*typesPrinted) + 1) == typeCount)
953
+ { WriteString(theEnv,logicalName,", or "); }
954
+ else
955
+ { WriteString(theEnv,logicalName,", "); }
956
+
957
+ WriteString(theEnv,logicalName,typeName);
958
+ (*typesPrinted)++;
959
+ }
960
+
961
+ /********************/
962
+ /* PrintTypesString */
963
+ /********************/
964
+ void PrintTypesString(
965
+ Environment *theEnv,
966
+ const char *logicalName,
967
+ unsigned expectedType,
968
+ bool printCRLF)
969
+ {
970
+ int typeCount, typesPrinted;
971
+
972
+ typeCount = 0;
973
+ if (expectedType & INTEGER_BIT) typeCount++;
974
+ if (expectedType & FLOAT_BIT) typeCount++;
975
+ if (expectedType & (SYMBOL_BIT | BOOLEAN_BIT)) typeCount++;
976
+ if (expectedType & STRING_BIT) typeCount++;
977
+ if (expectedType & INSTANCE_NAME_BIT) typeCount++;
978
+ if (expectedType & INSTANCE_ADDRESS_BIT) typeCount++;
979
+ if (expectedType & FACT_ADDRESS_BIT) typeCount++;
980
+ if (expectedType & EXTERNAL_ADDRESS_BIT) typeCount++;
981
+ if (expectedType & MULTIFIELD_BIT) typeCount++;
982
+
983
+ typesPrinted = 0;
984
+ if (expectedType & INTEGER_BIT)
985
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"integer"); }
986
+
987
+ if (expectedType & FLOAT_BIT)
988
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"float"); }
989
+
990
+ if (expectedType & SYMBOL_BIT)
991
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"symbol"); }
992
+ else if (expectedType & BOOLEAN_BIT)
993
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"boolean"); }
994
+
995
+ if (expectedType & STRING_BIT)
996
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"string"); }
997
+
998
+ if (expectedType & INSTANCE_NAME_BIT)
999
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"instance name"); }
1000
+
1001
+ if (expectedType & INSTANCE_ADDRESS_BIT)
1002
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"instance address"); }
1003
+
1004
+ if (expectedType & FACT_ADDRESS_BIT)
1005
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"fact address"); }
1006
+
1007
+ if (expectedType & EXTERNAL_ADDRESS_BIT)
1008
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"external address"); }
1009
+
1010
+ if (expectedType & MULTIFIELD_BIT)
1011
+ { PrintType(theEnv,logicalName,typeCount,&typesPrinted,"multifield"); }
1012
+
1013
+ if (printCRLF)
1014
+ { WriteString(theEnv,logicalName,".\n"); }
1015
+ }