pygments.rb 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +3 -0
  4. data/lexers +0 -0
  5. data/lib/pygments/popen.rb +3 -2
  6. data/lib/pygments/version.rb +1 -1
  7. data/pygments.rb.gemspec +2 -1
  8. data/vendor/pygments-main/AUTHORS +20 -1
  9. data/vendor/pygments-main/CHANGES +55 -3
  10. data/vendor/pygments-main/LICENSE +1 -1
  11. data/vendor/pygments-main/MANIFEST.in +1 -1
  12. data/vendor/pygments-main/Makefile +5 -8
  13. data/vendor/pygments-main/REVISION +1 -1
  14. data/vendor/pygments-main/doc/Makefile +153 -0
  15. data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
  16. data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
  17. data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
  18. data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
  19. data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
  20. data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
  21. data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
  22. data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
  23. data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
  24. data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
  25. data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
  26. data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
  27. data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
  28. data/vendor/pygments-main/doc/conf.py +249 -0
  29. data/vendor/pygments-main/doc/docs/api.rst +316 -0
  30. data/vendor/pygments-main/doc/docs/authors.rst +4 -0
  31. data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
  32. data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
  33. data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
  34. data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
  35. data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
  36. data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
  37. data/vendor/pygments-main/doc/docs/index.rst +66 -0
  38. data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
  39. data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
  40. data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
  41. data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
  42. data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
  43. data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
  44. data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
  45. data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
  46. data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
  47. data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
  48. data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
  49. data/vendor/pygments-main/doc/download.rst +41 -0
  50. data/vendor/pygments-main/doc/faq.rst +143 -0
  51. data/vendor/pygments-main/doc/index.rst +53 -0
  52. data/vendor/pygments-main/doc/languages.rst +151 -0
  53. data/vendor/pygments-main/doc/make.bat +190 -0
  54. data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
  55. data/vendor/pygments-main/external/autopygmentize +65 -48
  56. data/vendor/pygments-main/external/markdown-processor.py +15 -15
  57. data/vendor/pygments-main/external/moin-parser.py +1 -1
  58. data/vendor/pygments-main/external/rst-directive.py +2 -3
  59. data/vendor/pygments-main/ez_setup.py +340 -234
  60. data/vendor/pygments-main/pygments/__init__.py +4 -4
  61. data/vendor/pygments-main/pygments/cmdline.py +81 -68
  62. data/vendor/pygments-main/pygments/console.py +1 -1
  63. data/vendor/pygments-main/pygments/filter.py +1 -1
  64. data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
  65. data/vendor/pygments-main/pygments/formatter.py +3 -3
  66. data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
  67. data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
  68. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  69. data/vendor/pygments-main/pygments/formatters/html.py +44 -26
  70. data/vendor/pygments-main/pygments/formatters/img.py +21 -14
  71. data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
  72. data/vendor/pygments-main/pygments/formatters/other.py +53 -6
  73. data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
  74. data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
  75. data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
  76. data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
  77. data/vendor/pygments-main/pygments/lexer.py +59 -39
  78. data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
  79. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
  80. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
  81. data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
  82. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
  83. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
  84. data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
  85. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
  86. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
  87. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
  88. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
  89. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
  90. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
  91. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
  92. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
  93. data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
  94. data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
  95. data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
  96. data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
  97. data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
  98. data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
  99. data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
  100. data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
  101. data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
  102. data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
  103. data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
  104. data/vendor/pygments-main/pygments/lexers/math.py +438 -70
  105. data/vendor/pygments-main/pygments/lexers/other.py +885 -171
  106. data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
  107. data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
  108. data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
  109. data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
  110. data/vendor/pygments-main/pygments/lexers/special.py +7 -8
  111. data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
  112. data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
  113. data/vendor/pygments-main/pygments/lexers/text.py +208 -46
  114. data/vendor/pygments-main/pygments/lexers/web.py +729 -264
  115. data/vendor/pygments-main/pygments/modeline.py +1 -1
  116. data/vendor/pygments-main/pygments/plugin.py +1 -1
  117. data/vendor/pygments-main/pygments/scanner.py +1 -1
  118. data/vendor/pygments-main/pygments/sphinxext.py +153 -0
  119. data/vendor/pygments-main/pygments/style.py +3 -2
  120. data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
  121. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  122. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  123. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  124. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  125. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  126. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  127. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  128. data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
  129. data/vendor/pygments-main/pygments/styles/igor.py +29 -0
  130. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  131. data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
  132. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  133. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  134. data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
  135. data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
  136. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  137. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  138. data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
  139. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  140. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  141. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  142. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  143. data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
  144. data/vendor/pygments-main/pygments/token.py +4 -1
  145. data/vendor/pygments-main/pygments/unistring.py +6 -5
  146. data/vendor/pygments-main/pygments/util.py +35 -21
  147. data/vendor/pygments-main/scripts/check_sources.py +28 -44
  148. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
  149. data/vendor/pygments-main/scripts/find_codetags.py +27 -19
  150. data/vendor/pygments-main/scripts/find_error.py +16 -13
  151. data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
  152. data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
  153. data/vendor/pygments-main/setup.py +19 -19
  154. data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
  155. data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
  156. data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
  157. data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
  158. data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
  159. data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
  160. data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
  161. data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
  162. data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
  163. data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
  164. data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
  165. data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
  166. data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
  167. data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
  168. data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
  169. data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
  170. data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
  171. data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
  172. data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
  173. data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
  174. data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
  175. data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
  176. data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
  177. data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
  178. data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
  179. data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
  180. data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
  181. data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
  182. data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
  183. data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
  184. data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
  185. data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
  186. data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
  187. data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
  188. data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
  189. data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
  190. data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
  191. data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
  192. data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
  193. data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
  194. data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
  195. data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
  196. data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
  197. data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
  198. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
  199. data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
  200. data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
  201. data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
  202. data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
  203. data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
  204. data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
  205. data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
  206. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
  207. data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
  208. data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
  209. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
  210. data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
  211. data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
  212. data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
  213. data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
  214. data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
  215. data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
  216. data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
  217. data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
  218. data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
  219. data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
  220. data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
  221. data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
  222. data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
  223. data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
  224. data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
  225. data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
  226. data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
  227. data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
  228. data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
  229. data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
  230. data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
  231. data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
  232. data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
  233. data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
  234. data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
  235. data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
  236. data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
  237. data/vendor/pygments-main/tests/run.py +14 -19
  238. data/vendor/pygments-main/tests/string_asserts.py +22 -0
  239. data/vendor/pygments-main/tests/test_basic_api.py +28 -14
  240. data/vendor/pygments-main/tests/test_cfm.py +46 -0
  241. data/vendor/pygments-main/tests/test_clexer.py +208 -3
  242. data/vendor/pygments-main/tests/test_cmdline.py +6 -5
  243. data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
  244. data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
  245. data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
  246. data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
  247. data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
  248. data/vendor/pygments-main/tests/test_perllexer.py +1 -1
  249. data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
  250. data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
  251. data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
  252. data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
  253. data/vendor/pygments-main/tests/test_token.py +3 -3
  254. data/vendor/pygments-main/tests/test_using_api.py +1 -1
  255. data/vendor/pygments-main/tests/test_util.py +1 -1
  256. metadata +138 -51
  257. data/vendor/pygments-main/docs/generate.py +0 -472
  258. data/vendor/pygments-main/docs/src/api.txt +0 -270
  259. data/vendor/pygments-main/docs/src/authors.txt +0 -5
  260. data/vendor/pygments-main/docs/src/changelog.txt +0 -5
  261. data/vendor/pygments-main/docs/src/index.txt +0 -69
  262. data/vendor/pygments-main/docs/src/installation.txt +0 -71
  263. data/vendor/pygments-main/external/rst-directive-old.py +0 -77
  264. data/vendor/pygments-main/scripts/reindent.py +0 -291
  265. data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
  266. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
  267. data/vendor/pygments-main/tests/old_run.py +0 -138
@@ -0,0 +1,5 @@
1
+ { :old_syntax => 'ok' }
2
+ { 'stings as key' => 'should be ok' }
3
+ { new_syntax: 'broken until now' }
4
+ { withoutunderscore: 'should be ok' }
5
+ { _underscoreinfront: 'might be ok, if I understand the pygments code correct' }
@@ -0,0 +1,6 @@
1
+ def me := object: {
2
+ def name := "Kevin";
3
+ def sayHello(peerName) {
4
+ system.println(peerName + " says hello!");
5
+ };
6
+ };
@@ -0,0 +1,5 @@
1
+ module hello.World
2
+
3
+ function main = |args| {
4
+ println("Hello world!")
5
+ }
@@ -0,0 +1,12 @@
1
+ default
2
+ {
3
+ state_entry()
4
+ {
5
+ llSay(0, "Hello, Avatar!");
6
+ }
7
+
8
+ touch_start(integer total_number)
9
+ {
10
+ llSay(0, "Touched.");
11
+ }
12
+ }
@@ -0,0 +1,23 @@
1
+ iex> :" multi
2
+ ...> line ' \s \123 \x20
3
+ ...> atom"
4
+ :" multi\n line ' S \natom"
5
+
6
+ iex(1)> <<"hello"::binary, c :: utf8, x::[4, unit(2)]>> = "hello™1"
7
+ "hello™1"
8
+
9
+ iex(2)> c
10
+ 8482
11
+
12
+ iex> 1 + :atom
13
+ ** (ArithmeticError) bad argument in arithmetic expression
14
+ :erlang.+(1, :atom)
15
+
16
+ iex(3)> 1 +
17
+ ...(3)> 2 +
18
+ ...(3)> 3
19
+ 6
20
+
21
+ iex> IO.puts "Hello world"
22
+ Hello world
23
+ :ok
@@ -1,5 +1,5 @@
1
- re = import!
2
- sys = import!
1
+ import '/re'
2
+ import '/sys'
3
3
 
4
4
 
5
5
  # IPv6address = hexpart [ ":" IPv4address ]
@@ -20,7 +20,7 @@ addrv6 = re.compile $ r'(?i)(?:{})(?::{})?$'.format hexpart addrv4
20
20
  #
21
21
  # :return: a decimal integer
22
22
  #
23
- base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
23
+ base_n = q digits -> foldl (x y -> x * q + y) 0 digits
24
24
 
25
25
 
26
26
  # Parse a sequence of hexadecimal numbers
@@ -29,7 +29,7 @@ base_n = (q digits) -> foldl (x y) -> (x * q + y) 0 digits
29
29
  #
30
30
  # :return: an iterable of Python ints
31
31
  #
32
- unhex = q -> q and map p -> (int p 16) (q.split ':')
32
+ unhex = q -> q and map (p -> int p 16) (q.split ':')
33
33
 
34
34
 
35
35
  # Parse an IPv6 address as specified in RFC 4291.
@@ -39,33 +39,33 @@ unhex = q -> q and map p -> (int p 16) (q.split ':')
39
39
  # :return: an integer which, written in binary form, points to the same node.
40
40
  #
41
41
  inet_pton6 = address ->
42
- raise $ ValueError 'not a valid IPv6 address' if not (match = addrv6.match address)
42
+ not (match = addrv6.match address) => raise $ ValueError 'not a valid IPv6 address'
43
43
  start, end, *ipv4 = match.groups!
44
44
 
45
45
  is_ipv4 = not $ None in ipv4
46
46
  shift = (7 - start.count ':' - 2 * is_ipv4) * 16
47
47
 
48
- raise $ ValueError 'not a valid IPv6 address' if (end is None and shift) or shift < 0
48
+ (end is None and shift) or shift < 0 => raise $ ValueError 'not a valid IPv6 address'
49
49
  hexaddr = (base_n 0x10000 (unhex start) << shift) + base_n 0x10000 (unhex $ end or '')
50
- (hexaddr << 32) + base_n 0x100 (map int ipv4) if is_ipv4 else hexaddr
50
+ if (is_ipv4 => (hexaddr << 32) + base_n 0x100 (map int ipv4)) (otherwise => hexaddr)
51
51
 
52
52
 
53
- inet6_type = q -> switch
54
- not q = 'unspecified'
55
- q == 1 = 'loopback'
56
- (q >> 32) == 0x000000000000ffff = 'IPv4-mapped'
57
- (q >> 64) == 0xfe80000000000000 = 'link-local'
58
- (q >> 120) != 0x00000000000000ff = 'general unicast'
59
- (q >> 112) % (1 << 4) == 0x0000000000000000 = 'multicast w/ reserved scope value'
60
- (q >> 112) % (1 << 4) == 0x000000000000000f = 'multicast w/ reserved scope value'
61
- (q >> 112) % (1 << 4) == 0x0000000000000001 = 'interface-local multicast'
62
- (q >> 112) % (1 << 4) == 0x0000000000000004 = 'admin-local multicast'
63
- (q >> 112) % (1 << 4) == 0x0000000000000005 = 'site-local multicast'
64
- (q >> 112) % (1 << 4) == 0x0000000000000008 = 'organization-local multicast'
65
- (q >> 112) % (1 << 4) == 0x000000000000000e = 'global multicast'
66
- (q >> 112) % (1 << 4) != 0x0000000000000002 = 'multicast w/ unknown scope value'
67
- (q >> 24) % (1 << 112) == 0x00000000000001ff = 'solicited-node multicast'
68
- True = 'link-local multicast'
53
+ inet6_type = q -> if
54
+ q == 0 => 'unspecified'
55
+ q == 1 => 'loopback'
56
+ (q >> 32) == 0x000000000000ffff => 'IPv4-mapped'
57
+ (q >> 64) == 0xfe80000000000000 => 'link-local'
58
+ (q >> 120) != 0x00000000000000ff => 'general unicast'
59
+ (q >> 112) % (1 << 4) == 0x0000000000000000 => 'multicast w/ reserved scope value'
60
+ (q >> 112) % (1 << 4) == 0x000000000000000f => 'multicast w/ reserved scope value'
61
+ (q >> 112) % (1 << 4) == 0x0000000000000001 => 'interface-local multicast'
62
+ (q >> 112) % (1 << 4) == 0x0000000000000004 => 'admin-local multicast'
63
+ (q >> 112) % (1 << 4) == 0x0000000000000005 => 'site-local multicast'
64
+ (q >> 112) % (1 << 4) == 0x0000000000000008 => 'organization-local multicast'
65
+ (q >> 112) % (1 << 4) == 0x000000000000000e => 'global multicast'
66
+ (q >> 112) % (1 << 4) != 0x0000000000000002 => 'multicast w/ unknown scope value'
67
+ (q >> 24) % (1 << 112) == 0x00000000000001ff => 'solicited-node multicast'
68
+ otherwise => 'link-local multicast'
69
69
 
70
70
 
71
- print $ (x -> (inet6_type x, hex x)) $ inet_pton6 $ sys.stdin.read!.strip!
71
+ print $ (x -> inet6_type x, hex x) $ inet_pton6 $ sys.stdin.read!.strip!
@@ -0,0 +1,165 @@
1
+ ;;;; This contains some of the core Hy functions used
2
+ ;;;; to make functional programming slightly easier.
3
+ ;;;;
4
+
5
+
6
+ (defn _numeric-check [x]
7
+ (if (not (numeric? x))
8
+ (raise (TypeError (.format "{0!r} is not a number" x)))))
9
+
10
+ (defn cycle [coll]
11
+ "Yield an infinite repetition of the items in coll"
12
+ (setv seen [])
13
+ (for [x coll]
14
+ (yield x)
15
+ (.append seen x))
16
+ (while seen
17
+ (for [x seen]
18
+ (yield x))))
19
+
20
+ (defn dec [n]
21
+ "Decrement n by 1"
22
+ (_numeric-check n)
23
+ (- n 1))
24
+
25
+ (defn distinct [coll]
26
+ "Return a generator from the original collection with duplicates
27
+ removed"
28
+ (let [[seen []] [citer (iter coll)]]
29
+ (for [val citer]
30
+ (if (not_in val seen)
31
+ (do
32
+ (yield val)
33
+ (.append seen val))))))
34
+
35
+ (defn drop [count coll]
36
+ "Drop `count` elements from `coll` and yield back the rest"
37
+ (let [[citer (iter coll)]]
38
+ (try (for [i (range count)]
39
+ (next citer))
40
+ (catch [StopIteration]))
41
+ citer))
42
+
43
+ (defn even? [n]
44
+ "Return true if n is an even number"
45
+ (_numeric-check n)
46
+ (= (% n 2) 0))
47
+
48
+ (defn filter [pred coll]
49
+ "Return all elements from `coll` that pass `pred`"
50
+ (let [[citer (iter coll)]]
51
+ (for [val citer]
52
+ (if (pred val)
53
+ (yield val)))))
54
+
55
+ (defn inc [n]
56
+ "Increment n by 1"
57
+ (_numeric-check n)
58
+ (+ n 1))
59
+
60
+ (defn instance? [klass x]
61
+ (isinstance x klass))
62
+
63
+ (defn iterable? [x]
64
+ "Return true if x is iterable"
65
+ (try (do (iter x) true)
66
+ (catch [Exception] false)))
67
+
68
+ (defn iterate [f x]
69
+ (setv val x)
70
+ (while true
71
+ (yield val)
72
+ (setv val (f val))))
73
+
74
+ (defn iterator? [x]
75
+ "Return true if x is an iterator"
76
+ (try (= x (iter x))
77
+ (catch [TypeError] false)))
78
+
79
+ (defn neg? [n]
80
+ "Return true if n is < 0"
81
+ (_numeric-check n)
82
+ (< n 0))
83
+
84
+ (defn none? [x]
85
+ "Return true if x is None"
86
+ (is x None))
87
+
88
+ (defn numeric? [x]
89
+ (import numbers)
90
+ (instance? numbers.Number x))
91
+
92
+ (defn nth [coll index]
93
+ "Return nth item in collection or sequence, counting from 0"
94
+ (if (not (neg? index))
95
+ (if (iterable? coll)
96
+ (try (first (list (take 1 (drop index coll))))
97
+ (catch [IndexError] None))
98
+ (try (get coll index)
99
+ (catch [IndexError] None)))
100
+ None))
101
+
102
+ (defn odd? [n]
103
+ "Return true if n is an odd number"
104
+ (_numeric-check n)
105
+ (= (% n 2) 1))
106
+
107
+ (defn pos? [n]
108
+ "Return true if n is > 0"
109
+ (_numeric_check n)
110
+ (> n 0))
111
+
112
+ (defn remove [pred coll]
113
+ "Return coll with elements removed that pass `pred`"
114
+ (let [[citer (iter coll)]]
115
+ (for [val citer]
116
+ (if (not (pred val))
117
+ (yield val)))))
118
+
119
+ (defn repeat [x &optional n]
120
+ "Yield x forever or optionally n times"
121
+ (if (none? n)
122
+ (setv dispatch (fn [] (while true (yield x))))
123
+ (setv dispatch (fn [] (for [_ (range n)] (yield x)))))
124
+ (dispatch))
125
+
126
+ (defn repeatedly [func]
127
+ "Yield result of running func repeatedly"
128
+ (while true
129
+ (yield (func))))
130
+
131
+ (defn take [count coll]
132
+ "Take `count` elements from `coll`, or the whole set if the total
133
+ number of entries in `coll` is less than `count`."
134
+ (let [[citer (iter coll)]]
135
+ (for [_ (range count)]
136
+ (yield (next citer)))))
137
+
138
+ (defn take-nth [n coll]
139
+ "Return every nth member of coll
140
+ raises ValueError for (not (pos? n))"
141
+ (if (pos? n)
142
+ (let [[citer (iter coll)] [skip (dec n)]]
143
+ (for [val citer]
144
+ (yield val)
145
+ (for [_ (range skip)]
146
+ (next citer))))
147
+ (raise (ValueError "n must be positive"))))
148
+
149
+ (defn take-while [pred coll]
150
+ "Take all elements while `pred` is true"
151
+ (let [[citer (iter coll)]]
152
+ (for [val citer]
153
+ (if (pred val)
154
+ (yield val)
155
+ (break)))))
156
+
157
+ (defn zero? [n]
158
+ "Return true if n is 0"
159
+ (_numeric_check n)
160
+ (= n 0))
161
+
162
+ (def *exports* ["cycle" "dec" "distinct" "drop" "even?" "filter" "inc"
163
+ "instance?" "iterable?" "iterate" "iterator?" "neg?"
164
+ "none?" "nth" "numeric?" "odd?" "pos?" "remove" "repeat"
165
+ "repeatedly" "take" "take_nth" "take_while" "zero?"])
@@ -0,0 +1,456 @@
1
+ implement Ninewin;
2
+ include "sys.m";
3
+ sys: Sys;
4
+ include "draw.m";
5
+ draw: Draw;
6
+ Image, Display, Pointer: import draw;
7
+ include "arg.m";
8
+ include "keyboard.m";
9
+ include "tk.m";
10
+ include "wmclient.m";
11
+ wmclient: Wmclient;
12
+ Window: import wmclient;
13
+ include "sh.m";
14
+ sh: Sh;
15
+
16
+ # run a p9 graphics program (default rio) under inferno wm,
17
+ # making available to it:
18
+ # /dev/winname - naming the current inferno window (changing on resize)
19
+ # /dev/mouse - pointer file + resize events; write to change position
20
+ # /dev/cursor - change appearance of cursor.
21
+ # /dev/draw - inferno draw device
22
+ # /dev/cons - read keyboard events, write to 9win stdout.
23
+
24
+ Ninewin: module {
25
+ init: fn(ctxt: ref Draw->Context, argv: list of string);
26
+ };
27
+ winname: string;
28
+
29
+ init(ctxt: ref Draw->Context, argv: list of string)
30
+ {
31
+ size := Draw->Point(500, 500);
32
+ sys = load Sys Sys->PATH;
33
+ draw = load Draw Draw->PATH;
34
+ wmclient = load Wmclient Wmclient->PATH;
35
+ wmclient->init();
36
+ sh = load Sh Sh->PATH;
37
+
38
+ buts := Wmclient->Resize;
39
+ if(ctxt == nil){
40
+ ctxt = wmclient->makedrawcontext();
41
+ buts = Wmclient->Plain;
42
+ }
43
+ arg := load Arg Arg->PATH;
44
+ arg->init(argv);
45
+ arg->setusage("9win [-s] [-x width] [-y height]");
46
+ exportonly := 0;
47
+ while(((opt := arg->opt())) != 0){
48
+ case opt {
49
+ 's' =>
50
+ exportonly = 1;
51
+ 'x' =>
52
+ size.x = int arg->earg();
53
+ 'y' =>
54
+ size.y = int arg->earg();
55
+ * =>
56
+ arg->usage();
57
+ }
58
+ }
59
+ if(size.x < 1 || size.y < 1)
60
+ arg->usage();
61
+ argv = arg->argv();
62
+ if(argv != nil && hd argv == "-s"){
63
+ exportonly = 1;
64
+ argv = tl argv;
65
+ }
66
+ if(argv == nil && !exportonly)
67
+ argv = "rio" :: nil;
68
+ if(argv != nil && exportonly){
69
+ sys->fprint(sys->fildes(2), "9win: no command allowed with -s flag\n");
70
+ raise "fail:usage";
71
+ }
72
+ title := "9win";
73
+ if(!exportonly)
74
+ title += " " + hd argv;
75
+ w := wmclient->window(ctxt, title, buts);
76
+ w.reshape(((0, 0), size));
77
+ w.onscreen(nil);
78
+ if(w.image == nil){
79
+ sys->fprint(sys->fildes(2), "9win: cannot get image to draw on\n");
80
+ raise "fail:no window";
81
+ }
82
+
83
+ sys->pctl(Sys->FORKNS|Sys->NEWPGRP, nil);
84
+ ld := "/n/9win";
85
+ if(sys->bind("#s", ld, Sys->MREPL) == -1 &&
86
+ sys->bind("#s", ld = "/n/local", Sys->MREPL) == -1){
87
+ sys->fprint(sys->fildes(2), "9win: cannot bind files: %r\n");
88
+ raise "fail:error";
89
+ }
90
+ w.startinput("kbd" :: "ptr" :: nil);
91
+ spawn ptrproc(rq := chan of Sys->Rread, ptr := chan[10] of ref Pointer, reshape := chan[1] of int);
92
+
93
+
94
+ fwinname := sys->file2chan(ld, "winname");
95
+ fconsctl := sys->file2chan(ld, "consctl");
96
+ fcons := sys->file2chan(ld, "cons");
97
+ fmouse := sys->file2chan(ld, "mouse");
98
+ fcursor := sys->file2chan(ld, "cursor");
99
+ if(!exportonly){
100
+ spawn run(sync := chan of string, w.ctl, ld, argv);
101
+ if((e := <-sync) != nil){
102
+ sys->fprint(sys->fildes(2), "9win: %s", e);
103
+ raise "fail:error";
104
+ }
105
+ }
106
+ spawn serveproc(w, rq, fwinname, fconsctl, fcons, fmouse, fcursor);
107
+ if(!exportonly){
108
+ # handle events synchronously so that we don't get a "killed" message
109
+ # from the shell.
110
+ handleevents(w, ptr, reshape);
111
+ }else{
112
+ spawn handleevents(w, ptr, reshape);
113
+ sys->bind(ld, "/dev", Sys->MBEFORE);
114
+ export(sys->fildes(0), w.ctl);
115
+ }
116
+ }
117
+
118
+ handleevents(w: ref Window, ptr: chan of ref Pointer, reshape: chan of int)
119
+ {
120
+ for(;;)alt{
121
+ c := <-w.ctxt.ctl or
122
+ c = <-w.ctl =>
123
+ e := w.wmctl(c);
124
+ if(e != nil)
125
+ sys->fprint(sys->fildes(2), "9win: ctl error: %s\n", e);
126
+ if(e == nil && c != nil && c[0] == '!'){
127
+ alt{
128
+ reshape <-= 1 =>
129
+ ;
130
+ * =>
131
+ ;
132
+ }
133
+ winname = nil;
134
+ }
135
+ p := <-w.ctxt.ptr =>
136
+ if(w.pointer(*p) == 0){
137
+ # XXX would block here if client isn't reading mouse... but we do want to
138
+ # extert back-pressure, which conflicts.
139
+ alt{
140
+ ptr <-= p =>
141
+ ;
142
+ * =>
143
+ ; # sys->fprint(sys->fildes(2), "9win: discarding mouse event\n");
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ serveproc(w: ref Window, mouserq: chan of Sys->Rread, fwinname, fconsctl, fcons, fmouse, fcursor: ref Sys->FileIO)
150
+ {
151
+ winid := 0;
152
+ krc: list of Sys->Rread;
153
+ ks: string;
154
+
155
+ for(;;)alt {
156
+ c := <-w.ctxt.kbd =>
157
+ ks[len ks] = inf2p9key(c);
158
+ if(krc != nil){
159
+ hd krc <-= (array of byte ks, nil);
160
+ ks = nil;
161
+ krc = tl krc;
162
+ }
163
+ (nil, d, nil, wc) := <-fcons.write =>
164
+ if(wc != nil){
165
+ sys->write(sys->fildes(1), d, len d);
166
+ wc <-= (len d, nil);
167
+ }
168
+ (nil, nil, nil, rc) := <-fcons.read =>
169
+ if(rc != nil){
170
+ if(ks != nil){
171
+ rc <-= (array of byte ks, nil);
172
+ ks = nil;
173
+ }else
174
+ krc = rc :: krc;
175
+ }
176
+ (offset, nil, nil, rc) := <-fwinname.read =>
177
+ if(rc != nil){
178
+ if(winname == nil){
179
+ winname = sys->sprint("noborder.9win.%d", winid++);
180
+ if(w.image.name(winname, 1) == -1){
181
+ sys->fprint(sys->fildes(2), "9win: namewin %q failed: %r", winname);
182
+ rc <-= (nil, "namewin failure");
183
+ break;
184
+ }
185
+ }
186
+ d := array of byte winname;
187
+ if(offset < len d)
188
+ d = d[offset:];
189
+ else
190
+ d = nil;
191
+ rc <-= (d, nil);
192
+ }
193
+ (nil, nil, nil, wc) := <-fwinname.write =>
194
+ if(wc != nil)
195
+ wc <-= (-1, "permission denied");
196
+ (nil, nil, nil, rc) := <-fconsctl.read =>
197
+ if(rc != nil)
198
+ rc <-= (nil, "permission denied");
199
+ (nil, d, nil, wc) := <-fconsctl.write =>
200
+ if(wc != nil){
201
+ if(string d != "rawon")
202
+ wc <-= (-1, "cannot change console mode");
203
+ else
204
+ wc <-= (len d, nil);
205
+ }
206
+ (nil, nil, nil, rc) := <-fmouse.read =>
207
+ if(rc != nil)
208
+ mouserq <-= rc;
209
+ (nil, d, nil, wc) := <-fmouse.write =>
210
+ if(wc != nil){
211
+ e := cursorset(w, string d);
212
+ if(e == nil)
213
+ wc <-= (len d, nil);
214
+ else
215
+ wc <-= (-1, e);
216
+ }
217
+ (nil, nil, nil, rc) := <-fcursor.read =>
218
+ if(rc != nil)
219
+ rc <-= (nil, "permission denied");
220
+ (nil, d, nil, wc) := <-fcursor.write =>
221
+ if(wc != nil){
222
+ e := cursorswitch(w, d);
223
+ if(e == nil)
224
+ wc <-= (len d, nil);
225
+ else
226
+ wc <-= (-1, e);
227
+ }
228
+ }
229
+ }
230
+
231
+ ptrproc(rq: chan of Sys->Rread, ptr: chan of ref Pointer, reshape: chan of int)
232
+ {
233
+ rl: list of Sys->Rread;
234
+ c := ref Pointer(0, (0, 0), 0);
235
+ for(;;){
236
+ ch: int;
237
+ alt{
238
+ p := <-ptr =>
239
+ ch = 'm';
240
+ c = p;
241
+ <-reshape =>
242
+ ch = 'r';
243
+ rc := <-rq =>
244
+ rl = rc :: rl;
245
+ continue;
246
+ }
247
+ if(rl == nil)
248
+ rl = <-rq :: rl;
249
+ hd rl <-= (sys->aprint("%c%11d %11d %11d %11d ", ch, c.xy.x, c.xy.y, c.buttons, c.msec), nil);
250
+ rl = tl rl;
251
+ }
252
+ }
253
+
254
+ cursorset(w: ref Window, m: string): string
255
+ {
256
+ if(m == nil || m[0] != 'm')
257
+ return "invalid mouse message";
258
+ x := int m[1:];
259
+ for(i := 1; i < len m; i++)
260
+ if(m[i] == ' '){
261
+ while(m[i] == ' ')
262
+ i++;
263
+ break;
264
+ }
265
+ if(i == len m)
266
+ return "invalid mouse message";
267
+ y := int m[i:];
268
+ return w.wmctl(sys->sprint("ptr %d %d", x, y));
269
+ }
270
+
271
+ cursorswitch(w: ref Window, d: array of byte): string
272
+ {
273
+ Hex: con "0123456789abcdef";
274
+ if(len d != 2*4+64)
275
+ return w.wmctl("cursor");
276
+ hot := Draw->Point(bglong(d, 0*4), bglong(d, 1*4));
277
+ s := sys->sprint("cursor %d %d 16 32 ", hot.x, hot.y);
278
+ for(i := 2*4; i < len d; i++){
279
+ c := int d[i];
280
+ s[len s] = Hex[c >> 4];
281
+ s[len s] = Hex[c & 16rf];
282
+ }
283
+ return w.wmctl(s);
284
+ }
285
+
286
+ run(sync, ctl: chan of string, ld: string, argv: list of string)
287
+ {
288
+ Rcmeta: con "|<>&^*[]?();";
289
+ sys->pctl(Sys->FORKNS, nil);
290
+ if(sys->bind("#₪", "/srv", Sys->MCREATE) == -1){
291
+ sync <-= sys->sprint("cannot bind srv device: %r");
292
+ exit;
293
+ }
294
+ srvname := "/srv/9win."+string sys->pctl(0, nil); # XXX do better.
295
+ fd := sys->create(srvname, Sys->ORDWR, 8r600);
296
+ if(fd == nil){
297
+ sync <-= sys->sprint("cannot create %s: %r", srvname);
298
+ exit;
299
+ }
300
+ sync <-= nil;
301
+ spawn export(fd, ctl);
302
+ sh->run(nil, "os" ::
303
+ "rc" :: "-c" ::
304
+ "mount "+srvname+" /mnt/term;"+
305
+ "rm "+srvname+";"+
306
+ "bind -b /mnt/term"+ld+" /dev;"+
307
+ "bind /mnt/term/dev/draw /dev/draw ||"+
308
+ "bind -a /mnt/term/dev /dev;"+
309
+ quotedc("cd"::"/mnt/term"+cwd()::nil, Rcmeta)+";"+
310
+ quotedc(argv, Rcmeta)+";"::
311
+ nil
312
+ );
313
+ }
314
+
315
+ export(fd: ref Sys->FD, ctl: chan of string)
316
+ {
317
+ sys->export(fd, "/", Sys->EXPWAIT);
318
+ ctl <-= "exit";
319
+ }
320
+
321
+ inf2p9key(c: int): int
322
+ {
323
+ KF: import Keyboard;
324
+
325
+ P9KF: con 16rF000;
326
+ Spec: con 16rF800;
327
+ Khome: con P9KF|16r0D;
328
+ Kup: con P9KF|16r0E;
329
+ Kpgup: con P9KF|16r0F;
330
+ Kprint: con P9KF|16r10;
331
+ Kleft: con P9KF|16r11;
332
+ Kright: con P9KF|16r12;
333
+ Kdown: con Spec|16r00;
334
+ Kview: con Spec|16r00;
335
+ Kpgdown: con P9KF|16r13;
336
+ Kins: con P9KF|16r14;
337
+ Kend: con P9KF|16r18;
338
+ Kalt: con P9KF|16r15;
339
+ Kshift: con P9KF|16r16;
340
+ Kctl: con P9KF|16r17;
341
+
342
+ case c {
343
+ Keyboard->LShift =>
344
+ return Kshift;
345
+ Keyboard->LCtrl =>
346
+ return Kctl;
347
+ Keyboard->LAlt =>
348
+ return Kalt;
349
+ Keyboard->Home =>
350
+ return Khome;
351
+ Keyboard->End =>
352
+ return Kend;
353
+ Keyboard->Up =>
354
+ return Kup;
355
+ Keyboard->Down =>
356
+ return Kdown;
357
+ Keyboard->Left =>
358
+ return Kleft;
359
+ Keyboard->Right =>
360
+ return Kright;
361
+ Keyboard->Pgup =>
362
+ return Kpgup;
363
+ Keyboard->Pgdown =>
364
+ return Kpgdown;
365
+ Keyboard->Ins =>
366
+ return Kins;
367
+
368
+ # function keys
369
+ KF|1 or
370
+ KF|2 or
371
+ KF|3 or
372
+ KF|4 or
373
+ KF|5 or
374
+ KF|6 or
375
+ KF|7 or
376
+ KF|8 or
377
+ KF|9 or
378
+ KF|10 or
379
+ KF|11 or
380
+ KF|12 =>
381
+ return (c - KF) + P9KF;
382
+ }
383
+ return c;
384
+ }
385
+
386
+ cwd(): string
387
+ {
388
+ return sys->fd2path(sys->open(".", Sys->OREAD));
389
+ }
390
+
391
+ # from string.b, waiting for declaration to be uncommented.
392
+ quotedc(argv: list of string, cl: string): string
393
+ {
394
+ s := "";
395
+ while (argv != nil) {
396
+ arg := hd argv;
397
+ for (i := 0; i < len arg; i++) {
398
+ c := arg[i];
399
+ if (c == ' ' || c == '\t' || c == '\n' || c == '\'' || in(c, cl))
400
+ break;
401
+ }
402
+ if (i < len arg || arg == nil) {
403
+ s += "'" + arg[0:i];
404
+ for (; i < len arg; i++) {
405
+ if (arg[i] == '\'')
406
+ s[len s] = '\'';
407
+ s[len s] = arg[i];
408
+ }
409
+ s[len s] = '\'';
410
+ } else
411
+ s += arg;
412
+ if (tl argv != nil)
413
+ s[len s] = ' ';
414
+ argv = tl argv;
415
+ }
416
+ return s;
417
+ }
418
+
419
+ in(c: int, s: string): int
420
+ {
421
+ n := len s;
422
+ if(n == 0)
423
+ return 0;
424
+ ans := 0;
425
+ negate := 0;
426
+ if(s[0] == '^') {
427
+ negate = 1;
428
+ s = s[1:];
429
+ n--;
430
+ }
431
+ for(i := 0; i < n; i++) {
432
+ if(s[i] == '-' && i > 0 && i < n-1) {
433
+ if(c >= s[i-1] && c <= s[i+1]) {
434
+ ans = 1;
435
+ break;
436
+ }
437
+ i++;
438
+ }
439
+ else
440
+ if(c == s[i]) {
441
+ ans = 1;
442
+ break;
443
+ }
444
+ }
445
+ if(negate)
446
+ ans = !ans;
447
+
448
+ # just to showcase labels
449
+ skip:
450
+ return ans;
451
+ }
452
+
453
+ bglong(d: array of byte, i: int): int
454
+ {
455
+ return int d[i] | (int d[i+1]<<8) | (int d[i+2]<<16) | (int d[i+3]<<24);
456
+ }