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,1801 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.41 12/04/22 */
5
+ /* */
6
+ /* MISCELLANEOUS FUNCTIONS MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: */
11
+ /* */
12
+ /* Principal Programmer(s): */
13
+ /* Gary D. Riley */
14
+ /* */
15
+ /* Contributing Programmer(s): */
16
+ /* Brian L. Dantes */
17
+ /* */
18
+ /* Revision History: */
19
+ /* */
20
+ /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
21
+ /* */
22
+ /* Corrected compilation errors for files */
23
+ /* generated by constructs-to-c. DR0861 */
24
+ /* */
25
+ /* Changed name of variable exp to theExp */
26
+ /* because of Unix compiler warnings of shadowed */
27
+ /* definitions. */
28
+ /* */
29
+ /* 6.24: Removed CONFLICT_RESOLUTION_STRATEGIES, */
30
+ /* DYNAMIC_SALIENCE, INCREMENTAL_RESET, */
31
+ /* LOGICAL_DEPENDENCIES, IMPERATIVE_METHODS */
32
+ /* INSTANCE_PATTERN_MATCHING, */
33
+ /* IMPERATIVE_MESSAGE_HANDLERS, and */
34
+ /* AUXILIARY_MESSAGE_HANDLERS compilation flags. */
35
+ /* */
36
+ /* Renamed BOOLEAN macro type to intBool. */
37
+ /* */
38
+ /* 6.30: Support for long long integers. */
39
+ /* */
40
+ /* Used gensprintf instead of sprintf. */
41
+ /* */
42
+ /* Removed conditional code for unsupported */
43
+ /* compilers/operating systems. */
44
+ /* */
45
+ /* Renamed EX_MATH compiler flag to */
46
+ /* EXTENDED_MATH_FUNCTIONS. */
47
+ /* */
48
+ /* Combined BASIC_IO and EXT_IO compilation */
49
+ /* flags into the IO_FUNCTIONS compilation flag. */
50
+ /* */
51
+ /* Removed code associated with HELP_FUNCTIONS */
52
+ /* and EMACS_EDITOR compiler flags. */
53
+ /* */
54
+ /* Added operating-system function. */
55
+ /* */
56
+ /* Added new function (for future use). */
57
+ /* */
58
+ /* Added const qualifiers to remove C++ */
59
+ /* deprecation warnings. */
60
+ /* */
61
+ /* Removed deallocating message parameter from */
62
+ /* EnvReleaseMem. */
63
+ /* */
64
+ /* Removed support for BLOCK_MEMORY. */
65
+ /* */
66
+ /* 6.31: Added local-time and gm-time functions. */
67
+ /* */
68
+ /* 6.40: Changed restrictions from char * to */
69
+ /* CLIPSLexeme * to support strings */
70
+ /* originating from sources that are not */
71
+ /* statically allocated. */
72
+ /* */
73
+ /* Added Env prefix to GetEvaluationError and */
74
+ /* SetEvaluationError functions. */
75
+ /* */
76
+ /* Added Env prefix to GetHaltExecution and */
77
+ /* SetHaltExecution functions. */
78
+ /* */
79
+ /* Refactored code to reduce header dependencies */
80
+ /* in sysdep.c. */
81
+ /* */
82
+ /* Pragma once and other inclusion changes. */
83
+ /* */
84
+ /* Added support for booleans with <stdbool.h>. */
85
+ /* */
86
+ /* Removed use of void pointers for specific */
87
+ /* data structures. */
88
+ /* */
89
+ /* Removed VAX_VMS support. */
90
+ /* */
91
+ /* Removed mv-append and length functions. */
92
+ /* */
93
+ /* UDF redesign. */
94
+ /* */
95
+ /* The system function now returns the completion */
96
+ /* status of the command. If no arguments are */
97
+ /* passed, the return value indicates whether a */
98
+ /* command processor is available. */
99
+ /* */
100
+ /* Added get-error, set-error, and clear-error */
101
+ /* functions. */
102
+ /* */
103
+ /* Added void function. */
104
+ /* */
105
+ /* Function operating system returns MAC-OS */
106
+ /* instead of MAC-OS-X. */
107
+ /* */
108
+ /* Removed WINDOW_INTERFACE flag. */
109
+ /* */
110
+ /* 6.41: Added SYSTEM_FUNCTION compiler flag. */
111
+ /* */
112
+ /* Used gensnprintf in place of gensprintf and. */
113
+ /* sprintf. */
114
+ /* */
115
+ /*************************************************************/
116
+
117
+ #include <stdio.h>
118
+ #include <string.h>
119
+ #include <time.h>
120
+
121
+ #include "setup.h"
122
+
123
+ #include "argacces.h"
124
+ #include "envrnmnt.h"
125
+ #include "exprnpsr.h"
126
+ #include "memalloc.h"
127
+ #include "multifld.h"
128
+ #include "prntutil.h"
129
+ #include "router.h"
130
+ #include "sysdep.h"
131
+ #include "utility.h"
132
+
133
+ #if DEFFUNCTION_CONSTRUCT
134
+ #include "dffnxfun.h"
135
+ #endif
136
+
137
+ #if DEFTEMPLATE_CONSTRUCT
138
+ #include "factfun.h"
139
+ #include "tmpltutl.h"
140
+ #endif
141
+
142
+ #include "miscfun.h"
143
+
144
+ #define MISCFUN_DATA 9
145
+
146
+ struct miscFunctionData
147
+ {
148
+ long long GensymNumber;
149
+ CLIPSValue errorCode;
150
+ };
151
+
152
+ #define MiscFunctionData(theEnv) ((struct miscFunctionData *) GetEnvironmentData(theEnv,MISCFUN_DATA))
153
+
154
+ /***************************************/
155
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
156
+ /***************************************/
157
+
158
+ static void ExpandFuncMultifield(Environment *,UDFValue *,Expression *,
159
+ Expression **,void *);
160
+ static int FindLanguageType(Environment *,const char *);
161
+ static void ConvertTime(Environment *,UDFValue *,struct tm *);
162
+
163
+ /*****************************************************************/
164
+ /* MiscFunctionDefinitions: Initializes miscellaneous functions. */
165
+ /*****************************************************************/
166
+ void MiscFunctionDefinitions(
167
+ Environment *theEnv)
168
+ {
169
+ AllocateEnvironmentData(theEnv,MISCFUN_DATA,sizeof(struct miscFunctionData),NULL);
170
+ MiscFunctionData(theEnv)->GensymNumber = 1;
171
+ MiscFunctionData(theEnv)->errorCode.lexemeValue = FalseSymbol(theEnv);
172
+ Retain(theEnv,MiscFunctionData(theEnv)->errorCode.header);
173
+
174
+ #if ! RUN_TIME
175
+ AddUDF(theEnv,"exit","v",0,1,"l",ExitCommand,"ExitCommand",NULL);
176
+
177
+ AddUDF(theEnv,"gensym","y",0,0,NULL,GensymFunction,"GensymFunction",NULL);
178
+ AddUDF(theEnv,"gensym*","y",0,0,NULL,GensymStarFunction,"GensymStarFunction",NULL);
179
+ AddUDF(theEnv,"setgen","l",1,1,"l",SetgenFunction,"SetgenFunction",NULL);
180
+
181
+ #if SYSTEM_FUNCTION
182
+ AddUDF(theEnv,"system","ly",0,UNBOUNDED,"sy",SystemCommand,"SystemCommand",NULL);
183
+ #endif
184
+ AddUDF(theEnv,"length$","l",1,1,"m",LengthFunction,"LengthFunction",NULL);
185
+ AddUDF(theEnv,"time","d",0,0,NULL,TimeFunction,"TimeFunction",NULL);
186
+ AddUDF(theEnv,"local-time","m",0,0,NULL,LocalTimeFunction,"LocalTimeFunction",NULL);
187
+ AddUDF(theEnv,"gm-time","m",0,0,NULL,GMTimeFunction,"GMTimeFunction",NULL);
188
+
189
+ AddUDF(theEnv,"random","l",0,2,"l",RandomFunction,"RandomFunction",NULL);
190
+ AddUDF(theEnv,"seed","v",1,1,"l",SeedFunction,"SeedFunction",NULL);
191
+ AddUDF(theEnv,"conserve-mem","v",1,1,"y",ConserveMemCommand,"ConserveMemCommand",NULL);
192
+ AddUDF(theEnv,"release-mem","l",0,0,NULL,ReleaseMemCommand,"ReleaseMemCommand",NULL);
193
+ #if DEBUGGING_FUNCTIONS
194
+ AddUDF(theEnv,"mem-used","l",0,0,NULL,MemUsedCommand,"MemUsedCommand",NULL);
195
+ AddUDF(theEnv,"mem-requests","l",0,0,NULL,MemRequestsCommand,"MemRequestsCommand",NULL);
196
+ #endif
197
+
198
+ AddUDF(theEnv,"options","v",0,0,NULL,OptionsCommand,"OptionsCommand",NULL);
199
+
200
+ AddUDF(theEnv,"operating-system","y",0,0,NULL,OperatingSystemFunction,"OperatingSystemFunction",NULL);
201
+ AddUDF(theEnv,"(expansion-call)","*",0,UNBOUNDED,NULL,ExpandFuncCall,"ExpandFuncCall",NULL);
202
+ AddUDF(theEnv,"expand$","*",1,1,"m",DummyExpandFuncMultifield,"DummyExpandFuncMultifield",NULL);
203
+ FuncSeqOvlFlags(theEnv,"expand$",false,false);
204
+ AddUDF(theEnv,"(set-evaluation-error)","y",0,0,NULL,CauseEvaluationError,"CauseEvaluationError",NULL);
205
+ AddUDF(theEnv,"set-sequence-operator-recognition","b",1,1,"y",SetSORCommand,"SetSORCommand",NULL);
206
+ AddUDF(theEnv,"get-sequence-operator-recognition","b",0,0,NULL,GetSORCommand,"GetSORCommand",NULL);
207
+ AddUDF(theEnv,"get-function-restrictions","s",1,1,"y",GetFunctionRestrictions,"GetFunctionRestrictions",NULL);
208
+ AddUDF(theEnv,"create$","m",0,UNBOUNDED,NULL,CreateFunction,"CreateFunction",NULL);
209
+ AddUDF(theEnv,"apropos","v",1,1,"y",AproposCommand,"AproposCommand",NULL);
210
+ AddUDF(theEnv,"get-function-list","m",0,0,NULL,GetFunctionListFunction,"GetFunctionListFunction",NULL);
211
+ AddUDF(theEnv,"funcall","*",1,UNBOUNDED,"*;sy",FuncallFunction,"FuncallFunction",NULL);
212
+ AddUDF(theEnv,"new","*",1,UNBOUNDED,"*;y",NewFunction,"NewFunction",NULL);
213
+ AddUDF(theEnv,"call","*",1,UNBOUNDED,"*",CallFunction,"CallFunction",NULL);
214
+ AddUDF(theEnv,"timer","d",0,UNBOUNDED,NULL,TimerFunction,"TimerFunction",NULL);
215
+
216
+ AddUDF(theEnv,"get-error","*",0,0,NULL,GetErrorFunction,"GetErrorFunction",NULL);
217
+ AddUDF(theEnv,"clear-error","*",0,0,NULL,ClearErrorFunction,"ClearErrorFunction",NULL);
218
+ AddUDF(theEnv,"set-error","v",1,1,NULL,SetErrorFunction,"SetErrorFunction",NULL);
219
+
220
+ AddUDF(theEnv,"void","v",0,0,NULL,VoidFunction,"VoidFunction",NULL);
221
+ #endif
222
+ }
223
+
224
+ /*****************************************************/
225
+ /* ExitCommand: H/L command for exiting the program. */
226
+ /*****************************************************/
227
+ void ExitCommand(
228
+ Environment *theEnv,
229
+ UDFContext *context,
230
+ UDFValue *returnValue)
231
+ {
232
+ unsigned int argCnt;
233
+ int status;
234
+ UDFValue theArg;
235
+
236
+ argCnt = UDFArgumentCount(context);
237
+
238
+ if (argCnt == 0)
239
+ { ExitRouter(theEnv,EXIT_SUCCESS); }
240
+ else
241
+ {
242
+ if (! UDFFirstArgument(context,INTEGER_BIT,&theArg))
243
+ { ExitRouter(theEnv,EXIT_SUCCESS); }
244
+
245
+ status = (int) theArg.integerValue->contents;
246
+ if (GetEvaluationError(theEnv)) return;
247
+ ExitRouter(theEnv,status);
248
+ }
249
+
250
+ return;
251
+ }
252
+
253
+ /******************************************************************/
254
+ /* CreateFunction: H/L access routine for the create$ function. */
255
+ /******************************************************************/
256
+ void CreateFunction(
257
+ Environment *theEnv,
258
+ UDFContext *context,
259
+ UDFValue *returnValue)
260
+ {
261
+ StoreInMultifield(theEnv,returnValue,GetFirstArgument(),true);
262
+ }
263
+
264
+ /*****************************************************************/
265
+ /* SetgenFunction: H/L access routine for the setgen function. */
266
+ /*****************************************************************/
267
+ void SetgenFunction(
268
+ Environment *theEnv,
269
+ UDFContext *context,
270
+ UDFValue *returnValue)
271
+ {
272
+ long long theLong;
273
+
274
+ /*====================================================*/
275
+ /* Check to see that an integer argument is provided. */
276
+ /*====================================================*/
277
+
278
+ if (! UDFNthArgument(context,1,INTEGER_BIT,returnValue))
279
+ { return; }
280
+
281
+ /*========================================*/
282
+ /* The integer must be greater than zero. */
283
+ /*========================================*/
284
+
285
+ theLong = returnValue->integerValue->contents;
286
+
287
+ if (theLong < 1LL)
288
+ {
289
+ UDFInvalidArgumentMessage(context,"integer (greater than or equal to 1)");
290
+ returnValue->integerValue = CreateInteger(theEnv,MiscFunctionData(theEnv)->GensymNumber);
291
+ return;
292
+ }
293
+
294
+ /*==============================================*/
295
+ /* Set the gensym index to the number provided. */
296
+ /*==============================================*/
297
+
298
+ MiscFunctionData(theEnv)->GensymNumber = theLong;
299
+ }
300
+
301
+ /****************************************/
302
+ /* GensymFunction: H/L access routine */
303
+ /* for the gensym function. */
304
+ /****************************************/
305
+ void GensymFunction(
306
+ Environment *theEnv,
307
+ UDFContext *context,
308
+ UDFValue *returnValue)
309
+ {
310
+ char genstring[128];
311
+
312
+ /*================================================*/
313
+ /* Create a symbol using the current gensym index */
314
+ /* as the postfix. */
315
+ /*================================================*/
316
+
317
+ gensnprintf(genstring,sizeof(genstring),"gen%lld",MiscFunctionData(theEnv)->GensymNumber);
318
+ MiscFunctionData(theEnv)->GensymNumber++;
319
+
320
+ /*====================*/
321
+ /* Return the symbol. */
322
+ /*====================*/
323
+
324
+ returnValue->lexemeValue = CreateSymbol(theEnv,genstring);
325
+ }
326
+
327
+ /************************************************/
328
+ /* GensymStarFunction: H/L access routine for */
329
+ /* the gensym* function. */
330
+ /************************************************/
331
+ void GensymStarFunction(
332
+ Environment *theEnv,
333
+ UDFContext *context,
334
+ UDFValue *returnValue)
335
+ {
336
+ /*====================*/
337
+ /* Return the symbol. */
338
+ /*====================*/
339
+
340
+ GensymStar(theEnv,returnValue);
341
+ }
342
+
343
+ /************************************/
344
+ /* GensymStar: C access routine for */
345
+ /* the gensym* function. */
346
+ /************************************/
347
+ void GensymStar(
348
+ Environment *theEnv,
349
+ UDFValue *returnValue)
350
+ {
351
+ char genstring[128];
352
+
353
+ /*=======================================================*/
354
+ /* Create a symbol using the current gensym index as the */
355
+ /* postfix. If the symbol is already present in the */
356
+ /* symbol table, then continue generating symbols until */
357
+ /* a unique symbol is found. */
358
+ /*=======================================================*/
359
+
360
+ do
361
+ {
362
+ gensnprintf(genstring,sizeof(genstring),"gen%lld",MiscFunctionData(theEnv)->GensymNumber);
363
+ MiscFunctionData(theEnv)->GensymNumber++;
364
+ }
365
+ while (FindSymbolHN(theEnv,genstring,SYMBOL_BIT) != NULL);
366
+
367
+ /*====================*/
368
+ /* Return the symbol. */
369
+ /*====================*/
370
+
371
+ returnValue->lexemeValue = CreateSymbol(theEnv,genstring);
372
+ }
373
+
374
+ /********************************************/
375
+ /* RandomFunction: H/L access routine for */
376
+ /* the random function. */
377
+ /********************************************/
378
+ void RandomFunction(
379
+ Environment *theEnv,
380
+ UDFContext *context,
381
+ UDFValue *returnValue)
382
+ {
383
+ unsigned int argCount;
384
+ long long rv;
385
+ UDFValue theArg;
386
+ long long begin, end;
387
+
388
+ /*====================================*/
389
+ /* The random function accepts either */
390
+ /* zero or two arguments. */
391
+ /*====================================*/
392
+
393
+ argCount = UDFArgumentCount(context);
394
+
395
+ if ((argCount != 0) && (argCount != 2))
396
+ {
397
+ PrintErrorID(theEnv,"MISCFUN",2,false);
398
+ WriteString(theEnv,STDERR,"Function random expected either 0 or 2 arguments\n");
399
+ }
400
+
401
+ /*========================================*/
402
+ /* Return the randomly generated integer. */
403
+ /*========================================*/
404
+
405
+ rv = genrand();
406
+
407
+ if (argCount == 2)
408
+ {
409
+ if (! UDFFirstArgument(context,INTEGER_BIT,&theArg))
410
+ { return; }
411
+ begin = theArg.integerValue->contents;
412
+
413
+ if (! UDFNextArgument(context,INTEGER_BIT,&theArg))
414
+ { return; }
415
+
416
+ end = theArg.integerValue->contents;
417
+ if (end < begin)
418
+ {
419
+ PrintErrorID(theEnv,"MISCFUN",3,false);
420
+ WriteString(theEnv,STDERR,"Function random expected argument #1 to be less than argument #2\n");
421
+ returnValue->integerValue = CreateInteger(theEnv,rv);
422
+ return;
423
+ }
424
+
425
+ rv = begin + (rv % ((end - begin) + 1));
426
+ }
427
+
428
+ returnValue->integerValue = CreateInteger(theEnv,rv);
429
+ }
430
+
431
+ /******************************************/
432
+ /* SeedFunction: H/L access routine for */
433
+ /* the seed function. */
434
+ /******************************************/
435
+ void SeedFunction(
436
+ Environment *theEnv,
437
+ UDFContext *context,
438
+ UDFValue *returnValue)
439
+ {
440
+ UDFValue theValue;
441
+
442
+ /*==========================================================*/
443
+ /* Check to see that a single integer argument is provided. */
444
+ /*==========================================================*/
445
+
446
+ if (! UDFFirstArgument(context,INTEGER_BIT,&theValue))
447
+ { return; }
448
+
449
+ /*=============================================================*/
450
+ /* Seed the random number generator with the provided integer. */
451
+ /*=============================================================*/
452
+
453
+ genseed((unsigned int) theValue.integerValue->contents);
454
+ }
455
+
456
+ /********************************************/
457
+ /* LengthFunction: H/L access routine for */
458
+ /* the length$ function. */
459
+ /********************************************/
460
+ void LengthFunction(
461
+ Environment *theEnv,
462
+ UDFContext *context,
463
+ UDFValue *returnValue)
464
+ {
465
+ UDFValue theArg;
466
+
467
+ /*====================================================*/
468
+ /* The length$ function expects exactly one argument. */
469
+ /*====================================================*/
470
+
471
+ if (! UDFFirstArgument(context, MULTIFIELD_BIT, &theArg))
472
+ { return; }
473
+
474
+ /*==============================================*/
475
+ /* Return the number of fields in the argument. */
476
+ /*==============================================*/
477
+
478
+ returnValue->value = CreateInteger(theEnv,(long long) theArg.range);
479
+ }
480
+
481
+ /*******************************************/
482
+ /* ReleaseMemCommand: H/L access routine */
483
+ /* for the release-mem function. */
484
+ /*******************************************/
485
+ void ReleaseMemCommand(
486
+ Environment *theEnv,
487
+ UDFContext *context,
488
+ UDFValue *returnValue)
489
+ {
490
+ /*========================================*/
491
+ /* Release memory to the operating system */
492
+ /* and return the amount of memory freed. */
493
+ /*========================================*/
494
+
495
+ returnValue->integerValue = CreateInteger(theEnv,ReleaseMem(theEnv,-1));
496
+ }
497
+
498
+ /******************************************/
499
+ /* ConserveMemCommand: H/L access routine */
500
+ /* for the conserve-mem command. */
501
+ /******************************************/
502
+ void ConserveMemCommand(
503
+ Environment *theEnv,
504
+ UDFContext *context,
505
+ UDFValue *returnValue)
506
+ {
507
+ const char *argument;
508
+ UDFValue theValue;
509
+
510
+ /*===================================*/
511
+ /* The conserve-mem function expects */
512
+ /* a single symbol argument. */
513
+ /*===================================*/
514
+
515
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue))
516
+ { return; }
517
+
518
+ argument = theValue.lexemeValue->contents;
519
+
520
+ /*====================================================*/
521
+ /* If the argument is the symbol "on", then store the */
522
+ /* pretty print representation of a construct when it */
523
+ /* is defined. */
524
+ /*====================================================*/
525
+
526
+ if (strcmp(argument,"on") == 0)
527
+ { SetConserveMemory(theEnv,true); }
528
+
529
+ /*======================================================*/
530
+ /* Otherwise, if the argument is the symbol "off", then */
531
+ /* don't store the pretty print representation of a */
532
+ /* construct when it is defined. */
533
+ /*======================================================*/
534
+
535
+ else if (strcmp(argument,"off") == 0)
536
+ { SetConserveMemory(theEnv,false); }
537
+
538
+ /*=====================================================*/
539
+ /* Otherwise, generate an error since the only allowed */
540
+ /* arguments are "on" or "off." */
541
+ /*=====================================================*/
542
+
543
+ else
544
+ {
545
+ UDFInvalidArgumentMessage(context,"symbol with value on or off");
546
+ return;
547
+ }
548
+
549
+ return;
550
+ }
551
+
552
+ #if DEBUGGING_FUNCTIONS
553
+
554
+ /****************************************/
555
+ /* MemUsedCommand: H/L access routine */
556
+ /* for the mem-used command. */
557
+ /****************************************/
558
+ void MemUsedCommand(
559
+ Environment *theEnv,
560
+ UDFContext *context,
561
+ UDFValue *returnValue)
562
+ {
563
+ /*============================================*/
564
+ /* Return the amount of memory currently held */
565
+ /* (both for current use and for later use). */
566
+ /*============================================*/
567
+
568
+ returnValue->integerValue = CreateInteger(theEnv,MemUsed(theEnv));
569
+ }
570
+
571
+ /********************************************/
572
+ /* MemRequestsCommand: H/L access routine */
573
+ /* for the mem-requests command. */
574
+ /********************************************/
575
+ void MemRequestsCommand(
576
+ Environment *theEnv,
577
+ UDFContext *context,
578
+ UDFValue *returnValue)
579
+ {
580
+ /*==================================*/
581
+ /* Return the number of outstanding */
582
+ /* memory requests. */
583
+ /*==================================*/
584
+
585
+ returnValue->integerValue = CreateInteger(theEnv,MemRequests(theEnv));
586
+ }
587
+
588
+ #endif
589
+
590
+ /****************************************/
591
+ /* AproposCommand: H/L access routine */
592
+ /* for the apropos command. */
593
+ /****************************************/
594
+ void AproposCommand(
595
+ Environment *theEnv,
596
+ UDFContext *context,
597
+ UDFValue *returnValue)
598
+ {
599
+ const char *argument;
600
+ UDFValue theArg;
601
+ CLIPSLexeme *hashPtr = NULL;
602
+ size_t theLength;
603
+
604
+ /*=======================================================*/
605
+ /* The apropos command expects a single symbol argument. */
606
+ /*=======================================================*/
607
+
608
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg))
609
+ { return; }
610
+
611
+ /*=======================================*/
612
+ /* Determine the length of the argument. */
613
+ /*=======================================*/
614
+
615
+ argument = theArg.lexemeValue->contents;
616
+ theLength = strlen(argument);
617
+
618
+ /*====================================================================*/
619
+ /* Print each entry in the symbol table that contains the argument as */
620
+ /* a substring. When using a non-ANSI compiler, only those strings */
621
+ /* that contain the substring starting at the beginning of the string */
622
+ /* are printed. */
623
+ /*====================================================================*/
624
+
625
+ while ((hashPtr = GetNextSymbolMatch(theEnv,argument,theLength,hashPtr,true,NULL)) != NULL)
626
+ {
627
+ WriteString(theEnv,STDOUT,hashPtr->contents);
628
+ WriteString(theEnv,STDOUT,"\n");
629
+ }
630
+ }
631
+
632
+ /****************************************/
633
+ /* OptionsCommand: H/L access routine */
634
+ /* for the options command. */
635
+ /****************************************/
636
+ void OptionsCommand(
637
+ Environment *theEnv,
638
+ UDFContext *context,
639
+ UDFValue *returnValue)
640
+ {
641
+ /*=======================*/
642
+ /* Set the return value. */
643
+ /*=======================*/
644
+
645
+ returnValue->voidValue = VoidConstant(theEnv);
646
+
647
+ /*=================================*/
648
+ /* Print the state of the compiler */
649
+ /* flags for this executable. */
650
+ /*=================================*/
651
+
652
+ WriteString(theEnv,STDOUT,"Machine type: ");
653
+
654
+ #if GENERIC
655
+ WriteString(theEnv,STDOUT,"Generic ");
656
+ #endif
657
+ #if UNIX_V
658
+ WriteString(theEnv,STDOUT,"UNIX System V or 4.2BSD ");
659
+ #endif
660
+ #if DARWIN
661
+ WriteString(theEnv,STDOUT,"Darwin ");
662
+ #endif
663
+ #if LINUX
664
+ WriteString(theEnv,STDOUT,"Linux ");
665
+ #endif
666
+ #if UNIX_7
667
+ WriteString(theEnv,STDOUT,"UNIX System III Version 7 or Sun Unix ");
668
+ #endif
669
+ #if MAC_XCD
670
+ WriteString(theEnv,STDOUT,"Apple Macintosh with Xcode");
671
+ #endif
672
+ #if WIN_MVC
673
+ WriteString(theEnv,STDOUT,"Microsoft Windows with Microsoft Visual C++");
674
+ #endif
675
+ #if WIN_GCC
676
+ WriteString(theEnv,STDOUT,"Microsoft Windows with DJGPP");
677
+ #endif
678
+ WriteString(theEnv,STDOUT,"\n");
679
+
680
+ WriteString(theEnv,STDOUT,"Defrule construct is ");
681
+ #if DEFRULE_CONSTRUCT
682
+ WriteString(theEnv,STDOUT,"ON\n");
683
+ #else
684
+ WriteString(theEnv,STDOUT,"OFF\n");
685
+ #endif
686
+
687
+ WriteString(theEnv,STDOUT,"Defmodule construct is ");
688
+ #if DEFMODULE_CONSTRUCT
689
+ WriteString(theEnv,STDOUT,"ON\n");
690
+ #else
691
+ WriteString(theEnv,STDOUT,"OFF\n");
692
+ #endif
693
+
694
+ WriteString(theEnv,STDOUT,"Deftemplate construct is ");
695
+ #if DEFTEMPLATE_CONSTRUCT
696
+ WriteString(theEnv,STDOUT,"ON\n");
697
+ #else
698
+ WriteString(theEnv,STDOUT,"OFF\n");
699
+ #endif
700
+
701
+ WriteString(theEnv,STDOUT," Fact-set queries are ");
702
+ #if FACT_SET_QUERIES
703
+ WriteString(theEnv,STDOUT,"ON\n");
704
+ #else
705
+ WriteString(theEnv,STDOUT,"OFF\n");
706
+ #endif
707
+
708
+ #if DEFTEMPLATE_CONSTRUCT
709
+
710
+ WriteString(theEnv,STDOUT," Deffacts construct is ");
711
+ #if DEFFACTS_CONSTRUCT
712
+ WriteString(theEnv,STDOUT,"ON\n");
713
+ #else
714
+ WriteString(theEnv,STDOUT,"OFF\n");
715
+ #endif
716
+
717
+ #endif
718
+
719
+ WriteString(theEnv,STDOUT,"Defglobal construct is ");
720
+ #if DEFGLOBAL_CONSTRUCT
721
+ WriteString(theEnv,STDOUT,"ON\n");
722
+ #else
723
+ WriteString(theEnv,STDOUT,"OFF\n");
724
+ #endif
725
+
726
+ WriteString(theEnv,STDOUT,"Deffunction construct is ");
727
+ #if DEFFUNCTION_CONSTRUCT
728
+ WriteString(theEnv,STDOUT,"ON\n");
729
+ #else
730
+ WriteString(theEnv,STDOUT,"OFF\n");
731
+ #endif
732
+
733
+ WriteString(theEnv,STDOUT,"Defgeneric/Defmethod constructs are ");
734
+ #if DEFGENERIC_CONSTRUCT
735
+ WriteString(theEnv,STDOUT,"ON\n");
736
+ #else
737
+ WriteString(theEnv,STDOUT,"OFF\n");
738
+ #endif
739
+
740
+ WriteString(theEnv,STDOUT,"Object System is ");
741
+ #if OBJECT_SYSTEM
742
+ WriteString(theEnv,STDOUT,"ON\n");
743
+ #else
744
+ WriteString(theEnv,STDOUT,"OFF\n");
745
+ #endif
746
+
747
+ #if OBJECT_SYSTEM
748
+
749
+ WriteString(theEnv,STDOUT," Definstances construct is ");
750
+ #if DEFINSTANCES_CONSTRUCT
751
+ WriteString(theEnv,STDOUT,"ON\n");
752
+ #else
753
+ WriteString(theEnv,STDOUT,"OFF\n");
754
+ #endif
755
+
756
+ WriteString(theEnv,STDOUT," Instance-set queries are ");
757
+ #if INSTANCE_SET_QUERIES
758
+ WriteString(theEnv,STDOUT,"ON\n");
759
+ #else
760
+ WriteString(theEnv,STDOUT,"OFF\n");
761
+ #endif
762
+
763
+ WriteString(theEnv,STDOUT," Binary loading of instances is ");
764
+ #if BLOAD_INSTANCES
765
+ WriteString(theEnv,STDOUT,"ON\n");
766
+ #else
767
+ WriteString(theEnv,STDOUT,"OFF\n");
768
+ #endif
769
+
770
+ WriteString(theEnv,STDOUT," Binary saving of instances is ");
771
+ #if BSAVE_INSTANCES
772
+ WriteString(theEnv,STDOUT,"ON\n");
773
+ #else
774
+ WriteString(theEnv,STDOUT,"OFF\n");
775
+ #endif
776
+
777
+ #endif
778
+
779
+ WriteString(theEnv,STDOUT,"Extended math function package is ");
780
+ #if EXTENDED_MATH_FUNCTIONS
781
+ WriteString(theEnv,STDOUT,"ON\n");
782
+ #else
783
+ WriteString(theEnv,STDOUT,"OFF\n");
784
+ #endif
785
+
786
+ WriteString(theEnv,STDOUT,"Text processing function package is ");
787
+ #if TEXTPRO_FUNCTIONS
788
+ WriteString(theEnv,STDOUT,"ON\n");
789
+ #else
790
+ WriteString(theEnv,STDOUT,"OFF\n");
791
+ #endif
792
+
793
+ WriteString(theEnv,STDOUT,"Bload capability is ");
794
+ #if BLOAD_ONLY
795
+ WriteString(theEnv,STDOUT,"BLOAD ONLY");
796
+ #endif
797
+ #if BLOAD
798
+ WriteString(theEnv,STDOUT,"BLOAD");
799
+ #endif
800
+ #if BLOAD_AND_BSAVE
801
+ WriteString(theEnv,STDOUT,"BLOAD AND BSAVE");
802
+ #endif
803
+ #if (! BLOAD_ONLY) && (! BLOAD) && (! BLOAD_AND_BSAVE)
804
+ WriteString(theEnv,STDOUT,"OFF ");
805
+ #endif
806
+ WriteString(theEnv,STDOUT,"\n");
807
+
808
+ WriteString(theEnv,STDOUT,"Construct compiler is ");
809
+ #if CONSTRUCT_COMPILER
810
+ WriteString(theEnv,STDOUT,"ON\n");
811
+ #else
812
+ WriteString(theEnv,STDOUT,"OFF\n");
813
+ #endif
814
+
815
+ WriteString(theEnv,STDOUT,"I/O function package is ");
816
+ #if IO_FUNCTIONS
817
+ WriteString(theEnv,STDOUT,"ON\n");
818
+ #else
819
+ WriteString(theEnv,STDOUT,"OFF\n");
820
+ #endif
821
+
822
+ WriteString(theEnv,STDOUT,"String function package is ");
823
+ #if STRING_FUNCTIONS
824
+ WriteString(theEnv,STDOUT,"ON\n");
825
+ #else
826
+ WriteString(theEnv,STDOUT,"OFF\n");
827
+ #endif
828
+
829
+ WriteString(theEnv,STDOUT,"Multifield function package is ");
830
+ #if MULTIFIELD_FUNCTIONS
831
+ WriteString(theEnv,STDOUT,"ON\n");
832
+ #else
833
+ WriteString(theEnv,STDOUT,"OFF\n");
834
+ #endif
835
+
836
+ WriteString(theEnv,STDOUT,"Debugging function package is ");
837
+ #if DEBUGGING_FUNCTIONS
838
+ WriteString(theEnv,STDOUT,"ON\n");
839
+ #else
840
+ WriteString(theEnv,STDOUT,"OFF\n");
841
+ #endif
842
+
843
+ WriteString(theEnv,STDOUT,"Developer flag is ");
844
+ #if DEVELOPER
845
+ WriteString(theEnv,STDOUT,"ON\n");
846
+ #else
847
+ WriteString(theEnv,STDOUT,"OFF\n");
848
+ #endif
849
+
850
+ WriteString(theEnv,STDOUT,"Run time module is ");
851
+ #if RUN_TIME
852
+ WriteString(theEnv,STDOUT,"ON\n");
853
+ #else
854
+ WriteString(theEnv,STDOUT,"OFF\n");
855
+ #endif
856
+ }
857
+
858
+ /***********************************************/
859
+ /* OperatingSystemFunction: H/L access routine */
860
+ /* for the operating system function. */
861
+ /***********************************************/
862
+ void OperatingSystemFunction(
863
+ Environment *theEnv,
864
+ UDFContext *context,
865
+ UDFValue *returnValue)
866
+ {
867
+ #if GENERIC
868
+ returnValue->lexemeValue = CreateSymbol(theEnv,"UNKNOWN");
869
+ #elif UNIX_V
870
+ returnValue->lexemeValue = CreateSymbol(theEnv,"UNIX-V");
871
+ #elif UNIX_7
872
+ returnValue->lexemeValue = CreateSymbol(theEnv,"UNIX-7");
873
+ #elif LINUX
874
+ returnValue->lexemeValue = CreateSymbol(theEnv,"LINUX");
875
+ #elif DARWIN
876
+ returnValue->lexemeValue = CreateSymbol(theEnv,"DARWIN");
877
+ #elif MAC_XCD
878
+ returnValue->lexemeValue = CreateSymbol(theEnv,"MAC-OS");
879
+ #elif WINDOWS_OS
880
+ returnValue->lexemeValue = CreateSymbol(theEnv,"WINDOWS");
881
+ #else
882
+ returnValue->lexemeValue = CreateSymbol(theEnv,"UNKNOWN");
883
+ #endif
884
+ }
885
+
886
+ /********************************************************************
887
+ NAME : ExpandFuncCall
888
+ DESCRIPTION : This function is a wrap-around for a normal
889
+ function call. It preexamines the argument
890
+ expression list and expands any references to the
891
+ sequence operator. It builds a copy of the
892
+ function call expression with these new arguments
893
+ inserted and evaluates the function call.
894
+ INPUTS : A data object buffer
895
+ RETURNS : Nothing useful
896
+ SIDE EFFECTS : Expressions alloctaed/deallocated
897
+ Function called and arguments evaluated
898
+ EvaluationError set on errors
899
+ NOTES : None
900
+ *******************************************************************/
901
+ void ExpandFuncCall(
902
+ Environment *theEnv,
903
+ UDFContext *context,
904
+ UDFValue *returnValue)
905
+ {
906
+ Expression *newargexp,*fcallexp;
907
+ struct functionDefinition *func;
908
+
909
+ /* ======================================================================
910
+ Copy the original function call's argument expression list.
911
+ Look for expand$ function callsexpressions and replace those
912
+ with the equivalent expressions of the expansions of evaluations
913
+ of the arguments.
914
+ ====================================================================== */
915
+ newargexp = CopyExpression(theEnv,GetFirstArgument()->argList);
916
+ ExpandFuncMultifield(theEnv,returnValue,newargexp,&newargexp,
917
+ FindFunction(theEnv,"expand$"));
918
+
919
+ /* ===================================================================
920
+ Build the new function call expression with the expanded arguments.
921
+ Check the number of arguments, if necessary, and call the thing.
922
+ =================================================================== */
923
+ fcallexp = get_struct(theEnv,expr);
924
+ fcallexp->type = GetFirstArgument()->type;
925
+ fcallexp->value = GetFirstArgument()->value;
926
+ fcallexp->nextArg = NULL;
927
+ fcallexp->argList = newargexp;
928
+ if (fcallexp->type == FCALL)
929
+ {
930
+ func = fcallexp->functionValue;
931
+ if (CheckFunctionArgCount(theEnv,func,CountArguments(newargexp)) == false)
932
+ {
933
+ returnValue->lexemeValue = FalseSymbol(theEnv);
934
+ ReturnExpression(theEnv,fcallexp);
935
+ return;
936
+ }
937
+ }
938
+ #if DEFFUNCTION_CONSTRUCT
939
+ else if (fcallexp->type == PCALL)
940
+ {
941
+ if (CheckDeffunctionCall(theEnv,(Deffunction *) fcallexp->value,
942
+ CountArguments(fcallexp->argList)) == false)
943
+ {
944
+ returnValue->lexemeValue = FalseSymbol(theEnv);
945
+ ReturnExpression(theEnv,fcallexp);
946
+ SetEvaluationError(theEnv,true);
947
+ return;
948
+ }
949
+ }
950
+ #endif
951
+
952
+ EvaluateExpression(theEnv,fcallexp,returnValue);
953
+ ReturnExpression(theEnv,fcallexp);
954
+ }
955
+
956
+ /***********************************************************************
957
+ NAME : DummyExpandFuncMultifield
958
+ DESCRIPTION : The expansion of multifield arguments is valid only
959
+ when done for a function call. All these expansions
960
+ are handled by the H/L wrap-around function
961
+ (expansion-call) - see ExpandFuncCall. If the H/L
962
+ function, epand-multifield is ever called directly,
963
+ it is an error.
964
+ INPUTS : Data object buffer
965
+ RETURNS : Nothing useful
966
+ SIDE EFFECTS : EvaluationError set
967
+ NOTES : None
968
+ **********************************************************************/
969
+ void DummyExpandFuncMultifield(
970
+ Environment *theEnv,
971
+ UDFContext *context,
972
+ UDFValue *returnValue)
973
+ {
974
+ returnValue->lexemeValue = FalseSymbol(theEnv);
975
+ SetEvaluationError(theEnv,true);
976
+ PrintErrorID(theEnv,"MISCFUN",1,false);
977
+ WriteString(theEnv,STDERR,"The function 'expand$' must be used in the argument list of a function call.\n");
978
+ }
979
+
980
+ /***********************************************************************
981
+ NAME : ExpandFuncMultifield
982
+ DESCRIPTION : Recursively examines an expression and replaces
983
+ PROC_EXPAND_MULTIFIELD expressions with the expanded
984
+ evaluation expression of its argument
985
+ INPUTS : 1) A data object result buffer
986
+ 2) The expression to modify
987
+ 3) The address of the expression, in case it is
988
+ deleted entirely
989
+ 4) The address of the H/L function expand$
990
+ RETURNS : Nothing useful
991
+ SIDE EFFECTS : Expressions allocated/deallocated as necessary
992
+ Evaluations performed
993
+ On errors, argument expression set to call a function
994
+ which causes an evaluation error when evaluated
995
+ a second time by actual caller.
996
+ NOTES : THIS ROUTINE MODIFIES EXPRESSIONS AT RUNTIME!! MAKE
997
+ SURE THAT THE Expression PASSED IS SAFE TO CHANGE!!
998
+ **********************************************************************/
999
+ static void ExpandFuncMultifield(
1000
+ Environment *theEnv,
1001
+ UDFValue *returnValue,
1002
+ Expression *theExp,
1003
+ Expression **sto,
1004
+ void *expmult)
1005
+ {
1006
+ Expression *newexp,*top,*bot;
1007
+ size_t i; /* 6.04 Bug Fix */
1008
+
1009
+ while (theExp != NULL)
1010
+ {
1011
+ if (theExp->value == expmult)
1012
+ {
1013
+ EvaluateExpression(theEnv,theExp->argList,returnValue);
1014
+ ReturnExpression(theEnv,theExp->argList);
1015
+ if ((EvaluationData(theEnv)->EvaluationError) ||
1016
+ (returnValue->header->type != MULTIFIELD_TYPE))
1017
+ {
1018
+ theExp->argList = NULL;
1019
+ if ((EvaluationData(theEnv)->EvaluationError == false) &&
1020
+ (returnValue->header->type != MULTIFIELD_TYPE))
1021
+ ExpectedTypeError2(theEnv,"expand$",1);
1022
+ theExp->value = FindFunction(theEnv,"(set-evaluation-error)");
1023
+ EvaluationData(theEnv)->EvaluationError = false;
1024
+ EvaluationData(theEnv)->HaltExecution = false;
1025
+ return;
1026
+ }
1027
+ top = bot = NULL;
1028
+ for (i = returnValue->begin ; i < (returnValue->begin + returnValue->range) ; i++)
1029
+ {
1030
+ newexp = get_struct(theEnv,expr);
1031
+ newexp->type = returnValue->multifieldValue->contents[i].header->type;
1032
+ newexp->value = returnValue->multifieldValue->contents[i].value;
1033
+ newexp->argList = NULL;
1034
+ newexp->nextArg = NULL;
1035
+ if (top == NULL)
1036
+ top = newexp;
1037
+ else
1038
+ bot->nextArg = newexp;
1039
+ bot = newexp;
1040
+ }
1041
+ if (top == NULL)
1042
+ {
1043
+ *sto = theExp->nextArg;
1044
+ rtn_struct(theEnv,expr,theExp);
1045
+ theExp = *sto;
1046
+ }
1047
+ else
1048
+ {
1049
+ bot->nextArg = theExp->nextArg;
1050
+ *sto = top;
1051
+ rtn_struct(theEnv,expr,theExp);
1052
+ sto = &bot->nextArg;
1053
+ theExp = bot->nextArg;
1054
+ }
1055
+ }
1056
+ else
1057
+ {
1058
+ if (theExp->argList != NULL)
1059
+ ExpandFuncMultifield(theEnv,returnValue,theExp->argList,&theExp->argList,expmult);
1060
+ sto = &theExp->nextArg;
1061
+ theExp = theExp->nextArg;
1062
+ }
1063
+ }
1064
+ }
1065
+
1066
+ /****************************************************************
1067
+ NAME : CauseEvaluationError
1068
+ DESCRIPTION : Dummy function use to cause evaluation errors on
1069
+ a function call to generate error messages
1070
+ INPUTS : None
1071
+ RETURNS : A pointer to the FalseSymbol
1072
+ SIDE EFFECTS : EvaluationError set
1073
+ NOTES : None
1074
+ ****************************************************************/
1075
+ void CauseEvaluationError(
1076
+ Environment *theEnv,
1077
+ UDFContext *context,
1078
+ UDFValue *returnValue)
1079
+ {
1080
+ SetEvaluationError(theEnv,true);
1081
+ returnValue->lexemeValue = FalseSymbol(theEnv);
1082
+ }
1083
+
1084
+ /************************************************/
1085
+ /* GetSORCommand: H/L access routine for the */
1086
+ /* get-sequence-operator-recognition command. */
1087
+ /************************************************/
1088
+ void GetSORCommand(
1089
+ Environment *theEnv,
1090
+ UDFContext *context,
1091
+ UDFValue *returnValue)
1092
+ {
1093
+ returnValue->lexemeValue = CreateBoolean(theEnv,GetSequenceOperatorRecognition(theEnv));
1094
+ }
1095
+
1096
+ /************************************************/
1097
+ /* SetSORCommand: H/L access routine for the */
1098
+ /* set-sequence-operator-recognition command. */
1099
+ /************************************************/
1100
+ void SetSORCommand(
1101
+ Environment *theEnv,
1102
+ UDFContext *context,
1103
+ UDFValue *returnValue)
1104
+ {
1105
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
1106
+ UDFValue theArg;
1107
+
1108
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg))
1109
+ { return; }
1110
+
1111
+ returnValue->lexemeValue = CreateBoolean(theEnv,SetSequenceOperatorRecognition(theEnv,theArg.value != FalseSymbol(theEnv)));
1112
+ #else
1113
+ returnValue->lexemeValue = CreateBoolean(theEnv,ExpressionData(theEnv)->SequenceOpMode);
1114
+ #endif
1115
+ }
1116
+
1117
+ /********************************************************************
1118
+ NAME : GetFunctionRestrictions
1119
+ DESCRIPTION : Gets DefineFunction2() restriction list for function
1120
+ INPUTS : None
1121
+ RETURNS : A string containing the function restriction codes
1122
+ SIDE EFFECTS : EvaluationError set on errors
1123
+ NOTES : None
1124
+ ********************************************************************/
1125
+ void GetFunctionRestrictions(
1126
+ Environment *theEnv,
1127
+ UDFContext *context,
1128
+ UDFValue *returnValue)
1129
+ {
1130
+ UDFValue theArg;
1131
+ struct functionDefinition *fptr;
1132
+ char *stringBuffer = NULL;
1133
+ size_t bufferPosition = 0;
1134
+ size_t bufferMaximum = 0;
1135
+
1136
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg))
1137
+ { return; }
1138
+
1139
+ fptr = FindFunction(theEnv,theArg.lexemeValue->contents);
1140
+ if (fptr == NULL)
1141
+ {
1142
+ CantFindItemErrorMessage(theEnv,"function",theArg.lexemeValue->contents,true);
1143
+ SetEvaluationError(theEnv,true);
1144
+ returnValue->lexemeValue = CreateString(theEnv,"");
1145
+ return;
1146
+ }
1147
+
1148
+ if (fptr->minArgs == UNBOUNDED)
1149
+ {
1150
+ stringBuffer = AppendToString(theEnv,"0",
1151
+ stringBuffer,&bufferPosition,&bufferMaximum);
1152
+ }
1153
+ else
1154
+ {
1155
+ stringBuffer = AppendToString(theEnv,LongIntegerToString(theEnv,fptr->minArgs),
1156
+ stringBuffer,&bufferPosition,&bufferMaximum);
1157
+ }
1158
+
1159
+ stringBuffer = AppendToString(theEnv,";",
1160
+ stringBuffer,&bufferPosition,&bufferMaximum);
1161
+
1162
+ if (fptr->maxArgs == UNBOUNDED)
1163
+ {
1164
+ stringBuffer = AppendToString(theEnv,"*",
1165
+ stringBuffer,&bufferPosition,&bufferMaximum);
1166
+ }
1167
+ else
1168
+ {
1169
+ stringBuffer = AppendToString(theEnv,LongIntegerToString(theEnv,fptr->maxArgs),
1170
+ stringBuffer,&bufferPosition,&bufferMaximum);
1171
+ }
1172
+
1173
+ stringBuffer = AppendToString(theEnv,";",
1174
+ stringBuffer,&bufferPosition,&bufferMaximum);
1175
+
1176
+ if (fptr->restrictions == NULL)
1177
+ {
1178
+ stringBuffer = AppendToString(theEnv,"*",
1179
+ stringBuffer,&bufferPosition,&bufferMaximum);
1180
+ }
1181
+ else
1182
+ {
1183
+ stringBuffer = AppendToString(theEnv,fptr->restrictions->contents,
1184
+ stringBuffer,&bufferPosition,&bufferMaximum);
1185
+ }
1186
+
1187
+ returnValue->lexemeValue = CreateString(theEnv,stringBuffer);
1188
+
1189
+ rm(theEnv,stringBuffer,bufferMaximum);
1190
+ }
1191
+
1192
+ /*************************************************/
1193
+ /* GetFunctionListFunction: H/L access routine */
1194
+ /* for the get-function-list function. */
1195
+ /*************************************************/
1196
+ void GetFunctionListFunction(
1197
+ Environment *theEnv,
1198
+ UDFContext *context,
1199
+ UDFValue *returnValue)
1200
+ {
1201
+ struct functionDefinition *theFunction;
1202
+ Multifield *theList;
1203
+ unsigned long functionCount = 0;
1204
+
1205
+ for (theFunction = GetFunctionList(theEnv);
1206
+ theFunction != NULL;
1207
+ theFunction = theFunction->next)
1208
+ { functionCount++; }
1209
+
1210
+ returnValue->begin = 0;
1211
+ returnValue->range = functionCount;
1212
+ theList = CreateMultifield(theEnv,functionCount);
1213
+ returnValue->value = theList;
1214
+
1215
+ for (theFunction = GetFunctionList(theEnv), functionCount = 0;
1216
+ theFunction != NULL;
1217
+ theFunction = theFunction->next, functionCount++)
1218
+ {
1219
+ theList->contents[functionCount].lexemeValue = theFunction->callFunctionName;
1220
+ }
1221
+ }
1222
+
1223
+ /***************************************/
1224
+ /* FuncallFunction: H/L access routine */
1225
+ /* for the funcall function. */
1226
+ /***************************************/
1227
+ void FuncallFunction(
1228
+ Environment *theEnv,
1229
+ UDFContext *context,
1230
+ UDFValue *returnValue)
1231
+ {
1232
+ size_t j;
1233
+ UDFValue theArg;
1234
+ Expression theReference;
1235
+ const char *name;
1236
+ Multifield *theMultifield;
1237
+ struct expr *lastAdd = NULL, *nextAdd, *multiAdd;
1238
+ struct functionDefinition *theFunction = NULL;
1239
+
1240
+ /*==================================*/
1241
+ /* Set up the default return value. */
1242
+ /*==================================*/
1243
+
1244
+ returnValue->lexemeValue = FalseSymbol(theEnv);
1245
+
1246
+ /*============================================*/
1247
+ /* Get the name of the function to be called. */
1248
+ /*============================================*/
1249
+
1250
+ if (! UDFFirstArgument(context,LEXEME_BITS,&theArg))
1251
+ { return; }
1252
+
1253
+ /*====================*/
1254
+ /* Find the function. */
1255
+ /*====================*/
1256
+
1257
+ name = theArg.lexemeValue->contents;
1258
+ if (! GetFunctionReference(theEnv,name,&theReference))
1259
+ {
1260
+ ExpectedTypeError1(theEnv,"funcall",1,"function, deffunction, or generic function name");
1261
+ return;
1262
+ }
1263
+
1264
+ /*====================================*/
1265
+ /* Functions with specialized parsers */
1266
+ /* cannot be used with funcall. */
1267
+ /*====================================*/
1268
+
1269
+ if (theReference.type == FCALL)
1270
+ {
1271
+ theFunction = FindFunction(theEnv,name);
1272
+ if (theFunction->parser != NULL)
1273
+ {
1274
+ ExpectedTypeError1(theEnv,"funcall",1,"function without specialized parser");
1275
+ return;
1276
+ }
1277
+ }
1278
+
1279
+ /*======================================*/
1280
+ /* Add the arguments to the expression. */
1281
+ /*======================================*/
1282
+
1283
+ ExpressionInstall(theEnv,&theReference);
1284
+
1285
+ while (UDFHasNextArgument(context))
1286
+ {
1287
+ if (! UDFNextArgument(context,ANY_TYPE_BITS,&theArg))
1288
+ {
1289
+ ExpressionDeinstall(theEnv,&theReference);
1290
+ return;
1291
+ }
1292
+
1293
+ switch(theArg.header->type)
1294
+ {
1295
+ case MULTIFIELD_TYPE:
1296
+ nextAdd = GenConstant(theEnv,FCALL,FindFunction(theEnv,"create$"));
1297
+
1298
+ if (lastAdd == NULL)
1299
+ { theReference.argList = nextAdd; }
1300
+ else
1301
+ { lastAdd->nextArg = nextAdd; }
1302
+ lastAdd = nextAdd;
1303
+
1304
+ multiAdd = NULL;
1305
+ theMultifield = theArg.multifieldValue;
1306
+ for (j = theArg.begin; j < (theArg.begin + theArg.range); j++)
1307
+ {
1308
+ nextAdd = GenConstant(theEnv,theMultifield->contents[j].header->type,
1309
+ theMultifield->contents[j].value);
1310
+ if (multiAdd == NULL)
1311
+ { lastAdd->argList = nextAdd; }
1312
+ else
1313
+ { multiAdd->nextArg = nextAdd; }
1314
+ multiAdd = nextAdd;
1315
+ }
1316
+
1317
+ ExpressionInstall(theEnv,lastAdd);
1318
+ break;
1319
+
1320
+ default:
1321
+ nextAdd = GenConstant(theEnv,theArg.header->type,theArg.value);
1322
+ if (lastAdd == NULL)
1323
+ { theReference.argList = nextAdd; }
1324
+ else
1325
+ { lastAdd->nextArg = nextAdd; }
1326
+ lastAdd = nextAdd;
1327
+ ExpressionInstall(theEnv,lastAdd);
1328
+ break;
1329
+ }
1330
+ }
1331
+
1332
+ /*===========================================================*/
1333
+ /* Verify a deffunction has the correct number of arguments. */
1334
+ /*===========================================================*/
1335
+
1336
+ #if DEFFUNCTION_CONSTRUCT
1337
+ if (theReference.type == PCALL)
1338
+ {
1339
+ if (CheckDeffunctionCall(theEnv,(Deffunction *) theReference.value,CountArguments(theReference.argList)) == false)
1340
+ {
1341
+ PrintErrorID(theEnv,"MISCFUN",4,false);
1342
+ WriteString(theEnv,STDERR,"Function 'funcall' called with the wrong number of arguments for deffunction '");
1343
+ WriteString(theEnv,STDERR,DeffunctionName((Deffunction *) theReference.value));
1344
+ WriteString(theEnv,STDERR,"'.\n");
1345
+ ExpressionDeinstall(theEnv,&theReference);
1346
+ ReturnExpression(theEnv,theReference.argList);
1347
+ return;
1348
+ }
1349
+ }
1350
+ #endif
1351
+
1352
+ /*=========================================*/
1353
+ /* Verify the correct number of arguments. */
1354
+ /*=========================================*/
1355
+
1356
+ // TBD Support run time check of arguments
1357
+ #if ! RUN_TIME
1358
+ if (theReference.type == FCALL)
1359
+ {
1360
+ if (CheckExpressionAgainstRestrictions(theEnv,&theReference,theFunction,name))
1361
+ {
1362
+ ExpressionDeinstall(theEnv,&theReference);
1363
+ ReturnExpression(theEnv,theReference.argList);
1364
+ return;
1365
+ }
1366
+ }
1367
+ #endif
1368
+
1369
+ /*======================*/
1370
+ /* Call the expression. */
1371
+ /*======================*/
1372
+
1373
+ EvaluateExpression(theEnv,&theReference,returnValue);
1374
+
1375
+ /*========================================*/
1376
+ /* Return the expression data structures. */
1377
+ /*========================================*/
1378
+
1379
+ ExpressionDeinstall(theEnv,&theReference);
1380
+ ReturnExpression(theEnv,theReference.argList);
1381
+ }
1382
+
1383
+ /***********************************/
1384
+ /* NewFunction: H/L access routine */
1385
+ /* for the new function. */
1386
+ /***********************************/
1387
+ void NewFunction(
1388
+ Environment *theEnv,
1389
+ UDFContext *context,
1390
+ UDFValue *returnValue)
1391
+ {
1392
+ int theType;
1393
+ UDFValue theValue;
1394
+ const char *name;
1395
+
1396
+ /*==================================*/
1397
+ /* Set up the default return value. */
1398
+ /*==================================*/
1399
+
1400
+ returnValue->lexemeValue = FalseSymbol(theEnv);
1401
+
1402
+ /*====================================*/
1403
+ /* Get the name of the language type. */
1404
+ /*====================================*/
1405
+
1406
+ if (! UDFFirstArgument(context,SYMBOL_BIT,&theValue))
1407
+ { return; }
1408
+
1409
+ /*=========================*/
1410
+ /* Find the language type. */
1411
+ /*=========================*/
1412
+
1413
+ name = theValue.lexemeValue->contents;
1414
+
1415
+ theType = FindLanguageType(theEnv,name);
1416
+
1417
+ if (theType == -1)
1418
+ {
1419
+ ExpectedTypeError1(theEnv,"new",1,"external language");
1420
+ return;
1421
+ }
1422
+
1423
+ /*====================================================*/
1424
+ /* Invoke the new function for the specific language. */
1425
+ /*====================================================*/
1426
+
1427
+ if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
1428
+ (EvaluationData(theEnv)->ExternalAddressTypes[theType]->newFunction != NULL))
1429
+ { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->newFunction)(context,returnValue); }
1430
+ }
1431
+
1432
+ /************************************/
1433
+ /* CallFunction: H/L access routine */
1434
+ /* for the new function. */
1435
+ /************************************/
1436
+ void CallFunction(
1437
+ Environment *theEnv,
1438
+ UDFContext *context,
1439
+ UDFValue *returnValue)
1440
+ {
1441
+ int theType;
1442
+ UDFValue theValue;
1443
+ const char *name;
1444
+ CLIPSExternalAddress *theEA;
1445
+
1446
+ /*==================================*/
1447
+ /* Set up the default return value. */
1448
+ /*==================================*/
1449
+
1450
+ returnValue->lexemeValue = FalseSymbol(theEnv);
1451
+
1452
+ /*=========================*/
1453
+ /* Get the first argument. */
1454
+ /*=========================*/
1455
+
1456
+ if (! UDFFirstArgument(context,SYMBOL_BIT | EXTERNAL_ADDRESS_BIT,&theValue))
1457
+ { return; }
1458
+
1459
+ /*============================================*/
1460
+ /* If the first argument is a symbol, then it */
1461
+ /* should be an external language type. */
1462
+ /*============================================*/
1463
+
1464
+ if (theValue.header->type == SYMBOL_TYPE)
1465
+ {
1466
+ name = theValue.lexemeValue->contents;
1467
+
1468
+ theType = FindLanguageType(theEnv,name);
1469
+
1470
+ if (theType == -1)
1471
+ {
1472
+ ExpectedTypeError1(theEnv,"call",1,"external language symbol or external address");
1473
+ return;
1474
+ }
1475
+
1476
+ /*====================================================================*/
1477
+ /* Invoke the call function for the specific language. Typically this */
1478
+ /* will invoke a static method of a class (specified with the third */
1479
+ /* and second arguments to the call function. */
1480
+ /*====================================================================*/
1481
+
1482
+ if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
1483
+ (EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction != NULL))
1484
+ { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction)(context,&theValue,returnValue); }
1485
+
1486
+ return;
1487
+ }
1488
+
1489
+ /*===============================================*/
1490
+ /* If the first argument is an external address, */
1491
+ /* then we can determine the external language */
1492
+ /* type be examining the pointer. */
1493
+ /*===============================================*/
1494
+
1495
+ if (theValue.header->type == EXTERNAL_ADDRESS_TYPE)
1496
+ {
1497
+ theEA = theValue.externalAddressValue;
1498
+
1499
+ theType = theEA->type;
1500
+
1501
+ if ((EvaluationData(theEnv)->ExternalAddressTypes[theType] != NULL) &&
1502
+ (EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction != NULL))
1503
+ { (*EvaluationData(theEnv)->ExternalAddressTypes[theType]->callFunction)(context,&theValue,returnValue); }
1504
+
1505
+ return;
1506
+ }
1507
+ }
1508
+
1509
+ /*********************/
1510
+ /* FindLanguageType: */
1511
+ /*********************/
1512
+ static int FindLanguageType(
1513
+ Environment *theEnv,
1514
+ const char *languageName)
1515
+ {
1516
+ int theType;
1517
+
1518
+ for (theType = 0; theType < EvaluationData(theEnv)->numberOfAddressTypes; theType++)
1519
+ {
1520
+ if (strcmp(EvaluationData(theEnv)->ExternalAddressTypes[theType]->name,languageName) == 0)
1521
+ { return(theType); }
1522
+ }
1523
+
1524
+ return -1;
1525
+ }
1526
+
1527
+ /************************************/
1528
+ /* TimeFunction: H/L access routine */
1529
+ /* for the time function. */
1530
+ /************************************/
1531
+ void TimeFunction(
1532
+ Environment *theEnv,
1533
+ UDFContext *context,
1534
+ UDFValue *returnValue)
1535
+ {
1536
+ /*==================*/
1537
+ /* Return the time. */
1538
+ /*==================*/
1539
+
1540
+ returnValue->floatValue = CreateFloat(theEnv,gentime());
1541
+ }
1542
+
1543
+ /****************************************/
1544
+ /* ConvertTime: Function for converting */
1545
+ /* time for local-time and gm-time. */
1546
+ /****************************************/
1547
+ static void ConvertTime(
1548
+ Environment *theEnv,
1549
+ UDFValue *returnValue,
1550
+ struct tm *info)
1551
+ {
1552
+ returnValue->begin = 0;
1553
+ returnValue->range = 9;
1554
+ returnValue->value = CreateMultifield(theEnv,9L);
1555
+
1556
+ returnValue->multifieldValue->contents[0].integerValue = CreateInteger(theEnv,info->tm_year + 1900);
1557
+ returnValue->multifieldValue->contents[1].integerValue = CreateInteger(theEnv,info->tm_mon + 1);
1558
+ returnValue->multifieldValue->contents[2].integerValue = CreateInteger(theEnv,info->tm_mday);
1559
+ returnValue->multifieldValue->contents[3].integerValue = CreateInteger(theEnv,info->tm_hour);
1560
+ returnValue->multifieldValue->contents[4].integerValue = CreateInteger(theEnv,info->tm_min);
1561
+ returnValue->multifieldValue->contents[5].integerValue = CreateInteger(theEnv,info->tm_sec);
1562
+
1563
+ switch (info->tm_wday)
1564
+ {
1565
+ case 0:
1566
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Sunday");
1567
+ break;
1568
+
1569
+ case 1:
1570
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Monday");
1571
+ break;
1572
+
1573
+ case 2:
1574
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Tuesday");
1575
+ break;
1576
+
1577
+ case 3:
1578
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Wednesday");
1579
+ break;
1580
+
1581
+ case 4:
1582
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Thursday");
1583
+ break;
1584
+
1585
+ case 5:
1586
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Friday");
1587
+ break;
1588
+
1589
+ case 6:
1590
+ returnValue->multifieldValue->contents[6].lexemeValue = CreateSymbol(theEnv,"Saturday");
1591
+ break;
1592
+ }
1593
+
1594
+ returnValue->multifieldValue->contents[7].integerValue = CreateInteger(theEnv,info->tm_yday);
1595
+
1596
+ if (info->tm_isdst > 0)
1597
+ { returnValue->multifieldValue->contents[8].lexemeValue = TrueSymbol(theEnv); }
1598
+ else if (info->tm_isdst == 0)
1599
+ { returnValue->multifieldValue->contents[8].lexemeValue = FalseSymbol(theEnv); }
1600
+ else
1601
+ { returnValue->multifieldValue->contents[8].lexemeValue = CreateSymbol(theEnv,"UNKNOWN"); }
1602
+ }
1603
+
1604
+ /*****************************************/
1605
+ /* LocalTimeFunction: H/L access routine */
1606
+ /* for the local-time function. */
1607
+ /*****************************************/
1608
+ void LocalTimeFunction(
1609
+ Environment *theEnv,
1610
+ UDFContext *context,
1611
+ UDFValue *returnValue)
1612
+ {
1613
+ time_t rawtime;
1614
+ struct tm *info;
1615
+
1616
+ /*=====================*/
1617
+ /* Get the local time. */
1618
+ /*=====================*/
1619
+
1620
+ time(&rawtime);
1621
+ info = localtime(&rawtime);
1622
+
1623
+ ConvertTime(theEnv,returnValue,info);
1624
+ }
1625
+
1626
+ /**************************************/
1627
+ /* GMTimeFunction: H/L access routine */
1628
+ /* for the gm-time function. */
1629
+ /**************************************/
1630
+ void GMTimeFunction(
1631
+ Environment *theEnv,
1632
+ UDFContext *context,
1633
+ UDFValue *returnValue)
1634
+ {
1635
+ time_t rawtime;
1636
+ struct tm *info;
1637
+
1638
+ /*=====================*/
1639
+ /* Get the local time. */
1640
+ /*=====================*/
1641
+
1642
+ time(&rawtime);
1643
+ info = gmtime(&rawtime);
1644
+
1645
+ ConvertTime(theEnv,returnValue,info);
1646
+ }
1647
+
1648
+ /***************************************/
1649
+ /* TimerFunction: H/L access routine */
1650
+ /* for the timer function. */
1651
+ /***************************************/
1652
+ void TimerFunction(
1653
+ Environment *theEnv,
1654
+ UDFContext *context,
1655
+ UDFValue *returnValue)
1656
+ {
1657
+ double startTime;
1658
+ UDFValue theArg;
1659
+
1660
+ startTime = gentime();
1661
+
1662
+ while (UDFHasNextArgument(context) &&
1663
+ (! GetHaltExecution(theEnv)))
1664
+ { UDFNextArgument(context,ANY_TYPE_BITS,&theArg); }
1665
+
1666
+ returnValue->floatValue = CreateFloat(theEnv,gentime() - startTime);
1667
+ }
1668
+
1669
+ #if SYSTEM_FUNCTION
1670
+ /***************************************/
1671
+ /* SystemCommand: H/L access routine */
1672
+ /* for the system function. */
1673
+ /***************************************/
1674
+ void SystemCommand(
1675
+ Environment *theEnv,
1676
+ UDFContext *context,
1677
+ UDFValue *returnValue)
1678
+ {
1679
+ char *commandBuffer = NULL;
1680
+ size_t bufferPosition = 0;
1681
+ size_t bufferMaximum = 0;
1682
+ UDFValue tempValue;
1683
+ const char *theString;
1684
+
1685
+ /*============================================================*/
1686
+ /* Concatenate the arguments together to form a single string */
1687
+ /* containing the command to be sent to the operating system. */
1688
+ /*============================================================*/
1689
+
1690
+ while (UDFHasNextArgument(context))
1691
+ {
1692
+ if (! UDFNextArgument(context,LEXEME_BITS,&tempValue))
1693
+ {
1694
+ returnValue->lexemeValue = FalseSymbol(theEnv);
1695
+ return;
1696
+ }
1697
+
1698
+ theString = tempValue.lexemeValue->contents;
1699
+
1700
+ commandBuffer = AppendToString(theEnv,theString,commandBuffer,&bufferPosition,&bufferMaximum);
1701
+ }
1702
+
1703
+ /*=======================================*/
1704
+ /* Execute the operating system command. */
1705
+ /*=======================================*/
1706
+
1707
+ returnValue->integerValue = CreateInteger(theEnv,gensystem(theEnv,commandBuffer));
1708
+
1709
+ /*==================================================*/
1710
+ /* Return the string buffer containing the command. */
1711
+ /*==================================================*/
1712
+
1713
+ if (commandBuffer != NULL)
1714
+ { rm(theEnv,commandBuffer,bufferMaximum); }
1715
+ }
1716
+ #endif
1717
+
1718
+ /****************************************/
1719
+ /* GetErrorFunction: H/L access routine */
1720
+ /* for the geterror function. */
1721
+ /****************************************/
1722
+ void GetErrorFunction(
1723
+ Environment *theEnv,
1724
+ UDFContext *context,
1725
+ UDFValue *returnValue)
1726
+ {
1727
+ CLIPSToUDFValue(&MiscFunctionData(theEnv)->errorCode,returnValue);
1728
+ }
1729
+
1730
+ /*****************/
1731
+ /* SetErrorValue */
1732
+ /*****************/
1733
+ void SetErrorValue(
1734
+ Environment *theEnv,
1735
+ TypeHeader *theValue)
1736
+ {
1737
+ Release(theEnv,MiscFunctionData(theEnv)->errorCode.header);
1738
+
1739
+ if (theValue == NULL)
1740
+ { MiscFunctionData(theEnv)->errorCode.lexemeValue = FalseSymbol(theEnv); }
1741
+ else
1742
+ { MiscFunctionData(theEnv)->errorCode.header = theValue; }
1743
+
1744
+ Retain(theEnv,MiscFunctionData(theEnv)->errorCode.header);
1745
+ }
1746
+
1747
+ /*******************/
1748
+ /* ClearErrorValue */
1749
+ /*******************/
1750
+ void ClearErrorValue(
1751
+ Environment *theEnv)
1752
+ {
1753
+ Release(theEnv,MiscFunctionData(theEnv)->errorCode.header);
1754
+ MiscFunctionData(theEnv)->errorCode.lexemeValue = FalseSymbol(theEnv);
1755
+ Retain(theEnv,MiscFunctionData(theEnv)->errorCode.header);
1756
+ }
1757
+
1758
+ /******************************************/
1759
+ /* ClearErrorFunction: H/L access routine */
1760
+ /* for the clear-error function. */
1761
+ /******************************************/
1762
+ void ClearErrorFunction(
1763
+ Environment *theEnv,
1764
+ UDFContext *context,
1765
+ UDFValue *returnValue)
1766
+ {
1767
+ CLIPSToUDFValue(&MiscFunctionData(theEnv)->errorCode,returnValue);
1768
+ ClearErrorValue(theEnv);
1769
+ }
1770
+
1771
+ /****************************************/
1772
+ /* SetErrorFunction: H/L access routine */
1773
+ /* for the set-error function. */
1774
+ /****************************************/
1775
+ void SetErrorFunction(
1776
+ Environment *theEnv,
1777
+ UDFContext *context,
1778
+ UDFValue *returnValue)
1779
+ {
1780
+ CLIPSValue cv;
1781
+ UDFValue theArg;
1782
+
1783
+ if (! UDFFirstArgument(context,ANY_TYPE_BITS,&theArg))
1784
+ { return; }
1785
+
1786
+ NormalizeMultifield(theEnv,&theArg);
1787
+ cv.value = theArg.value;
1788
+ SetErrorValue(theEnv,cv.header);
1789
+ }
1790
+
1791
+ /************************************/
1792
+ /* VoidFunction: H/L access routine */
1793
+ /* for the void function. */
1794
+ /************************************/
1795
+ void VoidFunction(
1796
+ Environment *theEnv,
1797
+ UDFContext *context,
1798
+ UDFValue *returnValue)
1799
+ {
1800
+ returnValue->voidValue = VoidConstant(theEnv);
1801
+ }