kibi-swipl-linux-x64-gnu 1.0.0

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 (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,1516 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jan Wielemaker
4
+ E-mail: J.Wielemaker@vu.nl
5
+ WWW: https://www.swi-prolog.org
6
+ Copyright (c) 1995-2025, University of Amsterdam
7
+ VU University Amsterdam
8
+ CWI, Amsterdam
9
+ SWI-Prolog Solutions b.v.
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions
14
+ are met:
15
+
16
+ 1. Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+
19
+ 2. Redistributions in binary form must reproduce the above copyright
20
+ notice, this list of conditions and the following disclaimer in
21
+ the documentation and/or other materials provided with the
22
+ distribution.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
+ POSSIBILITY OF SUCH DAMAGE.
36
+ */
37
+
38
+ :- module(qsave,
39
+ [ qsave_program/1, % +File
40
+ qsave_program/2 % +File, +Options
41
+ ]).
42
+ :- use_module(library(zip)).
43
+ :- use_module(library(lists)).
44
+ :- use_module(library(option)).
45
+ :- use_module(library(error)).
46
+ :- use_module(library(apply)).
47
+ :- autoload(library(shlib), [current_foreign_library/2]).
48
+ :- autoload(library(prolog_autoload), [autoload_all/1]).
49
+
50
+ /** <module> Save current program as a state or executable
51
+
52
+ This library provides qsave_program/1 and qsave_program/2, which are
53
+ also used by the commandline sequence below.
54
+
55
+ ==
56
+ swipl -o exe -c file.pl ...
57
+ ==
58
+ */
59
+
60
+ :- meta_predicate
61
+ qsave_program(+, :).
62
+
63
+ :- multifile error:has_type/2.
64
+ error:has_type(qsave_foreign_option, Term) :-
65
+ is_of_type(oneof([save, no_save, copy]), Term),
66
+ !.
67
+ error:has_type(qsave_foreign_option, arch(Archs)) :-
68
+ is_of_type(list(atom), Archs),
69
+ !.
70
+
71
+ save_option(stack_limit, integer,
72
+ "Stack limit (bytes)").
73
+ save_option(goal, callable,
74
+ "Main initialization goal").
75
+ save_option(toplevel, callable,
76
+ "Toplevel goal").
77
+ save_option(init_file, atom,
78
+ "Application init file").
79
+ save_option(pce, boolean,
80
+ "Do (not) include the xpce graphics subsystem").
81
+ save_option(packs, boolean,
82
+ "Do (not) attach packs").
83
+ save_option(class, oneof([runtime,development,prolog]),
84
+ "Development state").
85
+ save_option(op, oneof([save,standard]),
86
+ "Save operators").
87
+ save_option(autoload, boolean,
88
+ "Resolve autoloadable predicates").
89
+ save_option(map, atom,
90
+ "File to report content of the state").
91
+ save_option(home, atom,
92
+ "Home directory to use for running SWI-Prolog").
93
+ save_option(stand_alone, boolean,
94
+ "Add emulator at start").
95
+ save_option(traditional, boolean,
96
+ "Use traditional mode").
97
+ save_option(emulator, ground,
98
+ "Emulator to use").
99
+ save_option(foreign, qsave_foreign_option,
100
+ "Include foreign code in state").
101
+ save_option(obfuscate, boolean,
102
+ "Obfuscate identifiers").
103
+ save_option(verbose, boolean,
104
+ "Be more verbose about the state creation").
105
+ save_option(undefined, oneof([ignore,error]),
106
+ "How to handle undefined predicates").
107
+ save_option(on_error, oneof([print,halt,status]),
108
+ "How to handle errors").
109
+ save_option(on_warning, oneof([print,halt,status]),
110
+ "How to handle warnings").
111
+ save_option(zip, boolean,
112
+ "If true, create a clean `.zip` file").
113
+
114
+ term_expansion(save_pred_options,
115
+ (:- predicate_options(qsave_program/2, 2, Options))) :-
116
+ findall(O,
117
+ ( save_option(Name, Type, _),
118
+ O =.. [Name,Type]
119
+ ),
120
+ Options).
121
+
122
+ save_pred_options.
123
+
124
+ :- set_prolog_flag(generate_debug_info, false).
125
+
126
+ :- dynamic
127
+ verbose/1,
128
+ saved_resource_file/1.
129
+ :- volatile
130
+ verbose/1, % contains a stream-handle
131
+ saved_resource_file/1.
132
+
133
+ %! qsave_program(+File) is det.
134
+ %! qsave_program(+File, :Options) is det.
135
+ %
136
+ % Make a saved state in file `File'.
137
+
138
+ qsave_program(File) :-
139
+ qsave_program(File, []).
140
+
141
+ qsave_program(FileBase, Options0) :-
142
+ meta_options(is_meta, Options0, Options1),
143
+ check_options(Options1),
144
+ exe_file(FileBase, File, Options1),
145
+ option(class(SaveClass), Options1, runtime),
146
+ qsave_init_file_option(SaveClass, Options1, Options),
147
+ prepare_entry_points(Options),
148
+ save_autoload(Options),
149
+ qsave_state(File, SaveClass, Options).
150
+
151
+ qsave_state(File, SaveClass, Options) :-
152
+ system_specific_join(Join, Options),
153
+ !,
154
+ current_prolog_flag(pid, PID),
155
+ format(atom(ZipFile), '_swipl_state_~d.zip', [PID]),
156
+ qsave_state(ZipFile, SaveClass, [zip(true)|Options]),
157
+ emulator(Emulator, Options),
158
+ call_cleanup(
159
+ join_exe_and_state(Join, Emulator, ZipFile, File),
160
+ delete_file(ZipFile)).
161
+ qsave_state(File, SaveClass, Options) :-
162
+ setup_call_cleanup(
163
+ open_map(Options),
164
+ ( prepare_state(Options),
165
+ create_prolog_flag(saved_program, true, []),
166
+ create_prolog_flag(saved_program_class, SaveClass, []),
167
+ delete_if_exists(File), % truncate will crash a Prolog
168
+ % running on this state
169
+ setup_call_catcher_cleanup(
170
+ open(File, write, StateOut, [type(binary)]),
171
+ write_state(StateOut, SaveClass, File, Options),
172
+ Reason,
173
+ finalize_state(Reason, StateOut, File, Options))
174
+ ),
175
+ close_map),
176
+ cleanup.
177
+
178
+ write_state(StateOut, SaveClass, ExeFile, Options) :-
179
+ make_header(StateOut, SaveClass, Options),
180
+ setup_call_cleanup(
181
+ zip_open_stream(StateOut, RC, []),
182
+ write_zip_state(RC, SaveClass, ExeFile, Options),
183
+ zip_close(RC, [comment('SWI-Prolog saved state')])),
184
+ flush_output(StateOut).
185
+
186
+ write_zip_state(RC, SaveClass, ExeFile, Options) :-
187
+ save_options(RC, SaveClass, Options),
188
+ save_resources(RC, SaveClass),
189
+ lock_files(SaveClass),
190
+ save_program(RC, SaveClass, Options),
191
+ save_foreign_libraries(RC, ExeFile, Options).
192
+
193
+ %! finalize_state(+Status, +StateStream:stream, +File:atom, +Options)
194
+ %! is det.
195
+ %
196
+ % Fixpu the result. Normally closes StateStream used to create File
197
+ % and makes the file executable.
198
+
199
+ finalize_state(exit, StateOut, _File, Options) :-
200
+ option(zip(true), Options),
201
+ !,
202
+ close(StateOut).
203
+ finalize_state(exit, StateOut, File, _Options) :-
204
+ close(StateOut),
205
+ '$mark_executable'(File).
206
+ finalize_state(!, StateOut, File, Options) :-
207
+ print_message(warning, qsave(nondet)),
208
+ finalize_state(exit, StateOut, File, Options).
209
+ finalize_state(_, StateOut, File, _Options) :-
210
+ close(StateOut, [force(true)]),
211
+ catch(delete_file(File),
212
+ Error,
213
+ print_message(error, Error)).
214
+
215
+ cleanup :-
216
+ retractall(saved_resource_file(_)).
217
+
218
+ is_meta(goal).
219
+ is_meta(toplevel).
220
+
221
+ %! exe_file(+Base, -Exe, +Options) is det.
222
+ %
223
+ % True when Exe is the name of the file we create. This adds ``.exe``
224
+ % to the given name on Windows.
225
+
226
+ exe_file(Base, Exe, Options) :-
227
+ current_prolog_flag(windows, true),
228
+ option(stand_alone(true), Options, true),
229
+ file_name_extension(_, '', Base),
230
+ !,
231
+ file_name_extension(Base, exe, Exe).
232
+ exe_file(Base, Exe, Options) :-
233
+ option(zip(true), Options),
234
+ file_name_extension(_, '', Base),
235
+ !,
236
+ file_name_extension(Base, zip, Exe).
237
+ exe_file(Exe, Exe, _).
238
+
239
+ delete_if_exists(File) :-
240
+ ( exists_file(File)
241
+ -> delete_file(File)
242
+ ; true
243
+ ).
244
+
245
+ qsave_init_file_option(runtime, Options1, Options) :-
246
+ \+ option(init_file(_), Options1),
247
+ !,
248
+ Options = [init_file(none)|Options1].
249
+ qsave_init_file_option(_, Options, Options).
250
+
251
+ %! system_specific_join(-How, +Options) is semidet.
252
+ %
253
+ % Normally we create the saved state as a header with the zip file
254
+ % containing the actual state on its back. This is troublesome as the
255
+ % result looks like a normal executable, but does not satisfy the
256
+ % target system binary format. On some platforms we can do better and
257
+ % add the state as an additional section to the executable. This may
258
+ % fix issues using the executable with tools to manage binaries such
259
+ % as strip(1) or gdb.
260
+ %
261
+ % This predicate succeeds, indicating how to perform the join, if the
262
+ % current platform supports this feature. After the zip file is
263
+ % created, join_exe_and_state/4 is called to join the emulator to the
264
+ % zip file.
265
+
266
+ system_specific_join(objcopy(Prog), Options) :-
267
+ current_prolog_flag(executable_format, elf),
268
+ option(stand_alone(true), Options),
269
+ \+ option(zip(true), Options),
270
+ absolute_file_name(path(objcopy), Prog,
271
+ [ access(execute),
272
+ file_errors(fail)
273
+ ]).
274
+
275
+ %! join_exe_and_state(+How, +Emulator, +ZipFile, +Executable) is det.
276
+ %
277
+ % Create Executable by combining Emulator with ZipFile. Emulator must
278
+ % be a native binary. Typically it is `swipl`.
279
+ %
280
+ % Note that we use shell/1 rather than process_create/3. This would be
281
+ % easier, but we do not want dependencies on foreign code that is not
282
+ % needed.
283
+
284
+ join_exe_and_state(objcopy(Prog), Emulator, ZipFile, File) =>
285
+ copy_file(Emulator, File),
286
+ '$mark_executable'(File),
287
+ shell_quote(Prog, QProg),
288
+ shell_quote(ZipFile, QZipFile),
289
+ shell_quote(File, QFile),
290
+ format(string(Cmd),
291
+ '~w --add-section .zipdata=~w \c
292
+ --set-section-flags .zipdata=readonly,data \c
293
+ ~w',
294
+ [QProg, QZipFile, QFile]),
295
+ shell(Cmd).
296
+
297
+ copy_file(From, To) :-
298
+ setup_call_cleanup(
299
+ open(To, write, Out, [type(binary)]),
300
+ setup_call_cleanup(
301
+ open(From, read, In, [type(binary)]),
302
+ copy_stream_data(In, Out),
303
+ close(In)),
304
+ close(Out)).
305
+
306
+ %! shell_quote(+Arg, -QArg) is det.
307
+ %
308
+ % Quote argument against shell. Currently uses either single or double
309
+ % quotes and refuses names containing a single quote and a `$`. Should
310
+ % we ignore any name holding a quote or `$`?
311
+
312
+ shell_quote(Arg, QArg) :-
313
+ sub_atom(Arg, _, _, _, '\''),
314
+ !,
315
+ ( ( sub_atom(Arg, _, _, _, '"')
316
+ ; sub_atom(Arg, _, _, _, '$')
317
+ )
318
+ -> domain_error(save_file, Arg)
319
+ ; format(string(QArg), '"~w"', [Arg])
320
+ ).
321
+ shell_quote(Arg, QArg) :-
322
+ format(string(QArg), '\'~w\'', [Arg]).
323
+
324
+
325
+ /*******************************
326
+ * HEADER *
327
+ *******************************/
328
+
329
+ %! make_header(+Out:stream, +SaveClass, +Options) is det.
330
+ %
331
+ % Write the header after which we add the zip file. This is normally
332
+ % either ``swipl[.exe]`` or a shell script.
333
+
334
+ make_header(_Out, _, Options) :-
335
+ option(zip(true), Options),
336
+ !.
337
+ make_header(Out, _, Options) :-
338
+ stand_alone(Options),
339
+ !,
340
+ emulator(Emulator, Options),
341
+ setup_call_cleanup(
342
+ open(Emulator, read, In, [type(binary)]),
343
+ copy_stream_data(In, Out),
344
+ close(In)).
345
+ make_header(Out, SaveClass, Options) :-
346
+ current_prolog_flag(unix, true),
347
+ !,
348
+ emulator(Emulator, Options),
349
+ current_prolog_flag(posix_shell, Shell),
350
+ format(Out, '#!~w~n', [Shell]),
351
+ format(Out, '# SWI-Prolog saved state~n', []),
352
+ ( SaveClass == runtime
353
+ -> ArgSep = ' -- '
354
+ ; ArgSep = ' '
355
+ ),
356
+ format(Out, 'exec ${SWIPL:-~w} -x "$0"~w"$@"~n~n', [Emulator, ArgSep]).
357
+ make_header(_, _, _).
358
+
359
+ stand_alone(Options) :-
360
+ ( current_prolog_flag(windows, true)
361
+ -> DefStandAlone = true
362
+ ; DefStandAlone = false
363
+ ),
364
+ option(stand_alone(true), Options, DefStandAlone).
365
+
366
+ emulator(Emulator, Options) :-
367
+ ( option(emulator(OptVal), Options)
368
+ -> absolute_file_name(OptVal, [access(read)], Emulator)
369
+ ; current_prolog_flag(executable, Emulator)
370
+ ).
371
+
372
+
373
+
374
+ /*******************************
375
+ * OPTIONS *
376
+ *******************************/
377
+
378
+ min_stack(stack_limit, 100_000).
379
+
380
+ convert_option(Stack, Val, NewVal, '~w') :- % stack-sizes are in K-bytes
381
+ min_stack(Stack, Min),
382
+ !,
383
+ ( Val == 0
384
+ -> NewVal = Val
385
+ ; NewVal is max(Min, Val)
386
+ ).
387
+ convert_option(toplevel, Callable, Callable, '~q') :- !.
388
+ convert_option(_, Value, Value, '~w').
389
+
390
+ doption(Name) :- min_stack(Name, _).
391
+ doption(init_file).
392
+ doption(system_init_file).
393
+ doption(class).
394
+ doption(home).
395
+ doption(nosignals).
396
+
397
+ %! save_options(+ArchiveHandle, +SaveClass, +Options)
398
+ %
399
+ % Save the options in the '$options' resource. The home directory is
400
+ % saved for development states to make it keep refering to the
401
+ % development home.
402
+ %
403
+ % The script files (-s script) are not saved at all. I think this is
404
+ % fine to avoid a save-script loading itself.
405
+
406
+ save_options(RC, SaveClass, Options) :-
407
+ zipper_open_new_file_in_zip(RC, '$prolog/options.txt', Fd, []),
408
+ ( doption(OptionName),
409
+ ( OptTerm =.. [OptionName,OptionVal2],
410
+ option(OptTerm, Options)
411
+ -> convert_option(OptionName, OptionVal2, OptionVal, FmtVal)
412
+ ; '$cmd_option_val'(OptionName, OptionVal0),
413
+ save_option_value(SaveClass, OptionName, OptionVal0, OptionVal1),
414
+ OptionVal = OptionVal1,
415
+ FmtVal = '~w'
416
+ ),
417
+ atomics_to_string(['~w=', FmtVal, '~n'], Fmt),
418
+ format(Fd, Fmt, [OptionName, OptionVal]),
419
+ fail
420
+ ; true
421
+ ),
422
+ save_init_goals(Fd, Options),
423
+ close(Fd).
424
+
425
+ %! save_option_value(+SaveClass, +OptionName, +OptionValue, -FinalValue)
426
+
427
+ save_option_value(Class, class, _, Class) :- !.
428
+ save_option_value(runtime, home, _, _) :- !, fail.
429
+ save_option_value(_, _, Value, Value).
430
+
431
+ %! save_init_goals(+Stream, +Options)
432
+ %
433
+ % Save initialization goals. If there is a goal(Goal) option, use
434
+ % that, else save the goals from '$cmd_option_val'/2.
435
+
436
+ save_init_goals(Out, Options) :-
437
+ option(goal(Goal), Options),
438
+ !,
439
+ format(Out, 'goal=~q~n', [Goal]),
440
+ save_toplevel_goal(Out, halt, Options).
441
+ save_init_goals(Out, Options) :-
442
+ '$cmd_option_val'(goals, Goals),
443
+ forall(member(Goal, Goals),
444
+ format(Out, 'goal=~w~n', [Goal])),
445
+ ( Goals == []
446
+ -> DefToplevel = default
447
+ ; DefToplevel = halt
448
+ ),
449
+ save_toplevel_goal(Out, DefToplevel, Options).
450
+
451
+ save_toplevel_goal(Out, _Default, Options) :-
452
+ option(toplevel(Goal), Options),
453
+ !,
454
+ unqualify_reserved_goal(Goal, Goal1),
455
+ format(Out, 'toplevel=~q~n', [Goal1]).
456
+ save_toplevel_goal(Out, _Default, _Options) :-
457
+ '$cmd_option_val'(toplevel, Toplevel),
458
+ Toplevel \== default,
459
+ !,
460
+ format(Out, 'toplevel=~w~n', [Toplevel]).
461
+ save_toplevel_goal(Out, Default, _Options) :-
462
+ format(Out, 'toplevel=~q~n', [Default]).
463
+
464
+ unqualify_reserved_goal(_:prolog, prolog) :- !.
465
+ unqualify_reserved_goal(_:default, default) :- !.
466
+ unqualify_reserved_goal(Goal, Goal).
467
+
468
+
469
+ /*******************************
470
+ * RESOURCES *
471
+ *******************************/
472
+
473
+ save_resources(_RC, development) :- !.
474
+ save_resources(RC, _SaveClass) :-
475
+ feedback('~nRESOURCES~n~n', []),
476
+ copy_resources(RC),
477
+ forall(declared_resource(Name, FileSpec, Options),
478
+ save_resource(RC, Name, FileSpec, Options)).
479
+
480
+ declared_resource(RcName, FileSpec, []) :-
481
+ current_predicate(_, M:resource(_,_)),
482
+ M:resource(Name, FileSpec),
483
+ mkrcname(M, Name, RcName).
484
+ declared_resource(RcName, FileSpec, Options) :-
485
+ current_predicate(_, M:resource(_,_,_)),
486
+ M:resource(Name, A2, A3),
487
+ ( is_list(A3)
488
+ -> FileSpec = A2,
489
+ Options = A3
490
+ ; FileSpec = A3
491
+ ),
492
+ mkrcname(M, Name, RcName).
493
+
494
+ %! mkrcname(+Module, +NameSpec, -Name)
495
+ %
496
+ % Turn a resource name term into a resource name atom.
497
+
498
+ mkrcname(user, Name0, Name) :-
499
+ !,
500
+ path_segments_to_atom(Name0, Name).
501
+ mkrcname(M, Name0, RcName) :-
502
+ path_segments_to_atom(Name0, Name),
503
+ atomic_list_concat([M, :, Name], RcName).
504
+
505
+ path_segments_to_atom(Name0, Name) :-
506
+ phrase(segments_to_atom(Name0), Atoms),
507
+ atomic_list_concat(Atoms, /, Name).
508
+
509
+ segments_to_atom(Var) -->
510
+ { var(Var), !,
511
+ instantiation_error(Var)
512
+ }.
513
+ segments_to_atom(A/B) -->
514
+ !,
515
+ segments_to_atom(A),
516
+ segments_to_atom(B).
517
+ segments_to_atom(A) -->
518
+ [A].
519
+
520
+ %! save_resource(+Zipper, +Name, +FileSpec, +Options) is det.
521
+ %
522
+ % Add the content represented by FileSpec to Zipper under Name.
523
+
524
+ save_resource(RC, Name, FileSpec, _Options) :-
525
+ absolute_file_name(FileSpec,
526
+ [ access(read),
527
+ file_errors(fail)
528
+ ], File),
529
+ !,
530
+ feedback('~t~8|~w~t~32|~w~n',
531
+ [Name, File]),
532
+ zipper_append_file(RC, Name, File, []).
533
+ save_resource(RC, Name, FileSpec, Options) :-
534
+ findall(Dir,
535
+ absolute_file_name(FileSpec, Dir,
536
+ [ access(read),
537
+ file_type(directory),
538
+ file_errors(fail),
539
+ solutions(all)
540
+ ]),
541
+ Dirs),
542
+ Dirs \== [],
543
+ !,
544
+ forall(member(Dir, Dirs),
545
+ ( feedback('~t~8|~w~t~32|~w~n',
546
+ [Name, Dir]),
547
+ zipper_append_directory(RC, Name, Dir, Options))).
548
+ save_resource(RC, Name, _, _Options) :-
549
+ '$rc_handle'(SystemRC),
550
+ copy_resource(SystemRC, RC, Name),
551
+ !.
552
+ save_resource(_, Name, FileSpec, _Options) :-
553
+ print_message(warning,
554
+ error(existence_error(resource,
555
+ resource(Name, FileSpec)),
556
+ _)).
557
+
558
+ copy_resources(ToRC) :-
559
+ '$rc_handle'(FromRC),
560
+ zipper_members(FromRC, List),
561
+ ( member(Name, List),
562
+ \+ declared_resource(Name, _, _),
563
+ \+ reserved_resource(Name),
564
+ copy_resource(FromRC, ToRC, Name),
565
+ fail
566
+ ; true
567
+ ).
568
+
569
+ reserved_resource('$prolog/state.qlf').
570
+ reserved_resource('$prolog/options.txt').
571
+
572
+ copy_resource(FromRC, ToRC, Name) :-
573
+ ( zipper_goto(FromRC, file(Name))
574
+ -> true
575
+ ; existence_error(resource, Name)
576
+ ),
577
+ zipper_file_info(FromRC, _Name, Attrs),
578
+ get_dict(time, Attrs, Time),
579
+ setup_call_cleanup(
580
+ zipper_open_current(FromRC, FdIn,
581
+ [ type(binary),
582
+ time(Time)
583
+ ]),
584
+ setup_call_cleanup(
585
+ zipper_open_new_file_in_zip(ToRC, Name, FdOut, []),
586
+ ( feedback('~t~8|~w~t~24|~w~n',
587
+ [Name, '<Copied from running state>']),
588
+ copy_stream_data(FdIn, FdOut)
589
+ ),
590
+ close(FdOut)),
591
+ close(FdIn)).
592
+
593
+
594
+ /*******************************
595
+ * OBFUSCATE *
596
+ *******************************/
597
+
598
+ %! create_mapping(+Options) is det.
599
+ %
600
+ % Call hook to obfuscate symbols.
601
+
602
+ :- multifile prolog:obfuscate_identifiers/1.
603
+
604
+ create_mapping(Options) :-
605
+ option(obfuscate(true), Options),
606
+ !,
607
+ ( predicate_property(prolog:obfuscate_identifiers(_), number_of_clauses(N)),
608
+ N > 0
609
+ -> true
610
+ ; use_module(library(obfuscate))
611
+ ),
612
+ ( catch(prolog:obfuscate_identifiers(Options), E,
613
+ print_message(error, E))
614
+ -> true
615
+ ; print_message(warning, failed(obfuscate_identifiers))
616
+ ).
617
+ create_mapping(_).
618
+
619
+ %! lock_files(+SaveClass) is det.
620
+ %
621
+ % When saving as `runtime`, lock all files such that when running the
622
+ % program the system stops checking existence and modification time on
623
+ % the filesystem.
624
+ %
625
+ % @tbd `system` is a poor name. Maybe use `resource`?
626
+
627
+ lock_files(runtime) :-
628
+ !,
629
+ '$set_source_files'(system). % implies from_state
630
+ lock_files(_) :-
631
+ '$set_source_files'(from_state).
632
+
633
+ %! save_program(+Zipper, +SaveClass, +Options) is det.
634
+ %
635
+ % Save the program itself as virtual machine code to Zipper.
636
+
637
+ save_program(RC, SaveClass, Options) :-
638
+ setup_call_cleanup(
639
+ ( zipper_open_new_file_in_zip(RC, '$prolog/state.qlf', StateFd,
640
+ [ zip64(true)
641
+ ]),
642
+ current_prolog_flag(access_level, OldLevel),
643
+ set_prolog_flag(access_level, system), % generate system modules
644
+ '$open_wic'(StateFd, Options)
645
+ ),
646
+ ( create_mapping(Options),
647
+ save_modules(SaveClass),
648
+ save_records,
649
+ save_flags,
650
+ save_prompt,
651
+ save_imports,
652
+ save_prolog_flags(Options),
653
+ save_operators(Options),
654
+ save_format_predicates
655
+ ),
656
+ ( '$close_wic',
657
+ set_prolog_flag(access_level, OldLevel),
658
+ close(StateFd)
659
+ )).
660
+
661
+
662
+ /*******************************
663
+ * MODULES *
664
+ *******************************/
665
+
666
+ save_modules(SaveClass) :-
667
+ forall(special_module(X),
668
+ save_module(X, SaveClass)),
669
+ forall((current_module(X), \+ special_module(X)),
670
+ save_module(X, SaveClass)).
671
+
672
+ special_module(system).
673
+ special_module(user).
674
+
675
+
676
+ %! prepare_entry_points(+Options)
677
+ %
678
+ % Prepare the --goal=Goal and --toplevel=Goal options. Preparing
679
+ % implies autoloading the definition and declaring it _public_ such at
680
+ % it doesn't get obfuscated.
681
+
682
+ prepare_entry_points(Options) :-
683
+ define_init_goal(Options),
684
+ define_toplevel_goal(Options).
685
+
686
+ define_init_goal(Options) :-
687
+ option(goal(Goal), Options),
688
+ !,
689
+ entry_point(Goal).
690
+ define_init_goal(_).
691
+
692
+ define_toplevel_goal(Options) :-
693
+ option(toplevel(Goal), Options),
694
+ !,
695
+ entry_point(Goal).
696
+ define_toplevel_goal(_).
697
+
698
+ entry_point(Goal) :-
699
+ define_predicate(Goal),
700
+ ( \+ predicate_property(Goal, built_in),
701
+ \+ predicate_property(Goal, imported_from(_))
702
+ -> goal_pi(Goal, PI),
703
+ public(PI)
704
+ ; true
705
+ ).
706
+
707
+ define_predicate(Head) :-
708
+ '$define_predicate'(Head),
709
+ !. % autoloader
710
+ define_predicate(Head) :-
711
+ strip_module(Head, _, Term),
712
+ functor(Term, Name, Arity),
713
+ throw(error(existence_error(procedure, Name/Arity), _)).
714
+
715
+ goal_pi(M:G, QPI) :-
716
+ !,
717
+ strip_module(M:G, Module, Goal),
718
+ functor(Goal, Name, Arity),
719
+ QPI = Module:Name/Arity.
720
+ goal_pi(Goal, Name/Arity) :-
721
+ functor(Goal, Name, Arity).
722
+
723
+ %! prepare_state(+Options) is det.
724
+ %
725
+ % Prepare the executable by running the `prepare_state` registered
726
+ % initialization hooks.
727
+
728
+ prepare_state(_) :-
729
+ forall('$init_goal'(when(prepare_state), Goal, Ctx),
730
+ run_initialize(Goal, Ctx)).
731
+
732
+ run_initialize(Goal, Ctx) :-
733
+ ( catch(Goal, E, true),
734
+ ( var(E)
735
+ -> true
736
+ ; throw(error(initialization_error(E, Goal, Ctx), _))
737
+ )
738
+ ; throw(error(initialization_error(failed, Goal, Ctx), _))
739
+ ).
740
+
741
+
742
+ /*******************************
743
+ * AUTOLOAD *
744
+ *******************************/
745
+
746
+ %! save_autoload(+Options) is det.
747
+ %
748
+ % Resolve all autoload dependencies.
749
+ %
750
+ % @error existence_error(procedures, List) if undefined(true) is
751
+ % in Options and there are undefined predicates.
752
+
753
+ save_autoload(Options) :-
754
+ option(autoload(true), Options, true),
755
+ !,
756
+ setup_call_cleanup(
757
+ current_prolog_flag(autoload, Old),
758
+ autoload_all(Options),
759
+ set_prolog_flag(autoload, Old)).
760
+ save_autoload(_).
761
+
762
+
763
+ /*******************************
764
+ * MODULES *
765
+ *******************************/
766
+
767
+ %! save_module(+Module, +SaveClass)
768
+ %
769
+ % Saves a module
770
+
771
+ save_module(M, SaveClass) :-
772
+ '$qlf_start_module'(M),
773
+ feedback('~n~nMODULE ~w~n', [M]),
774
+ save_unknown(M),
775
+ ( P = (M:_H),
776
+ current_predicate(_, P),
777
+ \+ predicate_property(P, imported_from(_)),
778
+ save_predicate(P, SaveClass),
779
+ fail
780
+ ; '$qlf_end_part',
781
+ feedback('~n', [])
782
+ ).
783
+
784
+ save_predicate(P, _SaveClass) :-
785
+ predicate_property(P, foreign),
786
+ !,
787
+ P = (M:H),
788
+ functor(H, Name, Arity),
789
+ feedback('~npre-defining foreign ~w/~d ', [Name, Arity]),
790
+ '$add_directive_wic'('$predefine_foreign'(M:Name/Arity)),
791
+ save_attributes(P).
792
+ save_predicate(P, SaveClass) :-
793
+ P = (M:H),
794
+ functor(H, F, A),
795
+ feedback('~nsaving ~w/~d ', [F, A]),
796
+ ( ( H = resource(_,_)
797
+ ; H = resource(_,_,_)
798
+ )
799
+ -> ( SaveClass == development
800
+ -> true
801
+ ; save_attribute(P, (dynamic)),
802
+ ( M == user
803
+ -> save_attribute(P, (multifile))
804
+ ),
805
+ feedback('(Skipped clauses)', []),
806
+ fail
807
+ )
808
+ ; true
809
+ ),
810
+ ( no_save(P)
811
+ -> true
812
+ ; save_attributes(P),
813
+ \+ predicate_property(P, (volatile)),
814
+ ( nth_clause(P, _, Ref),
815
+ feedback('.', []),
816
+ '$qlf_assert_clause'(Ref, SaveClass),
817
+ fail
818
+ ; true
819
+ )
820
+ ).
821
+
822
+ no_save(P) :-
823
+ predicate_property(P, volatile),
824
+ \+ predicate_property(P, dynamic),
825
+ \+ predicate_property(P, multifile).
826
+
827
+ pred_attrib(meta_predicate(Term), Head, meta_predicate(M:Term)) :-
828
+ !,
829
+ strip_module(Head, M, _).
830
+ pred_attrib(Attrib, Head,
831
+ '$set_predicate_attribute'(M:Name/Arity, AttName, Val)) :-
832
+ attrib_name(Attrib, AttName, Val),
833
+ strip_module(Head, M, Term),
834
+ functor(Term, Name, Arity).
835
+
836
+ attrib_name(dynamic, dynamic, true).
837
+ attrib_name(incremental, incremental, true).
838
+ attrib_name(volatile, volatile, true).
839
+ attrib_name(thread_local, thread_local, true).
840
+ attrib_name(multifile, multifile, true).
841
+ attrib_name(public, public, true).
842
+ attrib_name(transparent, transparent, true).
843
+ attrib_name(discontiguous, discontiguous, true).
844
+ attrib_name(notrace, trace, false).
845
+ attrib_name(show_childs, hide_childs, false).
846
+ attrib_name(built_in, system, true).
847
+ attrib_name(nodebug, hide_childs, true).
848
+ attrib_name(quasi_quotation_syntax, quasi_quotation_syntax, true).
849
+ attrib_name(iso, iso, true).
850
+
851
+
852
+ save_attribute(P, Attribute) :-
853
+ pred_attrib(Attribute, P, D),
854
+ ( Attribute == built_in % no need if there are clauses
855
+ -> ( predicate_property(P, number_of_clauses(0))
856
+ -> true
857
+ ; predicate_property(P, volatile)
858
+ )
859
+ ; Attribute == (dynamic) % no need if predicate is thread_local
860
+ -> \+ predicate_property(P, thread_local)
861
+ ; true
862
+ ),
863
+ '$add_directive_wic'(D),
864
+ feedback('(~w) ', [Attribute]).
865
+
866
+ save_attributes(P) :-
867
+ ( predicate_property(P, Attribute),
868
+ save_attribute(P, Attribute),
869
+ fail
870
+ ; true
871
+ ).
872
+
873
+ % Save status of the unknown flag
874
+
875
+ save_unknown(M) :-
876
+ current_prolog_flag(M:unknown, Unknown),
877
+ ( Unknown == error
878
+ -> true
879
+ ; '$add_directive_wic'(set_prolog_flag(M:unknown, Unknown))
880
+ ).
881
+
882
+ /*******************************
883
+ * RECORDS *
884
+ *******************************/
885
+
886
+ save_records :-
887
+ feedback('~nRECORDS~n', []),
888
+ ( current_key(X),
889
+ X \== '$topvar', % do not safe toplevel variables
890
+ feedback('~n~t~8|~w ', [X]),
891
+ recorded(X, V, _),
892
+ feedback('.', []),
893
+ '$add_directive_wic'(recordz(X, V, _)),
894
+ fail
895
+ ; true
896
+ ).
897
+
898
+
899
+ /*******************************
900
+ * FLAGS *
901
+ *******************************/
902
+
903
+ save_flags :-
904
+ feedback('~nFLAGS~n~n', []),
905
+ ( current_flag(X),
906
+ flag(X, V, V),
907
+ feedback('~t~8|~w = ~w~n', [X, V]),
908
+ '$add_directive_wic'(set_flag(X, V)),
909
+ fail
910
+ ; true
911
+ ).
912
+
913
+ save_prompt :-
914
+ feedback('~nPROMPT~n~n', []),
915
+ prompt(Prompt, Prompt),
916
+ '$add_directive_wic'(prompt(_, Prompt)).
917
+
918
+
919
+ /*******************************
920
+ * IMPORTS *
921
+ *******************************/
922
+
923
+ %! save_imports
924
+ %
925
+ % Save import relations. An import relation is saved if a
926
+ % predicate is imported from a module that is not a default module
927
+ % for the destination module. If the predicate is dynamic, we
928
+ % always define the explicit import relation to make clear that an
929
+ % assert must assert on the imported predicate.
930
+
931
+ save_imports :-
932
+ feedback('~nIMPORTS~n~n', []),
933
+ ( predicate_property(M:H, imported_from(I)),
934
+ \+ default_import(M, H, I),
935
+ functor(H, F, A),
936
+ feedback('~t~8|~w:~w/~d <-- ~w~n', [M, F, A, I]),
937
+ '$add_directive_wic'(qsave:restore_import(M, I, F/A)),
938
+ fail
939
+ ; true
940
+ ).
941
+
942
+ default_import(To, Head, From) :-
943
+ '$get_predicate_attribute'(To:Head, (dynamic), 1),
944
+ predicate_property(From:Head, exported),
945
+ !,
946
+ fail.
947
+ default_import(Into, _, From) :-
948
+ default_module(Into, From).
949
+
950
+ %! restore_import(+TargetModule, +SourceModule, +PI) is det.
951
+ %
952
+ % Restore import relation. This notably deals with imports from
953
+ % the module =user=, avoiding a message that the predicate is not
954
+ % exported.
955
+
956
+ restore_import(To, user, PI) :-
957
+ !,
958
+ export(user:PI),
959
+ To:import(user:PI).
960
+ restore_import(To, From, PI) :-
961
+ To:import(From:PI).
962
+
963
+ /*******************************
964
+ * PROLOG FLAGS *
965
+ *******************************/
966
+
967
+ save_prolog_flags(Options) :-
968
+ feedback('~nPROLOG FLAGS~n~n', []),
969
+ '$current_prolog_flag'(Flag, Value0, _Scope, write, Type),
970
+ \+ no_save_flag(Flag),
971
+ map_flag(Flag, Value0, Value, Options),
972
+ feedback('~t~8|~w: ~w (type ~q)~n', [Flag, Value, Type]),
973
+ '$add_directive_wic'(qsave:restore_prolog_flag(Flag, Value, Type)),
974
+ fail.
975
+ save_prolog_flags(_).
976
+
977
+ no_save_flag(argv).
978
+ no_save_flag(os_argv).
979
+ no_save_flag(access_level).
980
+ no_save_flag(tty_control).
981
+ no_save_flag(readline).
982
+ no_save_flag(associated_file).
983
+ no_save_flag(cpu_count).
984
+ no_save_flag(tmp_dir).
985
+ no_save_flag(file_name_case_handling).
986
+ no_save_flag(hwnd). % should be read-only, but comes
987
+ % from user-code
988
+ map_flag(autoload, true, false, Options) :-
989
+ option(class(runtime), Options, runtime),
990
+ option(autoload(true), Options, true),
991
+ !.
992
+ map_flag(_, Value, Value, _).
993
+
994
+
995
+ %! restore_prolog_flag(+Name, +Value, +Type)
996
+ %
997
+ % Deal with possibly protected flags (debug_on_error and
998
+ % report_error are protected flags for the runtime kernel).
999
+
1000
+ restore_prolog_flag(Flag, Value, _Type) :-
1001
+ current_prolog_flag(Flag, Value),
1002
+ !.
1003
+ restore_prolog_flag(Flag, Value, _Type) :-
1004
+ current_prolog_flag(Flag, _),
1005
+ !,
1006
+ catch(set_prolog_flag(Flag, Value), _, true).
1007
+ restore_prolog_flag(Flag, Value, Type) :-
1008
+ create_prolog_flag(Flag, Value, [type(Type)]).
1009
+
1010
+
1011
+ /*******************************
1012
+ * OPERATORS *
1013
+ *******************************/
1014
+
1015
+ %! save_operators(+Options) is det.
1016
+ %
1017
+ % Save operators for all modules. Operators for =system= are
1018
+ % not saved because these are read-only anyway.
1019
+
1020
+ save_operators(Options) :-
1021
+ !,
1022
+ option(op(save), Options, save),
1023
+ feedback('~nOPERATORS~n', []),
1024
+ forall(current_module(M), save_module_operators(M)),
1025
+ feedback('~n', []).
1026
+ save_operators(_).
1027
+
1028
+ save_module_operators(system) :- !.
1029
+ save_module_operators(M) :-
1030
+ forall('$local_op'(P,T,M:N),
1031
+ ( feedback('~n~t~8|~w ', [op(P,T,M:N)]),
1032
+ '$add_directive_wic'(op(P,T,M:N))
1033
+ )).
1034
+
1035
+
1036
+ /*******************************
1037
+ * FORMAT PREDICATES *
1038
+ *******************************/
1039
+
1040
+ save_format_predicates :-
1041
+ feedback('~nFORMAT PREDICATES~n', []),
1042
+ current_format_predicate(Code, Head),
1043
+ qualify_head(Head, QHead),
1044
+ D = format_predicate(Code, QHead),
1045
+ feedback('~n~t~8|~w ', [D]),
1046
+ '$add_directive_wic'(D),
1047
+ fail.
1048
+ save_format_predicates.
1049
+
1050
+ qualify_head(T, T) :-
1051
+ functor(T, :, 2),
1052
+ !.
1053
+ qualify_head(T, user:T).
1054
+
1055
+
1056
+ /*******************************
1057
+ * FOREIGN LIBRARIES *
1058
+ *******************************/
1059
+
1060
+ %! save_foreign_libraries(+Archive, +ExeFile, +Options) is det.
1061
+ %
1062
+ % Save current foreign libraries into the archive.
1063
+
1064
+ save_foreign_libraries(RC, _, Options) :-
1065
+ option(foreign(save), Options),
1066
+ !,
1067
+ current_prolog_flag(arch, HostArch),
1068
+ feedback('~nHOST(~w) FOREIGN LIBRARIES~n', [HostArch]),
1069
+ save_foreign_libraries1(HostArch, RC, Options).
1070
+ save_foreign_libraries(RC, _, Options) :-
1071
+ option(foreign(arch(Archs)), Options),
1072
+ !,
1073
+ forall(member(Arch, Archs),
1074
+ ( feedback('~n~w FOREIGN LIBRARIES~n', [Arch]),
1075
+ save_foreign_libraries1(Arch, RC, Options)
1076
+ )).
1077
+ save_foreign_libraries(_RC, ExeFile, Options) :-
1078
+ option(foreign(copy), Options),
1079
+ !,
1080
+ copy_foreign_libraries(ExeFile, Options).
1081
+ save_foreign_libraries(_, _, _).
1082
+
1083
+ save_foreign_libraries1(Arch, RC, _Options) :-
1084
+ forall(current_foreign_library(FileSpec, _Predicates),
1085
+ ( find_foreign_library(Arch, FileSpec, EntryName, File, Time),
1086
+ term_to_atom(EntryName, Name),
1087
+ zipper_append_file(RC, Name, File, [time(Time)])
1088
+ )).
1089
+
1090
+ %! copy_foreign_libraries(+Exe, +Options) is det.
1091
+ %
1092
+ % Copy all required foreign libraries to an installation directory.
1093
+ % This is currently only implemented for Windows, copying all .dll
1094
+ % files to the directory where the executable is created.
1095
+
1096
+ :- if(current_prolog_flag(windows, true)).
1097
+ copy_foreign_libraries(ExeFile, _Options) :-
1098
+ !,
1099
+ file_directory_name(ExeFile, Dir),
1100
+ win_process_modules(Modules),
1101
+ include(prolog_dll, Modules, PrologDLLs),
1102
+ maplist(copy_dll(Dir), PrologDLLs).
1103
+ :- endif.
1104
+ copy_foreign_libraries(_ExeFile, _Options) :-
1105
+ print_message(warning, qsave(copy_foreign_libraries)).
1106
+
1107
+ prolog_dll(DLL) :-
1108
+ file_base_name(DLL, File),
1109
+ absolute_file_name(foreign(File), Abs,
1110
+ [ solutions(all) ]),
1111
+ same_file(DLL, Abs),
1112
+ !.
1113
+
1114
+ copy_dll(Dest, DLL) :-
1115
+ print_message(informational, copy_foreign_library(DLL, Dest)),
1116
+ copy_file(DLL, Dest).
1117
+
1118
+
1119
+ %! find_foreign_library(+Architecture, +FileSpec, -EntryName, -File, -Time)
1120
+ %! is det.
1121
+ %
1122
+ % Find the shared object specified by FileSpec for the named
1123
+ % Architecture. EntryName will be the name of the file within the
1124
+ % saved state archive. If posible, the shared object is stripped to
1125
+ % reduce its size. This is achieved by calling =|strip -o <tmp>
1126
+ % <shared-object>|=. Note that (if stripped) the file is a Prolog tmp
1127
+ % file and will be deleted on halt.
1128
+ %
1129
+ % @bug Should perform OS search on failure
1130
+
1131
+ find_foreign_library(Arch, FileSpec, shlib(Arch,Name), SharedObject, Time) :-
1132
+ FileSpec = foreign(Name),
1133
+ ( catch(arch_find_shlib(Arch, FileSpec, File),
1134
+ E,
1135
+ print_message(error, E)),
1136
+ exists_file(File)
1137
+ -> true
1138
+ ; throw(error(existence_error(architecture_shlib(Arch), FileSpec),_))
1139
+ ),
1140
+ time_file(File, Time),
1141
+ strip_file(File, SharedObject).
1142
+
1143
+ %! strip_file(+File, -Stripped) is det.
1144
+ %
1145
+ % Try to strip File. Unify Stripped with File if stripping fails for
1146
+ % some reason.
1147
+
1148
+ strip_file(File, Stripped) :-
1149
+ absolute_file_name(path(strip), Strip,
1150
+ [ access(execute),
1151
+ file_errors(fail)
1152
+ ]),
1153
+ tmp_file(shared, Stripped),
1154
+ ( catch(do_strip_file(Strip, File, Stripped), E,
1155
+ (print_message(warning, E), fail))
1156
+ -> true
1157
+ ; print_message(warning, qsave(strip_failed(File))),
1158
+ fail
1159
+ ),
1160
+ !.
1161
+ strip_file(File, File).
1162
+
1163
+ do_strip_file(Strip, File, Stripped) :-
1164
+ format(atom(Cmd), '"~w" -x -o "~w" "~w"',
1165
+ [Strip, Stripped, File]),
1166
+ shell(Cmd),
1167
+ exists_file(Stripped).
1168
+
1169
+ %! qsave:arch_shlib(+Architecture, +FileSpec, -File) is det.
1170
+ %
1171
+ % This is a user defined hook called by qsave_program/2. It is used to
1172
+ % find a shared library for the specified Architecture, named by
1173
+ % FileSpec. FileSpec is of the form foreign(Name), a specification
1174
+ % usable by absolute_file_name/2. The predicate should unify File with
1175
+ % the absolute path for the shared library that corresponds to the
1176
+ % specified Architecture.
1177
+ %
1178
+ % If this predicate fails to find a file for the specified
1179
+ % architecture an `existence_error` is thrown.
1180
+
1181
+ :- multifile arch_shlib/3.
1182
+
1183
+ arch_find_shlib(Arch, FileSpec, File) :-
1184
+ arch_shlib(Arch, FileSpec, File),
1185
+ !.
1186
+ arch_find_shlib(Arch, FileSpec, File) :-
1187
+ current_prolog_flag(arch, Arch),
1188
+ absolute_file_name(FileSpec,
1189
+ [ file_type(executable),
1190
+ access(read),
1191
+ file_errors(fail)
1192
+ ], File),
1193
+ !.
1194
+ arch_find_shlib(Arch, foreign(Base), File) :-
1195
+ current_prolog_flag(arch, Arch),
1196
+ current_prolog_flag(windows, true),
1197
+ current_prolog_flag(executable, WinExe),
1198
+ prolog_to_os_filename(Exe, WinExe),
1199
+ file_directory_name(Exe, BinDir),
1200
+ file_name_extension(Base, dll, DllFile),
1201
+ atomic_list_concat([BinDir, /, DllFile], File),
1202
+ exists_file(File).
1203
+
1204
+
1205
+ /*******************************
1206
+ * UTIL *
1207
+ *******************************/
1208
+
1209
+ open_map(Options) :-
1210
+ option(map(Map), Options),
1211
+ !,
1212
+ open(Map, write, Fd),
1213
+ asserta(verbose(Fd)).
1214
+ open_map(_) :-
1215
+ retractall(verbose(_)).
1216
+
1217
+ close_map :-
1218
+ retract(verbose(Fd)),
1219
+ close(Fd),
1220
+ !.
1221
+ close_map.
1222
+
1223
+ feedback(Fmt, Args) :-
1224
+ verbose(Fd),
1225
+ !,
1226
+ format(Fd, Fmt, Args).
1227
+ feedback(_, _).
1228
+
1229
+
1230
+ check_options([]) :- !.
1231
+ check_options([Var|_]) :-
1232
+ var(Var),
1233
+ !,
1234
+ throw(error(domain_error(save_options, Var), _)).
1235
+ check_options([Name=Value|T]) :-
1236
+ !,
1237
+ ( save_option(Name, Type, _Comment)
1238
+ -> ( must_be(Type, Value)
1239
+ -> check_options(T)
1240
+ ; throw(error(domain_error(Type, Value), _))
1241
+ )
1242
+ ; throw(error(domain_error(save_option, Name), _))
1243
+ ).
1244
+ check_options([Term|T]) :-
1245
+ Term =.. [Name,Arg],
1246
+ !,
1247
+ check_options([Name=Arg|T]).
1248
+ check_options([Var|_]) :-
1249
+ throw(error(domain_error(save_options, Var), _)).
1250
+ check_options(Opt) :-
1251
+ throw(error(domain_error(list, Opt), _)).
1252
+
1253
+
1254
+ %! zipper_append_file(+Zipper, +Name, +File, +Options) is det.
1255
+ %
1256
+ % Append the content of File under Name to the open Zipper.
1257
+
1258
+ zipper_append_file(_, Name, _, _) :-
1259
+ saved_resource_file(Name),
1260
+ !.
1261
+ zipper_append_file(_, _, File, _) :-
1262
+ source_file(File),
1263
+ !.
1264
+ zipper_append_file(Zipper, Name, File, Options) :-
1265
+ ( option(time(_), Options)
1266
+ -> Options1 = Options
1267
+ ; time_file(File, Stamp),
1268
+ Options1 = [time(Stamp)|Options]
1269
+ ),
1270
+ setup_call_cleanup(
1271
+ open(File, read, In, [type(binary)]),
1272
+ setup_call_cleanup(
1273
+ zipper_open_new_file_in_zip(Zipper, Name, Out, Options1),
1274
+ copy_stream_data(In, Out),
1275
+ close(Out)),
1276
+ close(In)),
1277
+ assertz(saved_resource_file(Name)).
1278
+
1279
+ %! zipper_add_directory(+Zipper, +Name, +Dir, +Options) is det.
1280
+ %
1281
+ % Add a directory entry. Dir is only used if there is no option
1282
+ % time(Stamp).
1283
+
1284
+ zipper_add_directory(Zipper, Name, Dir, Options) :-
1285
+ ( option(time(Stamp), Options)
1286
+ -> true
1287
+ ; time_file(Dir, Stamp)
1288
+ ),
1289
+ atom_concat(Name, /, DirName),
1290
+ ( saved_resource_file(DirName)
1291
+ -> true
1292
+ ; setup_call_cleanup(
1293
+ zipper_open_new_file_in_zip(Zipper, DirName, Out,
1294
+ [ method(store),
1295
+ time(Stamp)
1296
+ | Options
1297
+ ]),
1298
+ true,
1299
+ close(Out)),
1300
+ assertz(saved_resource_file(DirName))
1301
+ ).
1302
+
1303
+ add_parent_dirs(Zipper, Name, Dir, Options) :-
1304
+ ( option(time(Stamp), Options)
1305
+ -> true
1306
+ ; time_file(Dir, Stamp)
1307
+ ),
1308
+ file_directory_name(Name, Parent),
1309
+ ( Parent \== Name
1310
+ -> add_parent_dirs(Zipper, Parent, [time(Stamp)|Options])
1311
+ ; true
1312
+ ).
1313
+
1314
+ add_parent_dirs(_, '.', _) :-
1315
+ !.
1316
+ add_parent_dirs(Zipper, Name, Options) :-
1317
+ zipper_add_directory(Zipper, Name, _, Options),
1318
+ file_directory_name(Name, Parent),
1319
+ ( Parent \== Name
1320
+ -> add_parent_dirs(Zipper, Parent, Options)
1321
+ ; true
1322
+ ).
1323
+
1324
+
1325
+ %! zipper_append_directory(+Zipper, +Name, +Dir, +Options) is det.
1326
+ %
1327
+ % Append the content of Dir below Name in the resource archive.
1328
+ % Options:
1329
+ %
1330
+ % - include(+Patterns)
1331
+ % Only add entries that match an element from Patterns using
1332
+ % wildcard_match/2.
1333
+ % - exclude(+Patterns)
1334
+ % Ignore entries that match an element from Patterns using
1335
+ % wildcard_match/2.
1336
+ %
1337
+ % @tbd Process .gitignore. There also seem to exists other
1338
+ % standards for this.
1339
+
1340
+ zipper_append_directory(Zipper, Name, Dir, Options) :-
1341
+ exists_directory(Dir),
1342
+ !,
1343
+ add_parent_dirs(Zipper, Name, Dir, Options),
1344
+ zipper_add_directory(Zipper, Name, Dir, Options),
1345
+ directory_files(Dir, Members),
1346
+ forall(member(M, Members),
1347
+ ( reserved(M)
1348
+ -> true
1349
+ ; ignored(M, Options)
1350
+ -> true
1351
+ ; atomic_list_concat([Dir,M], /, Entry),
1352
+ atomic_list_concat([Name,M], /, Store),
1353
+ catch(zipper_append_directory(Zipper, Store, Entry, Options),
1354
+ E,
1355
+ print_message(warning, E))
1356
+ )).
1357
+ zipper_append_directory(Zipper, Name, File, Options) :-
1358
+ zipper_append_file(Zipper, Name, File, Options).
1359
+
1360
+ reserved(.).
1361
+ reserved(..).
1362
+
1363
+ %! ignored(+File, +Options) is semidet.
1364
+ %
1365
+ % Ignore File if there is an include(Patterns) option that does *not*
1366
+ % match File or an exclude(Patterns) that does match File.
1367
+
1368
+ ignored(File, Options) :-
1369
+ option(include(Patterns), Options),
1370
+ \+ ( ( is_list(Patterns)
1371
+ -> member(Pattern, Patterns)
1372
+ ; Pattern = Patterns
1373
+ ),
1374
+ glob_match(Pattern, File)
1375
+ ),
1376
+ !.
1377
+ ignored(File, Options) :-
1378
+ option(exclude(Patterns), Options),
1379
+ ( is_list(Patterns)
1380
+ -> member(Pattern, Patterns)
1381
+ ; Pattern = Patterns
1382
+ ),
1383
+ glob_match(Pattern, File),
1384
+ !.
1385
+
1386
+ glob_match(Pattern, File) :-
1387
+ current_prolog_flag(file_name_case_handling, case_sensitive),
1388
+ !,
1389
+ wildcard_match(Pattern, File).
1390
+ glob_match(Pattern, File) :-
1391
+ wildcard_match(Pattern, File, [case_sensitive(false)]).
1392
+
1393
+
1394
+ /********************************
1395
+ * SAVED STATE GENERATION *
1396
+ *********************************/
1397
+
1398
+ %! qsave_toplevel
1399
+ %
1400
+ % Called to handle `-c file` compilaton.
1401
+
1402
+ :- public
1403
+ qsave_toplevel/0.
1404
+
1405
+ qsave_toplevel :-
1406
+ current_prolog_flag(os_argv, Argv),
1407
+ qsave_options(Argv, Files, Options),
1408
+ set_on_error(Options),
1409
+ '$cmd_option_val'(compileout, Out),
1410
+ user:consult(Files),
1411
+ maybe_exit_on_errors,
1412
+ qsave_program(Out, user:Options).
1413
+
1414
+ set_on_error(Options) :-
1415
+ option(on_error(_), Options), !.
1416
+ set_on_error(_Options) :-
1417
+ set_prolog_flag(on_error, status).
1418
+
1419
+ maybe_exit_on_errors :-
1420
+ '$exit_code'(Code),
1421
+ ( Code =\= 0
1422
+ -> halt
1423
+ ; true
1424
+ ).
1425
+
1426
+ qsave_options([], [], []).
1427
+ qsave_options([--|_], [], []) :-
1428
+ !.
1429
+ qsave_options(['-c'|T0], Files, Options) :-
1430
+ !,
1431
+ argv_files(T0, T1, Files, FilesT),
1432
+ qsave_options(T1, FilesT, Options).
1433
+ qsave_options([O|T0], Files, [Option|T]) :-
1434
+ string_concat(--, Opt, O),
1435
+ split_string(Opt, =, '', [NameS|Rest]),
1436
+ split_string(NameS, '-', '', NameParts),
1437
+ atomic_list_concat(NameParts, '_', Name),
1438
+ qsave_option(Name, OptName, Rest, Value),
1439
+ !,
1440
+ Option =.. [OptName, Value],
1441
+ qsave_options(T0, Files, T).
1442
+ qsave_options([_|T0], Files, T) :-
1443
+ qsave_options(T0, Files, T).
1444
+
1445
+ argv_files([], [], Files, Files).
1446
+ argv_files([H|T], [H|T], Files, Files) :-
1447
+ sub_atom(H, 0, _, _, -),
1448
+ !.
1449
+ argv_files([H|T0], T, [H|Files0], Files) :-
1450
+ argv_files(T0, T, Files0, Files).
1451
+
1452
+ %! qsave_option(+Name, +ValueStrings, -Value) is semidet.
1453
+
1454
+ qsave_option(Name, Name, [], true) :-
1455
+ save_option(Name, boolean, _),
1456
+ !.
1457
+ qsave_option(NoName, Name, [], false) :-
1458
+ atom_concat('no_', Name, NoName),
1459
+ save_option(Name, boolean, _),
1460
+ !.
1461
+ qsave_option(Name, Name, ValueStrings, Value) :-
1462
+ save_option(Name, Type, _),
1463
+ !,
1464
+ atomics_to_string(ValueStrings, "=", ValueString),
1465
+ convert_option_value(Type, ValueString, Value).
1466
+ qsave_option(Name, Name, _Chars, _Value) :-
1467
+ existence_error(save_option, Name).
1468
+
1469
+ convert_option_value(integer, String, Value) =>
1470
+ ( number_string(Value, String)
1471
+ -> true
1472
+ ; sub_string(String, 0, _, 1, SubString),
1473
+ sub_string(String, _, 1, 0, Suffix0),
1474
+ downcase_atom(Suffix0, Suffix),
1475
+ number_string(Number, SubString),
1476
+ suffix_multiplier(Suffix, Multiplier)
1477
+ -> Value is Number * Multiplier
1478
+ ; domain_error(integer, String)
1479
+ ).
1480
+ convert_option_value(callable, String, Value) =>
1481
+ term_string(Value, String).
1482
+ convert_option_value(atom, String, Value) =>
1483
+ atom_string(Value, String).
1484
+ convert_option_value(boolean, String, Value) =>
1485
+ atom_string(Value, String).
1486
+ convert_option_value(oneof(_), String, Value) =>
1487
+ atom_string(Value, String).
1488
+ convert_option_value(ground, String, Value) =>
1489
+ atom_string(Value, String).
1490
+ convert_option_value(qsave_foreign_option, "save", Value) =>
1491
+ Value = save.
1492
+ convert_option_value(qsave_foreign_option, "copy", Value) =>
1493
+ Value = copy.
1494
+ convert_option_value(qsave_foreign_option, StrArchList, arch(ArchList)) =>
1495
+ split_string(StrArchList, ",", ", \t", StrArchList1),
1496
+ maplist(atom_string, ArchList, StrArchList1).
1497
+
1498
+ suffix_multiplier(b, 1).
1499
+ suffix_multiplier(k, 1024).
1500
+ suffix_multiplier(m, 1024 * 1024).
1501
+ suffix_multiplier(g, 1024 * 1024 * 1024).
1502
+
1503
+
1504
+ /*******************************
1505
+ * MESSAGES *
1506
+ *******************************/
1507
+
1508
+ :- multifile prolog:message/3.
1509
+
1510
+ prolog:message(no_resource(Name, File)) -->
1511
+ [ 'Could not find resource ~w on ~w or system resources'-
1512
+ [Name, File] ].
1513
+ prolog:message(qsave(nondet)) -->
1514
+ [ 'qsave_program/2 succeeded with a choice point'-[] ].
1515
+ prolog:message(copy_foreign_library(Lib,Dir)) -->
1516
+ [ 'Copying ~w to ~w'-[Lib, Dir] ].