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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +40 -0
- data/README.md +3 -0
- data/lexers +0 -0
- data/lib/pygments/popen.rb +3 -2
- data/lib/pygments/version.rb +1 -1
- data/pygments.rb.gemspec +2 -1
- data/vendor/pygments-main/AUTHORS +20 -1
- data/vendor/pygments-main/CHANGES +55 -3
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/MANIFEST.in +1 -1
- data/vendor/pygments-main/Makefile +5 -8
- data/vendor/pygments-main/REVISION +1 -1
- data/vendor/pygments-main/doc/Makefile +153 -0
- data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
- data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
- data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
- data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
- data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
- data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
- data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
- data/vendor/pygments-main/doc/conf.py +249 -0
- data/vendor/pygments-main/doc/docs/api.rst +316 -0
- data/vendor/pygments-main/doc/docs/authors.rst +4 -0
- data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
- data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
- data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
- data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
- data/vendor/pygments-main/doc/docs/index.rst +66 -0
- data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
- data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
- data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
- data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
- data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
- data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
- data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
- data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
- data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
- data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
- data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
- data/vendor/pygments-main/doc/download.rst +41 -0
- data/vendor/pygments-main/doc/faq.rst +143 -0
- data/vendor/pygments-main/doc/index.rst +53 -0
- data/vendor/pygments-main/doc/languages.rst +151 -0
- data/vendor/pygments-main/doc/make.bat +190 -0
- data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
- data/vendor/pygments-main/external/autopygmentize +65 -48
- data/vendor/pygments-main/external/markdown-processor.py +15 -15
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +2 -3
- data/vendor/pygments-main/ez_setup.py +340 -234
- data/vendor/pygments-main/pygments/__init__.py +4 -4
- data/vendor/pygments-main/pygments/cmdline.py +81 -68
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
- data/vendor/pygments-main/pygments/formatter.py +3 -3
- data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
- data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +44 -26
- data/vendor/pygments-main/pygments/formatters/img.py +21 -14
- data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
- data/vendor/pygments-main/pygments/formatters/other.py +53 -6
- data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
- data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
- data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
- data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
- data/vendor/pygments-main/pygments/lexer.py +59 -39
- data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
- data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
- data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
- data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
- data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
- data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
- data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
- data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
- data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
- data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
- data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
- data/vendor/pygments-main/pygments/lexers/math.py +438 -70
- data/vendor/pygments-main/pygments/lexers/other.py +885 -171
- data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
- data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
- data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
- data/vendor/pygments-main/pygments/lexers/special.py +7 -8
- data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
- data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
- data/vendor/pygments-main/pygments/lexers/text.py +208 -46
- data/vendor/pygments-main/pygments/lexers/web.py +729 -264
- data/vendor/pygments-main/pygments/modeline.py +1 -1
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/sphinxext.py +153 -0
- data/vendor/pygments-main/pygments/style.py +3 -2
- data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
- data/vendor/pygments-main/pygments/styles/igor.py +29 -0
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
- data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
- data/vendor/pygments-main/pygments/token.py +4 -1
- data/vendor/pygments-main/pygments/unistring.py +6 -5
- data/vendor/pygments-main/pygments/util.py +35 -21
- data/vendor/pygments-main/scripts/check_sources.py +28 -44
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
- data/vendor/pygments-main/scripts/find_codetags.py +27 -19
- data/vendor/pygments-main/scripts/find_error.py +16 -13
- data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
- data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
- data/vendor/pygments-main/setup.py +19 -19
- data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
- data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
- data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
- data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
- data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
- data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
- data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
- data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
- data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
- data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
- data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
- data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
- data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
- data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
- data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
- data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
- data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
- data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
- data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
- data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
- data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
- data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
- data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
- data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
- data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
- data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
- data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
- data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
- data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
- data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
- data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
- data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
- data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
- data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
- data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
- data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
- data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
- data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
- data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
- data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
- data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
- data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
- data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
- data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
- data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
- data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
- data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
- data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
- data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
- data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
- data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
- data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
- data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
- data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
- data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
- data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
- data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
- data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
- data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
- data/vendor/pygments-main/tests/run.py +14 -19
- data/vendor/pygments-main/tests/string_asserts.py +22 -0
- data/vendor/pygments-main/tests/test_basic_api.py +28 -14
- data/vendor/pygments-main/tests/test_cfm.py +46 -0
- data/vendor/pygments-main/tests/test_clexer.py +208 -3
- data/vendor/pygments-main/tests/test_cmdline.py +6 -5
- data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
- data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
- data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
- data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
- data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
- data/vendor/pygments-main/tests/test_perllexer.py +1 -1
- data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
- data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
- data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
- data/vendor/pygments-main/tests/test_token.py +3 -3
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +1 -1
- metadata +138 -51
- data/vendor/pygments-main/docs/generate.py +0 -472
- data/vendor/pygments-main/docs/src/api.txt +0 -270
- data/vendor/pygments-main/docs/src/authors.txt +0 -5
- data/vendor/pygments-main/docs/src/changelog.txt +0 -5
- data/vendor/pygments-main/docs/src/index.txt +0 -69
- data/vendor/pygments-main/docs/src/installation.txt +0 -71
- data/vendor/pygments-main/external/rst-directive-old.py +0 -77
- data/vendor/pygments-main/scripts/reindent.py +0 -291
- data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
- data/vendor/pygments-main/tests/old_run.py +0 -138
File without changes
|
File without changes
|
@@ -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
|
2
|
-
sys
|
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 =
|
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 ->
|
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'
|
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
|
-
|
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)
|
50
|
+
if (is_ipv4 => (hexaddr << 32) + base_n 0x100 (map int ipv4)) (otherwise => hexaddr)
|
51
51
|
|
52
52
|
|
53
|
-
inet6_type = q ->
|
54
|
-
|
55
|
-
q == 1
|
56
|
-
(q >> 32) == 0x000000000000ffff
|
57
|
-
(q >> 64) == 0xfe80000000000000
|
58
|
-
(q >> 120) != 0x00000000000000ff
|
59
|
-
(q >> 112) % (1 << 4) == 0x0000000000000000
|
60
|
-
(q >> 112) % (1 << 4) == 0x000000000000000f
|
61
|
-
(q >> 112) % (1 << 4) == 0x0000000000000001
|
62
|
-
(q >> 112) % (1 << 4) == 0x0000000000000004
|
63
|
-
(q >> 112) % (1 << 4) == 0x0000000000000005
|
64
|
-
(q >> 112) % (1 << 4) == 0x0000000000000008
|
65
|
-
(q >> 112) % (1 << 4) == 0x000000000000000e
|
66
|
-
(q >> 112) % (1 << 4) != 0x0000000000000002
|
67
|
-
(q >> 24) % (1 << 112) == 0x00000000000001ff
|
68
|
-
|
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 ->
|
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
|
+
}
|