gitlab-pygments.rb 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (399) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +2 -0
  3. data/README.md +91 -0
  4. data/Rakefile +78 -0
  5. data/bench.rb +22 -0
  6. data/cache-lexers.rb +8 -0
  7. data/lexers +0 -0
  8. data/lib/pygments/lexer.rb +148 -0
  9. data/lib/pygments/mentos.py +344 -0
  10. data/lib/pygments/popen.rb +389 -0
  11. data/lib/pygments/version.rb +3 -0
  12. data/lib/pygments.rb +8 -0
  13. data/pygments.rb.gemspec +24 -0
  14. data/test/test_data.c +2581 -0
  15. data/test/test_data.py +514 -0
  16. data/test/test_data_generated +2582 -0
  17. data/test/test_pygments.rb +276 -0
  18. data/vendor/custom_formatters/gitlab.py +171 -0
  19. data/vendor/custom_lexers/github.py +362 -0
  20. data/vendor/pygments-main/AUTHORS +115 -0
  21. data/vendor/pygments-main/CHANGES +762 -0
  22. data/vendor/pygments-main/LICENSE +25 -0
  23. data/vendor/pygments-main/MANIFEST.in +6 -0
  24. data/vendor/pygments-main/Makefile +59 -0
  25. data/vendor/pygments-main/REVISION +1 -0
  26. data/vendor/pygments-main/TODO +15 -0
  27. data/vendor/pygments-main/docs/generate.py +472 -0
  28. data/vendor/pygments-main/docs/pygmentize.1 +94 -0
  29. data/vendor/pygments-main/docs/src/api.txt +270 -0
  30. data/vendor/pygments-main/docs/src/authors.txt +5 -0
  31. data/vendor/pygments-main/docs/src/changelog.txt +5 -0
  32. data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
  33. data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
  34. data/vendor/pygments-main/docs/src/filters.txt +42 -0
  35. data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
  36. data/vendor/pygments-main/docs/src/formatters.txt +48 -0
  37. data/vendor/pygments-main/docs/src/index.txt +69 -0
  38. data/vendor/pygments-main/docs/src/installation.txt +71 -0
  39. data/vendor/pygments-main/docs/src/integrate.txt +43 -0
  40. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
  41. data/vendor/pygments-main/docs/src/lexers.txt +67 -0
  42. data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
  43. data/vendor/pygments-main/docs/src/plugins.txt +93 -0
  44. data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
  45. data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
  46. data/vendor/pygments-main/docs/src/styles.txt +143 -0
  47. data/vendor/pygments-main/docs/src/tokens.txt +349 -0
  48. data/vendor/pygments-main/docs/src/unicode.txt +49 -0
  49. data/vendor/pygments-main/external/markdown-processor.py +67 -0
  50. data/vendor/pygments-main/external/moin-parser.py +112 -0
  51. data/vendor/pygments-main/external/pygments.bashcomp +38 -0
  52. data/vendor/pygments-main/external/rst-directive-old.py +77 -0
  53. data/vendor/pygments-main/external/rst-directive.py +83 -0
  54. data/vendor/pygments-main/ez_setup.py +276 -0
  55. data/vendor/pygments-main/pygmentize +7 -0
  56. data/vendor/pygments-main/pygments/__init__.py +91 -0
  57. data/vendor/pygments-main/pygments/cmdline.py +433 -0
  58. data/vendor/pygments-main/pygments/console.py +74 -0
  59. data/vendor/pygments-main/pygments/filter.py +74 -0
  60. data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
  61. data/vendor/pygments-main/pygments/formatter.py +92 -0
  62. data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
  63. data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
  64. data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
  65. data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
  66. data/vendor/pygments-main/pygments/formatters/html.py +750 -0
  67. data/vendor/pygments-main/pygments/formatters/img.py +553 -0
  68. data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
  69. data/vendor/pygments-main/pygments/formatters/other.py +117 -0
  70. data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
  71. data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
  72. data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
  73. data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
  74. data/vendor/pygments-main/pygments/lexer.py +697 -0
  75. data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
  76. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
  77. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
  78. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
  79. data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
  80. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
  81. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
  82. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
  83. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
  84. data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
  85. data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
  86. data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
  87. data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
  88. data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
  89. data/vendor/pygments-main/pygments/lexers/github.py +362 -0
  90. data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
  91. data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
  92. data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
  93. data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
  94. data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
  95. data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
  96. data/vendor/pygments-main/pygments/lexers/special.py +100 -0
  97. data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
  98. data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
  99. data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
  100. data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
  101. data/vendor/pygments-main/pygments/plugin.py +74 -0
  102. data/vendor/pygments-main/pygments/scanner.py +104 -0
  103. data/vendor/pygments-main/pygments/style.py +117 -0
  104. data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
  105. data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
  106. data/vendor/pygments-main/pygments/styles/borland.py +51 -0
  107. data/vendor/pygments-main/pygments/styles/bw.py +49 -0
  108. data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
  109. data/vendor/pygments-main/pygments/styles/default.py +73 -0
  110. data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
  111. data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
  112. data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
  113. data/vendor/pygments-main/pygments/styles/manni.py +75 -0
  114. data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
  115. data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
  116. data/vendor/pygments-main/pygments/styles/native.py +65 -0
  117. data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
  118. data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
  119. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  120. data/vendor/pygments-main/pygments/styles/tango.py +141 -0
  121. data/vendor/pygments-main/pygments/styles/trac.py +63 -0
  122. data/vendor/pygments-main/pygments/styles/vim.py +63 -0
  123. data/vendor/pygments-main/pygments/styles/vs.py +38 -0
  124. data/vendor/pygments-main/pygments/token.py +195 -0
  125. data/vendor/pygments-main/pygments/unistring.py +130 -0
  126. data/vendor/pygments-main/pygments/util.py +232 -0
  127. data/vendor/pygments-main/scripts/check_sources.py +242 -0
  128. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
  129. data/vendor/pygments-main/scripts/epydoc.css +280 -0
  130. data/vendor/pygments-main/scripts/find_codetags.py +205 -0
  131. data/vendor/pygments-main/scripts/find_error.py +171 -0
  132. data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
  133. data/vendor/pygments-main/scripts/pylintrc +301 -0
  134. data/vendor/pygments-main/scripts/reindent.py +291 -0
  135. data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
  136. data/vendor/pygments-main/setup.cfg +6 -0
  137. data/vendor/pygments-main/setup.py +88 -0
  138. data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
  139. data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
  140. data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
  141. data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
  142. data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
  143. data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
  144. data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
  145. data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
  146. data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
  147. data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
  148. data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
  149. data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
  150. data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
  151. data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
  152. data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
  153. data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
  154. data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
  155. data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
  156. data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
  157. data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
  158. data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
  159. data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
  160. data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
  161. data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
  162. data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
  163. data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
  164. data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
  165. data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
  166. data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
  167. data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
  168. data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
  169. data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
  170. data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
  171. data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
  172. data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
  173. data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
  174. data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
  175. data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
  176. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  177. data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
  178. data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
  179. data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
  180. data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
  181. data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
  182. data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
  183. data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
  184. data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
  185. data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
  186. data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
  187. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  188. data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
  189. data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
  190. data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
  191. data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
  192. data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
  193. data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
  194. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  195. data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
  196. data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
  197. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  198. data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
  199. data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
  200. data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
  201. data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
  202. data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
  203. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  204. data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
  205. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  206. data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
  207. data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
  208. data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
  209. data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
  210. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  211. data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
  212. data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
  213. data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
  214. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  215. data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
  216. data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
  217. data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
  218. data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
  219. data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
  220. data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
  221. data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
  222. data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
  223. data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
  224. data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
  225. data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
  226. data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
  227. data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
  228. data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
  229. data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
  230. data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
  231. data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
  232. data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
  233. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  234. data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
  235. data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
  236. data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
  237. data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
  238. data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
  239. data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
  240. data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
  241. data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
  242. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  243. data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
  244. data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
  245. data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
  246. data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
  247. data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
  248. data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
  249. data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
  250. data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
  251. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
  252. data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
  253. data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
  254. data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
  255. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
  256. data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
  257. data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
  258. data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
  259. data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
  260. data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
  261. data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
  262. data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
  263. data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
  264. data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
  265. data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
  266. data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
  267. data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
  268. data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
  269. data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
  270. data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
  271. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
  272. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
  273. data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
  274. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  275. data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
  276. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  277. data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
  278. data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
  279. data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
  280. data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
  281. data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
  282. data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
  283. data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
  284. data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
  285. data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
  286. data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
  287. data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
  288. data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
  289. data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
  290. data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
  291. data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
  292. data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
  293. data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
  294. data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
  295. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  296. data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
  297. data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
  298. data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
  299. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  300. data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
  301. data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
  302. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  303. data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
  304. data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
  305. data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
  306. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  307. data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
  308. data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
  309. data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
  310. data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
  311. data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
  312. data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
  313. data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
  314. data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
  315. data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
  316. data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
  317. data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
  318. data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
  319. data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
  320. data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
  321. data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
  322. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  323. data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
  324. data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
  325. data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
  326. data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
  327. data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
  328. data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
  329. data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
  330. data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
  331. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  332. data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
  333. data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
  334. data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
  335. data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
  336. data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
  337. data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
  338. data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
  339. data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
  340. data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
  341. data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
  342. data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
  343. data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
  344. data/vendor/pygments-main/tests/old_run.py +138 -0
  345. data/vendor/pygments-main/tests/run.py +48 -0
  346. data/vendor/pygments-main/tests/support.py +15 -0
  347. data/vendor/pygments-main/tests/test_basic_api.py +294 -0
  348. data/vendor/pygments-main/tests/test_clexer.py +31 -0
  349. data/vendor/pygments-main/tests/test_cmdline.py +105 -0
  350. data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
  351. data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
  352. data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
  353. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  354. data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
  355. data/vendor/pygments-main/tests/test_token.py +46 -0
  356. data/vendor/pygments-main/tests/test_using_api.py +40 -0
  357. data/vendor/pygments-main/tests/test_util.py +116 -0
  358. data/vendor/simplejson/.gitignore +10 -0
  359. data/vendor/simplejson/.travis.yml +5 -0
  360. data/vendor/simplejson/CHANGES.txt +291 -0
  361. data/vendor/simplejson/LICENSE.txt +19 -0
  362. data/vendor/simplejson/MANIFEST.in +5 -0
  363. data/vendor/simplejson/README.rst +19 -0
  364. data/vendor/simplejson/conf.py +179 -0
  365. data/vendor/simplejson/index.rst +628 -0
  366. data/vendor/simplejson/scripts/make_docs.py +18 -0
  367. data/vendor/simplejson/setup.py +104 -0
  368. data/vendor/simplejson/simplejson/__init__.py +510 -0
  369. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  370. data/vendor/simplejson/simplejson/decoder.py +425 -0
  371. data/vendor/simplejson/simplejson/encoder.py +567 -0
  372. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  373. data/vendor/simplejson/simplejson/scanner.py +77 -0
  374. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  375. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  376. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  377. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  378. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  379. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  380. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  381. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  382. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  383. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  384. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  385. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  386. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  387. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  388. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  389. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  390. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  391. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  392. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  393. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  394. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  395. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  396. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  397. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  398. data/vendor/simplejson/simplejson/tool.py +39 -0
  399. metadata +492 -0
@@ -0,0 +1,166 @@
1
+ <%doc>formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters.</%doc>
2
+
3
+ <%global>
4
+ import string, re
5
+ import highlight
6
+ </%global>
7
+
8
+ <%method section>
9
+ <%doc>Main section formatting element.</%doc>
10
+ <%args>
11
+ toc
12
+ path
13
+ description=None
14
+ onepage=False
15
+ </%args>
16
+ <%init>
17
+ item = toc.get_by_path(path)
18
+ if item is None:
19
+ raise "path: " + path
20
+ </%init>
21
+
22
+ <A name="<% item.path %>"></a>
23
+
24
+ <div class="subsection" style="margin-left:<% repr(item.depth * 10) %>px;">
25
+
26
+ <%python>
27
+ content = m.content()
28
+ re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S)
29
+ content = re2.sub(lambda m: m.group(1), content)
30
+ </%python>
31
+
32
+ % if item.depth > 1:
33
+ <h3><% description or item.description %></h3>
34
+ %
35
+
36
+ <div class="sectiontext">
37
+ <% content %>
38
+ </div>
39
+
40
+ % if onepage or item.depth > 1:
41
+ % if (item.next and item.next.depth >= item.depth):
42
+ <a href="#<% item.get_page_root().path %>" class="toclink">back to section top</a>
43
+ %
44
+ % else:
45
+ <a href="#<% item.get_page_root().path %>" class="toclink">back to section top</a>
46
+ <& nav.myt:pagenav, item=item, onepage=onepage &>
47
+ %
48
+ </div>
49
+
50
+ </%method>
51
+
52
+
53
+ <%method formatplain>
54
+ <%filter>
55
+ import re
56
+ f = re.sub(r'\n[\s\t]*\n[\s\t]*', '</p>\n<p>', f)
57
+ f = "<p>" + f + "</p>"
58
+ return f
59
+ </%filter>
60
+ <% m.content() | h%>
61
+ </%method>
62
+
63
+
64
+
65
+
66
+ <%method codeline trim="both">
67
+ <span class="codeline"><% m.content() %></span>
68
+ </%method>
69
+
70
+ <%method code autoflush=False>
71
+ <%args>
72
+ title = None
73
+ syntaxtype = 'python'
74
+ html_escape = False
75
+ use_sliders = False
76
+ </%args>
77
+
78
+ <%init>
79
+ def fix_indent(f):
80
+ f =string.expandtabs(f, 4)
81
+ g = ''
82
+ lines = string.split(f, "\n")
83
+ whitespace = None
84
+ for line in lines:
85
+ if whitespace is None:
86
+ match = re.match(r"^([ ]*).+", line)
87
+ if match is not None:
88
+ whitespace = match.group(1)
89
+
90
+ if whitespace is not None:
91
+ line = re.sub(r"^%s" % whitespace, "", line)
92
+
93
+ if whitespace is not None or re.search(r"\w", line) is not None:
94
+ g += (line + "\n")
95
+
96
+
97
+ return g.rstrip()
98
+
99
+ p = re.compile(r'<pre>(.*?)</pre>', re.S)
100
+ def hlight(match):
101
+ return "<pre>" + highlight.highlight(fix_indent(match.group(1)), html_escape = html_escape, syntaxtype = syntaxtype) + "</pre>"
102
+ content = p.sub(hlight, "<pre>" + m.content() + "</pre>")
103
+ </%init>
104
+ <div class="<% use_sliders and "sliding_code" or "code" %>">
105
+ % if title is not None:
106
+ <div class="codetitle"><% title %></div>
107
+ %
108
+ <% content %></div>
109
+ </%method>
110
+
111
+
112
+
113
+
114
+ <%method popboxlink trim="both">
115
+ <%args>
116
+ name=None
117
+ show='show'
118
+ hide='hide'
119
+ </%args>
120
+ <%init>
121
+ if name is None:
122
+ name = m.attributes.setdefault('popbox_name', 0)
123
+ name += 1
124
+ m.attributes['popbox_name'] = name
125
+ name = "popbox_" + repr(name)
126
+ </%init>
127
+ javascript:togglePopbox('<% name %>', '<% show %>', '<% hide %>')
128
+ </%method>
129
+
130
+ <%method popbox trim="both">
131
+ <%args>
132
+ name = None
133
+ class_ = None
134
+ </%args>
135
+ <%init>
136
+ if name is None:
137
+ name = 'popbox_' + repr(m.attributes['popbox_name'])
138
+ </%init>
139
+ <div id="<% name %>_div" class="<% class_ %>" style="display:none;"><% m.content().strip() %></div>
140
+ </%method>
141
+
142
+ <%method poplink trim="both">
143
+ <%args>
144
+ link='sql'
145
+ </%args>
146
+ <%init>
147
+ href = m.scomp('SELF:popboxlink')
148
+ </%init>
149
+ '''PYESC<& nav.myt:link, href=href, text=link, class_="codepoplink" &>PYESC'''
150
+ </%method>
151
+
152
+ <%method codepopper trim="both">
153
+ <%init>
154
+ c = m.content()
155
+ c = re.sub(r'\n', '<br/>\n', c.strip())
156
+ </%init>
157
+ </pre><&|SELF:popbox, class_="codepop" &><% c %></&><pre>
158
+ </%method>
159
+
160
+ <%method poppedcode trim="both">
161
+ <%init>
162
+ c = m.content()
163
+ c = re.sub(r'\n', '<br/>\n', c.strip())
164
+ </%init>
165
+ </pre><div class="codepop"><% c %></div><pre>
166
+ </%method>
@@ -0,0 +1,93 @@
1
+ import re
2
+
3
+ for x in lines("myfile.txt"):
4
+ if x =~ re"(\w+)=(.*)":
5
+ echo "Key: ", matches[0],
6
+ " Value: ", matches[1]
7
+
8
+ Echo("What's your name? ")
9
+ var name: string = readLine(stdin)
10
+ if name == "":
11
+ echo("Poor soul, you lost your name?")
12
+ elif name == "name":
13
+ echo("Very funny, your name is name.")
14
+ else:
15
+ Echo("Hi, ", name, "!")
16
+
17
+ var name = readLine(stdin)
18
+ case name
19
+ of "":
20
+ echo("Poor soul, you lost your name?")
21
+ of "name":
22
+ echo("Very funny, your name is name.")
23
+ else:
24
+ Echo("Hi, ", name, "!")
25
+
26
+ from strutils import parseInt
27
+
28
+ Echo("A number please: ")
29
+ var n = parseInt(readLine(stdin))
30
+ case n
31
+ of 0..2, 4..7: Echo("The number is in the set: {0, 1, 2, 4, 5, 6, 7}")
32
+ of 3, 8: Echo("The number is 3 or 8")
33
+
34
+ Echo("Counting to 10: ")
35
+ var i = 1
36
+ while i <= 10:
37
+ Echo($i)
38
+ inc(i)
39
+
40
+ proc yes(question: string): bool =
41
+ Echo(question, " (y/n)")
42
+ while true:
43
+ case readLine(stdin)
44
+ of "y", "Y", "yes", "Yes": return true
45
+ of "n", "N", "no", "No": return false
46
+ else: Echo("Please be clear: yes or no")
47
+
48
+ proc even(n: int): bool
49
+
50
+ proc odd(n: int): bool =
51
+ if n == 1: return true
52
+ else: return even(n-1)
53
+
54
+ iterator countup(a, b: int): int =
55
+ var res = a
56
+ while res <= b:
57
+ yield res
58
+ inc(res)
59
+
60
+ type
61
+ TPerson = object of TObject
62
+ name*: string # the * means that `name` is accessible from other modules
63
+ age: int # no * means that the field is hidden from other modules
64
+
65
+ TStudent = object of TPerson # TStudent inherits from TPerson
66
+ id: int # with an id field
67
+
68
+ var
69
+ student: TStudent
70
+ person: TPerson
71
+ assert(student is TStudent)
72
+
73
+ echo({'a', 'b', 'c'}.card)
74
+ stdout.writeln("Hallo")
75
+ var
76
+ f: TFile
77
+ if open(f, "numbers.txt"):
78
+ try:
79
+ var a = readLine(f)
80
+ var b = readLine(f)
81
+ echo("sum: " & $(parseInt(a) + parseInt(b)))
82
+ except EOverflow:
83
+ echo("overflow!")
84
+ except EInvalidValue:
85
+ echo("could not convert string to integer")
86
+ except EIO:
87
+ echo("IO error!")
88
+ except:
89
+ echo("Unknown exception!")
90
+ # reraise the unknown exception:
91
+ raise
92
+ finally:
93
+ close(f)
@@ -0,0 +1,743 @@
1
+ //
2
+ // Sourcecode from http://www.delphi-library.de/topic_47880.html
3
+ //
4
+ uses Windows, Messages;
5
+
6
+ const
7
+ FFM_INIT = WM_USER + 1976;
8
+ FFM_ONFILEFOUND = WM_USER + 1974; // wParam: not used, lParam: Filename
9
+ FFM_ONDIRFOUND = WM_USER + 1975; // wParam: NumFolder, lParam: Directory
10
+ var
11
+ CntFolders : Cardinal = 0;
12
+ NumFolder : Cardinal = 0;
13
+
14
+
15
+ ////////////////////////////////////////////////////////////////////////////////
16
+ //
17
+ // FindAllFilesInit
18
+ //
19
+ //
20
+ procedure FindAllFilesInit; external;
21
+ label foo;
22
+ begin
23
+ CntFolders := 0;
24
+ NumFolder := 0;
25
+ foo:
26
+ Blub;
27
+ goto foo;
28
+ end;
29
+
30
+ ////////////////////////////////////////////////////////////////////////////////
31
+ //
32
+ // CountFolders
33
+ //
34
+ //
35
+ procedure CountFolders(Handle: THandle; RootFolder: string; Recurse: Boolean = True);
36
+ var
37
+ hFindFile : THandle;
38
+ wfd : TWin32FindData;
39
+ begin
40
+ SendMessage(Handle, FFM_INIT, 0, 0);
41
+ if RootFolder[length(RootFolder)] <> '\' then
42
+ RootFolder := RootFolder + '\';
43
+ ZeroMemory(@wfd, sizeof(wfd));
44
+ wfd.dwFileAttributes := FILE_ATTRIBUTE_NORMAL;
45
+ if Recurse then
46
+ begin
47
+ hFindFile := FindFirstFile(pointer(RootFolder + '*.*'), wfd);
48
+ if hFindFile <> 0 then
49
+ try
50
+ repeat
51
+ if wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY then
52
+ begin
53
+ if (string(wfd.cFileName) <> '.') and (string(wfd.cFileName) <> '..') then
54
+ begin
55
+ CountFolders(Handle, RootFolder + wfd.cFileName, Recurse);
56
+ end;
57
+ end;
58
+ until FindNextFile(hFindFile, wfd) = False;
59
+ Inc(CntFolders);
60
+ finally
61
+ Windows.FindClose(hFindFile);
62
+ end;
63
+ end;
64
+ end;
65
+
66
+ ////////////////////////////////////////////////////////////////////////////////
67
+ //
68
+ // FindAllFiles
69
+ //
70
+ procedure FindAllFiles(Handle: THandle; RootFolder: string; Mask: string; Recurse: Boolean = True);
71
+ var
72
+ hFindFile : THandle;
73
+ wfd : TWin32FindData;
74
+ begin
75
+ if RootFolder[length(RootFolder)] <> '\' then
76
+ RootFolder := RootFolder + '\';
77
+ ZeroMemory(@wfd, sizeof(wfd));
78
+ wfd.dwFileAttributes := FILE_ATTRIBUTE_NORMAL;
79
+ if Recurse then
80
+ begin
81
+ hFindFile := FindFirstFile(pointer(RootFolder + '*.*'), wfd);
82
+ if hFindFile <> 0 then
83
+ try
84
+ repeat
85
+ if wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY then
86
+ begin
87
+ if (string(wfd.cFileName) <> '.') and (string(wfd.cFileName) <> '..') then
88
+ begin
89
+ FindAllFiles(Handle, RootFolder + wfd.cFileName, Mask, Recurse);
90
+ end;
91
+ end;
92
+ until FindNextFile(hFindFile, wfd) = False;
93
+ Inc(NumFolder);
94
+ SendMessage(Handle, FFM_ONDIRFOUND, NumFolder, lParam(string(RootFolder)));
95
+ finally
96
+ Windows.FindClose(hFindFile);
97
+ end;
98
+ end;
99
+ hFindFile := FindFirstFile(pointer(RootFolder + Mask), wfd);
100
+ if hFindFile <> INVALID_HANDLE_VALUE then
101
+ try
102
+ repeat
103
+ if (wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY <> FILE_ATTRIBUTE_DIRECTORY) then
104
+ begin
105
+ SendMessage(Handle, FFM_ONFILEFOUND, 0, lParam(string(RootFolder + wfd.cFileName)));
106
+ end;
107
+ until FindNextFile(hFindFile, wfd) = False;
108
+ finally
109
+ Windows.FindClose(hFindFile);
110
+ end;
111
+ end;
112
+
113
+
114
+ property test: boolean read ftest write ftest;
115
+ procedure test: boolean read ftest write ftest;
116
+
117
+ //
118
+ // This sourcecode is part of omorphia
119
+ //
120
+
121
+ Function IsValidHandle(Const Handle: THandle): Boolean; {$IFDEF OMORPHIA_FEATURES_USEASM} Assembler;
122
+ Asm
123
+ TEST EAX, EAX
124
+ JZ @@Finish
125
+ NOT EAX
126
+ TEST EAX, EAX
127
+ SETNZ AL
128
+
129
+ {$IFDEF WINDOWS}
130
+ JZ @@Finish
131
+
132
+ //Save the handle against modifications or loss
133
+ PUSH EAX
134
+
135
+ //reserve some space for a later duplicate
136
+ PUSH EAX
137
+
138
+ //Check if we are working on NT-Platform
139
+ CALL IsWindowsNTSystem
140
+ TEST EAX, EAX
141
+ JZ @@NoNTSystem
142
+
143
+ PUSH DWORD PTR [ESP]
144
+ LEA EAX, DWORD PTR [ESP+$04]
145
+ PUSH EAX
146
+ CALL GetHandleInformation
147
+ TEST EAX, EAX
148
+ JNZ @@Finish2
149
+
150
+ @@NoNTSystem:
151
+ //Result := DuplicateHandle(GetCurrentProcess, Handle, GetCurrentProcess,
152
+ // @Duplicate, 0, False, DUPLICATE_SAME_ACCESS);
153
+ PUSH DUPLICATE_SAME_ACCESS
154
+ PUSH $00000000
155
+ PUSH $00000000
156
+ LEA EAX, DWORD PTR [ESP+$0C]
157
+ PUSH EAX
158
+ CALL GetCurrentProcess
159
+ PUSH EAX
160
+ PUSH DWORD PTR [ESP+$18]
161
+ PUSH EAX
162
+ CALL DuplicateHandle
163
+
164
+ TEST EAX, EAX
165
+ JZ @@Finish2
166
+
167
+ // Result := CloseHandle(Duplicate);
168
+ PUSH DWORD PTR [ESP]
169
+ CALL CloseHandle
170
+
171
+ @@Finish2:
172
+ POP EDX
173
+ POP EDX
174
+
175
+ PUSH EAX
176
+ PUSH $00000000
177
+ CALL SetLastError
178
+ POP EAX
179
+ {$ENDIF}
180
+
181
+ @@Finish:
182
+ End;
183
+ {$ELSE}
184
+ Var
185
+ Duplicate: THandle;
186
+ Flags: DWORD;
187
+ Begin
188
+ If IsWinNT Then
189
+ Result := GetHandleInformation(Handle, Flags)
190
+ Else
191
+ Result := False;
192
+ If Not Result Then
193
+ Begin
194
+ // DuplicateHandle is used as an additional check for those object types not
195
+ // supported by GetHandleInformation (e.g. according to the documentation,
196
+ // GetHandleInformation doesn't support window stations and desktop although
197
+ // tests show that it does). GetHandleInformation is tried first because its
198
+ // much faster. Additionally GetHandleInformation is only supported on NT...
199
+ Result := DuplicateHandle(GetCurrentProcess, Handle, GetCurrentProcess,
200
+ @Duplicate, 0, False, DUPLICATE_SAME_ACCESS);
201
+ If Result Then
202
+ Result := CloseHandle(Duplicate);
203
+ End;
204
+ End;
205
+ {$ENDIF}
206
+
207
+
208
+
209
+
210
+ {*******************************************************}
211
+ { }
212
+ { Delphi Supplemental Components }
213
+ { ZLIB Data Compression Interface Unit }
214
+ { }
215
+ { Copyright (c) 1997 Borland International }
216
+ { }
217
+ {*******************************************************}
218
+
219
+ { Modified for zlib 1.1.3 by Davide Moretti <dave@rimini.com }
220
+
221
+ unit zlib;
222
+
223
+ interface
224
+
225
+ uses Sysutils, Classes;
226
+
227
+ type
228
+ TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer;
229
+ TFree = procedure (AppData, Block: Pointer);
230
+
231
+ // Internal structure. Ignore.
232
+ TZStreamRec = packed record
233
+ next_in: PChar; // next input byte
234
+ avail_in: Integer; // number of bytes available at next_in
235
+ total_in: Integer; // total nb of input bytes read so far
236
+
237
+ next_out: PChar; // next output byte should be put here
238
+ avail_out: Integer; // remaining free space at next_out
239
+ total_out: Integer; // total nb of bytes output so far
240
+
241
+ msg: PChar; // last error message, NULL if no error
242
+ internal: Pointer; // not visible by applications
243
+
244
+ zalloc: TAlloc; // used to allocate the internal state
245
+ zfree: TFree; // used to free the internal state
246
+ AppData: Pointer; // private data object passed to zalloc and zfree
247
+
248
+ data_type: Integer; // best guess about the data type: ascii or binary
249
+ adler: Integer; // adler32 value of the uncompressed data
250
+ reserved: Integer; // reserved for future use
251
+ end;
252
+
253
+ // Abstract ancestor class
254
+ TCustomZlibStream = class(TStream)
255
+ private
256
+ FStrm: TStream;
257
+ FStrmPos: Integer;
258
+ FOnProgress: TNotifyEvent;
259
+ FZRec: TZStreamRec;
260
+ FBuffer: array [Word] of Char;
261
+ protected
262
+ procedure Progress(Sender: TObject); dynamic;
263
+ property OnProgress: TNotifyEvent read FOnProgress write FOnProgress;
264
+ constructor Create(Strm: TStream);
265
+ end;
266
+
267
+ { TCompressionStream compresses data on the fly as data is written to it, and
268
+ stores the compressed data to another stream.
269
+
270
+ TCompressionStream is write-only and strictly sequential. Reading from the
271
+ stream will raise an exception. Using Seek to move the stream pointer
272
+ will raise an exception.
273
+
274
+ Output data is cached internally, written to the output stream only when
275
+ the internal output buffer is full. All pending output data is flushed
276
+ when the stream is destroyed.
277
+
278
+ The Position property returns the number of uncompressed bytes of
279
+ data that have been written to the stream so far.
280
+
281
+ CompressionRate returns the on-the-fly percentage by which the original
282
+ data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100
283
+ If raw data size = 100 and compressed data size = 25, the CompressionRate
284
+ is 75%
285
+
286
+ The OnProgress event is called each time the output buffer is filled and
287
+ written to the output stream. This is useful for updating a progress
288
+ indicator when you are writing a large chunk of data to the compression
289
+ stream in a single call.}
290
+
291
+
292
+ TCompressionLevel = (clNone, clFastest, clDefault, clMax);
293
+
294
+ TCompressionStream = class(TCustomZlibStream)
295
+ private
296
+ function GetCompressionRate: Single;
297
+ public
298
+ constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream);
299
+ destructor Destroy; override;
300
+ function Read(var Buffer; Count: Longint): Longint; override;
301
+ function Write(const Buffer; Count: Longint): Longint; override;
302
+ function Seek(Offset: Longint; Origin: Word): Longint; override;
303
+ property CompressionRate: Single read GetCompressionRate;
304
+ property OnProgress;
305
+ end;
306
+
307
+ { TDecompressionStream decompresses data on the fly as data is read from it.
308
+
309
+ Compressed data comes from a separate source stream. TDecompressionStream
310
+ is read-only and unidirectional; you can seek forward in the stream, but not
311
+ backwards. The special case of setting the stream position to zero is
312
+ allowed. Seeking forward decompresses data until the requested position in
313
+ the uncompressed data has been reached. Seeking backwards, seeking relative
314
+ to the end of the stream, requesting the size of the stream, and writing to
315
+ the stream will raise an exception.
316
+
317
+ The Position property returns the number of bytes of uncompressed data that
318
+ have been read from the stream so far.
319
+
320
+ The OnProgress event is called each time the internal input buffer of
321
+ compressed data is exhausted and the next block is read from the input stream.
322
+ This is useful for updating a progress indicator when you are reading a
323
+ large chunk of data from the decompression stream in a single call.}
324
+
325
+ TDecompressionStream = class(TCustomZlibStream)
326
+ public
327
+ constructor Create(Source: TStream);
328
+ destructor Destroy; override;
329
+ function Read(var Buffer; Count: Longint): Longint; override;
330
+ function Write(const Buffer; Count: Longint): Longint; override;
331
+ function Seek(Offset: Longint; Origin: Word): Longint; override;
332
+ property OnProgress;
333
+ end;
334
+
335
+
336
+
337
+ { CompressBuf compresses data, buffer to buffer, in one call.
338
+ In: InBuf = ptr to compressed data
339
+ InBytes = number of bytes in InBuf
340
+ Out: OutBuf = ptr to newly allocated buffer containing decompressed data
341
+ OutBytes = number of bytes in OutBuf }
342
+ procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
343
+ out OutBuf: Pointer; out OutBytes: Integer);
344
+
345
+
346
+ { DecompressBuf decompresses data, buffer to buffer, in one call.
347
+ In: InBuf = ptr to compressed data
348
+ InBytes = number of bytes in InBuf
349
+ OutEstimate = zero, or est. size of the decompressed data
350
+ Out: OutBuf = ptr to newly allocated buffer containing decompressed data
351
+ OutBytes = number of bytes in OutBuf }
352
+ procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
353
+ OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
354
+
355
+ const
356
+ zlib_version = '1.1.3';
357
+
358
+ type
359
+ EZlibError = class(Exception);
360
+ ECompressionError = class(EZlibError);
361
+ EDecompressionError = class(EZlibError);
362
+
363
+ function adler32(adler: Integer; buf: PChar; len: Integer): Integer;
364
+
365
+ implementation
366
+
367
+ const
368
+ Z_NO_FLUSH = 0;
369
+ Z_PARTIAL_FLUSH = 1;
370
+ Z_SYNC_FLUSH = 2;
371
+ Z_FULL_FLUSH = 3;
372
+ Z_FINISH = 4;
373
+
374
+ Z_OK = 0;
375
+ Z_STREAM_END = 1;
376
+ Z_NEED_DICT = 2;
377
+ Z_ERRNO = (-1);
378
+ Z_STREAM_ERROR = (-2);
379
+ Z_DATA_ERROR = (-3);
380
+ Z_MEM_ERROR = (-4);
381
+ Z_BUF_ERROR = (-5);
382
+ Z_VERSION_ERROR = (-6);
383
+
384
+ Z_NO_COMPRESSION = 0;
385
+ Z_BEST_SPEED = 1;
386
+ Z_BEST_COMPRESSION = 9;
387
+ Z_DEFAULT_COMPRESSION = (-1);
388
+
389
+ Z_FILTERED = 1;
390
+ Z_HUFFMAN_ONLY = 2;
391
+ Z_DEFAULT_STRATEGY = 0;
392
+
393
+ Z_BINARY = 0;
394
+ Z_ASCII = 1;
395
+ Z_UNKNOWN = 2;
396
+
397
+ Z_DEFLATED = 8;
398
+
399
+ _z_errmsg: array[0..9] of PChar = (
400
+ 'need dictionary', // Z_NEED_DICT (2)
401
+ 'stream end', // Z_STREAM_END (1)
402
+ '', // Z_OK (0)
403
+ 'file error', // Z_ERRNO (-1)
404
+ 'stream error', // Z_STREAM_ERROR (-2)
405
+ 'data error', // Z_DATA_ERROR (-3)
406
+ 'insufficient memory', // Z_MEM_ERROR (-4)
407
+ 'buffer error', // Z_BUF_ERROR (-5)
408
+ 'incompatible version', // Z_VERSION_ERROR (-6)
409
+ ''
410
+ );
411
+
412
+ {$L deflate.obj}
413
+ {$L inflate.obj}
414
+ {$L inftrees.obj}
415
+ {$L trees.obj}
416
+ {$L adler32.obj}
417
+ {$L infblock.obj}
418
+ {$L infcodes.obj}
419
+ {$L infutil.obj}
420
+ {$L inffast.obj}
421
+
422
+ procedure _tr_init; external;
423
+ procedure _tr_tally; external;
424
+ procedure _tr_flush_block; external;
425
+ procedure _tr_align; external;
426
+ procedure _tr_stored_block; external;
427
+ function adler32; external;
428
+ procedure inflate_blocks_new; external;
429
+ procedure inflate_blocks; external;
430
+ procedure inflate_blocks_reset; external;
431
+ procedure inflate_blocks_free; external;
432
+ procedure inflate_set_dictionary; external;
433
+ procedure inflate_trees_bits; external;
434
+ procedure inflate_trees_dynamic; external;
435
+ procedure inflate_trees_fixed; external;
436
+ procedure inflate_codes_new; external;
437
+ procedure inflate_codes; external;
438
+ procedure inflate_codes_free; external;
439
+ procedure _inflate_mask; external;
440
+ procedure inflate_flush; external;
441
+ procedure inflate_fast; external;
442
+
443
+ procedure _memset(P: Pointer; B: Byte; count: Integer);cdecl;
444
+ begin
445
+ FillChar(P^, count, B);
446
+ end;
447
+
448
+ procedure _memcpy(dest, source: Pointer; count: Integer);cdecl;
449
+ begin
450
+ Move(source^, dest^, count);
451
+ end;
452
+
453
+
454
+
455
+ // deflate compresses data
456
+ function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
457
+ recsize: Integer): Integer; external;
458
+ function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;
459
+ function deflateEnd(var strm: TZStreamRec): Integer; external;
460
+
461
+ // inflate decompresses data
462
+ function inflateInit_(var strm: TZStreamRec; version: PChar;
463
+ recsize: Integer): Integer; external;
464
+ function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;
465
+ function inflateEnd(var strm: TZStreamRec): Integer; external;
466
+ function inflateReset(var strm: TZStreamRec): Integer; external;
467
+
468
+
469
+ function zcalloc(AppData: Pointer; Items, Size: Integer): Pointer;
470
+ begin
471
+ GetMem(Result, Items*Size);
472
+ end;
473
+
474
+ procedure zcfree(AppData, Block: Pointer);
475
+ begin
476
+ FreeMem(Block);
477
+ end;
478
+
479
+ function zlibCheck(code: Integer): Integer;
480
+ begin
481
+ Result := code;
482
+ if code < 0 then
483
+ raise EZlibError.Create('error'); //!!
484
+ end;
485
+
486
+ function CCheck(code: Integer): Integer;
487
+ begin
488
+ Result := code;
489
+ if code < 0 then
490
+ raise ECompressionError.Create('error'); //!!
491
+ end;
492
+
493
+ function DCheck(code: Integer): Integer;
494
+ begin
495
+ Result := code;
496
+ if code < 0 then
497
+ raise EDecompressionError.Create('error'); //!!
498
+ end;
499
+
500
+ procedure CompressBuf(const InBuf: Pointer; InBytes: Integer;
501
+ out OutBuf: Pointer; out OutBytes: Integer);
502
+ var
503
+ strm: TZStreamRec;
504
+ P: Pointer;
505
+ begin
506
+ FillChar(strm, sizeof(strm), 0);
507
+ OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255;
508
+ GetMem(OutBuf, OutBytes);
509
+ try
510
+ strm.next_in := InBuf;
511
+ strm.avail_in := InBytes;
512
+ strm.next_out := OutBuf;
513
+ strm.avail_out := OutBytes;
514
+ CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm)));
515
+ try
516
+ while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do
517
+ begin
518
+ P := OutBuf;
519
+ Inc(OutBytes, 256);
520
+ ReallocMem(OutBuf, OutBytes);
521
+ strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
522
+ strm.avail_out := 256;
523
+ end;
524
+ finally
525
+ CCheck(deflateEnd(strm));
526
+ end;
527
+ ReallocMem(OutBuf, strm.total_out);
528
+ OutBytes := strm.total_out;
529
+ except
530
+ FreeMem(OutBuf);
531
+ raise
532
+ end;
533
+ end;
534
+
535
+
536
+ procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer;
537
+ OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer);
538
+ var
539
+ strm: TZStreamRec;
540
+ P: Pointer;
541
+ BufInc: Integer;
542
+ begin
543
+ FillChar(strm, sizeof(strm), 0);
544
+ BufInc := (InBytes + 255) and not 255;
545
+ if OutEstimate = 0 then
546
+ OutBytes := BufInc
547
+ else
548
+ OutBytes := OutEstimate;
549
+ GetMem(OutBuf, OutBytes);
550
+ try
551
+ strm.next_in := InBuf;
552
+ strm.avail_in := InBytes;
553
+ strm.next_out := OutBuf;
554
+ strm.avail_out := OutBytes;
555
+ DCheck(inflateInit_(strm, zlib_version, sizeof(strm)));
556
+ try
557
+ while DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do
558
+ begin
559
+ P := OutBuf;
560
+ Inc(OutBytes, BufInc);
561
+ ReallocMem(OutBuf, OutBytes);
562
+ strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P)));
563
+ strm.avail_out := BufInc;
564
+ end;
565
+ finally
566
+ DCheck(inflateEnd(strm));
567
+ end;
568
+ ReallocMem(OutBuf, strm.total_out);
569
+ OutBytes := strm.total_out;
570
+ except
571
+ FreeMem(OutBuf);
572
+ raise
573
+ end;
574
+ end;
575
+
576
+
577
+ // TCustomZlibStream
578
+
579
+ constructor TCustomZLibStream.Create(Strm: TStream);
580
+ begin
581
+ inherited Create;
582
+ FStrm := Strm;
583
+ FStrmPos := Strm.Position;
584
+ end;
585
+
586
+ procedure TCustomZLibStream.Progress(Sender: TObject);
587
+ begin
588
+ if Assigned(FOnProgress) then FOnProgress(Sender);
589
+ end;
590
+
591
+
592
+ // TCompressionStream
593
+
594
+ constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel;
595
+ Dest: TStream);
596
+ const
597
+ Levels: array [TCompressionLevel] of ShortInt =
598
+ (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION);
599
+ begin
600
+ inherited Create(Dest);
601
+ FZRec.next_out := FBuffer;
602
+ FZRec.avail_out := sizeof(FBuffer);
603
+ CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec)));
604
+ end;
605
+
606
+ destructor TCompressionStream.Destroy;
607
+ begin
608
+ FZRec.next_in := nil;
609
+ FZRec.avail_in := 0;
610
+ try
611
+ if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
612
+ while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END)
613
+ and (FZRec.avail_out = 0) do
614
+ begin
615
+ FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
616
+ FZRec.next_out := FBuffer;
617
+ FZRec.avail_out := sizeof(FBuffer);
618
+ end;
619
+ if FZRec.avail_out < sizeof(FBuffer) then
620
+ FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out);
621
+ finally
622
+ deflateEnd(FZRec);
623
+ end;
624
+ inherited Destroy;
625
+ end;
626
+
627
+ function TCompressionStream.Read(var Buffer; Count: Longint): Longint;
628
+ begin
629
+ raise ECompressionError.Create('Invalid stream operation');
630
+ end;
631
+
632
+ function TCompressionStream.Write(const Buffer; Count: Longint): Longint;
633
+ begin
634
+ FZRec.next_in := @Buffer;
635
+ FZRec.avail_in := Count;
636
+ if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
637
+ while (FZRec.avail_in > 0) do
638
+ begin
639
+ CCheck(deflate(FZRec, 0));
640
+ if FZRec.avail_out = 0 then
641
+ begin
642
+ FStrm.WriteBuffer(FBuffer, sizeof(FBuffer));
643
+ FZRec.next_out := FBuffer;
644
+ FZRec.avail_out := sizeof(FBuffer);
645
+ FStrmPos := FStrm.Position;
646
+ Progress(Self);
647
+ end;
648
+ end;
649
+ Result := Count;
650
+ end;
651
+
652
+ function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
653
+ begin
654
+ if (Offset = 0) and (Origin = soFromCurrent) then
655
+ Result := FZRec.total_in
656
+ else
657
+ raise ECompressionError.Create('Invalid stream operation');
658
+ end;
659
+
660
+ function TCompressionStream.GetCompressionRate: Single;
661
+ begin
662
+ if FZRec.total_in = 0 then
663
+ Result := 0
664
+ else
665
+ Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0;
666
+ end;
667
+
668
+
669
+ // TDecompressionStream
670
+
671
+ constructor TDecompressionStream.Create(Source: TStream);
672
+ begin
673
+ inherited Create(Source);
674
+ FZRec.next_in := FBuffer;
675
+ FZRec.avail_in := 0;
676
+ DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec)));
677
+ end;
678
+
679
+ destructor TDecompressionStream.Destroy;
680
+ begin
681
+ inflateEnd(FZRec);
682
+ inherited Destroy;
683
+ end;
684
+
685
+ function TDecompressionStream.Read(var Buffer; Count: Longint): Longint;
686
+ begin
687
+ FZRec.next_out := @Buffer;
688
+ FZRec.avail_out := Count;
689
+ if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos;
690
+ while (FZRec.avail_out > 0) do
691
+ begin
692
+ if FZRec.avail_in = 0 then
693
+ begin
694
+ FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer));
695
+ if FZRec.avail_in = 0 then
696
+ begin
697
+ Result := Count - FZRec.avail_out;
698
+ Exit;
699
+ end;
700
+ FZRec.next_in := FBuffer;
701
+ FStrmPos := FStrm.Position;
702
+ Progress(Self);
703
+ end;
704
+ DCheck(inflate(FZRec, 0));
705
+ end;
706
+ Result := Count;
707
+ end;
708
+
709
+ function TDecompressionStream.Write(const Buffer; Count: Longint): Longint;
710
+ begin
711
+ raise EDecompressionError.Create('Invalid stream operation');
712
+ end;
713
+
714
+ function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint;
715
+ var
716
+ I: Integer;
717
+ Buf: array [0..4095] of Char;
718
+ begin
719
+ if (Offset = 0) and (Origin = soFromBeginning) then
720
+ begin
721
+ DCheck(inflateReset(FZRec));
722
+ FZRec.next_in := FBuffer;
723
+ FZRec.avail_in := 0;
724
+ FStrm.Position := 0;
725
+ FStrmPos := 0;
726
+ end
727
+ else if ( (Offset >= 0) and (Origin = soFromCurrent)) or
728
+ ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then
729
+ begin
730
+ if Origin = soFromBeginning then Dec(Offset, FZRec.total_out);
731
+ if Offset > 0 then
732
+ begin
733
+ for I := 1 to Offset div sizeof(Buf) do
734
+ ReadBuffer(Buf, sizeof(Buf));
735
+ ReadBuffer(Buf, Offset mod sizeof(Buf));
736
+ end;
737
+ end
738
+ else
739
+ raise EDecompressionError.Create('Invalid stream operation');
740
+ Result := FZRec.total_out;
741
+ end;
742
+
743
+ end.