mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Compare commits
398 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1d3f396bb | ||
|
|
65ae444791 | ||
|
|
e9916c644d | ||
|
|
1940a9ea92 | ||
|
|
c9f8a2677a | ||
|
|
5b6b3f74b5 | ||
|
|
f9ccac4240 | ||
|
|
aa7aae7808 | ||
|
|
7c66301583 | ||
|
|
7df872eb7f | ||
|
|
6a4f4c724c | ||
|
|
76828c45c7 | ||
|
|
27215f148b | ||
|
|
77d52463ad | ||
|
|
0f6c2afbf6 | ||
|
|
cbaa3ca6f4 | ||
|
|
63f54bdf06 | ||
|
|
b302863a4d | ||
|
|
ec46b1a92e | ||
|
|
ed65040539 | ||
|
|
cc1a420bc5 | ||
|
|
8555b20380 | ||
|
|
6462ba70f9 | ||
|
|
1ac43e0d7d | ||
|
|
6ac51968c6 | ||
|
|
cbcadf8e45 | ||
|
|
74b111501d | ||
|
|
67e4212f64 | ||
|
|
55559a1020 | ||
|
|
b103232e0e | ||
|
|
b587379f4a | ||
|
|
ba654b2a1d | ||
|
|
ae39475133 | ||
|
|
c641ea833f | ||
|
|
ebf10c2cd6 | ||
|
|
29ef8beb3f | ||
|
|
2b5f38264b | ||
|
|
5850716eb3 | ||
|
|
3db6c4a5b6 | ||
|
|
e79607372b | ||
|
|
b5472ab753 | ||
|
|
013188dcd9 | ||
|
|
3cf7bfbee2 | ||
|
|
3bb740fe9f | ||
|
|
3f5a96a15b | ||
|
|
840bdf95e3 | ||
|
|
01deb07ae9 | ||
|
|
6c37613bf0 | ||
|
|
188c7364f8 | ||
|
|
09ead55502 | ||
|
|
f7f9513fba | ||
|
|
dd2d2389c8 | ||
|
|
03b43a85c8 | ||
|
|
fb709e2e10 | ||
|
|
dad653492a | ||
|
|
0db133ffb2 | ||
|
|
6d1682911b | ||
|
|
d1de479c49 | ||
|
|
ad7e231f39 | ||
|
|
f36d239b85 | ||
|
|
540865d045 | ||
|
|
5ed0da7b08 | ||
|
|
e61be66d4f | ||
|
|
d263f0c91a | ||
|
|
fee0cebcec | ||
|
|
3745308642 | ||
|
|
8843fa3ed4 | ||
|
|
464d6e9ec4 | ||
|
|
02ced24751 | ||
|
|
8b9ad131d1 | ||
|
|
5ef944e8b8 | ||
|
|
ea0145fda5 | ||
|
|
53c3cb382c | ||
|
|
179c557e5b | ||
|
|
8da458e1a8 | ||
|
|
b009c85b64 | ||
|
|
3eb3dd7d4b | ||
|
|
c9a1159a2e | ||
|
|
8664668524 | ||
|
|
3ba4cf699a | ||
|
|
8bc39ce44f | ||
|
|
2d03eae413 | ||
|
|
0d848b342f | ||
|
|
ad6030b0e8 | ||
|
|
bdb2a221a5 | ||
|
|
44f505e687 | ||
|
|
d931dacd47 | ||
|
|
1da425ae2f | ||
|
|
9ceea4ac81 | ||
|
|
a1010b8cf8 | ||
|
|
19a300a4ba | ||
|
|
1bc1803628 | ||
|
|
7fdead0100 | ||
|
|
3dcdc11c1b | ||
|
|
e8326529b5 | ||
|
|
2d5476f6c8 | ||
|
|
781133d0d3 | ||
|
|
c7b4cf636f | ||
|
|
d81c796dc0 | ||
|
|
1a3680bba6 | ||
|
|
600bca149a | ||
|
|
3a56d632e1 | ||
|
|
7f3f0327c2 | ||
|
|
cc0c71b277 | ||
|
|
e5ce286c63 | ||
|
|
86a0cf9424 | ||
|
|
eaea6ac837 | ||
|
|
4efc3ff822 | ||
|
|
c22a6563d9 | ||
|
|
f9683efb74 | ||
|
|
08945923e6 | ||
|
|
4745c62853 | ||
|
|
7c593899e7 | ||
|
|
9151e7066a | ||
|
|
b358a22d32 | ||
|
|
8a0ff14d22 | ||
|
|
7604a2d80b | ||
|
|
78b1c8a430 | ||
|
|
4ef925d8be | ||
|
|
7ba4f0c571 | ||
|
|
63fc9dd6a5 | ||
|
|
b350f1572b | ||
|
|
e24a9ba602 | ||
|
|
a338228b57 | ||
|
|
d6d232ec37 | ||
|
|
b723405e9f | ||
|
|
cecb125b0b | ||
|
|
2177ff1806 | ||
|
|
674eb31cfe | ||
|
|
9783710adf | ||
|
|
8888555f71 | ||
|
|
13a6180507 | ||
|
|
9a86b9ad75 | ||
|
|
65260e3aaa | ||
|
|
51af1bd162 | ||
|
|
e093ac843f | ||
|
|
13eb7c796e | ||
|
|
1cdd3c55ab | ||
|
|
407dbbb7fb | ||
|
|
0bccf97d16 | ||
|
|
c6e16ee6bd | ||
|
|
2b25bb6d1c | ||
|
|
e791a71566 | ||
|
|
739b512cee | ||
|
|
effcab4297 | ||
|
|
2e1161e061 | ||
|
|
649a5987e7 | ||
|
|
71e0e2bc8e | ||
|
|
fd7633518f | ||
|
|
04252c28f2 | ||
|
|
94be1ab277 | ||
|
|
8561f2a6b0 | ||
|
|
2bd050657d | ||
|
|
c7d8f39ad8 | ||
|
|
ad4b5bdc16 | ||
|
|
ef5eff45aa | ||
|
|
d18c8614ba | ||
|
|
29192e8d5f | ||
|
|
c2e894c48c | ||
|
|
2cc6e5bfe6 | ||
|
|
2d15ea54cb | ||
|
|
6b26386a81 | ||
|
|
525e886d79 | ||
|
|
05f73df064 | ||
|
|
e592381a54 | ||
|
|
fecf0cc137 | ||
|
|
507d191d7d | ||
|
|
8420e4b044 | ||
|
|
2ca5868610 | ||
|
|
6d8559eccb | ||
|
|
53d020f7b0 | ||
|
|
ad9a2d231e | ||
|
|
7bbb3da010 | ||
|
|
76a85b7637 | ||
|
|
80f72a5093 | ||
|
|
df552c241e | ||
|
|
9e020dd15d | ||
|
|
c7c0c30ecf | ||
|
|
60deead669 | ||
|
|
6d843eca60 | ||
|
|
12c22d0311 | ||
|
|
d28f5e87c0 | ||
|
|
471fabfff5 | ||
|
|
2e1a6d9d43 | ||
|
|
d2d22e849e | ||
|
|
6c41bfa44d | ||
|
|
d54bcc85e7 | ||
|
|
6d94ddb114 | ||
|
|
7fd720bf39 | ||
|
|
e10558e444 | ||
|
|
7c48d5ee1f | ||
|
|
10ffd870e2 | ||
|
|
3a4ab156b0 | ||
|
|
651d863069 | ||
|
|
a3c595a4a9 | ||
|
|
7660714a9e | ||
|
|
71002dfb65 | ||
|
|
013cfdcdaf | ||
|
|
5ad6add91e | ||
|
|
2f5b49f4ae | ||
|
|
353479fe72 | ||
|
|
6f5c935837 | ||
|
|
1bf91d4281 | ||
|
|
8d2dd55c94 | ||
|
|
6a86e8ea97 | ||
|
|
a817d95d6c | ||
|
|
7cdb5ccba8 | ||
|
|
22b8d462c2 | ||
|
|
066052ddd2 | ||
|
|
d673010420 | ||
|
|
fffd1b986d | ||
|
|
dc852b6398 | ||
|
|
64471be009 | ||
|
|
d43ffe09b3 | ||
|
|
e0c1107a25 | ||
|
|
3475aefd04 | ||
|
|
4e4a18c71a | ||
|
|
9a2f2c1fb2 | ||
|
|
b2ee2cc7b8 | ||
|
|
ee0b4f96a8 | ||
|
|
665f9ee5b5 | ||
|
|
4eb8903bed | ||
|
|
d11b2f05bb | ||
|
|
11f7e6e1b4 | ||
|
|
72acbc567b | ||
|
|
1170ac6105 | ||
|
|
bdc724d548 | ||
|
|
74cd03de0b | ||
|
|
5e9bb67d10 | ||
|
|
e969172543 | ||
|
|
f570260dfe | ||
|
|
7ecf65551e | ||
|
|
fb6ec8aaa7 | ||
|
|
0ba6a7adf0 | ||
|
|
0019abe5e7 | ||
|
|
30d2883436 | ||
|
|
cc5881dca2 | ||
|
|
d17f5dfd9e | ||
|
|
4c037c644f | ||
|
|
a08f0da30d | ||
|
|
654cfd7a47 | ||
|
|
88e79cd3a8 | ||
|
|
4543c7a0b3 | ||
|
|
f5bc9735af | ||
|
|
107a27aa25 | ||
|
|
5c29ce0695 | ||
|
|
41e1b7bd4e | ||
|
|
462a570d3c | ||
|
|
7f1af4215a | ||
|
|
7a141a923c | ||
|
|
0db1d1c8ca | ||
|
|
201b0ba53c | ||
|
|
3e54d6651c | ||
|
|
6d770ab68f | ||
|
|
6ca149de1d | ||
|
|
2e76ce740e | ||
|
|
a664b9dd0c | ||
|
|
d49701f470 | ||
|
|
67fae52b32 | ||
|
|
bb9f6ff082 | ||
|
|
ad7fc977df | ||
|
|
0479a89982 | ||
|
|
d7b9791514 | ||
|
|
832d379ace | ||
|
|
b8f3078966 | ||
|
|
d496aaae55 | ||
|
|
87e60cfd78 | ||
|
|
2077fa3837 | ||
|
|
eaa03e15ed | ||
|
|
95bedf0bfc | ||
|
|
3a1b17f1f9 | ||
|
|
9fe9bf617f | ||
|
|
3c34da8bd3 | ||
|
|
9fa7adaa61 | ||
|
|
54a2f5347a | ||
|
|
a716d3ad49 | ||
|
|
8f70604466 | ||
|
|
2044e191a2 | ||
|
|
8fe9ec0521 | ||
|
|
034e510ba5 | ||
|
|
bdec1ac64d | ||
|
|
36a0d760e9 | ||
|
|
a901e85c3c | ||
|
|
6e9dc2339d | ||
|
|
3864e712ef | ||
|
|
8376f1e4a4 | ||
|
|
1b0fd752d3 | ||
|
|
bef473a48b | ||
|
|
0c60078d27 | ||
|
|
2f65462ce0 | ||
|
|
ace6156c65 | ||
|
|
ada8feba34 | ||
|
|
75d685a7f4 | ||
|
|
6b7f20323b | ||
|
|
c2ab5bc09d | ||
|
|
95d5b8bdbc | ||
|
|
da7b3182e8 | ||
|
|
08790f2f0a | ||
|
|
896270e617 | ||
|
|
fb40ee986f | ||
|
|
20b82e4bc9 | ||
|
|
513347911e | ||
|
|
1a3960e95d | ||
|
|
7d9a47b7c3 | ||
|
|
c80d085e33 | ||
|
|
98518e5c8c | ||
|
|
2b7a488d64 | ||
|
|
25aa6669be | ||
|
|
ef9e1c4e4f | ||
|
|
cf483c28e3 | ||
|
|
fecc39d97d | ||
|
|
339370a703 | ||
|
|
359e5157a8 | ||
|
|
207bd8d77c | ||
|
|
ba5454808e | ||
|
|
9196ba91bb | ||
|
|
5ff1b02e49 | ||
|
|
4f92d620eb | ||
|
|
e7f5779659 | ||
|
|
512cfc4858 | ||
|
|
437ba70b9e | ||
|
|
fadca563bc | ||
|
|
7a601b196e | ||
|
|
bf6bd246fd | ||
|
|
168ff4c050 | ||
|
|
d6fdbafa3c | ||
|
|
3e1570a716 | ||
|
|
160c0b4ac0 | ||
|
|
cf0bc3914f | ||
|
|
96154627d3 | ||
|
|
6f07b62a3f | ||
|
|
cae17b91b8 | ||
|
|
69b68f3a44 | ||
|
|
20a3e7e4b8 | ||
|
|
119a8fff1e | ||
|
|
8094b1bd92 | ||
|
|
98fc4d78aa | ||
|
|
d773c2e90d | ||
|
|
7929e7ab9c | ||
|
|
e8e95f113c | ||
|
|
429c791377 | ||
|
|
e536eea5b6 | ||
|
|
0a5b5eadeb | ||
|
|
12351d3a8a | ||
|
|
aa8eb955e9 | ||
|
|
8e52c18200 | ||
|
|
7421b2e553 | ||
|
|
8aa4dce6f4 | ||
|
|
feeceefe99 | ||
|
|
60483e3216 | ||
|
|
49837e0c20 | ||
|
|
c7668ad882 | ||
|
|
4f37563be1 | ||
|
|
e468723abc | ||
|
|
9c3ab95048 | ||
|
|
99bfde32a8 | ||
|
|
bf5651e127 | ||
|
|
f854a12043 | ||
|
|
dd09f02f53 | ||
|
|
268f43d668 | ||
|
|
d95b7504ab | ||
|
|
4d2b6ee99e | ||
|
|
6ad6984fe7 | ||
|
|
97d48a204a | ||
|
|
c6e8915627 | ||
|
|
496b3e5a78 | ||
|
|
01be9e68ee | ||
|
|
b178268cbc | ||
|
|
3886c406ab | ||
|
|
b56671c20d | ||
|
|
f3cbad065f | ||
|
|
4b3b1a80f6 | ||
|
|
7abcc39c8c | ||
|
|
a5b915d571 | ||
|
|
5d0e9484ce | ||
|
|
68f04a50aa | ||
|
|
dc96f62f9e | ||
|
|
1363af0317 | ||
|
|
2418356eff | ||
|
|
b63423ce37 | ||
|
|
0b02b68538 | ||
|
|
bbd1646ae5 | ||
|
|
c4da2dd557 | ||
|
|
c5a654e692 | ||
|
|
3ac69ed4e0 | ||
|
|
f9ad5dda56 | ||
|
|
ff6a10698e | ||
|
|
6072a63f99 | ||
|
|
1bd935b2b4 | ||
|
|
7702583314 | ||
|
|
5ffc4c0158 | ||
|
|
7b44baa417 | ||
|
|
2c5e8c4308 | ||
|
|
506b75c5e8 | ||
|
|
af4b64070f | ||
|
|
29d8e58d69 | ||
|
|
e4975fc476 | ||
|
|
e1064b13c0 |
122
.gitmodules
vendored
122
.gitmodules
vendored
@@ -121,9 +121,9 @@
|
||||
[submodule "vendor/grammars/Handlebars"]
|
||||
path = vendor/grammars/Handlebars
|
||||
url = https://github.com/daaain/Handlebars
|
||||
[submodule "vendor/grammars/powershell.tmbundle"]
|
||||
path = vendor/grammars/powershell.tmbundle
|
||||
url = https://github.com/davidpeckham/powershell.tmbundle
|
||||
[submodule "vendor/grammars/powershell"]
|
||||
path = vendor/grammars/powershell
|
||||
url = https://github.com/SublimeText/PowerShell
|
||||
[submodule "vendor/grammars/jade-tmbundle"]
|
||||
path = vendor/grammars/jade-tmbundle
|
||||
url = https://github.com/davidrios/jade-tmbundle
|
||||
@@ -249,7 +249,7 @@
|
||||
url = https://github.com/shellderp/sublime-robot-plugin
|
||||
[submodule "vendor/grammars/actionscript3-tmbundle"]
|
||||
path = vendor/grammars/actionscript3-tmbundle
|
||||
url = https://github.com/simongregory/actionscript3-tmbundle
|
||||
url = https://github.com/honzabrecka/actionscript3-tmbundle
|
||||
[submodule "vendor/grammars/Sublime-QML"]
|
||||
path = vendor/grammars/Sublime-QML
|
||||
url = https://github.com/skozlovf/Sublime-QML
|
||||
@@ -337,6 +337,9 @@
|
||||
[submodule "vendor/grammars/ini.tmbundle"]
|
||||
path = vendor/grammars/ini.tmbundle
|
||||
url = https://github.com/textmate/ini.tmbundle
|
||||
[submodule "vendor/grammars/desktop.tmbundle"]
|
||||
path = vendor/grammars/desktop.tmbundle
|
||||
url = https://github.com/Mailaender/desktop.tmbundle.git
|
||||
[submodule "vendor/grammars/io.tmbundle"]
|
||||
path = vendor/grammars/io.tmbundle
|
||||
url = https://github.com/textmate/io.tmbundle
|
||||
@@ -394,9 +397,6 @@
|
||||
[submodule "vendor/grammars/pascal.tmbundle"]
|
||||
path = vendor/grammars/pascal.tmbundle
|
||||
url = https://github.com/textmate/pascal.tmbundle
|
||||
[submodule "vendor/grammars/perl.tmbundle"]
|
||||
path = vendor/grammars/perl.tmbundle
|
||||
url = https://github.com/textmate/perl.tmbundle
|
||||
[submodule "vendor/grammars/php-smarty.tmbundle"]
|
||||
path = vendor/grammars/php-smarty.tmbundle
|
||||
url = https://github.com/textmate/php-smarty.tmbundle
|
||||
@@ -525,9 +525,6 @@
|
||||
[submodule "vendor/grammars/sublime-bsv"]
|
||||
path = vendor/grammars/sublime-bsv
|
||||
url = https://github.com/thotypous/sublime-bsv
|
||||
[submodule "vendor/grammars/AutoHotkey"]
|
||||
path = vendor/grammars/AutoHotkey
|
||||
url = https://github.com/robertcollier4/AutoHotkey
|
||||
[submodule "vendor/grammars/Sublime-HTTP"]
|
||||
path = vendor/grammars/Sublime-HTTP
|
||||
url = https://github.com/httpspec/sublime-highlighting
|
||||
@@ -549,3 +546,108 @@
|
||||
[submodule "vendor/grammars/turtle.tmbundle"]
|
||||
path = vendor/grammars/turtle.tmbundle
|
||||
url = https://github.com/peta/turtle.tmbundle
|
||||
[submodule "vendor/grammars/liquid.tmbundle"]
|
||||
path = vendor/grammars/liquid.tmbundle
|
||||
url = https://github.com/bastilian/validcode-textmate-bundles
|
||||
[submodule "vendor/grammars/ats.sublime"]
|
||||
path = vendor/grammars/ats.sublime
|
||||
url = https://github.com/steinwaywhw/ats-mode-sublimetext
|
||||
[submodule "vendor/grammars/Modelica"]
|
||||
path = vendor/grammars/Modelica
|
||||
url = https://github.com/BorisChumichev/modelicaSublimeTextPackage
|
||||
[submodule "vendor/grammars/sublime-apl"]
|
||||
path = vendor/grammars/sublime-apl
|
||||
url = https://github.com/StoneCypher/sublime-apl
|
||||
[submodule "vendor/grammars/CLIPS-sublime"]
|
||||
path = vendor/grammars/CLIPS-sublime
|
||||
url = https://github.com/psicomante/CLIPS-sublime
|
||||
[submodule "vendor/grammars/Creole"]
|
||||
path = vendor/grammars/Creole
|
||||
url = https://github.com/Siddley/Creole
|
||||
[submodule "vendor/grammars/GDScript-sublime"]
|
||||
path = vendor/grammars/GDScript-sublime
|
||||
url = https://github.com/beefsack/GDScript-sublime
|
||||
[submodule "vendor/grammars/sublime-golo"]
|
||||
path = vendor/grammars/sublime-golo
|
||||
url = https://github.com/TypeUnsafe/sublime-golo
|
||||
[submodule "vendor/grammars/JSyntax"]
|
||||
path = vendor/grammars/JSyntax
|
||||
url = https://github.com/bcj/JSyntax
|
||||
[submodule "vendor/grammars/TXL"]
|
||||
path = vendor/grammars/TXL
|
||||
url = https://github.com/MikeHoffert/Sublime-Text-TXL-syntax
|
||||
[submodule "vendor/grammars/G-Code"]
|
||||
path = vendor/grammars/G-Code
|
||||
url = https://github.com/robotmaster/sublime-text-syntax-highlighting
|
||||
[submodule "vendor/grammars/grace-tmbundle"]
|
||||
path = vendor/grammars/grace-tmbundle
|
||||
url = https://github.com/zmthy/grace-tmbundle
|
||||
[submodule "vendor/grammars/sublime-text-ox"]
|
||||
path = vendor/grammars/sublime-text-ox
|
||||
url = https://github.com/andreashetland/sublime-text-ox
|
||||
[submodule "vendor/grammars/AutoHotkey"]
|
||||
path = vendor/grammars/AutoHotkey
|
||||
url = https://github.com/ahkscript/SublimeAutoHotkey
|
||||
[submodule "vendor/grammars/ec.tmbundle"]
|
||||
path = vendor/grammars/ec.tmbundle
|
||||
url = https://github.com/ecere/ec.tmbundle
|
||||
[submodule "vendor/grammars/InnoSetup"]
|
||||
path = vendor/grammars/InnoSetup
|
||||
url = https://github.com/idleberg/InnoSetup-Sublime-Text
|
||||
[submodule "vendor/grammars/gap-tmbundle"]
|
||||
path = vendor/grammars/gap-tmbundle
|
||||
url = https://github.com/dhowden/gap-tmbundle
|
||||
[submodule "vendor/grammars/SublimePapyrus"]
|
||||
path = vendor/grammars/SublimePapyrus
|
||||
url = https://github.com/Kapiainen/SublimePapyrus
|
||||
[submodule "vendor/grammars/sublime-spintools"]
|
||||
path = vendor/grammars/sublime-spintools
|
||||
url = https://github.com/bitbased/sublime-spintools
|
||||
[submodule "vendor/grammars/PogoScript.tmbundle"]
|
||||
path = vendor/grammars/PogoScript.tmbundle
|
||||
url = https://github.com/featurist/PogoScript.tmbundle
|
||||
[submodule "vendor/grammars/sublime-opal"]
|
||||
path = vendor/grammars/sublime-opal
|
||||
url = https://github.com/artifactz/sublime-opal
|
||||
[submodule "vendor/grammars/mediawiki.tmbundle"]
|
||||
path = vendor/grammars/mediawiki.tmbundle
|
||||
url = https://github.com/textmate/mediawiki.tmbundle
|
||||
[submodule "vendor/grammars/oracle.tmbundle"]
|
||||
path = vendor/grammars/oracle.tmbundle
|
||||
url = https://github.com/mulander/oracle.tmbundle.git
|
||||
[submodule "vendor/grammars/BrightScript.tmbundle"]
|
||||
path = vendor/grammars/BrightScript.tmbundle
|
||||
url = https://github.com/cmink/BrightScript.tmbundle
|
||||
[submodule "vendor/grammars/Stylus"]
|
||||
path = vendor/grammars/Stylus
|
||||
url = https://github.com/billymoon/Stylus
|
||||
[submodule "vendor/grammars/asciidoc.tmbundle"]
|
||||
path = vendor/grammars/asciidoc.tmbundle
|
||||
url = https://github.com/zuckschwerdt/asciidoc.tmbundle
|
||||
[submodule "vendor/grammars/sublime-text-pig-latin"]
|
||||
path = vendor/grammars/sublime-text-pig-latin
|
||||
url = https://github.com/goblindegook/sublime-text-pig-latin
|
||||
[submodule "vendor/grammars/Lean.tmbundle"]
|
||||
path = vendor/grammars/Lean.tmbundle
|
||||
url = https://github.com/leanprover/Lean.tmbundle
|
||||
[submodule "vendor/grammars/ampl"]
|
||||
path = vendor/grammars/ampl
|
||||
url = https://github.com/ampl/sublime-ampl
|
||||
[submodule "vendor/grammars/openscad.tmbundle"]
|
||||
path = vendor/grammars/openscad.tmbundle
|
||||
url = https://github.com/tbuser/openscad.tmbundle
|
||||
[submodule "vendor/grammars/sublime-varnish"]
|
||||
path = vendor/grammars/sublime-varnish
|
||||
url = https://github.com/brandonwamboldt/sublime-varnish
|
||||
[submodule "vendor/grammars/xc.tmbundle"]
|
||||
path = vendor/grammars/xc.tmbundle
|
||||
url = https://github.com/graymalkin/xc.tmbundle
|
||||
[submodule "vendor/grammars/perl.tmbundle"]
|
||||
path = vendor/grammars/perl.tmbundle
|
||||
url = https://github.com/textmate/perl.tmbundle
|
||||
[submodule "vendor/grammars/sublime-netlinx"]
|
||||
path = vendor/grammars/sublime-netlinx
|
||||
url = https://github.com/amclain/sublime-netlinx
|
||||
[submodule "vendor/grammars/Sublime-Red"]
|
||||
path = vendor/grammars/Sublime-Red
|
||||
url = https://github.com/Oldes/Sublime-Red
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
sudo: false
|
||||
before_install: script/travis/before_install
|
||||
rvm:
|
||||
- 1.9.3
|
||||
|
||||
@@ -1,41 +1,81 @@
|
||||
## Contributing
|
||||
# Contributing
|
||||
|
||||
The majority of contributions won't need to touch any Ruby code at all. The [master language list][languages] is just a YAML configuration file.
|
||||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. The majority of contributions won't need to touch any Ruby code at all.
|
||||
|
||||
Almost all bug fixes or new language additions should come with some additional code samples. Just drop them under [`samples/`][samples] in the correct subdirectory and our test suite will automatically test them. In most cases you shouldn't need to add any new assertions.
|
||||
## Adding a language
|
||||
|
||||
### My code is detected as the wrong language
|
||||
We try only to add languages once they have some usage on GitHub. In most cases we prefer that languages be in use in hundreds of repositories before supporting them in Linguist.
|
||||
|
||||
This can usually be solved either by adding a new filename or file name extension to the language's entry in [`languages.yml`][languages] or adding more [samples][samples] for your language to the repository to make Linguist's classifier smarter.
|
||||
|
||||
### Syntax highlighting looks wrong
|
||||
|
||||
Assuming your code is being detected as the right language (see above), in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream. If you can, try to reproduce the highlighting problem in the text editor that the grammar is designed for (TextMate, Sublime Text, or Atom) and include that information in your bug report.
|
||||
|
||||
You can also try to fix the bug yourself and submit a Pull Request. [This piece from TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars. You can test grammars using [Lightshow](https://lightshow.githubapp.com).
|
||||
|
||||
Once the bug has been fixed upstream, please let us know and we'll pick it up for GitHub.
|
||||
|
||||
### I want to add support for the `X` programming language
|
||||
|
||||
Great! You'll need to:
|
||||
To add support for a new language:
|
||||
|
||||
0. Add an entry for your language to [`languages.yml`][languages].
|
||||
0. Add a grammar for your language. Please only add grammars that have a license that permits redistribution.
|
||||
0. Add your grammar as a submodule: `git submodule add https://github.com/JaneSmith/MyGrammar vendor/grammars/MyGrammar`.
|
||||
0. Add your grammar to [`grammars.yml`][grammars] by running `script/convert-grammars --add vendor/grammars/MyGrammar`.
|
||||
0. Add samples for your language to the [samples directory][samples].
|
||||
0. Add your grammar as a submodule: `git submodule add https://github.com/JaneSmith/MyGrammar vendor/grammars/MyGrammar`.
|
||||
0. Add your grammar to [`grammars.yml`][grammars] by running `script/convert-grammars --add vendor/grammars/MyGrammar`.
|
||||
0. Add samples for your language to the [samples directory][samples] in the correct subdirectory.
|
||||
0. Open a pull request, linking to a [GitHub search result](https://github.com/search?utf8=%E2%9C%93&q=extension%3Aboot+NOT+nothack&type=Code&ref=searchresults) showing in-the-wild usage.
|
||||
|
||||
In addition, if your new language defines an extension that's already listed in [`languages.yml`][languages] (such as `.foo`) then sometimes a few more steps will need to be taken:
|
||||
|
||||
0. Make sure that example `.foo` files are present in the [samples directory][samples] for each language that uses `.foo`.
|
||||
0. Make sure that example `.foo` files are present in the [samples directory][samples] for each language that uses `.foo`.
|
||||
0. Test the performance of the Bayesian classifier with a relatively large number (1000s) of sample `.foo` files. (ping @arfon or @bkeepers to help with this) to ensure we're not misclassifying files.
|
||||
0. If the Bayesian classifier does a bad job with the sample `.foo` files then a [heuristic](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb) may need to be written to help.
|
||||
|
||||
Remember, the goal here is to try and avoid false positives!
|
||||
|
||||
We try only to add languages once they have some usage on GitHub, so please note in-the-wild usage examples in your pull request. In most cases we prefer that languages already be in use in hundreds of repositories before supporting them in Linguist.
|
||||
## Fixing a misclassified language
|
||||
|
||||
Most languages are detected by their file extension defined in [languages.yml][languages]. For disambiguating between files with common extensions, linguist applies some [heuristics](/lib/linguist/heuristics.rb) and a [statistical classifier](lib/linguist/classifier.rb). This process can help differentiate between, for example, `.h` files which could be either C, C++, or Obj-C.
|
||||
|
||||
Misclassifications can often be solved by either adding a new filename or extension for the language or adding more [samples][samples] to make the classifier smarter.
|
||||
|
||||
## Fixing syntax highlighting
|
||||
|
||||
Syntax highlighting in GitHub is performed using TextMate-compatible grammars. These are the same grammars that TextMate, Sublime Text and Atom use. Every language in [languages.yml][languages] is mapped to its corresponding TM `scope`. This scope will be used when picking up a grammar for highlighting.
|
||||
|
||||
Assuming your code is being detected as the right language, in most cases this is due to a bug in the language grammar rather than a bug in Linguist. [`grammars.yml`][grammars] lists all the grammars we use for syntax highlighting on github.com. Find the one corresponding to your code's programming language and submit a bug report upstream. If you can, try to reproduce the highlighting problem in the text editor that the grammar is designed for (TextMate, Sublime Text, or Atom) and include that information in your bug report.
|
||||
|
||||
You can also try to fix the bug yourself and submit a Pull Request. [TextMate's documentation](http://manual.macromates.com/en/language_grammars) offers a good introduction on how to work with TextMate-compatible grammars. You can test grammars using [Lightshow](https://github-lightshow.herokuapp.com).
|
||||
|
||||
Once the bug has been fixed upstream, please let us know and we'll pick it up for GitHub.
|
||||
|
||||
## Testing
|
||||
|
||||
For development you are going to want to checkout out the source. To get it, clone the repo and run [Bundler](http://gembundler.com/) to install its dependencies.
|
||||
|
||||
git clone https://github.com/github/linguist.git
|
||||
cd linguist/
|
||||
script/bootstrap
|
||||
|
||||
To run the tests:
|
||||
|
||||
bundle exec rake test
|
||||
|
||||
Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay: be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away.
|
||||
|
||||
Here's our current build status: [](http://travis-ci.org/github/linguist)
|
||||
|
||||
## Releasing
|
||||
|
||||
If you are the current maintainer of this gem:
|
||||
|
||||
0. Create a branch for the release: `git checkout -b cut-release-vxx.xx.xx`
|
||||
0. Make sure your local dependencies are up to date: `script/bootstrap`
|
||||
0. If grammar submodules have not been updated recently, update them: `git submodule update --remote && git commit -a`
|
||||
0. Ensure that samples are updated: `bundle exec rake samples`
|
||||
0. Ensure that tests are green: `bundle exec rake test`
|
||||
0. Bump gem version in `lib/linguist/version.rb`, [like this](https://github.com/github/linguist/commit/8d2ea90a5ba3b2fe6e1508b7155aa4632eea2985).
|
||||
0. Make a PR to github/linguist, [like this](https://github.com/github/linguist/pull/1238).
|
||||
0. Build a local gem: `bundle exec rake build_gem`
|
||||
0. Test the gem:
|
||||
0. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
|
||||
0. Install the new gem locally
|
||||
0. Test behavior locally, branch deploy, whatever needs to happen
|
||||
0. Merge github/linguist PR
|
||||
0. Tag and push: `git tag vx.xx.xx; git push --tags`
|
||||
0. Push to rubygems.org -- `gem push github-linguist-3.0.0.gem`
|
||||
|
||||
[grammars]: /grammars.yml
|
||||
[languages]: /lib/linguist/languages.yml
|
||||
[samples]: /samples
|
||||
[new-issue]: https://github.com/github/linguist/issues/new
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2011-2014 GitHub, Inc.
|
||||
Copyright (c) 2011-2015 GitHub, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
225
README.md
225
README.md
@@ -1,45 +1,80 @@
|
||||
# Linguist
|
||||
|
||||
We use this library at GitHub to detect blob languages, ignore binary files, suppress generated files in diffs, and generate language breakdown graphs.
|
||||
[issues]: https://github.com/github/linguist/issues
|
||||
[new-issue]: https://github.com/github/linguist/issues/new
|
||||
|
||||
Tips for filing issues and creating pull requests can be found in [`CONTRIBUTING.md`](/CONTRIBUTING.md).
|
||||
This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs.
|
||||
|
||||
## Features
|
||||
See [Troubleshooting](#troubleshooting) and [`CONTRIBUTING.md`](/CONTRIBUTING.md) before filing an issue or creating a pull request.
|
||||
|
||||
### Language detection
|
||||
## Troubleshooting
|
||||
|
||||
Linguist defines a list of all languages known to GitHub in a [yaml file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
|
||||
### My repository is detected as the wrong language
|
||||
|
||||
Most languages are detected by their file extension. For disambiguating between files with common extensions, we first apply some common-sense heuristics to pick out obvious languages. After that, we use a
|
||||
[statistical
|
||||
classifier](https://github.com/github/linguist/blob/master/lib/linguist/classifier.rb).
|
||||
This process can help us tell the difference between, for example, `.h` files which could be either C, C++, or Obj-C.
|
||||

|
||||
|
||||
```ruby
|
||||
The Language stats bar is built by aggregating the languages of each file in that repository. If it is reporting a language that you don't expect:
|
||||
|
||||
Linguist::FileBlob.new("lib/linguist.rb").language.name #=> "Ruby"
|
||||
0. Click on the name of the language in the stats bar to see a list of the files that are identified as that language.
|
||||
0. If you see files that you didn't write, consider moving the files into one of the [paths for vendored code](https://github.com/github/linguist/blob/master/lib/linguist/vendor.yml), or use the [manual overrides](#overrides) feature to ignore them.
|
||||
0. If the files are being misclassified, search for [open issues][issues] to see if anyone else has already reported the issue. Any information you an add, especially links to public repositories, is helpful.
|
||||
0. If there are no reported issues of this misclassification, [open an issue][new-issue] and include a link to the repository or a sample of the code that is being misclassified.
|
||||
|
||||
Linguist::FileBlob.new("bin/linguist").language.name #=> "Ruby"
|
||||
## Overrides
|
||||
|
||||
Linguist supports a number of different custom overrides strategies for language definitions and vendored paths.
|
||||
|
||||
### Using gitattributes
|
||||
|
||||
Add a `.gitattributes` file to your project and use standard git-style path matchers for the files you want to override to set `linguist-documentation`, `linguist-language`, and `linguist-vendored`. `.gitattributes` will be used to determine language statistics, but will not be used to syntax highlight files. To manually set syntax highlighting, use [Vim or Emacs modelines](#using-emacs-and-vim-modelines).
|
||||
|
||||
```
|
||||
$ cat .gitattributes
|
||||
*.rb linguist-language=Java
|
||||
```
|
||||
|
||||
See [lib/linguist/language.rb](https://github.com/github/linguist/blob/master/lib/linguist/language.rb) and [lib/linguist/languages.yml](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml).
|
||||
Checking code you didn't write, such as JavaScript libraries, into your git repo is a common practice, but this often inflates your project's language stats and may even cause your project to be labeled as another language. By default, Linguist treats all of the paths defined in [lib/linguist/vendor.yml](https://github.com/github/linguist/blob/master/lib/linguist/vendor.yml) as vendored and therefore doesn't include them in the language statistics for a repository. Vendored files are also hidden by default in diffs on github.com.
|
||||
|
||||
### Syntax Highlighting
|
||||
Use the `linguist-vendored` attribute to vendor or un-vendor paths.
|
||||
|
||||
Syntax highlighting in GitHub is performed using TextMate-compatible grammars. These are the same grammars that TextMate, Sublime Text and Atom use.
|
||||
```
|
||||
$ cat .gitattributes
|
||||
special-vendored-path/* linguist-vendored
|
||||
jquery.js linguist-vendored=false
|
||||
```
|
||||
|
||||
Every language in `languages.yml` is mapped to its corresponding TM `scope`. This scope will be used when picking up a grammar for highlighting. **When adding a new language to Linguist, please add its corresponding scope too (assuming there's an existing TextMate bundle, Sublime Text package, or Atom package) so syntax highlighting works for it**.
|
||||
Similar to vendored files, Linguist excludes documentation files from your project's language stats. (Unlike vendored files, documentation files are displayed in diffs on github.com.) [lib/linguist/documentation.yml](lib/linguist/documentation.yml) lists common documentation paths and excludes them from the language statistics for your repository.
|
||||
|
||||
### Stats
|
||||
Use the `linguist-documentation` attribute to mark or unmark paths as documentation.
|
||||
|
||||
The Language stats bar that you see on every repository is built by aggregating the languages of each file in that repository. The top language in the graph determines the project's primary language.
|
||||
```
|
||||
$ cat .gitattributes
|
||||
project-docs/* linguist-documentation
|
||||
docs/formatter.rb linguist-documentation=false
|
||||
```
|
||||
|
||||
The repository stats API, accessed through `#languages`, can be used on a directory:
|
||||
### Using Emacs and Vim modelines
|
||||
|
||||
***API UPDATE***
|
||||
Alternatively, you can use Vim and Emacs style modelines to set the language for a single file. Modelines can be placed anywhere within a file and are respected when determining how to syntax-highlight a file on GitHub.com
|
||||
|
||||
Since [Version 3.0.0](https://github.com/github/linguist/releases/tag/v3.0.0) Linguist expects a git repository (in the form of a [Rugged::Repository](https://github.com/libgit2/rugged#repositories)) to be passed when initializing `Linguist::Repository`.
|
||||
```
|
||||
Vim
|
||||
vim: set filetype=prolog:
|
||||
vim: set ft=cpp:
|
||||
|
||||
Emacs
|
||||
-*- mode: php;-*-
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Install the gem:
|
||||
|
||||
```
|
||||
$ gem install github-linguist
|
||||
```
|
||||
|
||||
Then use it in your application:
|
||||
|
||||
```ruby
|
||||
require 'rugged'
|
||||
@@ -51,147 +86,27 @@ project.language #=> "Ruby"
|
||||
project.languages #=> { "Ruby" => 119387 }
|
||||
```
|
||||
|
||||
These stats are also printed out by the `linguist` binary. You can use the
|
||||
These stats are also printed out by the `linguist` executable. You can use the
|
||||
`--breakdown` flag, and the binary will also output the breakdown of files by language.
|
||||
|
||||
You can try running `linguist` on the root directory in this repository itself:
|
||||
|
||||
$ bundle exec linguist --breakdown
|
||||
```
|
||||
$ bundle exec linguist --breakdown
|
||||
|
||||
100.00% Ruby
|
||||
100.00% Ruby
|
||||
|
||||
Ruby:
|
||||
Gemfile
|
||||
Rakefile
|
||||
bin/linguist
|
||||
github-linguist.gemspec
|
||||
lib/linguist.rb
|
||||
lib/linguist/blob_helper.rb
|
||||
lib/linguist/classifier.rb
|
||||
lib/linguist/file_blob.rb
|
||||
lib/linguist/generated.rb
|
||||
lib/linguist/heuristics.rb
|
||||
lib/linguist/language.rb
|
||||
lib/linguist/lazy_blob.rb
|
||||
lib/linguist/md5.rb
|
||||
lib/linguist/repository.rb
|
||||
lib/linguist/samples.rb
|
||||
lib/linguist/tokenizer.rb
|
||||
lib/linguist/version.rb
|
||||
test/test_blob.rb
|
||||
test/test_classifier.rb
|
||||
test/test_heuristics.rb
|
||||
test/test_language.rb
|
||||
test/test_md5.rb
|
||||
test/test_pedantic.rb
|
||||
test/test_repository.rb
|
||||
test/test_samples.rb
|
||||
test/test_tokenizer.rb
|
||||
|
||||
#### Ignore vendored files
|
||||
|
||||
Checking other code into your git repo is a common practice. But this often inflates your project's language stats and may even cause your project to be labeled as another language. We are able to identify some of these files and directories and exclude them.
|
||||
|
||||
```ruby
|
||||
Linguist::FileBlob.new("vendor/plugins/foo.rb").vendored? # => true
|
||||
Ruby:
|
||||
Gemfile
|
||||
Rakefile
|
||||
bin/linguist
|
||||
github-linguist.gemspec
|
||||
lib/linguist.rb
|
||||
…
|
||||
```
|
||||
|
||||
See [Linguist::BlobHelper#vendored?](https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb) and [lib/linguist/vendor.yml](https://github.com/github/linguist/blob/master/lib/linguist/vendor.yml).
|
||||
## Contributing
|
||||
|
||||
#### Generated file detection
|
||||
Please check out our [contributing guidelines](CONTRIBUTING.md).
|
||||
|
||||
Not all plain text files are true source files. Generated files like minified js and compiled CoffeeScript can be detected and excluded from language stats. As an extra bonus, these files are suppressed in diffs.
|
||||
|
||||
```ruby
|
||||
Linguist::FileBlob.new("underscore.min.js").generated? # => true
|
||||
```
|
||||
|
||||
See [Linguist::Generated#generated?](https://github.com/github/linguist/blob/master/lib/linguist/generated.rb).
|
||||
|
||||
## Overrides
|
||||
|
||||
Linguist supports custom overrides for language definitions and vendored paths. Add a `.gitattributes` file to your project using the keys `linguist-language` and `linguist-vendored` with the standard git-style path matchers for the files you want to override.
|
||||
|
||||
Please note that the overrides currently only affect the language statistics for a repository and not the syntax-highlighting of files.
|
||||
|
||||
```
|
||||
$ cat .gitattributes
|
||||
*.rb linguist-language=Java
|
||||
|
||||
$ linguist --breakdown
|
||||
100.00% Java
|
||||
|
||||
Java:
|
||||
ruby_file.rb
|
||||
```
|
||||
|
||||
By default, Linguist treats all of the paths defined in [lib/linguist/vendor.yml](https://github.com/github/linguist/blob/master/lib/linguist/vendor.yml) as vendored and therefore doesn't include them in the language statistics for a repository. Use the `linguist-vendored` attribute to vendor or un-vendor paths.
|
||||
|
||||
```
|
||||
$ cat .gitattributes
|
||||
special-vendored-path/* linguist-vendored
|
||||
jquery.js linguist-vendored=false
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Github.com is usually running the latest version of the `github-linguist` gem that is released on [RubyGems.org](http://rubygems.org/gems/github-linguist).
|
||||
|
||||
But for development you are going to want to checkout out the source. To get it, clone the repo and run [Bundler](http://gembundler.com/) to install its dependencies.
|
||||
|
||||
git clone https://github.com/github/linguist.git
|
||||
cd linguist/
|
||||
script/bootstrap
|
||||
|
||||
To run the tests:
|
||||
|
||||
bundle exec rake test
|
||||
|
||||
### A note on language extensions
|
||||
|
||||
Linguist has a number of methods available to it for identifying the language of a particular file. The initial lookup is based upon the extension of the file, possible file extensions are defined in an array called `extensions`. Take a look at this example for example for `Perl`:
|
||||
|
||||
```
|
||||
Perl:
|
||||
type: programming
|
||||
ace_mode: perl
|
||||
color: "#0298c3"
|
||||
extensions:
|
||||
- .pl
|
||||
- .PL
|
||||
- .perl
|
||||
- .ph
|
||||
- .plx
|
||||
- .pm
|
||||
- .pod
|
||||
- .psgi
|
||||
interpreters:
|
||||
- perl
|
||||
```
|
||||
Any of the extensions defined are valid but the first in this array should be the most popular.
|
||||
|
||||
### Testing
|
||||
|
||||
Sometimes getting the tests running can be too much work, especially if you don't have much Ruby experience. It's okay: be lazy and let our build bot [Travis](http://travis-ci.org/#!/github/linguist) run the tests for you. Just open a pull request and the bot will start cranking away.
|
||||
|
||||
Here's our current build status, which is hopefully green: [](http://travis-ci.org/github/linguist)
|
||||
|
||||
### Releasing
|
||||
|
||||
If you are the current maintainer of this gem:
|
||||
|
||||
0. Create a branch for the release: `git checkout -b cut-release-vxx.xx.xx`
|
||||
0. Make sure your local dependencies are up to date: `script/bootstrap`
|
||||
0. If grammar submodules have not been updated recently, update them: `git submodule update --remote && git commit -a`
|
||||
0. Ensure that samples are updated: `bundle exec rake samples`
|
||||
0. Ensure that tests are green: `bundle exec rake test`
|
||||
0. Bump gem version in `lib/linguist/version.rb`. For example, [like this](https://github.com/github/linguist/commit/8d2ea90a5ba3b2fe6e1508b7155aa4632eea2985).
|
||||
0. Make a PR to github/linguist. For example, [#1238](https://github.com/github/linguist/pull/1238).
|
||||
0. Build a local gem: `bundle exec rake build_gem`
|
||||
0. Testing:
|
||||
0. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
|
||||
0. Install the new gem locally
|
||||
0. Test behavior locally, branch deploy, whatever needs to happen
|
||||
0. Merge github/linguist PR
|
||||
0. Tag and push: `git tag vx.xx.xx; git push --tags`
|
||||
0. Push to rubygems.org -- `gem push github-linguist-3.0.0.gem`
|
||||
##
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
# linguist — detect language type for a file, or, given a directory, determine language breakdown
|
||||
# usage: linguist <path> [<--breakdown>]
|
||||
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/language'
|
||||
require 'linguist/repository'
|
||||
#
|
||||
require 'linguist'
|
||||
require 'rugged'
|
||||
|
||||
path = ARGV[0] || Dir.pwd
|
||||
|
||||
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency 'charlock_holmes', '~> 0.7.3'
|
||||
s.add_dependency 'escape_utils', '~> 1.0.1'
|
||||
s.add_dependency 'mime-types', '>= 1.19'
|
||||
s.add_dependency 'rugged', '~> 0.22.0b4'
|
||||
s.add_dependency 'rugged', '~> 0.23.0b1'
|
||||
|
||||
s.add_development_dependency 'minitest', '>= 5.0'
|
||||
s.add_development_dependency 'mocha'
|
||||
|
||||
86
grammars.yml
86
grammars.yml
@@ -24,28 +24,51 @@ vendor/grammars/Agda.tmbundle:
|
||||
- source.agda
|
||||
vendor/grammars/Alloy.tmbundle:
|
||||
- source.alloy
|
||||
vendor/grammars/AutoHotkey:
|
||||
vendor/grammars/AutoHotkey/:
|
||||
- source.ahk
|
||||
vendor/grammars/BrightScript.tmbundle/:
|
||||
- source.brightauthorproject
|
||||
- source.brightscript
|
||||
vendor/grammars/CLIPS-sublime:
|
||||
- source.clips
|
||||
vendor/grammars/ColdFusion:
|
||||
- source.cfscript
|
||||
- source.cfscript.cfc
|
||||
- text.cfml.basic
|
||||
- text.html.cfm
|
||||
vendor/grammars/Creole:
|
||||
- text.html.creole
|
||||
vendor/grammars/Docker.tmbundle:
|
||||
- source.dockerfile
|
||||
vendor/grammars/Elm.tmLanguage:
|
||||
- source.elm
|
||||
vendor/grammars/G-Code/:
|
||||
- source.LS
|
||||
- source.MCPOST
|
||||
- source.MOD
|
||||
- source.apt
|
||||
- source.gcode
|
||||
vendor/grammars/GDScript-sublime/:
|
||||
- source.gdscript
|
||||
vendor/grammars/Handlebars:
|
||||
- text.html.handlebars
|
||||
vendor/grammars/IDL-Syntax:
|
||||
- source.webidl
|
||||
vendor/grammars/InnoSetup/:
|
||||
- source.inno
|
||||
vendor/grammars/Isabelle.tmbundle:
|
||||
- source.isabelle.root
|
||||
- source.isabelle.theory
|
||||
vendor/grammars/JSyntax/:
|
||||
- source.j
|
||||
vendor/grammars/Julia.tmbundle:
|
||||
- source.julia
|
||||
vendor/grammars/Lean.tmbundle:
|
||||
- source.lean
|
||||
vendor/grammars/LiveScript.tmbundle:
|
||||
- source.livescript
|
||||
vendor/grammars/Modelica/:
|
||||
- source.modelica
|
||||
vendor/grammars/NSIS:
|
||||
- source.nsis
|
||||
vendor/grammars/NimLime:
|
||||
@@ -54,6 +77,8 @@ vendor/grammars/NimLime:
|
||||
- source.nimcfg
|
||||
vendor/grammars/PHP-Twig.tmbundle:
|
||||
- text.html.twig
|
||||
vendor/grammars/PogoScript.tmbundle/:
|
||||
- source.pogoscript
|
||||
vendor/grammars/RDoc.tmbundle:
|
||||
- text.rdoc
|
||||
vendor/grammars/Racket:
|
||||
@@ -68,6 +93,8 @@ vendor/grammars/Slash.tmbundle:
|
||||
vendor/grammars/Stata.tmbundle:
|
||||
- source.mata
|
||||
- source.stata
|
||||
vendor/grammars/Stylus/:
|
||||
- source.stylus
|
||||
vendor/grammars/Sublime-Coq:
|
||||
- source.coq
|
||||
vendor/grammars/Sublime-HTTP:
|
||||
@@ -86,6 +113,8 @@ vendor/grammars/Sublime-QML:
|
||||
- source.qml
|
||||
vendor/grammars/Sublime-REBOL:
|
||||
- source.rebol
|
||||
vendor/grammars/Sublime-Red:
|
||||
- source.red
|
||||
vendor/grammars/Sublime-SQF-Language:
|
||||
- source.sqf
|
||||
vendor/grammars/Sublime-Text-2-OpenEdge-ABL:
|
||||
@@ -94,8 +123,14 @@ vendor/grammars/Sublime-VimL:
|
||||
- source.viml
|
||||
vendor/grammars/SublimeBrainfuck:
|
||||
- source.bf
|
||||
vendor/grammars/SublimePapyrus/:
|
||||
- source.compiled-papyrus
|
||||
- source.papyrus
|
||||
- source.papyrus-assembly
|
||||
vendor/grammars/SublimeXtend:
|
||||
- source.xtend
|
||||
vendor/grammars/TXL/:
|
||||
- source.txl
|
||||
vendor/grammars/Textmate-Gosu-Bundle:
|
||||
- source.gosu.2
|
||||
vendor/grammars/VBDotNetSyntax:
|
||||
@@ -110,6 +145,8 @@ vendor/grammars/actionscript3-tmbundle:
|
||||
- text.xml.flex-config
|
||||
vendor/grammars/ada.tmbundle:
|
||||
- source.ada
|
||||
vendor/grammars/ampl:
|
||||
- source.ampl
|
||||
vendor/grammars/ant.tmbundle:
|
||||
- text.xml.ant
|
||||
vendor/grammars/antlr.tmbundle:
|
||||
@@ -119,6 +156,8 @@ vendor/grammars/apache.tmbundle:
|
||||
- source.apache-config.mod_perl
|
||||
vendor/grammars/applescript.tmbundle:
|
||||
- source.applescript
|
||||
vendor/grammars/asciidoc.tmbundle/:
|
||||
- text.html.asciidoc
|
||||
vendor/grammars/asp.tmbundle:
|
||||
- source.asp
|
||||
- text.html.asp
|
||||
@@ -128,6 +167,8 @@ vendor/grammars/assembly.tmbundle:
|
||||
vendor/grammars/atom-salt:
|
||||
- source.python.salt
|
||||
- source.yaml.salt
|
||||
vendor/grammars/ats.sublime:
|
||||
- source.ats
|
||||
vendor/grammars/autoitv3-tmbundle:
|
||||
- source.autoit.3
|
||||
vendor/grammars/awk-sublime:
|
||||
@@ -170,6 +211,8 @@ vendor/grammars/dart-sublime-bundle:
|
||||
- source.dart
|
||||
- source.pubspec
|
||||
- text.dart-doccomments
|
||||
vendor/grammars/desktop.tmbundle:
|
||||
- source.desktop
|
||||
vendor/grammars/diff.tmbundle:
|
||||
- source.diff
|
||||
vendor/grammars/dylan.tmbundle:
|
||||
@@ -178,6 +221,8 @@ vendor/grammars/dylan.tmbundle:
|
||||
- source.makegen
|
||||
vendor/grammars/ebundles/Bundles/MSDOS batch file.tmbundle:
|
||||
- source.dosbatch
|
||||
vendor/grammars/ec.tmbundle/:
|
||||
- source.c.ec
|
||||
vendor/grammars/eiffel.tmbundle:
|
||||
- source.eiffel
|
||||
vendor/grammars/elixir-tmbundle:
|
||||
@@ -199,12 +244,16 @@ vendor/grammars/fortran.tmbundle:
|
||||
- source.fortran.modern
|
||||
vendor/grammars/fsharpbinding:
|
||||
- source.fsharp
|
||||
vendor/grammars/gap-tmbundle/:
|
||||
- source.gap
|
||||
vendor/grammars/gettext.tmbundle:
|
||||
- source.po
|
||||
vendor/grammars/gnuplot-tmbundle:
|
||||
- source.gnuplot
|
||||
vendor/grammars/go-tmbundle:
|
||||
- source.go
|
||||
vendor/grammars/grace-tmbundle/:
|
||||
- source.grace
|
||||
vendor/grammars/gradle.tmbundle:
|
||||
- source.groovy.gradle
|
||||
vendor/grammars/graphviz.tmbundle:
|
||||
@@ -289,6 +338,8 @@ vendor/grammars/less.tmbundle:
|
||||
- source.css.less
|
||||
vendor/grammars/lilypond.tmbundle:
|
||||
- source.lilypond
|
||||
vendor/grammars/liquid.tmbundle:
|
||||
- text.html.liquid
|
||||
vendor/grammars/lisp.tmbundle:
|
||||
- source.lisp
|
||||
vendor/grammars/llvm.tmbundle:
|
||||
@@ -308,6 +359,8 @@ vendor/grammars/matlab.tmbundle:
|
||||
- source.octave
|
||||
vendor/grammars/maven.tmbundle:
|
||||
- text.xml.pom
|
||||
vendor/grammars/mediawiki.tmbundle/:
|
||||
- text.html.mediawiki
|
||||
vendor/grammars/mercury-tmlanguage:
|
||||
- source.mercury
|
||||
vendor/grammars/monkey.tmbundle:
|
||||
@@ -334,12 +387,17 @@ vendor/grammars/ooc.tmbundle:
|
||||
- source.ooc
|
||||
vendor/grammars/opa.tmbundle:
|
||||
- source.opa
|
||||
vendor/grammars/openscad.tmbundle/:
|
||||
- source.scad
|
||||
vendor/grammars/oracle.tmbundle:
|
||||
- source.plsql.oracle
|
||||
vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage:
|
||||
- source.oz
|
||||
vendor/grammars/pascal.tmbundle:
|
||||
- source.pascal
|
||||
vendor/grammars/perl.tmbundle:
|
||||
vendor/grammars/perl.tmbundle/:
|
||||
- source.perl
|
||||
- source.perl.6
|
||||
vendor/grammars/php-smarty.tmbundle:
|
||||
- source.smarty
|
||||
vendor/grammars/php.tmbundle:
|
||||
@@ -348,7 +406,7 @@ vendor/grammars/pike-textmate:
|
||||
- source.pike
|
||||
vendor/grammars/postscript.tmbundle:
|
||||
- source.postscript
|
||||
vendor/grammars/powershell.tmbundle:
|
||||
vendor/grammars/powershell:
|
||||
- source.powershell
|
||||
vendor/grammars/processing.tmbundle:
|
||||
- source.processing
|
||||
@@ -400,6 +458,8 @@ vendor/grammars/standard-ml.tmbundle:
|
||||
- source.ml
|
||||
vendor/grammars/sublime-MuPAD:
|
||||
- source.mupad
|
||||
vendor/grammars/sublime-apl/:
|
||||
- source.apl
|
||||
vendor/grammars/sublime-befunge:
|
||||
- source.befunge
|
||||
vendor/grammars/sublime-better-typescript:
|
||||
@@ -411,25 +471,43 @@ vendor/grammars/sublime-cirru:
|
||||
vendor/grammars/sublime-glsl:
|
||||
- source.essl
|
||||
- source.glsl
|
||||
vendor/grammars/sublime-golo/:
|
||||
- source.golo
|
||||
vendor/grammars/sublime-idris:
|
||||
- source.idris
|
||||
vendor/grammars/sublime-mask:
|
||||
- source.mask
|
||||
vendor/grammars/sublime-netlinx:
|
||||
- source.netlinx
|
||||
- source.netlinx.erb
|
||||
vendor/grammars/sublime-nginx:
|
||||
- source.nginx
|
||||
vendor/grammars/sublime-nix:
|
||||
- source.nix
|
||||
vendor/grammars/sublime-opal/:
|
||||
- source.opal
|
||||
- source.opalsysdefs
|
||||
vendor/grammars/sublime-robot-plugin:
|
||||
- text.robot
|
||||
vendor/grammars/sublime-rust:
|
||||
- source.rust
|
||||
vendor/grammars/sublime-sourcepawn:
|
||||
- source.sp
|
||||
vendor/grammars/sublime-spintools/:
|
||||
- source.regexp.spin
|
||||
- source.spin
|
||||
vendor/grammars/sublime-tea:
|
||||
- source.tea
|
||||
vendor/grammars/sublime-text-ox/:
|
||||
- source.ox
|
||||
vendor/grammars/sublime-text-pig-latin/:
|
||||
- source.pig_latin
|
||||
vendor/grammars/sublime-varnish:
|
||||
- source.varnish.vcl
|
||||
vendor/grammars/sublime_cobol:
|
||||
- source.acucobol
|
||||
- source.cobol
|
||||
- source.jcl
|
||||
- source.opencobol
|
||||
vendor/grammars/sublime_man_page_support:
|
||||
- source.man
|
||||
@@ -459,6 +537,8 @@ vendor/grammars/verilog.tmbundle:
|
||||
- source.verilog
|
||||
vendor/grammars/x86-assembly-textmate-bundle:
|
||||
- source.asm.x86
|
||||
vendor/grammars/xc.tmbundle/:
|
||||
- source.xc
|
||||
vendor/grammars/xml.tmbundle:
|
||||
- text.xml
|
||||
- text.xml.xsl
|
||||
|
||||
@@ -6,3 +6,15 @@ require 'linguist/repository'
|
||||
require 'linguist/samples'
|
||||
require 'linguist/shebang'
|
||||
require 'linguist/version'
|
||||
|
||||
class << Linguist
|
||||
attr_accessor :instrumenter
|
||||
|
||||
def instrument(*args, &bk)
|
||||
if instrumenter
|
||||
instrumenter.instrument(*args, &bk)
|
||||
else
|
||||
yield if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,7 +99,7 @@ module Linguist
|
||||
elsif name.nil?
|
||||
"attachment"
|
||||
else
|
||||
"attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}"
|
||||
"attachment; filename=#{EscapeUtils.escape_url(name)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,7 +233,22 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def vendored?
|
||||
name =~ VendoredRegexp ? true : false
|
||||
path =~ VendoredRegexp ? true : false
|
||||
end
|
||||
|
||||
documentation_paths = YAML.load_file(File.expand_path("../documentation.yml", __FILE__))
|
||||
DocumentationRegexp = Regexp.new(documentation_paths.join('|'))
|
||||
|
||||
# Public: Is the blob in a documentation directory?
|
||||
#
|
||||
# Documentation files are ignored by language statistics.
|
||||
#
|
||||
# See "documentation.yml" for a list of documentation conventions that match
|
||||
# this pattern.
|
||||
#
|
||||
# Return true or false
|
||||
def documentation?
|
||||
path =~ DocumentationRegexp ? true : false
|
||||
end
|
||||
|
||||
# Public: Get each line of data
|
||||
@@ -301,7 +316,7 @@ module Linguist
|
||||
#
|
||||
# Return true or false
|
||||
def generated?
|
||||
@_generated ||= Generated.generated?(name, lambda { data })
|
||||
@_generated ||= Generated.generated?(path, lambda { data })
|
||||
end
|
||||
|
||||
# Public: Detects the Language of the blob.
|
||||
@@ -317,5 +332,15 @@ module Linguist
|
||||
def tm_scope
|
||||
language && language.tm_scope
|
||||
end
|
||||
|
||||
DETECTABLE_TYPES = [:programming, :markup].freeze
|
||||
|
||||
# Internal: Should this blob be included in repository language statistics?
|
||||
def include_in_language_stats?
|
||||
!vendored? &&
|
||||
!documentation? &&
|
||||
!generated? &&
|
||||
language && DETECTABLE_TYPES.include?(language.type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
23
lib/linguist/documentation.yml
Normal file
23
lib/linguist/documentation.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
# Documentation files and directories are excluded from language
|
||||
# statistics.
|
||||
#
|
||||
# Lines in this file are Regexps that are matched against the file
|
||||
# pathname.
|
||||
#
|
||||
# Please add additional test coverage to
|
||||
# `test/test_blob.rb#test_documentation` if you make any changes.
|
||||
|
||||
## Documentation directories ##
|
||||
|
||||
- ^docs?/
|
||||
- (^|/)[Dd]ocumentation/
|
||||
- (^|/)javadoc/
|
||||
- ^man/
|
||||
|
||||
## Documentation files ##
|
||||
|
||||
- (^|/)CONTRIBUTING(\.|$)
|
||||
- (^|/)COPYING(\.|$)
|
||||
- (^|/)INSTALL(\.|$)
|
||||
- (^|/)LICEN[CS]E(\.|$)
|
||||
- (^|/)README(\.|$)
|
||||
@@ -3,7 +3,7 @@ require 'linguist/blob_helper'
|
||||
module Linguist
|
||||
# A FileBlob is a wrapper around a File object to make it quack
|
||||
# like a Grit::Blob. It provides the basic interface: `name`,
|
||||
# `data`, and `size`.
|
||||
# `data`, `path` and `size`.
|
||||
class FileBlob
|
||||
include BlobHelper
|
||||
|
||||
@@ -14,43 +14,50 @@ module Linguist
|
||||
#
|
||||
# Returns a FileBlob.
|
||||
def initialize(path, base_path = nil)
|
||||
@path = path
|
||||
@name = base_path ? path.sub("#{base_path}/", '') : path
|
||||
@fullpath = path
|
||||
@path = base_path ? path.sub("#{base_path}/", '') : path
|
||||
end
|
||||
|
||||
# Public: Filename
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb").name
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb").path
|
||||
# # => "/path/to/linguist/lib/linguist.rb"
|
||||
#
|
||||
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
||||
# "/path/to/linguist").name
|
||||
# "/path/to/linguist").path
|
||||
# # => "lib/linguist.rb"
|
||||
#
|
||||
# Returns a String
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
|
||||
# Public: Read file permissions
|
||||
#
|
||||
# Returns a String like '100644'
|
||||
def mode
|
||||
File.stat(@path).mode.to_s(8)
|
||||
File.stat(@fullpath).mode.to_s(8)
|
||||
end
|
||||
|
||||
# Public: File name
|
||||
#
|
||||
# Returns a String
|
||||
def name
|
||||
File.basename(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Read file contents.
|
||||
#
|
||||
# Returns a String.
|
||||
def data
|
||||
File.read(@path)
|
||||
File.read(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get byte size
|
||||
#
|
||||
# Returns an Integer.
|
||||
def size
|
||||
File.size(@path)
|
||||
File.size(@fullpath)
|
||||
end
|
||||
|
||||
# Public: Get file extension.
|
||||
@@ -67,7 +74,7 @@ module Linguist
|
||||
#
|
||||
# Returns an Array
|
||||
def extensions
|
||||
basename, *segments = File.basename(name).split(".")
|
||||
basename, *segments = name.downcase.split(".")
|
||||
|
||||
segments.map.with_index do |segment, index|
|
||||
"." + segments[index..-1].join(".")
|
||||
|
||||
@@ -58,10 +58,13 @@ module Linguist
|
||||
godeps? ||
|
||||
generated_by_zephir? ||
|
||||
minified_files? ||
|
||||
source_map? ||
|
||||
compiled_coffeescript? ||
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_postscript? ||
|
||||
compiled_cython_file? ||
|
||||
generated_protocol_buffer_go? ||
|
||||
generated_protocol_buffer? ||
|
||||
generated_jni_header? ||
|
||||
vcr_cassette?
|
||||
@@ -94,6 +97,20 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Is the blob a generated source map?
|
||||
#
|
||||
# Source Maps usually have .css.map or .js.map extensions. In case they
|
||||
# are not following the name convention, detect them based on the content.
|
||||
#
|
||||
# Returns true or false.
|
||||
def source_map?
|
||||
return false unless extname.downcase == '.map'
|
||||
|
||||
name =~ /(\.css|\.js)\.map$/i || # Name convention
|
||||
lines[0] =~ /^{"version":\d+,/ || # Revision 2 and later begin with the version number
|
||||
lines[0] =~ /^\/\*\* Begin line maps\. \*\*\/{/ # Revision 1 begins with a magic comment
|
||||
end
|
||||
|
||||
# Internal: Is the blob of JS generated by CoffeeScript?
|
||||
#
|
||||
# CoffeeScript is meant to output JS that would be difficult to
|
||||
@@ -202,6 +219,13 @@ module Linguist
|
||||
creator.include?("ImageMagick")
|
||||
end
|
||||
|
||||
def generated_protocol_buffer_go?
|
||||
return false unless extname == '.go'
|
||||
return false unless lines.count > 1
|
||||
|
||||
return lines[0].include?("Code generated by protoc-gen-go")
|
||||
end
|
||||
|
||||
# Internal: Is the blob a C++, Java or Python source file generated by the
|
||||
# Protocol Buffer compiler?
|
||||
#
|
||||
@@ -262,5 +286,18 @@ module Linguist
|
||||
# VCR Cassettes have "recorded_with: VCR" in the second last line.
|
||||
return lines[-2].include?("recorded_with: VCR")
|
||||
end
|
||||
|
||||
# Internal: Is this a compiled C/C++ file from Cython?
|
||||
#
|
||||
# Cython-compiled C/C++ files typically contain:
|
||||
# /* Generated by Cython x.x.x on ... */
|
||||
# on the first line.
|
||||
#
|
||||
# Return true or false
|
||||
def compiled_cython_file?
|
||||
return false unless ['.c', '.cpp'].include? extname
|
||||
return false unless lines.count > 1
|
||||
return lines[0].include?("Generated by Cython")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ module Linguist
|
||||
# disambiguate "Perl", "Prolog" do |data|
|
||||
# if data.include?("use strict")
|
||||
# Language["Perl"]
|
||||
# elsif data.include?(":-")
|
||||
# elsif /^[^#]+:-/.match(data)
|
||||
# Language["Prolog"]
|
||||
# end
|
||||
# end
|
||||
@@ -61,6 +61,9 @@ module Linguist
|
||||
@heuristic.call(data)
|
||||
end
|
||||
|
||||
# Common heuristics
|
||||
ObjectiveCRegex = /^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/
|
||||
|
||||
disambiguate "BitBake", "BlitzBasic" do |data|
|
||||
if /^\s*; /.match(data) || data.include?("End Function")
|
||||
Language["BlitzBasic"]
|
||||
@@ -78,7 +81,7 @@ module Linguist
|
||||
end
|
||||
|
||||
disambiguate "Objective-C", "C++", "C" do |data|
|
||||
if (/^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data))
|
||||
if ObjectiveCRegex.match(data)
|
||||
Language["Objective-C"]
|
||||
elsif (/^\s*#\s*include <(cstdint|string|vector|map|list|array|bitset|queue|stack|forward_list|unordered_map|unordered_set|(i|o|io)stream)>/.match(data) ||
|
||||
/^\s*template\s*</.match(data) || /^[ \t]*try/.match(data) || /^[ \t]*catch\s*\(/.match(data) || /^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+/.match(data) || /^[ \t]*(private|public|protected):$/.match(data) || /std::\w+/.match(data))
|
||||
@@ -89,29 +92,42 @@ module Linguist
|
||||
disambiguate "Perl", "Perl6", "Prolog" do |data|
|
||||
if data.include?("use v6")
|
||||
Language["Perl6"]
|
||||
elsif data.include?("use strict")
|
||||
elsif data.match(/use strict|use\s+v?5\./)
|
||||
Language["Perl"]
|
||||
elsif data.include?(":-")
|
||||
elsif /^[^#]+:-/.match(data)
|
||||
Language["Prolog"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "ECL", "Prolog" do |data|
|
||||
if data.include?(":-")
|
||||
if /^[^#]+:-/.match(data)
|
||||
Language["Prolog"]
|
||||
elsif data.include?(":=")
|
||||
Language["ECL"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "IDL", "Prolog" do |data|
|
||||
if data.include?(":-")
|
||||
disambiguate "IDL", "Prolog", "INI", "QMake" do |data|
|
||||
if /^[^#]+:-/.match(data)
|
||||
Language["Prolog"]
|
||||
else
|
||||
elsif data.include?("last_client=")
|
||||
Language["INI"]
|
||||
elsif data.include?("HEADERS") && data.include?("SOURCES")
|
||||
Language["QMake"]
|
||||
elsif /^\s*function[ \w,]+$/.match(data)
|
||||
Language["IDL"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "GAP", "Scilab" do |data|
|
||||
if (data.include?("gap> "))
|
||||
Language["GAP"]
|
||||
# Heads up - we don't usually write heuristics like this (with no regex match)
|
||||
else
|
||||
Language["Scilab"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "Common Lisp", "OpenCL", "Cool" do |data|
|
||||
if data.include?("(defun ")
|
||||
Language["Common Lisp"]
|
||||
@@ -138,14 +154,20 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "AsciiDoc", "AGS Script" do |data|
|
||||
Language["AsciiDoc"] if /^=+(\s|\n)/.match(data)
|
||||
disambiguate "AsciiDoc", "AGS Script", "Public Key" do |data|
|
||||
if /^[=-]+(\s|\n)|{{[A-Za-z]/.match(data)
|
||||
Language["AsciiDoc"]
|
||||
elsif /^(\/\/.+|((import|export)\s+)?(function|int|float|char)\s+((room|repeatedly|on|game)_)?([A-Za-z]+[A-Za-z_0-9]+)\s*[;\(])/.match(data)
|
||||
Language["AGS Script"]
|
||||
elsif /^-----BEGIN/.match(data)
|
||||
Language["Public Key"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "FORTRAN", "Forth" do |data|
|
||||
disambiguate "FORTRAN", "Forth", "Formatted" do |data|
|
||||
if /^: /.match(data)
|
||||
Language["Forth"]
|
||||
elsif /^([c*][^a-z]| (subroutine|program)\s|!)/i.match(data)
|
||||
elsif /^([c*][^a-z]| (subroutine|program)\s|\s*!)/i.match(data)
|
||||
Language["FORTRAN"]
|
||||
end
|
||||
end
|
||||
@@ -160,6 +182,22 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "M", "MUF", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data|
|
||||
if ObjectiveCRegex.match(data)
|
||||
Language["Objective-C"]
|
||||
elsif data.include?(":- module")
|
||||
Language["Mercury"]
|
||||
elsif /^: /.match(data)
|
||||
Language["MUF"]
|
||||
elsif /^\s*;/.match(data)
|
||||
Language["M"]
|
||||
elsif /^\s*\(\*/.match(data)
|
||||
Language["Mathematica"]
|
||||
elsif /^\s*%/.match(data)
|
||||
Language["Matlab"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "Gosu", "JavaScript" do |data|
|
||||
Language["Gosu"] if /^uses java\./.match(data)
|
||||
end
|
||||
@@ -172,6 +210,14 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "Common Lisp", "NewLisp" do |data|
|
||||
if /^\s*\((defun|in-package|defpackage) /.match(data)
|
||||
Language["Common Lisp"]
|
||||
elsif /^\s*\(define /.match(data)
|
||||
Language["NewLisp"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "TypeScript", "XML" do |data|
|
||||
if data.include?("<TS ")
|
||||
Language["XML"]
|
||||
@@ -189,5 +235,48 @@ module Linguist
|
||||
Language["Text"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data|
|
||||
if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN( WORK| TRANSACTION)?;/i.match(data)
|
||||
#Postgres
|
||||
Language["PLpgSQL"]
|
||||
elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data)
|
||||
#IBM db2
|
||||
Language["SQLPL"]
|
||||
elsif /pragma|\$\$PLSQL_|XMLTYPE|sysdate|systimestamp|\.nextval|connect by|AUTHID (DEFINER|CURRENT_USER)/i.match(data) || /constructor\W+function/i.match(data)
|
||||
#Oracle
|
||||
Language["PLSQL"]
|
||||
elsif ! /begin|boolean|package|exception/i.match(data)
|
||||
#Generic SQL
|
||||
Language["SQL"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "D", "DTrace", "Makefile" do |data|
|
||||
if /^module /.match(data)
|
||||
Language["D"]
|
||||
elsif /^((dtrace:::)?BEGIN|provider |#pragma (D (option|attributes)|ident)\s)/.match(data)
|
||||
Language["DTrace"]
|
||||
elsif /(\/.*:( .* \\)$| : \\$|^ : |: \\$)/.match(data)
|
||||
Language["Makefile"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "OCaml", "Standard ML" do |data|
|
||||
if /module|let rec |match\s+(\S+\s)+with/.match(data)
|
||||
Language["OCaml"]
|
||||
elsif /=> |case\s+(\S+\s)+of/.match(data)
|
||||
Language["Standard ML"]
|
||||
end
|
||||
end
|
||||
|
||||
disambiguate "NL", "NewLisp" do |data|
|
||||
if /^g3 /.match(data)
|
||||
Language["NL"]
|
||||
else
|
||||
Language["NewLisp"]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,6 +11,7 @@ require 'linguist/samples'
|
||||
require 'linguist/file_blob'
|
||||
require 'linguist/blob_helper'
|
||||
require 'linguist/strategy/filename'
|
||||
require 'linguist/strategy/modeline'
|
||||
require 'linguist/shebang'
|
||||
|
||||
module Linguist
|
||||
@@ -31,13 +32,6 @@ module Linguist
|
||||
# Valid Languages types
|
||||
TYPES = [:data, :markup, :programming, :prose]
|
||||
|
||||
# Names of non-programming languages that we will still detect
|
||||
#
|
||||
# Returns an array
|
||||
def self.detectable_markup
|
||||
["CSS", "Less", "Sass", "SCSS", "Stylus", "TeX"]
|
||||
end
|
||||
|
||||
# Detect languages by a specific type
|
||||
#
|
||||
# type - A symbol that exists within TYPES
|
||||
@@ -79,7 +73,7 @@ module Linguist
|
||||
raise ArgumentError, "Extension is missing a '.': #{extension.inspect}"
|
||||
end
|
||||
|
||||
@extension_index[extension] << language
|
||||
@extension_index[extension.downcase] << language
|
||||
end
|
||||
|
||||
language.interpreters.each do |interpreter|
|
||||
@@ -94,8 +88,9 @@ module Linguist
|
||||
end
|
||||
|
||||
STRATEGIES = [
|
||||
Linguist::Strategy::Filename,
|
||||
Linguist::Strategy::Modeline,
|
||||
Linguist::Shebang,
|
||||
Linguist::Strategy::Filename,
|
||||
Linguist::Heuristics,
|
||||
Linguist::Classifier
|
||||
]
|
||||
@@ -110,19 +105,31 @@ module Linguist
|
||||
# Bail early if the blob is binary or empty.
|
||||
return nil if blob.likely_binary? || blob.binary? || blob.empty?
|
||||
|
||||
# Call each strategy until one candidate is returned.
|
||||
STRATEGIES.reduce([]) do |languages, strategy|
|
||||
candidates = strategy.call(blob, languages)
|
||||
if candidates.size == 1
|
||||
return candidates.first
|
||||
elsif candidates.size > 1
|
||||
# More than one candidate was found, pass them to the next strategy.
|
||||
candidates
|
||||
else
|
||||
# No candiates were found, pass on languages from the previous strategy.
|
||||
languages
|
||||
Linguist.instrument("linguist.detection", :blob => blob) do
|
||||
# Call each strategy until one candidate is returned.
|
||||
languages = []
|
||||
returning_strategy = nil
|
||||
|
||||
STRATEGIES.each do |strategy|
|
||||
returning_strategy = strategy
|
||||
candidates = Linguist.instrument("linguist.strategy", :blob => blob, :strategy => strategy, :candidates => languages) do
|
||||
strategy.call(blob, languages)
|
||||
end
|
||||
if candidates.size == 1
|
||||
languages = candidates
|
||||
break
|
||||
elsif candidates.size > 1
|
||||
# More than one candidate was found, pass them to the next strategy.
|
||||
languages = candidates
|
||||
else
|
||||
# No candidates, try the next strategy
|
||||
end
|
||||
end
|
||||
end.first
|
||||
|
||||
Linguist.instrument("linguist.detected", :blob => blob, :strategy => returning_strategy, :language => languages.first)
|
||||
|
||||
languages.first
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Get all Languages
|
||||
@@ -155,7 +162,7 @@ module Linguist
|
||||
# Language.find_by_alias('cpp')
|
||||
# # => #<Language name="C++">
|
||||
#
|
||||
# Returns the Lexer or nil if none was found.
|
||||
# Returns the Language or nil if none was found.
|
||||
def self.find_by_alias(name)
|
||||
name && @alias_index[name.downcase]
|
||||
end
|
||||
@@ -196,7 +203,7 @@ module Linguist
|
||||
# Returns all matching Languages or [] if none were found.
|
||||
def self.find_by_extension(extname)
|
||||
extname = ".#{extname}" unless extname.start_with?(".")
|
||||
@extension_index[extname]
|
||||
@extension_index[extname.downcase]
|
||||
end
|
||||
|
||||
# DEPRECATED
|
||||
@@ -219,7 +226,7 @@ module Linguist
|
||||
end
|
||||
|
||||
|
||||
# Public: Look up Language by its name or lexer.
|
||||
# Public: Look up Language by its name.
|
||||
#
|
||||
# name - The String name of the Language
|
||||
#
|
||||
@@ -243,7 +250,7 @@ module Linguist
|
||||
#
|
||||
# This list is configured in "popular.yml".
|
||||
#
|
||||
# Returns an Array of Lexers.
|
||||
# Returns an Array of Languages.
|
||||
def self.popular
|
||||
@popular ||= all.select(&:popular?).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
@@ -255,7 +262,7 @@ module Linguist
|
||||
#
|
||||
# This list is created from all the languages not listed in "popular.yml".
|
||||
#
|
||||
# Returns an Array of Lexers.
|
||||
# Returns an Array of Languages.
|
||||
def self.unpopular
|
||||
@unpopular ||= all.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
|
||||
end
|
||||
@@ -375,11 +382,6 @@ module Linguist
|
||||
# Returns the name String
|
||||
attr_reader :search_term
|
||||
|
||||
# Public: Get Lexer
|
||||
#
|
||||
# Returns the Lexer
|
||||
attr_reader :lexer
|
||||
|
||||
# Public: Get the name of a TextMate-compatible scope
|
||||
#
|
||||
# Returns the scope
|
||||
@@ -495,16 +497,6 @@ module Linguist
|
||||
@searchable
|
||||
end
|
||||
|
||||
# Public: Highlight syntax of text
|
||||
#
|
||||
# text - String of code to be highlighted
|
||||
# options - A Hash of options (defaults to {})
|
||||
#
|
||||
# Returns html String
|
||||
def colorize(text, options = {})
|
||||
lexer.highlight(text, options)
|
||||
end
|
||||
|
||||
# Public: Return name as String representation
|
||||
def to_s
|
||||
name
|
||||
@@ -548,8 +540,8 @@ module Linguist
|
||||
|
||||
if extnames = extensions[name]
|
||||
extnames.each do |extname|
|
||||
if !options['extensions'].index { |x| x.end_with? extname }
|
||||
warn "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" unless extname == '.script!'
|
||||
if !options['extensions'].index { |x| x.downcase.end_with? extname.downcase }
|
||||
warn "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" unless extname == '.script!'
|
||||
options['extensions'] << extname
|
||||
end
|
||||
end
|
||||
@@ -580,7 +572,6 @@ module Linguist
|
||||
:color => options['color'],
|
||||
:type => options['type'],
|
||||
:aliases => options['aliases'],
|
||||
:lexer => options['lexer'],
|
||||
:tm_scope => options['tm_scope'],
|
||||
:ace_mode => options['ace_mode'],
|
||||
:wrap => options['wrap'],
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
# language. This should match one of the scopes listed in
|
||||
# the grammars.yml file. Use "none" if there is no grammar
|
||||
# for this language.
|
||||
# group - Name of the parent language. Languages in a group are counted
|
||||
# in the statistics as the parent language.
|
||||
#
|
||||
# Any additions or modifications (even trivial) should have corresponding
|
||||
# test change in `test/test_blob.rb`.
|
||||
@@ -41,6 +43,14 @@ AGS Script:
|
||||
tm_scope: source.c++
|
||||
ace_mode: c_cpp
|
||||
|
||||
AMPL:
|
||||
type: programming
|
||||
color: "#00008B"
|
||||
extensions:
|
||||
- .ampl
|
||||
tm_scope: source.ampl
|
||||
ace_mode: text
|
||||
|
||||
ANTLR:
|
||||
type: programming
|
||||
color: "#9DC3FF"
|
||||
@@ -54,13 +64,14 @@ APL:
|
||||
extensions:
|
||||
- .apl
|
||||
- .dyalog
|
||||
tm_scope: none
|
||||
tm_scope: source.apl
|
||||
ace_mode: text
|
||||
|
||||
ASP:
|
||||
type: programming
|
||||
color: "#6a40fd"
|
||||
search_term: aspx-vb
|
||||
tm_scope: text.html.asp
|
||||
aliases:
|
||||
- aspx
|
||||
- aspx-vb
|
||||
@@ -81,10 +92,9 @@ ATS:
|
||||
- ats2
|
||||
extensions:
|
||||
- .dats
|
||||
- .atxt
|
||||
- .hats
|
||||
- .sats
|
||||
tm_scope: source.ocaml
|
||||
tm_scope: source.ats
|
||||
ace_mode: ocaml
|
||||
|
||||
ActionScript:
|
||||
@@ -140,7 +150,6 @@ ApacheConf:
|
||||
- apache
|
||||
extensions:
|
||||
- .apacheconf
|
||||
- .conf
|
||||
tm_scope: source.apache-config
|
||||
ace_mode: apache_conf
|
||||
|
||||
@@ -186,7 +195,7 @@ AsciiDoc:
|
||||
- .asciidoc
|
||||
- .adoc
|
||||
- .asc
|
||||
tm_scope: none
|
||||
tm_scope: text.html.asciidoc
|
||||
|
||||
AspectJ:
|
||||
type: programming
|
||||
@@ -198,14 +207,14 @@ AspectJ:
|
||||
|
||||
Assembly:
|
||||
type: programming
|
||||
color: "#a67219"
|
||||
color: "#6E4C13"
|
||||
search_term: nasm
|
||||
aliases:
|
||||
- nasm
|
||||
extensions:
|
||||
- .asm
|
||||
- .ASM
|
||||
- .a51
|
||||
- .nasm
|
||||
tm_scope: source.asm.x86
|
||||
ace_mode: assembly_x86
|
||||
|
||||
@@ -270,6 +279,7 @@ Batchfile:
|
||||
ace_mode: batchfile
|
||||
|
||||
Befunge:
|
||||
type: programming
|
||||
extensions:
|
||||
- .befunge
|
||||
ace_mode: text
|
||||
@@ -325,6 +335,7 @@ Boo:
|
||||
ace_mode: text
|
||||
|
||||
Brainfuck:
|
||||
type: programming
|
||||
extensions:
|
||||
- .b
|
||||
- .bf
|
||||
@@ -335,7 +346,7 @@ Brightscript:
|
||||
type: programming
|
||||
extensions:
|
||||
- .brs
|
||||
tm_scope: none
|
||||
tm_scope: source.brightscript
|
||||
ace_mode: text
|
||||
|
||||
Bro:
|
||||
@@ -346,15 +357,15 @@ Bro:
|
||||
|
||||
C:
|
||||
type: programming
|
||||
color: "#555"
|
||||
color: "#555555"
|
||||
extensions:
|
||||
- .c
|
||||
- .C
|
||||
- .H
|
||||
- .cats
|
||||
- .h
|
||||
- .idc
|
||||
- .w
|
||||
interpreters:
|
||||
- tcc
|
||||
ace_mode: c_cpp
|
||||
|
||||
C#:
|
||||
@@ -381,6 +392,7 @@ C++:
|
||||
- .cpp
|
||||
- .c++
|
||||
- .cc
|
||||
- .cp
|
||||
- .cxx
|
||||
- .h
|
||||
- .h++
|
||||
@@ -413,10 +425,11 @@ CLIPS:
|
||||
type: programming
|
||||
extensions:
|
||||
- .clp
|
||||
tm_scope: none
|
||||
tm_scope: source.clips
|
||||
ace_mode: text
|
||||
|
||||
CMake:
|
||||
type: programming
|
||||
extensions:
|
||||
- .cmake
|
||||
- .cmake.in
|
||||
@@ -428,8 +441,6 @@ COBOL:
|
||||
type: programming
|
||||
extensions:
|
||||
- .cob
|
||||
- .COB
|
||||
- .CPY
|
||||
- .cbl
|
||||
- .ccp
|
||||
- .cobol
|
||||
@@ -437,6 +448,8 @@ COBOL:
|
||||
ace_mode: cobol
|
||||
|
||||
CSS:
|
||||
type: markup
|
||||
tm_scope: source.css
|
||||
ace_mode: css
|
||||
color: "#563d7c"
|
||||
extensions:
|
||||
@@ -474,6 +487,7 @@ Chapel:
|
||||
ace_mode: text
|
||||
|
||||
ChucK:
|
||||
type: programming
|
||||
extensions:
|
||||
- .ck
|
||||
tm_scope: source.java
|
||||
@@ -501,6 +515,7 @@ Clojure:
|
||||
color: "#db5855"
|
||||
extensions:
|
||||
- .clj
|
||||
- .boot
|
||||
- .cl2
|
||||
- .cljc
|
||||
- .cljs
|
||||
@@ -622,7 +637,7 @@ Creole:
|
||||
wrap: true
|
||||
extensions:
|
||||
- .creole
|
||||
tm_scope: none
|
||||
tm_scope: text.html.creole
|
||||
ace_mode: text
|
||||
|
||||
Crystal:
|
||||
@@ -635,6 +650,7 @@ Crystal:
|
||||
- crystal
|
||||
|
||||
Cucumber:
|
||||
type: programming
|
||||
extensions:
|
||||
- .feature
|
||||
tm_scope: text.gherkin.feature
|
||||
@@ -693,7 +709,19 @@ DM:
|
||||
tm_scope: source.c++
|
||||
ace_mode: c_cpp
|
||||
|
||||
DTrace:
|
||||
type: programming
|
||||
aliases:
|
||||
- dtrace-script
|
||||
extensions:
|
||||
- .d
|
||||
interpreters:
|
||||
- dtrace
|
||||
tm_scope: source.c
|
||||
ace_mode: c_cpp
|
||||
|
||||
Darcs Patch:
|
||||
type: data
|
||||
search_term: dpatch
|
||||
aliases:
|
||||
- dpatch
|
||||
@@ -711,11 +739,14 @@ Dart:
|
||||
ace_mode: dart
|
||||
|
||||
Diff:
|
||||
type: data
|
||||
color: "#88dddd"
|
||||
extensions:
|
||||
- .diff
|
||||
- .patch
|
||||
aliases:
|
||||
- udiff
|
||||
tm_scope: source.diff
|
||||
ace_mode: diff
|
||||
|
||||
Dockerfile:
|
||||
@@ -811,9 +842,11 @@ Emacs Lisp:
|
||||
- emacs
|
||||
filenames:
|
||||
- .emacs
|
||||
- .emacs.desktop
|
||||
extensions:
|
||||
- .el
|
||||
- .emacs
|
||||
- .emacs.desktop
|
||||
ace_mode: lisp
|
||||
|
||||
EmberScript:
|
||||
@@ -864,14 +897,6 @@ FORTRAN:
|
||||
color: "#4d41b1"
|
||||
extensions:
|
||||
- .f90
|
||||
- .F
|
||||
- .F03
|
||||
- .F08
|
||||
- .F77
|
||||
- .F90
|
||||
- .F95
|
||||
- .FOR
|
||||
- .FPP
|
||||
- .f
|
||||
- .f03
|
||||
- .f08
|
||||
@@ -910,13 +935,19 @@ Fantom:
|
||||
tm_scope: source.fan
|
||||
ace_mode: text
|
||||
|
||||
Formatted:
|
||||
type: data
|
||||
extensions:
|
||||
- .for
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
Forth:
|
||||
type: programming
|
||||
color: "#341708"
|
||||
extensions:
|
||||
- .fth
|
||||
- .4th
|
||||
- .F
|
||||
- .f
|
||||
- .for
|
||||
- .forth
|
||||
@@ -939,7 +970,7 @@ G-code:
|
||||
- .g
|
||||
- .gco
|
||||
- .gcode
|
||||
tm_scope: none
|
||||
tm_scope: source.gcode
|
||||
ace_mode: gcode
|
||||
|
||||
GAMS:
|
||||
@@ -956,7 +987,8 @@ GAP:
|
||||
- .gap
|
||||
- .gd
|
||||
- .gi
|
||||
tm_scope: none
|
||||
- .tst
|
||||
tm_scope: source.gap
|
||||
ace_mode: text
|
||||
|
||||
GAS:
|
||||
@@ -964,7 +996,6 @@ GAS:
|
||||
group: Assembly
|
||||
extensions:
|
||||
- .s
|
||||
- .S
|
||||
tm_scope: source.asm.x86
|
||||
ace_mode: assembly_x86
|
||||
|
||||
@@ -972,11 +1003,10 @@ GDScript:
|
||||
type: programming
|
||||
extensions:
|
||||
- .gd
|
||||
tm_scope: none
|
||||
tm_scope: source.gdscript
|
||||
ace_mode: text
|
||||
|
||||
GLSL:
|
||||
group: C
|
||||
type: programming
|
||||
extensions:
|
||||
- .glsl
|
||||
@@ -1004,6 +1034,7 @@ Game Maker Language:
|
||||
ace_mode: c_cpp
|
||||
|
||||
Genshi:
|
||||
type: programming
|
||||
extensions:
|
||||
- .kid
|
||||
tm_scope: text.xml.genshi
|
||||
@@ -1013,6 +1044,7 @@ Genshi:
|
||||
ace_mode: xml
|
||||
|
||||
Gentoo Ebuild:
|
||||
type: programming
|
||||
group: Shell
|
||||
extensions:
|
||||
- .ebuild
|
||||
@@ -1020,6 +1052,7 @@ Gentoo Ebuild:
|
||||
ace_mode: sh
|
||||
|
||||
Gentoo Eclass:
|
||||
type: programming
|
||||
group: Shell
|
||||
extensions:
|
||||
- .eclass
|
||||
@@ -1027,6 +1060,7 @@ Gentoo Eclass:
|
||||
ace_mode: sh
|
||||
|
||||
Gettext Catalog:
|
||||
type: prose
|
||||
search_term: pot
|
||||
searchable: false
|
||||
aliases:
|
||||
@@ -1070,7 +1104,7 @@ Golo:
|
||||
color: "#f6a51f"
|
||||
extensions:
|
||||
- .golo
|
||||
tm_scope: none
|
||||
tm_scope: source.golo
|
||||
ace_mode: text
|
||||
|
||||
Gosu:
|
||||
@@ -1088,7 +1122,7 @@ Grace:
|
||||
type: programming
|
||||
extensions:
|
||||
- .grace
|
||||
tm_scope: none
|
||||
tm_scope: source.grace
|
||||
ace_mode: text
|
||||
|
||||
Gradle:
|
||||
@@ -1122,11 +1156,11 @@ Graphviz (DOT):
|
||||
tm_scope: source.dot
|
||||
extensions:
|
||||
- .dot
|
||||
- .DOT
|
||||
- .gv
|
||||
ace_mode: text
|
||||
|
||||
Groff:
|
||||
type: markup
|
||||
extensions:
|
||||
- .man
|
||||
- '.1'
|
||||
@@ -1154,6 +1188,7 @@ Groovy:
|
||||
- groovy
|
||||
|
||||
Groovy Server Pages:
|
||||
type: programming
|
||||
group: Groovy
|
||||
aliases:
|
||||
- gsp
|
||||
@@ -1167,6 +1202,7 @@ HTML:
|
||||
type: markup
|
||||
tm_scope: text.html.basic
|
||||
ace_mode: html
|
||||
color: "#e44b23"
|
||||
aliases:
|
||||
- xhtml
|
||||
extensions:
|
||||
@@ -1234,8 +1270,10 @@ Haml:
|
||||
|
||||
Handlebars:
|
||||
type: markup
|
||||
color: "#01a9d6"
|
||||
aliases:
|
||||
- hbs
|
||||
- htmlbars
|
||||
extensions:
|
||||
- .handlebars
|
||||
- .hbs
|
||||
@@ -1301,6 +1339,7 @@ INI:
|
||||
- .ini
|
||||
- .cfg
|
||||
- .prefs
|
||||
- .pro
|
||||
- .properties
|
||||
tm_scope: source.ini
|
||||
aliases:
|
||||
@@ -1308,6 +1347,7 @@ INI:
|
||||
ace_mode: ini
|
||||
|
||||
IRC log:
|
||||
type: data
|
||||
search_term: irc
|
||||
aliases:
|
||||
- irc
|
||||
@@ -1338,9 +1378,10 @@ Inform 7:
|
||||
ace_mode: text
|
||||
|
||||
Inno Setup:
|
||||
type: programming
|
||||
extensions:
|
||||
- .iss
|
||||
tm_scope: none
|
||||
tm_scope: source.inno
|
||||
ace_mode: text
|
||||
|
||||
Io:
|
||||
@@ -1369,9 +1410,10 @@ Isabelle:
|
||||
|
||||
J:
|
||||
type: programming
|
||||
color: "#2d8abd"
|
||||
extensions:
|
||||
- .ijs
|
||||
tm_scope: none
|
||||
tm_scope: source.j
|
||||
ace_mode: text
|
||||
|
||||
JSON:
|
||||
@@ -1432,6 +1474,7 @@ Java:
|
||||
- .java
|
||||
|
||||
Java Server Pages:
|
||||
type: programming
|
||||
group: Java
|
||||
search_term: jsp
|
||||
aliases:
|
||||
@@ -1527,6 +1570,7 @@ LFE:
|
||||
ace_mode: lisp
|
||||
|
||||
LLVM:
|
||||
type: programming
|
||||
extensions:
|
||||
- .ll
|
||||
ace_mode: text
|
||||
@@ -1578,6 +1622,13 @@ Latte:
|
||||
tm_scope: source.smarty
|
||||
ace_mode: smarty
|
||||
|
||||
Lean:
|
||||
type: programming
|
||||
extensions:
|
||||
- .lean
|
||||
- .hlean
|
||||
ace_mode: lean
|
||||
|
||||
Less:
|
||||
type: markup
|
||||
group: CSS
|
||||
@@ -1587,6 +1638,7 @@ Less:
|
||||
ace_mode: less
|
||||
|
||||
LilyPond:
|
||||
type: programming
|
||||
extensions:
|
||||
- .ly
|
||||
- .ily
|
||||
@@ -1596,7 +1648,7 @@ Liquid:
|
||||
type: markup
|
||||
extensions:
|
||||
- .liquid
|
||||
tm_scope: none
|
||||
tm_scope: text.html.liquid
|
||||
ace_mode: liquid
|
||||
|
||||
Literate Agda:
|
||||
@@ -1707,6 +1759,15 @@ MTML:
|
||||
tm_scope: text.html.basic
|
||||
ace_mode: html
|
||||
|
||||
MUF:
|
||||
type: programming
|
||||
group: Forth
|
||||
extensions:
|
||||
- .muf
|
||||
- .m
|
||||
tm_scope: none
|
||||
ace_mode: forth
|
||||
|
||||
Makefile:
|
||||
type: programming
|
||||
aliases:
|
||||
@@ -1715,6 +1776,7 @@ Makefile:
|
||||
- mf
|
||||
extensions:
|
||||
- .mak
|
||||
- .d
|
||||
- .mk
|
||||
filenames:
|
||||
- GNUmakefile
|
||||
@@ -1725,6 +1787,7 @@ Makefile:
|
||||
ace_mode: makefile
|
||||
|
||||
Mako:
|
||||
type: programming
|
||||
extensions:
|
||||
- .mako
|
||||
- .mao
|
||||
@@ -1761,6 +1824,8 @@ Mathematica:
|
||||
- .ma
|
||||
- .nb
|
||||
- .nbp
|
||||
- .wl
|
||||
- .wlt
|
||||
aliases:
|
||||
- mma
|
||||
ace_mode: text
|
||||
@@ -1801,7 +1866,7 @@ MediaWiki:
|
||||
wrap: true
|
||||
extensions:
|
||||
- .mediawiki
|
||||
tm_scope: none
|
||||
tm_scope: text.html.mediawiki
|
||||
ace_mode: text
|
||||
|
||||
Mercury:
|
||||
@@ -1817,6 +1882,7 @@ Mercury:
|
||||
ace_mode: prolog
|
||||
|
||||
MiniD: # Legacy
|
||||
type: programming
|
||||
searchable: false
|
||||
extensions:
|
||||
- .minid # Dummy extension
|
||||
@@ -1835,6 +1901,13 @@ Mirah:
|
||||
tm_scope: source.ruby
|
||||
ace_mode: ruby
|
||||
|
||||
Modelica:
|
||||
type: programming
|
||||
extensions:
|
||||
- .mo
|
||||
tm_scope: source.modelica
|
||||
ace_mode: text
|
||||
|
||||
Monkey:
|
||||
type: programming
|
||||
extensions:
|
||||
@@ -1857,12 +1930,21 @@ MoonScript:
|
||||
ace_mode: text
|
||||
|
||||
Myghty:
|
||||
type: programming
|
||||
extensions:
|
||||
- .myt
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
NL:
|
||||
type: data
|
||||
extensions:
|
||||
- .nl
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
NSIS:
|
||||
type: programming
|
||||
extensions:
|
||||
- .nsi
|
||||
- .nsh
|
||||
@@ -1875,6 +1957,24 @@ Nemerle:
|
||||
- .n
|
||||
ace_mode: text
|
||||
|
||||
NetLinx:
|
||||
type: programming
|
||||
color: "#0000ff"
|
||||
extensions:
|
||||
- .axs
|
||||
- .axi
|
||||
tm_scope: source.netlinx
|
||||
ace_mode: text
|
||||
|
||||
NetLinx+ERB:
|
||||
type: programming
|
||||
color: "#407fff"
|
||||
extensions:
|
||||
- .axs.erb
|
||||
- .axi.erb
|
||||
tm_scope: source.netlinx.erb
|
||||
ace_mode: text
|
||||
|
||||
NetLogo:
|
||||
type: programming
|
||||
color: "#ff2b2b"
|
||||
@@ -1883,6 +1983,19 @@ NetLogo:
|
||||
tm_scope: source.lisp
|
||||
ace_mode: lisp
|
||||
|
||||
NewLisp:
|
||||
type: programming
|
||||
lexer: NewLisp
|
||||
color: "#eedd66"
|
||||
extensions:
|
||||
- .nl
|
||||
- .lisp
|
||||
- .lsp
|
||||
interpreters:
|
||||
- newlisp
|
||||
tm_scope: source.lisp
|
||||
ace_mode: lisp
|
||||
|
||||
Nginx:
|
||||
type: markup
|
||||
extensions:
|
||||
@@ -1941,6 +2054,7 @@ Nu:
|
||||
- nush
|
||||
|
||||
NumPy:
|
||||
type: programming
|
||||
group: Python
|
||||
extensions:
|
||||
- .numpy
|
||||
@@ -2026,7 +2140,7 @@ Opal:
|
||||
color: "#f7ede0"
|
||||
extensions:
|
||||
- .opal
|
||||
tm_scope: none
|
||||
tm_scope: source.opal
|
||||
ace_mode: text
|
||||
|
||||
OpenCL:
|
||||
@@ -2054,8 +2168,8 @@ OpenSCAD:
|
||||
type: programming
|
||||
extensions:
|
||||
- .scad
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
tm_scope: source.scad
|
||||
ace_mode: scad
|
||||
|
||||
Org:
|
||||
type: prose
|
||||
@@ -2071,7 +2185,7 @@ Ox:
|
||||
- .ox
|
||||
- .oxh
|
||||
- .oxo
|
||||
tm_scope: none
|
||||
tm_scope: source.ox
|
||||
ace_mode: text
|
||||
|
||||
Oxygene:
|
||||
@@ -2119,6 +2233,27 @@ PHP:
|
||||
aliases:
|
||||
- inc
|
||||
|
||||
#Oracle
|
||||
PLSQL:
|
||||
type: programming
|
||||
ace_mode: sql
|
||||
tm_scope: source.plsql.oracle
|
||||
extensions:
|
||||
- .pls
|
||||
- .pkb
|
||||
- .pks
|
||||
- .plb
|
||||
- .plsql
|
||||
- .sql
|
||||
|
||||
#Postgres
|
||||
PLpgSQL:
|
||||
type: programming
|
||||
ace_mode: pgsql
|
||||
tm_scope: source.sql
|
||||
extensions:
|
||||
- .sql
|
||||
|
||||
Pan:
|
||||
type: programming
|
||||
color: '#cc0000'
|
||||
@@ -2132,7 +2267,7 @@ Papyrus:
|
||||
color: "#6600cc"
|
||||
extensions:
|
||||
- .psc
|
||||
tm_scope: none
|
||||
tm_scope: source.papyrus
|
||||
ace_mode: text
|
||||
|
||||
Parrot:
|
||||
@@ -2180,11 +2315,11 @@ Pascal:
|
||||
|
||||
Perl:
|
||||
type: programming
|
||||
tm_scope: source.perl
|
||||
ace_mode: perl
|
||||
color: "#0298c3"
|
||||
extensions:
|
||||
- .pl
|
||||
- .PL
|
||||
- .cgi
|
||||
- .fcgi
|
||||
- .perl
|
||||
@@ -2216,7 +2351,7 @@ Perl6:
|
||||
- Rexfile
|
||||
interpreters:
|
||||
- perl6
|
||||
tm_scope: none
|
||||
tm_scope: source.perl.6
|
||||
ace_mode: perl
|
||||
|
||||
PigLatin:
|
||||
@@ -2224,7 +2359,7 @@ PigLatin:
|
||||
color: "#fcd7de"
|
||||
extensions:
|
||||
- .pig
|
||||
tm_scope: none
|
||||
tm_scope: source.pig_latin
|
||||
ace_mode: text
|
||||
|
||||
Pike:
|
||||
@@ -2250,7 +2385,7 @@ PogoScript:
|
||||
color: "#d80074"
|
||||
extensions:
|
||||
- .pogo
|
||||
tm_scope: none
|
||||
tm_scope: source.pogoscript
|
||||
ace_mode: text
|
||||
|
||||
PostScript:
|
||||
@@ -2297,7 +2432,7 @@ Propeller Spin:
|
||||
color: "#2b446d"
|
||||
extensions:
|
||||
- .spin
|
||||
tm_scope: none
|
||||
tm_scope: source.spin
|
||||
ace_mode: text
|
||||
|
||||
Protocol Buffer:
|
||||
@@ -2379,6 +2514,8 @@ Python:
|
||||
- python
|
||||
- python2
|
||||
- python3
|
||||
aliases:
|
||||
- rusthon
|
||||
|
||||
Python traceback:
|
||||
type: data
|
||||
@@ -2390,7 +2527,7 @@ Python traceback:
|
||||
ace_mode: text
|
||||
|
||||
QML:
|
||||
type: markup
|
||||
type: programming
|
||||
color: "#44a51c"
|
||||
extensions:
|
||||
- .qml
|
||||
@@ -2398,6 +2535,7 @@ QML:
|
||||
ace_mode: text
|
||||
|
||||
QMake:
|
||||
type: programming
|
||||
extensions:
|
||||
- .pro
|
||||
- .pri
|
||||
@@ -2414,8 +2552,6 @@ R:
|
||||
- splus
|
||||
extensions:
|
||||
- .r
|
||||
- .R
|
||||
- .Rd
|
||||
- .rd
|
||||
- .rsx
|
||||
filenames:
|
||||
@@ -2426,7 +2562,6 @@ R:
|
||||
|
||||
RAML:
|
||||
type: data
|
||||
lexer: YAML
|
||||
ace_mode: yaml
|
||||
tm_scope: source.yaml
|
||||
color: "#77d9fb"
|
||||
@@ -2469,7 +2604,6 @@ RMarkdown:
|
||||
ace_mode: markdown
|
||||
extensions:
|
||||
- .rmd
|
||||
- .Rmd
|
||||
tm_scope: none
|
||||
|
||||
Racket:
|
||||
@@ -2480,6 +2614,8 @@ Racket:
|
||||
- .rktd
|
||||
- .rktl
|
||||
- .scrbl
|
||||
interpreters:
|
||||
- racket
|
||||
tm_scope: source.racket
|
||||
ace_mode: lisp
|
||||
|
||||
@@ -2495,6 +2631,7 @@ Ragel in Ruby Host:
|
||||
ace_mode: text
|
||||
|
||||
Raw token data:
|
||||
type: data
|
||||
search_term: raw
|
||||
aliases:
|
||||
- raw
|
||||
@@ -2513,6 +2650,7 @@ Rebol:
|
||||
- .r3
|
||||
- .rebol
|
||||
ace_mode: text
|
||||
tm_scope: source.rebol
|
||||
|
||||
Red:
|
||||
type: programming
|
||||
@@ -2522,10 +2660,11 @@ Red:
|
||||
- .reds
|
||||
aliases:
|
||||
- red/system
|
||||
tm_scope: none
|
||||
tm_scope: source.red
|
||||
ace_mode: text
|
||||
|
||||
Redcode:
|
||||
type: programming
|
||||
extensions:
|
||||
- .cw
|
||||
tm_scope: none
|
||||
@@ -2564,6 +2703,7 @@ Ruby:
|
||||
- .gemspec
|
||||
- .god
|
||||
- .irbrc
|
||||
- .jbuilder
|
||||
- .mspec
|
||||
- .pluginspec
|
||||
- .podspec
|
||||
@@ -2648,6 +2788,15 @@ SQL:
|
||||
- .udf
|
||||
- .viw
|
||||
|
||||
#IBM DB2
|
||||
SQLPL:
|
||||
type: programming
|
||||
ace_mode: sql
|
||||
tm_scope: source.sql
|
||||
extensions:
|
||||
- .sql
|
||||
- .db2
|
||||
|
||||
STON:
|
||||
type: data
|
||||
group: Smalltalk
|
||||
@@ -2656,6 +2805,13 @@ STON:
|
||||
tm_scope: source.smalltalk
|
||||
ace_mode: text
|
||||
|
||||
SVG:
|
||||
type: data
|
||||
extensions:
|
||||
- .svg
|
||||
tm_scope: text.xml
|
||||
ace_mode: xml
|
||||
|
||||
Sage:
|
||||
type: programming
|
||||
group: Python
|
||||
@@ -2714,7 +2870,6 @@ Scheme:
|
||||
- .ss
|
||||
interpreters:
|
||||
- guile
|
||||
- racket
|
||||
- bigloo
|
||||
- chicken
|
||||
ace_mode: scheme
|
||||
@@ -2805,6 +2960,7 @@ Smalltalk:
|
||||
ace_mode: text
|
||||
|
||||
Smarty:
|
||||
type: programming
|
||||
extensions:
|
||||
- .tpl
|
||||
ace_mode: smarty
|
||||
@@ -2816,6 +2972,7 @@ SourcePawn:
|
||||
- sourcemod
|
||||
extensions:
|
||||
- .sp
|
||||
- .sma
|
||||
tm_scope: source.sp
|
||||
ace_mode: text
|
||||
|
||||
@@ -2856,7 +3013,7 @@ Stylus:
|
||||
group: CSS
|
||||
extensions:
|
||||
- .styl
|
||||
tm_scope: none
|
||||
tm_scope: source.stylus
|
||||
ace_mode: stylus
|
||||
|
||||
SuperCollider:
|
||||
@@ -2895,7 +3052,7 @@ TXL:
|
||||
type: programming
|
||||
extensions:
|
||||
- .txl
|
||||
tm_scope: none
|
||||
tm_scope: source.txl
|
||||
ace_mode: text
|
||||
|
||||
Tcl:
|
||||
@@ -3027,11 +3184,11 @@ UnrealScript:
|
||||
|
||||
VCL:
|
||||
type: programming
|
||||
ace_mode: perl
|
||||
color: "#0298c3"
|
||||
extensions:
|
||||
- .vcl
|
||||
tm_scope: source.perl
|
||||
tm_scope: source.varnish.vcl
|
||||
ace_mode: text
|
||||
|
||||
VHDL:
|
||||
type: programming
|
||||
@@ -3069,12 +3226,15 @@ VimL:
|
||||
search_term: vim
|
||||
aliases:
|
||||
- vim
|
||||
- nvim
|
||||
extensions:
|
||||
- .vim
|
||||
filenames:
|
||||
- .nvimrc
|
||||
- .vimrc
|
||||
- _vimrc
|
||||
- gvimrc
|
||||
- nvimrc
|
||||
- vimrc
|
||||
ace_mode: text
|
||||
|
||||
@@ -3121,13 +3281,14 @@ WebIDL:
|
||||
|
||||
XC:
|
||||
type: programming
|
||||
color: "#99DA07"
|
||||
extensions:
|
||||
- .xc
|
||||
tm_scope: source.c
|
||||
tm_scope: source.xc
|
||||
ace_mode: c_cpp
|
||||
|
||||
XML:
|
||||
type: markup
|
||||
type: data
|
||||
ace_mode: xml
|
||||
aliases:
|
||||
- rss
|
||||
@@ -3169,16 +3330,16 @@ XML:
|
||||
- .rss
|
||||
- .scxml
|
||||
- .srdf
|
||||
- .storyboard
|
||||
- .stTheme
|
||||
- .sublime-snippet
|
||||
- .svg
|
||||
- .targets
|
||||
- .tmCommand
|
||||
- .tml
|
||||
- .tmLanguage
|
||||
- .tmPreferences
|
||||
- .tmSnippet
|
||||
- .tmTheme
|
||||
- .tml
|
||||
- .ts
|
||||
- .ui
|
||||
- .urdf
|
||||
@@ -3193,6 +3354,7 @@ XML:
|
||||
- .x3d
|
||||
- .xacro
|
||||
- .xaml
|
||||
- .xib
|
||||
- .xlf
|
||||
- .xliff
|
||||
- .xmi
|
||||
@@ -3229,6 +3391,7 @@ XQuery:
|
||||
ace_mode: xquery
|
||||
|
||||
XS:
|
||||
type: programming
|
||||
extensions:
|
||||
- .xs
|
||||
tm_scope: source.c
|
||||
@@ -3291,13 +3454,22 @@ Zimpl:
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
desktop:
|
||||
type: data
|
||||
extensions:
|
||||
- .desktop
|
||||
- .desktop.in
|
||||
tm_scope: source.desktop
|
||||
ace_mode: text
|
||||
|
||||
eC:
|
||||
type: programming
|
||||
color: "#4A4773"
|
||||
search_term: ec
|
||||
extensions:
|
||||
- .ec
|
||||
- .eh
|
||||
tm_scope: none
|
||||
tm_scope: source.c.ec
|
||||
ace_mode: text
|
||||
|
||||
edn:
|
||||
@@ -3317,6 +3489,7 @@ fish:
|
||||
ace_mode: text
|
||||
|
||||
mupad:
|
||||
type: programming
|
||||
extensions:
|
||||
- .mu
|
||||
ace_mode: text
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'rugged'
|
||||
|
||||
module Linguist
|
||||
class LazyBlob
|
||||
GIT_ATTR = ['linguist-language', 'linguist-vendored']
|
||||
GIT_ATTR = ['linguist-documentation', 'linguist-language', 'linguist-vendored']
|
||||
GIT_ATTR_OPTS = { :priority => [:index], :skip_system => true }
|
||||
GIT_ATTR_FLAGS = Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS)
|
||||
|
||||
@@ -14,13 +14,15 @@ module Linguist
|
||||
|
||||
attr_reader :repository
|
||||
attr_reader :oid
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
attr_reader :mode
|
||||
|
||||
def initialize(repo, oid, name, mode = nil)
|
||||
alias :name :path
|
||||
|
||||
def initialize(repo, oid, path, mode = nil)
|
||||
@repository = repo
|
||||
@oid = oid
|
||||
@name = name
|
||||
@path = path
|
||||
@mode = mode
|
||||
end
|
||||
|
||||
@@ -37,11 +39,19 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
def documentation?
|
||||
if attr = git_attributes['linguist-documentation']
|
||||
boolean_attribute(attr)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def language
|
||||
return @language if defined?(@language)
|
||||
|
||||
@language = if lang = git_attributes['linguist-language']
|
||||
Language.find_by_name(lang)
|
||||
Language.find_by_alias(lang)
|
||||
else
|
||||
super
|
||||
end
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
- CSS
|
||||
- Clojure
|
||||
- CoffeeScript
|
||||
- Common Lisp
|
||||
- Diff
|
||||
- Emacs Lisp
|
||||
- Erlang
|
||||
- Go
|
||||
- HTML
|
||||
- Haskell
|
||||
- Java
|
||||
- JavaScript
|
||||
- Lua
|
||||
- Matlab
|
||||
- Objective-C
|
||||
- PHP
|
||||
- Perl
|
||||
- Python
|
||||
- R
|
||||
- Ruby
|
||||
- SQL
|
||||
- Scala
|
||||
- Scheme
|
||||
- Shell
|
||||
- Swift
|
||||
- TeX
|
||||
- VimL
|
||||
|
||||
@@ -156,13 +156,8 @@ module Linguist
|
||||
|
||||
blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
|
||||
|
||||
# Skip vendored or generated blobs
|
||||
next if blob.vendored? || blob.generated? || blob.language.nil?
|
||||
|
||||
# Only include programming languages and acceptable markup languages
|
||||
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
|
||||
file_map[new] = [blob.language.group.name, blob.size]
|
||||
end
|
||||
next unless blob.include_in_language_stats?
|
||||
file_map[new] = [blob.language.group.name, blob.size]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
30
lib/linguist/strategy/modeline.rb
Normal file
30
lib/linguist/strategy/modeline.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Modeline
|
||||
EmacsModeline = /-\*-\s*mode:\s*(\w+);?\s*-\*-/i
|
||||
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//i
|
||||
|
||||
# Public: Detects language based on Vim and Emacs modelines
|
||||
#
|
||||
# blob - An object that quacks like a blob.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# Modeline.call(FileBlob.new("path/to/file"))
|
||||
#
|
||||
# Returns an Array with one Language if the blob has a Vim or Emacs modeline
|
||||
# that matches a Language name or alias. Returns an empty array if no match.
|
||||
def self.call(blob, _ = nil)
|
||||
Array(Language.find_by_alias(modeline(blob.data)))
|
||||
end
|
||||
|
||||
# Public: Get the modeline from the first n-lines of the file
|
||||
#
|
||||
# Returns a String or nil
|
||||
def self.modeline(data)
|
||||
match = data.match(EmacsModeline) || data.match(VimModeline)
|
||||
match[1] if match
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -33,7 +33,8 @@ module Linguist
|
||||
['<!--', '-->'], # XML
|
||||
['{-', '-}'], # Haskell
|
||||
['(*', '*)'], # Coq
|
||||
['"""', '"""'] # Python
|
||||
['"""', '"""'], # Python
|
||||
["'''", "'''"] # Python
|
||||
]
|
||||
|
||||
START_SINGLE_LINE_COMMENT = Regexp.compile(SINGLE_LINE_COMMENTS.map { |c|
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
# Minified JavaScript and CSS
|
||||
- (\.|-)min\.(js|css)$
|
||||
|
||||
#Stylesheets imported from packages
|
||||
# Stylesheets imported from packages
|
||||
- ([^\s]*)import\.(css|less|scss|styl)$
|
||||
|
||||
# Bootstrap css and js
|
||||
@@ -251,3 +251,6 @@
|
||||
# ProGuard
|
||||
- proguard.pro
|
||||
- proguard-rules.pro
|
||||
|
||||
# Android Google APIs
|
||||
- (^|/)\.google_apis/
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Linguist
|
||||
VERSION = "4.2.7"
|
||||
VERSION = "4.5.2"
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"repository": "https://github.com/github/linguist",
|
||||
"dependencies": {
|
||||
"season": "~>3.0"
|
||||
"season": "~>5.0"
|
||||
}
|
||||
}
|
||||
|
||||
25
samples/AMPL/toy.ampl
Normal file
25
samples/AMPL/toy.ampl
Normal file
@@ -0,0 +1,25 @@
|
||||
# A toy knapsack problem from the LocalSolver docs written in AMPL.
|
||||
|
||||
set I;
|
||||
param Value{I};
|
||||
param Weight{I};
|
||||
param KnapsackBound;
|
||||
var Take{I} binary;
|
||||
|
||||
maximize TotalValue: sum{i in I} Take[i] * Value[i];
|
||||
s.t. WeightLimit: sum{i in I} Take[i] * Weight[i] <= KnapsackBound;
|
||||
|
||||
data;
|
||||
|
||||
param:
|
||||
I: Weight Value :=
|
||||
0 10 1
|
||||
1 60 10
|
||||
2 30 15
|
||||
3 40 40
|
||||
4 30 60
|
||||
5 20 90
|
||||
6 20 100
|
||||
7 2 15;
|
||||
|
||||
param KnapsackBound := 102;
|
||||
@@ -1,215 +0,0 @@
|
||||
%{
|
||||
#include "./../ATEXT/atextfun.hats"
|
||||
%}
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
<title>EFFECTIVATS-DiningPhil2</title>
|
||||
#patscode_style()
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
Effective ATS: Dining Philosophers
|
||||
</h1>
|
||||
|
||||
In this article, I present an implementation of a slight variant of the
|
||||
famous problem of 5-Dining-Philosophers by Dijkstra that makes simple but
|
||||
convincing use of linear types.
|
||||
|
||||
<h2>
|
||||
The Original Problem
|
||||
</h2>
|
||||
|
||||
There are five philosophers sitting around a table and there are also 5
|
||||
forks placed on the table such that each fork is located between the left
|
||||
hand of a philosopher and the right hand of another philosopher. Each
|
||||
philosopher does the following routine repeatedly: thinking and dining. In
|
||||
order to dine, a philosopher needs to first acquire two forks: one located
|
||||
on his left-hand side and the other on his right-hand side. After
|
||||
finishing dining, a philosopher puts the two acquired forks onto the table:
|
||||
one on his left-hand side and the other on his right-hand side.
|
||||
|
||||
<h2>
|
||||
A Variant of the Original Problem
|
||||
</h2>
|
||||
|
||||
The following twist is added to the original version:
|
||||
|
||||
<p>
|
||||
|
||||
After a fork is used, it becomes a "dirty" fork and needs to be put in a
|
||||
tray for dirty forks. There is a cleaner who cleans dirty forks and then
|
||||
puts them back on the table.
|
||||
|
||||
<h2>
|
||||
Channels for Communication
|
||||
</h2>
|
||||
|
||||
A channel is just a shared queue of fixed capacity. The following two
|
||||
functions are for inserting an element into and taking an element out of a
|
||||
given channel:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun{a:vt0p} channel_insert (channel (a), a): void
|
||||
fun{a:vt0p} channel_takeout (chan: channel (a)): (a)
|
||||
")</pre>
|
||||
|
||||
If [channel_insert] is called on a channel that is full, then the caller is
|
||||
blocked until an element is taken out of the channel. If [channel_takeout]
|
||||
is called on a channel that is empty, then the caller is blocked until an
|
||||
element is inserted into the channel.
|
||||
|
||||
<h2>
|
||||
A Channel for Each Fork
|
||||
</h2>
|
||||
|
||||
Forks are resources given a linear type. Each fork is initially stored in a
|
||||
channel, which can be obtained by calling the following function:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun fork_changet (n: nphil): channel(fork)
|
||||
")</pre>
|
||||
|
||||
where the type [nphil] is defined to be [natLt(5)] (for natural numbers
|
||||
less than 5). The channels for storing forks are chosen to be of capacity
|
||||
2. The reason that channels of capacity 2 are chosen to store at most one
|
||||
element (in each of them) is to guarantee that these channels can never be
|
||||
full (so that there is no attempt made to send signals to awake callers
|
||||
supposedly being blocked due to channels being full).
|
||||
|
||||
|
||||
<h2>
|
||||
A Channel for the Fork Tray
|
||||
</h2>
|
||||
|
||||
A tray for storing "dirty" forks is also a channel, which can be obtained
|
||||
by calling the following function:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun forktray_changet ((*void*)): channel(fork)
|
||||
")</pre>
|
||||
|
||||
The capacity chosen for the channel is 6 (instead of 5) so that it can
|
||||
never become full (as there are only 5 forks in total).
|
||||
|
||||
<h2>
|
||||
Philosopher Loop
|
||||
</h2>
|
||||
|
||||
Each philosopher is implemented as a loop:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
phil_loop (n) = let
|
||||
//
|
||||
val () = phil_think (n)
|
||||
//
|
||||
val nl = phil_left (n) // = n
|
||||
val nr = phil_right (n) // = (n+1) % 5
|
||||
//
|
||||
val ch_lfork = fork_changet (nl)
|
||||
val ch_rfork = fork_changet (nr)
|
||||
//
|
||||
val lf = channel_takeout (ch_lfork)
|
||||
val () = println! ("phil_loop(", n, ") picks left fork")
|
||||
//
|
||||
val () = randsleep (2) // sleep up to 2 seconds
|
||||
//
|
||||
val rf = channel_takeout (ch_rfork)
|
||||
val () = println! ("phil_loop(", n, ") picks right fork")
|
||||
//
|
||||
val () = phil_dine (n, lf, rf)
|
||||
//
|
||||
val ch_forktray = forktray_changet ()
|
||||
val () = channel_insert (ch_forktray, lf) // left fork to dirty tray
|
||||
val () = channel_insert (ch_forktray, rf) // right fork to dirty tray
|
||||
//
|
||||
in
|
||||
phil_loop (n)
|
||||
end // end of [phil_loop]
|
||||
')</pre>
|
||||
|
||||
It should be straighforward to follow the code for [phil_loop].
|
||||
|
||||
<h2>
|
||||
Fork Cleaner Loop
|
||||
</h2>
|
||||
|
||||
A cleaner is implemented as a loop:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
cleaner_loop () = let
|
||||
//
|
||||
val ch = forktray_changet ()
|
||||
val f0 = channel_takeout (ch) // [f0] is dirty
|
||||
//
|
||||
val () = cleaner_wash (f0) // washes dirty [f0]
|
||||
val () = cleaner_return (f0) // puts back cleaned [f0]
|
||||
//
|
||||
in
|
||||
cleaner_loop ()
|
||||
end // end of [cleaner_loop]
|
||||
')</pre>
|
||||
|
||||
The function [cleaner_return] first finds out the number of a given fork
|
||||
and then uses the number to locate the channel for storing the fork. Its
|
||||
actual implementation is given as follows:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
cleaner_return (f) =
|
||||
{
|
||||
val n = fork_get_num (f)
|
||||
val ch = fork_changet (n)
|
||||
val () = channel_insert (ch, f)
|
||||
}
|
||||
')</pre>
|
||||
|
||||
It should now be straighforward to follow the code for [cleaner_loop].
|
||||
|
||||
<h2>
|
||||
Testing
|
||||
</h2>
|
||||
|
||||
The entire code of this implementation is stored in the following files:
|
||||
|
||||
<pre>
|
||||
DiningPhil2.sats
|
||||
DiningPhil2.dats
|
||||
DiningPhil2_fork.dats
|
||||
DiningPhil2_thread.dats
|
||||
</pre>
|
||||
|
||||
There is also a Makefile available for compiling the ATS source code into
|
||||
an excutable for testing. One should be able to encounter a deadlock after
|
||||
running the simulation for a while.
|
||||
|
||||
<hr size="2">
|
||||
|
||||
This article is written by <a href="http://www.cs.bu.edu/~hwxi/">Hongwei Xi</a>.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
%{
|
||||
implement main () = fprint_filsub (stdout_ref, "main_atxt.txt")
|
||||
%}
|
||||
2841
samples/Assembly/forth.nasm
Normal file
2841
samples/Assembly/forth.nasm
Normal file
File diff suppressed because it is too large
Load Diff
13
samples/Brainfuck/fib100.bf
Normal file
13
samples/Brainfuck/fib100.bf
Normal file
@@ -0,0 +1,13 @@
|
||||
# Calculate and output all fibonacci numbers under 100
|
||||
|
||||
+++++++++++
|
||||
>+>>>>++++++++++++++++++++++++++++++++++++++++++++
|
||||
>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
|
||||
+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
|
||||
<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
|
||||
-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
|
||||
>[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
|
||||
+++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
|
||||
++++++++++++++++++++++++++++++++++++++++++++.[-]<<
|
||||
<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
|
||||
[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
|
||||
4
samples/Brainfuck/hello.bf
Normal file
4
samples/Brainfuck/hello.bf
Normal file
@@ -0,0 +1,4 @@
|
||||
// More complex version of hello world
|
||||
|
||||
>++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>
|
||||
>+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++.
|
||||
3
samples/Brainfuck/helloworld.bf
Normal file
3
samples/Brainfuck/helloworld.bf
Normal file
@@ -0,0 +1,3 @@
|
||||
// Hello World
|
||||
|
||||
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
|
||||
30
samples/Brainfuck/rot13.bf
Normal file
30
samples/Brainfuck/rot13.bf
Normal file
@@ -0,0 +1,30 @@
|
||||
# ROT13 cipher
|
||||
|
||||
-,+[ Read first character and start outer character reading loop
|
||||
-[ Skip forward if character is 0
|
||||
>>++++[>++++++++<-] Set up divisor (32) for division loop
|
||||
(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
|
||||
<+<-[ Set up dividend (x minus 1) and enter division loop
|
||||
>+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward
|
||||
<[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient
|
||||
<<<<<- Decrement dividend
|
||||
] End division loop
|
||||
]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag
|
||||
>--[-[<->+++[-]]]<[ Zero that flag unless quotient was 2 or 3; zero quotient; check flag
|
||||
++++++++++++<[ If flag then set up divisor (13) for second division loop
|
||||
(MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero)
|
||||
>-[>+>>] Reduce divisor; Normal case: increase remainder
|
||||
>[+[<+>-]>+>>] Special case: increase remainder / move it back to divisor / increase quotient
|
||||
<<<<<- Decrease dividend
|
||||
] End division loop
|
||||
>>[<+>-] Add remainder back to divisor to get a useful 13
|
||||
>[ Skip forward if quotient was 0
|
||||
-[ Decrement quotient and skip forward if quotient was 1
|
||||
-<<[-]>> Zero quotient and divisor if quotient was 2
|
||||
]<<[<<->>-]>> Zero divisor and subtract 13 from copy if quotient was 1
|
||||
]<<[<<+>>-] Zero divisor and add 13 to copy if quotient was 0
|
||||
] End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3)
|
||||
<[-] Clear remainder from first division if second division was skipped
|
||||
<.[-] Output ROT13ed character from copy and clear it
|
||||
<-,+ Read next character
|
||||
] End character reading loop
|
||||
116
samples/C++/qsciprinter.cp
Normal file
116
samples/C++/qsciprinter.cp
Normal file
@@ -0,0 +1,116 @@
|
||||
// This module defines interface to the QsciPrinter class.
|
||||
//
|
||||
// Copyright (c) 2011 Riverbank Computing Limited <info@riverbankcomputing.com>
|
||||
//
|
||||
// This file is part of QScintilla.
|
||||
//
|
||||
// This file may be used under the terms of the GNU General Public
|
||||
// License versions 2.0 or 3.0 as published by the Free Software
|
||||
// Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
|
||||
// included in the packaging of this file. Alternatively you may (at
|
||||
// your option) use any later version of the GNU General Public
|
||||
// License if such license has been publicly approved by Riverbank
|
||||
// Computing Limited (or its successors, if any) and the KDE Free Qt
|
||||
// Foundation. In addition, as a special exception, Riverbank gives you
|
||||
// certain additional rights. These rights are described in the Riverbank
|
||||
// GPL Exception version 1.1, which can be found in the file
|
||||
// GPL_EXCEPTION.txt in this package.
|
||||
//
|
||||
// If you are unsure which license is appropriate for your use, please
|
||||
// contact the sales department at sales@riverbankcomputing.com.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
#ifndef QSCIPRINTER_H
|
||||
#define QSCIPRINTER_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern "C++" {
|
||||
#endif
|
||||
|
||||
#include <qprinter.h>
|
||||
|
||||
#include <Qsci/qsciglobal.h>
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QRect;
|
||||
class QPainter;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QsciScintillaBase;
|
||||
|
||||
|
||||
//! \brief The QsciPrinter class is a sub-class of the Qt QPrinter class that
|
||||
//! is able to print the text of a Scintilla document.
|
||||
//!
|
||||
//! The class can be further sub-classed to alter to layout of the text, adding
|
||||
//! headers and footers for example.
|
||||
class QSCINTILLA_EXPORT QsciPrinter : public QPrinter
|
||||
{
|
||||
public:
|
||||
//! Constructs a printer paint device with mode \a mode.
|
||||
QsciPrinter(PrinterMode mode = ScreenResolution);
|
||||
|
||||
//! Destroys the QsciPrinter instance.
|
||||
virtual ~QsciPrinter();
|
||||
|
||||
//! Format a page, by adding headers and footers for example, before the
|
||||
//! document text is drawn on it. \a painter is the painter to be used to
|
||||
//! add customised text and graphics. \a drawing is true if the page is
|
||||
//! actually being drawn rather than being sized. \a painter drawing
|
||||
//! methods must only be called when \a drawing is true. \a area is the
|
||||
//! area of the page that will be used to draw the text. This should be
|
||||
//! modified if it is necessary to reserve space for any customised text or
|
||||
//! graphics. By default the area is relative to the printable area of the
|
||||
//! page. Use QPrinter::setFullPage() because calling printRange() if you
|
||||
//! want to try and print over the whole page. \a pagenr is the number of
|
||||
//! the page. The first page is numbered 1.
|
||||
virtual void formatPage(QPainter &painter, bool drawing, QRect &area,
|
||||
int pagenr);
|
||||
|
||||
//! Return the number of points to add to each font when printing.
|
||||
//!
|
||||
//! \sa setMagnification()
|
||||
int magnification() const {return mag;}
|
||||
|
||||
//! Sets the number of points to add to each font when printing to \a
|
||||
//! magnification.
|
||||
//!
|
||||
//! \sa magnification()
|
||||
virtual void setMagnification(int magnification);
|
||||
|
||||
//! Print a range of lines from the Scintilla instance \a qsb. \a from is
|
||||
//! the first line to print and a negative value signifies the first line
|
||||
//! of text. \a to is the last line to print and a negative value
|
||||
//! signifies the last line of text. true is returned if there was no
|
||||
//! error.
|
||||
virtual int printRange(QsciScintillaBase *qsb, int from = -1, int to = -1);
|
||||
|
||||
//! Return the line wrap mode used when printing. The default is
|
||||
//! QsciScintilla::WrapWord.
|
||||
//!
|
||||
//! \sa setWrapMode()
|
||||
QsciScintilla::WrapMode wrapMode() const {return wrap;}
|
||||
|
||||
//! Sets the line wrap mode used when printing to \a wmode.
|
||||
//!
|
||||
//! \sa wrapMode()
|
||||
virtual void setWrapMode(QsciScintilla::WrapMode wmode);
|
||||
|
||||
private:
|
||||
int mag;
|
||||
QsciScintilla::WrapMode wrap;
|
||||
|
||||
QsciPrinter(const QsciPrinter &);
|
||||
QsciPrinter &operator=(const QsciPrinter &);
|
||||
};
|
||||
|
||||
#ifdef __APPLE__
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
2310
samples/C/filenames/script
Executable file
2310
samples/C/filenames/script
Executable file
File diff suppressed because it is too large
Load Diff
166
samples/C/pqiv.h
Normal file
166
samples/C/pqiv.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* pqiv
|
||||
*
|
||||
* Copyright (c) 2013-2014, Phillip Berndt
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// This file contains the definition of files, image types and
|
||||
// the plugin infrastructure. It should be included in file type
|
||||
// handlers.
|
||||
|
||||
#ifndef _PQIV_H_INCLUDED
|
||||
#define _PQIV_H_INCLUDED
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gio/gio.h>
|
||||
#include "lib/bostree.h"
|
||||
|
||||
#ifndef PQIV_VERSION
|
||||
#define PQIV_VERSION "2.3"
|
||||
#endif
|
||||
|
||||
#define FILE_FLAGS_ANIMATION (guint)(1)
|
||||
#define FILE_FLAGS_MEMORY_IMAGE (guint)(1<<1)
|
||||
|
||||
// The structure for images {{{
|
||||
typedef struct file_type_handler_struct_t file_type_handler_t;
|
||||
typedef struct {
|
||||
// File type
|
||||
const file_type_handler_t *file_type;
|
||||
|
||||
// Special flags
|
||||
// FILE_FLAGS_ANIMATION -> Animation functions are invoked
|
||||
// Set by file type handlers
|
||||
// FILE_FLAGS_MEMORY_IMAGE -> File lives in memory
|
||||
guint file_flags;
|
||||
|
||||
// The file name to display and to sort by
|
||||
gchar *display_name;
|
||||
|
||||
// The URI or file name of the file
|
||||
gchar *file_name;
|
||||
|
||||
// If the file is a memory image, the actual image data
|
||||
GBytes *file_data;
|
||||
|
||||
// The file monitor structure is used for inotify-watching of
|
||||
// the files
|
||||
GFileMonitor *file_monitor;
|
||||
|
||||
// This flag stores whether this image is currently loaded
|
||||
// and valid. i.e. if it is set, you can assume that
|
||||
// private_data contains a representation of the image;
|
||||
// if not, you can NOT assume that it does not.
|
||||
gboolean is_loaded;
|
||||
|
||||
// Cached image size
|
||||
guint width;
|
||||
guint height;
|
||||
|
||||
// File-type specific data, allocated and freed by the file type handlers
|
||||
void *private;
|
||||
} file_t;
|
||||
// }}}
|
||||
// Definition of the built-in file types {{{
|
||||
|
||||
// If you want to implement your own file type, you'll have to implement the
|
||||
// following functions and a non-static initialization function named
|
||||
// file_type_NAME_initializer that fills a file_type_handler_t with pointers to
|
||||
// the functions. Store the file in backends/NAME.c and adjust the Makefile to
|
||||
// add the required libraries if your backend is listed in the $(BACKENDS)
|
||||
// variable.
|
||||
|
||||
typedef enum { PARAMETER, RECURSION, INOTIFY, BROWSE_ORIGINAL_PARAMETER, FILTER_OUTPUT } load_images_state_t;
|
||||
// Allocation function: Allocate the ->private structure within a file and add the
|
||||
// image(s) to the list of available images via load_images_handle_parameter_add_file()
|
||||
// If an image is not to be loaded for any reason, the file structure should be
|
||||
// deallocated using file_free()
|
||||
// Returns a pointer to the first added image
|
||||
// Optional, you can also set the pointer to this function to NULL.
|
||||
typedef BOSNode *(*file_type_alloc_fn_t)(load_images_state_t state, file_t *file);
|
||||
|
||||
// Deallocation, if a file is removed from the images list. Free the ->private structure.
|
||||
// Only called if ->private is non-NULL.
|
||||
typedef void (*file_type_free_fn_t)(file_t *file);
|
||||
|
||||
// Actually load a file into memory
|
||||
typedef void (*file_type_load_fn_t)(file_t *file, GInputStream *data, GError **error_pointer);
|
||||
|
||||
// Unload a file
|
||||
typedef void (*file_type_unload_fn_t)(file_t *file);
|
||||
|
||||
// Animation support: Initialize memory for animations, return ms until first frame
|
||||
// Optional, you can also set the pointer to this function to NULL.
|
||||
typedef double (*file_type_animation_initialize_fn_t)(file_t *file);
|
||||
|
||||
// Animation support: Advance to the next frame, return ms until next frame
|
||||
// Optional, you can also set the pointer to this function to NULL.
|
||||
typedef double (*file_type_animation_next_frame_fn_t)(file_t *file);
|
||||
|
||||
// Draw the current view to a cairo context
|
||||
typedef void (*file_type_draw_fn_t)(file_t *file, cairo_t *cr);
|
||||
|
||||
struct file_type_handler_struct_t {
|
||||
// All files will be filtered with this filter. If it lets it pass,
|
||||
// a handler is assigned to a file. If none do, the file is
|
||||
// discarded if it was found during directory traversal or
|
||||
// loaded using the first image backend if it was an explicit
|
||||
// parameter.
|
||||
GtkFileFilter *file_types_handled;
|
||||
|
||||
// Pointers to the functions defined above
|
||||
file_type_alloc_fn_t alloc_fn;
|
||||
file_type_free_fn_t free_fn;
|
||||
file_type_load_fn_t load_fn;
|
||||
file_type_unload_fn_t unload_fn;
|
||||
file_type_animation_initialize_fn_t animation_initialize_fn;
|
||||
file_type_animation_next_frame_fn_t animation_next_frame_fn;
|
||||
file_type_draw_fn_t draw_fn;
|
||||
};
|
||||
|
||||
// Initialization function: Tell pqiv about a backend
|
||||
typedef void (*file_type_initializer_fn_t)(file_type_handler_t *info);
|
||||
|
||||
// pqiv symbols available to plugins {{{
|
||||
|
||||
// Global cancellable that should be used for every i/o operation
|
||||
extern GCancellable *image_loader_cancellable;
|
||||
|
||||
// Current scale level. For backends that don't support cairo natively.
|
||||
extern gdouble current_scale_level;
|
||||
|
||||
// Load a file from disc/memory/network
|
||||
GInputStream *image_loader_stream_file(file_t *file, GError **error_pointer);
|
||||
|
||||
// Add a file to the list of loaded files
|
||||
// Should be called at least once in a file_type_alloc_fn_t, with the state being
|
||||
// forwarded unaltered.
|
||||
BOSNode *load_images_handle_parameter_add_file(load_images_state_t state, file_t *file);
|
||||
|
||||
// Load all data from an input stream into memory, conveinience function
|
||||
GBytes *g_input_stream_read_completely(GInputStream *input_stream, GCancellable *cancellable, GError **error_pointer);
|
||||
|
||||
// Free a file
|
||||
void file_free(file_t *file);
|
||||
|
||||
// }}}
|
||||
|
||||
// File type handlers, used in the initializer and file type guessing
|
||||
extern file_type_handler_t file_type_handlers[];
|
||||
|
||||
/* }}} */
|
||||
|
||||
#endif
|
||||
343
samples/CLIPS/demo.clp
Normal file
343
samples/CLIPS/demo.clp
Normal file
@@ -0,0 +1,343 @@
|
||||
;;;***************************
|
||||
;;;* DEFFACTS KNOWLEDGE BASE *
|
||||
;;;***************************
|
||||
|
||||
(deffacts MAIN::knowledge-base
|
||||
(welcome (message WelcomeMessage))
|
||||
(goal (variable type.animal))
|
||||
(legalanswers (values yes no))
|
||||
(displayanswers (values "Yes" "No"))
|
||||
(rule (if backbone is yes)
|
||||
(then superphylum is backbone))
|
||||
(rule (if backbone is no)
|
||||
(then superphylum is jellyback))
|
||||
(question (variable backbone)
|
||||
(query backbone.query))
|
||||
(rule (if superphylum is backbone and
|
||||
warm.blooded is yes)
|
||||
(then phylum is warm))
|
||||
(rule (if superphylum is backbone and
|
||||
warm.blooded is no)
|
||||
(then phylum is cold))
|
||||
(question (variable warm.blooded)
|
||||
(query warm.blooded.query))
|
||||
(rule (if superphylum is jellyback and
|
||||
live.prime.in.soil is yes)
|
||||
(then phylum is soil))
|
||||
(rule (if superphylum is jellyback and
|
||||
live.prime.in.soil is no)
|
||||
(then phylum is elsewhere))
|
||||
(question (variable live.prime.in.soil)
|
||||
(query live.prime.in.soil.query))
|
||||
(rule (if phylum is warm and
|
||||
has.breasts is yes)
|
||||
(then class is breasts))
|
||||
(rule (if phylum is warm and
|
||||
has.breasts is no)
|
||||
(then type.animal is bird))
|
||||
(question (variable has.breasts)
|
||||
(query has.breasts.query))
|
||||
(rule (if phylum is cold and
|
||||
always.in.water is yes)
|
||||
(then class is water))
|
||||
(rule (if phylum is cold and
|
||||
always.in.water is no)
|
||||
(then class is dry))
|
||||
(question (variable always.in.water)
|
||||
(query always.in.water.query))
|
||||
(rule (if phylum is soil and
|
||||
flat.bodied is yes)
|
||||
(then type.animal is flatworm))
|
||||
(rule (if phylum is soil and
|
||||
flat.bodied is no)
|
||||
(then type.animal is worm.leech))
|
||||
(question (variable flat.bodied)
|
||||
(query flat.bodied.query))
|
||||
(rule (if phylum is elsewhere and
|
||||
body.in.segments is yes)
|
||||
(then class is segments))
|
||||
(rule (if phylum is elsewhere and
|
||||
body.in.segments is no)
|
||||
(then class is unified))
|
||||
(question (variable body.in.segments)
|
||||
(query body.in.segments.query))
|
||||
(rule (if class is breasts and
|
||||
can.eat.meat is yes)
|
||||
(then order is meat))
|
||||
(rule (if class is breasts and
|
||||
can.eat.meat is no)
|
||||
(then order is vegy))
|
||||
(question (variable can.eat.meat)
|
||||
(query can.eat.meat.query))
|
||||
(rule (if class is water and
|
||||
boney is yes)
|
||||
(then type.animal is fish))
|
||||
(rule (if class is water and
|
||||
boney is no)
|
||||
(then type.animal is shark.ray))
|
||||
(question (variable boney)
|
||||
(query boney.query))
|
||||
(rule (if class is dry and
|
||||
scaly is yes)
|
||||
(then order is scales))
|
||||
(rule (if class is dry and
|
||||
scaly is no)
|
||||
(then order is soft))
|
||||
(question (variable scaly)
|
||||
(query scaly.query))
|
||||
(rule (if class is segments and
|
||||
shell is yes)
|
||||
(then order is shell))
|
||||
(rule (if class is segments and
|
||||
shell is no)
|
||||
(then type.animal is centipede.millipede.insect))
|
||||
(question (variable shell)
|
||||
(query shell.query))
|
||||
(rule (if class is unified and
|
||||
digest.cells is yes)
|
||||
(then order is cells))
|
||||
(rule (if class is unified and
|
||||
digest.cells is no)
|
||||
(then order is stomach))
|
||||
(question (variable digest.cells)
|
||||
(query digest.cells.query))
|
||||
(rule (if order is meat and
|
||||
fly is yes)
|
||||
(then type.animal is bat))
|
||||
(rule (if order is meat and
|
||||
fly is no)
|
||||
(then family is nowings))
|
||||
(question (variable fly)
|
||||
(query fly.query))
|
||||
(rule (if order is vegy and
|
||||
hooves is yes)
|
||||
(then family is hooves))
|
||||
(rule (if order is vegy and
|
||||
hooves is no)
|
||||
(then family is feet))
|
||||
(question (variable hooves)
|
||||
(query hooves.query))
|
||||
(rule (if order is scales and
|
||||
rounded.shell is yes)
|
||||
(then type.animal is turtle))
|
||||
(rule (if order is scales and
|
||||
rounded.shell is no)
|
||||
(then family is noshell))
|
||||
(question (variable rounded.shell)
|
||||
(query rounded.shell.query))
|
||||
(rule (if order is soft and
|
||||
jump is yes)
|
||||
(then type.animal is frog))
|
||||
(rule (if order is soft and
|
||||
jump is no)
|
||||
(then type.animal is salamander))
|
||||
(question (variable jump)
|
||||
(query jump.query))
|
||||
(rule (if order is shell and
|
||||
tail is yes)
|
||||
(then type.animal is lobster))
|
||||
(rule (if order is shell and
|
||||
tail is no)
|
||||
(then type.animal is crab))
|
||||
(question (variable tail)
|
||||
(query tail.query))
|
||||
(rule (if order is cells and
|
||||
stationary is yes)
|
||||
(then family is stationary))
|
||||
(rule (if order is cells and
|
||||
stationary is no)
|
||||
(then type.animal is jellyfish))
|
||||
(question (variable stationary)
|
||||
(query stationary.query))
|
||||
(rule (if order is stomach and
|
||||
multicelled is yes)
|
||||
(then family is multicelled))
|
||||
(rule (if order is stomach and
|
||||
multicelled is no)
|
||||
(then type.animal is protozoa))
|
||||
(question (variable multicelled)
|
||||
(query multicelled.query))
|
||||
(rule (if family is nowings and
|
||||
opposing.thumb is yes)
|
||||
(then genus is thumb))
|
||||
(rule (if family is nowings and
|
||||
opposing.thumb is no)
|
||||
(then genus is nothumb))
|
||||
(question (variable opposing.thumb)
|
||||
(query opposing.thumb.query))
|
||||
(rule (if family is hooves and
|
||||
two.toes is yes)
|
||||
(then genus is twotoes))
|
||||
(rule (if family is hooves and
|
||||
two.toes is no)
|
||||
(then genus is onetoe))
|
||||
(question (variable two.toes)
|
||||
(query two.toes.query))
|
||||
(rule (if family is feet and
|
||||
live.in.water is yes)
|
||||
(then genus is water))
|
||||
(rule (if family is feet and
|
||||
live.in.water is no)
|
||||
(then genus is dry))
|
||||
(question (variable live.in.water)
|
||||
(query live.in.water.query))
|
||||
(rule (if family is noshell and
|
||||
limbs is yes)
|
||||
(then type.animal is crocodile.alligator))
|
||||
(rule (if family is noshell and
|
||||
limbs is no)
|
||||
(then type.animal is snake))
|
||||
(question (variable limbs)
|
||||
(query limbs.query))
|
||||
(rule (if family is stationary and
|
||||
spikes is yes)
|
||||
(then type.animal is sea.anemone))
|
||||
(rule (if family is stationary and
|
||||
spikes is no)
|
||||
(then type.animal is coral.sponge))
|
||||
(question (variable spikes)
|
||||
(query spikes.query))
|
||||
(rule (if family is multicelled and
|
||||
spiral.shell is yes)
|
||||
(then type.animal is snail))
|
||||
(rule (if family is multicelled and
|
||||
spiral.shell is no)
|
||||
(then genus is noshell))
|
||||
(question (variable spiral.shell)
|
||||
(query spiral.shell.query))
|
||||
(rule (if genus is thumb and
|
||||
prehensile.tail is yes)
|
||||
(then type.animal is monkey))
|
||||
(rule (if genus is thumb and
|
||||
prehensile.tail is no)
|
||||
(then species is notail))
|
||||
(question (variable prehensile.tail)
|
||||
(query prehensile.tail.query))
|
||||
(rule (if genus is nothumb and
|
||||
over.400 is yes)
|
||||
(then species is 400))
|
||||
(rule (if genus is nothumb and
|
||||
over.400 is no)
|
||||
(then species is under400))
|
||||
(question (variable over.400)
|
||||
(query over.400.query))
|
||||
(rule (if genus is twotoes and
|
||||
horns is yes)
|
||||
(then species is horns))
|
||||
(rule (if genus is twotoes and
|
||||
horns is no)
|
||||
(then species is nohorns))
|
||||
(question (variable horns)
|
||||
(query horns.query))
|
||||
(rule (if genus is onetoe and
|
||||
plating is yes)
|
||||
(then type.animal is rhinoceros))
|
||||
(rule (if genus is onetoe and
|
||||
plating is no)
|
||||
(then type.animal is horse.zebra))
|
||||
(question (variable plating)
|
||||
(query plating.query))
|
||||
(rule (if genus is water and
|
||||
hunted is yes)
|
||||
(then type.animal is whale))
|
||||
(rule (if genus is water and
|
||||
hunted is no)
|
||||
(then type.animal is dolphin.porpoise))
|
||||
(question (variable hunted)
|
||||
(query hunted.query))
|
||||
(rule (if genus is dry and
|
||||
front.teeth is yes)
|
||||
(then species is teeth))
|
||||
(rule (if genus is dry and
|
||||
front.teeth is no)
|
||||
(then species is noteeth))
|
||||
(question (variable front.teeth)
|
||||
(query front.teeth.query))
|
||||
(rule (if genus is noshell and
|
||||
bivalve is yes)
|
||||
(then type.animal is clam.oyster))
|
||||
(rule (if genus is noshell and
|
||||
bivalve is no)
|
||||
(then type.animal is squid.octopus))
|
||||
(question (variable bivalve)
|
||||
(query bivalve.query))
|
||||
(rule (if species is notail and
|
||||
nearly.hairless is yes)
|
||||
(then type.animal is man))
|
||||
(rule (if species is notail and
|
||||
nearly.hairless is no)
|
||||
(then subspecies is hair))
|
||||
(question (variable nearly.hairless)
|
||||
(query nearly.hairless.query))
|
||||
(rule (if species is 400 and
|
||||
land.based is yes)
|
||||
(then type.animal is bear.tiger.lion))
|
||||
(rule (if species is 400 and
|
||||
land.based is no)
|
||||
(then type.animal is walrus))
|
||||
(question (variable land.based)
|
||||
(query land.based.query))
|
||||
(rule (if species is under400 and
|
||||
thintail is yes)
|
||||
(then type.animal is cat))
|
||||
(rule (if species is under400 and
|
||||
thintail is no)
|
||||
(then type.animal is coyote.wolf.fox.dog))
|
||||
(question (variable thintail)
|
||||
(query thintail.query))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is yes)
|
||||
(then type.animal is camel))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is no and
|
||||
semi.aquatic is no)
|
||||
(then type.animal is giraffe))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is no and
|
||||
semi.aquatic is yes)
|
||||
(then type.animal is hippopotamus))
|
||||
(question (variable lives.in.desert)
|
||||
(query lives.in.desert.query))
|
||||
(question (variable semi.aquatic)
|
||||
(query semi.aquatic.query))
|
||||
(rule (if species is teeth and
|
||||
large.ears is yes)
|
||||
(then type.animal is rabbit))
|
||||
(rule (if species is teeth and
|
||||
large.ears is no)
|
||||
(then type.animal is rat.mouse.squirrel.beaver.porcupine))
|
||||
(question (variable large.ears)
|
||||
(query large.ears.query))
|
||||
(rule (if species is noteeth and
|
||||
pouch is yes)
|
||||
(then type.animal is kangaroo.koala.bear))
|
||||
(rule (if species is noteeth and
|
||||
pouch is no)
|
||||
(then type.animal is mole.shrew.elephant))
|
||||
(question (variable pouch)
|
||||
(query pouch.query))
|
||||
(rule (if subspecies is hair and
|
||||
long.powerful.arms is yes)
|
||||
(then type.animal is orangutan.gorilla.chimpanzee))
|
||||
(rule (if subspecies is hair and
|
||||
long.powerful.arms is no)
|
||||
(then type.animal is baboon))
|
||||
(question (variable long.powerful.arms)
|
||||
(query long.powerful.arms.query))
|
||||
(rule (if species is horns and
|
||||
fleece is yes)
|
||||
(then type.animal is sheep.goat))
|
||||
(rule (if species is horns and
|
||||
fleece is no)
|
||||
(then subsubspecies is nofleece))
|
||||
(question (variable fleece)
|
||||
(query fleece.query))
|
||||
(rule (if subsubspecies is nofleece and
|
||||
domesticated is yes)
|
||||
(then type.animal is cow))
|
||||
(rule (if subsubspecies is nofleece and
|
||||
domesticated is no)
|
||||
(then type.animal is deer.moose.antelope))
|
||||
(question (variable domesticated)
|
||||
(query domesticated.query))
|
||||
(answer (prefix "I think your animal is a ") (variable type.animal) (postfix ".")))
|
||||
281
samples/CLIPS/sudoku.clp
Normal file
281
samples/CLIPS/sudoku.clp
Normal file
@@ -0,0 +1,281 @@
|
||||
;;; http://www.angusj.com/sudoku/hints
|
||||
;;; http://www.scanraid.com/BasicStrategies.htm
|
||||
;;; http://www.sudokuoftheday.com/pages/techniques-overview
|
||||
;;; http://www.sudokuonline.us/sudoku_solving_techniques
|
||||
;;; http://www.sadmansoftware.com/sudoku/techniques.htm
|
||||
;;; http://www.krazydad.com/blog/2005/09/29/an-index-of-sudoku-strategies/
|
||||
|
||||
;;; #######################
|
||||
;;; DEFTEMPLATES & DEFFACTS
|
||||
;;; #######################
|
||||
|
||||
(deftemplate possible
|
||||
(slot row)
|
||||
(slot column)
|
||||
(slot value)
|
||||
(slot group)
|
||||
(slot id))
|
||||
|
||||
(deftemplate impossible
|
||||
(slot id)
|
||||
(slot value)
|
||||
(slot priority)
|
||||
(slot reason))
|
||||
|
||||
(deftemplate technique-employed
|
||||
(slot reason)
|
||||
(slot priority))
|
||||
|
||||
(deftemplate technique
|
||||
(slot name)
|
||||
(slot priority))
|
||||
|
||||
(deffacts startup
|
||||
(phase grid-values))
|
||||
|
||||
(deftemplate size-value
|
||||
(slot size)
|
||||
(slot value))
|
||||
|
||||
(deffacts values
|
||||
(size-value (size 1) (value 1))
|
||||
(size-value (size 2) (value 2))
|
||||
(size-value (size 2) (value 3))
|
||||
(size-value (size 2) (value 4))
|
||||
(size-value (size 3) (value 5))
|
||||
(size-value (size 3) (value 6))
|
||||
(size-value (size 3) (value 7))
|
||||
(size-value (size 3) (value 8))
|
||||
(size-value (size 3) (value 9))
|
||||
(size-value (size 4) (value 10))
|
||||
(size-value (size 4) (value 11))
|
||||
(size-value (size 4) (value 12))
|
||||
(size-value (size 4) (value 13))
|
||||
(size-value (size 4) (value 14))
|
||||
(size-value (size 4) (value 15))
|
||||
(size-value (size 4) (value 16))
|
||||
(size-value (size 5) (value 17))
|
||||
(size-value (size 5) (value 18))
|
||||
(size-value (size 5) (value 19))
|
||||
(size-value (size 5) (value 20))
|
||||
(size-value (size 5) (value 21))
|
||||
(size-value (size 5) (value 22))
|
||||
(size-value (size 5) (value 23))
|
||||
(size-value (size 5) (value 24))
|
||||
(size-value (size 5) (value 25)))
|
||||
|
||||
;;; ###########
|
||||
;;; SETUP RULES
|
||||
;;; ###########
|
||||
|
||||
;;; ***********
|
||||
;;; stress-test
|
||||
;;; ***********
|
||||
|
||||
(defrule stress-test
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase match)
|
||||
|
||||
(stress-test)
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(technique (priority ?next&:(> ?next ?last)))
|
||||
|
||||
(not (technique (priority ?p&:(> ?p ?last)&:(< ?p ?next))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority ?next)))
|
||||
|
||||
;;; *****************
|
||||
;;; enable-techniques
|
||||
;;; *****************
|
||||
|
||||
(defrule enable-techniques
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase match)
|
||||
|
||||
(size ?)
|
||||
|
||||
(not (possible (value any)))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority 1)))
|
||||
|
||||
;;; **********
|
||||
;;; expand-any
|
||||
;;; **********
|
||||
|
||||
(defrule expand-any
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase expand-any)
|
||||
|
||||
?f <- (possible (row ?r) (column ?c) (value any) (group ?g) (id ?id))
|
||||
|
||||
(not (possible (value any) (id ?id2&:(< ?id2 ?id))))
|
||||
|
||||
(size ?s)
|
||||
|
||||
(size-value (size ?as&:(<= ?as ?s)) (value ?v))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v)))
|
||||
|
||||
(not (and (size-value (value ?v2&:(< ?v2 ?v)))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v2)))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (possible (row ?r) (column ?c) (value ?v) (group ?g) (id ?id))))
|
||||
|
||||
;;; *****************
|
||||
;;; position-expanded
|
||||
;;; *****************
|
||||
|
||||
(defrule position-expanded
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase expand-any)
|
||||
|
||||
?f <- (possible (row ?r) (column ?c) (value any) (group ?g) (id ?id))
|
||||
|
||||
(size ?s)
|
||||
|
||||
(not (and (size-value (size ?as&:(<= ?as ?s)) (value ?v))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v)))))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f))
|
||||
|
||||
;;; ###########
|
||||
;;; PHASE RULES
|
||||
;;; ###########
|
||||
|
||||
;;; ***************
|
||||
;;; expand-any-done
|
||||
;;; ***************
|
||||
|
||||
(defrule expand-any-done
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
?f <- (phase expand-any)
|
||||
|
||||
(not (possible (value any)))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase initial-output))
|
||||
(assert (print-position 1 1)))
|
||||
|
||||
;;; ***********
|
||||
;;; begin-match
|
||||
;;; ***********
|
||||
|
||||
(defrule begin-match
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase initial-output)
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase match)))
|
||||
|
||||
;;; *****************
|
||||
;;; begin-elimination
|
||||
;;; *****************
|
||||
|
||||
(defrule begin-elimination
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase match)
|
||||
|
||||
(not (not (impossible)))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase elimination)))
|
||||
|
||||
;;; *************
|
||||
;;; next-priority
|
||||
;;; *************
|
||||
|
||||
(defrule next-priority
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
(phase match)
|
||||
|
||||
(not (impossible))
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(technique (priority ?next&:(> ?next ?last)))
|
||||
|
||||
(not (technique (priority ?p&:(> ?p ?last)&:(< ?p ?next))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority ?next)))
|
||||
|
||||
;;; ************
|
||||
;;; begin-output
|
||||
;;; ************
|
||||
|
||||
(defrule begin-output
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase match)
|
||||
|
||||
(not (impossible))
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(not (technique (priority ?next&:(> ?next ?last))))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase final-output))
|
||||
(assert (print-position 1 1)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
15
samples/Clojure/build.boot
Normal file
15
samples/Clojure/build.boot
Normal file
@@ -0,0 +1,15 @@
|
||||
;; from: https://github.com/boot-clj/boot#configure-task-options
|
||||
|
||||
(set-env!
|
||||
:source-paths #{"src"}
|
||||
:dependencies '[[me.raynes/conch "0.8.0"]])
|
||||
|
||||
(task-options!
|
||||
pom {:project 'my-project
|
||||
:version "0.1.0"}
|
||||
jar {:manifest {"Foo" "bar"}})
|
||||
|
||||
(deftask build
|
||||
"Build my project."
|
||||
[]
|
||||
(comp (pom) (jar) (install)))
|
||||
21
samples/Common Lisp/sample.lsp
Normal file
21
samples/Common Lisp/sample.lsp
Normal file
@@ -0,0 +1,21 @@
|
||||
;;;; -*- lisp -*-
|
||||
|
||||
(in-package :foo)
|
||||
|
||||
;;; Header comment.
|
||||
(defvar *foo*)
|
||||
|
||||
(eval-when (:execute :compile-toplevel :load-toplevel)
|
||||
(defun add (x &optional y &key z)
|
||||
(declare (ignore z))
|
||||
;; Inline comment.
|
||||
(+ x (or y 1))))
|
||||
|
||||
#|
|
||||
Multi-line comment.
|
||||
|#
|
||||
|
||||
(defmacro foo (x &body b)
|
||||
(if x
|
||||
`(1+ ,x) ;After-line comment.
|
||||
42))
|
||||
318
samples/D/mpq.d
Normal file
318
samples/D/mpq.d
Normal file
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* mpq.d -- D programming language module for libmpq
|
||||
*
|
||||
* Copyright (c) 2008 Georg Lukas <georg@op-co.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* This module is written to support Phobos. Patches to allow binding to
|
||||
* Tango are welcome.
|
||||
*/
|
||||
|
||||
module mpq;
|
||||
|
||||
/* the following pragma does not work on DMD/Linux, generates a warning on
|
||||
* GDC/Linux and has not been tested on Windows. Commented out for now. */
|
||||
// pragma(lib, "libmpq");
|
||||
|
||||
import std.string; // for format() and toStringz()
|
||||
import std.traits; // for ParameterTypeTuple!()
|
||||
|
||||
/* XXX: this assumes that libmpq is compiled with Large File Support on */
|
||||
alias long off_t;
|
||||
|
||||
/* libmpq error return values */
|
||||
const LIBMPQ_ERROR_OPEN = -1; /* open error on file. */
|
||||
const LIBMPQ_ERROR_CLOSE = -2; /* close error on file. */
|
||||
const LIBMPQ_ERROR_SEEK = -3; /* lseek error on file. */
|
||||
const LIBMPQ_ERROR_READ = -4; /* read error on file. */
|
||||
const LIBMPQ_ERROR_WRITE = -5; /* write error on file. */
|
||||
const LIBMPQ_ERROR_MALLOC = -6; /* memory allocation error. */
|
||||
const LIBMPQ_ERROR_FORMAT = -7; /* format errror. */
|
||||
const LIBMPQ_ERROR_NOT_INITIALIZED = -8; /* init() wasn't called. */
|
||||
const LIBMPQ_ERROR_SIZE = -9; /* buffer size is to small. */
|
||||
const LIBMPQ_ERROR_EXIST = -10; /* file or block does not exist in archive. */
|
||||
const LIBMPQ_ERROR_DECRYPT = -11; /* we don't know the decryption seed. */
|
||||
const LIBMPQ_ERROR_UNPACK = -12; /* error on unpacking file. */
|
||||
|
||||
/** libmpq internal meta-data for an archive */
|
||||
extern struct mpq_archive_s;
|
||||
|
||||
extern(C) {
|
||||
|
||||
/* libmpq__generic information about library. */
|
||||
char *libmpq__version();
|
||||
|
||||
/* libmpq__generic mpq archive information. */
|
||||
int libmpq__archive_open(mpq_archive_s **mpq_archive, char *mpq_filename, off_t archive_offset);
|
||||
int libmpq__archive_close(mpq_archive_s *mpq_archive);
|
||||
int libmpq__archive_packed_size(mpq_archive_s *mpq_archive, off_t *packed_size);
|
||||
int libmpq__archive_unpacked_size(mpq_archive_s *mpq_archive, off_t *unpacked_size);
|
||||
int libmpq__archive_offset(mpq_archive_s *mpq_archive, off_t *offset);
|
||||
int libmpq__archive_version(mpq_archive_s *mpq_archive, uint *version_);
|
||||
int libmpq__archive_files(mpq_archive_s *mpq_archive, uint *files);
|
||||
|
||||
/* libmpq__generic file processing functions. */
|
||||
int libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint file_number, off_t *packed_size);
|
||||
int libmpq__file_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, off_t *unpacked_size);
|
||||
int libmpq__file_offset(mpq_archive_s *mpq_archive, uint file_number, off_t *offset);
|
||||
int libmpq__file_blocks(mpq_archive_s *mpq_archive, uint file_number, uint *blocks);
|
||||
int libmpq__file_encrypted(mpq_archive_s *mpq_archive, uint file_number, uint *encrypted);
|
||||
int libmpq__file_compressed(mpq_archive_s *mpq_archive, uint file_number, uint *compressed);
|
||||
int libmpq__file_imploded(mpq_archive_s *mpq_archive, uint file_number, uint *imploded);
|
||||
int libmpq__file_number(mpq_archive_s *mpq_archive, char *filename, uint *number);
|
||||
int libmpq__file_read(mpq_archive_s *mpq_archive, uint file_number, ubyte *out_buf, off_t out_size, off_t *transferred);
|
||||
|
||||
/* libmpq__generic block processing functions. */
|
||||
int libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint file_number);
|
||||
int libmpq__block_close_offset(mpq_archive_s *mpq_archive, uint file_number);
|
||||
int libmpq__block_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, uint block_number, off_t *unpacked_size);
|
||||
int libmpq__block_read(mpq_archive_s *mpq_archive, uint file_number, uint block_number, ubyte *out_buf, off_t out_size, off_t *transferred);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** exception class for failed libmpq calls */
|
||||
class MPQException : Exception {
|
||||
const string[] Errors = [
|
||||
"unknown error",
|
||||
"open error on file",
|
||||
"close error on file",
|
||||
"lseek error on file",
|
||||
"read error on file",
|
||||
"write error on file",
|
||||
"memory allocation error",
|
||||
"format errror",
|
||||
"init() wasn't called",
|
||||
"buffer size is to small",
|
||||
"file or block does not exist in archive",
|
||||
"we don't know the decryption seed",
|
||||
"error on unpacking file"];
|
||||
|
||||
public int errno;
|
||||
this(char[] fnname = "unknown_function", int errno = 0) {
|
||||
|
||||
this.errno = errno;
|
||||
if (-errno >= Errors.length)
|
||||
errno = 0;
|
||||
super(std.string.format("Error in %s(): %s (%d)",
|
||||
fnname, Errors[-errno], errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** template to wrap function calls and throw exceptions in case of error
|
||||
*
|
||||
* thanks for the idea to while(nan) blog,
|
||||
* http://while-nan.blogspot.com/2007/06/wrapping-functions-for-fun-and-profit.html
|
||||
*
|
||||
* use: MPQ_CHECKERR(libmpq__archive_open)(&m, "foo.mpq", -1);
|
||||
* returns the retval of archive_open on success;
|
||||
* throws an MPQException on failure.
|
||||
*
|
||||
* @param Fn libmpq__function reference
|
||||
* @param args libmpq__function parameters
|
||||
* @return return value of libmpq__function on success
|
||||
* @throw MPQException on error
|
||||
*/
|
||||
int MPQ_CHECKERR(alias Fn)(ParameterTypeTuple!(Fn) args)
|
||||
{
|
||||
int result = Fn(args);
|
||||
if (result < 0) {
|
||||
/* XXX: relying on non-specified stringof() behaviour */
|
||||
throw new MPQException((&Fn).stringof[2..$], result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** mixin alias to wrap library functions into MPQ_CHECKERR.
|
||||
*
|
||||
* alias mpq.func_name(...) to MPQ_CHECKERR(libmpq__func_name)(...)
|
||||
* @param func_name name of the function to be wrapped
|
||||
*/
|
||||
template MPQ_FUNC(char[] func_name) {
|
||||
const char[] MPQ_FUNC = "alias MPQ_CHECKERR!(libmpq__" ~ func_name ~ ") " ~ func_name ~ ";";
|
||||
}
|
||||
|
||||
alias libmpq__version libversion; /* must be direct alias because it returns char*, not error int */
|
||||
mixin(MPQ_FUNC!("archive_open"));
|
||||
mixin(MPQ_FUNC!("archive_close"));
|
||||
mixin(MPQ_FUNC!("archive_packed_size"));
|
||||
mixin(MPQ_FUNC!("archive_unpacked_size"));
|
||||
mixin(MPQ_FUNC!("archive_offset"));
|
||||
mixin(MPQ_FUNC!("archive_version"));
|
||||
mixin(MPQ_FUNC!("archive_files"));
|
||||
mixin(MPQ_FUNC!("file_packed_size"));
|
||||
mixin(MPQ_FUNC!("file_unpacked_size"));
|
||||
mixin(MPQ_FUNC!("file_offset"));
|
||||
mixin(MPQ_FUNC!("file_blocks"));
|
||||
mixin(MPQ_FUNC!("file_encrypted"));
|
||||
mixin(MPQ_FUNC!("file_compressed"));
|
||||
mixin(MPQ_FUNC!("file_imploded"));
|
||||
mixin(MPQ_FUNC!("file_number"));
|
||||
mixin(MPQ_FUNC!("file_read"));
|
||||
mixin(MPQ_FUNC!("block_open_offset"));
|
||||
mixin(MPQ_FUNC!("block_close_offset"));
|
||||
mixin(MPQ_FUNC!("block_unpacked_size"));
|
||||
mixin(MPQ_FUNC!("block_read"));
|
||||
|
||||
/** getter function named name for returning archive_* single values:
|
||||
*
|
||||
* <type> Archive.<name>() { return libmpq__archive_<name>() }
|
||||
*
|
||||
* @param type return type for the original function reference
|
||||
* @param name name of the original function
|
||||
* @param name2 name for the prototype (defaults to name, used for "version")
|
||||
* @return getter function mixin
|
||||
*/
|
||||
template MPQ_A_GET(char[] type, char[] name, char[] name2 = name) {
|
||||
const char[] MPQ_A_GET = type ~ " " ~ name2 ~ "() { " ~
|
||||
type ~ " ret; " ~
|
||||
"archive_" ~ name ~ "(m, &ret); return ret;" ~
|
||||
"}";
|
||||
}
|
||||
|
||||
/** wrapper class for an MPQ Archive
|
||||
*
|
||||
* syntax: auto a = new mpq.Archive("somefile.mpq");
|
||||
*/
|
||||
class Archive {
|
||||
mpq_archive_s *m;
|
||||
File listfile;
|
||||
char[][] listfiledata;
|
||||
|
||||
this(char[] archivename, off_t offset = -1) {
|
||||
archive_open(&m, toStringz(archivename), offset);
|
||||
}
|
||||
|
||||
mixin(MPQ_A_GET!("off_t", "packed_size"));
|
||||
mixin(MPQ_A_GET!("off_t", "unpacked_size"));
|
||||
mixin(MPQ_A_GET!("off_t", "offset"));
|
||||
mixin(MPQ_A_GET!("uint", "version", "version_"));
|
||||
mixin(MPQ_A_GET!("uint", "files"));
|
||||
|
||||
~this() {
|
||||
archive_close(m);
|
||||
}
|
||||
|
||||
mpq_archive_s* archive() {
|
||||
return m;
|
||||
}
|
||||
|
||||
File opIndex(char[] fname) {
|
||||
return new File(this, fname);
|
||||
}
|
||||
File opIndex(int fno) {
|
||||
return new File(this, fno);
|
||||
}
|
||||
|
||||
char[][] filelist() {
|
||||
try {
|
||||
if (!listfile) {
|
||||
listfile = this["(listfile)"];
|
||||
listfiledata = (cast(char[])listfile.read()).splitlines();
|
||||
}
|
||||
return listfiledata;
|
||||
} catch (MPQException e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/+uint filenumber(char[] filename) {
|
||||
try {
|
||||
if (!listfile) {
|
||||
listfile = this["(listfile)"];
|
||||
listfiledata = (cast(char[])listfile.read()).splitlines();
|
||||
}
|
||||
return listfiledata;
|
||||
} catch (MPQException e) {
|
||||
return [];
|
||||
}
|
||||
}+/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** getter function named name for returning file_* single values:
|
||||
*
|
||||
* <type> File.<name>() { return libmpq__file_<name>() }
|
||||
*
|
||||
* @param type return type for the original function reference
|
||||
* @param name name of the original function
|
||||
* @param name2 name for the prototype (defaults to name, used for "version")
|
||||
* @return getter function mixin
|
||||
*/
|
||||
template MPQ_F_GET(char[] type, char[] name, char[] name2 = name) {
|
||||
const char[] MPQ_F_GET = type ~ " " ~ name2 ~ "() { " ~
|
||||
type ~ " ret; " ~
|
||||
"file_" ~ name ~ "(am, fileno, &ret); " ~
|
||||
"return ret;" ~
|
||||
"}";
|
||||
}
|
||||
|
||||
/** wrapper class for a single file in an MPQ Archive
|
||||
*
|
||||
* syntax:
|
||||
* auto a = new mpq.Archive("somefile.mpq");
|
||||
* auto f = a["(listfile)"];
|
||||
* auto f2 = a[0];
|
||||
* auto f3 = new File(a, "(listfile)");
|
||||
*/
|
||||
class File {
|
||||
Archive a;
|
||||
mpq_archive_s* am;
|
||||
char[] filename;
|
||||
uint fileno;
|
||||
|
||||
this(Archive a, int fileno) {
|
||||
this.a = a;
|
||||
this.am = a.archive();
|
||||
if (fileno >= a.files) {
|
||||
throw new MPQException(format("File(%d)", fileno),
|
||||
LIBMPQ_ERROR_EXIST);
|
||||
}
|
||||
this.filename = format("file%04d.xxx", fileno);
|
||||
this.fileno = fileno;
|
||||
}
|
||||
|
||||
this(Archive a, char[] filename) {
|
||||
this.a = a;
|
||||
this.am = a.archive();
|
||||
this.filename = filename;
|
||||
/* this line will throw an exception when the file is not there */
|
||||
mpq.file_number(am, toStringz(filename), &this.fileno);
|
||||
}
|
||||
|
||||
mixin(MPQ_F_GET!("off_t", "packed_size"));
|
||||
mixin(MPQ_F_GET!("off_t", "unpacked_size"));
|
||||
mixin(MPQ_F_GET!("off_t", "offset"));
|
||||
mixin(MPQ_F_GET!("uint", "blocks"));
|
||||
mixin(MPQ_F_GET!("uint", "encrypted"));
|
||||
mixin(MPQ_F_GET!("uint", "compressed"));
|
||||
mixin(MPQ_F_GET!("uint", "imploded"));
|
||||
|
||||
uint no() { return fileno; }
|
||||
char[] name() { return filename; }
|
||||
|
||||
ubyte[] read() {
|
||||
ubyte[] content;
|
||||
content.length = this.unpacked_size();
|
||||
off_t trans;
|
||||
mpq.file_read(am, fileno, content.ptr, content.length, &trans);
|
||||
content.length = trans;
|
||||
return content;
|
||||
}
|
||||
}
|
||||
23
samples/DTrace/counts.d
Normal file
23
samples/DTrace/counts.d
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This software is in the public domain.
|
||||
*
|
||||
* $Id: counts.d 10510 2005-08-15 01:46:19Z kateturner $
|
||||
*/
|
||||
|
||||
#pragma D option quiet
|
||||
|
||||
self int tottime;
|
||||
BEGIN {
|
||||
tottime = timestamp;
|
||||
}
|
||||
|
||||
php$target:::function-entry
|
||||
@counts[copyinstr(arg0)] = count();
|
||||
}
|
||||
|
||||
END {
|
||||
printf("Total time: %dus\n", (timestamp - tottime) / 1000);
|
||||
printf("# calls by function:\n");
|
||||
printa("%-40s %@d\n", @counts);
|
||||
}
|
||||
|
||||
73
samples/DTrace/javascript-trace.d
Normal file
73
samples/DTrace/javascript-trace.d
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: dtrace-script; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* Copyright (C) 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* javascript provider probes
|
||||
*
|
||||
* function-entry (filename, classname, funcname)
|
||||
* function-info (filename, classname, funcname, lineno,
|
||||
* runfilename, runlineno)
|
||||
* function-args (filename, classname, funcname, argc, argv, argv0,
|
||||
* argv1, argv2, argv3, argv4)
|
||||
* function-rval (filename, classname, funcname, lineno, rval, rval0)
|
||||
* function-return (filename, classname, funcname)
|
||||
* object-create-start (filename, classname)
|
||||
* object-create (filename, classname, *object, rlineno)
|
||||
* object-create-done (filename, classname)
|
||||
* object-finalize (NULL, classname, *object)
|
||||
* execute-start (filename, lineno)
|
||||
* execute-done (filename, lineno)
|
||||
*/
|
||||
|
||||
provider javascript {
|
||||
probe function__entry(char *, char *, char *);
|
||||
probe function__info(char *, char *, char *, int, char *, int);
|
||||
probe function__args(char *, char *, char *, int, void *, void *, void *,
|
||||
void *, void *, void *);
|
||||
probe function__rval(char *, char *, char *, int, void *, void *);
|
||||
probe function__return(char *, char *, char *);
|
||||
probe object__create__start(char *, char *);
|
||||
probe object__create__done(char *, char *);
|
||||
/* XXX must use unsigned longs here instead of uintptr_t for OS X
|
||||
(Apple radar: 5194316 & 5565198) */
|
||||
probe object__create(char *, char *, unsigned long, int);
|
||||
probe object__finalize(char *, char *, unsigned long);
|
||||
probe execute__start(char *, int);
|
||||
probe execute__done(char *, int);
|
||||
};
|
||||
|
||||
/*
|
||||
#pragma D attributes Unstable/Unstable/Common provider mozilla provider
|
||||
#pragma D attributes Private/Private/Unknown provider mozilla module
|
||||
#pragma D attributes Private/Private/Unknown provider mozilla function
|
||||
#pragma D attributes Unstable/Unstable/Common provider mozilla name
|
||||
#pragma D attributes Unstable/Unstable/Common provider mozilla args
|
||||
*/
|
||||
|
||||
93
samples/DTrace/probes.d
Normal file
93
samples/DTrace/probes.d
Normal file
@@ -0,0 +1,93 @@
|
||||
/* ----------
|
||||
* DTrace probes for PostgreSQL backend
|
||||
*
|
||||
* Copyright (c) 2006-2009, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/probes.d,v 1.11 2009/04/02 20:59:10 momjian Exp $
|
||||
* ----------
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Typedefs used in PostgreSQL.
|
||||
*
|
||||
* NOTE: Do not use system-provided typedefs (e.g. uintptr_t, uint32_t, etc)
|
||||
* in probe definitions, as they cause compilation errors on Mac OS X 10.5.
|
||||
*/
|
||||
#define LocalTransactionId unsigned int
|
||||
#define LWLockId int
|
||||
#define LWLockMode int
|
||||
#define LOCKMODE int
|
||||
#define BlockNumber unsigned int
|
||||
#define Oid unsigned int
|
||||
#define ForkNumber int
|
||||
#define bool char
|
||||
|
||||
provider postgresql {
|
||||
|
||||
probe transaction__start(LocalTransactionId);
|
||||
probe transaction__commit(LocalTransactionId);
|
||||
probe transaction__abort(LocalTransactionId);
|
||||
|
||||
probe lwlock__acquire(LWLockId, LWLockMode);
|
||||
probe lwlock__release(LWLockId);
|
||||
probe lwlock__wait__start(LWLockId, LWLockMode);
|
||||
probe lwlock__wait__done(LWLockId, LWLockMode);
|
||||
probe lwlock__condacquire(LWLockId, LWLockMode);
|
||||
probe lwlock__condacquire__fail(LWLockId, LWLockMode);
|
||||
|
||||
probe lock__wait__start(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE);
|
||||
probe lock__wait__done(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE);
|
||||
|
||||
probe query__parse__start(const char *);
|
||||
probe query__parse__done(const char *);
|
||||
probe query__rewrite__start(const char *);
|
||||
probe query__rewrite__done(const char *);
|
||||
probe query__plan__start();
|
||||
probe query__plan__done();
|
||||
probe query__execute__start();
|
||||
probe query__execute__done();
|
||||
probe query__start(const char *);
|
||||
probe query__done(const char *);
|
||||
probe statement__status(const char *);
|
||||
|
||||
probe sort__start(int, bool, int, int, bool);
|
||||
probe sort__done(bool, long);
|
||||
|
||||
probe buffer__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, bool, bool);
|
||||
probe buffer__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, bool, bool, bool);
|
||||
probe buffer__flush__start(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
probe buffer__flush__done(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
|
||||
probe buffer__checkpoint__start(int);
|
||||
probe buffer__checkpoint__sync__start();
|
||||
probe buffer__checkpoint__done();
|
||||
probe buffer__sync__start(int, int);
|
||||
probe buffer__sync__written(int);
|
||||
probe buffer__sync__done(int, int, int);
|
||||
probe buffer__write__dirty__start(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
probe buffer__write__dirty__done(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
|
||||
probe deadlock__found();
|
||||
|
||||
probe checkpoint__start(int);
|
||||
probe checkpoint__done(int, int, int, int, int);
|
||||
probe clog__checkpoint__start(bool);
|
||||
probe clog__checkpoint__done(bool);
|
||||
probe subtrans__checkpoint__start(bool);
|
||||
probe subtrans__checkpoint__done(bool);
|
||||
probe multixact__checkpoint__start(bool);
|
||||
probe multixact__checkpoint__done(bool);
|
||||
probe twophase__checkpoint__start();
|
||||
probe twophase__checkpoint__done();
|
||||
|
||||
probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int);
|
||||
probe smgr__md__write__start(ForkNumber, BlockNumber, Oid, Oid, Oid);
|
||||
probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int);
|
||||
|
||||
probe xlog__insert(unsigned char, unsigned char);
|
||||
probe xlog__switch();
|
||||
probe wal__buffer__write__dirty__start();
|
||||
probe wal__buffer__write__dirty__done();
|
||||
};
|
||||
44
samples/Eiffel/application.e
Normal file
44
samples/Eiffel/application.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description : "nino application root class"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
APPLICATION
|
||||
|
||||
inherit
|
||||
ARGUMENTS
|
||||
|
||||
HTTP_SERVER_SHARED_CONFIGURATION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Run application.
|
||||
local
|
||||
l_server : HTTP_SERVER
|
||||
l_cfg: HTTP_SERVER_CONFIGURATION
|
||||
l_http_handler : HTTP_HANDLER
|
||||
do
|
||||
create l_cfg.make
|
||||
l_cfg.http_server_port := 9_000
|
||||
l_cfg.document_root := default_document_root
|
||||
set_server_configuration (l_cfg)
|
||||
debug ("nino")
|
||||
l_cfg.set_is_verbose (True)
|
||||
end
|
||||
|
||||
create l_server.make (l_cfg)
|
||||
create {APPLICATION_CONNECTION_HANDLER} l_http_handler.make (l_server)
|
||||
l_server.setup (l_http_handler)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
default_document_root: STRING = "webroot"
|
||||
|
||||
end
|
||||
|
||||
82
samples/Eiffel/book_collection.e
Normal file
82
samples/Eiffel/book_collection.e
Normal file
@@ -0,0 +1,82 @@
|
||||
class
|
||||
BOOK_COLLECTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: STRING_32)
|
||||
-- Create a book collection with `a_name' as `name'.
|
||||
do
|
||||
set_name (a_name)
|
||||
create book_index.make (10)
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING_32
|
||||
-- Name.
|
||||
|
||||
books: LIST [BOOK]
|
||||
-- collection of book.
|
||||
do
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
across
|
||||
book_index as it
|
||||
loop
|
||||
Result.append (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
books_by_author (a_author: STRING_32): LIST [BOOK]
|
||||
-- Books wrote by `a_author' in this collection.
|
||||
do
|
||||
if attached book_index [a_author] as l_result then
|
||||
Result := l_result
|
||||
else
|
||||
create {LINKED_LIST [BOOK]} Result.make
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
add_book (a_book: BOOK)
|
||||
-- Extend collection with `a_book'.
|
||||
local
|
||||
l: detachable LIST [BOOK]
|
||||
do
|
||||
l := book_index.at (a_book.author.name)
|
||||
if l = Void then
|
||||
create {LINKED_LIST [BOOK]} l.make
|
||||
book_index.put (l, a_book.author.name)
|
||||
end
|
||||
l.force (a_book)
|
||||
end
|
||||
|
||||
add_books (book_list: like books)
|
||||
-- Append collection with `book_list'.
|
||||
do
|
||||
across
|
||||
book_list as it
|
||||
loop
|
||||
add_book (it.item)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
book_index: HASH_TABLE [LIST [BOOK], STRING_32]
|
||||
-- Association of author name and its books.
|
||||
|
||||
end -- class BOOK_COLLECTION
|
||||
41
samples/Eiffel/git_checkout_command.e
Normal file
41
samples/Eiffel/git_checkout_command.e
Normal file
@@ -0,0 +1,41 @@
|
||||
note
|
||||
description: "Git checkout command."
|
||||
author: "Olivier Ligot"
|
||||
|
||||
class
|
||||
GIT_CHECKOUT_COMMAND
|
||||
|
||||
inherit
|
||||
GIT_COMMAND
|
||||
|
||||
create
|
||||
make,
|
||||
make_master
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_branch: STRING)
|
||||
-- Checkout the branch `a_branch'.
|
||||
do
|
||||
initialize
|
||||
arguments.force_last (a_branch)
|
||||
branch := a_branch
|
||||
ensure
|
||||
branch_set: branch = a_branch
|
||||
end
|
||||
|
||||
make_master
|
||||
-- Checkout the master branch.
|
||||
do
|
||||
make ("master")
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
branch: STRING
|
||||
-- Branch to checkout
|
||||
|
||||
name: STRING = "checkout"
|
||||
-- Git subcommand name
|
||||
|
||||
end
|
||||
29
samples/Emacs Lisp/.emacs.desktop
Normal file
29
samples/Emacs Lisp/.emacs.desktop
Normal file
@@ -0,0 +1,29 @@
|
||||
;; -*- mode: emacs-lisp; coding: emacs-mule; -*-
|
||||
;; --------------------------------------------------------------------------
|
||||
;; Desktop File for Emacs
|
||||
;; --------------------------------------------------------------------------
|
||||
;; Created Sat Jan 3 12:46:35 2015
|
||||
;; Desktop file format version 206
|
||||
;; Emacs version 24.3.1
|
||||
|
||||
;; Global section:
|
||||
(setq desktop-missing-file-warning nil)
|
||||
(setq tags-file-name nil)
|
||||
(setq tags-table-list nil)
|
||||
(setq search-ring nil)
|
||||
(setq regexp-search-ring nil)
|
||||
(setq register-alist nil)
|
||||
(setq file-name-history nil)
|
||||
|
||||
;; Buffer section -- buffers listed in same order as in buffer list:
|
||||
(desktop-create-buffer 206
|
||||
"/home/foo/bar"
|
||||
"bar"
|
||||
'fundamental-mode
|
||||
nil
|
||||
11572
|
||||
'(11554 nil)
|
||||
nil
|
||||
nil
|
||||
'((buffer-file-coding-system . undecided-unix)))
|
||||
|
||||
1317
samples/Formatted/wksst8110.for
Normal file
1317
samples/Formatted/wksst8110.for
Normal file
File diff suppressed because it is too large
Load Diff
133
samples/Forth/tools.4TH
Normal file
133
samples/Forth/tools.4TH
Normal file
@@ -0,0 +1,133 @@
|
||||
\ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
|
||||
|
||||
( Tools words. )
|
||||
|
||||
: .s ( -- )
|
||||
[char] < emit depth (.) ." > "
|
||||
'SP @ >r r@ depth 1- cells +
|
||||
begin
|
||||
dup r@ <>
|
||||
while
|
||||
dup @ .
|
||||
/cell -
|
||||
repeat r> 2drop ;
|
||||
|
||||
: ? @ . ;
|
||||
|
||||
: c? c@ . ;
|
||||
|
||||
: dump bounds do i ? /cell +loop cr ;
|
||||
|
||||
: cdump bounds do i c? loop cr ;
|
||||
|
||||
: again postpone branch , ; immediate
|
||||
|
||||
: see-find ( caddr -- end xt )
|
||||
>r here lastxt @
|
||||
begin
|
||||
dup 0= abort" Undefined word"
|
||||
dup r@ word= if r> drop exit then
|
||||
nip dup >nextxt
|
||||
again ;
|
||||
|
||||
: cabs ( char -- |char| ) dup 127 > if 256 swap - then ;
|
||||
|
||||
: xt. ( xt -- )
|
||||
( >name ) count cabs type ;
|
||||
|
||||
: xt? ( xt -- flag )
|
||||
>r lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
dup r@ = if r> 2drop -1 exit then
|
||||
>nextxt
|
||||
repeat r> drop 0 ;
|
||||
|
||||
: disassemble ( x -- )
|
||||
dup xt? if
|
||||
( >name ) count
|
||||
dup 127 > if ." postpone " then
|
||||
cabs type
|
||||
else
|
||||
.
|
||||
then ;
|
||||
|
||||
: .addr dup . ;
|
||||
|
||||
: see-line ( addr -- )
|
||||
cr ." ( " .addr ." ) " @ disassemble ;
|
||||
|
||||
: see-word ( end xt -- )
|
||||
>r ." : " r@ xt.
|
||||
r@ >body do i see-line /cell +loop
|
||||
." ;" r> c@ 127 > if ." immediate" then ;
|
||||
|
||||
: see bl word see-find see-word cr ;
|
||||
|
||||
: #body bl word see-find >body - ;
|
||||
|
||||
: type-word ( end xt -- flag )
|
||||
xt. space drop 0 ;
|
||||
|
||||
: traverse-dictionary ( in.. xt -- out.. )
|
||||
\ xt execution: ( in.. end xt2 -- in.. 0 | in.. end xt2 -- out.. true )
|
||||
>r here lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
r> 2dup >r >r execute
|
||||
if r> r> 2drop exit then
|
||||
r> dup >nextxt
|
||||
repeat r> 2drop ;
|
||||
|
||||
: words ( -- )
|
||||
['] type-word traverse-dictionary cr ;
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Tools extension words. )
|
||||
|
||||
\ ;code
|
||||
|
||||
\ assembler
|
||||
|
||||
\ in kernel: bye
|
||||
|
||||
\ code
|
||||
|
||||
\ cs-pick
|
||||
|
||||
\ cs-roll
|
||||
|
||||
\ editor
|
||||
|
||||
: forget ' dup >nextxt lastxt ! 'here ! reveal ;
|
||||
|
||||
\ Kernel: state
|
||||
|
||||
\ [else]
|
||||
|
||||
\ [if]
|
||||
|
||||
\ [then]
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Forth2012 tools extension words. )
|
||||
|
||||
\ TODO: n>r
|
||||
|
||||
\ TODO: nr>
|
||||
|
||||
\ TODO: synonym
|
||||
|
||||
: [undefined] bl-word find nip 0= ; immediate
|
||||
|
||||
: [defined] postpone [undefined] invert ; immediate
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
: @+ ( addr -- addr+/cell x ) dup cell+ swap @ ;
|
||||
|
||||
: !+ ( x addr -- addr+/cell ) tuck ! cell+ ;
|
||||
|
||||
: -rot swap >r swap r> ;
|
||||
161
samples/GAP/bugfix.tst
Normal file
161
samples/GAP/bugfix.tst
Normal file
@@ -0,0 +1,161 @@
|
||||
gap> START_TEST("Test for various former bugs");
|
||||
|
||||
|
||||
gap> # The following used to trigger an error starting with:
|
||||
gap> # "SolutionMat: matrix and vector incompatible called from"
|
||||
gap> K:=AbelianPcpGroup([3,3,3]);;
|
||||
gap> A:=Subgroup(K,[K.1]);;
|
||||
gap> cr:=CRRecordBySubgroup(K,A);;
|
||||
gap> ExtensionsCR(cr);;
|
||||
|
||||
|
||||
# Comparing homomorphisms used to be broken
|
||||
gap> K:=AbelianPcpGroup(1,[3]);;
|
||||
gap> hom1:=GroupHomomorphismByImages(K,K,[K.1],[K.1]);;
|
||||
gap> hom2:=GroupHomomorphismByImages(K,K,[K.1^2],[K.1^2]);;
|
||||
gap> hom1=hom2;
|
||||
true
|
||||
gap> hom1=IdentityMapping(K);
|
||||
true
|
||||
gap> hom2=IdentityMapping(K);
|
||||
true
|
||||
|
||||
|
||||
gap> # The following incorrectly triggered an error at some point
|
||||
gap> IsTorsionFree(ExamplesOfSomePcpGroups(5));
|
||||
true
|
||||
|
||||
|
||||
gap> # Verify IsGeneratorsOfMagmaWithInverses warnings are silenced
|
||||
gap> IsGeneratorsOfMagmaWithInverses(GeneratorsOfGroup(ExamplesOfSomePcpGroups(5)));
|
||||
true
|
||||
|
||||
|
||||
gap> # Check for a bug reported 2012-01-19 by Robert Morse
|
||||
gap> g := PcGroupToPcpGroup(SmallGroup(48,1));
|
||||
Pcp-group with orders [ 2, 2, 2, 2, 3 ]
|
||||
gap> # The next two commands used to trigger errors
|
||||
gap> NonAbelianTensorSquare(Centre(g));
|
||||
Pcp-group with orders [ 8 ]
|
||||
gap> NonAbelianExteriorSquare(Centre(g));
|
||||
Pcp-group with orders [ ]
|
||||
|
||||
|
||||
gap> # Check for a bug reported 2012-01-19 by Robert Morse
|
||||
gap> F := FreeGroup("x","y");
|
||||
<free group on the generators [ x, y ]>
|
||||
gap> x := F.1;; y := F.2;;
|
||||
gap> G := F/[x^2/y^24, y^24, y^x/y^23];
|
||||
<fp group on the generators [ x, y ]>
|
||||
gap> iso := IsomorphismPcGroup(G);
|
||||
[ x, y ] -> [ f1, f2*f5 ]
|
||||
gap> iso1 := IsomorphismPcpGroup(Image(iso));
|
||||
[ f1, f2, f3, f4, f5 ] -> [ g1, g2, g3, g4, g5 ]
|
||||
gap> G := Image(iso*iso1);
|
||||
Pcp-group with orders [ 2, 2, 2, 2, 3 ]
|
||||
gap> # The next command used to trigger an error
|
||||
gap> NonAbelianTensorSquare(Image(iso*iso1));
|
||||
Pcp-group with orders [ 2, 2, 3, 2, 2, 2, 2 ]
|
||||
|
||||
|
||||
gap> # The problem with the previous example is/was that Igs(G)
|
||||
gap> # is set to a non-standard value:
|
||||
gap> Igs(G);
|
||||
[ g1, g2*g5, g3*g4*g5^2, g4*g5, g5 ]
|
||||
gap> # Unfortunately, it seems that a lot of code that
|
||||
gap> # really should be using Ngs or Cgs is using Igs incorrectly.
|
||||
gap> # For example, direct products could return *invalid* embeddings:
|
||||
gap> D := DirectProduct(G, G);
|
||||
Pcp-group with orders [ 2, 2, 2, 2, 3, 2, 2, 2, 2, 3 ]
|
||||
gap> hom:=Embedding(D,1);;
|
||||
gap> mapi:=MappingGeneratorsImages(hom);;
|
||||
gap> GroupHomomorphismByImages(Source(hom),Range(hom),mapi[1],mapi[2]) <> fail;
|
||||
true
|
||||
gap> hom:=Projection(D,1);;
|
||||
gap> mapi:=MappingGeneratorsImages(hom);;
|
||||
gap> GroupHomomorphismByImages(Source(hom),Range(hom),mapi[1],mapi[2]) <> fail;
|
||||
true
|
||||
|
||||
|
||||
gap> # Check for bug computing Schur extension of infinite cyclic groups,
|
||||
gap> # found by Max Horn 2012-05-25
|
||||
gap> G:=AbelianPcpGroup(1,[0]);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> # The next command used to trigger an error
|
||||
gap> SchurExtension(G);
|
||||
Pcp-group with orders [ 0 ]
|
||||
|
||||
|
||||
gap> # Check for bug computing Schur extensions of subgroups, found by MH 2012-05-25.
|
||||
gap> G:=HeisenbergPcpGroup(2);
|
||||
Pcp-group with orders [ 0, 0, 0, 0, 0 ]
|
||||
gap> H:=Subgroup(G,[G.2^3*G.3^2, G.1^9]);
|
||||
Pcp-group with orders [ 0, 0, 0 ]
|
||||
gap> # The next command used to trigger an error
|
||||
gap> SchurExtension(H);
|
||||
Pcp-group with orders [ 0, 0, 0, 0, 0, 0 ]
|
||||
|
||||
|
||||
gap> # Check for bug computing Schur extensions of subgroups, found by MH 2012-05-25.
|
||||
gap> G:=HeisenbergPcpGroup(2);
|
||||
Pcp-group with orders [ 0, 0, 0, 0, 0 ]
|
||||
gap> H:=Subgroup(G,[G.1, G.2]);
|
||||
Pcp-group with orders [ 0, 0 ]
|
||||
gap> # The next command used to trigger an error
|
||||
gap> SchurExtension(H);
|
||||
Pcp-group with orders [ 0, 0, 0 ]
|
||||
|
||||
|
||||
gap> # Check for bug computing normalizer of two subgroups, found by MH 2012-05-30.
|
||||
gap> # The problem was caused by incorrect resp. overly restrictive use of Parent().
|
||||
gap> G:=HeisenbergPcpGroup(2);
|
||||
Pcp-group with orders [ 0, 0, 0, 0, 0 ]
|
||||
gap> A:=Subgroup(Subgroup(G,[G.2,G.3,G.4,G.5]), [G.3]);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> B:=Subgroup(Subgroup(G,[G.1,G.4,G.5]), [G.4]);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> Normalizer(A,B);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> # The following used to trigger the error "arguments must have a common parent group"
|
||||
gap> Normalizer(B,A);
|
||||
Pcp-group with orders [ 0 ]
|
||||
|
||||
|
||||
gap> # In polycyclic 2.9 and 2.10, the code for 2-cohomology computations was broken.
|
||||
gap> G := UnitriangularPcpGroup(3,0);
|
||||
Pcp-group with orders [ 0, 0, 0 ]
|
||||
gap> mats := G!.mats;
|
||||
[ [ [ 1, 1, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ],
|
||||
[ [ 1, 0, 0 ], [ 0, 1, 1 ], [ 0, 0, 1 ] ],
|
||||
[ [ 1, 0, 1 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] ]
|
||||
gap> C := CRRecordByMats(G,mats);;
|
||||
gap> cc := TwoCohomologyCR(C);;
|
||||
gap> cc.factor.rels;
|
||||
[ 2, 0, 0 ]
|
||||
gap> c := cc.factor.prei[2];
|
||||
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 1 ]
|
||||
gap> cc.gcb;
|
||||
[ [ 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1 ],
|
||||
[ -1, 0, 1, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1 ] ]
|
||||
gap> cc.gcc;
|
||||
[ [ 1, 0, 0, 0, 0, -2, -1, 0, 1, 1, -1, -1, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 1, 0, 0, -2, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0 ],
|
||||
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 1 ],
|
||||
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1 ] ]
|
||||
|
||||
|
||||
gap> # LowerCentralSeriesOfGroup for non-nilpotent pcp-groups used to trigger
|
||||
gap> # an infinite recursion
|
||||
gap> G := PcGroupToPcpGroup(SmallGroup(6,1));
|
||||
Pcp-group with orders [ 2, 3 ]
|
||||
gap> LowerCentralSeriesOfGroup(G);
|
||||
[ Pcp-group with orders [ 2, 3 ], Pcp-group with orders [ 3 ] ]
|
||||
|
||||
|
||||
gap> STOP_TEST( "bugfix.tst", 10000000);
|
||||
21
samples/GAP/factor.tst
Normal file
21
samples/GAP/factor.tst
Normal file
@@ -0,0 +1,21 @@
|
||||
gap> START_TEST("Test of factor groups and natural homomorphisms");
|
||||
|
||||
gap> G:=HeisenbergPcpGroup(2);
|
||||
Pcp-group with orders [ 0, 0, 0, 0, 0 ]
|
||||
|
||||
gap> H:=Subgroup(G,[G.2,G.3,G.4,G.5]);
|
||||
gap> K:=G/H;
|
||||
gap> NaturalHomomorphism(K);
|
||||
|
||||
gap> A:=Subgroup(H, [G.3]);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> B:=Subgroup(Subgroup(G,[G.1,G.4,G.5]), [G.4]);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> Normalizer(A,B);
|
||||
Pcp-group with orders [ 0 ]
|
||||
gap> # The following used to trigger the error "arguments must have a common parent group"
|
||||
gap> Normalizer(B,A);
|
||||
Pcp-group with orders [ 0 ]
|
||||
|
||||
|
||||
gap> STOP_TEST( "factor.tst", 10000000);
|
||||
1157
samples/Go/api.pb.go
Normal file
1157
samples/Go/api.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
71
samples/INI/MouseKeyboard.pro
Normal file
71
samples/INI/MouseKeyboard.pro
Normal file
@@ -0,0 +1,71 @@
|
||||
update=Sun 15 Feb 2015 01:10:10 PM EST
|
||||
last_client=eeschema
|
||||
[pcbnew]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
LastNetListRead=
|
||||
UseCmpFile=1
|
||||
PadDrill=0.6
|
||||
PadDrillOvalY=0.6
|
||||
PadSizeH=1.5
|
||||
PadSizeV=1.5
|
||||
PcbTextSizeV=1.5
|
||||
PcbTextSizeH=1.5
|
||||
PcbTextThickness=0.3
|
||||
ModuleTextSizeV=1
|
||||
ModuleTextSizeH=1
|
||||
ModuleTextSizeThickness=0.15
|
||||
SolderMaskClearance=0
|
||||
SolderMaskMinWidth=0
|
||||
DrawSegmentWidth=0.2
|
||||
BoardOutlineThickness=0.09999999999999999
|
||||
ModuleOutlineThickness=0.15
|
||||
[pcbnew/libraries]
|
||||
LibDir=
|
||||
[general]
|
||||
version=1
|
||||
[eeschema]
|
||||
version=1
|
||||
PageLayoutDescrFile=
|
||||
SubpartIdSeparator=0
|
||||
SubpartFirstId=65
|
||||
LibDir=/home/hschmale/KiCad/LibMods-3rdParty
|
||||
NetFmtName=
|
||||
RptD_X=0
|
||||
RptD_Y=100
|
||||
RptLab=1
|
||||
LabSize=60
|
||||
[eeschema/libraries]
|
||||
LibName1=power
|
||||
LibName2=device
|
||||
LibName3=transistors
|
||||
LibName4=conn
|
||||
LibName5=linear
|
||||
LibName6=regul
|
||||
LibName7=74xx
|
||||
LibName8=cmos4000
|
||||
LibName9=adc-dac
|
||||
LibName10=memory
|
||||
LibName11=xilinx
|
||||
LibName12=special
|
||||
LibName13=microcontrollers
|
||||
LibName14=dsp
|
||||
LibName15=microchip
|
||||
LibName16=analog_switches
|
||||
LibName17=motorola
|
||||
LibName18=texas
|
||||
LibName19=intel
|
||||
LibName20=audio
|
||||
LibName21=interface
|
||||
LibName22=digital-audio
|
||||
LibName23=philips
|
||||
LibName24=display
|
||||
LibName25=cypress
|
||||
LibName26=siliconi
|
||||
LibName27=opto
|
||||
LibName28=atmel
|
||||
LibName29=contrib
|
||||
LibName30=valves
|
||||
LibName31=arduino_shieldsNCL
|
||||
LibName32=con-usb-2
|
||||
LibName33=2axispotwselect
|
||||
69
samples/Inno Setup/expat.iss
Normal file
69
samples/Inno Setup/expat.iss
Normal file
@@ -0,0 +1,69 @@
|
||||
; Basic setup script for the Inno Setup installer builder. For more
|
||||
; information on the free installer builder, see www.jrsoftware.org.
|
||||
;
|
||||
; This script was contributed by Tim Peters.
|
||||
; It was designed for Inno Setup 2.0.19 but works with later versions as well.
|
||||
|
||||
[Setup]
|
||||
AppName=Expat
|
||||
AppId=expat
|
||||
AppVersion=2.1.0
|
||||
AppVerName=Expat 2.1.0
|
||||
AppCopyright=Copyright 1998-2012 Thai Open Source Software Center, Clark Cooper, and the Expat maintainers
|
||||
AppPublisher=The Expat Developers
|
||||
AppPublisherURL=http://www.libexpat.org/
|
||||
AppSupportURL=http://www.libexpat.org/
|
||||
AppUpdatesURL=http://www.libexpat.org/
|
||||
UninstallDisplayName=Expat XML Parser 2.1.0
|
||||
VersionInfoVersion=2.1.0
|
||||
|
||||
DefaultDirName={pf}\Expat 2.1.0
|
||||
UninstallFilesDir={app}\Uninstall
|
||||
|
||||
Compression=lzma
|
||||
SolidCompression=yes
|
||||
SourceDir=..
|
||||
OutputDir=win32
|
||||
DisableStartupPrompt=yes
|
||||
AllowNoIcons=yes
|
||||
DisableProgramGroupPage=yes
|
||||
DisableReadyPage=yes
|
||||
|
||||
[Files]
|
||||
Flags: ignoreversion; Source: win32\bin\Release\xmlwf.exe; DestDir: "{app}\Bin"
|
||||
Flags: ignoreversion; Source: win32\MANIFEST.txt; DestDir: "{app}"
|
||||
Flags: ignoreversion; Source: Changes; DestDir: "{app}"; DestName: Changes.txt
|
||||
Flags: ignoreversion; Source: COPYING; DestDir: "{app}"; DestName: COPYING.txt
|
||||
Flags: ignoreversion; Source: README; DestDir: "{app}"; DestName: README.txt
|
||||
Flags: ignoreversion; Source: doc\*.html; DestDir: "{app}\Doc"
|
||||
Flags: ignoreversion; Source: doc\*.css; DestDir: "{app}\Doc"
|
||||
Flags: ignoreversion; Source: doc\*.png; DestDir: "{app}\Doc"
|
||||
Flags: ignoreversion; Source: win32\bin\Release\*.dll; DestDir: "{app}\Bin"
|
||||
Flags: ignoreversion; Source: win32\bin\Release\*.lib; DestDir: "{app}\Bin"
|
||||
Flags: ignoreversion; Source: expat.dsw; DestDir: "{app}\Source"
|
||||
Flags: ignoreversion; Source: win32\README.txt; DestDir: "{app}\Source"
|
||||
Flags: ignoreversion; Source: bcb5\*.bp*; DestDir: "{app}\Source\bcb5"
|
||||
Flags: ignoreversion; Source: bcb5\*.mak; DestDir: "{app}\Source\bcb5"
|
||||
Flags: ignoreversion; Source: bcb5\*.def; DestDir: "{app}\Source\bcb5"
|
||||
Flags: ignoreversion; Source: bcb5\*.txt; DestDir: "{app}\Source\bcb5"
|
||||
Flags: ignoreversion; Source: bcb5\*.bat; DestDir: "{app}\Source\bcb5"
|
||||
Flags: ignoreversion; Source: lib\*.c; DestDir: "{app}\Source\lib"
|
||||
Flags: ignoreversion; Source: lib\*.h; DestDir: "{app}\Source\lib"
|
||||
Flags: ignoreversion; Source: lib\*.def; DestDir: "{app}\Source\lib"
|
||||
Flags: ignoreversion; Source: lib\*.dsp; DestDir: "{app}\Source\lib"
|
||||
Flags: ignoreversion; Source: examples\*.c; DestDir: "{app}\Source\examples"
|
||||
Flags: ignoreversion; Source: examples\*.dsp; DestDir: "{app}\Source\examples"
|
||||
Flags: ignoreversion; Source: tests\*.c; DestDir: "{app}\Source\tests"
|
||||
Flags: ignoreversion; Source: tests\*.cpp; DestDir: "{app}\Source\tests"
|
||||
Flags: ignoreversion; Source: tests\*.h; DestDir: "{app}\Source\tests"
|
||||
Flags: ignoreversion; Source: tests\README.txt; DestDir: "{app}\Source\tests"
|
||||
Flags: ignoreversion; Source: tests\benchmark\*.c; DestDir: "{app}\Source\tests\benchmark"
|
||||
Flags: ignoreversion; Source: tests\benchmark\*.ds*; DestDir: "{app}\Source\tests\benchmark"
|
||||
Flags: ignoreversion; Source: tests\benchmark\README.txt; DestDir: "{app}\Source\tests\benchmark"
|
||||
Flags: ignoreversion; Source: xmlwf\*.c*; DestDir: "{app}\Source\xmlwf"
|
||||
Flags: ignoreversion; Source: xmlwf\*.h; DestDir: "{app}\Source\xmlwf"
|
||||
Flags: ignoreversion; Source: xmlwf\*.dsp; DestDir: "{app}\Source\xmlwf"
|
||||
|
||||
[Messages]
|
||||
WelcomeLabel1=Welcome to the Expat XML Parser Setup Wizard
|
||||
WelcomeLabel2=This will install [name/ver] on your computer.%n%nExpat is an XML parser with a C-language API, and is primarily made available to allow developers to build applications which use XML using a portable API and fast implementation.%n%nIt is strongly recommended that you close all other applications you have running before continuing. This will help prevent any conflicts during the installation process.
|
||||
73
samples/J/stwij.ijs
Normal file
73
samples/J/stwij.ijs
Normal file
@@ -0,0 +1,73 @@
|
||||
NB. From "Continuing to write in J".
|
||||
NB. See http://www.jsoftware.com/help/jforc/continuing_to_write_in_j.htm
|
||||
|
||||
empno=: 316 317 319 320
|
||||
payrate=: 60 42 44 54
|
||||
billrate=: 120 90 90 108
|
||||
clientlist=: 10011 10012 10025
|
||||
emp_client=: 10012 10025 10012 10025
|
||||
hoursworked=: 4 31 $ 8 0 3 10 9 8 8 9 4 0 8 7 10 10 12 9 0 6 8 9 9 9 0 0 10 11 9 7 10 2 0 8 0 0 9 9 8 9 10 0 0 8 8 10 7 10 0 0 7 8 9 8 9 0 4 9 8 9 8 9 0 0 5 0 0 8 9 9 9 9 0 0 8 7 0 0 9 0 2 10 10 9 11 8 0 0 8 9 10 8 9 0 0 9 0 0 9 10 8 6 6 8 0 9 8 10 6 9 7 0 6 8 8 8 9 0 5 8 9 8 8 12 0 0
|
||||
|
||||
NB. Finds the number of hours each employee worked in the given month.
|
||||
emphours=: 3 : '+/"1 hoursworked'
|
||||
|
||||
NB. Determines the wages earned by each employee in the given month.
|
||||
empearnings=: 3 : 'payrate * +/"1 hoursworked'
|
||||
|
||||
NB. Determines the profit brought in by each employee.
|
||||
empprofit=: 3 : 0
|
||||
(billrate - payrate) * +/"1 hoursworked
|
||||
)
|
||||
|
||||
NB. Returns the amount to bill a given client.
|
||||
billclient=: 3 : 0
|
||||
mask=. emp_client = y
|
||||
+/ (mask # billrate) * +/"1 mask # hoursworked
|
||||
)
|
||||
|
||||
NB. Finds for each day of the month the employee who billed the most hours.
|
||||
dailydrudge=: 3 : 0
|
||||
((|: hoursworked) i."1 0 >./ hoursworked) { empno
|
||||
)
|
||||
|
||||
NB. Returns the employees, in descending order of the profit brought in by each.
|
||||
producers=: 3 : 'empno \: empprofit 0'
|
||||
|
||||
NB. Returns the clients, in descending order of the profit generated by each.
|
||||
custbyprofit=: 3 : 0
|
||||
clientlist \: +/ (clientlist ="1 0 emp_client) * empprofit 0
|
||||
)
|
||||
|
||||
NB. Calculates withholding tax on each employee's earnings.
|
||||
renderuntocaesar=: 3 : 0
|
||||
bktmin=. 0 6000 10000 20000 NB. Four brackets, 0..6000..10000..20000.._
|
||||
bktrate=. 0.05 0.10 0.20 0.30
|
||||
bktearns=. 0 >. ((1 |.!._ bktmin) <."1 0 empearnings'') -"1 bktmin
|
||||
+/"1 bktrate *"1 bktearns
|
||||
)
|
||||
|
||||
NB. Main
|
||||
|
||||
echo 'Problem 1'
|
||||
echo emphours''
|
||||
|
||||
echo 'Problem 2'
|
||||
echo empearnings''
|
||||
|
||||
echo 'Problem 3'
|
||||
echo empprofit''
|
||||
|
||||
echo 'Problem 4'
|
||||
echo billclient 10025
|
||||
|
||||
echo 'Problem 5'
|
||||
echo dailydrudge''
|
||||
|
||||
echo 'Problem 6'
|
||||
echo producers''
|
||||
|
||||
echo 'Problem 7'
|
||||
echo custbyprofit''
|
||||
|
||||
echo 'Problem 8'
|
||||
echo 0j2 ": renderuntocaesar''
|
||||
75
samples/Lean/binary.lean
Normal file
75
samples/Lean/binary.lean
Normal file
@@ -0,0 +1,75 @@
|
||||
/-
|
||||
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Module: algebra.binary
|
||||
Authors: Leonardo de Moura, Jeremy Avigad
|
||||
|
||||
General properties of binary operations.
|
||||
-/
|
||||
|
||||
import logic.eq
|
||||
open eq.ops
|
||||
|
||||
namespace binary
|
||||
section
|
||||
variable {A : Type}
|
||||
variables (op₁ : A → A → A) (inv : A → A) (one : A)
|
||||
|
||||
local notation a * b := op₁ a b
|
||||
local notation a ⁻¹ := inv a
|
||||
local notation 1 := one
|
||||
|
||||
definition commutative := ∀a b, a * b = b * a
|
||||
definition associative := ∀a b c, (a * b) * c = a * (b * c)
|
||||
definition left_identity := ∀a, 1 * a = a
|
||||
definition right_identity := ∀a, a * 1 = a
|
||||
definition left_inverse := ∀a, a⁻¹ * a = 1
|
||||
definition right_inverse := ∀a, a * a⁻¹ = 1
|
||||
definition left_cancelative := ∀a b c, a * b = a * c → b = c
|
||||
definition right_cancelative := ∀a b c, a * b = c * b → a = c
|
||||
|
||||
definition inv_op_cancel_left := ∀a b, a⁻¹ * (a * b) = b
|
||||
definition op_inv_cancel_left := ∀a b, a * (a⁻¹ * b) = b
|
||||
definition inv_op_cancel_right := ∀a b, a * b⁻¹ * b = a
|
||||
definition op_inv_cancel_right := ∀a b, a * b * b⁻¹ = a
|
||||
|
||||
variable (op₂ : A → A → A)
|
||||
|
||||
local notation a + b := op₂ a b
|
||||
|
||||
definition left_distributive := ∀a b c, a * (b + c) = a * b + a * c
|
||||
definition right_distributive := ∀a b c, (a + b) * c = a * c + b * c
|
||||
end
|
||||
|
||||
context
|
||||
variable {A : Type}
|
||||
variable {f : A → A → A}
|
||||
variable H_comm : commutative f
|
||||
variable H_assoc : associative f
|
||||
infixl `*` := f
|
||||
theorem left_comm : ∀a b c, a*(b*c) = b*(a*c) :=
|
||||
take a b c, calc
|
||||
a*(b*c) = (a*b)*c : H_assoc
|
||||
... = (b*a)*c : H_comm
|
||||
... = b*(a*c) : H_assoc
|
||||
|
||||
theorem right_comm : ∀a b c, (a*b)*c = (a*c)*b :=
|
||||
take a b c, calc
|
||||
(a*b)*c = a*(b*c) : H_assoc
|
||||
... = a*(c*b) : H_comm
|
||||
... = (a*c)*b : H_assoc
|
||||
end
|
||||
|
||||
context
|
||||
variable {A : Type}
|
||||
variable {f : A → A → A}
|
||||
variable H_assoc : associative f
|
||||
infixl `*` := f
|
||||
theorem assoc4helper (a b c d) : (a*b)*(c*d) = a*((b*c)*d) :=
|
||||
calc
|
||||
(a*b)*(c*d) = a*(b*(c*d)) : H_assoc
|
||||
... = a*((b*c)*d) : H_assoc
|
||||
end
|
||||
|
||||
end binary
|
||||
70
samples/Lean/set.hlean
Normal file
70
samples/Lean/set.hlean
Normal file
@@ -0,0 +1,70 @@
|
||||
-- Copyright (c) 2015 Jakob von Raumer. All rights reserved.
|
||||
-- Released under Apache 2.0 license as described in the file LICENSE.
|
||||
-- Authors: Jakob von Raumer
|
||||
-- Category of sets
|
||||
|
||||
import .basic types.pi trunc
|
||||
|
||||
open truncation sigma sigma.ops pi function eq morphism precategory
|
||||
open equiv
|
||||
|
||||
namespace precategory
|
||||
|
||||
universe variable l
|
||||
|
||||
definition set_precategory : precategory.{l+1 l} (Σ (A : Type.{l}), is_hset A) :=
|
||||
begin
|
||||
fapply precategory.mk.{l+1 l},
|
||||
intros, apply (a.1 → a_1.1),
|
||||
intros, apply trunc_pi, intros, apply b.2,
|
||||
intros, intro x, exact (a_1 (a_2 x)),
|
||||
intros, exact (λ (x : a.1), x),
|
||||
intros, apply funext.path_pi, intro x, apply idp,
|
||||
intros, apply funext.path_pi, intro x, apply idp,
|
||||
intros, apply funext.path_pi, intro x, apply idp,
|
||||
end
|
||||
|
||||
end precategory
|
||||
|
||||
namespace category
|
||||
|
||||
universe variable l
|
||||
local attribute precategory.set_precategory.{l+1 l} [instance]
|
||||
|
||||
definition set_category_equiv_iso (a b : (Σ (A : Type.{l}), is_hset A))
|
||||
: (a ≅ b) = (a.1 ≃ b.1) :=
|
||||
/-begin
|
||||
apply ua, fapply equiv.mk,
|
||||
intro H,
|
||||
apply (isomorphic.rec_on H), intros (H1, H2),
|
||||
apply (is_iso.rec_on H2), intros (H3, H4, H5),
|
||||
fapply equiv.mk,
|
||||
apply (isomorphic.rec_on H), intros (H1, H2),
|
||||
exact H1,
|
||||
fapply is_equiv.adjointify, exact H3,
|
||||
exact sorry,
|
||||
exact sorry,
|
||||
end-/ sorry
|
||||
|
||||
definition set_category : category.{l+1 l} (Σ (A : Type.{l}), is_hset A) :=
|
||||
/-begin
|
||||
assert (C : precategory.{l+1 l} (Σ (A : Type.{l}), is_hset A)),
|
||||
apply precategory.set_precategory,
|
||||
apply category.mk,
|
||||
assert (p : (λ A B p, (set_category_equiv_iso A B) ▹ iso_of_path p) = (λ A B p, @equiv_path A.1 B.1 p)),
|
||||
apply is_equiv.adjointify,
|
||||
intros,
|
||||
apply (isomorphic.rec_on a_1), intros (iso', is_iso'),
|
||||
apply (is_iso.rec_on is_iso'), intros (f', f'sect, f'retr),
|
||||
fapply sigma.path,
|
||||
apply ua, fapply equiv.mk, exact iso',
|
||||
fapply is_equiv.adjointify,
|
||||
exact f',
|
||||
intros, apply (f'retr ▹ _),
|
||||
intros, apply (f'sect ▹ _),
|
||||
apply (@is_hprop.elim),
|
||||
apply is_trunc_is_hprop,
|
||||
intros,
|
||||
end -/ sorry
|
||||
|
||||
end category
|
||||
278
samples/MUF/39.m
Normal file
278
samples/MUF/39.m
Normal file
@@ -0,0 +1,278 @@
|
||||
$include $lib/strings
|
||||
$include $lib/match
|
||||
lvar check-obj-addr
|
||||
|
||||
: check-next-loop (d -- )
|
||||
dup not if pop exit then
|
||||
dup exit? over thing? or
|
||||
me @ 3 pick .controls and if
|
||||
dup check-obj-addr @ execute
|
||||
then
|
||||
next check-next-loop
|
||||
;
|
||||
|
||||
: check-contents (d -- )
|
||||
contents check-next-loop
|
||||
;
|
||||
|
||||
: check-exits (d -- )
|
||||
exits check-next-loop
|
||||
;
|
||||
|
||||
: exec-err (d mtypestr warnstr -- )
|
||||
"On " 4 rotate unparseobj strcat
|
||||
", in it's " strcat rot strcat
|
||||
", " strcat swap strcat .tell
|
||||
;
|
||||
|
||||
: can-linkto? (player object -- i)
|
||||
dup "link_ok" flag? if pop pop 1 exit then
|
||||
.controls
|
||||
;
|
||||
|
||||
: check-exec (d mtype execstr -- )
|
||||
dup "@" 1 strncmp if pop pop pop exit then
|
||||
1 strcut swap pop
|
||||
" " .split pop
|
||||
dup "$" 1 strncmp not if
|
||||
dup match ok? not if
|
||||
" is not a known registered program." strcat
|
||||
exec-err exit
|
||||
then
|
||||
dup match program? not if
|
||||
" is not a program." strcat
|
||||
exec-err exit
|
||||
then
|
||||
3 pick owner over match can-linkto? not if
|
||||
" is not Link_OK." strcat
|
||||
exec-err exit
|
||||
then
|
||||
else
|
||||
dup number? not if
|
||||
" is not a program dbref." strcat
|
||||
"@" swap strcat exec-err exit
|
||||
then
|
||||
dup atoi dbref ok? not if
|
||||
" is not a valid program reference." strcat
|
||||
"@" swap strcat exec-err exit
|
||||
then
|
||||
dup atoi dbref program? not if
|
||||
" is not a valid program reference." strcat
|
||||
"@" swap strcat exec-err exit
|
||||
then
|
||||
3 pick owner over atoi dbref can-linkto? not if
|
||||
" is not Link_OK." strcat
|
||||
"@" swap strcat exec-err exit
|
||||
then
|
||||
then
|
||||
pop pop pop
|
||||
;
|
||||
|
||||
|
||||
: missing-err ( d s -- )
|
||||
swap unparseobj
|
||||
" is missing an "
|
||||
strcat swap strcat
|
||||
" message." strcat .tell
|
||||
;
|
||||
|
||||
: colon-err ( d s -- )
|
||||
swap unparseobj
|
||||
" has an unnecesary ':' at the start of its "
|
||||
strcat swap strcat
|
||||
" message." strcat .tell
|
||||
;
|
||||
|
||||
: check-desc (d -- )
|
||||
dup desc not if
|
||||
"@description" missing-err
|
||||
else
|
||||
"@description" over
|
||||
desc check-exec
|
||||
then
|
||||
;
|
||||
|
||||
: check-succ (d -- )
|
||||
dup succ not if
|
||||
"@success" missing-err
|
||||
else
|
||||
"@success" over
|
||||
succ check-exec
|
||||
then
|
||||
;
|
||||
|
||||
: check-fail (d -- )
|
||||
dup fail not if
|
||||
"@fail" missing-err
|
||||
else
|
||||
"@fail" over
|
||||
fail check-exec
|
||||
then
|
||||
;
|
||||
|
||||
: check-drop (d -- )
|
||||
dup drop not if
|
||||
"@drop" missing-err
|
||||
else
|
||||
"@drop" over
|
||||
drop check-exec
|
||||
then
|
||||
;
|
||||
|
||||
: check-osucc (d -- )
|
||||
dup osucc not if
|
||||
"@osuccess" missing-err
|
||||
else
|
||||
dup osucc ":" 1 strncmp not if
|
||||
"@osuccess" colon-err
|
||||
else pop
|
||||
then
|
||||
then
|
||||
;
|
||||
|
||||
: check-ofail (d -- )
|
||||
dup ofail not if
|
||||
"@ofail" missing-err
|
||||
else
|
||||
dup ofail ":" 1 strncmp not if
|
||||
"@ofail" colon-err
|
||||
else pop
|
||||
then
|
||||
then
|
||||
;
|
||||
|
||||
: check-odrop (d -- )
|
||||
dup odrop not if
|
||||
"@odrop" missing-err
|
||||
else
|
||||
dup odrop ":" 1 strncmp not if
|
||||
"@odrop" colon-err
|
||||
else pop
|
||||
then
|
||||
then
|
||||
;
|
||||
|
||||
|
||||
$define islocked? (d -- i) getlockstr "*UNLOCKED*" stringcmp $enddef
|
||||
|
||||
: islocked_always? (d -- i)
|
||||
getlockstr dup "#0" stringcmp not if pop 1 exit then
|
||||
dup "#" STRsplit swap pop atoi
|
||||
"#" swap intostr strcat
|
||||
(lockstr "#dbref")
|
||||
dup "&!" over strcat strcat
|
||||
3 pick stringcmp not if pop pop 1 exit then
|
||||
"&" over strcat strcat "!" swap strcat
|
||||
stringcmp not if 1 exit then
|
||||
0
|
||||
;
|
||||
|
||||
: check-link ( d -- )
|
||||
dup getlink not if
|
||||
dup unparseobj " is unlinked." strcat .tell
|
||||
else
|
||||
dup getlink over location dbcmp if
|
||||
dup islocked? not if
|
||||
dup unparseobj
|
||||
" is linked to it's location, but is unlocked."
|
||||
strcat .tell
|
||||
then
|
||||
else (is not linked to it's location)
|
||||
dup getlink program? if
|
||||
dup dup owner swap getlink can-linkto? not if
|
||||
dup unparseobj
|
||||
" is linked to a program which is not Link_OK."
|
||||
strcat .tell
|
||||
then
|
||||
then
|
||||
then
|
||||
then
|
||||
pop
|
||||
;
|
||||
|
||||
: check-room (d -- )
|
||||
dup check-desc
|
||||
dup islocked? if
|
||||
dup islocked_always? not if
|
||||
dup check-succ
|
||||
then
|
||||
dup check-fail
|
||||
then
|
||||
dup getlink if
|
||||
dup check-drop
|
||||
dup check-odrop
|
||||
then
|
||||
dup check-contents
|
||||
check-exits
|
||||
;
|
||||
|
||||
: check-exit ( d -- )
|
||||
dup check-link
|
||||
dup check-desc
|
||||
dup getlink dup ok? if
|
||||
program? not if
|
||||
dup islocked_always? not if
|
||||
dup check-succ
|
||||
dup check-osucc
|
||||
dup check-odrop
|
||||
then
|
||||
dup islocked? if
|
||||
dup check-fail
|
||||
dup check-ofail
|
||||
then
|
||||
then
|
||||
else pop
|
||||
then
|
||||
pop
|
||||
;
|
||||
|
||||
: check-thing ( d -- )
|
||||
dup check-desc
|
||||
dup islocked_always? not if
|
||||
dup check-succ
|
||||
dup check-osucc
|
||||
then
|
||||
dup islocked? if
|
||||
dup check-fail
|
||||
dup check-ofail
|
||||
then
|
||||
dup check-drop
|
||||
dup check-odrop
|
||||
check-exits
|
||||
;
|
||||
|
||||
: check-player ( d -- )
|
||||
dup check-desc
|
||||
dup islocked_always? not if
|
||||
dup check-succ
|
||||
dup check-osucc
|
||||
then
|
||||
dup islocked? if
|
||||
dup check-fail
|
||||
dup check-ofail
|
||||
then
|
||||
dup check-contents
|
||||
check-exits
|
||||
;
|
||||
|
||||
: check-program ( d -- )
|
||||
check-desc
|
||||
;
|
||||
|
||||
: check-obj (d -- )
|
||||
dup room? if check-room exit then
|
||||
dup exit? if check-exit exit then
|
||||
dup thing? if check-thing exit then
|
||||
dup player? if check-player exit then
|
||||
check-program
|
||||
;
|
||||
|
||||
: main
|
||||
'check-obj check-obj-addr !
|
||||
.strip dup not if pop "here" then
|
||||
.match_controlled
|
||||
dup #-3 dbcmp if pop me @ getlink then
|
||||
dup ok? not if pop exit then
|
||||
check-obj
|
||||
me @ "Check done." notify
|
||||
;
|
||||
275
samples/MUF/cmd-say.muf
Normal file
275
samples/MUF/cmd-say.muf
Normal file
@@ -0,0 +1,275 @@
|
||||
@program cmd-say.muf
|
||||
1 1000 d
|
||||
i
|
||||
( cmd-say.muf by Natasha@HLM
|
||||
|
||||
Copyright 2002-2004 Natasha Snunkmeox. Copyright 2002-2004 Here Lie Monsters.
|
||||
"@view $box/mit" for license information.
|
||||
)
|
||||
$author Natasha Snunkmeox <natmeox@neologasm.org>
|
||||
$note Say for Fuzzball 6.
|
||||
$version 1.0
|
||||
|
||||
$include $lib/ignore
|
||||
$include $lib/strings
|
||||
$include $lib/match
|
||||
|
||||
$def str_program "saypose"
|
||||
$def prop_third "_prefs/say/third"
|
||||
$def prop_quotes "_say/def/quotes"
|
||||
$def prop_overb "_say/def/osay"
|
||||
$def prop_verb "_say/def/say"
|
||||
$def prop_split "_prefs/say/split"
|
||||
$def prop_color "_prefs/say/color"
|
||||
$def prop_meow "_prefs/say/meow"
|
||||
|
||||
lvar randomWord
|
||||
|
||||
lvar verb
|
||||
lvar overb
|
||||
lvar lquo
|
||||
lvar rquo
|
||||
lvar splitsay
|
||||
|
||||
: rtn-getThirdVerb[ var:overb -- ]
|
||||
( Get the third-person verb. )
|
||||
me @ prop_overb getpropstr dup if ( str strOverb )
|
||||
strip dup dup "," instr not and if "," strcat then
|
||||
else pop "says," then ( str strOverb )
|
||||
me @ "%D %s" fmtstring overb @ ! ( str )
|
||||
;
|
||||
|
||||
: rtn-getFirstVerb[ var:verb var:overb -- ]
|
||||
me @ prop_third getpropstr .yes? not if ( str )
|
||||
( Get the first-person verb. )
|
||||
me @ prop_verb getpropstr dup if ( str strVerb )
|
||||
strip dup dup "," instr not and if "," strcat then
|
||||
else pop "say," then ( str strVerb )
|
||||
splitsay @ if "you %s" else "You %s" then fmtstring ( str strVerb )
|
||||
else overb @ @ then verb @ ! ( str )
|
||||
;
|
||||
|
||||
: rtn-getQuotes[ var:lquo var:rquo -- ]
|
||||
me @ prop_quotes getpropstr dup "%m" instr if ( strQuotes )
|
||||
"%m" split ( strLquo strRquo )
|
||||
else pop "\"" dup then ( strLquo strRquo )
|
||||
rquo @ ! lquo @ ! ( )
|
||||
;
|
||||
|
||||
: do-say ( str -- )
|
||||
"" randomWord !
|
||||
|
||||
var who
|
||||
var exclude
|
||||
|
||||
( Ignoring? Get 'em outta here. )
|
||||
loc @ contents_array ( str arrHere )
|
||||
dup me @ str_program array_get_ignorers ( str arrHere arrIgnorers )
|
||||
dup exclude !
|
||||
swap array_diff who !
|
||||
|
||||
|
||||
( Anyone #meowing this player? Go ahead and notify before special formatting. )
|
||||
who @ prop_meow me @ owner "*{%d}*" fmtstring array_filter_prop ( str arrMeow )
|
||||
dup if ( str arrMeow )
|
||||
dup who @ array_diff who ! ( str arrMeow )
|
||||
dup exclude @ array_union exclude ! ( str arrMeow )
|
||||
|
||||
over ansi_strip ( str arrMeow str )
|
||||
"\\b[A-Z0-9_]+\\b" "MEOW" REG_ALL regsub ( str arrMeow str' )
|
||||
"\\b[A-Z0-9_][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*\\b" "Meow" REG_ALL regsub ( str arrMeow str' )
|
||||
"\\b[a-z_][A-Za-z0-9_]*\\b" "meow" REG_ALL regsub ( str arrMeow str' )
|
||||
me @ "%D meows, \"%s\"" fmtstring ( str arrMeow str" )
|
||||
1 array_make swap array_notify ( str )
|
||||
else pop then ( str )
|
||||
|
||||
|
||||
var msg
|
||||
|
||||
dup ",," instr ( str boolCommas )
|
||||
me @ prop_split getpropstr .no? not ( str boolCommas boolSplitOK )
|
||||
and if ( str )
|
||||
",," split ( str- -str )
|
||||
|
||||
( User-supplied verb? )
|
||||
dup ",," instr if
|
||||
",," split ( str- strVerb -str )
|
||||
swap dup if ( str- -str strVerb )
|
||||
strip ( str- -str strVerb )
|
||||
dup me @ name instr over tolower "%n" instr or if ( str- -str strVerb )
|
||||
"%n" "%N" subst me @ name "%n" subst ( str- -str strVerb )
|
||||
else
|
||||
me @ swap "%s %D," fmtstring ( str- -str -str- )
|
||||
then ( str- -str -str- )
|
||||
dup "*[-!.,:;]" smatch not if "," strcat then ( str- -str -str- )
|
||||
dup verb ! overb ! ( str- -str )
|
||||
else pop then ( str- -str )
|
||||
then ( str- -str )
|
||||
|
||||
2 array_make ( arrMsg )
|
||||
1
|
||||
else 0 then splitsay ! msg !
|
||||
|
||||
|
||||
verb @ string? not if
|
||||
overb rtn-getThirdVerb
|
||||
verb overb rtn-getFirstVerb
|
||||
then
|
||||
lquo rquo rtn-getQuotes ( str )
|
||||
|
||||
|
||||
( Say. )
|
||||
msg @ string? if
|
||||
rquo @ msg @ lquo @ ( strRquo strMsg strLquo )
|
||||
"%s %s%s%s" ( strRquo strMsg strLquo strFormat )
|
||||
|
||||
4 dupn
|
||||
verb @ swap fmtstring .tell ( strRquo strMsg strLquo strFormat )
|
||||
overb @ swap fmtstring ( strOsay )
|
||||
else
|
||||
rquo @ msg @ array_vals pop ( strRquo strMsg strMsg2 )
|
||||
swap dup "*[-!.,:;]" smatch not if "," strcat then swap ( strRquo strMsg strMsg2 )
|
||||
( Only handle strMsg if there's no strMsg2. )
|
||||
dup if ( strRquo strMsg strMsg2 )
|
||||
swap ( strRquo strMsg2 strMsg )
|
||||
lquo @ swap rquo @ swap lquo @ ( strRquo strMsg2 strLquo strRquo strMsg' strLquo )
|
||||
"%s%s%s %s %s%s%s" ( strRquo strMsg2 strLquo strRquo strMsg' strLquo strFormat )
|
||||
|
||||
7
|
||||
else ( strRquo strMsg strMsg2 )
|
||||
pop lquo @ ( strRquo strMsg' strLquo )
|
||||
"%s%s%s %s" ( strRquo strMsg' strLquo strFormat )
|
||||
|
||||
verb @ ",$" "." 0 regsub verb !
|
||||
overb @ ",$" "." 0 regsub overb !
|
||||
|
||||
4
|
||||
then ( ... strRquo strMsg strLquo strFormat intDepth )
|
||||
|
||||
dupn
|
||||
verb @ -5 rotate fmtstring .tell ( ... strRquo strMsg strLquo strFormat )
|
||||
overb @ -5 rotate fmtstring ( strOsay )
|
||||
then ( strOsay )
|
||||
|
||||
|
||||
( Is there color to avoid? )
|
||||
dup "\[[" instr if
|
||||
who @ prop_color "{n*|0}" array_filter_prop ( strOsay arrGreyed )
|
||||
dup if ( strOsay arrGreyed )
|
||||
over ansi_strip 1 array_make ( strOsay arrGreyed arrMsg )
|
||||
over array_notify ( strOsay arrGreyed )
|
||||
|
||||
exclude @ array_union exclude ! ( strOsay )
|
||||
else pop then ( strOsay )
|
||||
then ( strOsay )
|
||||
|
||||
loc @ ( strOsay db )
|
||||
exclude @ array_vals ( strOsay db dbExcludeN..dbExclude1 intN )
|
||||
me @ swap ++ ( strOsay db dbGreyedN..dbGreyed1' intN' )
|
||||
dup 3 + rotate ( db dbGreyedN..dbGreyed1 intN strOsay )
|
||||
notify_exclude ( )
|
||||
;
|
||||
|
||||
: do-help pop pop .showhelp ;
|
||||
: do-ignore pop str_program cmd-ignore-add ;
|
||||
: do-unignore pop str_program cmd-ignore-del ;
|
||||
|
||||
: do-third ( strY strZ -- )
|
||||
pop pop ( )
|
||||
me @ prop_third "yes" setprop
|
||||
me @ "You will see your own says in the third person (\"%D says\")." fmtstring .tellgood
|
||||
;
|
||||
: do-unthird ( strY strZ -- )
|
||||
pop pop ( )
|
||||
me @ prop_third remove_prop
|
||||
"You will see your own says in the second person (\"You say\")." .tellgood
|
||||
;
|
||||
|
||||
: do-grey ( strY strZ -- )
|
||||
pop pop ( )
|
||||
me @ prop_color "no" setprop
|
||||
me @ "You will not see color in any says. Note you will see color in your own says." fmtstring .tellgood
|
||||
;
|
||||
: do-ungrey ( strY strZ -- )
|
||||
pop pop ( )
|
||||
me @ prop_color remove_prop
|
||||
"You will see color in says." .tellgood
|
||||
;
|
||||
|
||||
: do-meow ( strY strZ -- )
|
||||
pop ( strY )
|
||||
dup if
|
||||
.noisy_pmatch dup ok? not if pop exit then ( db )
|
||||
me @ prop_meow 3 pick reflist_find if ( db )
|
||||
"%D is already in your #meow list." fmtstring .tellbad exit ( )
|
||||
then ( db )
|
||||
me @ prop_meow 3 pick reflist_add ( db )
|
||||
"%D added." fmtstring .tellgood
|
||||
else
|
||||
me @ prop_meow array_get_reflist ( arr )
|
||||
"" swap foreach swap pop "%D %s" fmtstring repeat
|
||||
"Your meowlist: " swap strcat .tellgood
|
||||
then
|
||||
;
|
||||
: do-unmeow ( strY strZ -- )
|
||||
pop ( strY )
|
||||
.noisy_pmatch dup ok? not if pop exit then ( db )
|
||||
me @ prop_meow 3 pick reflist_find not if ( db )
|
||||
"%D is not in your #meow list." fmtstring .tellbad exit ( )
|
||||
then ( db )
|
||||
me @ prop_meow 3 pick reflist_del ( db )
|
||||
"%D removed." fmtstring .tellgood
|
||||
;
|
||||
|
||||
$define dict_commands {
|
||||
"help" 'do-help
|
||||
"ignore" 'do-ignore
|
||||
"!ignore" 'do-unignore
|
||||
"meow" 'do-meow
|
||||
"!meow" 'do-unmeow
|
||||
"third" 'do-third
|
||||
"!third" 'do-unthird
|
||||
"grey" 'do-grey
|
||||
"gray" 'do-grey
|
||||
"!grey" 'do-ungrey
|
||||
"!gray" 'do-ungrey
|
||||
}dict $enddef
|
||||
|
||||
: main ( str -- )
|
||||
dup STRparse ( str strX strY strZ )
|
||||
3 pick string? if 3 pick "#" stringpfx if ( str strX strY strZ )
|
||||
pop pop pop ( str )
|
||||
"#" split strcat ( str' )
|
||||
do-say exit ( )
|
||||
then then
|
||||
3 pick int? if pop pop pop do-say exit then
|
||||
4 rotate pop ( strX strY strZ )
|
||||
|
||||
rot dict_commands over array_getitem ( strY strZ strX ? )
|
||||
dup address? if ( strY strZ strX adr )
|
||||
swap pop ( strY strZ adr )
|
||||
execute ( )
|
||||
else pop ( strY strZ strX )
|
||||
"I don't recognize the command '#%s'. Try 'say #help' for help, or using '##' to say something starting with '#'." fmtstring .tellbad ( strY strZ )
|
||||
pop pop ( )
|
||||
then ( )
|
||||
;
|
||||
.
|
||||
c
|
||||
q
|
||||
|
||||
lsedit #257=_help
|
||||
.del 1 $
|
||||
say <message>
|
||||
."<message>
|
||||
say #[!]ignore <names>
|
||||
say #[!]third
|
||||
say #[!]grey
|
||||
say #[!]meow <names>
|
||||
|
||||
Speaks <message> to the room. Use #ignore <name> to not see <name>'s says, poses, and spoofs; use #meow <name> to see <name>'s says with all the words replaced with "meow." Use #third to see your own says in the third person (that is, "Puck says" instead of the normal "You say"). Use #grey to turn off color in others' says and poses.
|
||||
|
||||
Say supports a "split" say if you put two consecutive commas in your message. For example, if CobaltBlue typed '"Hello,,how are you?' everyone would see '"Hello," says CobaltBlue, "how are you?"' You can also specify an "ad-hoc" verb by putting a message with your name or '%N' between pairs of commas: '"Hello,,%N welcomes Weiran,,how are you?' would display '"Hello," CobaltBlue welcomes Weiran, "how are you?"'
|
||||
.format 10=78
|
||||
.format 8=78
|
||||
.end
|
||||
5
samples/Makefile/foo.o.d
Normal file
5
samples/Makefile/foo.o.d
Normal file
@@ -0,0 +1,5 @@
|
||||
bar/foo.o: \
|
||||
bar/foo.c \
|
||||
bar/baz.h
|
||||
|
||||
bar/baz.h:
|
||||
344
samples/Mathematica/HeyexImport.m
Normal file
344
samples/Mathematica/HeyexImport.m
Normal file
@@ -0,0 +1,344 @@
|
||||
(* Mathematica Package *)
|
||||
(* Created with IntelliJ IDEA and the Mathematica Language plugin *)
|
||||
|
||||
(* :Title: Importer for the RAW data-format of the Heidelberg Eye Explorer (known as HEYEX) *)
|
||||
|
||||
(* :Context: HeyexImport` *)
|
||||
|
||||
(* :Author: Patrick Scheibe pscheibe@trm.uni-leipzig.de *)
|
||||
|
||||
(* :Package Version: 1.0 *)
|
||||
|
||||
(* :Mathematica Version: 8.0 *)
|
||||
|
||||
(* :Copyright: Patrick Scheibe, 2013-2015 *)
|
||||
|
||||
(* :Discussion: This package registers a new importer which can load the RAW data-format exported by a
|
||||
Heidelberg Spectralis OCT. The import-functionality can access different information contained
|
||||
in a file:
|
||||
1. The file header which contains meta data like when the patient was scanned etc
|
||||
2. The scanned volume data
|
||||
3. Images which represent slices of the scanned volume
|
||||
4. The Scanning laser ophthalmoscopy (SLO) image which is taken with every scanned patient
|
||||
5. The segmentation data for different retina layers provided by the software
|
||||
|
||||
*)
|
||||
|
||||
(* :Keywords: Import, Heyex, OCT, Spectralis, Heidelberg Engineering *)
|
||||
|
||||
BeginPackage[ "HeyexImport`" ]
|
||||
|
||||
HeyexEyePosition::usage = "HeyexEyePosition[file] tries to extract which eye was scanned, left or right.";
|
||||
|
||||
HeyexImport::wrongHdr = "Error importing OCT data. Broken/Wrong file?";
|
||||
|
||||
|
||||
Begin[ "`Private`" ];
|
||||
|
||||
(*
|
||||
Registration of all import possibilities for the Heidelberg OCT.
|
||||
*)
|
||||
|
||||
ImportExport`RegisterImport[
|
||||
"Heyex" ,
|
||||
{
|
||||
"FileHeader" :> importHeader,
|
||||
{ "Data" , n_Integer} :> (importData[n][##]&),
|
||||
"Data" :> importData,
|
||||
{ "Images" , n_Integer} :> (importImages[n][##]&),
|
||||
"Images" :> importImages,
|
||||
"SLOImage" :> importSLOImage,
|
||||
"SegmentationData" :> importSegmentation,
|
||||
{ "SegmentationData" , n_Integer} :> (importSegmentation[n][##]&),
|
||||
"DataSize" :> importDataSize,
|
||||
importData
|
||||
},
|
||||
|
||||
{
|
||||
"Image3D" :> (Image3D["Data" /. #1]&)
|
||||
},
|
||||
|
||||
"AvailableElements" -> {"FileHeader", "Data", "DataSize", "Images", "SLOImage", "SegmentationData", "Image3D"}
|
||||
];
|
||||
|
||||
|
||||
If[Quiet[Check[TrueQ[Compile[{}, 0, CompilationTarget -> "C"][] == 0], False]],
|
||||
$compileTarget = CompilationTarget -> "C",
|
||||
$compileTarget = CompilationTarget -> "MVM"
|
||||
];
|
||||
|
||||
|
||||
(*
|
||||
Helper function which reads data from a stream. This is
|
||||
only a unification so I can map the read function over a
|
||||
list.
|
||||
*)
|
||||
read[{id_String, type_String}, str_] :=
|
||||
id -> BinaryRead[str, type];
|
||||
read[{type_String, n_Integer}, str_] := BinaryReadList[str, type, n];
|
||||
read[{id_String, {type_String, n_Integer}}, str_] := id -> BinaryReadList[str, type, n];
|
||||
(*
|
||||
Note that when reading bytes explicitly I convert them to
|
||||
a string and remove any zeroes at the end.
|
||||
*)
|
||||
read[{id_String, { "Byte" , n_Integer}}, str_] :=
|
||||
id -> StringJoin[
|
||||
FromCharacterCode /@ (Rest[
|
||||
NestList[BinaryRead[str, "Byte" ] &, Null,
|
||||
n]] /. {chars___Integer, Longest[0 ...]} :> {chars})];
|
||||
|
||||
(*
|
||||
The layout of a file exported with "Raw Export"
|
||||
|
||||
*****************
|
||||
* File Header *
|
||||
*****************
|
||||
* SLO Image *
|
||||
*****************
|
||||
* B-Scan #0 *
|
||||
*****************
|
||||
* ..... *
|
||||
*****************
|
||||
* B-Scan #n-1 *
|
||||
*****************
|
||||
*)
|
||||
|
||||
With[{i = "Integer32", f = "Real32", d = "Real64", b = "Byte"},
|
||||
|
||||
$fileHeaderInfo = Transpose[{
|
||||
{
|
||||
"Version" , "SizeX" , "NumBScans" , "SizeZ" , "ScaleX" , "Distance" ,
|
||||
"ScaleZ" , "SizeXSlo" , "SizeYSlo" , "ScaleXSlo" , "ScaleYSlo" ,
|
||||
"FieldSizeSlo" , "ScanFocus" , "ScanPosition" , "ExamTime" ,
|
||||
"ScanPattern" , "BScanHdrSize" , "ID" , "ReferenceID" , "PID" ,
|
||||
"PatientID" , "Padding" , "DOB" , "VID" , "VisitID" , "VisitDate" ,
|
||||
"Spare"
|
||||
},
|
||||
{
|
||||
{b, 12}, i, i, i, d, d, d, i, i, d, d, i, d, {b, 4}, {i, 2}, i, i,
|
||||
{b, 16}, {b, 16}, i, {b, 21}, {b, 3}, d, i, {b, 24}, d, {b, 1840}
|
||||
}
|
||||
}];
|
||||
|
||||
$bScanHeaderInfo = Transpose[{
|
||||
{
|
||||
"Version" , "BScanHdrSize" , "StartX" , "StartY" , "EndX" , "EndY" ,
|
||||
"NumSeg" , "OffSeg" , "Quality" , "Spare"
|
||||
},
|
||||
{{b, 12}, i, d, d, d, d, i, i, f, {b, 196}}
|
||||
}];
|
||||
];
|
||||
|
||||
|
||||
isHeyexRawFormat[{"Version" -> version_String, "SizeX" -> _Integer, "NumBScans" -> _Integer, _Rule..}] /; StringMatchQ[version, "HSF-OCT" ~~__] := True ;
|
||||
isHeyexRawFormat[___] := False;
|
||||
|
||||
readFileHeader[str_InputStream] := With[{hdr = Quiet[read[#, str]] & /@ $fileHeaderInfo},
|
||||
hdr /; TrueQ[isHeyexRawFormat[hdr]]
|
||||
];
|
||||
readFileHeader[___] := (Message[HeyexImport::wrongHdr]; Throw[$Failed]);
|
||||
|
||||
|
||||
(* Reads the camera image of the retina. Note that you must have the
|
||||
information from the fileheader and you must be at the right position
|
||||
of the file stream for this.*)
|
||||
readSLOImage[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Image[Partition[
|
||||
BinaryReadList[str, "Byte" , "SizeXSlo" * "SizeYSlo" /. fileHdr],
|
||||
"SizeXSlo" /. fileHdr], "Byte" ];
|
||||
|
||||
skipSLOImage[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Skip[str, "Byte" , "SizeXSlo" * "SizeYSlo" /. fileHdr];
|
||||
|
||||
|
||||
(* One single BScan consists itself again of a header and a data part *)
|
||||
readBScanHeader[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Module[{i = "Integer32", f = "Real32", d = "Real64", b = "Byte",
|
||||
bScanHdr},
|
||||
bScanHdr = read[#, str] & /@ Transpose[{
|
||||
{ "Version" , "BScanHdrSize" , "StartX" , "StartY" , "EndX" , "EndY" ,
|
||||
"NumSeg" , "OffSeg" , "Quality" , "Spare" },
|
||||
{{b, 12}, i, d, d, d, d, i, i, f, {b, 196}}}
|
||||
];
|
||||
AppendTo[bScanHdr,
|
||||
read[{ "SegArray" , { "Real32" ,
|
||||
"NumSeg" * "SizeX" /. bScanHdr /. fileHdr}}, str]
|
||||
];
|
||||
(*
|
||||
This is horrible slow, therefore I just skip the fillbytes
|
||||
|
||||
AppendTo[bScanHdr,
|
||||
read[{"Fillbytes", {"Byte",
|
||||
"BScanHdrSize" - 256 - "NumSeg"*"SizeX"*4 /. bScanHdr /.
|
||||
fileHdr}}, str]
|
||||
]
|
||||
*)
|
||||
Skip[str, "Byte" , "BScanHdrSize" - 256 - "NumSeg" * "SizeX" * 4 /. bScanHdr /. fileHdr];
|
||||
AppendTo[bScanHdr, "FillBytes" -> None]
|
||||
]
|
||||
|
||||
skipBScanHeader[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Skip[str, "Byte" , "BScanHdrSize" /. fileHdr];
|
||||
|
||||
readBScanData[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Module[{},
|
||||
Developer`ToPackedArray[
|
||||
Partition[read[{ "Real32" , "SizeX" * "SizeZ" /. fileHdr}, str],
|
||||
"SizeX" /. fileHdr]]
|
||||
];
|
||||
|
||||
skipBScanData[str_InputStream, fileHdr : {(_String -> _) ..}] :=
|
||||
Skip[str, "Byte" , "SizeX" * "SizeZ" * 4 /. fileHdr];
|
||||
|
||||
skipBScanBlocks[str_InputStream, fileHdr : {(_String -> _) ..}, n_Integer] :=
|
||||
Skip[str, "Byte" , n * ("BScanHdrSize" + "SizeX" * "SizeZ" * 4) /. fileHdr];
|
||||
|
||||
|
||||
importHeader[filename_String, ___] := Module[
|
||||
{str, header},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
Close[str];
|
||||
"FileHeader" -> header
|
||||
];
|
||||
|
||||
|
||||
(* Imports the dimension of the scanned volume. *)
|
||||
importDataSize[filename_String, r___] := Module[{header = importHeader[filename]},
|
||||
"DataSize" -> ({"NumBScans", "SizeZ", "SizeXSlo"} /. ("FileHeader" /. header))
|
||||
]
|
||||
|
||||
importSLOImage[filename_String, ___] := Module[
|
||||
{str, header, slo},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
slo = readSLOImage[str, header];
|
||||
Close[str];
|
||||
"SLOImage" -> slo
|
||||
]
|
||||
|
||||
importData[filename_String, ___] := Module[
|
||||
{str, header, nx, n, data},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
{nx, n} = { "SizeX" , "SizeX" * "SizeZ"} /. header;
|
||||
skipSLOImage[str, header];
|
||||
data = Table[
|
||||
skipBScanHeader[str, header];
|
||||
Partition[read[{ "Real32" , n}, str], nx],
|
||||
{"NumBScans" /. header}
|
||||
];
|
||||
Close[str];
|
||||
"Data" -> Developer`ToPackedArray[data]
|
||||
];
|
||||
|
||||
importData[num_Integer][filename_String, ___] := Module[
|
||||
{str, header, nx, n, data},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
{nx, n} = { "SizeX" , "SizeX" * "SizeZ"} /. header;
|
||||
skipSLOImage[str, header];
|
||||
skipBScanBlocks[str, header, Max[Min["NumBScans" /. header, num - 1], 0] ];
|
||||
skipBScanHeader[str, header];
|
||||
data = Partition[read[{ "Real32" , n}, str], nx];
|
||||
Close[str];
|
||||
{"Data" -> {num -> Developer`ToPackedArray[data]}}
|
||||
];
|
||||
|
||||
(*
|
||||
As suggested in the Heidelberg OCT Manual the importer will adjust
|
||||
the graylevels when importing images. Since this is very time-consuming
|
||||
for the whole scanned volume, I use an optimized version of this function.
|
||||
*)
|
||||
With[{$compileTarget = $compileTarget}, $adjustGraylevelFunc := ($adjustGraylevelFunc = Compile[{{values, _Real, 2}},
|
||||
Map[Floor[255.0 * Min[Max[0.0, #], 1.0]^(0.25) + 0.5] &, values, {2}],
|
||||
RuntimeAttributes -> {Listable},
|
||||
Parallelization -> True,
|
||||
RuntimeOptions -> "Speed",
|
||||
$compileTarget
|
||||
])];
|
||||
|
||||
importImages[filename_String, ___] := Module[
|
||||
{data},
|
||||
data = "Data" /. importData[filename];
|
||||
"Images" -> (Image[#, "Byte" ]& /@ $adjustGraylevelFunc[data])
|
||||
]
|
||||
|
||||
importImages[imageNumber_Integer][filename_String, ___] := Module[
|
||||
{data},
|
||||
data = {imageNumber /. ("Data" /. importData[imageNumber][filename])};
|
||||
{"Images" -> {imageNumber -> (Image[#, "Byte" ]& @@ $adjustGraylevelFunc[data])}}
|
||||
];
|
||||
|
||||
importSegmentation[filename_String, ___] := Module[
|
||||
{str, header, data},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
skipSLOImage[str, header];
|
||||
data = Table[
|
||||
Module[{bScanHeader, t},
|
||||
{t, bScanHeader} = Timing@readBScanHeader[str, header];
|
||||
skipBScanData[str, header];
|
||||
bScanHeader
|
||||
], {"NumBScans" /. header}
|
||||
];
|
||||
Close[str];
|
||||
(*
|
||||
The BScanHeaderData contain the segmentation vectors as a single list
|
||||
of numbers. Before returning the result, I check how many segmentations
|
||||
there are inside the BScan an I transform the segmentation value list
|
||||
into separate vectors and call them "ILM", "RPE" and "NFL" like described
|
||||
in the manual
|
||||
*)
|
||||
"SegmentationData" -> Function[{bhdr},
|
||||
Block[{numVecs = "NumSeg" /. bhdr, vecNames, nx = "SizeX" /. header},
|
||||
If[numVecs > 0,
|
||||
vecNames = Take[{ "ILM" , "RPE" , "NFL" }, numVecs];
|
||||
bhdr /. ("SegArray" -> vec_) :> Sequence @@ (Rule @@@ Transpose[{vecNames, Partition[vec, nx]} ]),
|
||||
bhdr
|
||||
]
|
||||
]] /@ data
|
||||
]
|
||||
|
||||
importSegmentation[num_Integer][filename_String, ___] := Module[
|
||||
{str, header, bhdr},
|
||||
str = OpenRead[filename, BinaryFormat -> True];
|
||||
header = readFileHeader[str];
|
||||
skipSLOImage[str, header];
|
||||
skipBScanBlocks[str, header, Max[Min["NumBScans" /. header, num - 1], 0] ];
|
||||
bhdr = readBScanHeader[str, header];
|
||||
Close[str];
|
||||
(* See doc above *)
|
||||
{"SegmentationData" -> {num -> Block[
|
||||
{numVecs = "NumSeg" /. bhdr, vecNames, nx = "SizeX" /. header},
|
||||
If[ numVecs > 0,
|
||||
vecNames = Take[{ "ILM" , "RPE" , "NFL" }, numVecs];
|
||||
bhdr /. ("SegArray" -> vec_) :> Sequence @@ (Rule @@@ Transpose[{vecNames, Partition[vec, nx]} ]),
|
||||
bhdr
|
||||
]
|
||||
]
|
||||
}}
|
||||
]
|
||||
|
||||
(* Extracts which eye was scanned. This is stored in the header of the file *)
|
||||
(* OD stands for oculus dexter which is latin for "right eye" and OS stands
|
||||
for oculus sinister which is latin for "left eye" *)
|
||||
HeyexEyePosition[file_String /; FileExistsQ[file]] := Module[{position},
|
||||
Check[
|
||||
position = "ScanPosition" /. Import[file, { "Heyex" , "FileHeader" }];
|
||||
Switch[
|
||||
position,
|
||||
"OD" ,
|
||||
Right,
|
||||
"OS" ,
|
||||
Left,
|
||||
_,
|
||||
$Failed
|
||||
],
|
||||
$Failed
|
||||
]
|
||||
];
|
||||
|
||||
End[]
|
||||
|
||||
EndPackage[]
|
||||
150
samples/Mathematica/Predicates.wl
Normal file
150
samples/Mathematica/Predicates.wl
Normal file
@@ -0,0 +1,150 @@
|
||||
(* ::Package:: *)
|
||||
|
||||
BeginPackage["Predicates`"];
|
||||
|
||||
|
||||
(* ::Title:: *)
|
||||
(*Predicates*)
|
||||
|
||||
|
||||
(* ::Section::Closed:: *)
|
||||
(*Fuzzy Logic*)
|
||||
|
||||
|
||||
(* ::Subsection:: *)
|
||||
(*Documentation*)
|
||||
|
||||
|
||||
PossiblyTrueQ::usage="Returns True if the argument is not definitely False.";
|
||||
PossiblyFalseQ::usage="Returns True if the argument is not definitely True.";
|
||||
PossiblyNonzeroQ::usage="Returns True if and only if its argument is not definitely zero.";
|
||||
|
||||
|
||||
(* ::Subsection:: *)
|
||||
(*Implimentation*)
|
||||
|
||||
|
||||
Begin["`Private`"];
|
||||
|
||||
|
||||
PossiblyTrueQ[expr_]:=\[Not]TrueQ[\[Not]expr]
|
||||
|
||||
|
||||
PossiblyFalseQ[expr_]:=\[Not]TrueQ[expr]
|
||||
|
||||
|
||||
End[];
|
||||
|
||||
|
||||
(* ::Section::Closed:: *)
|
||||
(*Numbers and Lists*)
|
||||
|
||||
|
||||
(* ::Subsection:: *)
|
||||
(*Documentation*)
|
||||
|
||||
|
||||
AnyQ::usage="Given a predicate and a list, retuns True if and only if that predicate is True for at least one element of the list.";
|
||||
AnyElementQ::usage="Returns True if cond matches any element of L.";
|
||||
AllQ::usage="Given a predicate and a list, retuns True if and only if that predicate is True for all elements of the list.";
|
||||
AllElementQ::usage="Returns True if cond matches any element of L.";
|
||||
|
||||
|
||||
AnyNonzeroQ::usage="Returns True if L is a list such that at least one element is definitely not zero.";
|
||||
AnyPossiblyNonzeroQ::usage="Returns True if expr is a list such that at least one element is not definitely zero.";
|
||||
|
||||
|
||||
RealQ::usage="Returns True if and only if the argument is a real number";
|
||||
PositiveQ::usage="Returns True if and only if the argument is a positive real number";
|
||||
NonnegativeQ::usage="Returns True if and only if the argument is a non-negative real number";
|
||||
PositiveIntegerQ::usage="Returns True if and only if the argument is a positive integer";
|
||||
NonnegativeIntegerQ::usage="Returns True if and only if the argument is a non-negative integer";
|
||||
|
||||
|
||||
IntegerListQ::usage="Returns True if and only if the input is a list of integers.";
|
||||
PositiveIntegerListQ::usage="Returns True if and only if the input is a list of positive integers.";
|
||||
NonnegativeIntegerListQ::usage="Returns True if and only if the input is a list of non-negative integers.";
|
||||
IntegerOrListQ::usage="Returns True if and only if the input is a list of integers or an integer.";
|
||||
PositiveIntegerOrListQ::usage="Returns True if and only if the input is a list of positive integers or a positive integer.";
|
||||
NonnegativeIntegerOrListQ::usage="Returns True if and only if the input is a list of positive integers or a positive integer.";
|
||||
|
||||
|
||||
SymbolQ::usage="Returns True if argument is an unassigned symbol.";
|
||||
SymbolOrNumberQ::usage="Returns True if argument is a number of has head 'Symbol'";
|
||||
|
||||
|
||||
(* ::Subsection:: *)
|
||||
(*Implimentation*)
|
||||
|
||||
|
||||
Begin["`Private`"];
|
||||
|
||||
|
||||
AnyQ[cond_, L_] := Fold[Or, False, cond /@ L]
|
||||
|
||||
|
||||
AnyElementQ[cond_,L_]:=AnyQ[cond,Flatten[L]]
|
||||
|
||||
|
||||
AllQ[cond_, L_] := Fold[And, True, cond /@ L]
|
||||
|
||||
|
||||
AllElementQ[cond_, L_] := Fold[And, True, cond /@ L]
|
||||
|
||||
|
||||
AnyNonzeroQ[L_]:=AnyElementQ[#!=0&,L]
|
||||
|
||||
|
||||
PossiblyNonzeroQ[expr_]:=PossiblyTrueQ[expr!=0]
|
||||
|
||||
|
||||
AnyPossiblyNonzeroQ[expr_]:=AnyElementQ[PossiblyNonzeroQ,expr]
|
||||
|
||||
|
||||
RealQ[n_]:=TrueQ[Im[n]==0];
|
||||
|
||||
|
||||
PositiveQ[n_]:=Positive[n];
|
||||
|
||||
|
||||
PositiveIntegerQ[n_]:=PositiveQ[n]\[And]IntegerQ[n];
|
||||
|
||||
|
||||
NonnegativeQ[n_]:=TrueQ[RealQ[n]&&n>=0];
|
||||
|
||||
|
||||
NonnegativeIntegerQ[n_]:=NonnegativeQ[n]\[And]IntegerQ[n];
|
||||
|
||||
|
||||
IntegerListQ[input_]:=ListQ[input]&&Not[MemberQ[IntegerQ/@input,False]];
|
||||
|
||||
|
||||
IntegerOrListQ[input_]:=IntegerListQ[input]||IntegerQ[input];
|
||||
|
||||
|
||||
PositiveIntegerListQ[input_]:=IntegerListQ[input]&&Not[MemberQ[Positive[input],False]];
|
||||
|
||||
|
||||
PositiveIntegerOrListQ[input_]:=PositiveIntegerListQ[input]||PositiveIntegerQ[input];
|
||||
|
||||
|
||||
NonnegativeIntegerListQ[input_]:=IntegerListQ[input]&&Not[MemberQ[NonnegativeIntegerQ[input],False]];
|
||||
|
||||
|
||||
NonnegativeIntegerOrListQ[input_]:=NonnegativeIntegerListQ[input]||NonnegativeIntegerQ[input];
|
||||
|
||||
|
||||
SymbolQ[a_]:=Head[a]===Symbol;
|
||||
|
||||
|
||||
SymbolOrNumberQ[a_]:=NumericQ[a]||Head[a]===Symbol;
|
||||
|
||||
|
||||
End[];
|
||||
|
||||
|
||||
(* ::Section:: *)
|
||||
(*Epilogue*)
|
||||
|
||||
|
||||
EndPackage[];
|
||||
17
samples/Mathematica/UnitTest.wlt
Normal file
17
samples/Mathematica/UnitTest.wlt
Normal file
@@ -0,0 +1,17 @@
|
||||
BeginTestSection["Untitled-5"]
|
||||
|
||||
VerificationTest[(* 1 *)
|
||||
RotationMatrix[phi]
|
||||
,
|
||||
List[List[Cos[phi], Times[-1, Sin[phi]]], List[Sin[phi], Cos[phi]]]
|
||||
]
|
||||
|
||||
VerificationTest[(* 2 *)
|
||||
Times[1, Power[Plus[a, Times[-1, a]], -1]]
|
||||
,
|
||||
ComplexInfinity
|
||||
,
|
||||
{Power::infy}
|
||||
]
|
||||
|
||||
EndTestSection[]
|
||||
46
samples/Mercury/switch_detection_bug.m
Normal file
46
samples/Mercury/switch_detection_bug.m
Normal file
@@ -0,0 +1,46 @@
|
||||
% This is a regression test for a bug in switch detection
|
||||
% where it was preferring incomplete switches to complete
|
||||
% one-case switches, and hence inferring the wrong determinism.
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
|
||||
:- module switch_detection_bug.
|
||||
|
||||
:- interface.
|
||||
|
||||
:- type note ---> note(rank, modifier, octave).
|
||||
|
||||
:- type rank ---> c ; d ; e ; f ; g ; a ; b .
|
||||
|
||||
:- type modifier ---> natural ; sharp ; flat .
|
||||
|
||||
:- type octave == int.
|
||||
|
||||
:- type qualifier ---> maj ; min .
|
||||
|
||||
:- pred next_topnote(note, qualifier, note).
|
||||
:- mode next_topnote(in, in, out) is multi.
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
|
||||
:- implementation.
|
||||
|
||||
next_topnote(note(c, _, Oct), _, note(d, natural, Oct)).
|
||||
next_topnote(note(d, _, Oct), _, note(c, natural, Oct)).
|
||||
next_topnote(note(d, _, Oct), maj, note(e, natural, Oct)).
|
||||
next_topnote(note(d, _, Oct), min, note(e, flat, Oct)).
|
||||
next_topnote(note(e, _, Oct), _, note(d, natural, Oct)).
|
||||
next_topnote(note(e, _, Oct), _, note(f, natural, Oct)).
|
||||
next_topnote(note(f, _, Oct), maj, note(e, natural, Oct)).
|
||||
next_topnote(note(f, _, Oct), min, note(e, flat, Oct)).
|
||||
next_topnote(note(g, _, Oct), _, note(f, natural, Oct)).
|
||||
next_topnote(note(g, _, Oct), min, note(a, flat, Oct)).
|
||||
next_topnote(note(g, _, Oct), maj, note(a, natural, Oct)).
|
||||
next_topnote(note(a, _, Oct), _, note(g, natural, Oct)).
|
||||
next_topnote(note(a, _, Oct), min, note(b, flat, Oct)).
|
||||
next_topnote(note(a, _, Oct), maj, note(b, natural, Oct)).
|
||||
next_topnote(note(b, _, Oct), maj, note(a, natural, Oct)).
|
||||
next_topnote(note(b, _, Oct), min, note(a, flat, Oct)).
|
||||
|
||||
%------------------------------------------------------------------------------%
|
||||
|
||||
5281
samples/Modelica/Translational.mo
Normal file
5281
samples/Modelica/Translational.mo
Normal file
File diff suppressed because it is too large
Load Diff
285
samples/Modelica/modelica.mo
Normal file
285
samples/Modelica/modelica.mo
Normal file
@@ -0,0 +1,285 @@
|
||||
within Modelica.Electrical.Analog;
|
||||
package Sensors "Potential, voltage, current, and power sensors"
|
||||
|
||||
extends Modelica.Icons.SensorsPackage;
|
||||
|
||||
model PotentialSensor "Sensor to measure the potential"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "pin to be measured" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput phi
|
||||
"Absolute voltage potential as output signal"
|
||||
annotation (Placement(transformation(extent={{100,-10},{120,10}},
|
||||
rotation=0)));
|
||||
equation
|
||||
p.i = 0;
|
||||
phi = p.v;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="V"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Line(points={{100,0},{70,0}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{100,0},{70,0}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The potential sensor converts the voltage of a node (with respect to the ground node) into a real valued signal. It does not influence the current sum at the node which voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end PotentialSensor;
|
||||
|
||||
model VoltageSensor "Sensor to measure the voltage between two pins"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "positive pin" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Interfaces.NegativePin n "negative pin" annotation (Placement(
|
||||
transformation(extent={{90,-10},{110,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput v
|
||||
"Voltage between pin p and n (= p.v - n.v) as output signal"
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-100},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
|
||||
equation
|
||||
p.i = 0;
|
||||
n.i = 0;
|
||||
v = p.v - n.v;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="V"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{90,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{96,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The voltage sensor converts the voltage between the two connectors into a real valued signal. It does not influence the current sum at the nodes in between the voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end VoltageSensor;
|
||||
|
||||
model CurrentSensor "Sensor to measure the current in a branch"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "positive pin" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Interfaces.NegativePin n "negative pin" annotation (Placement(
|
||||
transformation(extent={{90,-10},{110,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput i
|
||||
"current in the branch from p to n as output signal"
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-100},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
|
||||
equation
|
||||
p.v = n.v;
|
||||
p.i = i;
|
||||
n.i = -i;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="A"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{70,0},{90,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-153,79},{147,119}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{96,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The current sensor converts the current flowing between the two connectors into a real valued signal. The two connectors are in the sensor connected like a short cut. The sensor has to be placed within an electrical connection in series. It does not influence the current sum at the connected nodes. Therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end CurrentSensor;
|
||||
|
||||
model PowerSensor "Sensor to measure the power"
|
||||
|
||||
Modelica.Electrical.Analog.Interfaces.PositivePin pc
|
||||
"Positive pin, current path"
|
||||
annotation (Placement(transformation(extent={{-90,-10},{-110,10}}, rotation=
|
||||
0)));
|
||||
Modelica.Electrical.Analog.Interfaces.NegativePin nc
|
||||
"Negative pin, current path"
|
||||
annotation (Placement(transformation(extent={{110,-10},{90,10}}, rotation=0)));
|
||||
Modelica.Electrical.Analog.Interfaces.PositivePin pv
|
||||
"Positive pin, voltage path"
|
||||
annotation (Placement(transformation(extent={{-10,110},{10,90}}, rotation=0)));
|
||||
Modelica.Electrical.Analog.Interfaces.NegativePin nv
|
||||
"Negative pin, voltage path"
|
||||
annotation (Placement(transformation(extent={{10,-110},{-10,-90}}, rotation=
|
||||
0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput power
|
||||
annotation (Placement(transformation(
|
||||
origin={-80,-110},
|
||||
extent={{-10,10},{10,-10}},
|
||||
rotation=270)));
|
||||
Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensor
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-30},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor
|
||||
annotation (Placement(transformation(extent={{-50,-10},{-30,10}}, rotation=
|
||||
0)));
|
||||
Modelica.Blocks.Math.Product product
|
||||
annotation (Placement(transformation(
|
||||
origin={-30,-50},
|
||||
extent={{-10,-10},{10,10}},
|
||||
rotation=270)));
|
||||
|
||||
equation
|
||||
connect(pv, voltageSensor.p) annotation (Line(points={{0,100},{0,-20},{
|
||||
6.12323e-016,-20}}, color={0,0,255}));
|
||||
connect(voltageSensor.n, nv) annotation (Line(points={{-6.12323e-016,-40},{
|
||||
-6.12323e-016,-63},{0,-63},{0,-100}}, color={0,0,255}));
|
||||
connect(pc, currentSensor.p)
|
||||
annotation (Line(points={{-100,0},{-50,0}}, color={0,0,255}));
|
||||
connect(currentSensor.n, nc)
|
||||
annotation (Line(points={{-30,0},{100,0}}, color={0,0,255}));
|
||||
connect(currentSensor.i, product.u2) annotation (Line(points={{-40,-10},{-40,
|
||||
-30},{-36,-30},{-36,-38}}, color={0,0,127}));
|
||||
connect(voltageSensor.v, product.u1) annotation (Line(points={{10,-30},{-24,
|
||||
-30},{-24,-38}}, color={0,0,127}));
|
||||
connect(product.y, power) annotation (Line(points={{-30,-61},{-30,-80},{-80,
|
||||
-80},{-80,-110}}, color={0,0,127}));
|
||||
annotation (Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={2,2}), graphics={
|
||||
Ellipse(
|
||||
extent={{-70,70},{70,-70}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={255,255,255},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Line(points={{0,100},{0,70}}, color={0,0,255}),
|
||||
Line(points={{0,-70},{0,-100}}, color={0,0,255}),
|
||||
Line(points={{-80,-100},{-80,0}}, color={0,0,255}),
|
||||
Line(points={{-100,0},{100,0}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{150,120},{-150,160}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{0,70},{0,40}}, color={0,0,0}),
|
||||
Line(points={{22.9,32.8},{40.2,57.3}}, color={0,0,0}),
|
||||
Line(points={{-22.9,32.8},{-40.2,57.3}}, color={0,0,0}),
|
||||
Line(points={{37.6,13.7},{65.8,23.9}}, color={0,0,0}),
|
||||
Line(points={{-37.6,13.7},{-65.8,23.9}}, color={0,0,0}),
|
||||
Line(points={{0,0},{9.02,28.6}}, color={0,0,0}),
|
||||
Polygon(
|
||||
points={{-0.48,31.6},{18,26},{18,57.2},{-0.48,31.6}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={0,0,0},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Ellipse(
|
||||
extent={{-5,5},{5,-5}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={0,0,0},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="P")}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={2,2}), graphics),
|
||||
Documentation(info="<html>
|
||||
<p>This power sensor measures instantaneous electrical power of a singlephase system and has a separated voltage and current path. The pins of the voltage path are pv and nv, the pins of the current path are pc and nc. The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.</p>
|
||||
</html>", revisions="<html>
|
||||
<ul>
|
||||
<li><i>January 12, 2006</i> by Anton Haumer implemented</li>
|
||||
</ul>
|
||||
</html>"));
|
||||
end PowerSensor;
|
||||
annotation (
|
||||
Documentation(info="<html>
|
||||
<p>This package contains potential, voltage, and current sensors. The sensors can be used to convert voltages or currents into real signal values o be connected to components of the Blocks package. The sensors are designed in such a way that they do not influence the electrical behavior.</p>
|
||||
</html>",
|
||||
revisions="<html>
|
||||
<dl>
|
||||
<dt>
|
||||
<b>Main Authors:</b>
|
||||
<dd>
|
||||
Christoph Clauß
|
||||
<<a href=\"mailto:Christoph.Clauss@eas.iis.fraunhofer.de\">Christoph.Clauss@eas.iis.fraunhofer.de</a>><br>
|
||||
André Schneider
|
||||
<<a href=\"mailto:Andre.Schneider@eas.iis.fraunhofer.de\">Andre.Schneider@eas.iis.fraunhofer.de</a>><br>
|
||||
Fraunhofer Institute for Integrated Circuits<br>
|
||||
Design Automation Department<br>
|
||||
Zeunerstraße 38<br>
|
||||
D-01069 Dresden<br>
|
||||
<p>
|
||||
<dt>
|
||||
<b>Copyright:</b>
|
||||
<dd>
|
||||
Copyright © 1998-2010, Modelica Association and Fraunhofer-Gesellschaft.<br>
|
||||
<i>The Modelica package is <b>free</b> software; it can be redistributed and/or modified
|
||||
under the terms of the <b>Modelica license</b>, see the license conditions
|
||||
and the accompanying <b>disclaimer</b> in the documentation of package
|
||||
Modelica in file \"Modelica/package.mo\".</i><br>
|
||||
<p>
|
||||
</dl>
|
||||
</html>"));
|
||||
end Sensors;
|
||||
84
samples/NL/assign0.nl
Normal file
84
samples/NL/assign0.nl
Normal file
@@ -0,0 +1,84 @@
|
||||
g3 0 1 0 # problem assign0
|
||||
9 6 1 0 6 # vars, constraints, objectives, ranges, eqns
|
||||
0 0 # nonlinear constraints, objectives
|
||||
0 0 # network constraints: nonlinear, linear
|
||||
0 0 0 # nonlinear vars in constraints, objectives, both
|
||||
0 0 0 1 # linear network variables; functions; arith, flags
|
||||
9 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o)
|
||||
18 9 # nonzeros in Jacobian, gradients
|
||||
0 0 # max name lengths: constraints, variables
|
||||
0 0 0 0 0 # common exprs: b,c,o,c1,o1
|
||||
C0
|
||||
n0
|
||||
C1
|
||||
n0
|
||||
C2
|
||||
n0
|
||||
C3
|
||||
n0
|
||||
C4
|
||||
n0
|
||||
C5
|
||||
n0
|
||||
O0 0
|
||||
n0
|
||||
r
|
||||
4 1
|
||||
4 1
|
||||
4 1
|
||||
4 1
|
||||
4 1
|
||||
4 1
|
||||
b
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
0 0 1
|
||||
k8
|
||||
2
|
||||
4
|
||||
6
|
||||
8
|
||||
10
|
||||
12
|
||||
14
|
||||
16
|
||||
J0 3
|
||||
0 1
|
||||
1 1
|
||||
2 1
|
||||
J1 3
|
||||
3 1
|
||||
4 1
|
||||
5 1
|
||||
J2 3
|
||||
6 1
|
||||
7 1
|
||||
8 1
|
||||
J3 3
|
||||
0 1
|
||||
3 1
|
||||
6 1
|
||||
J4 3
|
||||
1 1
|
||||
4 1
|
||||
7 1
|
||||
J5 3
|
||||
2 1
|
||||
5 1
|
||||
8 1
|
||||
G0 9
|
||||
0 1
|
||||
1 3
|
||||
2 3
|
||||
3 2
|
||||
4 3
|
||||
5 3
|
||||
6 3
|
||||
7 3
|
||||
8 2
|
||||
2284
samples/NL/balassign0.nl
Normal file
2284
samples/NL/balassign0.nl
Normal file
File diff suppressed because it is too large
Load Diff
78
samples/NetLinx+ERB/sample.axi.erb
Normal file
78
samples/NetLinx+ERB/sample.axi.erb
Normal file
@@ -0,0 +1,78 @@
|
||||
(***********************************************************
|
||||
Sample File
|
||||
|
||||
For testing syntax highlighting
|
||||
************************************************************)
|
||||
|
||||
#if_not_defined Sample
|
||||
#define Sample 1
|
||||
(***********************************************************)
|
||||
(* System Type : NetLinx *)
|
||||
(***********************************************************)
|
||||
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_DEVICE
|
||||
|
||||
(***********************************************************)
|
||||
(* CONSTANT DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_CONSTANT
|
||||
|
||||
<% global_constant_justify = 20 -%>
|
||||
// Video Source Select Buttons
|
||||
<%=
|
||||
video_sources = {
|
||||
BTN_VID_FOH_PC: { btn: 11, input: :VID_SRC_FOH_PC },
|
||||
BTN_VID_STAGE_PC: { btn: 12, input: :VID_SRC_STAGE_PC },
|
||||
BTN_VID_BLURAY: { btn: 13, input: :VID_SRC_BLURAY },
|
||||
}
|
||||
|
||||
print_constant_hash video_sources.remap(:btn),
|
||||
justify: global_constant_justify
|
||||
%>
|
||||
|
||||
(***********************************************************)
|
||||
(* INCLUDES GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
(***********************************************************)
|
||||
(* DATA TYPE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_TYPE
|
||||
|
||||
(***********************************************************)
|
||||
(* VARIABLE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_VARIABLE
|
||||
|
||||
(***********************************************************)
|
||||
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
(***********************************************************)
|
||||
(* STARTUP CODE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_START
|
||||
|
||||
(***********************************************************)
|
||||
(* THE EVENTS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_EVENT
|
||||
|
||||
// Video Source Select
|
||||
<%=
|
||||
justify group(video_sources.remap :input) { |name, input|
|
||||
"[#{@dvTP}, #{name}] = (outputs[VID_DEST_PROJECTOR].input == #{input});"
|
||||
}
|
||||
%>
|
||||
|
||||
(***********************************************************)
|
||||
(* THE MAINLINE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_PROGRAM
|
||||
|
||||
(***********************************************************)
|
||||
(* END OF PROGRAM *)
|
||||
(* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
|
||||
(***********************************************************)
|
||||
#end_if
|
||||
78
samples/NetLinx+ERB/sample.axs.erb
Normal file
78
samples/NetLinx+ERB/sample.axs.erb
Normal file
@@ -0,0 +1,78 @@
|
||||
(***********************************************************
|
||||
Sample File
|
||||
|
||||
For testing syntax highlighting
|
||||
************************************************************)
|
||||
|
||||
#if_not_defined Sample
|
||||
#define Sample 1
|
||||
(***********************************************************)
|
||||
(* System Type : NetLinx *)
|
||||
(***********************************************************)
|
||||
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_DEVICE
|
||||
|
||||
(***********************************************************)
|
||||
(* CONSTANT DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_CONSTANT
|
||||
|
||||
<% global_constant_justify = 20 -%>
|
||||
// Video Source Select Buttons
|
||||
<%=
|
||||
video_sources = {
|
||||
BTN_VID_FOH_PC: { btn: 11, input: :VID_SRC_FOH_PC },
|
||||
BTN_VID_STAGE_PC: { btn: 12, input: :VID_SRC_STAGE_PC },
|
||||
BTN_VID_BLURAY: { btn: 13, input: :VID_SRC_BLURAY },
|
||||
}
|
||||
|
||||
print_constant_hash video_sources.remap(:btn),
|
||||
justify: global_constant_justify
|
||||
%>
|
||||
|
||||
(***********************************************************)
|
||||
(* INCLUDES GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
(***********************************************************)
|
||||
(* DATA TYPE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_TYPE
|
||||
|
||||
(***********************************************************)
|
||||
(* VARIABLE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_VARIABLE
|
||||
|
||||
(***********************************************************)
|
||||
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
(***********************************************************)
|
||||
(* STARTUP CODE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_START
|
||||
|
||||
(***********************************************************)
|
||||
(* THE EVENTS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_EVENT
|
||||
|
||||
// Video Source Select
|
||||
<%=
|
||||
justify group(video_sources.remap :input) { |name, input|
|
||||
"[#{@dvTP}, #{name}] = (outputs[VID_DEST_PROJECTOR].input == #{input});"
|
||||
}
|
||||
%>
|
||||
|
||||
(***********************************************************)
|
||||
(* THE MAINLINE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_PROGRAM
|
||||
|
||||
(***********************************************************)
|
||||
(* END OF PROGRAM *)
|
||||
(* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
|
||||
(***********************************************************)
|
||||
#end_if
|
||||
132
samples/NetLinx/projector.axi
Normal file
132
samples/NetLinx/projector.axi
Normal file
@@ -0,0 +1,132 @@
|
||||
(***********************************************************
|
||||
Mock Projector
|
||||
|
||||
For testing syntax highlighting
|
||||
************************************************************)
|
||||
|
||||
#if_not_defined MOCK_PROJECTOR
|
||||
#define MOCK_PROJECTOR 1
|
||||
(***********************************************************)
|
||||
(* System Type : NetLinx *)
|
||||
(***********************************************************)
|
||||
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_DEVICE
|
||||
|
||||
dvPROJECTOR = 5001:1:0;
|
||||
|
||||
(***********************************************************)
|
||||
(* CONSTANT DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_CONSTANT
|
||||
|
||||
// Power States
|
||||
POWER_STATE_ON = 0;
|
||||
POWER_STATE_OFF = 1;
|
||||
POWER_STATE_WARMING = 2;
|
||||
POWER_STATE_COOLING = 3;
|
||||
|
||||
// Inputs
|
||||
INPUT_HDMI = 0;
|
||||
INPUT_VGA = 1;
|
||||
INPUT_COMPOSITE = 2;
|
||||
INPUT_SVIDEO = 3;
|
||||
|
||||
(***********************************************************)
|
||||
(* INCLUDES GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
#include 'amx-lib-log'
|
||||
|
||||
(***********************************************************)
|
||||
(* DATA TYPE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_TYPE
|
||||
|
||||
struct projector_t
|
||||
{
|
||||
integer power_state;
|
||||
integer input;
|
||||
integer lamp_hours;
|
||||
}
|
||||
|
||||
(***********************************************************)
|
||||
(* VARIABLE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_VARIABLE
|
||||
|
||||
volatile projector_t proj_1;
|
||||
|
||||
(***********************************************************)
|
||||
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
define_function initialize(projector_t self)
|
||||
{
|
||||
self.power_state = POWER_STATE_OFF;
|
||||
self.input = INPUT_HDMI;
|
||||
self.lamp_hours = 0;
|
||||
}
|
||||
|
||||
define_function switch_input(projector_t self, integer input)
|
||||
{
|
||||
self.input = input;
|
||||
print(LOG_LEVEL_INFO, "'Projector set to input: ', itoa(input)");
|
||||
}
|
||||
|
||||
(***********************************************************)
|
||||
(* STARTUP CODE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_START
|
||||
|
||||
initialize(proj_1);
|
||||
|
||||
(***********************************************************)
|
||||
(* THE EVENTS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_EVENT
|
||||
|
||||
data_event[dvPROJECTOR]
|
||||
{
|
||||
string:
|
||||
{
|
||||
parse_message(data.text);
|
||||
}
|
||||
|
||||
command: {}
|
||||
online: {}
|
||||
offline: {}
|
||||
}
|
||||
|
||||
button_event[dvTP, BTN_HDMI]
|
||||
button_event[dvTP, BTN_VGA]
|
||||
button_event[dvTP, BTN_COMPOSITE]
|
||||
button_event[dvTP, BTN_SVIDEO]
|
||||
{
|
||||
push:
|
||||
{
|
||||
switch (button.input.channel)
|
||||
{
|
||||
case BTN_HDMI: switch_input(proj_1, INPUT_HDMI);
|
||||
case BTN_VGA: switch_input(proj_1, INPUT_VGA);
|
||||
case BTN_COMPOSITE: switch_input(proj_1, INPUT_COMPOSITE);
|
||||
case BTN_SVIDEO: switch_input(proj_1, INPUT_SVIDEO);
|
||||
}
|
||||
}
|
||||
|
||||
release: {}
|
||||
}
|
||||
|
||||
(***********************************************************)
|
||||
(* THE MAINLINE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_PROGRAM
|
||||
|
||||
[dvTP, BTN_POWER_ON] = (proj_1.power_state == POWER_STATE_ON);
|
||||
[dvTP, BTN_POWER_OFF] = (proj_1.power_state == POWER_STATE_OFF);
|
||||
|
||||
(***********************************************************)
|
||||
(* END OF PROGRAM *)
|
||||
(* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
|
||||
(***********************************************************)
|
||||
#end_if
|
||||
158
samples/NetLinx/volume-array.axs
Normal file
158
samples/NetLinx/volume-array.axs
Normal file
@@ -0,0 +1,158 @@
|
||||
(***********************************************************
|
||||
AMX VOLUME CONTROL
|
||||
VOLUME ARRAY EXAMPLE
|
||||
|
||||
Website: https://sourceforge.net/projects/amx-lib-volume/
|
||||
|
||||
|
||||
This application demonstrates the use of volume control
|
||||
arrays using the amx-lib-volume library.
|
||||
|
||||
Volume control operation can be viewed by watching the
|
||||
master's internal diagnostic output.
|
||||
|
||||
I/O PORT CONNECTIONS:
|
||||
Ch 1: Volume Up Button
|
||||
Ch 2: Volume Down Button
|
||||
************************************************************
|
||||
Copyright 2011, 2012, 2014 Alex McLain
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
************************************************************)
|
||||
|
||||
PROGRAM_NAME='volume array'
|
||||
(***********************************************************)
|
||||
(***********************************************************)
|
||||
(* System Type : NetLinx *)
|
||||
(***********************************************************)
|
||||
(* REV HISTORY: *)
|
||||
(***********************************************************)
|
||||
(*
|
||||
$History: See version control repository.
|
||||
*)
|
||||
(***********************************************************)
|
||||
(* INCLUDES GO BELOW *)
|
||||
(***********************************************************)
|
||||
|
||||
// Include the volume control library.
|
||||
#include 'amx-lib-volume'
|
||||
|
||||
(***********************************************************)
|
||||
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_DEVICE
|
||||
|
||||
dvDebug = 0:0:0; // For debug output.
|
||||
|
||||
dvIO = 36000:1:0; // Volume up/down button connections.
|
||||
|
||||
(***********************************************************)
|
||||
(* CONSTANT DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_CONSTANT
|
||||
|
||||
// Volume control indexes.
|
||||
MIC1 = 1; // Microphone 1.
|
||||
MIC2 = 2; // Microphone 2.
|
||||
MIC3 = 3; // Microphone 3.
|
||||
MIC4 = 4; // Microphone 4.
|
||||
WLS1 = 5; // Wireless mic 1.
|
||||
WLS2 = 6; // Wireless mic 2.
|
||||
IPOD = 7; // iPod input.
|
||||
CD = 8; // CD player input.
|
||||
|
||||
(***********************************************************)
|
||||
(* DATA TYPE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_TYPE
|
||||
|
||||
(***********************************************************)
|
||||
(* VARIABLE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_VARIABLE
|
||||
|
||||
// Define a volume control array for the input devices.
|
||||
volume inputs[8];
|
||||
|
||||
(***********************************************************)
|
||||
(* LATCHING DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_LATCHING
|
||||
|
||||
(***********************************************************)
|
||||
(* MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_MUTUALLY_EXCLUSIVE
|
||||
|
||||
(***********************************************************)
|
||||
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
|
||||
(***********************************************************)
|
||||
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
|
||||
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
|
||||
|
||||
(***********************************************************)
|
||||
(* STARTUP CODE GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_START
|
||||
|
||||
// Initialize the array of volume controls.
|
||||
volArrayInit(inputs, 0, VOL_UNMUTED, 10000, 20000, 5);
|
||||
|
||||
(***********************************************************)
|
||||
(* THE EVENTS GO BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_EVENT
|
||||
|
||||
// Volume Up
|
||||
button_event[dvIO, 1]
|
||||
{
|
||||
PUSH:
|
||||
{
|
||||
volArrayIncrement(inputs); // Increment the volume up a step.
|
||||
send_string dvDebug, "'Volume Up MIC1: ', itoa(volGetLevel(inputs[MIC1]))";
|
||||
send_string dvDebug, "'Volume Up MIC2: ', itoa(volGetLevel(inputs[MIC2]))";
|
||||
send_string dvDebug, "'Volume Up MIC3: ', itoa(volGetLevel(inputs[MIC3]))";
|
||||
send_string dvDebug, "'Volume Up MIC4: ', itoa(volGetLevel(inputs[MIC4]))";
|
||||
send_string dvDebug, "'Volume Up WLS1: ', itoa(volGetLevel(inputs[WLS1]))";
|
||||
send_string dvDebug, "'Volume Up WLS2: ', itoa(volGetLevel(inputs[WLS2]))";
|
||||
send_string dvDebug, "'Volume Up IPOD: ', itoa(volGetLevel(inputs[IPOD]))";
|
||||
send_string dvDebug, "'Volume Up CD: ', itoa(volGetLevel(inputs[CD]))";
|
||||
}
|
||||
}
|
||||
|
||||
// Volume Down
|
||||
button_event[dvIO, 2]
|
||||
{
|
||||
PUSH:
|
||||
{
|
||||
volArrayDecrement(inputs); // Decrement the volume down a step.
|
||||
send_string dvDebug, "'Volume Dn MIC1: ', itoa(volGetLevel(inputs[MIC1]))";
|
||||
send_string dvDebug, "'Volume Dn MIC2: ', itoa(volGetLevel(inputs[MIC2]))";
|
||||
send_string dvDebug, "'Volume Dn MIC3: ', itoa(volGetLevel(inputs[MIC3]))";
|
||||
send_string dvDebug, "'Volume Dn MIC4: ', itoa(volGetLevel(inputs[MIC4]))";
|
||||
send_string dvDebug, "'Volume Dn WLS1: ', itoa(volGetLevel(inputs[WLS1]))";
|
||||
send_string dvDebug, "'Volume Dn WLS2: ', itoa(volGetLevel(inputs[WLS2]))";
|
||||
send_string dvDebug, "'Volume Dn IPOD: ', itoa(volGetLevel(inputs[IPOD]))";
|
||||
send_string dvDebug, "'Volume Dn CD: ', itoa(volGetLevel(inputs[CD]))";
|
||||
}
|
||||
}
|
||||
|
||||
(***********************************************************)
|
||||
(* THE ACTUAL PROGRAM GOES BELOW *)
|
||||
(***********************************************************)
|
||||
DEFINE_PROGRAM
|
||||
|
||||
(***********************************************************)
|
||||
(* END OF PROGRAM *)
|
||||
(* DO NOT PUT ANY CODE BELOW THIS COMMENT *)
|
||||
(***********************************************************)
|
||||
239
samples/NewLisp/irc.lsp
Normal file
239
samples/NewLisp/irc.lsp
Normal file
@@ -0,0 +1,239 @@
|
||||
#!/usr/bin/env newlisp
|
||||
|
||||
;; @module IRC
|
||||
;; @description a basic irc library
|
||||
;; @version early alpha! 0.1 2013-01-02 20:11:22
|
||||
;; @author cormullion
|
||||
;; Usage:
|
||||
;; (IRC:init "newlithper") ; a username/nick (not that one obviously :-)
|
||||
;; (IRC:connect "irc.freenode.net" 6667) ; irc/server
|
||||
;; (IRC:join-channel {#newlisp}) ; join a room
|
||||
;; either (IRC:read-irc-loop) ; loop - monitor only, no input
|
||||
;; or (IRC:session) ; a command-line session, end with /QUIT
|
||||
|
||||
(context 'IRC)
|
||||
(define Inickname)
|
||||
(define Ichannels)
|
||||
(define Iserver)
|
||||
(define Iconnected)
|
||||
(define Icallbacks '())
|
||||
(define Idle-time 400) ; seconds
|
||||
(define Itime-stamp) ; time since last message was processed
|
||||
|
||||
(define (register-callback callback-name callback-function)
|
||||
(println {registering callback for } callback-name { : } (sym (term callback-function) (prefix callback-function)))
|
||||
(push (list callback-name (sym (term callback-function) (prefix callback-function))) Icallbacks))
|
||||
|
||||
(define (deregister-callback callback-name)
|
||||
(println {deregistering callback for } callback-name)
|
||||
(setf (assoc "idle-event" Icallbacks) nil)
|
||||
(println {current callbacks: } Icallbacks))
|
||||
|
||||
(define (do-callback callback-name data)
|
||||
(when (set 'func (lookup callback-name Icallbacks)) ; find first callback
|
||||
(if-not (catch (apply func (list data)) 'error)
|
||||
(println {error in callback } callback-name {: } error))))
|
||||
|
||||
(define (do-callbacks callback-name data)
|
||||
(dolist (rf (ref-all callback-name Icallbacks))
|
||||
(set 'callback-entry (Icallbacks (first rf)))
|
||||
(when (set 'func (last callback-entry))
|
||||
(if-not (catch (apply func (list data)) 'error)
|
||||
(println {error in callback } callback-name {: } error)))))
|
||||
|
||||
(define (init str)
|
||||
(set 'Inickname str)
|
||||
(set 'Iconnected nil)
|
||||
(set 'Ichannels '())
|
||||
(set 'Itime-stamp (time-of-day)))
|
||||
|
||||
(define (connect server port)
|
||||
(set 'Iserver (net-connect server port))
|
||||
(net-send Iserver (format "USER %s %s %s :%s\r\n" Inickname Inickname Inickname Inickname))
|
||||
(net-send Iserver (format "NICK %s \r\n" Inickname))
|
||||
(set 'Iconnected true)
|
||||
(do-callbacks "connect" (list (list "server" server) (list "port" port))))
|
||||
|
||||
(define (identify password)
|
||||
(net-send Iserver (format "PRIVMSG nickserv :identify %s\r\n" password)))
|
||||
|
||||
(define (join-channel channel)
|
||||
(when (net-send Iserver (format "JOIN %s \r\n" channel))
|
||||
(push channel Ichannels)
|
||||
(do-callbacks "join-channel" (list (list "channel" channel) (list "nickname" Inickname)))))
|
||||
|
||||
(define (part chan)
|
||||
(if-not (empty? chan)
|
||||
; leave specified
|
||||
(begin
|
||||
(net-send Iserver (format "PART %s\r\n" chan))
|
||||
(replace channel Ichannels)
|
||||
(do-callbacks "part" (list (list "channel" channel))))
|
||||
; leave all
|
||||
(begin
|
||||
(dolist (channel Ichannels)
|
||||
(net-send Iserver (format "PART %s\r\n" channel))
|
||||
(replace channel Ichannels)
|
||||
(do-callbacks "part" (list (list "channel" channel)))))))
|
||||
|
||||
(define (do-quit message)
|
||||
(do-callbacks "quit" '()) ; chance to do stuff before quit...
|
||||
(net-send Iserver (format "QUIT :%s\r\n" message))
|
||||
(sleep 1000)
|
||||
(set 'Ichannels '())
|
||||
(close Iserver)
|
||||
(set 'Iconnected nil))
|
||||
|
||||
(define (privmsg user message)
|
||||
(net-send Iserver (format "PRIVMSG %s :%s\r\n" user message)))
|
||||
|
||||
(define (notice user message)
|
||||
(net-send Iserver (format "NOTICE %s :%s\r\n" user message)))
|
||||
|
||||
(define (send-to-server message (channel nil))
|
||||
(cond
|
||||
((starts-with message {/}) ; default command character
|
||||
(set 'the-message (replace "^/" (copy message) {} 0)) ; keep original
|
||||
(net-send Iserver (format "%s \r\n" the-message)) ; send it
|
||||
; do a quit
|
||||
(if (starts-with (lower-case the-message) "quit")
|
||||
(do-quit { enough})))
|
||||
(true
|
||||
(if (nil? channel)
|
||||
; say to all channels
|
||||
(dolist (c Ichannels)
|
||||
(net-send Iserver (format "PRIVMSG %s :%s\r\n" c message)))
|
||||
; say to specified channel
|
||||
(if (find channel Ichannels)
|
||||
(net-send Iserver (format "PRIVMSG %s :%s\r\n" channel message))))))
|
||||
(do-callbacks "send-to-server" (list (list "channel" channel) (list "message" message))))
|
||||
|
||||
(define (process-command sender command text)
|
||||
(cond
|
||||
((= sender "PING")
|
||||
(net-send Iserver (format "PONG %s\r\n" command)))
|
||||
((or (= command "NOTICE") (= command "PRIVMSG"))
|
||||
(process-message sender command text))
|
||||
((= command "JOIN")
|
||||
(set 'username (first (clean empty? (parse sender {!|:} 0))))
|
||||
(set 'channel (last (clean empty? (parse sender {!|:} 0))))
|
||||
(println {username } username { joined } channel)
|
||||
(do-callbacks "join" (list (list "channel" channel) (list "username" username))))
|
||||
(true
|
||||
nil)))
|
||||
|
||||
(define (process-message sender command text)
|
||||
(let ((username {} target {} message {}))
|
||||
(set 'username (first (clean empty? (parse sender {!|:} 0))))
|
||||
(set 'target (trim (first (clean empty? (parse text {!|:} 0)))))
|
||||
(set 'message (slice text (+ (find {:} text) 1)))
|
||||
(cond
|
||||
((starts-with message "\001")
|
||||
(process-ctcp username target message))
|
||||
((find target Ichannels)
|
||||
(cond
|
||||
((= command {PRIVMSG})
|
||||
(do-callbacks "channel-message" (list (list "channel" target) (list "username" username) (list "message" message))))
|
||||
((= command {NOTICE})
|
||||
(do-callbacks "channel-notice" (list (list "channel" target) (list "username" username) (list "message" message))))))
|
||||
((= target Inickname)
|
||||
(cond
|
||||
((= command {PRIVMSG})
|
||||
(do-callbacks "private-message" (list (list "username" username) (list "message" message))))
|
||||
((= command {NOTICE})
|
||||
(do-callbacks "private-notice" (list (list "username" username) (list "message" message))))))
|
||||
(true
|
||||
nil))))
|
||||
|
||||
(define (process-ctcp username target message)
|
||||
(cond
|
||||
((starts-with message "\001VERSION\001")
|
||||
(net-send Iserver (format "NOTICE %s :\001VERSION %s\001\r\n" username message)))
|
||||
((starts-with message "\001PING")
|
||||
(set 'data (first (rest (clean empty? (parse message { } 0)))))
|
||||
(set 'data (trim data "\001" "\001"))
|
||||
(net-send Iserver (format "NOTICE %s :\001PING %s\001\r\n" username data)))
|
||||
((starts-with message "\001ACTION")
|
||||
; (set 'data (first (rest (clean empty? (parse message { } 0)))))
|
||||
; (set 'data (join data { }))
|
||||
; (set 'data (trim data "\001" "\001"))
|
||||
(if (find target Ichannels)
|
||||
(do-callbacks "channel-action" (list (list "username" username) (list "message" message))))
|
||||
(if (= target Inickname)
|
||||
(do-callbacks "private-action" (list (list "username" username) (list "message" message)))))
|
||||
((starts-with message "\001TIME\001")
|
||||
(net-send Iserver (format "NOTICE %s:\001TIME :%s\001\r\n" username (date))))))
|
||||
|
||||
(define (parse-buffer raw-buffer)
|
||||
(let ((messages (clean empty? (parse raw-buffer "\r\n" 0)))
|
||||
(sender {} command {} text {}))
|
||||
; check for elapsed time since last activity
|
||||
(when (> (sub (time-of-day) Itime-stamp) (mul Idle-time 1000))
|
||||
(do-callbacks "idle-event")
|
||||
(set 'Itime-stamp (time-of-day)))
|
||||
(dolist (message messages)
|
||||
(set 'message-parts (parse message { }))
|
||||
(unless (empty? message-parts)
|
||||
(set 'sender (first message-parts))
|
||||
(catch (set 'command (first (rest message-parts))) 'error)
|
||||
(catch (set 'text (join (rest (rest message-parts)) { })) 'error))
|
||||
(process-command sender command text))))
|
||||
|
||||
(define (read-irc)
|
||||
(let ((buffer {}))
|
||||
(when (!= (net-peek Iserver) 0)
|
||||
(net-receive Iserver buffer 8192 "\n")
|
||||
(unless (empty? buffer)
|
||||
(parse-buffer buffer)))))
|
||||
|
||||
(define (read-irc-loop) ; monitoring
|
||||
(let ((buffer {}))
|
||||
(while Iconnected
|
||||
(read-irc)
|
||||
(sleep 1000))))
|
||||
|
||||
(define (print-raw-message data) ; example of using a callback
|
||||
(set 'raw-data (lookup "message" data))
|
||||
(set 'channel (lookup "channel" data))
|
||||
(set 'message-text raw-data)
|
||||
(println (date (date-value) 0 {%H:%M:%S }) username {> } message-text))
|
||||
|
||||
(define (print-outgoing-message data)
|
||||
(set 'raw-data (lookup "message" data))
|
||||
(set 'channel (lookup "channel" data))
|
||||
(set 'message-text raw-data)
|
||||
(println (date (date-value) 0 {%H:%M:%S }) Inickname {> } message-text))
|
||||
|
||||
(define (session); interactive terminal
|
||||
; must add callbacks to display messages
|
||||
(register-callback "channel-message" 'print-raw-message)
|
||||
(register-callback "send-to-server" 'print-outgoing-message)
|
||||
(while Iconnected
|
||||
(while (zero? (peek 0))
|
||||
(read-irc)
|
||||
(sleep 1000))
|
||||
(send-to-server (string (read-line 0))))
|
||||
(println {finished session } (date))
|
||||
(exit))
|
||||
|
||||
; end of IRC code
|
||||
|
||||
[text]
|
||||
|
||||
simple bot code:
|
||||
(load (string (env {HOME}) {/projects/programming/newlisp-projects/irc.lsp}))
|
||||
(context 'BOT)
|
||||
(define bot-name "bot")
|
||||
(define (join-channel data)
|
||||
(println {in BOT:join-channel with data: } data))
|
||||
(define (process-message data)
|
||||
????)
|
||||
(IRC:register-callback "join-channel" 'join-channel)
|
||||
(IRC:register-callback "channel-message" 'process-message)
|
||||
(IRC:register-callback "idle-event" 'do-idle-event)
|
||||
(IRC:register-callback "send-to-server" 'do-send-event)
|
||||
(IRC:init bot-name)
|
||||
(IRC:connect "irc.freenode.net" 6667)
|
||||
(IRC:join-channel {#newlisp})
|
||||
(IRC:read-irc-loop)
|
||||
[/text]
|
||||
195
samples/NewLisp/log-to-database.lisp
Normal file
195
samples/NewLisp/log-to-database.lisp
Normal file
@@ -0,0 +1,195 @@
|
||||
(module "sqlite3.lsp") ; loads the SQLite3 database module
|
||||
|
||||
; FUNCTIONS-------------------------------------------------
|
||||
|
||||
(define (displayln str-to-display)
|
||||
(println str-to-display)
|
||||
)
|
||||
|
||||
(define (open-database sql-db-to-open)
|
||||
(if (sql3:open (string sql-db-to-open ".db"))
|
||||
(displayln "")
|
||||
(displayln "There was a problem opening the database " sql-db-to-open ": " (sql3:error))))
|
||||
|
||||
(define (close-database)
|
||||
(if (sql3:close)
|
||||
(displayln "")
|
||||
(displayln "There was a problem closing the database: " (sql3:error))))
|
||||
|
||||
;====== SAFE-FOR-SQL ===============================================================
|
||||
; this function makes strings safe for inserting into SQL statements
|
||||
; to avoid SQL injection issues
|
||||
; it's simple right now but will add to it later
|
||||
;===================================================================================
|
||||
(define (safe-for-sql str-sql-query)
|
||||
(if (string? str-sql-query) (begin
|
||||
(replace "&" str-sql-query "&")
|
||||
(replace "'" str-sql-query "'")
|
||||
(replace "\"" str-sql-query """)
|
||||
))
|
||||
(set 'result str-sql-query))
|
||||
|
||||
(define (query sql-text)
|
||||
(set 'sqlarray (sql3:sql sql-text)) ; results of query
|
||||
(if sqlarray
|
||||
(setq query-return sqlarray)
|
||||
(if (sql3:error)
|
||||
(displayln (sql3:error) " query problem ")
|
||||
(setq query-return nil))))
|
||||
|
||||
(define-macro (create-record)
|
||||
; first save the values
|
||||
(set 'temp-record-values nil)
|
||||
(set 'temp-table-name (first (args)))
|
||||
;(displayln "<BR>Arguments: " (args))
|
||||
(dolist (s (rest (args))) (push (eval s) temp-record-values -1))
|
||||
; now save the arguments as symbols under the context "DB"
|
||||
(dolist (s (rest (args)))
|
||||
(set 'temp-index-num (string $idx)) ; we need to number the symbols to keep them in the correct order
|
||||
(if (= (length temp-index-num) 1) (set 'temp-index-num (string "0" temp-index-num))) ; leading 0 keeps the max at 100.
|
||||
(sym (string temp-index-num s) 'DB))
|
||||
; now create the sql query
|
||||
(set 'temp-sql-query (string "INSERT INTO " temp-table-name " ("))
|
||||
;(displayln "<P>TABLE NAME: " temp-table-name)
|
||||
;(displayln "<P>SYMBOLS: " (symbols DB))
|
||||
;(displayln "<BR>VALUES: " temp-record-values)
|
||||
(dolist (d (symbols DB)) (extend temp-sql-query (rest (rest (rest (rest (rest (string d)))))) ", "))
|
||||
(set 'temp-sql-query (chop (chop temp-sql-query)))
|
||||
(extend temp-sql-query ") VALUES (")
|
||||
(dolist (q temp-record-values)
|
||||
(if (string? q) (extend temp-sql-query "'")) ; only quote if value is non-numeric
|
||||
(extend temp-sql-query (string (safe-for-sql q)))
|
||||
(if (string? q) (extend temp-sql-query "'")) ; close quote if value is non-numeric
|
||||
(extend temp-sql-query ", ")) ; all values are sanitized to avoid SQL injection
|
||||
(set 'temp-sql-query (chop (chop temp-sql-query)))
|
||||
(extend temp-sql-query ");")
|
||||
;(displayln "<p>***** SQL QUERY: " temp-sql-query)
|
||||
(displayln (query temp-sql-query)) ; actually run the query against the database
|
||||
(delete 'DB) ; we're done, so delete all symbols in the DB context.
|
||||
)
|
||||
|
||||
(define-macro (update-record)
|
||||
; first save the values
|
||||
(set 'temp-record-values nil)
|
||||
(set 'temp-table-name (first (args)))
|
||||
(set 'continue true) ; debugging
|
||||
(dolist (s (rest (args))) (push (eval s) temp-record-values -1))
|
||||
; now save the arguments as symbols under the context "D2"
|
||||
(dolist (st (rest (args)))
|
||||
(set 'temp-index-num (string $idx)) ; we need to number the symbols to keep them in the correct order
|
||||
(if (= (length temp-index-num) 1) (set 'temp-index-num (string "0" temp-index-num))) ; leading 0 keeps the max at 100.
|
||||
;(displayln "<br>SYMBOL>>>>" (string temp-index-num st) "<<<") ; debugging
|
||||
(sym (string temp-index-num st) 'D2)
|
||||
)
|
||||
(if continue (begin ; --- temporary debugging
|
||||
; now create the sql query
|
||||
(set 'temp-sql-query (string "UPDATE " temp-table-name " SET "))
|
||||
;(displayln "<P>TABLE NAME: " temp-table-name)
|
||||
;(displayln "<P>SYMBOLS: " (symbols D2))
|
||||
;(displayln "<BR>VALUES: " temp-record-values)
|
||||
(dolist (d (rest (symbols D2))) ; ignore the first argument, as it will be the ConditionColumn for later
|
||||
(extend temp-sql-query (rest (rest (rest (rest (rest (string d)))))) "=")
|
||||
(set 'q (temp-record-values (+ $idx 1)))
|
||||
(if (string? q) (extend temp-sql-query "'")) ; only quote if value is non-numeric
|
||||
(extend temp-sql-query (string (safe-for-sql q)))
|
||||
(if (string? q) (extend temp-sql-query "'")) ; close quote if value is non-numeric
|
||||
(extend temp-sql-query ", ") ; all values are sanitized to avoid SQL injection
|
||||
)
|
||||
(set 'temp-sql-query (chop (chop temp-sql-query)))
|
||||
; okay now add the ConditionColumn value
|
||||
(extend temp-sql-query (string " WHERE " (rest (rest (rest (rest (rest (string (first (symbols D2)))))))) "="))
|
||||
(if (string? (first temp-record-values)) (extend temp-sql-query "'"))
|
||||
(extend temp-sql-query (string (safe-for-sql (first temp-record-values))))
|
||||
(if (string? (first temp-record-values)) (extend temp-sql-query "'"))
|
||||
(extend temp-sql-query ";")
|
||||
;(displayln "<p>***** SQL QUERY: " temp-sql-query)
|
||||
(query temp-sql-query) ; actually run the query against the database
|
||||
(delete 'D2) ; we're done, so delete all symbols in the DB context.
|
||||
)) ; --- end temporary debugging
|
||||
)
|
||||
|
||||
(define-macro (delete-record)
|
||||
(set 'temp-table-name (first (args)))
|
||||
(set 'temp-record-values nil)
|
||||
(dolist (s (rest (args))) (push (eval s) temp-record-values -1)) ; only one value for NOW...
|
||||
(sym (first (rest (args))) 'DB) ; put the second argument (for now) into a symbol in the DB context
|
||||
; this will have to be in a dolist loop of (rest (args)) when I add more
|
||||
(set 'temp-sql-query (string "DELETE FROM " temp-table-name " WHERE "))
|
||||
(dolist (d (symbols DB)) (extend temp-sql-query (rest (rest (rest (string d))))))
|
||||
(extend temp-sql-query "=")
|
||||
; why am I doing a loop here? There should be only one value, right? But maybe for future extension...
|
||||
(dolist (q temp-record-values)
|
||||
(if (string? q) (extend temp-sql-query "'")) ; only quote if value is non-numeric
|
||||
(extend temp-sql-query (string (safe-for-sql q)))
|
||||
(if (string? q) (extend temp-sql-query "'"))) ; close quote if value is non-numeric
|
||||
(extend temp-sql-query ";")
|
||||
;(displayln "TEMP-DELETE-QUERY: " temp-sql-query)
|
||||
(query temp-sql-query)
|
||||
(delete 'DB) ; we're done, so delete all symbols in the DB context.
|
||||
)
|
||||
|
||||
(define-macro (get-record)
|
||||
(set 'temp-table-name (first (args)))
|
||||
; if you have more arguments than just the table name, they become the elements of the WHERE clause
|
||||
(if (> (length (args)) 1) (begin
|
||||
(set 'temp-record-values nil)
|
||||
(dolist (s (rest (args))) (push (eval s) temp-record-values -1)) ; only one value for NOW...
|
||||
(sym (first (rest (args))) 'DB) ; put the second argument (for now) into a symbol in the DB context
|
||||
; this will have to be in a dolist loop of (rest (args)) when I add more
|
||||
(set 'temp-sql-query (string "SELECT * FROM " temp-table-name " WHERE "))
|
||||
(dolist (d (symbols DB)) (extend temp-sql-query (rest (rest (rest (string d))))))
|
||||
(extend temp-sql-query "=")
|
||||
; why am I doing a loop here? There should be only one value, right? But maybe for future extension...
|
||||
(dolist (q temp-record-values)
|
||||
(if (string? q) (extend temp-sql-query "'")) ; only quote if value is non-numeric
|
||||
(extend temp-sql-query (string (safe-for-sql q)))
|
||||
(if (string? q) (extend temp-sql-query "'"))) ; close quote if value is non-numeric
|
||||
(extend temp-sql-query ";")
|
||||
)
|
||||
; otherwise, just get everything in that table
|
||||
(set 'temp-sql-query (string "SELECT * FROM " temp-table-name ";"))
|
||||
)
|
||||
;(displayln "TEMP-GET-QUERY: " temp-sql-query)
|
||||
(delete 'DB) ; we're done, so delete all symbols in the DB context.
|
||||
(set 'return-value (query temp-sql-query)) ; this returns a list of everything in the record
|
||||
)
|
||||
|
||||
; END FUNCTIONS ===================
|
||||
|
||||
|
||||
(open-database "SERVER-LOGS")
|
||||
(query "CREATE TABLE Logs (Id INTEGER PRIMARY KEY, IP TEXT, UserId TEXT, UserName TEXT, Date DATE, Request TEXT, Result TEXT, Size INTEGER, Referrer TEXT, UserAgent TEXT)")
|
||||
;(print (query "SELECT * from SQLITE_MASTER;"))
|
||||
(set 'access-log (read-file "/var/log/apache2/access.log"))
|
||||
(set 'access-list (parse access-log "\n"))
|
||||
(set 'max-items (integer (first (first (query "select count(*) from Logs")))))
|
||||
(println "Number of items in database: " max-items)
|
||||
(println "Number of lines in log: " (length access-list))
|
||||
(dolist (line access-list)
|
||||
(set 'line-list (parse line))
|
||||
;(println "Line# " $idx " - " line-list)
|
||||
;(println "Length of line: " (length line-list))
|
||||
(if (> (length line-list) 0) (begin
|
||||
(++ max-items)
|
||||
(set 'Id max-items) (print $idx "/" (length access-list))
|
||||
(set 'IP (string (line-list 0) (line-list 1) (line-list 2)))
|
||||
(set 'UserId (line-list 3))
|
||||
(set 'UserName (line-list 4))
|
||||
(set 'Date (line-list 5))
|
||||
(set 'Date (trim Date "["))
|
||||
(set 'Date (trim Date "]"))
|
||||
;(println "DATE: " Date)
|
||||
(set 'date-parsed (date-parse Date "%d/%b/%Y:%H:%M:%S -0700"))
|
||||
;(println "DATE-PARSED: " date-parsed)
|
||||
(set 'Date (date date-parsed 0 "%Y-%m-%dT%H:%M:%S"))
|
||||
(println " " Date)
|
||||
(set 'Request (line-list 6))
|
||||
(set 'Result (line-list 7))
|
||||
(set 'Size (line-list 8))
|
||||
(set 'Referrer (line-list 9))
|
||||
(set 'UserAgent (line-list 10))
|
||||
(create-record "Logs" Id IP UserId UserName Date Request Result Size Referrer UserAgent)
|
||||
))
|
||||
)
|
||||
(close-database)
|
||||
(exit)
|
||||
49
samples/NewLisp/queens.nl
Normal file
49
samples/NewLisp/queens.nl
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env newlisp
|
||||
|
||||
(constant 'NUM 8)
|
||||
|
||||
(define (intersects? q1 q2)
|
||||
(or
|
||||
(= (q1 0) (q2 0))
|
||||
(= (q1 1) (q2 1))
|
||||
(= (abs (- (q1 0) (q2 0))) (abs (- (q1 1) (q2 1))))))
|
||||
|
||||
(define (variant? alist)
|
||||
(set 'logic nil)
|
||||
(cond
|
||||
((= (length alist) 1) true)
|
||||
((> (length alist) 1)
|
||||
(while (> (length alist) 1)
|
||||
(set 'q (pop alist -1))
|
||||
(dolist (el alist)
|
||||
(push
|
||||
(intersects?
|
||||
(list q (inc (length alist)))
|
||||
(list el (+ 1 $idx)))
|
||||
logic -1)))
|
||||
(not (apply or logic)))))
|
||||
|
||||
(define (fork-by-line alist)
|
||||
(let (res '())
|
||||
(dolist (i (sequence 1 NUM))
|
||||
(set 'tmp alist)
|
||||
(push i tmp -1)
|
||||
(setf res (push tmp res -1)))
|
||||
res))
|
||||
|
||||
(define (find-variants num)
|
||||
(let (res '())
|
||||
(cond
|
||||
((< num 1)
|
||||
(begin (println "num < 1") (exit)))
|
||||
((= num 1)
|
||||
(dolist (i (sequence 1 NUM)) (push (list i) res -1)))
|
||||
((> num 1)
|
||||
(dolist (v (find-variants (dec num)))
|
||||
(set 'passed (filter variant? (fork-by-line v)))
|
||||
(if (not (empty? passed)) (extend res passed)))))
|
||||
res))
|
||||
|
||||
(set 'solutions (find-variants NUM))
|
||||
(println (length solutions))
|
||||
;;(exit)
|
||||
1344
samples/OCaml/cmdliner.ml
Normal file
1344
samples/OCaml/cmdliner.ml
Normal file
File diff suppressed because it is too large
Load Diff
14
samples/OCaml/common.ml
Normal file
14
samples/OCaml/common.ml
Normal file
@@ -0,0 +1,14 @@
|
||||
(*
|
||||
* Copyright (c) 2013 Jeremy Yallop.
|
||||
*
|
||||
* This file is distributed under the terms of the MIT License.
|
||||
* See the file LICENSE for details.
|
||||
*)
|
||||
|
||||
let string_of format v =
|
||||
let buf = Buffer.create 100 in
|
||||
let fmt = Format.formatter_of_buffer buf in begin
|
||||
format fmt v;
|
||||
Format.pp_print_flush fmt ();
|
||||
Buffer.contents buf
|
||||
end
|
||||
40
samples/OCaml/date.ml
Normal file
40
samples/OCaml/date.ml
Normal file
@@ -0,0 +1,40 @@
|
||||
(*
|
||||
* Copyright (c) 2013 Jeremy Yallop.
|
||||
*
|
||||
* This file is distributed under the terms of the MIT License.
|
||||
* See the file LICENSE for details.
|
||||
*)
|
||||
|
||||
open Ctypes
|
||||
open PosixTypes
|
||||
open Foreign
|
||||
|
||||
type tm
|
||||
let tm = structure "tm"
|
||||
let (-:) ty label = field tm label ty
|
||||
let tm_sec = int -: "tm_sec" (* seconds *)
|
||||
let tm_min = int -: "tm_min" (* minutes *)
|
||||
let tm_hour = int -: "tm_hour" (* hours *)
|
||||
let tm_mday = int -: "tm_mday" (* day of the month *)
|
||||
let tm_mon = int -: "tm_mon" (* month *)
|
||||
let tm_year = int -: "tm_year" (* year *)
|
||||
let tm_wday = int -: "tm_wday" (* day of the week *)
|
||||
let tm_yday = int -: "tm_yday" (* day in the year *)
|
||||
let tm_isdst = int -: "tm_isdst" (* daylight saving time *)
|
||||
let () = seal (tm : tm structure typ)
|
||||
|
||||
let time = foreign "time" ~check_errno:true (ptr time_t @-> returning time_t)
|
||||
|
||||
let asctime = foreign "asctime" (ptr tm @-> returning string)
|
||||
|
||||
let localtime = foreign "localtime" (ptr time_t @-> returning (ptr tm))
|
||||
|
||||
let () = begin
|
||||
let timep = allocate_n ~count:1 time_t in
|
||||
let time = time timep in
|
||||
assert (time = !@timep);
|
||||
let tm = localtime timep in
|
||||
Printf.printf "tm.tm_mon = %d\n" (getf !@tm tm_mon);
|
||||
Printf.printf "tm.tm_year = %d\n" (getf !@tm tm_year);
|
||||
print_endline (asctime tm)
|
||||
end
|
||||
337
samples/OCaml/map.ml
Normal file
337
samples/OCaml/map.ml
Normal file
@@ -0,0 +1,337 @@
|
||||
(***********************************************************************)
|
||||
(* *)
|
||||
(* OCaml *)
|
||||
(* *)
|
||||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
||||
(* *)
|
||||
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
||||
(* en Automatique. All rights reserved. This file is distributed *)
|
||||
(* under the terms of the GNU Library General Public License, with *)
|
||||
(* the special exception on linking described in file ../LICENSE. *)
|
||||
(* *)
|
||||
(***********************************************************************)
|
||||
|
||||
module type OrderedType =
|
||||
sig
|
||||
type t
|
||||
val compare: t -> t -> int
|
||||
end
|
||||
|
||||
module type S =
|
||||
sig
|
||||
type key
|
||||
type +'a t
|
||||
val empty: 'a t
|
||||
val is_empty: 'a t -> bool
|
||||
val mem: key -> 'a t -> bool
|
||||
val add: key -> 'a -> 'a t -> 'a t
|
||||
val singleton: key -> 'a -> 'a t
|
||||
val remove: key -> 'a t -> 'a t
|
||||
val merge:
|
||||
(key -> 'a option -> 'b option -> 'c option) -> 'a t -> 'b t -> 'c t
|
||||
val compare: ('a -> 'a -> int) -> 'a t -> 'a t -> int
|
||||
val equal: ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
|
||||
val iter: (key -> 'a -> unit) -> 'a t -> unit
|
||||
val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
||||
val for_all: (key -> 'a -> bool) -> 'a t -> bool
|
||||
val exists: (key -> 'a -> bool) -> 'a t -> bool
|
||||
val filter: (key -> 'a -> bool) -> 'a t -> 'a t
|
||||
val partition: (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
|
||||
val cardinal: 'a t -> int
|
||||
val bindings: 'a t -> (key * 'a) list
|
||||
val min_binding: 'a t -> (key * 'a)
|
||||
val max_binding: 'a t -> (key * 'a)
|
||||
val choose: 'a t -> (key * 'a)
|
||||
val split: key -> 'a t -> 'a t * 'a option * 'a t
|
||||
val find: key -> 'a t -> 'a
|
||||
val map: ('a -> 'b) -> 'a t -> 'b t
|
||||
val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t
|
||||
end
|
||||
|
||||
module Make(Ord: OrderedType) = struct
|
||||
|
||||
type key = Ord.t
|
||||
|
||||
type 'a t =
|
||||
Empty
|
||||
| Node of 'a t * key * 'a * 'a t * int
|
||||
|
||||
let height = function
|
||||
Empty -> 0
|
||||
| Node(_,_,_,_,h) -> h
|
||||
|
||||
let create l x d r =
|
||||
let hl = height l and hr = height r in
|
||||
Node(l, x, d, r, (if hl >= hr then hl + 1 else hr + 1))
|
||||
|
||||
let singleton x d = Node(Empty, x, d, Empty, 1)
|
||||
|
||||
let bal l x d r =
|
||||
let hl = match l with Empty -> 0 | Node(_,_,_,_,h) -> h in
|
||||
let hr = match r with Empty -> 0 | Node(_,_,_,_,h) -> h in
|
||||
if hl > hr + 2 then begin
|
||||
match l with
|
||||
Empty -> invalid_arg "Map.bal"
|
||||
| Node(ll, lv, ld, lr, _) ->
|
||||
if height ll >= height lr then
|
||||
create ll lv ld (create lr x d r)
|
||||
else begin
|
||||
match lr with
|
||||
Empty -> invalid_arg "Map.bal"
|
||||
| Node(lrl, lrv, lrd, lrr, _)->
|
||||
create (create ll lv ld lrl) lrv lrd (create lrr x d r)
|
||||
end
|
||||
end else if hr > hl + 2 then begin
|
||||
match r with
|
||||
Empty -> invalid_arg "Map.bal"
|
||||
| Node(rl, rv, rd, rr, _) ->
|
||||
if height rr >= height rl then
|
||||
create (create l x d rl) rv rd rr
|
||||
else begin
|
||||
match rl with
|
||||
Empty -> invalid_arg "Map.bal"
|
||||
| Node(rll, rlv, rld, rlr, _) ->
|
||||
create (create l x d rll) rlv rld (create rlr rv rd rr)
|
||||
end
|
||||
end else
|
||||
Node(l, x, d, r, (if hl >= hr then hl + 1 else hr + 1))
|
||||
|
||||
let empty = Empty
|
||||
|
||||
let is_empty = function Empty -> true | _ -> false
|
||||
|
||||
let rec add x data = function
|
||||
Empty ->
|
||||
Node(Empty, x, data, Empty, 1)
|
||||
| Node(l, v, d, r, h) ->
|
||||
let c = Ord.compare x v in
|
||||
if c = 0 then
|
||||
Node(l, x, data, r, h)
|
||||
else if c < 0 then
|
||||
bal (add x data l) v d r
|
||||
else
|
||||
bal l v d (add x data r)
|
||||
|
||||
let rec find x = function
|
||||
Empty ->
|
||||
raise Not_found
|
||||
| Node(l, v, d, r, _) ->
|
||||
let c = Ord.compare x v in
|
||||
if c = 0 then d
|
||||
else find x (if c < 0 then l else r)
|
||||
|
||||
let rec mem x = function
|
||||
Empty ->
|
||||
false
|
||||
| Node(l, v, d, r, _) ->
|
||||
let c = Ord.compare x v in
|
||||
c = 0 || mem x (if c < 0 then l else r)
|
||||
|
||||
let rec min_binding = function
|
||||
Empty -> raise Not_found
|
||||
| Node(Empty, x, d, r, _) -> (x, d)
|
||||
| Node(l, x, d, r, _) -> min_binding l
|
||||
|
||||
let rec max_binding = function
|
||||
Empty -> raise Not_found
|
||||
| Node(l, x, d, Empty, _) -> (x, d)
|
||||
| Node(l, x, d, r, _) -> max_binding r
|
||||
|
||||
let rec remove_min_binding = function
|
||||
Empty -> invalid_arg "Map.remove_min_elt"
|
||||
| Node(Empty, x, d, r, _) -> r
|
||||
| Node(l, x, d, r, _) -> bal (remove_min_binding l) x d r
|
||||
|
||||
let merge t1 t2 =
|
||||
match (t1, t2) with
|
||||
(Empty, t) -> t
|
||||
| (t, Empty) -> t
|
||||
| (_, _) ->
|
||||
let (x, d) = min_binding t2 in
|
||||
bal t1 x d (remove_min_binding t2)
|
||||
|
||||
let rec remove x = function
|
||||
Empty ->
|
||||
Empty
|
||||
| Node(l, v, d, r, h) ->
|
||||
let c = Ord.compare x v in
|
||||
if c = 0 then
|
||||
merge l r
|
||||
else if c < 0 then
|
||||
bal (remove x l) v d r
|
||||
else
|
||||
bal l v d (remove x r)
|
||||
|
||||
let rec iter f = function
|
||||
Empty -> ()
|
||||
| Node(l, v, d, r, _) ->
|
||||
iter f l; f v d; iter f r
|
||||
|
||||
let rec map f = function
|
||||
Empty ->
|
||||
Empty
|
||||
| Node(l, v, d, r, h) ->
|
||||
let l' = map f l in
|
||||
let d' = f d in
|
||||
let r' = map f r in
|
||||
Node(l', v, d', r', h)
|
||||
|
||||
let rec mapi f = function
|
||||
Empty ->
|
||||
Empty
|
||||
| Node(l, v, d, r, h) ->
|
||||
let l' = mapi f l in
|
||||
let d' = f v d in
|
||||
let r' = mapi f r in
|
||||
Node(l', v, d', r', h)
|
||||
|
||||
let rec fold f m accu =
|
||||
match m with
|
||||
Empty -> accu
|
||||
| Node(l, v, d, r, _) ->
|
||||
fold f r (f v d (fold f l accu))
|
||||
|
||||
let rec for_all p = function
|
||||
Empty -> true
|
||||
| Node(l, v, d, r, _) -> p v d && for_all p l && for_all p r
|
||||
|
||||
let rec exists p = function
|
||||
Empty -> false
|
||||
| Node(l, v, d, r, _) -> p v d || exists p l || exists p r
|
||||
|
||||
(* Beware: those two functions assume that the added k is *strictly*
|
||||
smaller (or bigger) than all the present keys in the tree; it
|
||||
does not test for equality with the current min (or max) key.
|
||||
|
||||
Indeed, they are only used during the "join" operation which
|
||||
respects this precondition.
|
||||
*)
|
||||
|
||||
let rec add_min_binding k v = function
|
||||
| Empty -> singleton k v
|
||||
| Node (l, x, d, r, h) ->
|
||||
bal (add_min_binding k v l) x d r
|
||||
|
||||
let rec add_max_binding k v = function
|
||||
| Empty -> singleton k v
|
||||
| Node (l, x, d, r, h) ->
|
||||
bal l x d (add_max_binding k v r)
|
||||
|
||||
(* Same as create and bal, but no assumptions are made on the
|
||||
relative heights of l and r. *)
|
||||
|
||||
let rec join l v d r =
|
||||
match (l, r) with
|
||||
(Empty, _) -> add_min_binding v d r
|
||||
| (_, Empty) -> add_max_binding v d l
|
||||
| (Node(ll, lv, ld, lr, lh), Node(rl, rv, rd, rr, rh)) ->
|
||||
if lh > rh + 2 then bal ll lv ld (join lr v d r) else
|
||||
if rh > lh + 2 then bal (join l v d rl) rv rd rr else
|
||||
create l v d r
|
||||
|
||||
(* Merge two trees l and r into one.
|
||||
All elements of l must precede the elements of r.
|
||||
No assumption on the heights of l and r. *)
|
||||
|
||||
let concat t1 t2 =
|
||||
match (t1, t2) with
|
||||
(Empty, t) -> t
|
||||
| (t, Empty) -> t
|
||||
| (_, _) ->
|
||||
let (x, d) = min_binding t2 in
|
||||
join t1 x d (remove_min_binding t2)
|
||||
|
||||
let concat_or_join t1 v d t2 =
|
||||
match d with
|
||||
| Some d -> join t1 v d t2
|
||||
| None -> concat t1 t2
|
||||
|
||||
let rec split x = function
|
||||
Empty ->
|
||||
(Empty, None, Empty)
|
||||
| Node(l, v, d, r, _) ->
|
||||
let c = Ord.compare x v in
|
||||
if c = 0 then (l, Some d, r)
|
||||
else if c < 0 then
|
||||
let (ll, pres, rl) = split x l in (ll, pres, join rl v d r)
|
||||
else
|
||||
let (lr, pres, rr) = split x r in (join l v d lr, pres, rr)
|
||||
|
||||
let rec merge f s1 s2 =
|
||||
match (s1, s2) with
|
||||
(Empty, Empty) -> Empty
|
||||
| (Node (l1, v1, d1, r1, h1), _) when h1 >= height s2 ->
|
||||
let (l2, d2, r2) = split v1 s2 in
|
||||
concat_or_join (merge f l1 l2) v1 (f v1 (Some d1) d2) (merge f r1 r2)
|
||||
| (_, Node (l2, v2, d2, r2, h2)) ->
|
||||
let (l1, d1, r1) = split v2 s1 in
|
||||
concat_or_join (merge f l1 l2) v2 (f v2 d1 (Some d2)) (merge f r1 r2)
|
||||
| _ ->
|
||||
assert false
|
||||
|
||||
let rec filter p = function
|
||||
Empty -> Empty
|
||||
| Node(l, v, d, r, _) ->
|
||||
(* call [p] in the expected left-to-right order *)
|
||||
let l' = filter p l in
|
||||
let pvd = p v d in
|
||||
let r' = filter p r in
|
||||
if pvd then join l' v d r' else concat l' r'
|
||||
|
||||
let rec partition p = function
|
||||
Empty -> (Empty, Empty)
|
||||
| Node(l, v, d, r, _) ->
|
||||
(* call [p] in the expected left-to-right order *)
|
||||
let (lt, lf) = partition p l in
|
||||
let pvd = p v d in
|
||||
let (rt, rf) = partition p r in
|
||||
if pvd
|
||||
then (join lt v d rt, concat lf rf)
|
||||
else (concat lt rt, join lf v d rf)
|
||||
|
||||
type 'a enumeration = End | More of key * 'a * 'a t * 'a enumeration
|
||||
|
||||
let rec cons_enum m e =
|
||||
match m with
|
||||
Empty -> e
|
||||
| Node(l, v, d, r, _) -> cons_enum l (More(v, d, r, e))
|
||||
|
||||
let compare cmp m1 m2 =
|
||||
let rec compare_aux e1 e2 =
|
||||
match (e1, e2) with
|
||||
(End, End) -> 0
|
||||
| (End, _) -> -1
|
||||
| (_, End) -> 1
|
||||
| (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) ->
|
||||
let c = Ord.compare v1 v2 in
|
||||
if c <> 0 then c else
|
||||
let c = cmp d1 d2 in
|
||||
if c <> 0 then c else
|
||||
compare_aux (cons_enum r1 e1) (cons_enum r2 e2)
|
||||
in compare_aux (cons_enum m1 End) (cons_enum m2 End)
|
||||
|
||||
let equal cmp m1 m2 =
|
||||
let rec equal_aux e1 e2 =
|
||||
match (e1, e2) with
|
||||
(End, End) -> true
|
||||
| (End, _) -> false
|
||||
| (_, End) -> false
|
||||
| (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) ->
|
||||
Ord.compare v1 v2 = 0 && cmp d1 d2 &&
|
||||
equal_aux (cons_enum r1 e1) (cons_enum r2 e2)
|
||||
in equal_aux (cons_enum m1 End) (cons_enum m2 End)
|
||||
|
||||
let rec cardinal = function
|
||||
Empty -> 0
|
||||
| Node(l, _, _, r, _) -> cardinal l + 1 + cardinal r
|
||||
|
||||
let rec bindings_aux accu = function
|
||||
Empty -> accu
|
||||
| Node(l, v, d, r, _) -> bindings_aux ((v, d) :: bindings_aux accu r) l
|
||||
|
||||
let bindings s =
|
||||
bindings_aux [] s
|
||||
|
||||
let choose = min_binding
|
||||
|
||||
end
|
||||
2503
samples/OCaml/mirage.ml
Normal file
2503
samples/OCaml/mirage.ml
Normal file
File diff suppressed because it is too large
Load Diff
125
samples/OCaml/reload.ml
Normal file
125
samples/OCaml/reload.ml
Normal file
@@ -0,0 +1,125 @@
|
||||
(***********************************************************************)
|
||||
(* *)
|
||||
(* OCaml *)
|
||||
(* *)
|
||||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
||||
(* *)
|
||||
(* Copyright 2000 Institut National de Recherche en Informatique et *)
|
||||
(* en Automatique. All rights reserved. This file is distributed *)
|
||||
(* under the terms of the Q Public License version 1.0. *)
|
||||
(* *)
|
||||
(***********************************************************************)
|
||||
|
||||
open Cmm
|
||||
open Arch
|
||||
open Reg
|
||||
open Mach
|
||||
|
||||
(* Reloading for the AMD64 *)
|
||||
|
||||
(* Summary of instruction set constraints:
|
||||
"S" means either stack or register, "R" means register only.
|
||||
Operation Res Arg1 Arg2
|
||||
Imove R S
|
||||
or S R
|
||||
Iconst_int S if 32-bit signed, R otherwise
|
||||
Iconst_float R
|
||||
Iconst_symbol (not PIC) S
|
||||
Iconst_symbol (PIC) R
|
||||
Icall_ind R
|
||||
Itailcall_ind R
|
||||
Iload R R R
|
||||
Istore R R
|
||||
Iintop(Icomp) R R S
|
||||
or S S R
|
||||
Iintop(Imul|Idiv|mod) R R S
|
||||
Iintop(shift) S S R
|
||||
Iintop(others) R R S
|
||||
or S S R
|
||||
Iintop_imm(Iadd, n)/lea R R
|
||||
Iintop_imm(others) S S
|
||||
Inegf...Idivf R R S
|
||||
Ifloatofint R S
|
||||
Iintoffloat R S
|
||||
Ispecific(Ilea) R R R
|
||||
Ispecific(Ifloatarithmem) R R R
|
||||
|
||||
Conditional branches:
|
||||
Iinttest S R
|
||||
or R S
|
||||
Ifloattest R S (or S R if swapped test)
|
||||
other tests S
|
||||
*)
|
||||
|
||||
let stackp r =
|
||||
match r.loc with
|
||||
Stack _ -> true
|
||||
| _ -> false
|
||||
|
||||
class reload = object (self)
|
||||
|
||||
inherit Reloadgen.reload_generic as super
|
||||
|
||||
method! reload_operation op arg res =
|
||||
match op with
|
||||
| Iintop(Iadd|Isub|Iand|Ior|Ixor|Icomp _|Icheckbound) ->
|
||||
(* One of the two arguments can reside in the stack, but not both *)
|
||||
if stackp arg.(0) && stackp arg.(1)
|
||||
then ([|arg.(0); self#makereg arg.(1)|], res)
|
||||
else (arg, res)
|
||||
| Iintop_imm(Iadd, _) when arg.(0).loc <> res.(0).loc ->
|
||||
(* This add will be turned into a lea; args and results must be
|
||||
in registers *)
|
||||
super#reload_operation op arg res
|
||||
| Iintop(Idiv | Imod | Ilsl | Ilsr | Iasr)
|
||||
| Iintop_imm(_, _) ->
|
||||
(* The argument(s) and results can be either in register or on stack *)
|
||||
(* Note: Idiv, Imod: arg(0) and res(0) already forced in regs
|
||||
Ilsl, Ilsr, Iasr: arg(1) already forced in regs *)
|
||||
(arg, res)
|
||||
| Iintop(Imul) | Iaddf | Isubf | Imulf | Idivf ->
|
||||
(* First argument (= result) must be in register, second arg
|
||||
can reside in the stack *)
|
||||
if stackp arg.(0)
|
||||
then (let r = self#makereg arg.(0) in ([|r; arg.(1)|], [|r|]))
|
||||
else (arg, res)
|
||||
| Ifloatofint | Iintoffloat ->
|
||||
(* Result must be in register, but argument can be on stack *)
|
||||
(arg, (if stackp res.(0) then [| self#makereg res.(0) |] else res))
|
||||
| Iconst_int n ->
|
||||
if n <= 0x7FFFFFFFn && n >= -0x80000000n
|
||||
then (arg, res)
|
||||
else super#reload_operation op arg res
|
||||
| Iconst_symbol _ ->
|
||||
if !pic_code || !Clflags.dlcode
|
||||
then super#reload_operation op arg res
|
||||
else (arg, res)
|
||||
| _ -> (* Other operations: all args and results in registers *)
|
||||
super#reload_operation op arg res
|
||||
|
||||
method! reload_test tst arg =
|
||||
match tst with
|
||||
Iinttest cmp ->
|
||||
(* One of the two arguments can reside on stack *)
|
||||
if stackp arg.(0) && stackp arg.(1)
|
||||
then [| self#makereg arg.(0); arg.(1) |]
|
||||
else arg
|
||||
| Ifloattest((Clt|Cle), _) ->
|
||||
(* Cf. emit.mlp: we swap arguments in this case *)
|
||||
(* First argument can be on stack, second must be in register *)
|
||||
if stackp arg.(1)
|
||||
then [| arg.(0); self#makereg arg.(1) |]
|
||||
else arg
|
||||
| Ifloattest((Ceq|Cne|Cgt|Cge), _) ->
|
||||
(* Second argument can be on stack, first must be in register *)
|
||||
if stackp arg.(0)
|
||||
then [| self#makereg arg.(0); arg.(1) |]
|
||||
else arg
|
||||
| _ ->
|
||||
(* The argument(s) can be either in register or on stack *)
|
||||
arg
|
||||
|
||||
end
|
||||
|
||||
let fundecl f =
|
||||
(new reload)#fundecl f
|
||||
70
samples/OCaml/sigset.ml
Normal file
70
samples/OCaml/sigset.ml
Normal file
@@ -0,0 +1,70 @@
|
||||
(*
|
||||
* Copyright (c) 2013 Jeremy Yallop.
|
||||
*
|
||||
* This file is distributed under the terms of the MIT License.
|
||||
* See the file LICENSE for details.
|
||||
*)
|
||||
|
||||
open PosixTypes
|
||||
open Ctypes
|
||||
open Foreign
|
||||
|
||||
type t = sigset_t ptr
|
||||
|
||||
let t = ptr sigset_t
|
||||
|
||||
(* This function initializes the signal set set to exclude all of the defined
|
||||
signals. It always returns 0. *)
|
||||
let sigemptyset = foreign "sigemptyset" (ptr sigset_t @-> returning int)
|
||||
|
||||
let empty () =
|
||||
let setp = allocate_n ~count:1 sigset_t in begin
|
||||
ignore (sigemptyset setp);
|
||||
setp
|
||||
end
|
||||
|
||||
(* This function initializes the signal set set to include all of the defined
|
||||
signals. Again, the return value is 0. *)
|
||||
let sigfillset = foreign "sigfillset" (ptr sigset_t @-> returning int)
|
||||
|
||||
let full () =
|
||||
let setp = allocate_n ~count:1 sigset_t in begin
|
||||
ignore (sigfillset setp);
|
||||
setp
|
||||
end
|
||||
|
||||
(* This function adds the signal signum to the signal set set. All sigaddset
|
||||
does is modify set; it does not block or unblock any signals.
|
||||
|
||||
The return value is 0 on success and -1 on failure. The following errno
|
||||
error condition is defined for this function:
|
||||
|
||||
EINVAL The signum argument doesn't specify a valid signal.
|
||||
*)
|
||||
let sigaddset = foreign "sigaddset" ~check_errno:true
|
||||
(ptr sigset_t @-> int @-> returning int)
|
||||
|
||||
let add set signal = ignore (sigaddset set signal)
|
||||
|
||||
(* This function removes the signal signum from the signal set set. All
|
||||
sigdelset does is modify set; it does not block or unblock any signals.
|
||||
|
||||
The return value and error conditions are the same as for
|
||||
sigaddset. *)
|
||||
let sigdelset = foreign "sigdelset" ~check_errno:true
|
||||
(ptr sigset_t @-> int @-> returning int)
|
||||
|
||||
let del set signal = ignore (sigdelset set signal)
|
||||
|
||||
(* The sigismember function tests whether the signal signum is a member of the
|
||||
signal set set. It returns 1 if the signal is in the set, 0 if not, and -1 if
|
||||
there is an error.
|
||||
|
||||
The following errno error condition is defined for this function:
|
||||
|
||||
EINVAL The signum argument doesn't specify a valid signal.
|
||||
*)
|
||||
let sigismember = foreign "sigismember" ~check_errno:true
|
||||
(ptr sigset_t @-> int @-> returning int)
|
||||
|
||||
let mem set signal = sigismember set signal <> 0
|
||||
810
samples/OCaml/uutf.ml
Normal file
810
samples/OCaml/uutf.ml
Normal file
@@ -0,0 +1,810 @@
|
||||
(*---------------------------------------------------------------------------
|
||||
Copyright 2012 Daniel C. Bünzli. All rights reserved.
|
||||
Distributed under the BSD3 license, see license at the end of the file.
|
||||
%%NAME%% release %%VERSION%%
|
||||
---------------------------------------------------------------------------*)
|
||||
|
||||
let io_buffer_size = 65536 (* IO_BUFFER_SIZE 4.0.0 *)
|
||||
|
||||
let pp = Format.fprintf
|
||||
let invalid_encode () = invalid_arg "expected `Await encode"
|
||||
let invalid_bounds j l =
|
||||
invalid_arg (Printf.sprintf "invalid bounds (index %d, length %d)" j l)
|
||||
|
||||
(* Unsafe string byte manipulations. If you don't believe the author's
|
||||
invariants, replacing with safe versions makes everything safe in
|
||||
the module. He won't be upset. *)
|
||||
|
||||
let unsafe_chr = Char.unsafe_chr
|
||||
let unsafe_blit = String.unsafe_blit
|
||||
let unsafe_array_get = Array.unsafe_get
|
||||
let unsafe_byte s j = Char.code (String.unsafe_get s j)
|
||||
let unsafe_set_byte s j byte = String.unsafe_set s j (Char.unsafe_chr byte)
|
||||
|
||||
(* Unicode characters *)
|
||||
|
||||
type uchar = int
|
||||
let u_bom = 0xFEFF (* BOM. *)
|
||||
let u_rep = 0xFFFD (* replacement character. *)
|
||||
let is_uchar cp =
|
||||
(0x0000 <= cp && cp <= 0xD7FF) || (0xE000 <= cp && cp <= 0x10FFFF)
|
||||
|
||||
let pp_cp ppf cp =
|
||||
if cp < 0 || cp > 0x10FFFF then pp ppf "U+Invalid(%X)" cp else
|
||||
if cp <= 0xFFFF then pp ppf "U+%04X" cp else
|
||||
pp ppf "U+%X" cp
|
||||
|
||||
let cp_to_string cp = (* NOT thread safe. *)
|
||||
pp Format.str_formatter "%a" pp_cp cp; Format.flush_str_formatter ()
|
||||
|
||||
(* Unicode encoding schemes *)
|
||||
|
||||
type encoding = [ `UTF_8 | `UTF_16 | `UTF_16BE | `UTF_16LE ]
|
||||
type decoder_encoding = [ encoding | `US_ASCII | `ISO_8859_1 ]
|
||||
|
||||
let encoding_of_string s = match String.uppercase s with (* IANA names. *)
|
||||
| "UTF-8" -> Some `UTF_8
|
||||
| "UTF-16" -> Some `UTF_16
|
||||
| "UTF-16LE" -> Some `UTF_16LE
|
||||
| "UTF-16BE" -> Some `UTF_16BE
|
||||
| "ANSI_X3.4-1968" | "ISO-IR-6" | "ANSI_X3.4-1986" | "ISO_646.IRV:1991"
|
||||
| "ASCII" | "ISO646-US" | "US-ASCII" | "US" | "IBM367" | "CP367" | "CSASCII" ->
|
||||
Some `US_ASCII
|
||||
| "ISO_8859-1:1987" | "ISO-IR-100" | "ISO_8859-1" | "ISO-8859-1"
|
||||
| "LATIN1" | "L1" | "IBM819" | "CP819" | "CSISOLATIN1" ->
|
||||
Some `ISO_8859_1
|
||||
| _ -> None
|
||||
|
||||
let encoding_to_string = function
|
||||
| `UTF_8 -> "UTF-8" | `UTF_16 -> "UTF-16" | `UTF_16BE -> "UTF-16BE"
|
||||
| `UTF_16LE -> "UTF-16LE" | `US_ASCII -> "US-ASCII"
|
||||
| `ISO_8859_1 -> "ISO-8859-1"
|
||||
|
||||
(* Base character decoders. They assume enough data. *)
|
||||
|
||||
let malformed s j l = `Malformed (String.sub s j l)
|
||||
let malformed_pair be hi s j l = (* missing or half low surrogate at eoi. *)
|
||||
let bs1 = String.sub s j l in
|
||||
let bs0 = String.create 2 in
|
||||
let j0, j1 = if be then (0, 1) else (1, 0) in
|
||||
unsafe_set_byte bs0 j0 (hi lsr 8);
|
||||
unsafe_set_byte bs0 j1 (hi land 0xFF);
|
||||
`Malformed (bs0 ^ bs1)
|
||||
|
||||
let r_us_ascii s j =
|
||||
(* assert (0 <= j && j < String.length s); *)
|
||||
let b0 = unsafe_byte s j in
|
||||
if b0 <= 127 then `Uchar b0 else malformed s j 1
|
||||
|
||||
let r_iso_8859_1 s j =
|
||||
(* assert (0 <= j && j < String.length s); *)
|
||||
`Uchar (unsafe_byte s j)
|
||||
|
||||
let utf_8_len = [| (* uchar byte length according to first UTF-8 byte. *)
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
|
||||
1; 1; 1; 1; 1; 1; 1; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
|
||||
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
|
||||
0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0;
|
||||
0; 0; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2; 2;
|
||||
2; 2; 2; 2; 2; 2; 2; 2; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3; 3;
|
||||
4; 4; 4; 4; 4; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0 |]
|
||||
|
||||
let r_utf_8 s j l =
|
||||
(* assert (0 <= j && 0 <= l && j + l <= String.length s); *)
|
||||
match l with
|
||||
| 1 -> `Uchar (unsafe_byte s j)
|
||||
| 2 ->
|
||||
let b0 = unsafe_byte s j in let b1 = unsafe_byte s (j + 1) in
|
||||
if b1 lsr 6 != 0b10 then malformed s j l else
|
||||
`Uchar (((b0 land 0x1F) lsl 6) lor (b1 land 0x3F))
|
||||
| 3 ->
|
||||
let b0 = unsafe_byte s j in let b1 = unsafe_byte s (j + 1) in
|
||||
let b2 = unsafe_byte s (j + 2) in
|
||||
let c = `Uchar (((b0 land 0x0F) lsl 12) lor
|
||||
((b1 land 0x3F) lsl 6) lor
|
||||
(b2 land 0x3F))
|
||||
in
|
||||
if b2 lsr 6 != 0b10 then malformed s j l else
|
||||
begin match b0 with
|
||||
| 0xE0 -> if b1 < 0xA0 || 0xBF < b1 then malformed s j l else c
|
||||
| 0xED -> if b1 < 0x80 || 0x9F < b1 then malformed s j l else c
|
||||
| _ -> if b1 lsr 6 != 0b10 then malformed s j l else c
|
||||
end
|
||||
| 4 ->
|
||||
let b0 = unsafe_byte s j in let b1 = unsafe_byte s (j + 1) in
|
||||
let b2 = unsafe_byte s (j + 2) in let b3 = unsafe_byte s (j + 3) in
|
||||
let c = `Uchar (((b0 land 0x07) lsl 18) lor
|
||||
((b1 land 0x3F) lsl 12) lor
|
||||
((b2 land 0x3F) lsl 6) lor
|
||||
(b3 land 0x3F))
|
||||
in
|
||||
if b3 lsr 6 != 0b10 || b2 lsr 6 != 0b10 then malformed s j l else
|
||||
begin match b0 with
|
||||
| 0xF0 -> if b1 < 0x90 || 0xBF < b1 then malformed s j l else c
|
||||
| 0xF4 -> if b1 < 0x80 || 0x8F < b1 then malformed s j l else c
|
||||
| _ -> if b1 lsr 6 != 0b10 then malformed s j l else c
|
||||
end
|
||||
| _ -> assert false
|
||||
|
||||
let r_utf_16 s j0 j1 = (* May return a high surrogate. *)
|
||||
(* assert (0 <= j0 && 0 <= j1 && max j0 j1 < String.length s); *)
|
||||
let b0 = unsafe_byte s j0 in let b1 = unsafe_byte s j1 in
|
||||
let u = (b0 lsl 8) lor b1 in
|
||||
if u < 0xD800 || u > 0xDFFF then `Uchar u else
|
||||
if u > 0xDBFF then malformed s (min j0 j1) 2 else `Hi u
|
||||
|
||||
let r_utf_16_lo hi s j0 j1 = (* Combines [hi] with a low surrogate. *)
|
||||
(* assert (0 <= j0 && 0 <= j1 && max j0 j1 < String.length s); *)
|
||||
let b0 = unsafe_byte s j0 in
|
||||
let b1 = unsafe_byte s j1 in
|
||||
let lo = (b0 lsl 8) lor b1 in
|
||||
if lo < 0xDC00 || lo > 0xDFFF
|
||||
then malformed_pair (j0 < j1 (* true => be *)) hi s (min j0 j1) 2
|
||||
else `Uchar ((((hi land 0x3FF) lsl 10) lor (lo land 0x3FF)) + 0x10000)
|
||||
|
||||
let r_encoding s j l = (* guess encoding with max. 3 bytes. *)
|
||||
(* assert (0 <= j && 0 <= l && j + l <= String.length s) *)
|
||||
let some i = if i < l then Some (unsafe_byte s (j + i)) else None in
|
||||
match (some 0), (some 1), (some 2) with
|
||||
| Some 0xEF, Some 0xBB, Some 0xBF -> `UTF_8 `BOM
|
||||
| Some 0xFE, Some 0xFF, _ -> `UTF_16BE `BOM
|
||||
| Some 0xFF, Some 0xFE, _ -> `UTF_16LE `BOM
|
||||
| Some 0x00, Some p, _ when p > 0 -> `UTF_16BE (`ASCII p)
|
||||
| Some p, Some 0x00, _ when p > 0 -> `UTF_16LE (`ASCII p)
|
||||
| Some u, _, _ when utf_8_len.(u) <> 0 -> `UTF_8 `Decode
|
||||
| Some _, Some _, _ -> `UTF_16BE `Decode
|
||||
| Some _, None , None -> `UTF_8 `Decode
|
||||
| None , None , None -> `UTF_8 `End
|
||||
| None , Some _, _ -> assert false
|
||||
| Some _, None , Some _ -> assert false
|
||||
| None , None , Some _ -> assert false
|
||||
|
||||
(* Decode *)
|
||||
|
||||
type src = [ `Channel of in_channel | `String of string | `Manual ]
|
||||
type nln = [ `ASCII of uchar | `NLF of uchar | `Readline of uchar ]
|
||||
type decode = [ `Await | `End | `Malformed of string | `Uchar of uchar]
|
||||
|
||||
let pp_decode ppf = function
|
||||
| `Uchar u -> pp ppf "@[`Uchar %a@]" pp_cp u
|
||||
| `End -> pp ppf "`End"
|
||||
| `Await -> pp ppf "`Await"
|
||||
| `Malformed bs ->
|
||||
let l = String.length bs in
|
||||
pp ppf "@[`Malformed (";
|
||||
if l > 0 then pp ppf "%02X" (Char.code (bs.[0]));
|
||||
for i = 1 to l - 1 do pp ppf " %02X" (Char.code (bs.[i])) done;
|
||||
pp ppf ")@]"
|
||||
|
||||
type decoder =
|
||||
{ src : src; (* input source. *)
|
||||
mutable encoding : decoder_encoding; (* decoded encoding. *)
|
||||
nln : nln option; (* newline normalization (if any). *)
|
||||
nl : int; (* newline normalization character. *)
|
||||
mutable i : string; (* current input chunk. *)
|
||||
mutable i_pos : int; (* input current position. *)
|
||||
mutable i_max : int; (* input maximal position. *)
|
||||
t : string; (* four bytes temporary buffer for overlapping reads. *)
|
||||
mutable t_len : int; (* current byte length of [t]. *)
|
||||
mutable t_need : int; (* number of bytes needed in [t]. *)
|
||||
mutable removed_bom : bool; (* [true] if an initial BOM was removed. *)
|
||||
mutable last_cr : bool; (* [true] if last char was CR. *)
|
||||
mutable line : int; (* line number. *)
|
||||
mutable col : int; (* column number. *)
|
||||
mutable byte_count : int; (* byte count. *)
|
||||
mutable count : int; (* char count. *)
|
||||
mutable pp : (* decoder post-processor for BOM, position and nln. *)
|
||||
decoder -> [ `Malformed of string | `Uchar of uchar ] -> decode;
|
||||
mutable k : decoder -> decode } (* decoder continuation. *)
|
||||
|
||||
(* On decodes that overlap two (or more) [d.i] buffers, we use [t_fill] to copy
|
||||
the input data to [d.t] and decode from there. If the [d.i] buffers are not
|
||||
too small this is faster than continuation based byte per byte writes.
|
||||
|
||||
End of input (eoi) is signalled by [d.i_pos = 0] and [d.i_max = min_int]
|
||||
which implies that [i_rem d < 0] is [true]. *)
|
||||
|
||||
let i_rem d = d.i_max - d.i_pos + 1 (* remaining bytes to read in [d.i]. *)
|
||||
let eoi d = d.i <- ""; d.i_pos <- 0; d.i_max <- min_int (* set eoi in [d]. *)
|
||||
let src d s j l = (* set [d.i] with [s]. *)
|
||||
if (j < 0 || l < 0 || j + l > String.length s) then invalid_bounds j l else
|
||||
if (l = 0) then eoi d else
|
||||
(d.i <- s; d.i_pos <- j; d.i_max <- j + l - 1)
|
||||
|
||||
let refill k d = match d.src with (* get new input in [d.i] and [k]ontinue. *)
|
||||
| `Manual -> d.k <- k; `Await
|
||||
| `String _ -> eoi d; k d
|
||||
| `Channel ic ->
|
||||
let rc = input ic d.i 0 (String.length d.i) in
|
||||
(src d d.i 0 rc; k d)
|
||||
|
||||
let t_need d need = d.t_len <- 0; d.t_need <- need
|
||||
let rec t_fill k d = (* get [d.t_need] bytes (or less if eoi) in [i.t]. *)
|
||||
let blit d l =
|
||||
unsafe_blit d.i d.i_pos d.t d.t_len (* write pos. *) l;
|
||||
d.i_pos <- d.i_pos + l; d.t_len <- d.t_len + l;
|
||||
in
|
||||
let rem = i_rem d in
|
||||
if rem < 0 (* eoi *) then k d else
|
||||
let need = d.t_need - d.t_len in
|
||||
if rem < need then (blit d rem; refill (t_fill k) d) else (blit d need; k d)
|
||||
|
||||
let ret k v byte_count d = (* return post-processed [v]. *)
|
||||
d.k <- k; d.byte_count <- d.byte_count + byte_count; d.pp d v
|
||||
|
||||
(* Decoders. *)
|
||||
|
||||
let rec decode_us_ascii d =
|
||||
let rem = i_rem d in
|
||||
if rem <= 0 then (if rem < 0 then `End else refill decode_us_ascii d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 1; ret decode_us_ascii (r_us_ascii d.i j) 1 d
|
||||
|
||||
let rec decode_iso_8859_1 d =
|
||||
let rem = i_rem d in
|
||||
if rem <= 0 then (if rem < 0 then `End else refill decode_iso_8859_1 d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 1; ret decode_iso_8859_1 (r_iso_8859_1 d.i j) 1 d
|
||||
|
||||
(* UTF-8 decoder *)
|
||||
|
||||
let rec t_decode_utf_8 d = (* decode from [d.t]. *)
|
||||
if d.t_len < d.t_need
|
||||
then ret decode_utf_8 (malformed d.t 0 d.t_len) d.t_len d
|
||||
else ret decode_utf_8 (r_utf_8 d.t 0 d.t_len) d.t_len d
|
||||
|
||||
and decode_utf_8 d =
|
||||
let rem = i_rem d in
|
||||
if rem <= 0 then (if rem < 0 then `End else refill decode_utf_8 d) else
|
||||
let need = unsafe_array_get utf_8_len (unsafe_byte d.i d.i_pos) in
|
||||
if rem < need then (t_need d need; t_fill t_decode_utf_8 d) else
|
||||
let j = d.i_pos in
|
||||
if need = 0
|
||||
then (d.i_pos <- d.i_pos + 1; ret decode_utf_8 (malformed d.i j 1) 1 d)
|
||||
else (d.i_pos <- d.i_pos + need; ret decode_utf_8 (r_utf_8 d.i j need) need d)
|
||||
|
||||
(* UTF-16BE decoder *)
|
||||
|
||||
let rec t_decode_utf_16be_lo hi d = (* decode from [d.t]. *)
|
||||
let bcount = d.t_len + 2 (* hi count *) in
|
||||
if d.t_len < d.t_need
|
||||
then ret decode_utf_16be (malformed_pair true hi d.t 0 d.t_len) bcount d
|
||||
else ret decode_utf_16be (r_utf_16_lo hi d.t 0 1) bcount d
|
||||
|
||||
and t_decode_utf_16be d = (* decode from [d.t]. *)
|
||||
if d.t_len < d.t_need
|
||||
then ret decode_utf_16be (malformed d.t 0 d.t_len) d.t_len d
|
||||
else decode_utf_16be_lo (r_utf_16 d.t 0 1) d
|
||||
|
||||
and decode_utf_16be_lo v d = match v with
|
||||
| `Uchar _ | `Malformed _ as v -> ret decode_utf_16be v 2 d
|
||||
| `Hi hi ->
|
||||
let rem = i_rem d in
|
||||
if rem < 2 then (t_need d 2; t_fill (t_decode_utf_16be_lo hi) d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 2;
|
||||
ret decode_utf_16be (r_utf_16_lo hi d.i j (j + 1)) 4 d
|
||||
|
||||
and decode_utf_16be d =
|
||||
let rem = i_rem d in
|
||||
if rem <= 0 then (if rem < 0 then `End else refill decode_utf_16be d) else
|
||||
if rem < 2 then (t_need d 2; t_fill t_decode_utf_16be d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 2; decode_utf_16be_lo (r_utf_16 d.i j (j + 1)) d
|
||||
|
||||
(* UTF-16LE decoder, same as UTF-16BE with byte swapped. *)
|
||||
|
||||
let rec t_decode_utf_16le_lo hi d = (* decode from [d.t]. *)
|
||||
let bcount = d.t_len + 2 (* hi count *) in
|
||||
if d.t_len < d.t_need
|
||||
then ret decode_utf_16le (malformed_pair false hi d.t 0 d.t_len) bcount d
|
||||
else ret decode_utf_16le (r_utf_16_lo hi d.t 1 0) bcount d
|
||||
|
||||
and t_decode_utf_16le d = (* decode from [d.t]. *)
|
||||
if d.t_len < d.t_need
|
||||
then ret decode_utf_16le (malformed d.t 0 d.t_len) d.t_len d
|
||||
else decode_utf_16le_lo (r_utf_16 d.t 1 0) d
|
||||
|
||||
and decode_utf_16le_lo v d = match v with
|
||||
| `Uchar _ | `Malformed _ as v -> ret decode_utf_16le v 2 d
|
||||
| `Hi hi ->
|
||||
let rem = i_rem d in
|
||||
if rem < 2 then (t_need d 2; t_fill (t_decode_utf_16le_lo hi) d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 2;
|
||||
ret decode_utf_16le (r_utf_16_lo hi d.i (j + 1) j) 4 d
|
||||
|
||||
and decode_utf_16le d =
|
||||
let rem = i_rem d in
|
||||
if rem <= 0 then (if rem < 0 then `End else refill decode_utf_16le d) else
|
||||
if rem < 2 then (t_need d 2; t_fill t_decode_utf_16le d) else
|
||||
let j = d.i_pos in
|
||||
d.i_pos <- d.i_pos + 2; decode_utf_16le_lo (r_utf_16 d.i (j + 1) j) d
|
||||
|
||||
(* Encoding guessing. The guess is simple but starting the decoder
|
||||
after is tedious, uutf's decoders are not designed to put bytes
|
||||
back in the stream. *)
|
||||
|
||||
let guessed_utf_8 d = (* start decoder after `UTF_8 guess. *)
|
||||
let b3 d = (* handles the third read byte. *)
|
||||
let b3 = unsafe_byte d.t 2 in
|
||||
match utf_8_len.(b3) with
|
||||
| 0 -> ret decode_utf_8 (malformed d.t 2 1) 1 d
|
||||
| n ->
|
||||
d.t_need <- n; d.t_len <- 1; unsafe_set_byte d.t 0 b3;
|
||||
t_fill t_decode_utf_8 d
|
||||
in
|
||||
let b2 d = (* handle second read byte. *)
|
||||
let b2 = unsafe_byte d.t 1 in
|
||||
let b3 = if d.t_len > 2 then b3 else decode_utf_8 (* decodes `End *) in
|
||||
match utf_8_len.(b2) with
|
||||
| 0 -> ret b3 (malformed d.t 1 1) 1 d
|
||||
| 1 -> ret b3 (r_utf_8 d.t 1 1) 1 d
|
||||
| n -> (* copy d.t.(1-2) to d.t.(0-1) and decode *)
|
||||
d.t_need <- n;
|
||||
unsafe_set_byte d.t 0 b2;
|
||||
if (d.t_len < 3) then d.t_len <- 1 else
|
||||
(d.t_len <- 2; unsafe_set_byte d.t 1 (unsafe_byte d.t 2); );
|
||||
t_fill t_decode_utf_8 d
|
||||
in
|
||||
let b1 = unsafe_byte d.t 0 in (* handle first read byte. *)
|
||||
let b2 = if d.t_len > 1 then b2 else decode_utf_8 (* decodes `End *) in
|
||||
match utf_8_len.(b1) with
|
||||
| 0 -> ret b2 (malformed d.t 0 1) 1 d
|
||||
| 1 -> ret b2 (r_utf_8 d.t 0 1) 1 d
|
||||
| 2 ->
|
||||
if d.t_len < 2 then ret decode_utf_8 (malformed d.t 0 1) 1 d else
|
||||
if d.t_len < 3 then ret decode_utf_8 (r_utf_8 d.t 0 2) 2 d else
|
||||
ret b3 (r_utf_8 d.t 0 2) 2 d
|
||||
| 3 ->
|
||||
if d.t_len < 3
|
||||
then ret decode_utf_8 (malformed d.t 0 d.t_len) d.t_len d
|
||||
else ret decode_utf_8 (r_utf_8 d.t 0 3) 3 d
|
||||
| 4 ->
|
||||
if d.t_len < 3
|
||||
then ret decode_utf_8 (malformed d.t 0 d.t_len) d.t_len d
|
||||
else (d.t_need <- 4; t_fill t_decode_utf_8 d)
|
||||
| n -> assert false
|
||||
|
||||
let guessed_utf_16 d be v = (* start decoder after `UTF_16{BE,LE} guess. *)
|
||||
let decode_utf_16, t_decode_utf_16, t_decode_utf_16_lo, j0, j1 =
|
||||
if be then decode_utf_16be, t_decode_utf_16be, t_decode_utf_16be_lo, 0, 1
|
||||
else decode_utf_16le, t_decode_utf_16le, t_decode_utf_16le_lo, 1, 0
|
||||
in
|
||||
let b3 k d =
|
||||
if d.t_len < 3 then decode_utf_16 d (* decodes `End *) else
|
||||
begin (* copy d.t.(2) to d.t.(0) and decode. *)
|
||||
d.t_need <- 2; d.t_len <- 1;
|
||||
unsafe_set_byte d.t 0 (unsafe_byte d.t 2);
|
||||
t_fill k d
|
||||
end
|
||||
in
|
||||
match v with
|
||||
| `BOM -> ret (b3 t_decode_utf_16) (`Uchar u_bom) 2 d
|
||||
| `ASCII u -> ret (b3 t_decode_utf_16) (`Uchar u) 2 d
|
||||
| `Decode ->
|
||||
match r_utf_16 d.t j0 j1 with
|
||||
| `Malformed _ | `Uchar _ as v -> ret (b3 t_decode_utf_16) v 2 d
|
||||
| `Hi hi ->
|
||||
if d.t_len < 3
|
||||
then ret decode_utf_16 (malformed_pair be hi "" 0 0) d.t_len d
|
||||
else (b3 (t_decode_utf_16_lo hi)) d
|
||||
|
||||
let guess_encoding d = (* guess encoding and start decoder. *)
|
||||
let setup d = match r_encoding d.t 0 d.t_len with
|
||||
| `UTF_8 r ->
|
||||
d.encoding <- `UTF_8; d.k <- decode_utf_8;
|
||||
begin match r with
|
||||
| `BOM -> ret decode_utf_8 (`Uchar u_bom) 3 d
|
||||
| `Decode -> guessed_utf_8 d
|
||||
| `End -> `End
|
||||
end
|
||||
| `UTF_16BE r ->
|
||||
d.encoding <- `UTF_16BE; d.k <- decode_utf_16be; guessed_utf_16 d true r
|
||||
| `UTF_16LE r ->
|
||||
d.encoding <- `UTF_16LE; d.k <- decode_utf_16le; guessed_utf_16 d false r
|
||||
|
||||
in
|
||||
(t_need d 3; t_fill setup d)
|
||||
|
||||
(* Character post-processors. Used for BOM handling, newline
|
||||
normalization and position tracking. The [pp_remove_bom] is only
|
||||
used for the first character to remove a possible initial BOM and
|
||||
handle UTF-16 endianness recognition. *)
|
||||
|
||||
let nline d = d.col <- 0; d.line <- d.line + 1 (* inlined. *)
|
||||
let ncol d = d.col <- d.col + 1 (* inlined. *)
|
||||
let ncount d = d.count <- d.count + 1 (* inlined. *)
|
||||
let cr d b = d.last_cr <- b (* inlined. *)
|
||||
|
||||
let pp_remove_bom utf16 pp d = function(* removes init. BOM, handles UTF-16. *)
|
||||
| `Uchar 0xFEFF (* BOM *) ->
|
||||
if utf16 then (d.encoding <- `UTF_16BE; d.k <- decode_utf_16be);
|
||||
d.removed_bom <- true; d.pp <- pp; d.k d
|
||||
| `Uchar 0xFFFE (* BOM reversed from decode_utf_16be *) when utf16 ->
|
||||
d.encoding <- `UTF_16LE; d.k <- decode_utf_16le;
|
||||
d.removed_bom <- true; d.pp <- pp; d.k d
|
||||
| `Malformed _ | `Uchar _ as v ->
|
||||
d.removed_bom <- false; d.pp <- pp; d.pp d v
|
||||
|
||||
let pp_nln_none d = function
|
||||
| `Uchar 0x000A (* LF *) as v ->
|
||||
let last_cr = d.last_cr in
|
||||
cr d false; ncount d; if last_cr then v else (nline d; v)
|
||||
| `Uchar 0x000D (* CR *) as v -> cr d true; ncount d; nline d; v
|
||||
| `Uchar (0x0085 | 0x000C | 0x2028 | 0x2029) (* NEL | FF | LS | PS *) as v ->
|
||||
cr d false; ncount d; nline d; v
|
||||
| `Uchar _ | `Malformed _ as v -> cr d false; ncount d; ncol d; v
|
||||
|
||||
let pp_nln_readline d = function
|
||||
| `Uchar 0x000A (* LF *) ->
|
||||
let last_cr = d.last_cr in
|
||||
cr d false; if last_cr then d.k d else (ncount d; nline d; `Uchar d.nl)
|
||||
| `Uchar 0x000D (* CR *) -> cr d true; ncount d; nline d; `Uchar d.nl
|
||||
| `Uchar (0x0085 | 0x000C | 0x2028 | 0x2029) (* NEL | FF | LS | PS *) ->
|
||||
cr d false; ncount d; nline d; `Uchar d.nl
|
||||
| `Uchar _ | `Malformed _ as v -> cr d false; ncount d; ncol d; v
|
||||
|
||||
let pp_nln_nlf d = function
|
||||
| `Uchar 0x000A (* LF *) ->
|
||||
let last_cr = d.last_cr in
|
||||
cr d false; if last_cr then d.k d else (ncount d; nline d; `Uchar d.nl)
|
||||
| `Uchar 0x000D (* CR *) -> cr d true; ncount d; nline d; `Uchar d.nl
|
||||
| `Uchar 0x0085 (* NEL *) -> cr d false; ncount d; nline d; `Uchar d.nl
|
||||
| `Uchar (0x000C | 0x2028 | 0x2029) as v (* FF | LS | PS *) ->
|
||||
cr d false; ncount d; nline d; v
|
||||
| `Uchar _ | `Malformed _ as v -> cr d false; ncount d; ncol d; v
|
||||
|
||||
let pp_nln_ascii d = function
|
||||
| `Uchar 0x000A (* LF *) ->
|
||||
let last_cr = d.last_cr in
|
||||
cr d false; if last_cr then d.k d else (ncount d; nline d; `Uchar d.nl)
|
||||
| `Uchar 0x000D (* CR *) -> cr d true; ncount d; nline d; `Uchar d.nl
|
||||
| `Uchar (0x0085 | 0x000C | 0x2028 | 0x2029) as v (* NEL | FF | LS | PS *) ->
|
||||
cr d false; ncount d; nline d; v
|
||||
| `Uchar _ | `Malformed _ as v -> cr d false; ncount d; ncol d; v
|
||||
|
||||
let decode_fun = function
|
||||
| `UTF_8 -> decode_utf_8
|
||||
| `UTF_16 -> decode_utf_16be (* see [pp_remove_bom]. *)
|
||||
| `UTF_16BE -> decode_utf_16be
|
||||
| `UTF_16LE -> decode_utf_16le
|
||||
| `US_ASCII -> decode_us_ascii
|
||||
| `ISO_8859_1 -> decode_iso_8859_1
|
||||
|
||||
let decoder ?nln ?encoding src =
|
||||
let pp, nl = match nln with
|
||||
| None -> pp_nln_none, 0x000A (* not used. *)
|
||||
| Some (`ASCII nl) -> pp_nln_ascii, nl
|
||||
| Some (`NLF nl) -> pp_nln_nlf, nl
|
||||
| Some (`Readline nl) -> pp_nln_readline, nl
|
||||
in
|
||||
let encoding, k = match encoding with
|
||||
| None -> `UTF_8, guess_encoding
|
||||
| Some e -> (e :> decoder_encoding), decode_fun e
|
||||
in
|
||||
let i, i_pos, i_max = match src with
|
||||
| `Manual -> "", 1, 0 (* implies src_rem d = 0. *)
|
||||
| `Channel _ -> String.create io_buffer_size, 1, 0 (* idem. *)
|
||||
| `String s -> s, 0, String.length s - 1
|
||||
in
|
||||
{ src = (src :> src); encoding; nln = (nln :> nln option); nl;
|
||||
i; i_pos; i_max; t = String.create 4; t_len = 0; t_need = 0;
|
||||
removed_bom = false; last_cr = false; line = 1; col = 0;
|
||||
byte_count = 0; count = 0;
|
||||
pp = pp_remove_bom (encoding = `UTF_16) pp; k }
|
||||
|
||||
let decode d = d.k d
|
||||
let decoder_line d = d.line
|
||||
let decoder_col d = d.col
|
||||
let decoder_byte_count d = d.byte_count
|
||||
let decoder_count d = d.count
|
||||
let decoder_removed_bom d = d.removed_bom
|
||||
let decoder_src d = d.src
|
||||
let decoder_nln d = d.nln
|
||||
let decoder_encoding d = d.encoding
|
||||
let set_decoder_encoding d e =
|
||||
d.encoding <- (e :> decoder_encoding); d.k <- decode_fun e
|
||||
|
||||
(* Encode *)
|
||||
|
||||
type dst = [ `Channel of out_channel | `Buffer of Buffer.t | `Manual ]
|
||||
type encode = [ `Await | `End | `Uchar of uchar ]
|
||||
type encoder =
|
||||
{ dst : dst; (* output destination. *)
|
||||
encoding : encoding; (* encoded encoding. *)
|
||||
mutable o : string; (* current output chunk. *)
|
||||
mutable o_pos : int; (* next output position to write. *)
|
||||
mutable o_max : int; (* maximal output position to write. *)
|
||||
t : string; (* four bytes buffer for overlapping writes. *)
|
||||
mutable t_pos : int; (* next position to read in [t]. *)
|
||||
mutable t_max : int; (* maximal position to read in [t]. *)
|
||||
mutable k : (* encoder continuation. *)
|
||||
encoder -> encode -> [ `Ok | `Partial ] }
|
||||
|
||||
(* On encodes that overlap two (or more) [e.o] buffers, we encode the
|
||||
character to the temporary buffer [o.t] and continue with
|
||||
[tmp_flush] to write this data on the different [e.o] buffers. If
|
||||
the [e.o] buffers are not too small this is faster than
|
||||
continuation based byte per byte writes. *)
|
||||
|
||||
let o_rem e = e.o_max - e.o_pos + 1 (* remaining bytes to write in [e.o]. *)
|
||||
let dst e s j l = (* set [e.o] with [s]. *)
|
||||
if (j < 0 || l < 0 || j + l > String.length s) then invalid_bounds j l;
|
||||
e.o <- s; e.o_pos <- j; e.o_max <- j + l - 1
|
||||
|
||||
let partial k e = function `Await -> k e | `Uchar _ | `End -> invalid_encode ()
|
||||
let flush k e = match e.dst with(* get free storage in [d.o] and [k]ontinue. *)
|
||||
| `Manual -> e.k <- partial k; `Partial
|
||||
| `Buffer b -> Buffer.add_substring b e.o 0 e.o_pos; e.o_pos <- 0; k e
|
||||
| `Channel oc -> output oc e.o 0 e.o_pos; e.o_pos <- 0; k e
|
||||
|
||||
let t_range e max = e.t_pos <- 0; e.t_max <- max
|
||||
let rec t_flush k e = (* flush [d.t] up to [d.t_max] in [d.i]. *)
|
||||
let blit e l =
|
||||
unsafe_blit e.t e.t_pos e.o e.o_pos l;
|
||||
e.o_pos <- e.o_pos + l; e.t_pos <- e.t_pos + l
|
||||
in
|
||||
let rem = o_rem e in
|
||||
let len = e.t_max - e.t_pos + 1 in
|
||||
if rem < len then (blit e rem; flush (t_flush k) e) else (blit e len; k e)
|
||||
|
||||
(* Encoders. *)
|
||||
|
||||
let rec encode_utf_8 e v =
|
||||
let k e = e.k <- encode_utf_8; `Ok in
|
||||
match v with
|
||||
| `Await -> k e
|
||||
| `End -> flush k e
|
||||
| `Uchar u as v ->
|
||||
let rem = o_rem e in
|
||||
if u <= 0x007F then
|
||||
if rem < 1 then flush (fun e -> encode_utf_8 e v) e else
|
||||
(unsafe_set_byte e.o e.o_pos u; e.o_pos <- e.o_pos + 1; k e)
|
||||
else if u <= 0x07FF then
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 2 then (t_range e 1; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 2; e.o, j, k)
|
||||
in
|
||||
unsafe_set_byte s j (0xC0 lor (u lsr 6));
|
||||
unsafe_set_byte s (j + 1) (0x80 lor (u land 0x3F));
|
||||
k e
|
||||
end
|
||||
else if u <= 0xFFFF then
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 3 then (t_range e 2; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 3; e.o, j, k)
|
||||
in
|
||||
unsafe_set_byte s j (0xE0 lor (u lsr 12));
|
||||
unsafe_set_byte s (j + 1) (0x80 lor ((u lsr 6) land 0x3F));
|
||||
unsafe_set_byte s (j + 2) (0x80 lor (u land 0x3F));
|
||||
k e
|
||||
end
|
||||
else
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 4 then (t_range e 3; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 4; e.o, j, k)
|
||||
in
|
||||
unsafe_set_byte s j (0xF0 lor (u lsr 18));
|
||||
unsafe_set_byte s (j + 1) (0x80 lor ((u lsr 12) land 0x3F));
|
||||
unsafe_set_byte s (j + 2) (0x80 lor ((u lsr 6) land 0x3F));
|
||||
unsafe_set_byte s (j + 3) (0x80 lor (u land 0x3F));
|
||||
k e
|
||||
end
|
||||
|
||||
let rec encode_utf_16be e v =
|
||||
let k e = e.k <- encode_utf_16be; `Ok in
|
||||
match v with
|
||||
| `Await -> k e
|
||||
| `End -> flush k e
|
||||
| `Uchar u ->
|
||||
let rem = o_rem e in
|
||||
if u < 0x10000 then
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 2 then (t_range e 1; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 2; e.o, j, k)
|
||||
in
|
||||
unsafe_set_byte s j (u lsr 8);
|
||||
unsafe_set_byte s (j + 1) (u land 0xFF);
|
||||
k e
|
||||
end else begin
|
||||
let s, j, k =
|
||||
if rem < 4 then (t_range e 3; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 4; e.o, j, k)
|
||||
in
|
||||
let u' = u - 0x10000 in
|
||||
let hi = (0xD800 lor (u' lsr 10)) in
|
||||
let lo = (0xDC00 lor (u' land 0x3FF)) in
|
||||
unsafe_set_byte s j (hi lsr 8);
|
||||
unsafe_set_byte s (j + 1) (hi land 0xFF);
|
||||
unsafe_set_byte s (j + 2) (lo lsr 8);
|
||||
unsafe_set_byte s (j + 3) (lo land 0xFF);
|
||||
k e
|
||||
end
|
||||
|
||||
let rec encode_utf_16le e v = (* encode_uft_16be with bytes swapped. *)
|
||||
let k e = e.k <- encode_utf_16le; `Ok in
|
||||
match v with
|
||||
| `Await -> k e
|
||||
| `End -> flush k e
|
||||
| `Uchar u ->
|
||||
let rem = o_rem e in
|
||||
if u < 0x10000 then
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 2 then (t_range e 1; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 2; e.o, j, k)
|
||||
in
|
||||
unsafe_set_byte s j (u land 0xFF);
|
||||
unsafe_set_byte s (j + 1) (u lsr 8);
|
||||
k e
|
||||
end
|
||||
else
|
||||
begin
|
||||
let s, j, k =
|
||||
if rem < 4 then (t_range e 3; e.t, 0, t_flush k) else
|
||||
let j = e.o_pos in (e.o_pos <- e.o_pos + 4; e.o, j, k)
|
||||
in
|
||||
let u' = u - 0x10000 in
|
||||
let hi = (0xD800 lor (u' lsr 10)) in
|
||||
let lo = (0xDC00 lor (u' land 0x3FF)) in
|
||||
unsafe_set_byte s j (hi land 0xFF);
|
||||
unsafe_set_byte s (j + 1) (hi lsr 8);
|
||||
unsafe_set_byte s (j + 2) (lo land 0xFF);
|
||||
unsafe_set_byte s (j + 3) (lo lsr 8);
|
||||
k e
|
||||
end
|
||||
|
||||
let encode_fun = function
|
||||
| `UTF_8 -> encode_utf_8
|
||||
| `UTF_16 -> encode_utf_16be
|
||||
| `UTF_16BE -> encode_utf_16be
|
||||
| `UTF_16LE -> encode_utf_16le
|
||||
|
||||
let encoder encoding dst =
|
||||
let o, o_pos, o_max = match dst with
|
||||
| `Manual -> "", 1, 0 (* implies o_rem e = 0. *)
|
||||
| `Buffer _
|
||||
| `Channel _ -> String.create io_buffer_size, 0, io_buffer_size - 1
|
||||
in
|
||||
{ dst = (dst :> dst); encoding = (encoding :> encoding); o; o_pos; o_max;
|
||||
t = String.create 4; t_pos = 1; t_max = 0; k = encode_fun encoding}
|
||||
|
||||
let encode e v = e.k e (v :> encode)
|
||||
let encoder_encoding e = e.encoding
|
||||
let encoder_dst e = e.dst
|
||||
|
||||
(* Manual sources and destinations. *)
|
||||
|
||||
module Manual = struct
|
||||
let src = src
|
||||
let dst = dst
|
||||
let dst_rem = o_rem
|
||||
end
|
||||
|
||||
(* Strings folders and Buffer encoders *)
|
||||
|
||||
module String = struct
|
||||
let encoding_guess s = match r_encoding s 0 (max (String.length s) 3) with
|
||||
| `UTF_8 d -> `UTF_8, (d = `BOM)
|
||||
| `UTF_16BE d -> `UTF_16BE, (d = `BOM)
|
||||
| `UTF_16LE d -> `UTF_16LE, (d = `BOM)
|
||||
|
||||
type 'a folder =
|
||||
'a -> int -> [ `Uchar of uchar | `Malformed of string ] -> 'a
|
||||
|
||||
let fold_utf_8 f acc s =
|
||||
let rec loop acc f s i l =
|
||||
if i = l then acc else
|
||||
let need = unsafe_array_get utf_8_len (unsafe_byte s i) in
|
||||
if need = 0 then loop (f acc i (malformed s i 1)) f s (i + 1) l else
|
||||
let rem = l - i in
|
||||
if rem < need then f acc i (malformed s i rem) else
|
||||
loop (f acc i (r_utf_8 s i need)) f s (i + need) l
|
||||
in
|
||||
loop acc f s 0 (String.length s)
|
||||
|
||||
let fold_utf_16be f acc s =
|
||||
let rec loop acc f s i l =
|
||||
if i = l then acc else
|
||||
let rem = l - i in
|
||||
if rem < 2 then f acc i (malformed s i 1) else
|
||||
match r_utf_16 s i (i + 1) with
|
||||
| `Uchar _ | `Malformed _ as v -> loop (f acc i v) f s (i + 2) l
|
||||
| `Hi hi ->
|
||||
if rem < 4 then f acc i (malformed s i rem) else
|
||||
loop (f acc i (r_utf_16_lo hi s (i + 2) (i + 3))) f s (i + 4) l
|
||||
in
|
||||
loop acc f s 0 (String.length s)
|
||||
|
||||
let fold_utf_16le f acc s = (* [fold_utf_16be], bytes swapped. *)
|
||||
let rec loop acc f s i l =
|
||||
if i = l then acc else
|
||||
let rem = l - i in
|
||||
if rem < 2 then f acc i (malformed s i 1) else
|
||||
match r_utf_16 s (i + 1) i with
|
||||
| `Uchar _ | `Malformed _ as v -> loop (f acc i v) f s (i + 2) l
|
||||
| `Hi hi ->
|
||||
if rem < 4 then f acc i (malformed s i rem) else
|
||||
loop (f acc i (r_utf_16_lo hi s (i + 3) (i + 2))) f s (i + 4) l
|
||||
in
|
||||
loop acc f s 0 (String.length s)
|
||||
end
|
||||
|
||||
module Buffer = struct
|
||||
let add_utf_8 b u =
|
||||
let w byte = Buffer.add_char b (unsafe_chr byte) in (* inlined. *)
|
||||
if u <= 0x007F then
|
||||
(w u)
|
||||
else if u <= 0x07FF then
|
||||
(w (0xC0 lor (u lsr 6));
|
||||
w (0x80 lor (u land 0x3F)))
|
||||
else if u <= 0xFFFF then
|
||||
(w (0xE0 lor (u lsr 12));
|
||||
w (0x80 lor ((u lsr 6) land 0x3F));
|
||||
w (0x80 lor (u land 0x3F)))
|
||||
else
|
||||
(w (0xF0 lor (u lsr 18));
|
||||
w (0x80 lor ((u lsr 12) land 0x3F));
|
||||
w (0x80 lor ((u lsr 6) land 0x3F));
|
||||
w (0x80 lor (u land 0x3F)))
|
||||
|
||||
let add_utf_16be b u =
|
||||
let w byte = Buffer.add_char b (unsafe_chr byte) in (* inlined. *)
|
||||
if u < 0x10000 then (w (u lsr 8); w (u land 0xFF)) else
|
||||
let u' = u - 0x10000 in
|
||||
let hi = (0xD800 lor (u' lsr 10)) in
|
||||
let lo = (0xDC00 lor (u' land 0x3FF)) in
|
||||
w (hi lsr 8); w (hi land 0xFF);
|
||||
w (lo lsr 8); w (lo land 0xFF)
|
||||
|
||||
let add_utf_16le b u = (* swapped add_utf_16be. *)
|
||||
let w byte = Buffer.add_char b (unsafe_chr byte) in (* inlined. *)
|
||||
if u < 0x10000 then (w (u land 0xFF); w (u lsr 8)) else
|
||||
let u' = u - 0x10000 in
|
||||
let hi = (0xD800 lor (u' lsr 10)) in
|
||||
let lo = (0xDC00 lor (u' land 0x3FF)) in
|
||||
w (hi land 0xFF); w (hi lsr 8);
|
||||
w (lo land 0xFF); w (lo lsr 8)
|
||||
end
|
||||
|
||||
(*---------------------------------------------------------------------------
|
||||
Copyright 2012 Daniel C. Bünzli
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
3. Neither the name of Daniel C. Bünzli nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*)
|
||||
15
samples/PLSQL/myobject.sql
Normal file
15
samples/PLSQL/myobject.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
create or replace type myobject
|
||||
AUTHID DEFINER
|
||||
AS OBJECT
|
||||
(
|
||||
m_name varchar2(200),
|
||||
member function toString RETURN VARCHAR2,
|
||||
map member function Compare return varchar2
|
||||
|
||||
)
|
||||
not instantiable not final;
|
||||
/
|
||||
|
||||
prompt create type myarray
|
||||
create or replace type myarray as table of myobject;
|
||||
/
|
||||
58
samples/PLSQL/packagebody.pkb
Normal file
58
samples/PLSQL/packagebody.pkb
Normal file
@@ -0,0 +1,58 @@
|
||||
CREATE OR REPLACE PACKAGE BODY linguistpackage
|
||||
AS
|
||||
/*
|
||||
* Package: linguist pacakage body
|
||||
* Purpose: a sample PLSQL file for linguist to work with
|
||||
*
|
||||
* Date: 03/03/2014
|
||||
* Author: david pyke le brun
|
||||
* Comments: initial version
|
||||
*/
|
||||
|
||||
PROCEDURE proc_1
|
||||
IS
|
||||
BEGIN
|
||||
NULL;
|
||||
END;
|
||||
|
||||
-- functions with 1 arg
|
||||
FUNCTION function1( param1 VARCHAR2 ) RETURN VARCHAR2
|
||||
IS
|
||||
CURSOR c IS
|
||||
select * from dual;
|
||||
v c%ROWTYPE;
|
||||
BEGIN
|
||||
open c;
|
||||
fetch c into v;
|
||||
close c;
|
||||
|
||||
return v;
|
||||
end;
|
||||
|
||||
FUNCTION function2( param1 NUMBER ) RETURN DATE
|
||||
IS
|
||||
BEGIN
|
||||
return SYSDATE;
|
||||
end;
|
||||
|
||||
--a few more to use all basic SQL types
|
||||
FUNCTION function3( param1 TIMESTAMP ) RETURN CHAR
|
||||
IS
|
||||
BEGIN
|
||||
IF 1 = 2 THEN
|
||||
return 'Y';
|
||||
ELSE
|
||||
return 'N';
|
||||
END IF;
|
||||
return NULL;
|
||||
END;
|
||||
|
||||
|
||||
FUNCTION function4( param1 CLOB ) RETURN BLOB
|
||||
IS
|
||||
BEGIN
|
||||
return null;
|
||||
END;
|
||||
|
||||
END linguistpackage;
|
||||
/
|
||||
28
samples/PLSQL/packageheader.pks
Normal file
28
samples/PLSQL/packageheader.pks
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE OR REPLACE PACKAGE linguistpackage
|
||||
AUTHID DEFINER
|
||||
AS
|
||||
/*
|
||||
* Package: linguist pacakage
|
||||
* Purpose: a sample PLSQL file for linguist to work with
|
||||
*
|
||||
* Date: 03/03/2014
|
||||
* Author: david pyke le brun
|
||||
* Comments: initial version
|
||||
*/
|
||||
|
||||
k_constant CONSTANT NUMBER(10,2) := 3.14;
|
||||
|
||||
--basic procedure
|
||||
PROCEDURE proc_1;
|
||||
|
||||
-- functions with 1 arg
|
||||
FUNCTION function1( param1 VARCHAR2 ) RETURN VARCHAR2;
|
||||
FUNCTION function2( param1 NUMBER ) RETURN DATE;
|
||||
|
||||
--a few more to use all basic SQL types
|
||||
FUNCTION function3( param1 TIMESTAMP ) RETURN CHAR;
|
||||
FUNCTION function4( param1 CLOB ) RETURN BLOB;
|
||||
|
||||
END linguistpackage;
|
||||
/
|
||||
|
||||
93
samples/PLSQL/prime#.plsql
Normal file
93
samples/PLSQL/prime#.plsql
Normal file
@@ -0,0 +1,93 @@
|
||||
create or replace package prime#
|
||||
is
|
||||
invalid_argument_error exception;
|
||||
|
||||
function nth (
|
||||
i_num pls_integer
|
||||
) return number;
|
||||
end prime#;
|
||||
/
|
||||
|
||||
create or replace package body prime#
|
||||
is
|
||||
type t_primes is table of number index by pls_integer;
|
||||
b_primes t_primes;
|
||||
|
||||
function is_prime(
|
||||
i_candidate number
|
||||
) return boolean
|
||||
is
|
||||
l_num number := 1;
|
||||
l_prime number;
|
||||
l_result number;
|
||||
begin
|
||||
if i_candidate < 2 then
|
||||
return false;
|
||||
end if;
|
||||
|
||||
loop
|
||||
l_prime := nth(l_num);
|
||||
if l_prime = i_candidate then
|
||||
return true;
|
||||
end if;
|
||||
|
||||
l_result := i_candidate / l_prime;
|
||||
if l_result = ceil(l_result) then
|
||||
return false;
|
||||
end if;
|
||||
|
||||
l_num := l_num + 1;
|
||||
exit when l_result <= l_prime;
|
||||
end loop;
|
||||
|
||||
return true;
|
||||
end is_prime;
|
||||
|
||||
function next (
|
||||
i_prime pls_integer
|
||||
) return number
|
||||
is
|
||||
l_next number;
|
||||
begin
|
||||
l_next := i_prime + case mod(i_prime, 2) when 0 then 1 else 2 end;
|
||||
|
||||
while not is_prime(l_next) loop
|
||||
l_next := l_next + 2;
|
||||
end loop;
|
||||
return l_next;
|
||||
end next;
|
||||
|
||||
function nth (
|
||||
i_num pls_integer
|
||||
) return number
|
||||
is
|
||||
l_index number := 2;
|
||||
l_prime number := 3;
|
||||
begin
|
||||
if i_num < 1
|
||||
or ceil(i_num) != i_num
|
||||
then
|
||||
raise invalid_argument_error;
|
||||
end if;
|
||||
|
||||
case i_num
|
||||
when 1 then return 2;
|
||||
else
|
||||
if b_primes.exists(i_num) then
|
||||
return b_primes(i_num);
|
||||
end if;
|
||||
while l_index < i_num loop
|
||||
l_index := l_index + 1;
|
||||
if b_primes.exists(l_index) then
|
||||
l_prime := b_primes(l_index);
|
||||
else
|
||||
l_prime := next(l_prime);
|
||||
b_primes(l_index) := l_prime;
|
||||
end if;
|
||||
end loop;
|
||||
return l_prime;
|
||||
end case;
|
||||
end nth;
|
||||
|
||||
end prime#;
|
||||
/
|
||||
65
samples/PLSQL/who_called_me.sql
Normal file
65
samples/PLSQL/who_called_me.sql
Normal file
@@ -0,0 +1,65 @@
|
||||
CREATE OR REPLACE PROCEDURE who_called_me
|
||||
( owner OUT VARCHAR2,
|
||||
name OUT VARCHAR2,
|
||||
lineno OUT NUMBER,
|
||||
caller_t OUT VARCHAR2 ,
|
||||
depth NUMBER DEFAULT 1
|
||||
)
|
||||
AUTHID DEFINER
|
||||
AS
|
||||
--depth based version of who_called_me from asktom
|
||||
call_stack VARCHAR2(4096) default dbms_utility.format_call_stack;
|
||||
n NUMBER;
|
||||
found_stack BOOLEAN DEFAULT FALSE;
|
||||
line VARCHAR2(255);
|
||||
cnt NUMBER := 0;
|
||||
BEGIN
|
||||
LOOP
|
||||
n := instr( call_stack, chr(10) );
|
||||
exit when ( n is NULL or n = 0 );
|
||||
--
|
||||
line := substr( call_stack, 1, n-1 );
|
||||
call_stack := substr( call_stack, n+1 );
|
||||
--
|
||||
if ( NOT found_stack ) then
|
||||
if ( line like '%handle%number%name%' ) then
|
||||
found_stack := TRUE;
|
||||
end if;
|
||||
else
|
||||
cnt := cnt + 1;
|
||||
-- cnt = 1 is ME
|
||||
-- cnt = 2 is MY Caller
|
||||
-- cnt = 3 is Their Caller
|
||||
if ( cnt = (2+depth) ) then
|
||||
lineno := to_number(substr( line, 13, 8 ));
|
||||
line := substr( line, 23 ); --set to rest of line .. change from 21 to 23
|
||||
if ( line like 'pr%' ) then
|
||||
n := length( 'procedure ' );
|
||||
elsif ( line like 'fun%' ) then
|
||||
n := length( 'function ' );
|
||||
elsif ( line like 'package body%' ) then
|
||||
n := length( 'package body ' );
|
||||
elsif ( line like 'pack%' ) then
|
||||
n := length( 'package ' );
|
||||
elsif ( line like 'anonymous%' ) then
|
||||
n := length( 'anonymous block ' );
|
||||
else
|
||||
n := null;
|
||||
end if;
|
||||
if ( n is not null ) then
|
||||
caller_t := ltrim(rtrim(upper(substr( line, 1, n-1 ))));
|
||||
else
|
||||
caller_t := 'TRIGGER';
|
||||
end if;
|
||||
|
||||
line := substr( line, nvl(n,1) );
|
||||
n := instr( line, '.' );
|
||||
owner := ltrim(rtrim(substr( line, 1, n-1 )));
|
||||
name := LTRIM(RTRIM(SUBSTR( LINE, N+1 )));
|
||||
exit;
|
||||
END IF;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
/
|
||||
|
||||
165
samples/PLpgSQL/plpgsql_lint-8.4.sql
Normal file
165
samples/PLpgSQL/plpgsql_lint-8.4.sql
Normal file
@@ -0,0 +1,165 @@
|
||||
load 'plpgsql';
|
||||
load 'plpgsql_lint';
|
||||
|
||||
create table t1(a int, b int);
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
update t1 set c = 30;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
as $$
|
||||
select 10,20;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
r := g1();
|
||||
if false then
|
||||
raise notice '%', r.c;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
returns setof record as $$
|
||||
select * from t1;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
raise notice '%', r.c;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
r.c := 20;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function f1()
|
||||
returns int as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r := a + b;
|
||||
end if;
|
||||
return r;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '%', 1, 2;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '% %';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int[];
|
||||
begin
|
||||
if false then
|
||||
r[c+10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r[10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create type diagnostic_info_type as (
|
||||
status text,
|
||||
message text,
|
||||
detail text,
|
||||
row_count int);
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare
|
||||
dg record;
|
||||
begin
|
||||
dg := NULL::diagnostic_info_type;
|
||||
if false then
|
||||
dg.status := '00000';
|
||||
dg.mistake := 'hello';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
165
samples/PLpgSQL/plpgsql_lint-9.0.sql
Normal file
165
samples/PLpgSQL/plpgsql_lint-9.0.sql
Normal file
@@ -0,0 +1,165 @@
|
||||
load 'plpgsql';
|
||||
load 'plpgsql_lint';
|
||||
|
||||
create table t1(a int, b int);
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
update t1 set c = 30;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
as $$
|
||||
select 10,20;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
r := g1();
|
||||
if false then
|
||||
raise notice '%', r.c;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
returns setof record as $$
|
||||
select * from t1;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
raise notice '%', r.c;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
r.c := 20;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function f1()
|
||||
returns int as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r := a + b;
|
||||
end if;
|
||||
return r;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '%', 1, 2;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '% %';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int[];
|
||||
begin
|
||||
if false then
|
||||
r[c+10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r[10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create type diagnostic_info_type as (
|
||||
status text,
|
||||
message text,
|
||||
detail text,
|
||||
row_count int);
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare
|
||||
dg record;
|
||||
begin
|
||||
dg := NULL::diagnostic_info_type;
|
||||
if false then
|
||||
dg.status := '00000';
|
||||
dg.mistake := 'hello';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
179
samples/PLpgSQL/plpgsql_lint-9.1.sql
Normal file
179
samples/PLpgSQL/plpgsql_lint-9.1.sql
Normal file
@@ -0,0 +1,179 @@
|
||||
load 'plpgsql';
|
||||
load 'plpgsql_lint';
|
||||
|
||||
create table t1(a int, b int);
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
update t1 set c = 30;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
as $$
|
||||
select 10,20;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
r := g1();
|
||||
if false then
|
||||
raise notice '%', r.c;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
returns setof record as $$
|
||||
select * from t1;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
raise notice '%', r.c;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
r.c := 20;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function f1()
|
||||
returns int as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r := a + b;
|
||||
end if;
|
||||
return r;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '%', 1, 2;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '% %';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int[];
|
||||
begin
|
||||
if false then
|
||||
r[c+10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r[10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create type diagnostic_info_type as (
|
||||
status text,
|
||||
message text,
|
||||
detail text,
|
||||
row_count int);
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare dg record;
|
||||
begin
|
||||
dg := NULL::diagnostic_info_type;
|
||||
if false then
|
||||
dg.status := '00000';
|
||||
dg.mistake := 'hello';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare dg record;
|
||||
begin
|
||||
if false then
|
||||
dg := 10,20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
166
samples/PLpgSQL/plpgsql_lint-9.2.sql
Normal file
166
samples/PLpgSQL/plpgsql_lint-9.2.sql
Normal file
@@ -0,0 +1,166 @@
|
||||
load 'plpgsql';
|
||||
load 'plpgsql_lint';
|
||||
|
||||
create table t1(a int, b int);
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
update t1 set c = 30;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
as $$
|
||||
select 10,20;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
r := g1();
|
||||
if false then
|
||||
raise notice '%', r.c;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
returns setof record as $$
|
||||
select * from t1;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
raise notice '%', r.c;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
r.c := 20;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function f1()
|
||||
returns int as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r := a + b;
|
||||
end if;
|
||||
return r;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '%', 1, 2;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '% %';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int[];
|
||||
begin
|
||||
if false then
|
||||
r[c+10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r[10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create type _exception_type as (
|
||||
state text,
|
||||
message text,
|
||||
detail text);
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare
|
||||
_exception record;
|
||||
begin
|
||||
_exception := NULL::_exception_type;
|
||||
exception when others then
|
||||
get stacked diagnostics
|
||||
_exception.state = RETURNED_SQLSTATE,
|
||||
_exception.message = MESSAGE_TEXT,
|
||||
_exception.detail = PG_EXCEPTION_DETAIL,
|
||||
_exception.hint = PG_EXCEPTION_HINT;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
166
samples/PLpgSQL/plpgsql_lint-9.3.sql
Normal file
166
samples/PLpgSQL/plpgsql_lint-9.3.sql
Normal file
@@ -0,0 +1,166 @@
|
||||
load 'plpgsql';
|
||||
load 'plpgsql_lint';
|
||||
|
||||
create table t1(a int, b int);
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
update t1 set c = 30;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
as $$
|
||||
select 10,20;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
r := g1();
|
||||
if false then
|
||||
raise notice '%', r.c;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function g1(out a int, out b int)
|
||||
returns setof record as $$
|
||||
select * from t1;
|
||||
$$ language sql;
|
||||
|
||||
create function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
raise notice '%', r.c;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r record;
|
||||
begin
|
||||
for r in select * from g1()
|
||||
loop
|
||||
r.c := 20;
|
||||
end loop;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
drop function g1();
|
||||
|
||||
create function f1()
|
||||
returns int as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r := a + b;
|
||||
end if;
|
||||
return r;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '%', 1, 2;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
begin
|
||||
if false then
|
||||
raise notice '% %';
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int[];
|
||||
begin
|
||||
if false then
|
||||
r[c+10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare r int;
|
||||
begin
|
||||
if false then
|
||||
r[10] := 20;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
|
||||
create type _exception_type as (
|
||||
state text,
|
||||
message text,
|
||||
detail text);
|
||||
|
||||
create or replace function f1()
|
||||
returns void as $$
|
||||
declare
|
||||
_exception record;
|
||||
begin
|
||||
_exception := NULL::_exception_type;
|
||||
exception when others then
|
||||
get stacked diagnostics
|
||||
_exception.state = RETURNED_SQLSTATE,
|
||||
_exception.message = MESSAGE_TEXT,
|
||||
_exception.detail = PG_EXCEPTION_DETAIL,
|
||||
_exception.hint = PG_EXCEPTION_HINT;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
select f1();
|
||||
|
||||
drop function f1();
|
||||
121
samples/Pascal/cwindirs.pp
Normal file
121
samples/Pascal/cwindirs.pp
Normal file
@@ -0,0 +1,121 @@
|
||||
|
||||
unit cwindirs;
|
||||
|
||||
|
||||
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
windows,
|
||||
strings;
|
||||
|
||||
Const
|
||||
CSIDL_PROGRAMS = $0002;
|
||||
CSIDL_PERSONAL = $0005;
|
||||
CSIDL_FAVORITES = $0006;
|
||||
CSIDL_STARTUP = $0007;
|
||||
CSIDL_RECENT = $0008;
|
||||
CSIDL_SENDTO = $0009;
|
||||
CSIDL_STARTMENU = $000B;
|
||||
CSIDL_MYMUSIC = $000D;
|
||||
CSIDL_MYVIDEO = $000E;
|
||||
CSIDL_DESKTOPDIRECTORY = $0010;
|
||||
CSIDL_NETHOOD = $0013;
|
||||
CSIDL_TEMPLATES = $0015;
|
||||
CSIDL_COMMON_STARTMENU = $0016;
|
||||
CSIDL_COMMON_PROGRAMS = $0017;
|
||||
CSIDL_COMMON_STARTUP = $0018;
|
||||
CSIDL_COMMON_DESKTOPDIRECTORY = $0019;
|
||||
CSIDL_APPDATA = $001A;
|
||||
CSIDL_PRINTHOOD = $001B;
|
||||
CSIDL_LOCAL_APPDATA = $001C;
|
||||
CSIDL_COMMON_FAVORITES = $001F;
|
||||
CSIDL_INTERNET_CACHE = $0020;
|
||||
CSIDL_COOKIES = $0021;
|
||||
CSIDL_HISTORY = $0022;
|
||||
CSIDL_COMMON_APPDATA = $0023;
|
||||
CSIDL_WINDOWS = $0024;
|
||||
CSIDL_SYSTEM = $0025;
|
||||
CSIDL_PROGRAM_FILES = $0026;
|
||||
CSIDL_MYPICTURES = $0027;
|
||||
CSIDL_PROFILE = $0028;
|
||||
CSIDL_PROGRAM_FILES_COMMON = $002B;
|
||||
CSIDL_COMMON_TEMPLATES = $002D;
|
||||
CSIDL_COMMON_DOCUMENTS = $002E;
|
||||
CSIDL_COMMON_ADMINTOOLS = $002F;
|
||||
CSIDL_ADMINTOOLS = $0030;
|
||||
CSIDL_COMMON_MUSIC = $0035;
|
||||
CSIDL_COMMON_PICTURES = $0036;
|
||||
CSIDL_COMMON_VIDEO = $0037;
|
||||
CSIDL_CDBURN_AREA = $003B;
|
||||
CSIDL_PROFILES = $003E;
|
||||
|
||||
CSIDL_FLAG_CREATE = $8000;
|
||||
|
||||
Function GetWindowsSpecialDir(ID : Integer) : String;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
sysutils;
|
||||
|
||||
Type
|
||||
PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall;
|
||||
|
||||
|
||||
var
|
||||
SHGetFolderPath : PFNSHGetFolderPath = Nil;
|
||||
CFGDLLHandle : THandle = 0;
|
||||
|
||||
Procedure InitDLL;
|
||||
|
||||
Var
|
||||
pathBuf: array[0..MAX_PATH-1] of char;
|
||||
pathLength: Integer;
|
||||
begin
|
||||
{ Load shfolder.dll using a full path, in order to prevent spoofing (Mantis #18185)
|
||||
Don't bother loading shell32.dll because shfolder.dll itself redirects SHGetFolderPath
|
||||
to shell32.dll whenever possible. }
|
||||
pathLength:=GetSystemDirectory(pathBuf, MAX_PATH);
|
||||
if (pathLength>0) and (pathLength<MAX_PATH-14) then
|
||||
begin
|
||||
StrLCopy(@pathBuf[pathLength],'\shfolder.dll',MAX_PATH-pathLength-1);
|
||||
CFGDLLHandle:=LoadLibrary(pathBuf);
|
||||
|
||||
if (CFGDLLHandle<>0) then
|
||||
begin
|
||||
Pointer(ShGetFolderPath):=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
|
||||
If @ShGetFolderPath=nil then
|
||||
begin
|
||||
FreeLibrary(CFGDLLHandle);
|
||||
CFGDllHandle:=0;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
If (@ShGetFolderPath=Nil) then
|
||||
Raise Exception.Create('Could not determine SHGetFolderPath Function');
|
||||
end;
|
||||
|
||||
Function GetWindowsSpecialDir(ID : Integer) : String;
|
||||
|
||||
Var
|
||||
APath : Array[0..MAX_PATH] of char;
|
||||
|
||||
begin
|
||||
Result:='';
|
||||
if (CFGDLLHandle=0) then
|
||||
InitDLL;
|
||||
If (SHGetFolderPath<>Nil) then
|
||||
begin
|
||||
if SHGetFolderPath(0,ID or CSIDL_FLAG_CREATE,0,0,@APATH[0])=S_OK then
|
||||
Result:=IncludeTrailingPathDelimiter(StrPas(@APath[0]));
|
||||
end;
|
||||
end;
|
||||
|
||||
Initialization
|
||||
Finalization
|
||||
if CFGDLLHandle<>0 then
|
||||
FreeLibrary(CFGDllHandle);
|
||||
end.
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
gtkextra.pp - GTK(2) widgetset - additional gdk/gtk functions
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This unit contains missing gdk/gtk functions and defines for certain
|
||||
versions of gtk or fpc.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Sun Jan 28th WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
*****************************************************************************
|
||||
This file is part of the Lazarus Component Library (LCL)
|
||||
|
||||
See the file COPYING.modifiedLGPL.txt, included in this distribution,
|
||||
for details about the license.
|
||||
*****************************************************************************
|
||||
}
|
||||
|
||||
unit GtkExtra;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
{$I gtkdefines.inc}
|
||||
|
||||
{$ifdef gtk1}
|
||||
{$I gtk1extrah.inc}
|
||||
{$endif}
|
||||
|
||||
{$ifdef gtk2}
|
||||
{$I gtk2extrah.inc}
|
||||
{$endif}
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$ifdef gtk1}
|
||||
{$I gtk1extra.inc}
|
||||
{$endif}
|
||||
|
||||
{$ifdef gtk2}
|
||||
{$I gtk2extra.inc}
|
||||
{$endif}
|
||||
|
||||
end.
|
||||
22
samples/Pascal/large.pp
Normal file
22
samples/Pascal/large.pp
Normal file
@@ -0,0 +1,22 @@
|
||||
program large;
|
||||
|
||||
const
|
||||
max = 100000000;
|
||||
|
||||
type
|
||||
tlist = array[1..max] of longint;
|
||||
|
||||
var
|
||||
data : tlist;
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
|
||||
i := 0;
|
||||
while(i < max)
|
||||
do
|
||||
begin
|
||||
data[i] := 0;
|
||||
Writeln(data[i])
|
||||
end
|
||||
end.
|
||||
26
samples/Pascal/tw27294.pp
Normal file
26
samples/Pascal/tw27294.pp
Normal file
@@ -0,0 +1,26 @@
|
||||
uses
|
||||
uw27294;
|
||||
|
||||
var
|
||||
p : procedure;
|
||||
|
||||
procedure test;
|
||||
|
||||
begin
|
||||
p:=@test;
|
||||
writeln('OK');
|
||||
end;
|
||||
|
||||
procedure global;
|
||||
begin
|
||||
p:=nil;
|
||||
test;
|
||||
p();
|
||||
end;
|
||||
|
||||
begin
|
||||
global;
|
||||
uw27294.global;
|
||||
end.
|
||||
|
||||
|
||||
117
samples/Perl/exception_handler.pl
Normal file
117
samples/Perl/exception_handler.pl
Normal file
@@ -0,0 +1,117 @@
|
||||
package exception_handler;
|
||||
use sigtrap qw(die normal-signals);
|
||||
use IO::Handle;
|
||||
use Carp;
|
||||
use File::Spec;
|
||||
use File::Basename;
|
||||
use Data::Dumper;
|
||||
|
||||
use sigtrap 'handler', \&tm_die;
|
||||
|
||||
$Carp::CarpLevel = 1; # How many extra package levels to skip on carp.
|
||||
|
||||
BEGIN {
|
||||
*CORE::GLOBAL::die = \&tm_die;
|
||||
$main::SIG{__DIE__} = \&tm_die;
|
||||
my $error_fd = $ENV{"TM_ERROR_FD"};
|
||||
open (TM_ERROR_FD, ">&=$error_fd");
|
||||
TM_ERROR_FD->autoflush(1);
|
||||
}
|
||||
|
||||
sub realwarn { CORE::warn(@_); }
|
||||
sub realdie { CORE::die(@_); }
|
||||
|
||||
sub longmess {
|
||||
my ($arg, @rest) = shift;
|
||||
{
|
||||
local $@;
|
||||
# XXX fix require to not clear $@?
|
||||
# don't use require unless we need to (for Safe compartments)
|
||||
require Carp::Heavy unless $INC{"Carp/Heavy.pm"};
|
||||
}
|
||||
# Icky backwards compatibility wrapper. :-(
|
||||
my $call_pack = caller();
|
||||
if ($Internal{$call_pack} or $Carp::CarpInternal{$call_pack}) {
|
||||
return longmess_heavy($arg, @rest);
|
||||
}
|
||||
else {
|
||||
local $Carp::CarpLevel = $Carp::CarpLevel + 1;
|
||||
return longmess_heavy($arg, @rest);
|
||||
}
|
||||
}
|
||||
|
||||
sub longmess_heavy {
|
||||
return @_ if ref($_[0]); # don't break references as exceptions
|
||||
my $i = Carp::long_error_loc();
|
||||
my ($arg, @rest) = @_;
|
||||
return ret_backtrace($i, $arg, @rest);
|
||||
}
|
||||
|
||||
sub quote {
|
||||
my $str = shift;
|
||||
$str =~ s/([^A-Za-z0-9\/_.-])/sprintf("%%%02X", ord($1))/seg;
|
||||
return $str;
|
||||
}
|
||||
|
||||
sub url_and_display_name {
|
||||
my $file = shift;
|
||||
my $url = "";
|
||||
my $display_name = "";
|
||||
$display_name = basename($file);
|
||||
$url = 'url=file://' . quote($file);
|
||||
return ($url, $display_name);
|
||||
}
|
||||
|
||||
# Returns a full stack backtrace starting from where it is
|
||||
# told.
|
||||
sub ret_backtrace {
|
||||
my ($i, $arg, @rest) = @_;
|
||||
my $mess;
|
||||
$i++;
|
||||
|
||||
my $tid_msg = '';
|
||||
if (defined &Thread::tid) {
|
||||
my $tid = Thread->self->tid;
|
||||
$tid_msg = " thread $tid" if $tid;
|
||||
}
|
||||
|
||||
my %i = Carp::caller_info($i);
|
||||
$arg =~ s/\n/\<br\>/g;
|
||||
$i{sub} =~ s/tm_die/die/g;
|
||||
$mess .= "<div id='exception_report' class='framed'>\n";
|
||||
$mess .= "<p id='exception'><strong>$arg</strong></p>\n";
|
||||
$mess .= "<blockquote><table border='0' cellspacing='0' cellpadding='0'>\n";
|
||||
my ($url, $display_name) = url_and_display_name($i{file});
|
||||
$mess .= "<tr><td><a href='txmt://open?line=$i{line}&" . $url . "'>$i{sub}</a></td><td> in $display_name at line $i{line}$tid_msg</td></tr>\n";
|
||||
while (my %i = Carp::caller_info(++$i)) {
|
||||
($url, $display_name) = url_and_display_name($i{file});
|
||||
$mess .= "<tr><td><a href='txmt://open?line=$i{line}&" . $url . "'>$i{sub}</a></td><td> in $display_name at line $i{line}$tid_msg</td></tr>\n";
|
||||
}
|
||||
$mess .= "</table></blockquote></div>";
|
||||
return $mess;
|
||||
}
|
||||
|
||||
sub ineval {
|
||||
(exists $ENV{MOD_PERL} ? 0 : $^S) || Carp::longmess() =~ /eval [\{\']/m
|
||||
}
|
||||
|
||||
sub htmlize {
|
||||
my $l = shift;
|
||||
$l =~ s/&/&/g;
|
||||
$l =~ s/</</g;
|
||||
$l =~ s/>/>/g;
|
||||
return $l;
|
||||
}
|
||||
|
||||
sub tm_die {
|
||||
my ($arg,@rest) = @_;
|
||||
if (ineval()) {
|
||||
realdie ($arg,@rest) if ineval();
|
||||
}
|
||||
if (!ref($arg)) {
|
||||
print TM_ERROR_FD longmess($arg,@rest);
|
||||
}
|
||||
exit($!);
|
||||
}
|
||||
|
||||
1;
|
||||
3
samples/Perl/use5.pl
Normal file
3
samples/Perl/use5.pl
Normal file
@@ -0,0 +1,3 @@
|
||||
use Mojolicious::Lite;
|
||||
use 5.20.0;
|
||||
use experimental 'signatures';
|
||||
116
samples/PowerShell/ZLocation.psd1
Normal file
116
samples/PowerShell/ZLocation.psd1
Normal file
@@ -0,0 +1,116 @@
|
||||
#
|
||||
# Module manifest for module 'ZLocation'
|
||||
#
|
||||
# Generated by: sevoroby
|
||||
#
|
||||
# Generated on: 12/10/2014
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ZLocation.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '18e8ca17-7f67-4f1c-85ff-159373bf66f5'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Sergei Vorobev'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2014 Sergei Vorobev. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
# Description = ''
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
||||
# Minimum version of the Windows PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module
|
||||
# DotNetFrameworkVersion = ''
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module
|
||||
# CLRVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
# ScriptsToProcess = @()
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
NestedModules = @("ZLocation.Storage.psm1", "ZLocation.Search.psm1")
|
||||
|
||||
# Functions to export from this module
|
||||
FunctionsToExport = '*'
|
||||
|
||||
# Cmdlets to export from this module
|
||||
CmdletsToExport = '*'
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module
|
||||
AliasesToExport = '*'
|
||||
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
|
||||
# A URL to the license for this module.
|
||||
# LicenseUri = ''
|
||||
|
||||
# A URL to the main website for this project.
|
||||
# ProjectUri = ''
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
|
||||
} # End of PSData hashtable
|
||||
|
||||
} # End of PrivateData hashtable
|
||||
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
|
||||
}
|
||||
91
samples/PowerShell/ZLocation.psm1
Normal file
91
samples/PowerShell/ZLocation.psm1
Normal file
@@ -0,0 +1,91 @@
|
||||
#
|
||||
# Weight function.
|
||||
#
|
||||
function Update-ZLocation([string]$path)
|
||||
{
|
||||
$now = [datetime]::Now
|
||||
if (Test-Path variable:global:__zlocation_current)
|
||||
{
|
||||
$prev = $global:__zlocation_current
|
||||
$weight = $now.Subtract($prev.Time).TotalSeconds
|
||||
Add-ZWeight ($prev.Location) $weight
|
||||
}
|
||||
|
||||
$global:__zlocation_current = @{
|
||||
Location = $path
|
||||
Time = [datetime]::Now
|
||||
}
|
||||
|
||||
# populate folder immidiatly after the first cd
|
||||
Add-ZWeight $path 0
|
||||
}
|
||||
|
||||
# this approach hurts `cd` performance (0.0008 sec vs 0.025 sec).
|
||||
# Consider replace it with OnIdle Event.
|
||||
(Get-Variable pwd).attributes.Add((new-object ValidateScript { Update-ZLocation $_.Path; return $true }))
|
||||
#
|
||||
# End of weight function.
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Tab complention.
|
||||
#
|
||||
if (Test-Path Function:\TabExpansion) {
|
||||
Rename-Item Function:\TabExpansion PreZTabExpansion
|
||||
}
|
||||
|
||||
function Get-EscapedPath
|
||||
{
|
||||
param(
|
||||
[Parameter(
|
||||
Position=0,
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true)
|
||||
]
|
||||
[string]$path
|
||||
)
|
||||
|
||||
process {
|
||||
if ($path.Contains(' '))
|
||||
{
|
||||
return '"' + $path + '"'
|
||||
}
|
||||
return $path
|
||||
}
|
||||
}
|
||||
|
||||
function global:TabExpansion($line, $lastWord) {
|
||||
switch -regex ($line) {
|
||||
"^(Set-ZLocation|z) .*" {
|
||||
$arguments = $line -split ' ' | Where { $_.length -gt 0 } | select -Skip 1
|
||||
Find-Matches (Get-ZLocation) $arguments | Get-EscapedPath
|
||||
}
|
||||
default {
|
||||
if (Test-Path Function:\PreZTabExpansion) {
|
||||
PreZTabExpansion $line $lastWord
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#
|
||||
# End of tab completion.
|
||||
#
|
||||
|
||||
function Set-ZLocation()
|
||||
{
|
||||
if (-not $args) {
|
||||
$args = @()
|
||||
}
|
||||
$matches = Find-Matches (Get-ZLocation) $args
|
||||
if ($matches) {
|
||||
Push-Location ($matches | Select-Object -First 1)
|
||||
} else {
|
||||
Write-Warning "Cannot find matching location"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set-Alias -Name z -Value Set-ZLocation
|
||||
Export-ModuleMember -Function Set-ZLocation, Get-ZLocation -Alias z
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user