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,1200 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jan Wielemaker
4
+ E-mail: J.Wielemaker@vu.nl
5
+ WWW: http://www.swi-prolog.org
6
+ Copyright (c) 2002-2025, University of Amsterdam
7
+ VU University Amsterdam
8
+ SWI-Prolog Solutions b.v.
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions
13
+ are met:
14
+
15
+ 1. Redistributions of source code must retain the above copyright
16
+ notice, this list of conditions and the following disclaimer.
17
+
18
+ 2. Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in
20
+ the documentation and/or other materials provided with the
21
+ distribution.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ POSSIBILITY OF SUCH DAMAGE.
35
+ */
36
+
37
+ :- module(prolog_main,
38
+ [ main/0,
39
+ argv_options/3, % +Argv, -RestArgv, -Options
40
+ argv_options/4, % +Argv, -RestArgv, -Options, +ParseOpts
41
+ argv_usage/1, % +Level
42
+ cli_parse_debug_options/2, % +OptionsIn, -Options
43
+ cli_debug_opt_type/3, % -Flag, -Option, -Type
44
+ cli_debug_opt_help/2, % -Option, -Message
45
+ cli_debug_opt_meta/2, % -Option, -Arg
46
+ cli_enable_development_system/0
47
+ ]).
48
+ :- use_module(library(debug), [debug/1]).
49
+ :- autoload(library(apply), [maplist/2, maplist/3, partition/4]).
50
+ :- autoload(library(lists),
51
+ [append/3, max_list/2, sum_list/2, list_to_set/2, member/2]).
52
+ :- autoload(library(pairs), [pairs_keys/2, pairs_values/2]).
53
+ :- autoload(library(prolog_code), [pi_head/2]).
54
+ :- autoload(library(prolog_debug), [spy/1]).
55
+ :- autoload(library(dcg/high_order), [sequence//3, sequence//2]).
56
+ :- autoload(library(option), [option/2, option/3]).
57
+ :- if(exists_source(library(doc_markdown))).
58
+ :- autoload(library(doc_markdown), [print_markdown/2]).
59
+ :- endif.
60
+
61
+ :- meta_predicate
62
+ argv_options(:, -, -),
63
+ argv_options(:, -, -, +),
64
+ argv_usage(:).
65
+
66
+ :- dynamic
67
+ interactive/0.
68
+
69
+ /** <module> Provide entry point for scripts
70
+
71
+ This library is intended for supporting PrologScript on Unix using the
72
+ ``#!`` magic sequence for scripts using commandline options. The entry
73
+ point main/0 calls the user-supplied predicate main/1 passing a list of
74
+ commandline options. Below is a simle `echo` implementation in Prolog.
75
+
76
+ ```
77
+ #!/usr/bin/env swipl
78
+
79
+ :- initialization(main, main).
80
+
81
+ main(Argv) :-
82
+ echo(Argv).
83
+
84
+ echo([]) :- nl.
85
+ echo([Last]) :- !,
86
+ write(Last), nl.
87
+ echo([H|T]) :-
88
+ write(H), write(' '),
89
+ echo(T).
90
+ ```
91
+
92
+ @see library(prolog_stack) to force backtraces in case of an
93
+ uncaught exception.
94
+ @see XPCE users should have a look at library(pce_main), which
95
+ starts the GUI and processes events until all windows have gone.
96
+ */
97
+
98
+ :- module_transparent
99
+ main/0.
100
+
101
+ %! main
102
+ %
103
+ % Call main/1 using the passed command-line arguments. Before calling
104
+ % main/1 this predicate installs a signal handler for =SIGINT=
105
+ % (Control-C) that terminates the process with status 1.
106
+ %
107
+ % When main/0 is called interactively it simply calls main/1 with the
108
+ % arguments. This allows for debugging scripts as follows:
109
+ %
110
+ % ```
111
+ % $ swipl -l script.pl -- arg ...
112
+ % ?- gspy(suspect/1). % setup debugging
113
+ % ?- main. % run program
114
+ % ```
115
+
116
+ main :-
117
+ current_prolog_flag(break_level, _),
118
+ !,
119
+ current_prolog_flag(argv, Av),
120
+ context_module(M),
121
+ M:main(Av).
122
+ main :-
123
+ context_module(M),
124
+ set_signals,
125
+ current_prolog_flag(argv, Av),
126
+ catch_with_backtrace(M:main(Av), Error, throw(Error)),
127
+ ( interactive
128
+ -> cli_enable_development_system
129
+ ; true
130
+ ).
131
+
132
+ set_signals :-
133
+ on_signal(int, _, interrupt).
134
+
135
+ %! interrupt(+Signal)
136
+ %
137
+ % We received an interrupt. This handler is installed using
138
+ % on_signal/3.
139
+
140
+ interrupt(_Sig) :-
141
+ halt(1).
142
+
143
+ /*******************************
144
+ * OPTIONS *
145
+ *******************************/
146
+
147
+ %! argv_options(:Argv, -Positional, -Options) is det.
148
+ %
149
+ % Parse command line arguments. This predicate acts in one of two
150
+ % modes.
151
+ %
152
+ % - If the calling module defines opt_type/3, full featured parsing
153
+ % with long and short options, type conversion and help is
154
+ % provided.
155
+ % - If opt_type/3 is not defined, only unguided transformation
156
+ % using long options is supported. See argv_untyped_options/3
157
+ % for details.
158
+ %
159
+ % When __guided__, three predicates are called in the calling module.
160
+ % opt_type/3 __must__ be defined, the others need not. Note that these
161
+ % three predicates _may_ be defined as _multifile_ to allow multiple
162
+ % modules contributing to the provided commandline options. Defining
163
+ % them as _discontiguous_ allows for creating blocks that describe a
164
+ % group of related options.
165
+ %
166
+ % - opt_type(Opt, Name, Type)
167
+ % Defines Opt to add an option Name(Value), where Value statisfies
168
+ % Type. Opt does not include the leading `-`. A single character
169
+ % implies a short option, multiple a long option. Long options
170
+ % use ``_`` as _word separator_, user options may use either ``_``
171
+ % or ``-``. Type is one of:
172
+ %
173
+ % - A|B
174
+ % Disjunctive type. Disjunction can be used create long
175
+ % options with optional values. For example, using the type
176
+ % ``nonneg|boolean``, for an option `http` handles ``--http``
177
+ % as http(true), ``--no-http`` as http(false) and ``--http=3000``
178
+ % as http(3000). Note that with an optional boolean a option is
179
+ % considered boolean unless it has a value written as
180
+ % ``--longopt=value``.
181
+ % - boolean(Default)
182
+ % - boolean
183
+ % Boolean options are special. They do not take a value except
184
+ % for when using the long ``--opt=value`` notation. This
185
+ % explicit value specification converts ``true``, ``True``,
186
+ % ``TRUE``, ``on``, ``On``, ``ON``, ``1`` and the obvious
187
+ % false equivalents to Prolog `true` or `false`. If the
188
+ % option is specified, Default is used. If ``--no-opt`` or
189
+ % ``--noopt`` is used, the inverse of Default is used.
190
+ % - integer
191
+ % Argument is converted to an integer
192
+ % - float
193
+ % Argument is converted to a float. User may specify an integer
194
+ % - nonneg
195
+ % As `integer`. Requires value >= 0.
196
+ % - natural
197
+ % As `integer`. Requires value >= 1.
198
+ % - number
199
+ % Any number (integer, float, rational).
200
+ % - between(Low, High)
201
+ % If both one of Low and High is a float, convert as `float`,
202
+ % else convert as `integer`. Then check the range.
203
+ % - atom
204
+ % No conversion
205
+ % - oneof(List)
206
+ % As `atom`, but requires the value to be a member of List
207
+ % (_enum_ type).
208
+ % - string
209
+ % Convert to a SWI-Prolog string
210
+ % - file
211
+ % Convert to a file name in Prolog canonical notation
212
+ % using prolog_to_os_filename/2.
213
+ % - directory
214
+ % Convert to a file name in Prolog canonical notation
215
+ % using prolog_to_os_filename/2. No checking is done and
216
+ % thus this type is the same as `file`
217
+ % - file(Access)
218
+ % As `file`, and check access using access_file/2. A value `-`
219
+ % is not checked for access, assuming the application handles
220
+ % this as standard input or output.
221
+ % - directory(Access)
222
+ % As `directory`, and check access. Access is one of `read`
223
+ % `write` or `create`. In the latter case the parent directory
224
+ % must exist and have write access.
225
+ % - term
226
+ % Parse option value to a Prolog term.
227
+ % - term(+Options)
228
+ % As `term`, but passes Options to term_string/3. If the option
229
+ % variable_names(Bindings) is given the option value is set to
230
+ % the _pair_ `Term-Bindings`.
231
+ %
232
+ % - opt_help(Name, HelpString)
233
+ % Help string used by argv_usage/1.
234
+ %
235
+ % - opt_meta(Name, Meta)
236
+ % If a typed argument is required this defines the placeholder
237
+ % in the help message. The default is the uppercase version of
238
+ % the type _functor name_. This produces the ``FILE`` in e.g. ``-f
239
+ % FILE``.
240
+ %
241
+ % By default, ``-h``, ``-?`` and ``--help`` are bound to help. If
242
+ % opt_type(Opt, help, boolean) is true for some `Opt`, the default
243
+ % help binding and help message are disabled and the normal user
244
+ % rules apply. In particular, the user should also provide a rule for
245
+ % opt_help(help, String).
246
+
247
+ argv_options(M:Argv, Positional, Options) :-
248
+ in(M:opt_type(_,_,_)),
249
+ !,
250
+ argv_options(M:Argv, Positional, Options, [on_error(halt(1))]).
251
+ argv_options(_:Argv, Positional, Options) :-
252
+ argv_untyped_options(Argv, Positional, Options).
253
+
254
+ %! argv_options(:Argv, -Positional, -Options, +ParseOptions) is det.
255
+ %
256
+ % As argv_options/3 in __guided__ mode, Currently this version allows
257
+ % parsing argument options throwing an exception rather than calling
258
+ % halt/1 by passing an empty list to ParseOptions. ParseOptions:
259
+ %
260
+ % - on_error(+Goal)
261
+ % If Goal is halt(Code), exit with Code. Other goals are
262
+ % currently not supported.
263
+ % - options_after_arguments(+Boolean)
264
+ % If `false` (default `true`), stop parsing after the first
265
+ % positional argument, returning options that follow this
266
+ % argument as positional arguments. E.g, ``-x file -y``
267
+ % results in positional arguments `[file, '-y']`
268
+ % - unknown_option(+Mode)
269
+ % One of `error` (default) or `pass`. Using `pass`, the
270
+ % option is passed in Positional. Multi-flag short options
271
+ % may be processed partially. For example, if ``-v`` is defined
272
+ % and `-iv` is in Argv, Positional receives `'-i'` and the
273
+ % option defined with ``-v`` is added to Options.
274
+ %
275
+ % @tbd When passing unknown options we may wish to process multi-flag
276
+ % options as a whole or not at all rather than passing the unknown
277
+ % flags.
278
+
279
+ argv_options(Argv, Positional, Options, POptions) :-
280
+ option(on_error(halt(Code)), POptions),
281
+ !,
282
+ E = error(_,_),
283
+ catch(opt_parse(Argv, Positional, Options, POptions), E,
284
+ ( print_message(error, E),
285
+ halt(Code)
286
+ )).
287
+ argv_options(Argv, Positional, Options, POptions) :-
288
+ opt_parse(Argv, Positional, Options, POptions).
289
+
290
+ %! argv_untyped_options(+Argv, -RestArgv, -Options) is det.
291
+ %
292
+ % Generic transformation of long commandline arguments to options.
293
+ % Each ``--Name=Value`` is mapped to Name(Value). Each plain name is
294
+ % mapped to Name(true), unless Name starts with ``no-``, in which case
295
+ % the option is mapped to Name(false). Numeric option values are
296
+ % mapped to Prolog numbers.
297
+
298
+ argv_untyped_options([], Pos, Opts) =>
299
+ Pos = [], Opts = [].
300
+ argv_untyped_options([--|R], Pos, Ops) =>
301
+ Pos = R, Ops = [].
302
+ argv_untyped_options([H0|T0], R, Ops), sub_atom(H0, 0, _, _, --) =>
303
+ Ops = [H|T],
304
+ ( sub_atom(H0, B, _, A, =)
305
+ -> B2 is B-2,
306
+ sub_atom(H0, 2, B2, _, Name),
307
+ sub_string(H0, _, A, 0, Value0),
308
+ convert_option(Name, Value0, Value)
309
+ ; sub_atom(H0, 2, _, 0, Name0),
310
+ ( sub_atom(Name0, 0, _, _, 'no-')
311
+ -> sub_atom(Name0, 3, _, 0, Name),
312
+ Value = false
313
+ ; Name = Name0,
314
+ Value = true
315
+ )
316
+ ),
317
+ canonical_name(Name, PlName),
318
+ H =.. [PlName,Value],
319
+ argv_untyped_options(T0, R, T).
320
+ argv_untyped_options([H|T0], Ops, T) =>
321
+ Ops = [H|R],
322
+ argv_untyped_options(T0, R, T).
323
+
324
+ convert_option(password, String, String) :- !.
325
+ convert_option(_, String, Number) :-
326
+ number_string(Number, String),
327
+ !.
328
+ convert_option(_, String, Atom) :-
329
+ atom_string(Atom, String).
330
+
331
+ canonical_name(Name, PlName) :-
332
+ split_string(Name, "-_", "", Parts),
333
+ atomic_list_concat(Parts, '_', PlName).
334
+
335
+ %! opt_parse(:Argv, -Positional, -Options, +POptions) is det.
336
+ %
337
+ % Rules follow those of Python optparse:
338
+ %
339
+ % - Short options must be boolean, except for the last.
340
+ % - The value of a short option can be connected or the next
341
+ % argument
342
+ % - Long options can have "=value" or have the value in the
343
+ % next argument.
344
+
345
+ opt_parse(M:Argv, _Positional, _Options, _POptions) :-
346
+ opt_needs_help(M:Argv),
347
+ !,
348
+ argv_usage(M:debug),
349
+ halt(0).
350
+ opt_parse(M:Argv, Positional, Options, POptions) :-
351
+ opt_parse(Argv, Positional, Options, M, POptions).
352
+
353
+ opt_needs_help(M:[Arg]) :-
354
+ in(M:opt_type(_, help, boolean)),
355
+ !,
356
+ in(M:opt_type(Opt, help, boolean)),
357
+ ( short_opt(Opt)
358
+ -> atom_concat(-, Opt, Arg)
359
+ ; atom_concat(--, Opt, Arg)
360
+ ),
361
+ !.
362
+ opt_needs_help(_:['-h']).
363
+ opt_needs_help(_:['-?']).
364
+ opt_needs_help(_:['--help']).
365
+
366
+ opt_parse([], Positional, Options, _, _) =>
367
+ Positional = [],
368
+ Options = [].
369
+ opt_parse([--|T], Positional, Options, _, _) =>
370
+ Positional = T,
371
+ Options = [].
372
+ opt_parse([H|T], Positional, Options, M, POptions), atom_concat(--, Long, H) =>
373
+ take_long(Long, T, Positional, Options, M, POptions).
374
+ opt_parse([H|T], Positional, Options, M, POptions),
375
+ H \== '-',
376
+ string_concat(-, Opts, H) =>
377
+ string_chars(Opts, Shorts),
378
+ take_shorts(Shorts, T, Positional, Options, M, POptions).
379
+ opt_parse(Argv, Positional, Options, _M, POptions),
380
+ option(options_after_arguments(false), POptions) =>
381
+ Positional = Argv,
382
+ Options = [].
383
+ opt_parse([H|T], Positional, Options, M, POptions) =>
384
+ Positional = [H|PT],
385
+ opt_parse(T, PT, Options, M, POptions).
386
+
387
+
388
+ %! take_long(+LongOpt, +Argv, -Positional, -Option, +M, +POptions) is det.
389
+
390
+ take_long(Long, T, Positional, Options, M, POptions) :- % --long=Value
391
+ sub_atom(Long, B, _, A, =),
392
+ !,
393
+ sub_atom(Long, 0, B, _, LName0),
394
+ sub_atom(Long, _, A, 0, VAtom),
395
+ canonical_name(LName0, LName),
396
+ ( in(M:opt_type(LName, Name, Type))
397
+ -> opt_value(Type, Long, VAtom, Value),
398
+ Opt =.. [Name,Value],
399
+ Options = [Opt|OptionsT],
400
+ opt_parse(T, Positional, OptionsT, M, POptions)
401
+ ; option(unknown_option(pass), POptions, error)
402
+ -> atom_concat(--, Long, Opt),
403
+ Positional = [Opt|PositionalT],
404
+ opt_parse(T, PositionalT, Options, M, POptions)
405
+ ; opt_error(unknown_option(M:LName0))
406
+ ).
407
+ take_long(LName0, T, Positional, Options, M, POptions) :- % --long
408
+ canonical_name(LName0, LName),
409
+ take_long_(LName, T, Positional, Options, M, POptions).
410
+
411
+ take_long_(Long, T, Positional, Options, M, POptions) :- % --long
412
+ opt_bool_type(Long, Name, Value, M), % only boolean
413
+ !,
414
+ Opt =.. [Name,Value],
415
+ Options = [Opt|OptionsT],
416
+ opt_parse(T, Positional, OptionsT, M, POptions).
417
+ take_long_(Long, T, Positional, Options, M, POptions) :- % --no-long, --nolong
418
+ ( atom_concat('no_', LName, Long)
419
+ ; atom_concat('no', LName, Long)
420
+ ),
421
+ in(M:opt_type(LName, Name, Type)),
422
+ type_optional_bool(Type, Value0),
423
+ !,
424
+ negate(Value0, Value),
425
+ Opt =.. [Name,Value],
426
+ Options = [Opt|OptionsT],
427
+ opt_parse(T, Positional, OptionsT, M, POptions).
428
+ take_long_(Long, T, Positional, Options, M, POptions) :- % --long [value]
429
+ in(M:opt_type(Long, Name, Type)),
430
+ type_optional_bool(Type, Value),
431
+ !,
432
+ Opt =.. [Name,Value],
433
+ Options = [Opt|OptionsT],
434
+ opt_parse(T, Positional, OptionsT, M, POptions).
435
+ take_long_(Long, T, Positional, Options, M, POptions) :- % --long
436
+ in(M:opt_type(Long, Name, Type)),
437
+ !,
438
+ ( T = [VAtom|T1]
439
+ -> opt_value(Type, Long, VAtom, Value),
440
+ Opt =.. [Name,Value],
441
+ Options = [Opt|OptionsT],
442
+ opt_parse(T1, Positional, OptionsT, M, POptions)
443
+ ; opt_error(missing_value(Long, Type))
444
+ ).
445
+ take_long_(Long, T, Positional, Options, M, POptions) :-
446
+ option(unknown_option(pass), POptions, error),
447
+ !,
448
+ atom_concat(--, Long, Opt),
449
+ Positional = [Opt|PositionalT],
450
+ opt_parse(T, PositionalT, Options, M, POptions).
451
+ take_long_(Long, _, _, _, M, _) :-
452
+ opt_error(unknown_option(M:Long)).
453
+
454
+ %! take_shorts(+OptChars, +Argv, -Positional, -Options, +M, +POptions)
455
+
456
+ take_shorts(OptChars, Argv, Positional, Options, M, POptions) :-
457
+ take_shorts_(OptChars, OptLeft, Argv, Positional0, Options, M, POptions),
458
+ ( OptLeft == []
459
+ -> Positional = Positional0
460
+ ; atom_chars(Pass, [-|OptLeft]),
461
+ Positional = [Pass|Positional0]
462
+ ).
463
+
464
+ take_shorts_([], [], T, Positional, Options, M, POptions) :-
465
+ opt_parse(T, Positional, Options, M, POptions).
466
+ take_shorts_([H|T], Pass, Argv, Positional, Options, M, POptions) :-
467
+ opt_bool_type(H, Name, Value, M),
468
+ !,
469
+ Opt =.. [Name,Value],
470
+ Options = [Opt|OptionsT],
471
+ take_shorts_(T, Pass, Argv, Positional, OptionsT, M, POptions).
472
+ take_shorts_([H|T], Pass, Argv, Positional, Options, M, POptions) :-
473
+ in(M:opt_type(H, Name, Type)),
474
+ !,
475
+ ( T == []
476
+ -> ( Argv = [VAtom|ArgvT]
477
+ -> opt_value(Type, H, VAtom, Value),
478
+ Opt =.. [Name,Value],
479
+ Options = [Opt|OptionsT],
480
+ take_shorts_(T, Pass, ArgvT, Positional, OptionsT, M, POptions)
481
+ ; opt_error(missing_value(H, Type))
482
+ )
483
+ ; atom_chars(VAtom, T),
484
+ opt_value(Type, H, VAtom, Value),
485
+ Opt =.. [Name,Value],
486
+ Options = [Opt|OptionsT],
487
+ take_shorts_([], Pass, Argv, Positional, OptionsT, M, POptions)
488
+ ).
489
+ take_shorts_([H|T], [H|Pass], Argv, Positional, Options, M, POptions) :-
490
+ option(unknown_option(pass), POptions, error), !,
491
+ take_shorts_(T, Pass, Argv, Positional, Options, M, POptions).
492
+ take_shorts_([H|_], _, _, _, _, M, _) :-
493
+ opt_error(unknown_option(M:H)).
494
+
495
+ opt_bool_type(Opt, Name, Value, M) :-
496
+ in(M:opt_type(Opt, Name, Type)),
497
+ type_bool(Type, Value).
498
+
499
+ type_bool(Type, Value) :-
500
+ ( Type == boolean
501
+ -> Value = true
502
+ ; Type = boolean(Value)
503
+ ).
504
+
505
+ type_optional_bool((A|B), Value) =>
506
+ ( type_optional_bool(A, Value)
507
+ -> true
508
+ ; type_optional_bool(B, Value)
509
+ ).
510
+ type_optional_bool(Type, Value) =>
511
+ type_bool(Type, Value).
512
+
513
+ negate(true, false).
514
+ negate(false, true).
515
+
516
+ %! opt_value(+Type, +Opt, +VAtom, -Value) is det.
517
+ %
518
+ % @error opt_error(Error)
519
+
520
+ opt_value(Type, _Opt, VAtom, Value) :-
521
+ opt_convert(Type, VAtom, Value),
522
+ !.
523
+ opt_value(Type, Opt, VAtom, _) :-
524
+ opt_error(value_type(Opt, Type, VAtom)).
525
+
526
+ %! opt_convert(+Type, +VAtom, -Value) is semidet.
527
+
528
+ opt_convert(A|B, Spec, Value) :-
529
+ ( opt_convert(A, Spec, Value)
530
+ -> true
531
+ ; opt_convert(B, Spec, Value)
532
+ ).
533
+ opt_convert(boolean, Spec, Value) :-
534
+ to_bool(Spec, Value).
535
+ opt_convert(boolean(_), Spec, Value) :-
536
+ to_bool(Spec, Value).
537
+ opt_convert(number, Spec, Value) :-
538
+ atom_number(Spec, Value).
539
+ opt_convert(integer, Spec, Value) :-
540
+ atom_number(Spec, Value),
541
+ integer(Value).
542
+ opt_convert(float, Spec, Value) :-
543
+ atom_number(Spec, Value0),
544
+ Value is float(Value0).
545
+ opt_convert(nonneg, Spec, Value) :-
546
+ atom_number(Spec, Value),
547
+ integer(Value),
548
+ Value >= 0.
549
+ opt_convert(natural, Spec, Value) :-
550
+ atom_number(Spec, Value),
551
+ integer(Value),
552
+ Value >= 1.
553
+ opt_convert(between(Low, High), Spec, Value) :-
554
+ atom_number(Spec, Value0),
555
+ ( ( float(Low) ; float(High) )
556
+ -> Value is float(Value0)
557
+ ; integer(Value0),
558
+ Value = Value0
559
+ ),
560
+ Value >= Low, Value =< High.
561
+ opt_convert(atom, Value, Value).
562
+ opt_convert(oneof(List), Value, Value) :-
563
+ memberchk(Value, List).
564
+ opt_convert(string, Value0, Value) :-
565
+ atom_string(Value0, Value).
566
+ opt_convert(file, Spec, Value) :-
567
+ prolog_to_os_filename(Value, Spec).
568
+ opt_convert(file(Access), Spec, Value) :-
569
+ ( Spec == '-'
570
+ -> Value = '-'
571
+ ; prolog_to_os_filename(Value, Spec),
572
+ ( access_file(Value, Access)
573
+ -> true
574
+ ; opt_error(access_file(Spec, Access))
575
+ )
576
+ ).
577
+ opt_convert(directory, Spec, Value) :-
578
+ prolog_to_os_filename(Value, Spec).
579
+ opt_convert(directory(Access), Spec, Value) :-
580
+ prolog_to_os_filename(Value, Spec),
581
+ access_directory(Value, Access).
582
+ opt_convert(term, Spec, Value) :-
583
+ term_string(Value, Spec, []).
584
+ opt_convert(term(Options), Spec, Value) :-
585
+ term_string(Term, Spec, Options),
586
+ ( option(variable_names(Bindings), Options)
587
+ -> Value = Term-Bindings
588
+ ; Value = Term
589
+ ).
590
+
591
+ access_directory(Dir, read) =>
592
+ exists_directory(Dir),
593
+ access_file(Dir, read).
594
+ access_directory(Dir, write) =>
595
+ exists_directory(Dir),
596
+ access_file(Dir, write).
597
+ access_directory(Dir, create) =>
598
+ ( exists_directory(Dir)
599
+ -> access_file(Dir, write)
600
+ ; \+ exists_file(Dir),
601
+ file_directory_name(Dir, Parent),
602
+ exists_directory(Parent),
603
+ access_file(Parent, write)
604
+ ).
605
+
606
+ to_bool(true, true).
607
+ to_bool('True', true).
608
+ to_bool('TRUE', true).
609
+ to_bool(on, true).
610
+ to_bool('On', true).
611
+ to_bool(yes, true).
612
+ to_bool('Yes', true).
613
+ to_bool('1', true).
614
+ to_bool(false, false).
615
+ to_bool('False', false).
616
+ to_bool('FALSE', false).
617
+ to_bool(off, false).
618
+ to_bool('Off', false).
619
+ to_bool(no, false).
620
+ to_bool('No', false).
621
+ to_bool('0', false).
622
+
623
+ %! argv_usage(:Level) is det.
624
+ %
625
+ % Use print_message/2 to print a usage message at Level. To print the
626
+ % message as plain text indefault color, use `debug`. Other meaningful
627
+ % options are `informational` or `warning`. The help page consists of
628
+ % four sections, two of which are optional:
629
+ %
630
+ % 1. The __header__ is created from opt_help(help(header), String).
631
+ % It is optional.
632
+ % 2. The __usage__ is added by default. The part behind
633
+ % ``Usage: <command>`` is by default ``[options]`` and can be
634
+ % overruled using opt_help(help(usage), String).
635
+ % 3. The actual option descriptions. The options are presented
636
+ % in the order they are defined in opt_type/3. Subsequent
637
+ % options for the same _destination_ (option name) are joined
638
+ % with the first.
639
+ % 4. The _footer__ is created from opt_help(help(footer), String).
640
+ % It is optional.
641
+ %
642
+ % The help provided by help(header), help(usage) and help(footer) are
643
+ % either a simple string or a list of elements as defined by
644
+ % print_message_lines/3. In the latter case, the construct `\Callable`
645
+ % can be used to call a DCG rule in the module from which the user
646
+ % calls argv_options/3. For example, we can add a bold title using
647
+ %
648
+ % opt_help(help(header), [ansi(bold, '~w', ['My title'])]).
649
+
650
+ argv_usage(M:Level) :-
651
+ print_message(Level, opt_usage(M)).
652
+
653
+ :- multifile
654
+ prolog:message//1.
655
+
656
+ prolog:message(opt_usage(M)) -->
657
+ usage(M).
658
+
659
+ usage(M) -->
660
+ usage_text(M:header),
661
+ usage_line(M),
662
+ usage_text(M:description),
663
+ usage_options(M),
664
+ usage_text(M:footer).
665
+
666
+ %! usage_text(:Which)// is det.
667
+ %
668
+ % Emit a user element. This may use elements as defined by
669
+ % print_message_lines/3 or can be a simple string.
670
+
671
+ usage_text(M:Which) -->
672
+ { in(M:opt_help(help(Which), Help))
673
+ },
674
+ !,
675
+ ( {Which == header ; Which == description}
676
+ -> user_text(M:Help), [nl, nl]
677
+ ; [nl, nl], user_text(M:Help)
678
+ ).
679
+ usage_text(_) -->
680
+ [].
681
+
682
+ user_text(M:Entries) -->
683
+ { is_list(Entries) },
684
+ !,
685
+ sequence(help_elem(M), Entries).
686
+ :- if(current_predicate(print_markdown/2)).
687
+ user_text(_:md(Help)) -->
688
+ !,
689
+ { with_output_to(string(String),
690
+ ( current_output(S),
691
+ set_stream(S, tty(true)),
692
+ print_markdown(Help, []))) },
693
+ [ '~s'-[String] ].
694
+ :- else.
695
+ user_text(_:md(Help)) -->
696
+ !,
697
+ [ '~w'-[Help] ].
698
+ :- endif.
699
+ user_text(_:Help) -->
700
+ [ '~w'-[Help] ].
701
+
702
+ help_elem(M, \Callable) -->
703
+ { callable(Callable) },
704
+ call(M:Callable),
705
+ !.
706
+ help_elem(_M, Elem) -->
707
+ [ Elem ].
708
+
709
+ usage_line(M) -->
710
+ { findall(Help, in(M:opt_help(help(usage), Help)), HelpLines)
711
+ },
712
+ [ ansi(comment, 'Usage: ', []) ],
713
+ ( {HelpLines == []}
714
+ -> cmdline(M), [ ' [options]'-[] ]
715
+ ; sequence(usage_line(M), [nl], HelpLines)
716
+ ),
717
+ [ nl, nl ].
718
+
719
+ usage_line(M, Help) -->
720
+ [ '~t~8|'-[] ],
721
+ cmdline(M),
722
+ user_text(M:Help).
723
+
724
+ cmdline(_M) -->
725
+ { current_prolog_flag(app_name, App),
726
+ !,
727
+ current_prolog_flag(os_argv, [Argv0|_])
728
+ },
729
+ cmdarg(Argv0), [' '-[], ansi(bold, '~w', [App])].
730
+ cmdline(_M) -->
731
+ { current_prolog_flag(associated_file, AbsFile),
732
+ file_base_name(AbsFile, Base),
733
+ current_prolog_flag(os_argv, Argv),
734
+ append(Pre, [File|_], Argv),
735
+ file_base_name(File, Base),
736
+ append(Pre, [File], Cmd),
737
+ !
738
+ },
739
+ sequence(cmdarg, [' '-[]], Cmd).
740
+ cmdline(_M) -->
741
+ { current_prolog_flag(saved_program, true),
742
+ current_prolog_flag(os_argv, OsArgv),
743
+ append(_, ['-x', State|_], OsArgv),
744
+ !
745
+ },
746
+ cmdarg(State).
747
+ cmdline(_M) -->
748
+ { current_prolog_flag(os_argv, [Argv0|_])
749
+ },
750
+ cmdarg(Argv0).
751
+
752
+ cmdarg(A) -->
753
+ [ '~w'-[A] ].
754
+
755
+ %! usage_options(+Module)//
756
+ %
757
+ % Find the defined options and display help on them. Uses opt_type/3
758
+ % to find the options and their type, opt_help/2 to find the option
759
+ % help comment and opt_meta/2 for _meta types_.
760
+
761
+ usage_options(M) -->
762
+ { findall(Opt, get_option(M, Opt), Opts),
763
+ maplist(options_width, Opts, OptWidths),
764
+ max_list(OptWidths, MaxOptWidth),
765
+ tty_width(Width),
766
+ OptColW is min(MaxOptWidth, 30),
767
+ HelpColW is Width-4-OptColW
768
+ },
769
+ [ ansi(comment, 'Options:', []), nl ],
770
+ sequence(opt_usage(OptColW, HelpColW), [nl], Opts).
771
+
772
+ % Just catch/3 is enough, but dependency tracking in e.g.,
773
+ % list_undefined/0 still considers this a missing dependency.
774
+ :- if(current_predicate(tty_size/2)).
775
+ tty_width(Width) :-
776
+ catch(tty_size(_, Width), _, Width = 80).
777
+ :- else.
778
+ tty_width(80).
779
+ :- endif.
780
+
781
+ opt_usage(OptColW, HelpColW, opt(_Name, Type, Short, Long, Help, Meta)) -->
782
+ options(Type, Short, Long, Meta),
783
+ [ '~t~*:| '-[OptColW] ],
784
+ help_text(Help, OptColW, HelpColW).
785
+
786
+ help_text([First|Lines], Indent, _Width) -->
787
+ !,
788
+ [ '~w'-[First], nl ],
789
+ sequence(rest_line(Indent), [nl], Lines).
790
+ help_text(Text, _Indent, Width) -->
791
+ { string_length(Text, Len),
792
+ Len =< Width
793
+ },
794
+ !,
795
+ [ '~w'-[Text] ].
796
+ help_text(Text, Indent, Width) -->
797
+ { wrap_text(Width, Text, [First|Lines])
798
+ },
799
+ [ '~w'-[First], nl ],
800
+ sequence(rest_line(Indent), [nl], Lines).
801
+
802
+ rest_line(Indent, Line) -->
803
+ [ '~t~*| ~w'-[Indent, Line] ].
804
+
805
+ %! wrap_text(+Width, +Text, -Wrapped)
806
+ %
807
+ % Simple text wrapper. Breaks Text into words and creates lines with
808
+ % minimally one word and as many additional words as fit in Width.
809
+ % Wrapped is a list of strings.
810
+
811
+ wrap_text(Width, Text, Wrapped) :-
812
+ split_string(Text, " \t\n", " \t\n", Words),
813
+ wrap_lines(Words, Width, Wrapped).
814
+
815
+ wrap_lines([], _, []).
816
+ wrap_lines([H|T0], Width, [Line|Lines]) :-
817
+ !,
818
+ string_length(H, Len),
819
+ take_line(T0, T1, Width, Len, LineWords),
820
+ atomics_to_string([H|LineWords], " ", Line),
821
+ wrap_lines(T1, Width, Lines).
822
+
823
+ take_line([H|T0], T, Width, Here, [H|Line]) :-
824
+ string_length(H, Len),
825
+ NewHere is Here+Len+1,
826
+ NewHere =< Width,
827
+ !,
828
+ take_line(T0, T, Width, NewHere, Line).
829
+ take_line(T, T, _, _, []).
830
+
831
+ %! options(+Type, +ShortOpt, +LongOpts, +Meta)//
832
+ %
833
+ % Emit a line with options.
834
+
835
+ options(Type, ShortOpt, LongOpts, Meta) -->
836
+ { append(ShortOpt, LongOpts, Opts) },
837
+ sequence(option(Type, Meta), [', '-[]], Opts).
838
+
839
+ option(boolean, _, Opt) -->
840
+ opt(Opt),
841
+ !.
842
+ option(_Type, [Meta], Opt) -->
843
+ \+ { short_opt(Opt) },
844
+ !,
845
+ opt(Opt),
846
+ [ '[='-[], ansi(var, '~w', [Meta]), ']'-[] ].
847
+ option(_Type, Meta, Opt) -->
848
+ opt(Opt),
849
+ ( { short_opt(Opt) }
850
+ -> [ ' '-[] ]
851
+ ; [ '='-[] ]
852
+ ),
853
+ [ ansi(var, '~w', [Meta]) ].
854
+
855
+ %! options_width(+Opt, -Width) is det.
856
+ %
857
+ % Compute the width of the column we need for the options.
858
+
859
+ options_width(opt(_Name, boolean, Short, Long, _Help, _Meta), W) =>
860
+ length(Short, SCount),
861
+ length(Long, LCount),
862
+ maplist(atom_length, Long, LLens),
863
+ sum_list(LLens, LLen),
864
+ W is ((SCount+LCount)-1)*2 + % ', ' seps
865
+ SCount*2 +
866
+ LCount*2 + LLen.
867
+ options_width(opt(_Name, _Type, Short, Long, _Help, Meta), W) =>
868
+ length(Short, SCount),
869
+ length(Long, LCount),
870
+ ( Meta = [MName]
871
+ -> atom_length(MName, MLen0),
872
+ MLen is MLen0+2
873
+ ; atom_length(Meta, MLen)
874
+ ),
875
+ maplist(atom_length, Long, LLens),
876
+ sum_list(LLens, LLen),
877
+ W is ((SCount+LCount)-1)*2 + % ', ' seps
878
+ SCount*3 + SCount*MLen +
879
+ LCount*3 + LLen + LCount*MLen.
880
+
881
+ %! get_option(+Module, -Opt) is multi.
882
+ %
883
+ % Get a description for a single option. Opt is a term
884
+ %
885
+ % opt(Name, Type, ShortFlags, Longflags, Help, Meta).
886
+
887
+ get_option(M, opt(help, boolean, [h,?], [help],
888
+ Help, -)) :-
889
+ \+ in(M:opt_type(_, help, boolean)), % user defined help
890
+ ( in(M:opt_help(help, Help))
891
+ -> true
892
+ ; Help = "Show this help message and exit"
893
+ ).
894
+ get_option(M, opt(Name, TypeName, Short, Long, Help, Meta)) :-
895
+ findall(Name, in(M:opt_type(_, Name, _)), Names),
896
+ list_to_set(Names, UNames),
897
+ member(Name, UNames),
898
+ findall(Opt-Type,
899
+ in(M:opt_type(Opt, Name, Type)),
900
+ Pairs),
901
+ option_type(Name, Pairs, TypeT),
902
+ functor(TypeT, TypeName, _),
903
+ pairs_keys(Pairs, Opts),
904
+ partition(short_opt, Opts, Short, Long),
905
+ ( in(M:opt_help(Name, Help))
906
+ -> true
907
+ ; Help = ''
908
+ ),
909
+ ( in(M:opt_meta(Name, Meta0))
910
+ -> true
911
+ ; type_name(TypeT, Meta0)
912
+ -> true
913
+ ; upcase_atom(TypeName, Meta0)
914
+ ),
915
+ ( \+ type_bool(TypeT, _),
916
+ type_optional_bool(TypeT, _)
917
+ -> Meta = [Meta0]
918
+ ; Meta = Meta0
919
+ ).
920
+
921
+ type_name(oneof(Values), Name) :-
922
+ atomics_to_string(Values, ",", S0),
923
+ format(atom(Name), '{~w}', [S0]).
924
+
925
+ option_type(Name, Pairs, Type) :-
926
+ pairs_values(Pairs, Types),
927
+ sort(Types, [Type|UTypes]),
928
+ ( UTypes = []
929
+ -> true
930
+ ; print_message(warning,
931
+ error(opt_error(multiple_types(Name, [Type|UTypes])),_))
932
+ ).
933
+
934
+ %! in(:Goal)
935
+ %
936
+ % As call/1, but fails silently if there is no predicate that
937
+ % implements Goal.
938
+
939
+ in(Goal) :-
940
+ pi_head(PI, Goal),
941
+ current_predicate(PI),
942
+ call(Goal).
943
+
944
+ short_opt(Opt) :-
945
+ atom_length(Opt, 1).
946
+
947
+ /*******************************
948
+ * OPT ERROR HANDLING *
949
+ *******************************/
950
+
951
+ %! opt_error(+Error)
952
+ %
953
+ % @error opt_error(Term)
954
+
955
+ opt_error(Error) :-
956
+ throw(error(opt_error(Error), _)).
957
+
958
+ :- multifile
959
+ prolog:error_message//1.
960
+
961
+ prolog:error_message(opt_error(Error)) -->
962
+ opt_error(Error).
963
+
964
+ opt_error(unknown_option(M:Opt)) -->
965
+ [ 'Unknown option: '-[] ],
966
+ opt(Opt),
967
+ hint_help(M).
968
+ opt_error(missing_value(Opt, Type)) -->
969
+ [ 'Option '-[] ],
970
+ opt(Opt),
971
+ [ ' requires an argument (of type ~p)'-[Type] ].
972
+ opt_error(value_type(Opt, Type, Found)) -->
973
+ [ 'Option '-[] ],
974
+ opt(Opt), [' requires'],
975
+ type(Type),
976
+ [ ' (found '-[], ansi(code, '~w', [Found]), ')'-[] ].
977
+ opt_error(access_file(File, exist)) -->
978
+ [ 'File '-[], ansi(code, '~w', [File]),
979
+ ' does not exist'-[]
980
+ ].
981
+ opt_error(access_file(File, Access)) -->
982
+ { access_verb(Access, Verb) },
983
+ [ 'Cannot access file '-[], ansi(code, '~w', [File]),
984
+ ' for '-[], ansi(code, '~w', [Verb])
985
+ ].
986
+
987
+ access_verb(read, reading).
988
+ access_verb(write, writing).
989
+ access_verb(append, writing).
990
+ access_verb(execute, executing).
991
+
992
+ hint_help(M) -->
993
+ { in(M:opt_type(Opt, help, boolean)) },
994
+ !,
995
+ [ ' (' ], opt(Opt), [' for help)'].
996
+ hint_help(_) -->
997
+ [ ' (-h for help)'-[] ].
998
+
999
+ opt(Opt) -->
1000
+ { short_opt(Opt) },
1001
+ !,
1002
+ [ ansi(bold, '-~w', [Opt]) ].
1003
+ opt(Opt) -->
1004
+ [ ansi(bold, '--~w', [Opt]) ].
1005
+
1006
+ type(A|B) -->
1007
+ type(A), [' or'],
1008
+ type(B).
1009
+ type(oneof([One])) -->
1010
+ !,
1011
+ [ ' ' ],
1012
+ atom(One).
1013
+ type(oneof(List)) -->
1014
+ !,
1015
+ [ ' one of '-[] ],
1016
+ sequence(atom, [', '], List).
1017
+ type(between(Low, High)) -->
1018
+ !,
1019
+ [ ' a number '-[],
1020
+ ansi(code, '~w', [Low]), '..', ansi(code, '~w', [High])
1021
+ ].
1022
+ type(nonneg) -->
1023
+ [ ' a non-negative integer'-[] ].
1024
+ type(natural) -->
1025
+ [ ' a positive integer (>= 1)'-[] ].
1026
+ type(file(Access)) -->
1027
+ [ ' a file with ~w access'-[Access] ].
1028
+ type(Type) -->
1029
+ [ ' an argument of type '-[], ansi(code, '~w', [Type]) ].
1030
+
1031
+ atom(A) -->
1032
+ [ ansi(code, '~w', [A]) ].
1033
+
1034
+
1035
+ /*******************************
1036
+ * DEBUG SUPPORT *
1037
+ *******************************/
1038
+
1039
+ %! cli_parse_debug_options(+OptionsIn, -Options) is det.
1040
+ %
1041
+ % Parse certain commandline options for debugging and development
1042
+ % purposes. Options processed are below. Note that the option
1043
+ % argument is an atom such that these options may be activated as
1044
+ % e.g., ``--debug='http(_)'``.
1045
+ %
1046
+ % - debug(Topic)
1047
+ % Call debug(Topic). See debug/1 and debug/3.
1048
+ % - spy(Predicate)
1049
+ % Place a spy-point on Predicate.
1050
+ % - gspy(Predicate)
1051
+ % As spy using the graphical debugger. See tspy/1.
1052
+ % - interactive(true)
1053
+ % Start the Prolog toplevel after main/1 completes.
1054
+
1055
+ cli_parse_debug_options([], []).
1056
+ cli_parse_debug_options([H|T0], Opts) :-
1057
+ debug_option(H),
1058
+ !,
1059
+ cli_parse_debug_options(T0, Opts).
1060
+ cli_parse_debug_options([H|T0], [H|T]) :-
1061
+ cli_parse_debug_options(T0, T).
1062
+
1063
+ %! cli_debug_opt_type(-Flag, -Option, -Type).
1064
+ %! cli_debug_opt_help(-Option, -Message).
1065
+ %! cli_debug_opt_meta(-Option, -Arg).
1066
+ %
1067
+ % Implements opt_type/3, opt_help/2 and opt_meta/2 for debug
1068
+ % arguments. Applications that wish to use these features can call
1069
+ % these predicates from their own hook. Fot example:
1070
+ %
1071
+ % ```
1072
+ % opt_type(..., ..., ...). % application types
1073
+ % opt_type(Flag, Opt, Type) :-
1074
+ % cli_debug_opt_type(Flag, Opt, Type).
1075
+ % % similar for opt_help/2 and opt_meta/2
1076
+ %
1077
+ % main(Argv) :-
1078
+ % argv_options(Argv, Positional, Options0),
1079
+ % cli_parse_debug_options(Options0, Options),
1080
+ % ...
1081
+ % ```
1082
+
1083
+ cli_debug_opt_type(debug, debug, string).
1084
+ cli_debug_opt_type(spy, spy, string).
1085
+ cli_debug_opt_type(gspy, gspy, string).
1086
+ cli_debug_opt_type(interactive, interactive, boolean).
1087
+
1088
+ cli_debug_opt_help(debug,
1089
+ "Call debug(Topic). See debug/1 and debug/3. \c
1090
+ Multiple topics may be separated by : or ;").
1091
+ cli_debug_opt_help(spy,
1092
+ "Place a spy-point on Predicate. \c
1093
+ Multiple topics may be separated by : or ;").
1094
+ cli_debug_opt_help(gspy,
1095
+ "As --spy using the graphical debugger. See tspy/1 \c
1096
+ Multiple topics may be separated by `;`").
1097
+ cli_debug_opt_help(interactive,
1098
+ "Start the Prolog toplevel after main/1 completes.").
1099
+
1100
+ cli_debug_opt_meta(debug, 'TOPICS').
1101
+ cli_debug_opt_meta(spy, 'PREDICATES').
1102
+ cli_debug_opt_meta(gspy, 'PREDICATES').
1103
+
1104
+ :- meta_predicate
1105
+ spy_from_string(1, +).
1106
+
1107
+ debug_option(interactive(true)) :-
1108
+ asserta(interactive).
1109
+ debug_option(debug(Spec)) :-
1110
+ split_string(Spec, ";", "", Specs),
1111
+ maplist(debug_from_string, Specs).
1112
+ debug_option(spy(Spec)) :-
1113
+ split_string(Spec, ";", "", Specs),
1114
+ maplist(spy_from_string(spy), Specs).
1115
+ debug_option(gspy(Spec)) :-
1116
+ split_string(Spec, ";", "", Specs),
1117
+ maplist(spy_from_string(cli_gspy), Specs).
1118
+
1119
+ debug_from_string(TopicS) :-
1120
+ term_string(Topic, TopicS),
1121
+ debug(Topic).
1122
+
1123
+ spy_from_string(Pred, Spec) :-
1124
+ atom_pi(Spec, PI),
1125
+ call(Pred, user:PI).
1126
+
1127
+ cli_gspy(PI) :-
1128
+ ( exists_source(library(threadutil))
1129
+ -> use_module(library(threadutil), [tspy/1]),
1130
+ Goal = tspy(PI)
1131
+ ; exists_source(library(gui_tracer))
1132
+ -> use_module(library(gui_tracer), [gspy/1]),
1133
+ Goal = gspy(PI)
1134
+ ; Goal = spy(PI)
1135
+ ),
1136
+ call(Goal).
1137
+
1138
+ atom_pi(Atom, Module:PI) :-
1139
+ split(Atom, :, Module, PiAtom),
1140
+ !,
1141
+ atom_pi(PiAtom, PI).
1142
+ atom_pi(Atom, Name//Arity) :-
1143
+ split(Atom, //, Name, Arity),
1144
+ !.
1145
+ atom_pi(Atom, Name/Arity) :-
1146
+ split(Atom, /, Name, Arity),
1147
+ !.
1148
+ atom_pi(Atom, _) :-
1149
+ format(user_error, 'Invalid predicate indicator: "~w"~n', [Atom]),
1150
+ halt(1).
1151
+
1152
+ split(Atom, Sep, Before, After) :-
1153
+ sub_atom(Atom, BL, _, AL, Sep),
1154
+ !,
1155
+ sub_atom(Atom, 0, BL, _, Before),
1156
+ sub_atom(Atom, _, AL, 0, AfterAtom),
1157
+ ( atom_number(AfterAtom, After)
1158
+ -> true
1159
+ ; After = AfterAtom
1160
+ ).
1161
+
1162
+
1163
+ %! cli_enable_development_system
1164
+ %
1165
+ % Re-enable the development environment. Currently re-enables xpce if
1166
+ % this was loaded, but not initialised and causes the interactive
1167
+ % toplevel to be re-enabled.
1168
+ %
1169
+ % This predicate may be called from main/1 to enter the Prolog
1170
+ % toplevel rather than terminating the application after main/1
1171
+ % completes.
1172
+
1173
+ cli_enable_development_system :-
1174
+ on_signal(int, _, debug),
1175
+ set_prolog_flag(xpce_threaded, true),
1176
+ set_prolog_flag(message_ide, true),
1177
+ ( current_prolog_flag(xpce_version, _)
1178
+ -> use_module(library(pce_dispatch)),
1179
+ memberchk(Goal, [pce_dispatch([])]),
1180
+ call(Goal)
1181
+ ; true
1182
+ ),
1183
+ set_prolog_flag(toplevel_goal, prolog).
1184
+
1185
+
1186
+ /*******************************
1187
+ * IDE SUPPORT *
1188
+ *******************************/
1189
+
1190
+ :- multifile
1191
+ prolog:called_by/2.
1192
+
1193
+ prolog:called_by(main, [main(_)]).
1194
+ prolog:called_by(argv_options(_,_,_),
1195
+ [ opt_type(_,_,_),
1196
+ opt_help(_,_),
1197
+ opt_meta(_,_)
1198
+ ]).
1199
+ prolog:called_by(argv_options(_,_,_,_), Called) :-
1200
+ prolog:called_by(argv_options(_,_,_), Called).