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,1217 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 05/03/19 */
5
+ /* */
6
+ /* COMMAND LINE MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Provides a set of routines for processing */
11
+ /* commands entered at the top level prompt. */
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: Renamed BOOLEAN macro type to intBool. */
22
+ /* */
23
+ /* Refactored several functions and added */
24
+ /* additional functions for use by an interface */
25
+ /* layered on top of CLIPS. */
26
+ /* */
27
+ /* 6.30: Local variables set with the bind function */
28
+ /* persist until a reset/clear command is issued. */
29
+ /* */
30
+ /* Changed garbage collection algorithm. */
31
+ /* */
32
+ /* Changed integer type/precision. */
33
+ /* */
34
+ /* Metrowerks CodeWarrior (MAC_MCW, IBM_MCW) is */
35
+ /* no longer supported. */
36
+ /* */
37
+ /* UTF-8 support. */
38
+ /* */
39
+ /* Command history and editing support */
40
+ /* */
41
+ /* Used genstrcpy instead of strcpy. */
42
+ /* */
43
+ /* Added before command execution callback */
44
+ /* function. */
45
+ /* */
46
+ /* Fixed RouteCommand return value. */
47
+ /* */
48
+ /* Added AwaitingInput flag. */
49
+ /* */
50
+ /* Added const qualifiers to remove C++ */
51
+ /* deprecation warnings. */
52
+ /* */
53
+ /* Added code to keep track of pointers to */
54
+ /* constructs that are contained externally to */
55
+ /* to constructs, DanglingConstructs. */
56
+ /* */
57
+ /* Added STDOUT and STDIN logical name */
58
+ /* definitions. */
59
+ /* */
60
+ /* 6.40: Added call to FlushParsingMessages to clear */
61
+ /* message buffer after each command. */
62
+ /* */
63
+ /* Added Env prefix to GetEvaluationError and */
64
+ /* SetEvaluationError functions. */
65
+ /* */
66
+ /* Added Env prefix to GetHaltExecution and */
67
+ /* SetHaltExecution functions. */
68
+ /* */
69
+ /* Refactored code to reduce header dependencies */
70
+ /* in sysdep.c. */
71
+ /* */
72
+ /* Pragma once and other inclusion changes. */
73
+ /* */
74
+ /* Added support for booleans with <stdbool.h>. */
75
+ /* */
76
+ /* Removed use of void pointers for specific */
77
+ /* data structures. */
78
+ /* */
79
+ /* UDF redesign. */
80
+ /* */
81
+ /* Eval support for run time and bload only. */
82
+ /* */
83
+ /* Removed fflush of stdin. */
84
+ /* */
85
+ /* Use of ?<var>, $?<var>, ?*<var>, and $?*var* */
86
+ /* by itself at the command prompt and within */
87
+ /* the eval function now consistently returns the */
88
+ /* value of the variable. */
89
+ /* */
90
+ /*************************************************************/
91
+
92
+ #include <stdio.h>
93
+ #include <string.h>
94
+ #include <ctype.h>
95
+
96
+ #include "setup.h"
97
+ #include "constant.h"
98
+
99
+ #include "argacces.h"
100
+ #include "constrct.h"
101
+ #include "cstrcpsr.h"
102
+ #include "envrnmnt.h"
103
+ #include "exprnpsr.h"
104
+ #include "fileutil.h"
105
+ #include "memalloc.h"
106
+ #include "multifld.h"
107
+ #include "pprint.h"
108
+ #include "prcdrfun.h"
109
+ #include "prcdrpsr.h"
110
+ #include "prntutil.h"
111
+ #include "router.h"
112
+ #include "scanner.h"
113
+ #include "strngrtr.h"
114
+ #include "symbol.h"
115
+ #include "sysdep.h"
116
+ #include "utility.h"
117
+
118
+ #include "commline.h"
119
+
120
+ /***************/
121
+ /* DEFINITIONS */
122
+ /***************/
123
+
124
+ #define NO_SWITCH 0
125
+ #define BATCH_SWITCH 1
126
+ #define BATCH_STAR_SWITCH 2
127
+ #define LOAD_SWITCH 3
128
+
129
+ /***************************************/
130
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
131
+ /***************************************/
132
+
133
+ #if ! RUN_TIME
134
+ static int DoString(const char *,int,bool *);
135
+ static int DoComment(const char *,int);
136
+ static int DoWhiteSpace(const char *,int);
137
+ static void DefaultGetNextEvent(Environment *);
138
+ #endif
139
+ static void DeallocateCommandLineData(Environment *);
140
+
141
+ /****************************************************/
142
+ /* InitializeCommandLineData: Allocates environment */
143
+ /* data for command line functionality. */
144
+ /****************************************************/
145
+ void InitializeCommandLineData(
146
+ Environment *theEnv)
147
+ {
148
+ AllocateEnvironmentData(theEnv,COMMANDLINE_DATA,sizeof(struct commandLineData),DeallocateCommandLineData);
149
+
150
+ #if ! RUN_TIME
151
+ CommandLineData(theEnv)->BannerString = BANNER_STRING;
152
+ CommandLineData(theEnv)->EventCallback = DefaultGetNextEvent;
153
+ #endif
154
+ }
155
+
156
+ /*******************************************************/
157
+ /* DeallocateCommandLineData: Deallocates environment */
158
+ /* data for the command line functionality. */
159
+ /******************************************************/
160
+ static void DeallocateCommandLineData(
161
+ Environment *theEnv)
162
+ {
163
+ #if ! RUN_TIME
164
+ if (CommandLineData(theEnv)->CommandString != NULL)
165
+ { rm(theEnv,CommandLineData(theEnv)->CommandString,CommandLineData(theEnv)->MaximumCharacters); }
166
+
167
+ if (CommandLineData(theEnv)->CurrentCommand != NULL)
168
+ { ReturnExpression(theEnv,CommandLineData(theEnv)->CurrentCommand); }
169
+ #else
170
+ #if MAC_XCD
171
+ #pragma unused(theEnv)
172
+ #endif
173
+ #endif
174
+ }
175
+
176
+ /*************************************************/
177
+ /* RerouteStdin: Processes the -f, -f2, and -l */
178
+ /* options available on machines which support */
179
+ /* argc and arv command line options. */
180
+ /*************************************************/
181
+ void RerouteStdin(
182
+ Environment *theEnv,
183
+ int argc,
184
+ char *argv[])
185
+ {
186
+ int i;
187
+ int theSwitch = NO_SWITCH;
188
+
189
+ /*======================================*/
190
+ /* If there aren't enough arguments for */
191
+ /* the -f argument, then return. */
192
+ /*======================================*/
193
+
194
+ if (argc < 3)
195
+ { return; }
196
+
197
+ /*=====================================*/
198
+ /* If argv was not passed then return. */
199
+ /*=====================================*/
200
+
201
+ if (argv == NULL) return;
202
+
203
+ /*=============================================*/
204
+ /* Process each of the command line arguments. */
205
+ /*=============================================*/
206
+
207
+ for (i = 1 ; i < argc ; i++)
208
+ {
209
+ if (strcmp(argv[i],"-f") == 0) theSwitch = BATCH_SWITCH;
210
+ #if ! RUN_TIME
211
+ else if (strcmp(argv[i],"-f2") == 0) theSwitch = BATCH_STAR_SWITCH;
212
+ else if (strcmp(argv[i],"-l") == 0) theSwitch = LOAD_SWITCH;
213
+ #endif
214
+ else if (theSwitch == NO_SWITCH)
215
+ {
216
+ PrintErrorID(theEnv,"SYSDEP",2,false);
217
+ WriteString(theEnv,STDERR,"Invalid option '");
218
+ WriteString(theEnv,STDERR,argv[i]);
219
+ WriteString(theEnv,STDERR,"'.\n");
220
+ }
221
+
222
+ if (i > (argc-1))
223
+ {
224
+ PrintErrorID(theEnv,"SYSDEP",1,false);
225
+ WriteString(theEnv,STDERR,"No file found for '");
226
+
227
+ switch(theSwitch)
228
+ {
229
+ case BATCH_SWITCH:
230
+ WriteString(theEnv,STDERR,"-f");
231
+ break;
232
+
233
+ case BATCH_STAR_SWITCH:
234
+ WriteString(theEnv,STDERR,"-f2");
235
+ break;
236
+
237
+ case LOAD_SWITCH:
238
+ WriteString(theEnv,STDERR,"-l");
239
+ }
240
+
241
+ WriteString(theEnv,STDERR,"' option.\n");
242
+ return;
243
+ }
244
+
245
+ switch(theSwitch)
246
+ {
247
+ case BATCH_SWITCH:
248
+ OpenBatch(theEnv,argv[++i],true);
249
+ break;
250
+
251
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
252
+ case BATCH_STAR_SWITCH:
253
+ BatchStar(theEnv,argv[++i]);
254
+ break;
255
+
256
+ case LOAD_SWITCH:
257
+ Load(theEnv,argv[++i]);
258
+ break;
259
+ #endif
260
+ }
261
+ }
262
+ }
263
+
264
+ #if ! RUN_TIME
265
+
266
+ /***************************************************/
267
+ /* ExpandCommandString: Appends a character to the */
268
+ /* command string. Returns true if the command */
269
+ /* string was successfully expanded, otherwise */
270
+ /* false. Expanding the string also includes */
271
+ /* adding a backspace character which reduces */
272
+ /* string's length. */
273
+ /***************************************************/
274
+ bool ExpandCommandString(
275
+ Environment *theEnv,
276
+ int inchar)
277
+ {
278
+ size_t k;
279
+
280
+ k = RouterData(theEnv)->CommandBufferInputCount;
281
+ CommandLineData(theEnv)->CommandString = ExpandStringWithChar(theEnv,inchar,CommandLineData(theEnv)->CommandString,&RouterData(theEnv)->CommandBufferInputCount,
282
+ &CommandLineData(theEnv)->MaximumCharacters,CommandLineData(theEnv)->MaximumCharacters+80);
283
+ return((RouterData(theEnv)->CommandBufferInputCount != k) ? true : false);
284
+ }
285
+
286
+ /******************************************************************/
287
+ /* FlushCommandString: Empties the contents of the CommandString. */
288
+ /******************************************************************/
289
+ void FlushCommandString(
290
+ Environment *theEnv)
291
+ {
292
+ if (CommandLineData(theEnv)->CommandString != NULL) rm(theEnv,CommandLineData(theEnv)->CommandString,CommandLineData(theEnv)->MaximumCharacters);
293
+ CommandLineData(theEnv)->CommandString = NULL;
294
+ CommandLineData(theEnv)->MaximumCharacters = 0;
295
+ RouterData(theEnv)->CommandBufferInputCount = 0;
296
+ RouterData(theEnv)->InputUngets = 0;
297
+ RouterData(theEnv)->AwaitingInput = true;
298
+ }
299
+
300
+ /*********************************************************************************/
301
+ /* SetCommandString: Sets the contents of the CommandString to a specific value. */
302
+ /*********************************************************************************/
303
+ void SetCommandString(
304
+ Environment *theEnv,
305
+ const char *str)
306
+ {
307
+ size_t length;
308
+
309
+ FlushCommandString(theEnv);
310
+ length = strlen(str);
311
+ CommandLineData(theEnv)->CommandString = (char *)
312
+ genrealloc(theEnv,CommandLineData(theEnv)->CommandString,
313
+ CommandLineData(theEnv)->MaximumCharacters,
314
+ CommandLineData(theEnv)->MaximumCharacters + length + 1);
315
+
316
+ genstrcpy(CommandLineData(theEnv)->CommandString,str);
317
+ CommandLineData(theEnv)->MaximumCharacters += (length + 1);
318
+ RouterData(theEnv)->CommandBufferInputCount += length;
319
+ }
320
+
321
+ /*************************************************************/
322
+ /* SetNCommandString: Sets the contents of the CommandString */
323
+ /* to a specific value up to N characters. */
324
+ /*************************************************************/
325
+ void SetNCommandString(
326
+ Environment *theEnv,
327
+ const char *str,
328
+ unsigned length)
329
+ {
330
+ FlushCommandString(theEnv);
331
+ CommandLineData(theEnv)->CommandString = (char *)
332
+ genrealloc(theEnv,CommandLineData(theEnv)->CommandString,
333
+ CommandLineData(theEnv)->MaximumCharacters,
334
+ CommandLineData(theEnv)->MaximumCharacters + length + 1);
335
+
336
+ genstrncpy(CommandLineData(theEnv)->CommandString,str,length);
337
+ CommandLineData(theEnv)->CommandString[CommandLineData(theEnv)->MaximumCharacters + length] = 0;
338
+ CommandLineData(theEnv)->MaximumCharacters += (length + 1);
339
+ RouterData(theEnv)->CommandBufferInputCount += length;
340
+ }
341
+
342
+ /******************************************************************************/
343
+ /* AppendCommandString: Appends a value to the contents of the CommandString. */
344
+ /******************************************************************************/
345
+ void AppendCommandString(
346
+ Environment *theEnv,
347
+ const char *str)
348
+ {
349
+ CommandLineData(theEnv)->CommandString = AppendToString(theEnv,str,CommandLineData(theEnv)->CommandString,&RouterData(theEnv)->CommandBufferInputCount,&CommandLineData(theEnv)->MaximumCharacters);
350
+ }
351
+
352
+ /******************************************************************************/
353
+ /* InsertCommandString: Inserts a value in the contents of the CommandString. */
354
+ /******************************************************************************/
355
+ void InsertCommandString(
356
+ Environment *theEnv,
357
+ const char *str,
358
+ unsigned int position)
359
+ {
360
+ CommandLineData(theEnv)->CommandString =
361
+ InsertInString(theEnv,str,position,CommandLineData(theEnv)->CommandString,
362
+ &RouterData(theEnv)->CommandBufferInputCount,&CommandLineData(theEnv)->MaximumCharacters);
363
+ }
364
+
365
+ /************************************************************/
366
+ /* AppendNCommandString: Appends a value up to N characters */
367
+ /* to the contents of the CommandString. */
368
+ /************************************************************/
369
+ void AppendNCommandString(
370
+ Environment *theEnv,
371
+ const char *str,
372
+ unsigned length)
373
+ {
374
+ CommandLineData(theEnv)->CommandString = AppendNToString(theEnv,str,CommandLineData(theEnv)->CommandString,length,&RouterData(theEnv)->CommandBufferInputCount,&CommandLineData(theEnv)->MaximumCharacters);
375
+ }
376
+
377
+ /*****************************************************************************/
378
+ /* GetCommandString: Returns a pointer to the contents of the CommandString. */
379
+ /*****************************************************************************/
380
+ char *GetCommandString(
381
+ Environment *theEnv)
382
+ {
383
+ return(CommandLineData(theEnv)->CommandString);
384
+ }
385
+
386
+ /**************************************************************************/
387
+ /* CompleteCommand: Determines whether a string forms a complete command. */
388
+ /* A complete command is either a constant, a variable, or a function */
389
+ /* call which is followed (at some point) by a carriage return. Once a */
390
+ /* complete command is found (not including the parenthesis), */
391
+ /* extraneous parenthesis and other tokens are ignored. If a complete */
392
+ /* command exists, then 1 is returned. 0 is returned if the command was */
393
+ /* not complete and without errors. -1 is returned if the command */
394
+ /* contains an error. */
395
+ /**************************************************************************/
396
+ int CompleteCommand(
397
+ const char *mstring)
398
+ {
399
+ int i;
400
+ char inchar;
401
+ int depth = 0;
402
+ bool moreThanZero = false;
403
+ bool complete;
404
+ bool error = false;
405
+
406
+ if (mstring == NULL) return 0;
407
+
408
+ /*===================================================*/
409
+ /* Loop through each character of the command string */
410
+ /* to determine if there is a complete command. */
411
+ /*===================================================*/
412
+
413
+ i = 0;
414
+ while ((inchar = mstring[i++]) != EOS)
415
+ {
416
+ switch(inchar)
417
+ {
418
+ /*======================================================*/
419
+ /* If a carriage return or line feed is found, there is */
420
+ /* at least one completed token in the command buffer, */
421
+ /* and parentheses are balanced, then a complete */
422
+ /* command has been found. Otherwise, remove all white */
423
+ /* space beginning with the current character. */
424
+ /*======================================================*/
425
+
426
+ case '\n' :
427
+ case '\r' :
428
+ if (error) return(-1);
429
+ if (moreThanZero && (depth == 0)) return 1;
430
+ i = DoWhiteSpace(mstring,i);
431
+ break;
432
+
433
+ /*=====================*/
434
+ /* Remove white space. */
435
+ /*=====================*/
436
+
437
+ case ' ' :
438
+ case '\f' :
439
+ case '\t' :
440
+ i = DoWhiteSpace(mstring,i);
441
+ break;
442
+
443
+ /*======================================================*/
444
+ /* If the opening quotation of a string is encountered, */
445
+ /* determine if the closing quotation of the string is */
446
+ /* in the command buffer. Until the closing quotation */
447
+ /* is found, a complete command can not be made. */
448
+ /*======================================================*/
449
+
450
+ case '"' :
451
+ i = DoString(mstring,i,&complete);
452
+ if ((depth == 0) && complete) moreThanZero = true;
453
+ break;
454
+
455
+ /*====================*/
456
+ /* Process a comment. */
457
+ /*====================*/
458
+
459
+ case ';' :
460
+ i = DoComment(mstring,i);
461
+ if (moreThanZero && (depth == 0) && (mstring[i] != EOS))
462
+ {
463
+ if (error) return -1;
464
+ else return 1;
465
+ }
466
+ else if (mstring[i] != EOS) i++;
467
+ break;
468
+
469
+ /*====================================================*/
470
+ /* A left parenthesis increases the nesting depth of */
471
+ /* the current command by 1. Don't bother to increase */
472
+ /* the depth if the first token encountered was not */
473
+ /* a parenthesis (e.g. for the command string */
474
+ /* "red (+ 3 4", the symbol red already forms a */
475
+ /* complete command, so the next carriage return will */
476
+ /* cause evaluation of red--the closing parenthesis */
477
+ /* for "(+ 3 4" does not have to be found). */
478
+ /*====================================================*/
479
+
480
+ case '(' :
481
+ if ((depth > 0) || (moreThanZero == false))
482
+ {
483
+ depth++;
484
+ moreThanZero = true;
485
+ }
486
+ break;
487
+
488
+ /*====================================================*/
489
+ /* A right parenthesis decreases the nesting depth of */
490
+ /* the current command by 1. If the parenthesis is */
491
+ /* the first token of the command, then an error is */
492
+ /* generated. */
493
+ /*====================================================*/
494
+
495
+ case ')' :
496
+ if (depth > 0) depth--;
497
+ else if (moreThanZero == false) error = true;
498
+ break;
499
+
500
+ /*=====================================================*/
501
+ /* If the command begins with any other character and */
502
+ /* an opening parenthesis hasn't yet been found, then */
503
+ /* skip all characters on the same line. If a carriage */
504
+ /* return or line feed is found, then a complete */
505
+ /* command exists. */
506
+ /*=====================================================*/
507
+
508
+ default:
509
+ if (depth == 0)
510
+ {
511
+ if (IsUTF8MultiByteStart(inchar) || isprint(inchar))
512
+ {
513
+ while ((inchar = mstring[i++]) != EOS)
514
+ {
515
+ if ((inchar == '\n') || (inchar == '\r'))
516
+ {
517
+ if (error) return -1;
518
+ else return 1;
519
+ }
520
+ }
521
+ return 0;
522
+ }
523
+ }
524
+ break;
525
+ }
526
+ }
527
+
528
+ /*====================================================*/
529
+ /* Return 0 because a complete command was not found. */
530
+ /*====================================================*/
531
+
532
+ return 0;
533
+ }
534
+
535
+ /***********************************************************/
536
+ /* DoString: Skips over a string contained within a string */
537
+ /* until the closing quotation mark is encountered. */
538
+ /***********************************************************/
539
+ static int DoString(
540
+ const char *str,
541
+ int pos,
542
+ bool *complete)
543
+ {
544
+ int inchar;
545
+
546
+ /*=================================================*/
547
+ /* Process the string character by character until */
548
+ /* the closing quotation mark is found. */
549
+ /*=================================================*/
550
+
551
+ inchar = str[pos];
552
+ while (inchar != '"')
553
+ {
554
+ /*=====================================================*/
555
+ /* If a \ is found, then the next character is ignored */
556
+ /* even if it is a closing quotation mark. */
557
+ /*=====================================================*/
558
+
559
+ if (inchar == '\\')
560
+ {
561
+ pos++;
562
+ inchar = str[pos];
563
+ }
564
+
565
+ /*===================================================*/
566
+ /* If the end of input is reached before the closing */
567
+ /* quotation mark is found, the return the last */
568
+ /* position that was reached and indicate that a */
569
+ /* complete string was not found. */
570
+ /*===================================================*/
571
+
572
+ if (inchar == EOS)
573
+ {
574
+ *complete = false;
575
+ return(pos);
576
+ }
577
+
578
+ /*================================*/
579
+ /* Move on to the next character. */
580
+ /*================================*/
581
+
582
+ pos++;
583
+ inchar = str[pos];
584
+ }
585
+
586
+ /*======================================================*/
587
+ /* Indicate that a complete string was found and return */
588
+ /* the position of the closing quotation mark. */
589
+ /*======================================================*/
590
+
591
+ pos++;
592
+ *complete = true;
593
+ return(pos);
594
+ }
595
+
596
+ /*************************************************************/
597
+ /* DoComment: Skips over a comment contained within a string */
598
+ /* until a line feed or carriage return is encountered. */
599
+ /*************************************************************/
600
+ static int DoComment(
601
+ const char *str,
602
+ int pos)
603
+ {
604
+ int inchar;
605
+
606
+ inchar = str[pos];
607
+ while ((inchar != '\n') && (inchar != '\r'))
608
+ {
609
+ if (inchar == EOS)
610
+ { return(pos); }
611
+
612
+ pos++;
613
+ inchar = str[pos];
614
+ }
615
+
616
+ return(pos);
617
+ }
618
+
619
+ /**************************************************************/
620
+ /* DoWhiteSpace: Skips over white space consisting of spaces, */
621
+ /* tabs, and form feeds that is contained within a string. */
622
+ /**************************************************************/
623
+ static int DoWhiteSpace(
624
+ const char *str,
625
+ int pos)
626
+ {
627
+ int inchar;
628
+
629
+ inchar = str[pos];
630
+ while ((inchar == ' ') || (inchar == '\f') || (inchar == '\t'))
631
+ {
632
+ pos++;
633
+ inchar = str[pos];
634
+ }
635
+
636
+ return(pos);
637
+ }
638
+
639
+ /********************************************************************/
640
+ /* CommandLoop: Endless loop which waits for user commands and then */
641
+ /* executes them. The command loop will bypass the EventFunction */
642
+ /* if there is an active batch file. */
643
+ /********************************************************************/
644
+ void CommandLoop(
645
+ Environment *theEnv)
646
+ {
647
+ int inchar;
648
+
649
+ WriteString(theEnv,STDOUT,CommandLineData(theEnv)->BannerString);
650
+ SetHaltExecution(theEnv,false);
651
+ SetEvaluationError(theEnv,false);
652
+
653
+ CleanCurrentGarbageFrame(theEnv,NULL);
654
+ CallPeriodicTasks(theEnv);
655
+
656
+ PrintPrompt(theEnv);
657
+ RouterData(theEnv)->CommandBufferInputCount = 0;
658
+ RouterData(theEnv)->InputUngets = 0;
659
+ RouterData(theEnv)->AwaitingInput = true;
660
+
661
+ while (true)
662
+ {
663
+ /*===================================================*/
664
+ /* If a batch file is active, grab the command input */
665
+ /* directly from the batch file, otherwise call the */
666
+ /* event function. */
667
+ /*===================================================*/
668
+
669
+ if (BatchActive(theEnv) == true)
670
+ {
671
+ inchar = LLGetcBatch(theEnv,STDIN,true);
672
+ if (inchar == EOF)
673
+ { (*CommandLineData(theEnv)->EventCallback)(theEnv); }
674
+ else
675
+ { ExpandCommandString(theEnv,(char) inchar); }
676
+ }
677
+ else
678
+ { (*CommandLineData(theEnv)->EventCallback)(theEnv); }
679
+
680
+ /*=================================================*/
681
+ /* If execution was halted, then remove everything */
682
+ /* from the command buffer. */
683
+ /*=================================================*/
684
+
685
+ if (GetHaltExecution(theEnv) == true)
686
+ {
687
+ SetHaltExecution(theEnv,false);
688
+ SetEvaluationError(theEnv,false);
689
+ FlushCommandString(theEnv);
690
+ WriteString(theEnv,STDOUT,"\n");
691
+ PrintPrompt(theEnv);
692
+ }
693
+
694
+ /*=========================================*/
695
+ /* If a complete command is in the command */
696
+ /* buffer, then execute it. */
697
+ /*=========================================*/
698
+
699
+ ExecuteIfCommandComplete(theEnv);
700
+ }
701
+ }
702
+
703
+ /***********************************************************/
704
+ /* CommandLoopBatch: Loop which waits for commands from a */
705
+ /* batch file and then executes them. Returns when there */
706
+ /* are no longer any active batch files. */
707
+ /***********************************************************/
708
+ void CommandLoopBatch(
709
+ Environment *theEnv)
710
+ {
711
+ SetHaltExecution(theEnv,false);
712
+ SetEvaluationError(theEnv,false);
713
+
714
+ CleanCurrentGarbageFrame(theEnv,NULL);
715
+ CallPeriodicTasks(theEnv);
716
+
717
+ PrintPrompt(theEnv);
718
+ RouterData(theEnv)->CommandBufferInputCount = 0;
719
+ RouterData(theEnv)->InputUngets = 0;
720
+ RouterData(theEnv)->AwaitingInput = true;
721
+
722
+ CommandLoopBatchDriver(theEnv);
723
+ }
724
+
725
+ /************************************************************/
726
+ /* CommandLoopOnceThenBatch: Loop which waits for commands */
727
+ /* from a batch file and then executes them. Returns when */
728
+ /* there are no longer any active batch files. */
729
+ /************************************************************/
730
+ void CommandLoopOnceThenBatch(
731
+ Environment *theEnv)
732
+ {
733
+ if (! ExecuteIfCommandComplete(theEnv)) return;
734
+
735
+ CommandLoopBatchDriver(theEnv);
736
+ }
737
+
738
+ /*********************************************************/
739
+ /* CommandLoopBatchDriver: Loop which waits for commands */
740
+ /* from a batch file and then executes them. Returns */
741
+ /* when there are no longer any active batch files. */
742
+ /*********************************************************/
743
+ void CommandLoopBatchDriver(
744
+ Environment *theEnv)
745
+ {
746
+ int inchar;
747
+
748
+ while (true)
749
+ {
750
+ if (GetHaltCommandLoopBatch(theEnv) == true)
751
+ {
752
+ CloseAllBatchSources(theEnv);
753
+ SetHaltCommandLoopBatch(theEnv,false);
754
+ }
755
+
756
+ /*===================================================*/
757
+ /* If a batch file is active, grab the command input */
758
+ /* directly from the batch file, otherwise call the */
759
+ /* event function. */
760
+ /*===================================================*/
761
+
762
+ if (BatchActive(theEnv) == true)
763
+ {
764
+ inchar = LLGetcBatch(theEnv,STDIN,true);
765
+ if (inchar == EOF)
766
+ { return; }
767
+ else
768
+ { ExpandCommandString(theEnv,(char) inchar); }
769
+ }
770
+ else
771
+ { return; }
772
+
773
+ /*=================================================*/
774
+ /* If execution was halted, then remove everything */
775
+ /* from the command buffer. */
776
+ /*=================================================*/
777
+
778
+ if (GetHaltExecution(theEnv) == true)
779
+ {
780
+ SetHaltExecution(theEnv,false);
781
+ SetEvaluationError(theEnv,false);
782
+ FlushCommandString(theEnv);
783
+ WriteString(theEnv,STDOUT,"\n");
784
+ PrintPrompt(theEnv);
785
+ }
786
+
787
+ /*=========================================*/
788
+ /* If a complete command is in the command */
789
+ /* buffer, then execute it. */
790
+ /*=========================================*/
791
+
792
+ ExecuteIfCommandComplete(theEnv);
793
+ }
794
+ }
795
+
796
+ /**********************************************************/
797
+ /* ExecuteIfCommandComplete: Checks to determine if there */
798
+ /* is a completed command and if so executes it. */
799
+ /**********************************************************/
800
+ bool ExecuteIfCommandComplete(
801
+ Environment *theEnv)
802
+ {
803
+ if ((CompleteCommand(CommandLineData(theEnv)->CommandString) == 0) ||
804
+ (RouterData(theEnv)->CommandBufferInputCount == 0) ||
805
+ (RouterData(theEnv)->AwaitingInput == false))
806
+ { return false; }
807
+
808
+ if (CommandLineData(theEnv)->BeforeCommandExecutionCallback != NULL)
809
+ {
810
+ if (! (*CommandLineData(theEnv)->BeforeCommandExecutionCallback)(theEnv))
811
+ { return false; }
812
+ }
813
+
814
+ FlushPPBuffer(theEnv);
815
+ SetPPBufferStatus(theEnv,false);
816
+ RouterData(theEnv)->CommandBufferInputCount = 0;
817
+ RouterData(theEnv)->InputUngets = 0;
818
+ RouterData(theEnv)->AwaitingInput = false;
819
+ RouteCommand(theEnv,CommandLineData(theEnv)->CommandString,true);
820
+ FlushPPBuffer(theEnv);
821
+ #if (! BLOAD_ONLY)
822
+ FlushParsingMessages(theEnv);
823
+ #endif
824
+ SetHaltExecution(theEnv,false);
825
+ SetEvaluationError(theEnv,false);
826
+ FlushCommandString(theEnv);
827
+
828
+ CleanCurrentGarbageFrame(theEnv,NULL);
829
+ CallPeriodicTasks(theEnv);
830
+
831
+ PrintPrompt(theEnv);
832
+
833
+ return true;
834
+ }
835
+
836
+ /*******************************/
837
+ /* CommandCompleteAndNotEmpty: */
838
+ /*******************************/
839
+ bool CommandCompleteAndNotEmpty(
840
+ Environment *theEnv)
841
+ {
842
+ if ((CompleteCommand(CommandLineData(theEnv)->CommandString) == 0) ||
843
+ (RouterData(theEnv)->CommandBufferInputCount == 0) ||
844
+ (RouterData(theEnv)->AwaitingInput == false))
845
+ { return false; }
846
+
847
+ return true;
848
+ }
849
+
850
+ /*******************************************/
851
+ /* PrintPrompt: Prints the command prompt. */
852
+ /*******************************************/
853
+ void PrintPrompt(
854
+ Environment *theEnv)
855
+ {
856
+ WriteString(theEnv,STDOUT,COMMAND_PROMPT);
857
+
858
+ if (CommandLineData(theEnv)->AfterPromptCallback != NULL)
859
+ { (*CommandLineData(theEnv)->AfterPromptCallback)(theEnv); }
860
+ }
861
+
862
+ /*****************************************/
863
+ /* PrintBanner: Prints the CLIPS banner. */
864
+ /*****************************************/
865
+ void PrintBanner(
866
+ Environment *theEnv)
867
+ {
868
+ WriteString(theEnv,STDOUT,CommandLineData(theEnv)->BannerString);
869
+ }
870
+
871
+ /************************************************/
872
+ /* SetAfterPromptFunction: Replaces the current */
873
+ /* value of AfterPromptFunction. */
874
+ /************************************************/
875
+ void SetAfterPromptFunction(
876
+ Environment *theEnv,
877
+ AfterPromptFunction *funptr)
878
+ {
879
+ CommandLineData(theEnv)->AfterPromptCallback = funptr;
880
+ }
881
+
882
+ /***********************************************************/
883
+ /* SetBeforeCommandExecutionFunction: Replaces the current */
884
+ /* value of BeforeCommandExecutionFunction. */
885
+ /***********************************************************/
886
+ void SetBeforeCommandExecutionFunction(
887
+ Environment *theEnv,
888
+ BeforeCommandExecutionFunction *funptr)
889
+ {
890
+ CommandLineData(theEnv)->BeforeCommandExecutionCallback = funptr;
891
+ }
892
+
893
+ /*********************************************************/
894
+ /* RouteCommand: Processes a completed command. Returns */
895
+ /* true if a command could be parsed, otherwise false. */
896
+ /*********************************************************/
897
+ bool RouteCommand(
898
+ Environment *theEnv,
899
+ const char *command,
900
+ bool printResult)
901
+ {
902
+ UDFValue returnValue;
903
+ struct expr *top;
904
+ const char *commandName;
905
+ struct token theToken;
906
+ int danglingConstructs;
907
+
908
+ if (command == NULL)
909
+ { return false; }
910
+
911
+ /*========================================*/
912
+ /* Open a string input source and get the */
913
+ /* first token from that source. */
914
+ /*========================================*/
915
+
916
+ OpenStringSource(theEnv,"command",command,0);
917
+
918
+ GetToken(theEnv,"command",&theToken);
919
+
920
+ /*=====================*/
921
+ /* Evaluate constants. */
922
+ /*=====================*/
923
+
924
+ if ((theToken.tknType == SYMBOL_TOKEN) || (theToken.tknType == STRING_TOKEN) ||
925
+ (theToken.tknType == FLOAT_TOKEN) || (theToken.tknType == INTEGER_TOKEN) ||
926
+ (theToken.tknType == INSTANCE_NAME_TOKEN))
927
+ {
928
+ CloseStringSource(theEnv,"command");
929
+ if (printResult)
930
+ {
931
+ PrintAtom(theEnv,STDOUT,TokenTypeToType(theToken.tknType),theToken.value);
932
+ WriteString(theEnv,STDOUT,"\n");
933
+ }
934
+ return true;
935
+ }
936
+
937
+ /*=====================*/
938
+ /* Evaluate variables. */
939
+ /*=====================*/
940
+
941
+ if ((theToken.tknType == GBL_VARIABLE_TOKEN) ||
942
+ (theToken.tknType == MF_GBL_VARIABLE_TOKEN) ||
943
+ (theToken.tknType == SF_VARIABLE_TOKEN) ||
944
+ (theToken.tknType == MF_VARIABLE_TOKEN))
945
+ {
946
+ CloseStringSource(theEnv,"command");
947
+ top = GenConstant(theEnv,TokenTypeToType(theToken.tknType),theToken.value);
948
+ EvaluateExpression(theEnv,top,&returnValue);
949
+ rtn_struct(theEnv,expr,top);
950
+ if (printResult)
951
+ {
952
+ WriteUDFValue(theEnv,STDOUT,&returnValue);
953
+ WriteString(theEnv,STDOUT,"\n");
954
+ }
955
+ return true;
956
+ }
957
+
958
+ /*========================================================*/
959
+ /* If the next token isn't the beginning left parenthesis */
960
+ /* of a command or construct, then whatever was entered */
961
+ /* cannot be evaluated at the command prompt. */
962
+ /*========================================================*/
963
+
964
+ if (theToken.tknType != LEFT_PARENTHESIS_TOKEN)
965
+ {
966
+ PrintErrorID(theEnv,"COMMLINE",1,false);
967
+ WriteString(theEnv,STDERR,"Expected a '(', constant, or variable.\n");
968
+ CloseStringSource(theEnv,"command");
969
+ return false;
970
+ }
971
+
972
+ /*===========================================================*/
973
+ /* The next token must be a function name or construct type. */
974
+ /*===========================================================*/
975
+
976
+ GetToken(theEnv,"command",&theToken);
977
+ if (theToken.tknType != SYMBOL_TOKEN)
978
+ {
979
+ PrintErrorID(theEnv,"COMMLINE",2,false);
980
+ WriteString(theEnv,STDERR,"Expected a command.\n");
981
+ CloseStringSource(theEnv,"command");
982
+ return false;
983
+ }
984
+
985
+ commandName = theToken.lexemeValue->contents;
986
+
987
+ /*======================*/
988
+ /* Evaluate constructs. */
989
+ /*======================*/
990
+
991
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
992
+ {
993
+ BuildError errorFlag;
994
+
995
+ errorFlag = ParseConstruct(theEnv,commandName,"command");
996
+ if (errorFlag != BE_CONSTRUCT_NOT_FOUND_ERROR)
997
+ {
998
+ CloseStringSource(theEnv,"command");
999
+ if (errorFlag == BE_PARSING_ERROR)
1000
+ {
1001
+ WriteString(theEnv,STDERR,"\nERROR:\n");
1002
+ WriteString(theEnv,STDERR,GetPPBuffer(theEnv));
1003
+ WriteString(theEnv,STDERR,"\n");
1004
+ }
1005
+ DestroyPPBuffer(theEnv);
1006
+
1007
+ SetWarningFileName(theEnv,NULL);
1008
+ SetErrorFileName(theEnv,NULL);
1009
+
1010
+ if (errorFlag == BE_NO_ERROR) return true;
1011
+ else return false;
1012
+ }
1013
+ }
1014
+ #endif
1015
+
1016
+ /*========================*/
1017
+ /* Parse a function call. */
1018
+ /*========================*/
1019
+
1020
+ danglingConstructs = ConstructData(theEnv)->DanglingConstructs;
1021
+ CommandLineData(theEnv)->ParsingTopLevelCommand = true;
1022
+ top = Function2Parse(theEnv,"command",commandName);
1023
+ CommandLineData(theEnv)->ParsingTopLevelCommand = false;
1024
+ ClearParsedBindNames(theEnv);
1025
+
1026
+ /*================================*/
1027
+ /* Close the string input source. */
1028
+ /*================================*/
1029
+
1030
+ CloseStringSource(theEnv,"command");
1031
+
1032
+ /*=========================*/
1033
+ /* Evaluate function call. */
1034
+ /*=========================*/
1035
+
1036
+ if (top == NULL)
1037
+ {
1038
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
1039
+ SetWarningFileName(theEnv,NULL);
1040
+ SetErrorFileName(theEnv,NULL);
1041
+ #endif
1042
+ ConstructData(theEnv)->DanglingConstructs = danglingConstructs;
1043
+ return false;
1044
+ }
1045
+
1046
+ ExpressionInstall(theEnv,top);
1047
+
1048
+ CommandLineData(theEnv)->EvaluatingTopLevelCommand = true;
1049
+ CommandLineData(theEnv)->CurrentCommand = top;
1050
+ EvaluateExpression(theEnv,top,&returnValue);
1051
+ CommandLineData(theEnv)->CurrentCommand = NULL;
1052
+ CommandLineData(theEnv)->EvaluatingTopLevelCommand = false;
1053
+
1054
+ ExpressionDeinstall(theEnv,top);
1055
+ ReturnExpression(theEnv,top);
1056
+ ConstructData(theEnv)->DanglingConstructs = danglingConstructs;
1057
+
1058
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
1059
+ SetWarningFileName(theEnv,NULL);
1060
+ SetErrorFileName(theEnv,NULL);
1061
+ #endif
1062
+
1063
+ /*=================================================*/
1064
+ /* Print the return value of the function/command. */
1065
+ /*=================================================*/
1066
+
1067
+ if ((returnValue.header->type != VOID_TYPE) && printResult)
1068
+ {
1069
+ WriteUDFValue(theEnv,STDOUT,&returnValue);
1070
+ WriteString(theEnv,STDOUT,"\n");
1071
+ }
1072
+
1073
+ return true;
1074
+ }
1075
+
1076
+ /*****************************************************************/
1077
+ /* DefaultGetNextEvent: Default event-handling function. Handles */
1078
+ /* only keyboard events by first calling ReadRouter to get a */
1079
+ /* character and then calling ExpandCommandString to add the */
1080
+ /* character to the CommandString. */
1081
+ /*****************************************************************/
1082
+ static void DefaultGetNextEvent(
1083
+ Environment *theEnv)
1084
+ {
1085
+ int inchar;
1086
+
1087
+ inchar = ReadRouter(theEnv,STDIN);
1088
+
1089
+ if (inchar == EOF) inchar = '\n';
1090
+
1091
+ ExpandCommandString(theEnv,(char) inchar);
1092
+ }
1093
+
1094
+ /*************************************/
1095
+ /* SetEventFunction: Replaces the */
1096
+ /* current value of EventFunction. */
1097
+ /*************************************/
1098
+ EventFunction *SetEventFunction(
1099
+ Environment *theEnv,
1100
+ EventFunction *theFunction)
1101
+ {
1102
+ EventFunction *tmp_ptr;
1103
+
1104
+ tmp_ptr = CommandLineData(theEnv)->EventCallback;
1105
+ CommandLineData(theEnv)->EventCallback = theFunction;
1106
+ return tmp_ptr;
1107
+ }
1108
+
1109
+ /****************************************/
1110
+ /* TopLevelCommand: Indicates whether a */
1111
+ /* top-level command is being parsed. */
1112
+ /****************************************/
1113
+ bool TopLevelCommand(
1114
+ Environment *theEnv)
1115
+ {
1116
+ return(CommandLineData(theEnv)->ParsingTopLevelCommand);
1117
+ }
1118
+
1119
+ /***********************************************************/
1120
+ /* GetCommandCompletionString: Returns the last token in a */
1121
+ /* string if it is a valid token for command completion. */
1122
+ /***********************************************************/
1123
+ const char *GetCommandCompletionString(
1124
+ Environment *theEnv,
1125
+ const char *theString,
1126
+ size_t maxPosition)
1127
+ {
1128
+ struct token lastToken;
1129
+ struct token theToken;
1130
+ char lastChar;
1131
+ const char *rs;
1132
+ size_t length;
1133
+
1134
+ /*=========================*/
1135
+ /* Get the command string. */
1136
+ /*=========================*/
1137
+
1138
+ if (theString == NULL) return("");
1139
+
1140
+ /*=========================================================================*/
1141
+ /* If the last character in the command string is a space, character */
1142
+ /* return, or quotation mark, then the command completion can be anything. */
1143
+ /*=========================================================================*/
1144
+
1145
+ lastChar = theString[maxPosition - 1];
1146
+ if ((lastChar == ' ') || (lastChar == '"') ||
1147
+ (lastChar == '\t') || (lastChar == '\f') ||
1148
+ (lastChar == '\n') || (lastChar == '\r'))
1149
+ { return(""); }
1150
+
1151
+ /*============================================*/
1152
+ /* Find the last token in the command string. */
1153
+ /*============================================*/
1154
+
1155
+ OpenTextSource(theEnv,"CommandCompletion",theString,0,maxPosition);
1156
+ ScannerData(theEnv)->IgnoreCompletionErrors = true;
1157
+ GetToken(theEnv,"CommandCompletion",&theToken);
1158
+ CopyToken(&lastToken,&theToken);
1159
+ while (theToken.tknType != STOP_TOKEN)
1160
+ {
1161
+ CopyToken(&lastToken,&theToken);
1162
+ GetToken(theEnv,"CommandCompletion",&theToken);
1163
+ }
1164
+ CloseStringSource(theEnv,"CommandCompletion");
1165
+ ScannerData(theEnv)->IgnoreCompletionErrors = false;
1166
+
1167
+ /*===============================================*/
1168
+ /* Determine if the last token can be completed. */
1169
+ /*===============================================*/
1170
+
1171
+ if (lastToken.tknType == SYMBOL_TOKEN)
1172
+ {
1173
+ rs = lastToken.lexemeValue->contents;
1174
+ if (rs[0] == '[') return (&rs[1]);
1175
+ return lastToken.lexemeValue->contents;
1176
+ }
1177
+ else if (lastToken.tknType == SF_VARIABLE_TOKEN)
1178
+ { return lastToken.lexemeValue->contents; }
1179
+ else if (lastToken.tknType == MF_VARIABLE_TOKEN)
1180
+ { return lastToken.lexemeValue->contents; }
1181
+ else if ((lastToken.tknType == GBL_VARIABLE_TOKEN) ||
1182
+ (lastToken.tknType == MF_GBL_VARIABLE_TOKEN) ||
1183
+ (lastToken.tknType == INSTANCE_NAME_TOKEN))
1184
+ { return NULL; }
1185
+ else if (lastToken.tknType == STRING_TOKEN)
1186
+ {
1187
+ length = strlen(lastToken.lexemeValue->contents);
1188
+ return GetCommandCompletionString(theEnv,lastToken.lexemeValue->contents,length);
1189
+ }
1190
+ else if ((lastToken.tknType == FLOAT_TOKEN) ||
1191
+ (lastToken.tknType == INTEGER_TOKEN))
1192
+ { return NULL; }
1193
+
1194
+ return("");
1195
+ }
1196
+
1197
+ /****************************************************************/
1198
+ /* SetHaltCommandLoopBatch: Sets the HaltCommandLoopBatch flag. */
1199
+ /****************************************************************/
1200
+ void SetHaltCommandLoopBatch(
1201
+ Environment *theEnv,
1202
+ bool value)
1203
+ {
1204
+ CommandLineData(theEnv)->HaltCommandLoopBatch = value;
1205
+ }
1206
+
1207
+ /*******************************************************************/
1208
+ /* GetHaltCommandLoopBatch: Returns the HaltCommandLoopBatch flag. */
1209
+ /*******************************************************************/
1210
+ bool GetHaltCommandLoopBatch(
1211
+ Environment *theEnv)
1212
+ {
1213
+ return(CommandLineData(theEnv)->HaltCommandLoopBatch);
1214
+ }
1215
+
1216
+ #endif
1217
+