Compare commits

...

271 Commits

Author SHA1 Message Date
Arfon Smith
78d4abe808 Merge pull request #2295 from github/cut-release-v4.5.4
Bumping version to v4.5.4
2015-03-31 20:16:53 -05:00
Arfon Smith
cb97417af8 Bumping version to v4.5.4 2015-03-31 19:48:34 -05:00
Arfon Smith
d1c94c75ea Merge pull request #2294 from github/grammars
Grammars update
2015-03-31 19:45:16 -05:00
Arfon Smith
0c8c6c9814 Merge pull request #2293 from github/sphinx-docs-tests
Some tests to go with #2290
2015-03-31 19:39:45 -05:00
Arfon Smith
3270a8896d Grammars update 2015-03-31 19:37:08 -05:00
Arfon Smith
20f19bf049 Some tests to go with #2290 2015-03-31 19:33:50 -05:00
Arfon Smith
0cc33fd560 Merge pull request #2290 from untitaker/patch-1
Ignore assets from Sphinx docs
2015-03-31 19:29:23 -05:00
Arfon Smith
fa54fc2735 Merge pull request #2233 from tesch1/tesch1-emacs-patch-1
fix emacs modeline parsing
2015-03-31 19:27:33 -05:00
Arfon Smith
216e0457ff Merge pull request #2291 from iFarbod/patch-1
Added Color for the Squirrel Language
2015-03-31 19:25:40 -05:00
iFarbod
678f90acf7 Added Color for the Squirrel Language
Picked the color from the Squirrel Language's website.
2015-04-01 01:23:59 +04:30
Arfon Smith
dd0d5c08bb Merge pull request #2289 from lepture/patch-fixtures
add tests/fixtures to vendor.yml
2015-03-31 11:43:39 -05:00
Markus Unterwaditzer
3837fed59e Ignore assets from Sphinx docs 2015-03-31 15:21:40 +02:00
Hsiaoming Yang
e4ce4edd5c add tests/fixtures to vendor.yml 2015-03-31 20:08:18 +08:00
Arfon Smith
a0fb54fe70 Merge pull request #2286 from github/puphpet
Adding puphpet to vendored list
2015-03-30 16:57:43 -05:00
Arfon Smith
e946ceaa6f Grammar 2015-03-30 16:24:55 -05:00
Arfon Smith
285af6512e Adding puphpet to vendored list 2015-03-30 16:24:11 -05:00
Arfon Smith
5ae5108a69 Merge pull request #2247 from larsbrinkhoff/renderscript
Add RenderScript and Filterscript
2015-03-30 16:08:42 -05:00
Lars Brinkhoff
02ae60f434 Samples for RenderScript and Filterscript.
All files are from The Android Open Source Project; license APL 2.0.
2015-03-28 12:34:20 +01:00
Lars Brinkhoff
03dc4e1ff4 Add RenderScript and Filterscript. 2015-03-28 12:34:20 +01:00
Arfon Smith
c39b42abba Merge pull request #2075 from philix/patch-1
Add cpplint.py to vendor.yml
2015-03-27 11:02:36 -07:00
Arfon Smith
661972f585 Merge pull request #2275 from github/bump-escape-utils
Bump escape-utils to 1.1.0
2015-03-27 09:25:29 -07:00
Arfon Smith
078aff6ee3 Merge pull request #2276 from MakeNowJust/patch-1
Fix ada aliases
2015-03-27 09:24:31 -07:00
Arfon Smith
4fed108b2c Merge pull request #2279 from joewiz/patch-1
Add .odd to XML extensions
2015-03-26 11:21:47 -07:00
Joe Wicentowski
fc9beb58aa Add sample TEI ODD file (.odd) 2015-03-26 14:00:17 -04:00
Joe Wicentowski
4623b4a83e Add .odd to XML extensions
See discussion at #2238. 

[ODD](http://en.wikipedia.org/wiki/Text_Encoding_Initiative#ODD) is an XML-based vocabulary for defining schemas for Text Encoding Initiative (TEI) projects, used widely in the humanities.  ODD should be rendered using XML syntax but is currently displayed as plain text (see [this example](https://github.com/wolfgangmm/tei-simple-pm/blob/master/odd/teisimple.odd)).  There are [nearly 500 ODD files](https://github.com/search?q=extension%3Aodd+NOT+djfhdirijdskqdhd&type=Code&utf8=%E2%9C%93) in GitHub, and this number is projected to grow.
2015-03-26 13:18:49 -04:00
TSUYUSATO Kitsune
2ba6ecefe5 Fix ada aliases 2015-03-26 12:08:46 +09:00
Garen Torikian
91c2a4682d Merge pull request #2274 from csimons/master
intro.wisp: Fixed typographical error ('rather then' -> 'rather than').
2015-03-25 13:24:10 -07:00
Patrick Toomey
738be195ef Bump escape-utils to 1.1.0 2015-03-25 14:18:46 -06:00
Christopher L. Simons
5dcc4d74ec intro.wisp: Fixed typographical error ('rather then' -> 'rather than'). 2015-03-25 14:35:16 -04:00
Arfon Smith
4213bec62a Merge pull request #2272 from lpil/master
Elixir: Add mix.lock filename
2015-03-25 09:04:07 -05:00
Louis Pilfold
babe733bf4 Elixir: Add mix.lock filename 2015-03-25 13:52:52 +00:00
Arfon Smith
ab5f60555e Merge pull request #2270 from larsbrinkhoff/ocaml
Add interpreters for OCaml.
2015-03-25 08:39:49 -05:00
Lars Brinkhoff
b61e33a49e Add interpreters for OCaml. 2015-03-25 08:11:40 +01:00
Arfon Smith
a0d5a8338b Merge pull request #2269 from stuartpb/patch-2
Use #000080 for Lua color
2015-03-24 19:24:34 -05:00
Arfon Smith
eec321f013 Merge pull request #2265 from github/cut-release-v4.5.3
Bumping to v4.5.3
2015-03-24 19:08:59 -05:00
Stuart P. Bentley
e538f72b63 Use #000080 for Lua color
This is the color of the official Lua logo, as seen at http://www.lua.org/images/
2015-03-24 14:34:13 -07:00
Arfon Smith
44c3d47b30 Bumping to v4.5.3 2015-03-24 12:33:35 -05:00
Arfon Smith
f1d3f396bb Merge pull request #2264 from github/grammar-update
Updating grammars
2015-03-24 12:28:29 -05:00
Arfon Smith
65ae444791 Updating grammars 2015-03-24 12:26:40 -05:00
Arfon Smith
e9916c644d Merge pull request #2263 from github/NetLinx
Net linx
2015-03-24 12:09:15 -05:00
Arfon Smith
1940a9ea92 Merge branch 'master' into NetLinx 2015-03-24 11:41:26 -05:00
Arfon Smith
c9f8a2677a Merge pull request #2261 from ntkme/storyboard-xib-xml
.storyboard and .xib as XML
2015-03-24 11:38:39 -05:00
Arfon Smith
5b6b3f74b5 Merge pull request #2262 from drautb/master
Fix categorization for Racket shell scripts.
2015-03-24 11:38:21 -05:00
Vicent Marti
f9ccac4240 Merge pull request #2259 from github/bump-rugged
Bump rugged to latest release
2015-03-24 08:36:52 -07:00
Ben Draut
aa7aae7808 Fix categorization for Racket shell scripts.
The current implementation categorizes shell scripts written in Racket
as Scheme, which is incorrect.

For example:

```racket
\#!/usr/bin/env racket

\#lang racket

"Hello World!"
```

This should be categorized as Racket, not Scheme. [This file][1]
demonstrates the problem in an existing repository.

[1]: https://github.com/drautb/sketchbook/blob/master/racket/sublime-project-generator/generate-sublime-project.rkt
2015-03-24 08:22:00 -06:00
なつき
7c66301583 .storyboard and .xib as XML 2015-03-24 01:58:55 -07:00
michael tesch
a5b0b333b0 Merge branch 'master' into tesch1-emacs-patch-1 2015-03-24 09:44:08 +01:00
Andy Delcambre
7df872eb7f Bump rugged to latest release 2015-03-23 14:33:03 -06:00
Arfon Smith
6a4f4c724c Merge pull request #2253 from larsbrinkhoff/dtrace-script-mode
Fix Emacs modeline in DTrace sample.
2015-03-23 15:30:03 -05:00
Lars Brinkhoff
76828c45c7 Fix Emacs modeline in DTrace sample.
Apparently, the DTrace mode for Emacs is called dtrace-script:
https://github.com/dotemacs/dtrace-script-mode
2015-03-23 19:43:32 +01:00
Arfon Smith
27215f148b Merge pull request #2257 from Oldes/rebol_grammar_scope
Adding tm_scope for REBOL language and removing REBOL from LICENSE_WHITE...
2015-03-23 11:30:48 -05:00
Arfon Smith
77d52463ad Merge pull request #2256 from Oldes/red_grammar
Added grammar submodule for Red language
2015-03-23 11:30:06 -05:00
Oldes
0f6c2afbf6 Sublime-REBOL submodule updated. 2015-03-23 15:58:01 +01:00
Oldes
cbaa3ca6f4 Adding tm_scope for REBOL language and removing REBOL from LICENSE_WHITELIST as now is license available in the Sublime-REBOL project. 2015-03-23 11:38:07 +01:00
Oldes
63f54bdf06 Added grammar submodule for Red language 2015-03-23 10:43:39 +01:00
Alex McLain
b302863a4d Added additional sample files. 2015-03-21 20:22:46 -07:00
Alex McLain
ec46b1a92e Added NetLinx language. 2015-03-21 18:58:09 -07:00
Arfon Smith
ed65040539 Merge pull request #2250 from shaneog/patch-2
Add Neovim config file names to VimL language
2015-03-21 16:56:00 -05:00
Arfon Smith
cc1a420bc5 Merge pull request #2254 from shaunlebron/master
add .boot to clojure extensions
2015-03-21 16:54:20 -05:00
Shaun Williams
8555b20380 add .boot Clojure sample 2015-03-21 12:02:20 -05:00
Shaun Williams
6462ba70f9 put .boot after primary .clj extension 2015-03-21 11:48:52 -05:00
Shaun Williams
1ac43e0d7d reorder .boot to be in order 2015-03-21 11:32:29 -05:00
Shaun Williams
6ac51968c6 add .boot to clojure extensions 2015-03-21 11:20:48 -05:00
Shane O'Grady
cbcadf8e45 Add Neovim config file names to VimL language
Neovim uses configuration files named `.nvimrc` rather than `.vimrc`

See this PR for details neovim/neovim#330
2015-03-21 09:53:21 -03:00
Arfon Smith
74b111501d Merge pull request #2213 from ntkme/source-map
Detect generated source maps
2015-03-20 09:26:40 -05:00
なつき
67e4212f64 Test detecting generated source maps 2015-03-19 19:50:40 -07:00
Arfon Smith
55559a1020 Merge pull request #2246 from ampl/nl
Add a heuristic to disambiguate between NL and NewLisp
2015-03-19 20:26:56 -05:00
なつき
b103232e0e Detect generated source maps 2015-03-19 17:38:59 -07:00
vitaut
b587379f4a Add a heuristic to disambiguate between NL and NewLisp 2015-03-19 17:33:52 -07:00
Arfon Smith
ba654b2a1d Merge pull request #2242 from larsbrinkhoff/types
Fix the type classification of some languages.
2015-03-19 08:46:55 -05:00
Lars Brinkhoff
ae39475133 Fix the type classification of some languages. 2015-03-19 07:09:42 +01:00
Arfon Smith
c641ea833f Merge pull request #2241 from github/cut-release-v4.5.2
v4.5.2
2015-03-18 10:45:42 -05:00
Arfon Smith
ebf10c2cd6 v4.5.2 2015-03-18 09:50:57 -05:00
Arfon Smith
29ef8beb3f Grammar submodule update 2015-03-18 09:47:43 -05:00
Arfon Smith
2b5f38264b Merge pull request #2222 from chriskuehl/master
languages.yml: don't assume .conf is Apache
2015-03-18 09:27:32 -05:00
Arfon Smith
5850716eb3 Merge pull request #2236 from Phasesaber/master
Give Diff a color
2015-03-18 09:24:46 -05:00
Arfon Smith
3db6c4a5b6 Merge pull request #2227 from samoht/OCaml
Disambiguate between OCaml and Standard ML
2015-03-18 09:05:12 -05:00
Thomas Gazagnaire
e79607372b Disambiguate between OCaml and Standard ML
Fix #2208
2015-03-18 09:58:14 +00:00
Arfon Smith
b5472ab753 Merge pull request #2123 from larsbrinkhoff/for
Some .for files are text.
2015-03-17 14:59:53 -05:00
Lars Brinkhoff
013188dcd9 Add new language Formatted for .for.
Sample file wksst8110.for is from the Climate Prediction Center at the
National Weather Service of the USA, and is in the public domain.
2015-03-17 20:44:06 +01:00
Jαdon Fowler
3cf7bfbee2 Give Diff a color 2015-03-16 23:44:08 -07:00
michael tesch
5f647f2236 more realistic emacs modeline for dtrace sample 2015-03-16 19:56:06 +01:00
Arfon Smith
3bb740fe9f Merge pull request #2198 from tarebyte/handlebars_color
Assign handlebars a color for the language bar.
2015-03-16 07:58:05 -05:00
michael tesch
50db5c012e disable modelines strategy for webidl sample 2015-03-15 20:18:57 +01:00
michael tesch
dcb14d0fc7 disable modelines strategy for webidl sample 2015-03-15 20:06:41 +01:00
michael tesch
419cfe54e0 disable modelines strategy match for dtrace sample 2015-03-15 13:05:43 +01:00
michael tesch
ce1f51a34f forgot a | 2015-03-15 12:51:14 +01:00
michael tesch
5fd7992f98 dont save useless matches, thanks to pchaigno 2015-03-15 12:40:31 +01:00
Arfon Smith
3f5a96a15b Merge pull request #2017 from github/revert-2014-revert-1976-path-for-fileblob
Cut 4.5.0 release
2015-03-14 20:42:20 -05:00
Arfon Smith
840bdf95e3 v4.5.1 2015-03-14 20:32:18 -05:00
Arfon Smith
01deb07ae9 Return false for empty file. 2015-03-14 20:19:11 -05:00
michael tesch
fda0f2a042 detect emacs modeline for fundamental as Text 2015-03-14 23:53:17 +01:00
michael tesch
6af4ab6db1 harder test 2015-03-14 23:26:08 +01:00
michael tesch
6aab682728 fixed case with multiple other file vars before and after mode: 2015-03-14 23:24:41 +01:00
Arfon Smith
6c37613bf0 Merge branch 'master' into revert-2014-revert-1976-path-for-fileblob 2015-03-14 17:18:36 -05:00
Arfon Smith
188c7364f8 Merge pull request #2209 from chezwicker/master
Add .plsql as extension for PL/SQL
2015-03-14 17:17:52 -05:00
Arfon Smith
09ead55502 Merge pull request #2232 from pchaigno/cython-generated-files
Detect Cython generated files
2015-03-14 17:16:45 -05:00
michael tesch
a364e4a2dc tests for emacs modeline regex 2015-03-14 23:13:59 +01:00
Arfon Smith
f7f9513fba Merge branch 'master' into revert-2014-revert-1976-path-for-fileblob 2015-03-14 17:13:31 -05:00
Arfon Smith
dd2d2389c8 Cobol grammars fix. 2015-03-14 17:11:44 -05:00
Michael Tesch
1bb639617c Create seeplusplusEmacs1
one type of emacs modeline
2015-03-14 22:44:02 +01:00
Chris Zwicker
03b43a85c8 Change sorting of extensions to fix failing test 2015-03-14 20:16:31 +00:00
Chris Zwicker
fb709e2e10 Add sample file for .plsql extension 2015-03-14 19:59:25 +00:00
Chris Zwicker
dad653492a Merge remote-tracking branch 'upstream/master' 2015-03-14 19:56:27 +00:00
Paul Chaignon
0db133ffb2 Detect Cython generated files 2015-03-14 19:43:17 +01:00
Arfon Smith
6d1682911b Merge branch 'master' into revert-2014-revert-1976-path-for-fileblob 2015-03-14 13:14:26 -05:00
Arfon Smith
d1de479c49 Merge branch 'master' of github.com:github/linguist 2015-03-14 13:13:07 -05:00
Arfon Smith
ad7e231f39 Updating grammars 2015-03-14 13:12:37 -05:00
Arfon Smith
f36d239b85 Merge pull request #2229 from pchaigno/perl6-grammar
Grammar for Perl6
2015-03-14 13:08:29 -05:00
Arfon Smith
540865d045 Merge pull request #2231 from pchaigno/description-group
Description of group attribute
2015-03-14 13:08:06 -05:00
Arfon Smith
5ed0da7b08 v4.5.0 2015-03-14 13:06:55 -05:00
Michael Tesch
068c8a341d better regex for matching emacs modeline
the emacs modeline is actually a per-file variable setting mechanism, which means it can have other flags in it.

this regex extracts the part that corresponds to the file's language ("mode:" - ie emacs major mode)

http://ergoemacs.org/emacs_manual/emacs/Specifying-File-Variables.html
2015-03-14 18:35:57 +01:00
Paul Chaignon
e61be66d4f Grammar for Perl and Perl6 from TextMate bundle 2015-03-14 11:47:44 +01:00
Paul Chaignon
d263f0c91a Remove submodule for Perl grammar 2015-03-14 11:42:30 +01:00
Arfon Smith
fee0cebcec Merge branch 'master' into revert-2014-revert-1976-path-for-fileblob 2015-03-13 11:42:24 -07:00
Arfon Smith
3745308642 Merge pull request #2224 from github/bin-linguist
Simplifying requires
2015-03-12 11:13:37 -07:00
Arfon Smith
8843fa3ed4 Merge pull request #2218 from xPaw/patch-1
Detect *.sma files as SourcePawn
2015-03-12 11:13:24 -07:00
Arfon Smith
464d6e9ec4 Simplifying requires 2015-03-12 10:41:34 -07:00
Chris Kuehl
02ced24751 languages.yml: don't assume .conf is Apache
The assumption that `.conf` files are Apache is causing many projects to
be detected incorrectly as being primarily "ApacheConf".

The `.conf` extension is widely used by software; Apache accounts for
only a very tiny proportion of its overall use. The addition of `.conf`
for ApacheConf has resulted in projects which contain none (or almost
no) Apache config being marked as primarily containing it.

The problem was introduced by 18a3ef9e5e
2015-03-10 22:19:22 -07:00
Pavel
8b9ad131d1 Create foo.sma 2015-03-10 16:20:59 +02:00
Pavel
5ef944e8b8 Detect *.sma files as SourcePawn 2015-03-10 11:16:17 +02:00
Mark Tareshawty
ea0145fda5 Merge branch 'master' into handlebars_color 2015-03-09 10:04:51 -04:00
Adam Roben
53c3cb382c Merge pull request #2207 from github/update-popular
Update popular languages
2015-03-09 09:15:30 -04:00
Brandon Keepers
179c557e5b Merge pull request #2215 from github/apt-get-update
apt-get update before downloading deps
2015-03-08 16:35:06 -07:00
Brandon Keepers
8da458e1a8 apt-get update before downloading deps 2015-03-08 16:24:05 -07:00
Mark Tareshawty
b009c85b64 inverted color 2015-03-08 15:31:52 -04:00
Brandon Keepers
3eb3dd7d4b Merge pull request #2178 from munrocape/patch-1
Standardized color hexcode length to 6
2015-03-07 19:57:24 -08:00
Chris Zwicker
c9a1159a2e Add .plsql as extension for PL/SQL 2015-03-07 08:51:16 +00:00
Adam Roben
8664668524 Update popular languages
I took all non-fork repositories on github.com, grouped them by their
primary language, and took the 25 most popular.
2015-03-06 14:26:09 -05:00
Arfon Smith
3ba4cf699a Merge pull request #2202 from pchaigno/jbuilder
.jbuilder as a Ruby extension
2015-03-06 07:33:51 -06:00
Arfon Smith
8bc39ce44f Merge pull request #2204 from aquileia/patch-1
Exclude gettext catalogues from statistics
2015-03-06 07:26:39 -06:00
aquileia
2d03eae413 Exclude gettext catalogues from statistics
Gettext catalogues are used for translations and are thus essentially prose, but were classified as "programming" in 507d191d7d.

In large projects like e.g. wesnoth/wesnoth, gettext can dominate the language statistics with about 95% although the actual code is C++.
2015-03-06 13:34:19 +01:00
Paul Chaignon
0d848b342f .jbuilder as a Ruby extension 2015-03-06 07:07:41 +01:00
Arfon Smith
ad6030b0e8 Merge pull request #2200 from github/cut-release-v4.4.3
Bumping version to 4.4.3
2015-03-05 16:37:40 -06:00
Arfon Smith
bdb2a221a5 Bumping version to 4.4.3 2015-03-05 15:13:54 -06:00
Arfon Smith
44f505e687 Grammars update 2015-03-05 15:08:05 -06:00
Arfon Smith
d931dacd47 Merge pull request #2196 from larsbrinkhoff/glsl-group
GLSL should not be in the C group.
2015-03-05 15:03:45 -06:00
Arfon Smith
1da425ae2f Merge pull request #2162 from github/instrumentation
Add instrumentation to detection and classification
2015-03-05 15:03:30 -06:00
Arfon Smith
9ceea4ac81 Merge pull request #2173 from github/moar-instrumentation
Instrument all calls and pass the blob, strategy and language candidates in the payload.
2015-03-05 15:02:42 -06:00
Arfon Smith
a1010b8cf8 Actually return the strategy 2015-03-05 13:21:07 -06:00
Paul Chaignon
19a300a4ba Description of group attribute 2015-03-05 20:14:15 +01:00
Arfon Smith
1bc1803628 Check for block here too 2015-03-05 12:50:12 -06:00
Brandon Keepers
7fdead0100 Only yield if block given 2015-03-05 10:11:08 -08:00
Brandon Keepers
3dcdc11c1b Avoid passing block to detected instrumenter 2015-03-05 10:03:51 -08:00
Brandon Keepers
e8326529b5 Pass blob to instrumentation 2015-03-05 10:03:01 -08:00
Brandon Keepers
2d5476f6c8 Yield the block in LocalInstrumenter 2015-03-05 10:01:28 -08:00
Mark Tareshawty
781133d0d3 assign handlebars a color 2015-03-04 19:42:32 -05:00
Lars Brinkhoff
c7b4cf636f GLSL should not be in the C group. 2015-03-04 21:26:55 +01:00
Arfon Smith
d81c796dc0 Merge pull request #2193 from pchaigno/nl
Support for NL file format
2015-03-03 21:43:55 -06:00
Arfon Smith
1a3680bba6 Merge pull request #2189 from pchaigno/qml-programming-type
QML as a programming language
2015-03-03 11:50:49 -06:00
Arfon Smith
600bca149a Merge pull request #2192 from graymalkin/master
Added XC syntax
2015-03-03 11:50:29 -06:00
Simon Cooksey
3a56d632e1 Fixed build by removing duplicate C syntax definition 2015-03-03 13:09:19 +00:00
Simon Cooksey
7f3f0327c2 Added XC syntax 2015-03-03 12:45:08 +00:00
Paul Chaignon
cc0c71b277 New sample for NL 2015-03-02 22:13:17 +01:00
Paul Chaignon
e5ce286c63 NL file format with .nl extension 2015-03-02 21:55:41 +01:00
Arfon Smith
86a0cf9424 Merge pull request #2188 from graymalkin/patch-1
Add colour for XMOS XC in linguist
2015-03-02 11:11:40 -06:00
Paul Chaignon
eaea6ac837 QML as a programming language 2015-03-02 18:09:09 +01:00
Simon Cooksey
4efc3ff822 Add colour for XMOS XC in linguist
Adds a colour matching the XMOS colour scheme for .xc files.
2015-03-02 17:04:18 +00:00
Arfon Smith
c22a6563d9 Writing some (failing) tests for instrumentation 2015-03-01 22:13:26 -06:00
Arfon Smith
f9683efb74 Merge pull request #2184 from redj/ec-lang-color
Add designated color of eC language for display in language bar.
2015-03-01 19:21:27 -06:00
Rejean Loyer
08945923e6 Add designated color of eC language in lib/linguist/languages.yml for display in repository page's language bar. 2015-03-01 18:54:47 -05:00
Arfon Smith
4745c62853 Merge pull request #2181 from pchaigno/prolog-heuristic
More specific heuristic for Prolog
2015-03-01 11:13:58 -06:00
Paul Chaignon
7c593899e7 Make heuristic for Prolog more specific 2015-03-01 12:43:35 +01:00
Arfon Smith
9151e7066a Merge pull request #2175 from github/sqlllll
Sqlllll
2015-02-28 20:45:08 -06:00
Zach Munro-Cape
b358a22d32 Standardized color hexcode length to 6
C was the only language to have a hex code length of 3. 
#555555 == #555 == rgb(85, 85, 85)
2015-02-27 23:02:13 -04:00
Arfon Smith
8a0ff14d22 Merge pull request #2112 from nwellnhof/patch-1
Mark XS files as "type: programming"
2015-02-27 14:19:42 -06:00
Arfon Smith
7604a2d80b Merge pull request #2176 from github/2073-local
2073 local
2015-02-27 14:16:03 -06:00
Arfon Smith
78b1c8a430 Merge branch 'master' into 2073-local 2015-02-27 14:12:23 -06:00
Arfon Smith
4ef925d8be Merge pull request #2087 from pchaigno/case-sensitivity
Detection by extension made case-insensitive
2015-02-27 14:06:50 -06:00
Arfon Smith
7ba4f0c571 Oracle grammar now has a license 2015-02-27 13:51:23 -06:00
Arfon Smith
63fc9dd6a5 Updating grammars 2015-02-27 13:50:29 -06:00
Arfon Smith
b350f1572b Reformatting 2015-02-27 13:36:20 -06:00
Arfon Smith
e24a9ba602 Ordering 2015-02-27 13:36:12 -06:00
Arfon Smith
a338228b57 Merge branch 'master' into sqlllll 2015-02-27 13:32:09 -06:00
Arfon Smith
d6d232ec37 Merge pull request #2154 from pchaigno/kicad-files
Support for .pro INI files (KiCad project files)
2015-02-27 10:14:20 -06:00
Brandon Keepers
b723405e9f Merge pull request #2174 from github/2171-local
2171 local
2015-02-27 01:00:54 -10:00
Arfon Smith
cecb125b0b Merge branch 'master' into 2171-local 2015-02-26 21:13:18 -06:00
Arfon Smith
2177ff1806 Merge pull request #2024 from halirutan/feature-Mathematica10Extensions
New Mathematica (aka Wolfram Language) extensions added
2015-02-26 21:10:00 -06:00
Arfon Smith
674eb31cfe Merge pull request #2145 from larsbrinkhoff/muf
Add MUF - Multi-user Forth
2015-02-26 21:04:13 -06:00
Arfon Smith
9783710adf Merge pull request #2160 from brandonwamboldt/use-vcl
Use correct VCL syntax highlighting
2015-02-26 21:02:35 -06:00
Arfon Smith
8888555f71 Merge pull request #2102 from phillipberndt/master
Added a sample of a C header file that is currently recognized as C++
2015-02-26 21:00:52 -06:00
Arfon Smith
13a6180507 Merge pull request #2128 from larsbrinkhoff/d
Add to .d: DTrace and Makefile dependencies
2015-02-26 20:52:41 -06:00
Arfon Smith
9a86b9ad75 Instrument all calls and pass the blob, strategy and language candidates in the payload. 2015-02-26 15:27:33 -06:00
Paul Chaignon
65260e3aaa Grammar for OpenScad from TextMate bundle 2015-02-26 21:59:03 +01:00
Victor Zverovich
51af1bd162 Use AMPL grammar 2015-02-26 10:40:56 -08:00
Victor Zverovich
e093ac843f Remove AMPL samples using .mod, .dat and .run extensions 2015-02-25 14:22:45 -08:00
Victor Zverovich
13eb7c796e Remove .dat, .mod and .run AMPL extensions as they are ambiguous
As discussed in #2073 adding these extensions will require more work
to avoid incorrect language detection.
2015-02-25 12:59:23 -08:00
Victor Zverovich
1cdd3c55ab Add AMPL grammar 2015-02-25 12:56:02 -08:00
Victor Zverovich
407dbbb7fb Mark AMPL with tm_scope: none because it doesn't have grammar info 2015-02-25 12:54:31 -08:00
Victor Zverovich
0bccf97d16 Add support for the AMPL modeling and script language 2015-02-25 12:54:31 -08:00
Lars Brinkhoff
c6e16ee6bd MUF sample files.
39.m by Revar; license GPL v2.
cmd-say.muf by Natasha Snunkemeox; license MIT.
2015-02-25 19:29:57 +01:00
Lars Brinkhoff
2b25bb6d1c Add MUF language - Multi-user Forth. 2015-02-25 19:29:57 +01:00
Lars Brinkhoff
e791a71566 Add DTrace and Makefile dependency includes.
Sample file mpq.d by Georg Lukas; license GPL 2.
Sample file counts.d by Kate Turner; public domain.
Sample file javascript-race.d by unknown; license MPL 1.1/GPL 2.0/LGPL 2.1.
Sample file probes.d by momjian; license TBD.
2015-02-25 19:29:56 +01:00
Arfon Smith
739b512cee Prefer 'statistics' 2015-02-25 08:18:45 -06:00
Arfon Smith
effcab4297 Merge pull request #2165 from deviantintegral/attr-highlight-note
Issue #2140: Note that only modelines control syntax highlighting.
2015-02-25 08:17:55 -06:00
Nick Wellnhofer
2e1161e061 Add sample XS file 2015-02-25 15:14:34 +01:00
Andrew Berry
649a5987e7 Issue #2140: Note that only modelines control syntax highlighting. 2015-02-25 08:54:41 -05:00
Brandon Wamboldt
71e0e2bc8e Use actual VCL syntax highlighting 2015-02-24 17:54:23 -08:00
Charlie Somerville
fd7633518f add instrumentation to detection and classification 2015-02-25 12:34:07 +11:00
Garen Torikian
04252c28f2 Merge pull request #2153 from github/enforce-type
Test that languages have a type
2015-02-24 13:34:22 -08:00
Arfon Smith
94be1ab277 documentation? should use path too 2015-02-24 15:20:58 -06:00
Arfon Smith
8561f2a6b0 Merge branch 'master' into revert-2014-revert-1976-path-for-fileblob
Conflicts:
	lib/linguist/version.rb
2015-02-24 14:54:14 -06:00
Arfon Smith
2bd050657d Merge pull request #2151 from soonhokong/master
add support for Lean Theorem Prover
2015-02-24 14:34:59 -06:00
Arfon Smith
c7d8f39ad8 Merge pull request #2158 from github/overrides-should-support-aliases-too
Finding by alias too.
2015-02-24 14:32:21 -06:00
Arfon Smith
ad4b5bdc16 Merge pull request #2157 from hoosierEE/master
Add a color code for J language to languages.yml.
2015-02-24 14:31:53 -06:00
Arfon Smith
ef5eff45aa Merge pull request #2152 from pchaigno/generated-go
Detect Go files generated by Protocol Buffers
2015-02-24 14:30:37 -06:00
Arfon Smith
d18c8614ba Merge pull request #2147 from pchaigno/tcc-interpreter
tcc interpreter for C
2015-02-24 14:25:38 -06:00
Arfon Smith
29192e8d5f Finding by alias too. 2015-02-24 14:10:41 -06:00
Soonho Kong
c2e894c48c add ace-mode support for Lean 2015-02-24 14:45:15 -05:00
Alex Shroyer
2cc6e5bfe6 Update languages.yml
Add a color for J language.  This color is the average of the colors of the [J wiki icon](http://www.jsoftware.com/jwiki/moin_static194/common/jwlogo.png).
2015-02-24 10:58:33 -05:00
Soonho Kong
2d15ea54cb add support for Lean Theorem Prover 2015-02-23 11:32:22 -05:00
Garen Torikian
6b26386a81 Improve "no type found" error message 2015-02-22 20:21:02 -08:00
CodingAnarchy
525e886d79 Comments added to one sample 2015-02-22 11:00:14 -08:00
CodingAnarchy
05f73df064 Brainfuck samples 2015-02-22 11:00:14 -08:00
Paul Chaignon
e592381a54 Support for .pro INI files (KiCad project files)
Update the heuristic for .pro to include both INI and QMake files
Fixes #2116
2015-02-22 19:33:06 +01:00
Garen Torikian
fecf0cc137 There is no "other" 2015-02-22 10:32:01 -08:00
Garen Torikian
507d191d7d Add missing types 2015-02-22 10:27:24 -08:00
Garen Torikian
8420e4b044 Test that languages have a type 2015-02-22 10:23:48 -08:00
Paul Chaignon
2ca5868610 Detect Go files generated by Protocol Buffers 2015-02-22 10:50:47 +01:00
Paul Chaignon
6d8559eccb Add test file for C interpreter tcc 2015-02-21 17:16:33 +01:00
Paul Chaignon
53d020f7b0 tcc interpreter for C 2015-02-21 17:10:43 +01:00
Adam Roben
ad9a2d231e Merge pull request #2141 from github/release-4.4.2
Release v4.4.2
2015-02-20 15:51:24 -05:00
Adam Roben
7bbb3da010 Bump version to 4.4.2 2015-02-20 15:00:42 -05:00
Adam Roben
76a85b7637 Merge pull request #2139 from github/stats-improvements
Improve repository language statistics
2015-02-20 15:00:06 -05:00
Adam Roben
80f72a5093 Classify the .google_apis/ directory as vendored
This is used in Android projects that use certain Google SDKs to store
the SDKs locally.
2015-02-20 10:36:47 -05:00
Adam Roben
df552c241e Classify XML as a data language
While XML is technically a markup language, in the majority of cases it
is just a serialization format for a tool (e.g., project files for IDEs)
rather than hand-authored markup. As such it isn't really useful to
include it in repository language statistics. A C# project doesn't
really care whether Visual Studio uses XML, JSON, or some other format
to serialize its project files, for example.
2015-02-20 10:30:44 -05:00
Adam Roben
9e020dd15d Classify "documentation/" directories (lowercase) as documentation
This is used in repositories like jashkenas/coffeescript.
2015-02-20 10:24:59 -05:00
Adam Roben
c7c0c30ecf Classify javadoc/ directories as documentation 2015-02-20 10:24:38 -05:00
Adam Roben
60deead669 Add a couple more documentation patterns
These are used in repositories like jashkenas/coffeescript and
tj/git-extras.
2015-02-20 09:53:07 -05:00
Adam Roben
6d843eca60 Merge pull request #2136 from github/release-4.4.1
Release v4.4.1
2015-02-20 09:35:32 -05:00
Adam Roben
12c22d0311 Bump version to 4.4.1 2015-02-19 16:56:20 -05:00
Adam Roben
d28f5e87c0 Merge pull request #2135 from github/rollback-clojure
Roll back to language-clojure v0.10.0
2015-02-19 16:55:44 -05:00
Adam Roben
471fabfff5 Roll back to language-clojure v0.10.0
v0.11.0 seems to have introduced deeply nested meta.expression.clojure
scopes.

* vendor/grammars/language-clojure cfc8a5c...bae6eee (6):
  < Prepare 0.12.0 release
  < Merge pull request #14 from joelash/master
  < Prepare 0.11.0 release
  < Merge pull request #13 from hanjos/proposed
  < Add initial spec
  < Add initial Travis CI config
2015-02-19 16:53:57 -05:00
Adam Roben
2e1a6d9d43 Merge pull request #2133 from github/update-grammars
Update grammar submodules
2015-02-19 11:19:44 -05:00
Adam Roben
d2d22e849e Update grammar submodules
* vendor/grammars/Modelica f2b1242...e1fd853 (1):
  > Some string improvements

* vendor/grammars/NimLime 58a1e0c...fac6b18 (2):
  > Added support for ST3
  > Merge pull request #15 from fenekku/master

* vendor/grammars/SublimePapyrus 152c7b7...2731300 (1):
  > Updated INI path setting behavior

* vendor/grammars/actionscript3-tmbundle d69fcc8...d24ad7d (1):
  > all contexts

* vendor/grammars/dart-sublime-bundle c1afc62...d55b1d4 (4):
  > Merge pull request #458 from guillermooo-forks/prep-release
  > Merge pull request #457 from guillermooo-forks/refactor
  > Merge pull request #455 from guillermooo-forks/fix-stagehand-unavailable
  > Merge pull request #452 from guillermooo-forks/improve-syntax-def

* vendor/grammars/grace-tmbundle c342d35...acbf9a2 (9):
  > Add simple block parameter highlighting
  > Track open braces for better interpolation
  > Add highlighting for full import syntax
  > Check for extra word characters after var keyword
  > Remove built-ins and change storage to support
  > Highlight untyped block parameters
  > Highlight interpolation braces as keywords
  > Highlight only capitalised words with generic args
  > Include comment highlighting in every construct

* vendor/grammars/language-javascript ac37d2a...d58edec (2):
  > Prepare 0.57.0 release
  > Merge pull request #101 from postcasio/iojs-shebang

* vendor/grammars/latex.tmbundle 0441781...669040b (1):
  > Fix doctest for `run_biber` in `texmate`

* vendor/grammars/mako-tmbundle e039636...da79638 (1):
  > Merge pull request #7 from seedofjoy/patch-1

* vendor/grammars/sublime-text-ox bdd03e0...10ca883 (5):
  > Update README.md
  > Update README.md
  > Moved license to separate md-file.
  > Ctrl+B executes on a single core instaed of two.
  > Added patterns for 'foreach' and 'delete'.
2015-02-19 10:50:00 -05:00
Brandon Keepers
6c41bfa44d Merge pull request #2118 from xbony2/patch-1
Made assembly color more noticeable
2015-02-18 11:51:57 +13:00
Brandon Keepers
d54bcc85e7 Merge pull request #2119 from pchaigno/new-grammars
Grammars for 4 languages
2015-02-18 11:39:13 +13:00
Arfon Smith
6d94ddb114 Merge pull request #2120 from github/ascii
Ascii
2015-02-16 11:23:08 -08:00
Arfon Smith
7fd720bf39 Merge branch 'master' into ascii 2015-02-16 11:18:31 -08:00
Arfon Smith
e10558e444 Fall back to classifier 2015-02-16 11:14:40 -08:00
Adam Roben
7c48d5ee1f Merge pull request #2114 from github/release-4.4.0
Release v4.4.0
2015-02-16 10:19:41 -05:00
Paul Chaignon
651d863069 Grammar for PigLatin from Sublime Text package 2015-02-15 17:45:25 +01:00
Paul Chaignon
a3c595a4a9 Grammar for AsciiDoc from TextMate bundle 2015-02-15 17:30:19 +01:00
Paul Chaignon
7660714a9e Stylus grammar from Sublime Text package 2015-02-15 17:24:56 +01:00
Paul Chaignon
71002dfb65 Grammar for BrightScript from TextMate bundle 2015-02-15 17:16:10 +01:00
xbony2
013cfdcdaf Made assembly color more noticeable 2015-02-15 11:12:40 -05:00
Nick Wellnhofer
7cdb5ccba8 Mark XS files as "type: programming"
I'd actually prefer to treat Perl XS files as C code, but this fix shouldn't be controversial.
2015-02-13 15:37:39 +01:00
Phillip Berndt
dc852b6398 Added a sample of a C header file that is currently recognized as C++
See https://github.com/github/linguist/issues/1626#issuecomment-73870081
Taken from 469fe63df4/pqiv.h
2015-02-11 13:00:11 +01:00
David Pyke Le Brun
5e9bb67d10 temporary add grammer to whitelist until license gets added 2015-02-09 14:27:14 +00:00
David Pyke Le Brun
e969172543 recode heuristic to use existing style. add additional sample 2015-02-09 14:16:25 +00:00
David Pyke Le Brun
f570260dfe Merge remote-tracking branch 'upstream/master' into plsql
Conflicts:
	.gitmodules
2015-02-09 12:04:21 +00:00
David Pyke Le Brun
7ecf65551e re-add oracle grammer module using https 2015-02-09 11:58:50 +00:00
David Pyke Le Brun
fb6ec8aaa7 remove oracle grammer. (to be readded) 2015-02-09 11:46:14 +00:00
Paul Chaignon
41e1b7bd4e Detection by extension made case-insensitive 2015-02-06 22:14:22 +01:00
David Pyke Le Brun
3e54d6651c update of old PL/SQL PLpgSQL and SQLPL patch based on current version
see [linguist] add support for oracle PLSQL (#1003)
2015-02-06 13:36:40 +00:00
Felipe Oliveira Carvalho
96c2f86613 Add cpplint.py to vendor.yml
`cpplint.py` is Google's Python script used for linting C++ files.
I have a small C++ project with `cpplint.py` included mistakenly making
Python the main language of my project.
2015-02-04 02:22:08 -03:00
Edmundo Ruiz
eaa03e15ed Improved Heuristics for .asc files. 2015-02-03 21:09:32 -08:00
Edmundo Ruiz
9fa7adaa61 #1638 New heuristics to distinguish between AsciiDoc, AGS Script, and Public Key. 2015-02-03 00:43:53 -08:00
Edmundo Ruiz
54a2f5347a Merge remote-tracking branch 'upstream/master'
Conflicts:
	lib/linguist/heuristics.rb
2015-02-02 22:13:00 -08:00
Edmundo Ruiz
a716d3ad49 Reverted name Adventure Game Studio back to AGS Script. 2015-02-02 21:48:36 -08:00
halirutan
aa8eb955e9 Removed .mt file extension and example since there are more languages that use this. 2015-01-26 01:44:45 +01:00
halirutan
8e52c18200 Merge branch 'master' into feature-Mathematica10Extensions 2015-01-26 01:43:13 +01:00
halirutan
e468723abc Reordered the extensions entries for Mathematica
Added examples for newly introduces file extensions
2015-01-24 01:00:41 +01:00
halirutan
99bfde32a8 Merge branch 'master' into feature-Mathematica10Extensions 2015-01-24 00:54:03 +01:00
halirutan
c6e8915627 Added Wolfram Language extensions to the Mathematica section. I checked whether other languages have the same extensions I indroduced which is not the case.
Added a sample .wlt file for a Wolfram Unit Test
2015-01-23 04:40:47 +01:00
Arfon Smith
496b3e5a78 Bumping to 4.3.0 beta 2015-01-20 14:48:25 -06:00
Arfon Smith
01be9e68ee Revert "Revert "Use path for Generated?"" 2015-01-20 14:34:36 -06:00
Edmundo Ruiz
2c5e8c4308 Fixed spelling error in disambiguate asc method name. Whoops. 2014-09-14 12:28:20 -07:00
Edmundo Ruiz
506b75c5e8 Merge remote-tracking branch 'upstream/master' 2014-09-14 12:21:50 -07:00
Edmundo Ruiz
af4b64070f Added heuristics to distinguish between AsciiDoc and Adventure Game Studio 2014-09-06 10:59:32 -07:00
Edmundo Ruiz
29d8e58d69 Renamed AGS Script to Adventure Game Studio since the language is unique to the app. 2014-09-06 10:58:36 -07:00
169 changed files with 19415 additions and 197 deletions

42
.gitmodules vendored
View File

@@ -397,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
@@ -615,3 +612,42 @@
[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

View File

@@ -1,4 +1,3 @@
sudo: false
before_install: script/travis/before_install
rvm:
- 1.9.3

View File

@@ -26,7 +26,7 @@ Linguist supports a number of different custom overrides strategies for language
### 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`.
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

View File

@@ -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

View File

@@ -14,9 +14,9 @@ Gem::Specification.new do |s|
s.executables << 'linguist'
s.add_dependency 'charlock_holmes', '~> 0.7.3'
s.add_dependency 'escape_utils', '~> 1.0.1'
s.add_dependency 'escape_utils', '~> 1.1.0'
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'

View File

@@ -26,6 +26,9 @@ vendor/grammars/Alloy.tmbundle:
- source.alloy
vendor/grammars/AutoHotkey/:
- source.ahk
vendor/grammars/BrightScript.tmbundle/:
- source.brightauthorproject
- source.brightscript
vendor/grammars/CLIPS-sublime:
- source.clips
vendor/grammars/ColdFusion:
@@ -60,6 +63,8 @@ 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/:
@@ -88,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:
@@ -106,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:
@@ -136,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:
@@ -145,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
@@ -374,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:
@@ -459,6 +477,9 @@ 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:
@@ -479,9 +500,14 @@ 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
@@ -511,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

View File

@@ -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

View File

@@ -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,7 @@ 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__))
@@ -248,7 +248,7 @@ module Linguist
#
# Return true or false
def documentation?
name =~ DocumentationRegexp ? true : false
path =~ DocumentationRegexp ? true : false
end
# Public: Get each line of data
@@ -316,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.

View File

@@ -7,10 +7,14 @@
# Please add additional test coverage to
# `test/test_blob.rb#test_documentation` if you make any changes.
## Documentation Conventions ##
## Documentation directories ##
- ^docs?/
- ^Documentation/
- (^|/)[Dd]ocumentation/
- (^|/)javadoc/
- ^man/
## Documentation files ##
- (^|/)CONTRIBUTING(\.|$)
- (^|/)COPYING(\.|$)

View File

@@ -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(".")

View File

@@ -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

View File

@@ -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
@@ -94,23 +94,27 @@ module Linguist
Language["Perl6"]
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
@@ -150,11 +154,17 @@ 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|\s*!)/i.match(data)
@@ -162,21 +172,25 @@ module Linguist
end
end
disambiguate "F#", "Forth", "GLSL" do |data|
disambiguate "F#", "Forth", "GLSL", "Filterscript" do |data|
if /^(: |new-device)/.match(data)
Language["Forth"]
elsif /^\s*(#light|import|let|module|namespace|open|type)/.match(data)
Language["F#"]
elsif /^\s*(#include|#pragma|precision|uniform|varying|void)/.match(data)
elsif /^\s*(#version|precision|uniform|varying|vec[234])/.match(data)
Language["GLSL"]
elsif /#include|#pragma\s+(rs|version)|__attribute__/.match(data)
Language["Filterscript"]
end
end
disambiguate "M", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data|
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)
@@ -223,5 +237,55 @@ 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
disambiguate "Rust", "RenderScript" do |data|
if data.include?("^(use |fn |mod |pub |macro_rules|impl|#!?\[)")
Language["Rust"]
elsif /#include|#pragma\s+(rs|version)|__attribute__/.match(data)
Language["RenderScript"]
end
end
end
end

View File

@@ -73,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|
@@ -105,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
@@ -191,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
@@ -528,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

View File

@@ -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"
@@ -108,7 +118,8 @@ Ada:
- .ada
- .ads
aliases:
- ada95ada2005
- ada95
- ada2005
ace_mode: ada
Agda:
@@ -140,7 +151,6 @@ ApacheConf:
- apache
extensions:
- .apacheconf
- .conf
tm_scope: source.apache-config
ace_mode: apache_conf
@@ -186,7 +196,7 @@ AsciiDoc:
- .asciidoc
- .adoc
- .asc
tm_scope: none
tm_scope: text.html.asciidoc
AspectJ:
type: programming
@@ -198,13 +208,12 @@ AspectJ:
Assembly:
type: programming
color: "#a67219"
color: "#6E4C13"
search_term: nasm
aliases:
- nasm
extensions:
- .asm
- .ASM
- .a51
- .nasm
tm_scope: source.asm.x86
@@ -271,6 +280,7 @@ Batchfile:
ace_mode: batchfile
Befunge:
type: programming
extensions:
- .befunge
ace_mode: text
@@ -326,6 +336,7 @@ Boo:
ace_mode: text
Brainfuck:
type: programming
extensions:
- .b
- .bf
@@ -336,7 +347,7 @@ Brightscript:
type: programming
extensions:
- .brs
tm_scope: none
tm_scope: source.brightscript
ace_mode: text
Bro:
@@ -347,15 +358,15 @@ Bro:
C:
type: programming
color: "#555"
color: "#555555"
extensions:
- .c
- .C
- .H
- .cats
- .h
- .idc
- .w
interpreters:
- tcc
ace_mode: c_cpp
C#:
@@ -419,6 +430,7 @@ CLIPS:
ace_mode: text
CMake:
type: programming
extensions:
- .cmake
- .cmake.in
@@ -430,8 +442,6 @@ COBOL:
type: programming
extensions:
- .cob
- .COB
- .CPY
- .cbl
- .ccp
- .cobol
@@ -478,6 +488,7 @@ Chapel:
ace_mode: text
ChucK:
type: programming
extensions:
- .ck
tm_scope: source.java
@@ -505,6 +516,7 @@ Clojure:
color: "#db5855"
extensions:
- .clj
- .boot
- .cl2
- .cljc
- .cljs
@@ -639,6 +651,7 @@ Crystal:
- crystal
Cucumber:
type: programming
extensions:
- .feature
tm_scope: text.gherkin.feature
@@ -697,7 +710,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
@@ -715,11 +740,14 @@ Dart:
ace_mode: dart
Diff:
type: data
color: "#88dddd"
extensions:
- .diff
- .patch
aliases:
- udiff
tm_scope: source.diff
ace_mode: diff
Dockerfile:
@@ -797,6 +825,8 @@ Elixir:
- .ex
- .exs
ace_mode: elixir
filenames:
- mix.lock
Elm:
type: programming
@@ -870,14 +900,6 @@ FORTRAN:
color: "#4d41b1"
extensions:
- .f90
- .F
- .F03
- .F08
- .F77
- .F90
- .F95
- .FOR
- .FPP
- .f
- .f03
- .f08
@@ -916,14 +938,27 @@ Fantom:
tm_scope: source.fan
ace_mode: text
Filterscript:
type: programming
group: RenderScript
extensions:
- .fs
tm_scope: none
ace_mode: text
Formatted:
type: data
extensions:
- .for
tm_scope: none
ace_mode: text
Forth:
type: programming
color: "#341708"
extensions:
- .fth
- .4TH
- .4th
- .F
- .f
- .for
- .forth
@@ -972,7 +1007,6 @@ GAS:
group: Assembly
extensions:
- .s
- .S
tm_scope: source.asm.x86
ace_mode: assembly_x86
@@ -984,7 +1018,6 @@ GDScript:
ace_mode: text
GLSL:
group: C
type: programming
extensions:
- .glsl
@@ -1012,6 +1045,7 @@ Game Maker Language:
ace_mode: c_cpp
Genshi:
type: programming
extensions:
- .kid
tm_scope: text.xml.genshi
@@ -1021,6 +1055,7 @@ Genshi:
ace_mode: xml
Gentoo Ebuild:
type: programming
group: Shell
extensions:
- .ebuild
@@ -1028,6 +1063,7 @@ Gentoo Ebuild:
ace_mode: sh
Gentoo Eclass:
type: programming
group: Shell
extensions:
- .eclass
@@ -1035,6 +1071,7 @@ Gentoo Eclass:
ace_mode: sh
Gettext Catalog:
type: prose
search_term: pot
searchable: false
aliases:
@@ -1130,11 +1167,11 @@ Graphviz (DOT):
tm_scope: source.dot
extensions:
- .dot
- .DOT
- .gv
ace_mode: text
Groff:
type: markup
extensions:
- .man
- '.1'
@@ -1162,6 +1199,7 @@ Groovy:
- groovy
Groovy Server Pages:
type: programming
group: Groovy
aliases:
- gsp
@@ -1243,6 +1281,7 @@ Haml:
Handlebars:
type: markup
color: "#01a9d6"
aliases:
- hbs
- htmlbars
@@ -1311,6 +1350,7 @@ INI:
- .ini
- .cfg
- .prefs
- .pro
- .properties
tm_scope: source.ini
aliases:
@@ -1318,6 +1358,7 @@ INI:
ace_mode: ini
IRC log:
type: data
search_term: irc
aliases:
- irc
@@ -1348,6 +1389,7 @@ Inform 7:
ace_mode: text
Inno Setup:
type: programming
extensions:
- .iss
tm_scope: source.inno
@@ -1379,6 +1421,7 @@ Isabelle:
J:
type: programming
color: "#2d8abd"
extensions:
- .ijs
tm_scope: source.j
@@ -1442,6 +1485,7 @@ Java:
- .java
Java Server Pages:
type: programming
group: Java
search_term: jsp
aliases:
@@ -1537,6 +1581,7 @@ LFE:
ace_mode: lisp
LLVM:
type: programming
extensions:
- .ll
ace_mode: text
@@ -1588,6 +1633,13 @@ Latte:
tm_scope: source.smarty
ace_mode: smarty
Lean:
type: programming
extensions:
- .lean
- .hlean
ace_mode: lean
Less:
type: markup
group: CSS
@@ -1597,6 +1649,7 @@ Less:
ace_mode: less
LilyPond:
type: programming
extensions:
- .ly
- .ily
@@ -1688,7 +1741,7 @@ LoomScript:
Lua:
type: programming
ace_mode: lua
color: "#fa1fa1"
color: "#000080"
extensions:
- .lua
- .fcgi
@@ -1717,6 +1770,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:
@@ -1725,6 +1787,7 @@ Makefile:
- mf
extensions:
- .mak
- .d
- .mk
filenames:
- GNUmakefile
@@ -1735,6 +1798,7 @@ Makefile:
ace_mode: makefile
Mako:
type: programming
extensions:
- .mako
- .mao
@@ -1771,6 +1835,8 @@ Mathematica:
- .ma
- .nb
- .nbp
- .wl
- .wlt
aliases:
- mma
ace_mode: text
@@ -1827,6 +1893,7 @@ Mercury:
ace_mode: prolog
MiniD: # Legacy
type: programming
searchable: false
extensions:
- .minid # Dummy extension
@@ -1874,12 +1941,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
@@ -1892,6 +1968,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"
@@ -1971,6 +2065,7 @@ Nu:
- nush
NumPy:
type: programming
group: Python
extensions:
- .numpy
@@ -1991,6 +2086,10 @@ OCaml:
- .mli
- .mll
- .mly
interpreters:
- ocaml
- ocamlrun
tm_scope: source.ocaml
ObjDump:
type: data
@@ -2084,7 +2183,7 @@ OpenSCAD:
type: programming
extensions:
- .scad
tm_scope: none
tm_scope: source.scad
ace_mode: scad
Org:
@@ -2149,6 +2248,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'
@@ -2210,11 +2330,11 @@ Pascal:
Perl:
type: programming
tm_scope: source.perl
ace_mode: perl
color: "#0298c3"
extensions:
- .pl
- .PL
- .cgi
- .fcgi
- .perl
@@ -2246,7 +2366,7 @@ Perl6:
- Rexfile
interpreters:
- perl6
tm_scope: none
tm_scope: source.perl.6
ace_mode: perl
PigLatin:
@@ -2254,7 +2374,7 @@ PigLatin:
color: "#fcd7de"
extensions:
- .pig
tm_scope: none
tm_scope: source.pig_latin
ace_mode: text
Pike:
@@ -2422,7 +2542,7 @@ Python traceback:
ace_mode: text
QML:
type: markup
type: programming
color: "#44a51c"
extensions:
- .qml
@@ -2430,6 +2550,7 @@ QML:
ace_mode: text
QMake:
type: programming
extensions:
- .pro
- .pri
@@ -2446,8 +2567,6 @@ R:
- splus
extensions:
- .r
- .R
- .Rd
- .rd
- .rsx
filenames:
@@ -2500,7 +2619,6 @@ RMarkdown:
ace_mode: markdown
extensions:
- .rmd
- .Rmd
tm_scope: none
Racket:
@@ -2511,6 +2629,8 @@ Racket:
- .rktd
- .rktl
- .scrbl
interpreters:
- racket
tm_scope: source.racket
ace_mode: lisp
@@ -2526,6 +2646,7 @@ Ragel in Ruby Host:
ace_mode: text
Raw token data:
type: data
search_term: raw
aliases:
- raw
@@ -2544,6 +2665,7 @@ Rebol:
- .r3
- .rebol
ace_mode: text
tm_scope: source.rebol
Red:
type: programming
@@ -2553,15 +2675,24 @@ Red:
- .reds
aliases:
- red/system
tm_scope: none
tm_scope: source.red
ace_mode: text
Redcode:
type: programming
extensions:
- .cw
tm_scope: none
ace_mode: text
RenderScript:
type: programming
extensions:
- .rs
- .rsh
tm_scope: none
ace_mode: text
RobotFramework:
type: programming
extensions:
@@ -2595,6 +2726,7 @@ Ruby:
- .gemspec
- .god
- .irbrc
- .jbuilder
- .mspec
- .pluginspec
- .podspec
@@ -2679,6 +2811,15 @@ SQL:
- .udf
- .viw
#IBM DB2
SQLPL:
type: programming
ace_mode: sql
tm_scope: source.sql
extensions:
- .sql
- .db2
STON:
type: data
group: Smalltalk
@@ -2752,7 +2893,6 @@ Scheme:
- .ss
interpreters:
- guile
- racket
- bigloo
- chicken
ace_mode: scheme
@@ -2843,6 +2983,7 @@ Smalltalk:
ace_mode: text
Smarty:
type: programming
extensions:
- .tpl
ace_mode: smarty
@@ -2854,11 +2995,13 @@ SourcePawn:
- sourcemod
extensions:
- .sp
- .sma
tm_scope: source.sp
ace_mode: text
Squirrel:
type: programming
color: "#800000"
extensions:
- .nut
tm_scope: source.c++
@@ -2894,7 +3037,7 @@ Stylus:
group: CSS
extensions:
- .styl
tm_scope: none
tm_scope: source.stylus
ace_mode: stylus
SuperCollider:
@@ -2991,6 +3134,8 @@ Tea:
Text:
type: prose
wrap: true
aliases:
- fundamental
extensions:
- .txt
- .fr
@@ -3065,11 +3210,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
@@ -3107,12 +3252,15 @@ VimL:
search_term: vim
aliases:
- vim
- nvim
extensions:
- .vim
filenames:
- .nvimrc
- .vimrc
- _vimrc
- gvimrc
- nvimrc
- vimrc
ace_mode: text
@@ -3159,13 +3307,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
@@ -3197,6 +3346,7 @@ XML:
- .mxml
- .nproj
- .nuspec
- .odd
- .osm
- .plist
- .pluginspec
@@ -3207,15 +3357,16 @@ XML:
- .rss
- .scxml
- .srdf
- .storyboard
- .stTheme
- .sublime-snippet
- .targets
- .tmCommand
- .tml
- .tmLanguage
- .tmPreferences
- .tmSnippet
- .tmTheme
- .tml
- .ts
- .ui
- .urdf
@@ -3230,6 +3381,7 @@ XML:
- .x3d
- .xacro
- .xaml
- .xib
- .xlf
- .xliff
- .xmi
@@ -3266,6 +3418,7 @@ XQuery:
ace_mode: xquery
XS:
type: programming
extensions:
- .xs
tm_scope: source.c
@@ -3338,6 +3491,7 @@ desktop:
eC:
type: programming
color: "#4A4773"
search_term: ec
extensions:
- .ec
@@ -3362,6 +3516,7 @@ fish:
ace_mode: text
mupad:
type: programming
extensions:
- .mu
ace_mode: text

View File

@@ -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
@@ -49,7 +51,7 @@ module Linguist
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

View File

@@ -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

View File

@@ -1,7 +1,7 @@
module Linguist
module Strategy
class Modeline
EmacsModeline = /-\*-\s*mode:\s*(\w+);?\s*-\*-/i
EmacsModeline = /-\*-\s*(?:(?!mode)[\w-]+\s*:\s*(?:[\w+-]+)\s*;?\s*)*(?:mode\s*:)?\s*([\w+-]+)\s*(?:;\s*(?!mode)[\w-]+\s*:\s*[\w+-]+\s*)*;?\s*-\*-/i
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//i
# Public: Detects language based on Vim and Emacs modelines

View File

@@ -24,6 +24,9 @@
- (^|/)config.guess$
- (^|/)config.sub$
# Linters
- cpplint.py
# Node dependencies
- node_modules/
@@ -143,6 +146,9 @@
## Python ##
# Sphinx
- (^|/)docs?/_?(build|themes?|templates?|static)/
# django
- (^|/)admin_media/
@@ -221,7 +227,7 @@
- ^readme$
# Test fixtures
- ^[Tt]est/fixtures/
- ^[Tt]ests?/fixtures/
# PhoneGap/Cordova
- (^|/)cordova([^.]*)\.js$
@@ -233,7 +239,7 @@
# Vagrant
- ^Vagrantfile$
# .DS_Store's
# .DS_Stores
- .[Dd][Ss]_[Ss]tore$
# R packages
@@ -251,3 +257,9 @@
# ProGuard
- proguard.pro
- proguard-rules.pro
# PuPHPet
- ^puphpet/
# Android Google APIs
- (^|/)\.google_apis/

View File

@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.4.0"
VERSION = "4.5.4"
end

25
samples/AMPL/toy.ampl Normal file
View 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;

View File

@@ -0,0 +1,13 @@
# Calculate and output all fibonacci numbers under 100
+++++++++++
>+>>>>++++++++++++++++++++++++++++++++++++++++++++
>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
>[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
+++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
++++++++++++++++++++++++++++++++++++++++++++.[-]<<
<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]

View File

@@ -0,0 +1,4 @@
// More complex version of hello world
>++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>
>+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++.

View File

@@ -0,0 +1,3 @@
// Hello World
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

View 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

2310
samples/C/filenames/script Executable file

File diff suppressed because it is too large Load Diff

166
samples/C/pqiv.h Normal file
View 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

View 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)))

318
samples/D/mpq.d Normal file
View 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
View 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);
}

View 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
View 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();
};

View 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

View 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

View 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

View File

@@ -0,0 +1,10 @@
%{"cowboy": {:hex, :cowboy, "1.0.0"},
"cowlib": {:hex, :cowlib, "1.0.1"},
"hackney": {:hex, :hackney, "0.14.3"},
"hound": {:hex, :hound, "0.6.0"},
"httpoison": {:hex, :httpoison, "0.5.0"},
"idna": {:hex, :idna, "1.0.1"},
"phoenix": {:hex, :phoenix, "0.10.0"},
"plug": {:hex, :plug, "0.11.1"},
"poison": {:hex, :poison, "1.3.1"},
"ranch": {:hex, :ranch, "1.0.0"}}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.
*/
#include "ip.rsh"
static rs_matrix4x4 Mat;
void init() {
rsMatrixLoadIdentity(&Mat);
}
void setMatrix(rs_matrix4x4 m) {
Mat = m;
}
uchar4 __attribute__((kernel)) root(uchar4 in) {
float4 f = convert_float4(in);
f = rsMatrixMultiply(&Mat, f);
f = clamp(f, 0.f, 255.f);
return convert_uchar4(f);
}

View File

@@ -0,0 +1,18 @@
#pragma version(1)
#pragma rs java_package_name(foo)
int __attribute__((kernel)) root(uint32_t ain) {
return 0;
}
void __attribute__((kernel)) in_only(uint32_t ain) {
}
int __attribute__((kernel)) out_only() {
return 0;
}
int __attribute__((kernel)) everything(uint32_t ain, uint32_t x, uint32_t y) {
return 0;
}

File diff suppressed because it is too large Load Diff

1157
samples/Go/api.pb.go Normal file

File diff suppressed because it is too large Load Diff

View 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

75
samples/Lean/binary.lean Normal file
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,5 @@
bar/foo.o: \
bar/foo.c \
bar/baz.h
bar/baz.h:

View 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[];

View 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[]

84
samples/NL/assign0.nl Normal file
View 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

File diff suppressed because it is too large Load Diff

View 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

View 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

View 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

View 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 *)
(***********************************************************)

49
samples/NewLisp/queens.nl Normal file
View 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

File diff suppressed because it is too large Load Diff

14
samples/OCaml/common.ml Normal file
View 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
View 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
View 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

File diff suppressed because it is too large Load Diff

125
samples/OCaml/reload.ml Normal file
View 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
View 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
View 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.
---------------------------------------------------------------------------*)

View 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;
/

View 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;
/

View 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;
/

View 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#;
/

View 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;
/

View 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();

View 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();

View 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();

View 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();

View 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();

View 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>&nbsp;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>&nbsp;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/&/&amp;/g;
$l =~ s/</&lt;/g;
$l =~ s/>/&gt;/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;

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.
*/
#pragma version(1)
#pragma rs java_package_name(com.android.gallery3d.filtershow.filters)
#pragma rs_fp_relaxed
int32_t gWidth;
int32_t gHeight;
const uchar4 *gPixels;
rs_allocation gIn;
float gCoeffs[9];
void root(const uchar4 *in, uchar4 *out, const void *usrData, uint32_t x, uint32_t y) {
uint32_t x1 = min((int32_t)x+1, gWidth-1);
uint32_t x2 = max((int32_t)x-1, 0);
uint32_t y1 = min((int32_t)y+1, gHeight-1);
uint32_t y2 = max((int32_t)y-1, 0);
float4 p00 = rsUnpackColor8888(gPixels[x1 + gWidth * y1]);
float4 p01 = rsUnpackColor8888(gPixels[x + gWidth * y1]);
float4 p02 = rsUnpackColor8888(gPixels[x2 + gWidth * y1]);
float4 p10 = rsUnpackColor8888(gPixels[x1 + gWidth * y]);
float4 p11 = rsUnpackColor8888(gPixels[x + gWidth * y]);
float4 p12 = rsUnpackColor8888(gPixels[x2 + gWidth * y]);
float4 p20 = rsUnpackColor8888(gPixels[x1 + gWidth * y2]);
float4 p21 = rsUnpackColor8888(gPixels[x + gWidth * y2]);
float4 p22 = rsUnpackColor8888(gPixels[x2 + gWidth * y2]);
p00 *= gCoeffs[0];
p01 *= gCoeffs[1];
p02 *= gCoeffs[2];
p10 *= gCoeffs[3];
p11 *= gCoeffs[4];
p12 *= gCoeffs[5];
p20 *= gCoeffs[6];
p21 *= gCoeffs[7];
p22 *= gCoeffs[8];
p00 += p01;
p02 += p10;
p11 += p12;
p20 += p21;
p22 += p00;
p02 += p11;
p20 += p22;
p20 += p02;
p20 = clamp(p20, 0.f, 1.f);
*out = rsPackColorTo8888(p20.r, p20.g, p20.b);
}

View File

@@ -0,0 +1,323 @@
// Copyright (C) 2011-2012 The Android Open Source Project
//
// 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.
#pragma version(1)
#pragma rs java_package_name(com.android.scenegraph)
#ifndef _TRANSFORM_DEF_
#define _TRANSFORM_DEF_
#include "rs_graphics.rsh"
#define TRANSFORM_NONE 0
#define TRANSFORM_TRANSLATE 1
#define TRANSFORM_ROTATE 2
#define TRANSFORM_SCALE 3
#define CULL_FRUSTUM 0
#define CULL_ALWAYS 2
#define LIGHT_POINT 0
#define LIGHT_DIRECTIONAL 1
// Shader params that involve only data
#define SHADER_PARAM_DATA_ONLY 10000
#define SHADER_PARAM_FLOAT4_DATA 10001
#define SHADER_PARAM_TRANSFORM_DATA 10002
#define SHADER_PARAM_TRANSFORM_MODEL 10003
// Shader params that involve camera
#define SHADER_PARAM_CAMERA 1000
#define SHADER_PARAM_FLOAT4_CAMERA_POS 1001
#define SHADER_PARAM_FLOAT4_CAMERA_DIR 1002
#define SHADER_PARAM_TRANSFORM_VIEW 1003
#define SHADER_PARAM_TRANSFORM_PROJ 1004
#define SHADER_PARAM_TRANSFORM_VIEW_PROJ 1005
#define SHADER_PARAM_TRANSFORM_MODEL_VIEW 1006
#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 1007
// Shader Params that only involve lights
#define SHADER_PARAM_LIGHT 100
#define SHADER_PARAM_FLOAT4_LIGHT_COLOR 103
#define SHADER_PARAM_FLOAT4_LIGHT_POS 104
#define SHADER_PARAM_FLOAT4_LIGHT_DIR 105
#define SHADER_PARAM_TEXTURE 10
#define TEXTURE_NONE 0
#define TEXTURE_2D 1
#define TEXTURE_CUBE 2
#define TEXTURE_RENDER_TARGET 3
typedef struct TransformComponent_s {
float4 value;
int type;
rs_allocation name;
} SgTransformComponent;
typedef struct __attribute__((packed, aligned(4))) SgTransform {
rs_matrix4x4 globalMat;
rs_matrix4x4 localMat;
rs_allocation components;
int isDirty;
rs_allocation children;
rs_allocation name;
// Used to check whether transform params need to be updated
uint32_t timestamp;
} SgTransform;
typedef struct VertexShader_s {
rs_program_vertex program;
// Buffer with vertex constant data
rs_allocation shaderConst;
// ShaderParam's that populate data
rs_allocation shaderConstParams;
// location of the per object constants on the buffer
int objectConstIndex;
} SgVertexShader;
typedef struct FragmentShader_s {
rs_program_fragment program;
// Buffer with vertex constant data
rs_allocation shaderConst;
// ShaderParam's that populate data
rs_allocation shaderConstParams;
// ShaderParam's that set textures
rs_allocation shaderTextureParams;
// location of the per object constants on the buffer
int objectConstIndex;
} SgFragmentShader;
typedef struct RenderState_s {
rs_allocation pv; // VertexShader struct
rs_allocation pf; // FragmentShader struct
rs_program_store ps;
rs_program_raster pr;
} SgRenderState;
typedef struct Renderable_s {
rs_allocation render_state;
// Buffer with vertex constant data
rs_allocation pv_const;
// ShaderParam's that populate data
rs_allocation pv_constParams;
// Buffer with fragment constant data
rs_allocation pf_const;
// ShaderParam's that populate data
rs_allocation pf_constParams;
rs_allocation pf_textures[8];
int pf_num_textures;
rs_mesh mesh;
int meshIndex;
rs_allocation transformMatrix;
rs_allocation name;
float4 boundingSphere;
float4 worldBoundingSphere;
int bVolInitialized;
int cullType; // specifies whether to frustum cull
int isVisible;
} SgRenderable;
typedef struct RenderPass_s {
rs_allocation color_target;
rs_allocation depth_target;
rs_allocation camera;
rs_allocation objects;
float4 clear_color;
float clear_depth;
bool should_clear_color;
bool should_clear_depth;
} SgRenderPass;
typedef struct Camera_s {
rs_matrix4x4 proj;
rs_matrix4x4 view;
rs_matrix4x4 viewProj;
float4 position;
float near;
float far;
float horizontalFOV;
float aspect;
rs_allocation name;
rs_allocation transformMatrix;
float4 frustumPlanes[6];
int isDirty;
// Timestamp of the camera itself to signal params if anything changes
uint32_t timestamp;
// Timestamp of our transform
uint32_t transformTimestamp;
} SgCamera;
typedef struct Light_s {
float4 position;
float4 color;
float intensity;
int type;
rs_allocation name;
rs_allocation transformMatrix;
} SgLight;
// This represents the shader parameter data needed to set a float or transform data
typedef struct ShaderParamData_s {
int type;
float4 float_value;
uint32_t timestamp;
rs_allocation paramName;
rs_allocation camera;
rs_allocation light;
rs_allocation transform;
rs_allocation texture;
} SgShaderParamData;
// This represents a shader parameter that knows how to update itself for a given
// renderable or shader and contains a timestamp for the last time this buffer was updated
typedef struct ShaderParam_s {
// Used to check whether transform params need to be updated
uint32_t transformTimestamp;
// Used to check whether data params need to be updated
// These are used when somebody set the matrix of float value directly in java
uint32_t dataTimestamp;
// Specifies where in the constant buffer data gets written to
int bufferOffset;
// An instance of SgShaderParamData that could be shared by multiple objects
rs_allocation data;
// How many components of the vector we need to write
int float_vecSize;
} SgShaderParam;
// This represents a texture object
typedef struct Texture_s {
uint32_t type;
rs_allocation texture;
} SgTexture;
static void printName(rs_allocation name) {
if (!rsIsObject(name)) {
rsDebug("no name", 0);
return;
}
rsDebug((const char*)rsGetElementAt(name, 0), 0);
}
static void printCameraInfo(const SgCamera *cam) {
rsDebug("***** Camera information. ptr:", cam);
printName(cam->name);
const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0);
rsDebug("Transform name:", camTransform);
printName(camTransform->name);
rsDebug("Aspect: ", cam->aspect);
rsDebug("Near: ", cam->near);
rsDebug("Far: ", cam->far);
rsDebug("Fov: ", cam->horizontalFOV);
rsDebug("Position: ", cam->position);
rsDebug("Proj: ", &cam->proj);
rsDebug("View: ", &cam->view);
}
static void printLightInfo(const SgLight *light) {
rsDebug("***** Light information. ptr:", light);
printName(light->name);
const SgTransform *lTransform = (const SgTransform *)rsGetElementAt(light->transformMatrix, 0);
rsDebug("Transform name:", lTransform);
printName(lTransform->name);
rsDebug("Position: ", light->position);
rsDebug("Color : ", light->color);
rsDebug("Intensity: ", light->intensity);
rsDebug("Type: ", light->type);
}
static void getCameraRay(const SgCamera *cam, int screenX, int screenY, float3 *pnt, float3 *vec) {
rsDebug("=================================", screenX);
rsDebug("Point X", screenX);
rsDebug("Point Y", screenY);
rs_matrix4x4 mvpInv;
rsMatrixLoad(&mvpInv, &cam->viewProj);
rsMatrixInverse(&mvpInv);
float width = (float)rsgGetWidth();
float height = (float)rsgGetHeight();
float4 pos = {(float)screenX, height - (float)screenY, 0.0f, 1.0f};
pos.x /= width;
pos.y /= height;
rsDebug("Pre Norm X", pos.x);
rsDebug("Pre Norm Y", pos.y);
pos.xy = pos.xy * 2.0f - 1.0f;
rsDebug("Norm X", pos.x);
rsDebug("Norm Y", pos.y);
pos = rsMatrixMultiply(&mvpInv, pos);
float oneOverW = 1.0f / pos.w;
pos.xyz *= oneOverW;
rsDebug("World X", pos.x);
rsDebug("World Y", pos.y);
rsDebug("World Z", pos.z);
rsDebug("Cam X", cam->position.x);
rsDebug("Cam Y", cam->position.y);
rsDebug("Cam Z", cam->position.z);
*vec = normalize(pos.xyz - cam->position.xyz);
rsDebug("Vec X", vec->x);
rsDebug("Vec Y", vec->y);
rsDebug("Vec Z", vec->z);
*pnt = cam->position.xyz;
}
static bool intersect(const SgRenderable *obj, float3 pnt, float3 vec) {
// Solving for t^2 + Bt + C = 0
float3 originMinusCenter = pnt - obj->worldBoundingSphere.xyz;
float B = dot(originMinusCenter, vec) * 2.0f;
float C = dot(originMinusCenter, originMinusCenter) -
obj->worldBoundingSphere.w * obj->worldBoundingSphere.w;
float discriminant = B * B - 4.0f * C;
if (discriminant < 0.0f) {
return false;
}
discriminant = sqrt(discriminant);
float t0 = (-B - discriminant) * 0.5f;
float t1 = (-B + discriminant) * 0.5f;
if (t0 > t1) {
float temp = t0;
t0 = t1;
t1 = temp;
}
// The sphere is behind us
if (t1 < 0.0f) {
return false;
}
return true;
}
#endif // _TRANSFORM_DEF_

View File

@@ -0,0 +1,4 @@
json.array!(@courts) do |court|
json.extract! court, :id, :name_r, :region, :region_r, :email, :website
json.url court_url(court, format: :json)
end

View File

@@ -0,0 +1,21 @@
CREATE TABLE x AS SELECT * FROM DUAL;
CREATE TABLE y (
col1 NUMBER NOT NULL ,
col2 VARCHAR2(200),
col3 DATE,
col4 TIMESTAMP WITH TIME ZONE NOT NULL
);
CREATE USER username IDENTIFIED BY password;
GRANT CONNECT, RESOURCE TO username;
GRANT CREATE TYPE TO username;
GRANT CREATE PROCEDURE TO username;
GRANT CREATE TABLE TO username;
GRANT CREATE VIEW TO username;

View File

@@ -0,0 +1,13 @@
drop procedure who_called_me;
drop package body linguist_package;
drop package linguist_package;
drop function functionname1;
drop table x;
drop table y cascade;
drop type typename1;
drop type typename2;
drop view viewname1;
drop view viewname2;

3
samples/SQL/dual.sql Normal file
View File

@@ -0,0 +1,3 @@
--this is the most basic oracle sql command
select * from dual;

View File

@@ -0,0 +1,39 @@
create procedure check_reorg_tables (in v_schema varchar(128), out v_reorg_counter integer)
begin
declare loc result_set_locator varying;
declare schema_out varchar(128);
declare table_out varchar(128);
declare card_out integer;
declare overflow_out integer;
declare npages_out integer;
declare fpages_out integer;
declare active_blocks_out integer;
declare tsize_out integer;
declare f1_out integer;
declare f2_out integer;
declare f3_out integer;
declare reorg_out varchar(3);
declare cursor_end smallint default 0;
declare continue handler for NOT FOUND
set cursor_end = 1;
set v_reorg_counter = 0;
call reorgchk_tb_stats('S', v_schema);
associate result set locator(loc) with procedure reorgchk_tb_stats;
allocate mycursor cursor for result set loc;
open mycursor;
repeat
fetch from mycursor into schema_out, table_out, card_out, overflow_out, npages_out, fpages_out, active_blocks_out, tsize_out, f1_out, f2_out, f3_out, reorg_out;
if reorg_out <> '---' then
set v_reorg_counter = v_reorg_counter + 1;
end if;
until cursor_end = 1
end repeat;
close mycursor;
end!

View File

@@ -0,0 +1,30 @@
DROP FUNCTION COMM_AMOUNT;
CREATE FUNCTION COMM_AMOUNT(SALARY DEC(9,2))
RETURNS DEC(9,2)
LANGUAGE SQL READS SQL DATA
BEGIN ATOMIC
DECLARE REMAINDER DEC(9,2) DEFAULT 0.0;--
DECLARE COMM_PAID DEC(9,2) DEFAULT 0.0;--
DECLARE COMM_INCR INT DEFAULT 1;--
DECLARE MAX_COMM DEC(9,2) DEFAULT 0.0;--
IF (SALARY <= 0) THEN
SIGNAL SQLSTATE '75000'
SET MESSAGE_TEXT = 'Bad Salary';--
END IF;--
SET REMAINDER = SALARY;--
L1: WHILE REMAINDER > 0.0 DO
SET COMM_PAID = COMM_PAID + (COMM_INCR * 500.00);--
SET REMAINDER = REMAINDER-(COMM_INCR * 5000.00);--
SET COMM_INCR = COMM_INCR + 1;--
END WHILE L1;--
SET MAX_COMM =
(SELECT SUM(SALARY)/100.00 FROM EMPLOYEE);--
IF (COMM_PAID > MAX_COMM) THEN
SET COMM_PAID = MAX_COMM;--
END IF;--
RETURN COMM_PAID;--
END;

View File

@@ -0,0 +1,13 @@
DROP TABLE TDEPT;
CREATE TABLE TDEPT (DEPTNO CHAR(4));
--#SET TERMINATOR @
BEGIN ATOMIC
DECLARE COUNT INT DEFAULT 5;
WHILE COUNT > 0 DO
INSERT INTO TDEPT VALUES 'F'||
RTRIM(CHAR(COUNT));
SET COUNT = COUNT - 1;
END WHILE;
END@

View File

@@ -0,0 +1,18 @@
create procedure runstats (out nr_tables integer, out nr_ok integer)
begin
declare SQLCODE integer;
declare stmt varchar(100);
set nr_tables = 0;
set nr_ok = 0;
for line as select tabschema, tabname from syscat.tables where type='T' and tabschema='SPODEN'
do
set nr_tables = nr_tables + 1;
set stmt = 'CALL SYSPROC.ADMIN_CMD (RUNSTATS ON TABLE ' concat rtrim(line.tabschema) concat '.' concat line.tabname concat ')';
execute immediate stmt;
if SQLCODE = 0 then
set nr_ok = nr_ok + 1;
end if;
end for;
end!

9
samples/SQLPL/sleep.sql Normal file
View File

@@ -0,0 +1,9 @@
create procedure sleep (in sleeptime integer)
begin
declare wait_until timestamp;
set wait_until = (current timestamp + sleeptime seconds);
while (wait_until > current timestamp)
do
end while;
end!

View File

@@ -0,0 +1,9 @@
create trigger CHECK_HIREDATE
no cascade before insert on EMPLOYEE
referencing new as N
for each row mode db2sql
if n.hiredate > current date
then
signal SQLSTATE '75000'
set MESSAGE_TEXT = 'Hire date must be in the past';
end if!

272
samples/SourcePawn/foo.sma Normal file
View File

@@ -0,0 +1,272 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
//
// TimeLeft Plugin
//
#include <amxmodx>
const TASK_TIMEREMAIN_SHORT = 8648458 // 0.8s repeat task
const TASK_TIMEREMAIN_LARGE = 34543 // 1.0s repeat task
// time display flags
const TD_BOTTOM_WHITE_TEXT = 1 // a - display white text on bottom
const TD_USE_VOICE = 2 // b - use voice
const TD_NO_REMAINING_VOICE = 4 // c - don't add "remaining" (only in voice)
const TD_NO_HOURS_MINS_SECS_VOICE = 8 // d - don't add "hours/minutes/seconds" (only in voice)
const TD_SHOW_SPEAK_VALUES_BELOW = 16 // e - show/speak if current time is less than this set in parameter
new g_TimeSet[32][2]
new g_LastTime
new g_CountDown
new g_Switch
// pcvars
new g_amx_time_voice, g_amx_timeleft
new g_mp_timelimit
public plugin_init()
{
register_plugin("TimeLeft", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("timeleft.txt")
g_amx_time_voice = register_cvar("amx_time_voice", "1")
register_srvcmd("amx_time_display", "setDisplaying")
g_amx_timeleft = register_cvar("amx_timeleft", "00:00", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
register_clcmd("say timeleft", "sayTimeLeft", 0, "- displays timeleft")
register_clcmd("say thetime", "sayTheTime", 0, "- displays current time")
set_task(0.8, "timeRemain", TASK_TIMEREMAIN_SHORT, "", 0, "b")
g_mp_timelimit = get_cvar_pointer("mp_timelimit")
}
public sayTheTime(id)
{
if (get_pcvar_num(g_amx_time_voice))
{
new mhours[6], mmins[6], whours[32], wmins[32], wpm[6]
get_time("%H", mhours, charsmax(mhours))
get_time("%M", mmins, charsmax(mmins))
new mins = str_to_num(mmins)
new hrs = str_to_num(mhours)
if (mins)
num_to_word(mins, wmins, charsmax(wmins))
else
wmins[0] = EOS
if (hrs < 12)
wpm = "am "
else
{
if (hrs > 12) hrs -= 12
wpm = "pm "
}
if (hrs)
num_to_word(hrs, whours, charsmax(whours))
else
whours = "twelve "
client_cmd(id, "spk ^"fvox/time_is_now %s_period %s%s^"", whours, wmins, wpm)
}
new ctime[64]
get_time("%m/%d/%Y - %H:%M:%S", ctime, charsmax(ctime))
client_print(0, print_chat, "%L: %s", LANG_PLAYER, "THE_TIME", ctime)
return PLUGIN_CONTINUE
}
public sayTimeLeft(id)
{
if (get_pcvar_float(g_mp_timelimit))
{
new a = get_timeleft()
if (get_pcvar_num(g_amx_time_voice))
{
new svoice[128]
setTimeVoice(svoice, charsmax(svoice), 0, a)
client_cmd(id, "%s", svoice)
}
client_print(0, print_chat, "%L: %d:%02d", LANG_PLAYER, "TIME_LEFT", (a / 60), (a % 60))
}
else
client_print(0, print_chat, "%L", LANG_PLAYER, "NO_T_LIMIT")
return PLUGIN_CONTINUE
}
setTimeText(text[], len, tmlf, id)
{
new secs = tmlf % 60
new mins = tmlf / 60
if (secs == 0)
formatex(text, len, "%d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE")
else if (mins == 0)
formatex(text, len, "%d %L", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
else
formatex(text, len, "%d %L %d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE", secs, id, (secs > 1) ? "SECONDS" : "SECOND")
}
setTimeVoice(text[], len, flags, tmlf)
{
new temp[7][32]
new secs = tmlf % 60
new mins = tmlf / 60
// for (new a = 0;a < 7;++a) // we just created it, already null
// temp[a][0] = 0
if (secs > 0)
{
num_to_word(secs, temp[4], charsmax(temp[]))
if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE )
temp[5] = "seconds " /* there is no "second" in default hl */
}
if (mins > 59)
{
new hours = mins / 60
num_to_word(hours, temp[0], charsmax(temp[]))
if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE )
temp[1] = "hours "
mins = mins % 60
}
if (mins > 0)
{
num_to_word(mins, temp[2], charsmax(temp[]))
if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE )
temp[3] = "minutes "
}
if ( ~flags & TD_NO_REMAINING_VOICE )
temp[6] = "remaining "
return formatex(text, len, "spk ^"vox/%s%s%s%s%s%s%s^"", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6])
}
findDispFormat(_time)
{
// it is important to check i<sizeof BEFORE g_TimeSet[i][0] to prevent out of bound error
for (new i = 0; i < sizeof(g_TimeSet) && g_TimeSet[i][0]; ++i)
{
if (g_TimeSet[i][1] & TD_SHOW_SPEAK_VALUES_BELOW)
{
if (g_TimeSet[i][0] > _time)
{
if (!g_Switch)
{
g_CountDown = g_Switch = _time
remove_task(TASK_TIMEREMAIN_SHORT)
set_task(1.0, "timeRemain", TASK_TIMEREMAIN_LARGE, "", 0, "b")
}
return i
}
}
else if (g_TimeSet[i][0] == _time)
{
return i
}
}
return -1
}
public setDisplaying()
{
new arg[32], flags[32], num[32]
new argc = read_argc() - 1
new i = 0
while (i < argc && i < sizeof(g_TimeSet))
{
read_argv(i + 1, arg, charsmax(arg))
parse(arg, flags, charsmax(flags), num, charsmax(num))
g_TimeSet[i][0] = str_to_num(num)
g_TimeSet[i][1] = read_flags(flags)
i++
}
if( i < sizeof(g_TimeSet) )
g_TimeSet[i][0] = 0 // has to be zeroed in case command is sent twice
return PLUGIN_HANDLED
}
public timeRemain(param[])
{
new gmtm = get_timeleft()
new tmlf = g_Switch ? --g_CountDown : gmtm
new stimel[12]
formatex(stimel, charsmax(stimel), "%02d:%02d", gmtm / 60, gmtm % 60)
set_pcvar_string(g_amx_timeleft, stimel)
if (g_Switch && gmtm > g_Switch)
{
remove_task(TASK_TIMEREMAIN_LARGE)
g_Switch = 0
set_task(0.8, "timeRemain", TASK_TIMEREMAIN_SHORT, "", 0, "b")
return
}
if (tmlf > 0 && g_LastTime != tmlf)
{
g_LastTime = tmlf
new tm_set = findDispFormat(tmlf)
if (tm_set != -1)
{
new flags = g_TimeSet[tm_set][1]
new arg[128]
if (flags & TD_BOTTOM_WHITE_TEXT)
{
new players[MAX_PLAYERS], pnum, plr
get_players(players, pnum, "c")
if (flags & TD_SHOW_SPEAK_VALUES_BELOW) // yes this is correct flag, just because message should be shorter if it is shown every seconds
set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 1.1, 0.1, 0.5, -1)
else
set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 3.0, 0.0, 0.5, -1)
for (new i = 0; i < pnum; i++)
{
plr = players[i]
setTimeText(arg, charsmax(arg), tmlf, plr)
show_hudmessage(plr, "%s", arg)
}
}
if (flags & TD_USE_VOICE)
{
setTimeVoice(arg, charsmax(arg), flags, tmlf)
client_cmd(0, "%s", arg)
}
}
}
}

View File

@@ -0,0 +1,10 @@
set nocompatible
set ignorecase
set smartcase
set showmatch
set showcmd
syntax on
set hlsearch " Highlight searches
set incsearch " Do incremental searching

View File

@@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: linguist-disable-strategy-modeline-IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: linguist-disable-strategy-modeline-IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UIApplication">
<connections>
<outlet property="delegate" destination="bYg-Ix-Cfg" id="h4M-LL-qlT"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<customObject id="bYg-Ix-Cfg" userLabel="App Delegate"/>
<window opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="Na2-4i-xf1">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</window>
</objects>
</document>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
</dependencies>
<scenes/>
</document>

466
samples/XS/CommonMark.xs Normal file
View File

@@ -0,0 +1,466 @@
/*
* This software is copyright (C) by Nick Wellnhofer <wellnhofer@aevum.de>.
*
* This is free software; you can redistribute it and/or modify it under
* the same terms as the Perl 5 programming language system itself.
*
* Terms of the Perl programming language system itself
*
* a) the GNU General Public License as published by the Free
* Software Foundation; either version 1, or (at your option) any
* later version, or
* b) the "Artistic License"
*/
/*
* Notes on memory management
*
* - A pointer to the Perl SV representing a node is stored in the
* user data slot of `struct cmark_node`, so there's a 1:1 mapping
* between Perl and C objects.
* - Every node SV keeps a reference to the parent SV. This is done
* indirectly by looking up the parent SV and increasing its refcount.
* - This makes sure that a document isn't freed if the last reference
* from Perl to the root node is dropped, as references to child nodes
* might still exist.
* - As a consequence, as long as a node is referenced from Perl, all its
* ancestor nodes will also be associated with a Perl object.
*/
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdlib.h>
#include <cmark.h>
#if CMARK_VERSION < 0x001000
#error libcmark 0.16.0 is required.
#endif
/* Fix prefixes of render functions. */
#define cmark_node_render_html cmark_render_html
#define cmark_node_render_xml cmark_render_xml
#define cmark_node_render_man cmark_render_man
static SV*
S_create_or_incref_node_sv(pTHX_ cmark_node *node) {
SV *new_obj = NULL;
while (node) {
SV *obj;
HV *stash;
/* Look for existing object. */
obj = (SV*)cmark_node_get_user_data(node);
if (obj) {
/* Incref if found. */
SvREFCNT_inc_simple_void_NN(obj);
if (!new_obj) {
new_obj = obj;
}
break;
}
/* Create a new SV. */
obj = newSViv(PTR2IV(node));
cmark_node_set_user_data(node, obj);
if (!new_obj) {
new_obj = obj;
}
/*
* Unfortunately, Perl doesn't offer an API function to bless an SV
* without a reference. The following code is mostly copied from
* sv_bless.
*/
SvOBJECT_on(obj);
#if (PERL_VERSION <= 16)
PL_sv_objcount++;
#endif
SvUPGRADE(obj, SVt_PVMG);
stash = gv_stashpvn("CommonMark::Node", 16, GV_ADD);
SvSTASH_set(obj, (HV*)SvREFCNT_inc(stash));
/* Recurse into parent. */
node = cmark_node_parent(node);
}
return new_obj;
}
static void
S_decref_node_sv(pTHX_ cmark_node *node) {
SV *obj;
if (!node) {
return;
}
obj = (SV*)cmark_node_get_user_data(node);
if (!obj) {
/* Should never happen. */
croak("Internal error: node SV not found");
}
SvREFCNT_dec_NN(obj);
}
/* Find or create an SV for a cmark_node. */
static SV*
S_node2sv(pTHX_ cmark_node *node) {
SV *obj;
if (!node) {
return &PL_sv_undef;
}
obj = S_create_or_incref_node_sv(aTHX_ node);
return newRV_noinc(obj);
}
/* Transfer refcount from a node to another. */
static void
S_transfer_refcount(pTHX_ cmark_node *from, cmark_node *to) {
if (from != to) {
S_create_or_incref_node_sv(aTHX_ to);
S_decref_node_sv(aTHX_ from);
}
}
/* Get C struct pointer from an SV argument. */
static void*
S_sv2c(pTHX_ SV *sv, const char *class_name, STRLEN len, CV *cv,
const char *var_name) {
if (!SvROK(sv) || !sv_derived_from_pvn(sv, class_name, len, 0)) {
const char *sub_name = GvNAME(CvGV(cv));
croak("%s: %s is not of type %s", sub_name, var_name, class_name);
}
return INT2PTR(void*, SvIV(SvRV(sv)));
}
MODULE = CommonMark PACKAGE = CommonMark PREFIX = cmark_
PROTOTYPES: DISABLE
BOOT:
if (cmark_version != CMARK_VERSION) {
warn("Compiled against libcmark %s, but runtime version is %s",
CMARK_VERSION_STRING, cmark_version_string);
}
char*
cmark_markdown_to_html(package, string)
SV *package = NO_INIT
SV *string
PREINIT:
STRLEN len;
const char *buffer;
CODE:
(void)package;
buffer = SvPVutf8(string, len);
RETVAL = cmark_markdown_to_html(buffer, len);
OUTPUT:
RETVAL
cmark_node*
cmark_parse_document(package, string)
SV *package = NO_INIT
SV *string
PREINIT:
STRLEN len;
const char *buffer;
CODE:
(void)package;
buffer = SvPVutf8(string, len);
RETVAL = cmark_parse_document(buffer, len);
OUTPUT:
RETVAL
cmark_node*
cmark_parse_file(package, file)
SV *package = NO_INIT
SV *file
PREINIT:
PerlIO *perl_io;
FILE *stream = NULL;
CODE:
(void)package;
perl_io = IoIFP(sv_2io(file));
if (perl_io) {
stream = PerlIO_findFILE(perl_io);
}
if (!stream) {
croak("parse_file: file is not a file handle");
}
RETVAL = cmark_parse_file(stream);
OUTPUT:
RETVAL
int
cmark_version(package)
SV *package = NO_INIT
CODE:
(void)package;
RETVAL = cmark_version;
OUTPUT:
RETVAL
const char*
cmark_version_string(package)
SV *package = NO_INIT
CODE:
(void)package;
RETVAL = cmark_version_string;
OUTPUT:
RETVAL
int
cmark_compile_time_version(package)
SV *package = NO_INIT
CODE:
(void)package;
RETVAL = CMARK_VERSION;
OUTPUT:
RETVAL
const char*
cmark_compile_time_version_string(package)
SV *package = NO_INIT
CODE:
(void)package;
RETVAL = CMARK_VERSION_STRING;
OUTPUT:
RETVAL
MODULE = CommonMark PACKAGE = CommonMark::Node PREFIX = cmark_node_
cmark_node*
new(package, type)
SV *package = NO_INIT
cmark_node_type type
CODE:
(void)package;
RETVAL = cmark_node_new(type);
OUTPUT:
RETVAL
void
DESTROY(cmark_node *node)
CODE:
cmark_node *parent = cmark_node_parent(node);
if (parent) {
cmark_node_set_user_data(node, NULL);
S_decref_node_sv(aTHX_ parent);
}
else {
cmark_node_free(node);
}
cmark_iter*
iterator(cmark_node *node)
CODE:
S_create_or_incref_node_sv(aTHX_ node);
RETVAL = cmark_iter_new(node);
OUTPUT:
RETVAL
cmark_node*
interface_get_node(cmark_node *node)
INTERFACE:
cmark_node_next
cmark_node_previous
cmark_node_parent
cmark_node_first_child
cmark_node_last_child
int
interface_get_int(cmark_node *node)
INTERFACE:
cmark_node_get_type
cmark_node_get_header_level
cmark_node_get_list_type
cmark_node_get_list_delim
cmark_node_get_list_start
cmark_node_get_list_tight
cmark_node_get_start_line
cmark_node_get_start_column
cmark_node_get_end_line
cmark_node_get_end_column
NO_OUTPUT int
interface_set_int(cmark_node *node, int value)
INTERFACE:
cmark_node_set_header_level
cmark_node_set_list_type
cmark_node_set_list_delim
cmark_node_set_list_start
cmark_node_set_list_tight
POSTCALL:
if (!RETVAL) {
croak("%s: invalid operation", GvNAME(CvGV(cv)));
}
const char*
interface_get_utf8(cmark_node *node)
INTERFACE:
cmark_node_get_type_string
cmark_node_get_literal
cmark_node_get_title
cmark_node_get_url
cmark_node_get_fence_info
NO_OUTPUT int
interface_set_utf8(cmark_node *node, const char *value)
INTERFACE:
cmark_node_set_literal
cmark_node_set_title
cmark_node_set_url
cmark_node_set_fence_info
POSTCALL:
if (!RETVAL) {
croak("%s: invalid operation", GvNAME(CvGV(cv)));
}
void
cmark_node_unlink(cmark_node *node)
PREINIT:
cmark_node *old_parent;
INIT:
old_parent = cmark_node_parent(node);
POSTCALL:
S_decref_node_sv(aTHX_ old_parent);
NO_OUTPUT int
interface_move_node(cmark_node *node, cmark_node *other)
PREINIT:
cmark_node *old_parent;
cmark_node *new_parent;
INIT:
old_parent = cmark_node_parent(other);
INTERFACE:
cmark_node_insert_before
cmark_node_insert_after
cmark_node_prepend_child
cmark_node_append_child
POSTCALL:
if (!RETVAL) {
croak("%s: invalid operation", GvNAME(CvGV(cv)));
}
new_parent = cmark_node_parent(other);
S_transfer_refcount(aTHX_ old_parent, new_parent);
char*
interface_render(cmark_node *root, long options = 0)
INTERFACE:
cmark_node_render_html
cmark_node_render_xml
cmark_node_render_man
MODULE = CommonMark PACKAGE = CommonMark::Iterator PREFIX = cmark_iter_
void
DESTROY(cmark_iter *iter)
CODE:
S_decref_node_sv(aTHX_ cmark_iter_get_node(iter));
S_decref_node_sv(aTHX_ cmark_iter_get_root(iter));
cmark_iter_free(iter);
void
cmark_iter_next(cmark_iter *iter)
PREINIT:
I32 gimme;
cmark_node *old_node;
cmark_event_type ev_type;
PPCODE:
gimme = GIMME_V;
old_node = cmark_iter_get_node(iter);
ev_type = cmark_iter_next(iter);
if (ev_type != CMARK_EVENT_DONE) {
cmark_node *node = cmark_iter_get_node(iter);
ST(0) = sv_2mortal(newSViv((IV)ev_type));
if (gimme == G_ARRAY) {
SV *obj = S_create_or_incref_node_sv(aTHX_ node);
/* A bit more efficient than S_transfer_refcount. */
if (old_node != node) {
S_decref_node_sv(aTHX_ old_node);
SvREFCNT_inc_simple_void_NN(obj);
}
ST(1) = sv_2mortal(newRV_noinc(obj));
XSRETURN(2);
}
else {
S_transfer_refcount(aTHX_ old_node, node);
XSRETURN(1);
}
}
else {
S_decref_node_sv(aTHX_ old_node);
if (gimme == G_ARRAY) {
XSRETURN_EMPTY;
}
else {
ST(0) = sv_2mortal(newSViv((IV)ev_type));
XSRETURN(1);
}
}
cmark_node*
cmark_iter_get_node(cmark_iter *iter)
cmark_event_type
cmark_iter_get_event_type(cmark_iter *iter)
void
cmark_iter_reset(iter, node, event_type)
cmark_iter *iter
cmark_node *node
cmark_event_type event_type
PREINIT:
cmark_node *old_node;
INIT:
old_node = cmark_iter_get_node(iter);
S_transfer_refcount(aTHX_ old_node, node);
MODULE = CommonMark PACKAGE = CommonMark::Parser PREFIX = cmark_parser_
cmark_parser*
cmark_parser_new(package)
SV *package = NO_INIT
CODE:
(void)package;
RETVAL = cmark_parser_new();
OUTPUT:
RETVAL
void
DESTROY(cmark_parser *parser)
CODE:
cmark_parser_free(parser);
void
cmark_parser_feed(cmark_parser *parser, SV *string)
PREINIT:
STRLEN len;
const char *buffer;
CODE:
buffer = SvPVutf8(string, len);
cmark_parser_feed(parser, buffer, len);
cmark_node*
cmark_parser_finish(cmark_parser *parser)

View File

@@ -258,7 +258,7 @@ My name is wisp!"
;; evaluating the reference to the value of the corresponding variable.
foo
;; If you wish to refer to the literal symbol, rather then reference you
;; If you wish to refer to the literal symbol, rather than reference you
;; could use
(quote foo)
;; or more usually

View File

@@ -5,6 +5,8 @@ set -ex
# Fetch all commits/refs needed to run our tests.
git fetch origin master:master v2.0.0:v2.0.0 test/attributes:test/attributes test/master:test/master
sudo apt-get update
script/vendor-deb libicu48 libicu-dev
if ruby -e 'exit RUBY_VERSION >= "2.0" && RUBY_VERSION < "2.1"'; then
# Workaround for https://bugs.ruby-lang.org/issues/8074. We can't use this

1304
tei-odd-sample.odd Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
// -*- fundamental -*-
int main(int argc, char * argc[])
{
this should not be syntax highlighted, even though it looks like c.
}

View File

@@ -0,0 +1,2 @@
// -*-c++-*-
template <typename X> class { X i; };

View File

@@ -0,0 +1,2 @@
// -*- c++ -*-
template <typename X> class { X i; };

View File

@@ -0,0 +1,2 @@
// -*- mode:C++ -*-
template <typename X> class { X i; };

View File

@@ -0,0 +1,2 @@
// -*- font:bar;mode:c++ -*-
template <typename X> class { X i; };

Some files were not shown because too many files have changed in this diff Show More