gitlab-pygments.rb 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/README.md +91 -0
- data/Rakefile +78 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +344 -0
- data/lib/pygments/popen.rb +389 -0
- data/lib/pygments/version.rb +3 -0
- data/lib/pygments.rb +8 -0
- data/pygments.rb.gemspec +24 -0
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +276 -0
- data/vendor/custom_formatters/gitlab.py +171 -0
- data/vendor/custom_lexers/github.py +362 -0
- data/vendor/pygments-main/AUTHORS +115 -0
- data/vendor/pygments-main/CHANGES +762 -0
- data/vendor/pygments-main/LICENSE +25 -0
- data/vendor/pygments-main/MANIFEST.in +6 -0
- data/vendor/pygments-main/Makefile +59 -0
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/TODO +15 -0
- data/vendor/pygments-main/docs/generate.py +472 -0
- data/vendor/pygments-main/docs/pygmentize.1 +94 -0
- data/vendor/pygments-main/docs/src/api.txt +270 -0
- data/vendor/pygments-main/docs/src/authors.txt +5 -0
- data/vendor/pygments-main/docs/src/changelog.txt +5 -0
- data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
- data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
- data/vendor/pygments-main/docs/src/filters.txt +42 -0
- data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
- data/vendor/pygments-main/docs/src/formatters.txt +48 -0
- data/vendor/pygments-main/docs/src/index.txt +69 -0
- data/vendor/pygments-main/docs/src/installation.txt +71 -0
- data/vendor/pygments-main/docs/src/integrate.txt +43 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
- data/vendor/pygments-main/docs/src/lexers.txt +67 -0
- data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
- data/vendor/pygments-main/docs/src/plugins.txt +93 -0
- data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
- data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
- data/vendor/pygments-main/docs/src/styles.txt +143 -0
- data/vendor/pygments-main/docs/src/tokens.txt +349 -0
- data/vendor/pygments-main/docs/src/unicode.txt +49 -0
- data/vendor/pygments-main/external/markdown-processor.py +67 -0
- data/vendor/pygments-main/external/moin-parser.py +112 -0
- data/vendor/pygments-main/external/pygments.bashcomp +38 -0
- data/vendor/pygments-main/external/rst-directive-old.py +77 -0
- data/vendor/pygments-main/external/rst-directive.py +83 -0
- data/vendor/pygments-main/ez_setup.py +276 -0
- data/vendor/pygments-main/pygmentize +7 -0
- data/vendor/pygments-main/pygments/__init__.py +91 -0
- data/vendor/pygments-main/pygments/cmdline.py +433 -0
- data/vendor/pygments-main/pygments/console.py +74 -0
- data/vendor/pygments-main/pygments/filter.py +74 -0
- data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
- data/vendor/pygments-main/pygments/formatter.py +92 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
- data/vendor/pygments-main/pygments/formatters/html.py +750 -0
- data/vendor/pygments-main/pygments/formatters/img.py +553 -0
- data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
- data/vendor/pygments-main/pygments/formatters/other.py +117 -0
- data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
- data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
- data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
- data/vendor/pygments-main/pygments/lexer.py +697 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
- data/vendor/pygments-main/pygments/lexers/github.py +362 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
- data/vendor/pygments-main/pygments/lexers/special.py +100 -0
- data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
- data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
- data/vendor/pygments-main/pygments/plugin.py +74 -0
- data/vendor/pygments-main/pygments/scanner.py +104 -0
- data/vendor/pygments-main/pygments/style.py +117 -0
- data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
- data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
- data/vendor/pygments-main/pygments/styles/borland.py +51 -0
- data/vendor/pygments-main/pygments/styles/bw.py +49 -0
- data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
- data/vendor/pygments-main/pygments/styles/default.py +73 -0
- data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
- data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
- data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
- data/vendor/pygments-main/pygments/styles/manni.py +75 -0
- data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
- data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
- data/vendor/pygments-main/pygments/styles/native.py +65 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
- data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +141 -0
- data/vendor/pygments-main/pygments/styles/trac.py +63 -0
- data/vendor/pygments-main/pygments/styles/vim.py +63 -0
- data/vendor/pygments-main/pygments/styles/vs.py +38 -0
- data/vendor/pygments-main/pygments/token.py +195 -0
- data/vendor/pygments-main/pygments/unistring.py +130 -0
- data/vendor/pygments-main/pygments/util.py +232 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
- data/vendor/pygments-main/scripts/epydoc.css +280 -0
- data/vendor/pygments-main/scripts/find_codetags.py +205 -0
- data/vendor/pygments-main/scripts/find_error.py +171 -0
- data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
- data/vendor/pygments-main/scripts/pylintrc +301 -0
- data/vendor/pygments-main/scripts/reindent.py +291 -0
- data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
- data/vendor/pygments-main/setup.cfg +6 -0
- data/vendor/pygments-main/setup.py +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
- data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
- data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
- data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
- data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
- data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
- data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
- data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
- data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
- data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
- data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
- data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
- data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
- data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
- data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
- data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
- data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
- data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
- data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
- data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
- data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
- data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
- data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
- data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
- data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
- data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
- data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
- data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
- data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
- data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
- data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
- data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
- data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
- data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
- data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
- data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
- data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
- data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
- data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
- data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
- data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
- data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
- data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
- data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
- data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
- data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
- data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
- data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
- data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
- data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
- data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
- data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
- data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
- data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
- data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
- data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
- data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
- data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
- data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
- data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
- data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
- data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
- data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
- data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
- data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
- data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
- data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
- data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
- data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
- data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
- data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
- data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
- data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
- data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
- data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
- data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
- data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
- data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
- data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
- data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
- data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
- data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
- data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
- data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
- data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
- data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
- data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
- data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
- data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
- data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
- data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
- data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
- data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
- data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
- data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
- data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
- data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
- data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
- data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
- data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
- data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
- data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
- data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
- data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
- data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
- data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
- data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
- data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
- data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
- data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
- data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
- data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
- data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
- data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
- data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
- data/vendor/pygments-main/tests/old_run.py +138 -0
- data/vendor/pygments-main/tests/run.py +48 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/test_basic_api.py +294 -0
- data/vendor/pygments-main/tests/test_clexer.py +31 -0
- data/vendor/pygments-main/tests/test_cmdline.py +105 -0
- data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
- data/vendor/pygments-main/tests/test_token.py +46 -0
- data/vendor/pygments-main/tests/test_using_api.py +40 -0
- data/vendor/pygments-main/tests/test_util.py +116 -0
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +492 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
Newsqueak2
|
2
|
+
'Langexplr
|
3
|
+
'
|
4
|
+
|
5
|
+
class ShapesExperiment usingLib: platform = (
|
6
|
+
"A small experiment for using Hopscotch shape classes ."
|
7
|
+
|
|
8
|
+
CanvasDependent = platform CanvasDependent.
|
9
|
+
Presenter = platform HPresenter.
|
10
|
+
Subject = platform Subject.
|
11
|
+
EllipseShape = platform EllipseShape.
|
12
|
+
Color = platform Color.
|
13
|
+
|
|
14
|
+
)
|
15
|
+
(
|
16
|
+
|
17
|
+
class ShapesExperimentSubject = Subject(
|
18
|
+
"Subject for shapes experiment"
|
19
|
+
|
|
20
|
+
|
21
|
+
|
|
22
|
+
)
|
23
|
+
('as yet unclassified'
|
24
|
+
createPresenter = (
|
25
|
+
^ShapesExperimentPresenter new subject: self.
|
26
|
+
)
|
27
|
+
|
28
|
+
)
|
29
|
+
|
30
|
+
class ShapesExperimentPresenter = Presenter (
|
31
|
+
"A presenter for a small experiment of using shape classes"
|
32
|
+
|
|
33
|
+
|
|
34
|
+
)
|
35
|
+
('as yet unclassified'
|
36
|
+
controlPoint = (
|
37
|
+
^ControlPoint new.
|
38
|
+
)
|
39
|
+
|
40
|
+
definition = (
|
41
|
+
^ column: {
|
42
|
+
canvas: {
|
43
|
+
at: 10 @ 10 display: controlPoint.
|
44
|
+
at: 15 @ 10 display: controlPoint.
|
45
|
+
}
|
46
|
+
}
|
47
|
+
)
|
48
|
+
|
49
|
+
)
|
50
|
+
|
51
|
+
class ControlPoint = CanvasDependent(
|
52
|
+
"A class that represents a small point in the screen"
|
53
|
+
|
|
54
|
+
|
|
55
|
+
)
|
56
|
+
('as yet unclassified'
|
57
|
+
addVisualsTo: container = (
|
58
|
+
container add: visual.
|
59
|
+
updateLayout.
|
60
|
+
)
|
61
|
+
|
62
|
+
createVisual = (
|
63
|
+
| s |
|
64
|
+
s:: EllipseShape new size: 5@5 .
|
65
|
+
s color: Color red.
|
66
|
+
^ s
|
67
|
+
)
|
68
|
+
|
69
|
+
))
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{include.i}
|
2
|
+
{nested.i {include.i}}
|
3
|
+
|
4
|
+
&SCOPED-DEFINE MY_NAME "Abe"
|
5
|
+
|
6
|
+
DEF VAR i AS INT NO-UNDO.
|
7
|
+
i = 0xABE + 1337 / (1 * 1.00)
|
8
|
+
|
9
|
+
def var clowercasetest as char no-undo.
|
10
|
+
DEF VAR vardashtest AS DATETIME-TZ NO-UNDO.
|
11
|
+
|
12
|
+
DEFINE TEMP-TABLE ttNames NO-UNDO
|
13
|
+
FIELD cName AS CHAR
|
14
|
+
INDEX IXPK_ttNames IS PRIMARY UNIQUE cName.
|
15
|
+
|
16
|
+
/* One-line comment */
|
17
|
+
/* Two-line
|
18
|
+
Comment */
|
19
|
+
/*
|
20
|
+
Nested
|
21
|
+
/*
|
22
|
+
Multiline
|
23
|
+
/*
|
24
|
+
Comment
|
25
|
+
*/
|
26
|
+
*/
|
27
|
+
*/
|
28
|
+
|
29
|
+
CREATE ttNames.
|
30
|
+
ASSIGN ttNames.cName = {&MY_NAME}.
|
31
|
+
|
32
|
+
FOR EACH ttNames:
|
33
|
+
MESSAGE "Hello, " + ttNames.cName + '!' VIEW-AS ALERT-BOX.
|
34
|
+
END.
|
@@ -0,0 +1,2708 @@
|
|
1
|
+
// vim:ft=pascal
|
2
|
+
|
3
|
+
unit YTools;
|
4
|
+
|
5
|
+
{===============================================================================
|
6
|
+
|
7
|
+
cYcnus.YTools 1.0.3 Beta for Delphi 4+
|
8
|
+
by licenser and Murphy
|
9
|
+
|
10
|
+
�2000-2003 by cYcnus
|
11
|
+
visit www.cYcnus.de
|
12
|
+
|
13
|
+
licenser@cYcnus.de (Heinz N. Gies)
|
14
|
+
murphy@cYcnus.de (Kornelius Kalnbach)
|
15
|
+
|
16
|
+
this unit is published under the terms of the GPL
|
17
|
+
|
18
|
+
===============================================================================}
|
19
|
+
|
20
|
+
interface
|
21
|
+
|
22
|
+
uses
|
23
|
+
Windows, SysUtils, Classes, YTypes;
|
24
|
+
|
25
|
+
const
|
26
|
+
BackSpace = #8;
|
27
|
+
Tab = #9;
|
28
|
+
LF = #10; //Line Feed
|
29
|
+
CR = #13; //Carriage Return
|
30
|
+
Space = #32;
|
31
|
+
EOLChars = [CR, LF];
|
32
|
+
{$IFNDEF VER140}
|
33
|
+
sLineBreak = #13#10;
|
34
|
+
SwitchChars = ['/', '-'];
|
35
|
+
{$ENDIF}
|
36
|
+
EOL = sLineBreak;
|
37
|
+
MaxCard = High(Cardinal);
|
38
|
+
AllChars = [#0..#255];
|
39
|
+
Alphabetical = ['A'..'Z', 'a'..'z'];
|
40
|
+
DecimalChars = ['0'..'9'];
|
41
|
+
AlphaNumerical = Alphabetical + DecimalChars;
|
42
|
+
StrangeChars = [#0..#31, #127, #129, #141..#144, #157, #158];
|
43
|
+
|
44
|
+
HexadecimalChars = DecimalChars + ['A'..'F', 'a'..'f'];
|
45
|
+
OctalChars = ['0'..'7'];
|
46
|
+
BinaryChars = ['0', '1'];
|
47
|
+
|
48
|
+
QuoteChars = ['''', '"'];
|
49
|
+
WildCards = ['*', '?'];
|
50
|
+
FileNameEnemies = WildCards + ['\', '/', ':', '<', '>', '|'];
|
51
|
+
|
52
|
+
HexChar: array[THex] of Char = (
|
53
|
+
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
|
54
|
+
LowerHexChar: array[THex] of Char = (
|
55
|
+
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
|
56
|
+
BaseNChar: array[TBaseN] of Char = (
|
57
|
+
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H',
|
58
|
+
'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
|
59
|
+
|
60
|
+
cYcnusOverlayColor = $050001;
|
61
|
+
|
62
|
+
faFindEveryFile = faReadOnly + faHidden + faSysFile + faArchive;
|
63
|
+
|
64
|
+
platWin9x = [VER_PLATFORM_WIN32s, VER_PLATFORM_WIN32_WINDOWS];
|
65
|
+
|
66
|
+
|
67
|
+
{ Debugging }
|
68
|
+
procedure ClearReport(const ReportName: string);
|
69
|
+
procedure Report(const ReportName, Text: string);
|
70
|
+
procedure ReportFmt(const ReportName, Fmt: string; const Args: array of const);
|
71
|
+
|
72
|
+
{ Params }
|
73
|
+
procedure GetParams(Strings: TStrings); overload;
|
74
|
+
function GetParams(const Separator: string = ' '): string; overload;
|
75
|
+
|
76
|
+
function ParamNum(const S: string): Integer;
|
77
|
+
function ParamPrefixNum(const Prefix: string): Integer;
|
78
|
+
function Param(const S: string): Boolean;
|
79
|
+
function ParamPrefix(const Prefix: string): Boolean;
|
80
|
+
|
81
|
+
function Switch(const Switch: string; const PrefixChars: TCharSet = SwitchChars;
|
82
|
+
IgnoreCase: Boolean = True): Boolean;
|
83
|
+
function GetParam(const Prefix: string = ''; const Default: string = ''): string;
|
84
|
+
|
85
|
+
{ Dirs & UserName}
|
86
|
+
function GetMyDir(FullPath: Boolean = False): string;
|
87
|
+
function WinDir: string;
|
88
|
+
function SysDir: string;
|
89
|
+
function UserName: string;
|
90
|
+
|
91
|
+
{ Strings & Chars}
|
92
|
+
function FirstChar(const S: string): Char;
|
93
|
+
function LastChar(const S: string): Char;
|
94
|
+
|
95
|
+
function CharPos(C: Char; const S: string; Offset: Integer = 1): Integer; overload;
|
96
|
+
function CharPos(C: TCharSet; const S: string; Offset: Integer = 1): Integer; overload;
|
97
|
+
function CharPosR(C: Char; const S: string; Offset: Integer = -1): Integer;
|
98
|
+
function PosEx(const SubStr, S: string; Offset: Integer = 1): Integer;
|
99
|
+
function PosExText(const SubStr, S: string; Offset: Integer = 1): Integer;
|
100
|
+
function PosExAnsiText(const SubStr, S: string; Offset: Integer = 1): Integer;
|
101
|
+
|
102
|
+
function UntilChar(const S: string; Brake: Char): string; overload;
|
103
|
+
function UntilChar(const S: string; Brake: TCharSet): string; overload;
|
104
|
+
function UntilLastChar(const S: string; Brake: Char;
|
105
|
+
IgnoreNoBrake: Boolean = True): string;
|
106
|
+
|
107
|
+
function FromChar(const S: string; Brake: Char): string; overload;
|
108
|
+
function FromChar(const S: string; Brake: TCharSet): string; overload;
|
109
|
+
function FromLastChar(const S: string; Brake: Char;
|
110
|
+
IgnoreNoBrake: Boolean = False): string;
|
111
|
+
|
112
|
+
function BetweenChars(const S: string; Start, Finish: Char;
|
113
|
+
Inclusive: Boolean = False): string;
|
114
|
+
|
115
|
+
function UntilStr(const S: string; Brake: string): string;
|
116
|
+
function FromStr(const S: string; Brake: string): string;
|
117
|
+
|
118
|
+
function StringWrap(const S: string; Width: Integer; const LineEnd: string = EOL): string;
|
119
|
+
|
120
|
+
{ Splitting & Combining }
|
121
|
+
function Split(const S, Separator: string; IgnoreMultiSep: Boolean = True;
|
122
|
+
MinCount: Integer = 0): TStrA; overload;
|
123
|
+
procedure Split(const S, Separator: string; Strings: TStrings;
|
124
|
+
IgnoreMultiSep: Boolean = True); overload;
|
125
|
+
function Split(const S: string; Separators: TCharSet;
|
126
|
+
IgnoreMultiSep: Boolean = True; MinCount: Integer = 0): TStrA; overload;
|
127
|
+
|
128
|
+
procedure TileStr(const S: string; BrakeStart: Integer; BrakeEnd: Integer;
|
129
|
+
out Left, Right: string);
|
130
|
+
|
131
|
+
function Join(Strings: TStrings; Separator: string = ' '): string; overload;
|
132
|
+
function Join(StrA: TStrA; Separator: string = ' '): string; overload;
|
133
|
+
|
134
|
+
function MulStr(const S: string; Count: Integer): string;
|
135
|
+
|
136
|
+
{ Strings ausrichten }
|
137
|
+
function AlignR(const S: string; Width: Integer; Filler: Char = ' '): string;
|
138
|
+
function MaxStr(const S: string; MaxLen: Integer): string;
|
139
|
+
|
140
|
+
{ Stringing }
|
141
|
+
function TrimAll(const S: string): string;
|
142
|
+
|
143
|
+
function ControlChar(C: Char): Boolean;
|
144
|
+
function FriendlyChar(C: Char): Char;
|
145
|
+
|
146
|
+
function FriendlyStr(const S: string): string; overload;
|
147
|
+
function FriendlyStr(a: TByteA): string; overload;
|
148
|
+
|
149
|
+
function Quote(const S: string; Quoter: Char = '"'): string;
|
150
|
+
function UnQuote(const S: string): string;
|
151
|
+
function DeQuote(const S: string): string;
|
152
|
+
|
153
|
+
function StrNumerus(const Value: Integer; const Singular, Plural: string;
|
154
|
+
const Zero: string = '0'): string;
|
155
|
+
|
156
|
+
function MakeStr(const Items: array of const; Separator: string = ''): string;
|
157
|
+
procedure ShowText(const Items: array of const; Separator: string = '');
|
158
|
+
|
159
|
+
{ Delete }
|
160
|
+
function DeleteChars(const S: string; C: Char): string; overload;
|
161
|
+
function DeleteChars(const S: string; C: TCharSet): string; overload;
|
162
|
+
function ExtractChars(const S: string; C: TCharSet): string;
|
163
|
+
|
164
|
+
{ Find }
|
165
|
+
function CharCount(const S: string; C: Char): Integer;
|
166
|
+
|
167
|
+
function CharIn(const S: string; C: Char): Boolean; overload;
|
168
|
+
function CharIn(const S: string; C: TCharSet): Boolean; overload;
|
169
|
+
|
170
|
+
function StrAtPos(const S: string; Pos: Integer; const Str: string): Boolean;
|
171
|
+
function StrAtBegin(const S, Str: string): Boolean;
|
172
|
+
function StrIn(const S, SubStr: string): Boolean; overload;
|
173
|
+
function StrIn(A: TStrA; const S: string): Boolean; overload;
|
174
|
+
function StrIn(SL: TStrings; const S: string): Boolean; overload;
|
175
|
+
function StrIndex(A: TStrA; const S: string): Integer; overload;
|
176
|
+
function StrIndex(SL: TStrings; const S: string): Integer; overload;
|
177
|
+
|
178
|
+
function TextAtPos(const S: string; Pos: Integer; const Text: string): Boolean;
|
179
|
+
function TextAtBegin(const S, Text: string): Boolean;
|
180
|
+
function TextIn(const S, Text: string): Boolean; overload;
|
181
|
+
function TextIn(A: TStrA; const Text: string): Boolean; overload;
|
182
|
+
function TextIn(SL: TStrings; const Text: string): Boolean; overload;
|
183
|
+
function TextIndex(A: TStrA; const Text: string): Integer; overload;
|
184
|
+
function TextIndex(SL: TStrings; const Text: string): Integer; overload;
|
185
|
+
|
186
|
+
{ Replace }
|
187
|
+
function ReplaceChars(const S: string; Old, New: Char): string; overload;
|
188
|
+
function ReplaceChars(const S: string; Old: TCharSet; New: Char): string; overload;
|
189
|
+
|
190
|
+
function Replace(const S, Old, New: string): string;
|
191
|
+
|
192
|
+
{ TStrings }
|
193
|
+
function SLOfFile(const FileName: string): TStringList;
|
194
|
+
function ContainsEmptyLines(SL: TStrings): Boolean;
|
195
|
+
procedure DeleteEmptyLines(SL: TStrings);
|
196
|
+
procedure DeleteCommentLines(SL: TStrings; const CommentSign: string = '//');
|
197
|
+
procedure WriteSL(Strings: TStrings; const Prefix: string = '';
|
198
|
+
const Suffix: string = '');
|
199
|
+
|
200
|
+
function FindLine(SL: TStrings; const S: string): Integer;
|
201
|
+
|
202
|
+
procedure QuickSortSL(SL: TStringList);
|
203
|
+
|
204
|
+
{ TStrA }
|
205
|
+
function IncStrA(StrA: TStrA): Integer;
|
206
|
+
|
207
|
+
{ TByteA }
|
208
|
+
function StrOfByteA(a: TByteA): string;
|
209
|
+
function ByteAOfStr(const S: string): TByteA;
|
210
|
+
function ByteAOfInt(i: Integer): TByteA;
|
211
|
+
function IntOfByteA(A: TByteA): Integer;
|
212
|
+
function ByteAOfHex(const Hex: string): TByteA;
|
213
|
+
|
214
|
+
function SameByteA(const A, B: TByteA): Boolean;
|
215
|
+
function Reverse(a: TByteA): TByteA;
|
216
|
+
function SaveByteA(Data: TByteA; const FileName: string; Overwrite: Boolean = True): Boolean;
|
217
|
+
function LoadByteA(const FileName: string): TByteA;
|
218
|
+
|
219
|
+
function Endian(i: Integer): Integer;
|
220
|
+
|
221
|
+
{ Files }
|
222
|
+
function SizeOfFile(const FileName: string): Integer;
|
223
|
+
function FileEx(const FileName: string; AllowFolders: Boolean = False): Boolean;
|
224
|
+
function LWPSolve(const Dir: string): string;
|
225
|
+
function LWPSlash(const Dir: string): string;
|
226
|
+
|
227
|
+
function ExtractDrive(const FileName: string): string;
|
228
|
+
function ExtractPath(const FileName: string): string;
|
229
|
+
function ExtractPrefix(const FileName: string): string;
|
230
|
+
function ExtractSuffix(const FileName: string): string;
|
231
|
+
|
232
|
+
function IsValidFileName(const FileName: string): Boolean;
|
233
|
+
function MakeValidFileName(FileName: string; const Default: string = 'File'): string;
|
234
|
+
|
235
|
+
{ Converting }
|
236
|
+
function IsValidInteger(const S: string): Boolean;
|
237
|
+
function IsValidCardinal(const S: string): Boolean;
|
238
|
+
|
239
|
+
function StrOfBool(flag: Boolean; const TrueStr: string = 'True';
|
240
|
+
const FalseStr: string = 'False'): string;
|
241
|
+
function StrOfInt(i: Integer): string;
|
242
|
+
function CardOfStr(const S: string): Cardinal;
|
243
|
+
|
244
|
+
function HexOrd(Hex: Char): THex;
|
245
|
+
function ByteOfHex(Hex: THexByteStr): Byte;
|
246
|
+
|
247
|
+
function DecOfHex(const Hex: string): string;
|
248
|
+
function HexOfByte(b: Byte): THexByteStr;
|
249
|
+
function HexOfCard(i: Cardinal): string; overload;
|
250
|
+
function HexOfCard(i: Cardinal; Digits: Integer): string; overload;
|
251
|
+
|
252
|
+
function PascalHexArray(a: TByteA; Name: string): string;
|
253
|
+
|
254
|
+
function HexOfByteA(a: TByteA; Blocks: Integer = 1;
|
255
|
+
const Splitter: string = ' '): string;
|
256
|
+
function BinOfByteA(a: TByteA; Blocks: Integer = 4;
|
257
|
+
const Splitter: string = ' '): string;
|
258
|
+
|
259
|
+
function CardOfHex(Hex: string): Cardinal;
|
260
|
+
function IntOfBin(Bin: string): Cardinal;
|
261
|
+
|
262
|
+
function BinOfIntFill(n: cardinal; MinCount: Integer = 8): string;
|
263
|
+
function BinOfInt(n: cardinal): string;
|
264
|
+
|
265
|
+
function BaseNOfInt(I: Cardinal; B: TBaseN): string;
|
266
|
+
function IntOfBaseN(V: string; B: TBaseN): Cardinal;
|
267
|
+
|
268
|
+
{ Ranges }
|
269
|
+
function KeepIn(i, Bottom, Top: Variant): Variant;
|
270
|
+
function InRange(Value, Bottom, Top: Variant): Boolean;
|
271
|
+
function InStrictRange(Value, Bottom, Top: Variant): Boolean;
|
272
|
+
function Min(const A, B: Integer): Integer; overload;
|
273
|
+
function Min(const A: TIntA): Integer; overload;
|
274
|
+
function Max(const A, B: Integer): Integer; overload;
|
275
|
+
function Max(const A: TIntA): Integer; overload;
|
276
|
+
|
277
|
+
const
|
278
|
+
RangesSeparator = ',';
|
279
|
+
RangeInnerSeparator = '-';
|
280
|
+
RangeInfinite = '*';
|
281
|
+
RangeSpecialChars = [RangesSeparator, RangeInnerSeparator, RangeInfinite];
|
282
|
+
|
283
|
+
function RangesOfStr(const S: string): TRanges;
|
284
|
+
function InRanges(Ranges: TRanges; TestValue: Cardinal): Boolean;
|
285
|
+
|
286
|
+
function Success(Res: Integer; ResultOnSuccess: Integer = ERROR_SUCCESS): Boolean;
|
287
|
+
function Failure(Res: Integer; ResultOnSuccess: Integer = ERROR_SUCCESS): Boolean;
|
288
|
+
|
289
|
+
function ExpandString(const S: string): string;
|
290
|
+
|
291
|
+
{ Files }
|
292
|
+
procedure DeleteFiles(const Mask: string; ScanSubDirs: Boolean = True;
|
293
|
+
Attributes: Integer = faFindEveryFile);
|
294
|
+
procedure FileNew(const FileName: string);
|
295
|
+
function DateTimeOfFileTime(const FileTime: TFileTime): TDateTime;
|
296
|
+
|
297
|
+
{ FileNames }
|
298
|
+
function GetFileNew(FileName: string; NoFloppyDrives: Boolean = True): string;
|
299
|
+
|
300
|
+
{ Finding Files }
|
301
|
+
function FindAll(Strings: TStrings; const Mask: string;
|
302
|
+
ScanSubDirs: Boolean = True; Attributes: Integer = faFindEveryFile;
|
303
|
+
FileReturn: TFileNameFunc = nil): Boolean;
|
304
|
+
function FindAllFirst(const Mask: string; ScanSubDirs: Boolean = True;
|
305
|
+
Attributes: Integer = faFindEveryFile): string;
|
306
|
+
|
307
|
+
function FullOSInfo: string;
|
308
|
+
function Win32PlatformStr: string;
|
309
|
+
function Win9x: Boolean;
|
310
|
+
function WinNT: Boolean;
|
311
|
+
function Win2000: Boolean;
|
312
|
+
function WinXP: Boolean;
|
313
|
+
|
314
|
+
var
|
315
|
+
MyDir: string = '';
|
316
|
+
LastSuccessRes: Integer = 0;
|
317
|
+
|
318
|
+
{ Backward compatibility }
|
319
|
+
{$IFNDEF VER130}
|
320
|
+
function SameText(const S1, S2: string): Boolean;
|
321
|
+
{$ENDIF}
|
322
|
+
|
323
|
+
implementation
|
324
|
+
{$IFNDEF VER140}
|
325
|
+
uses FileCtrl;
|
326
|
+
{$ENDIF}
|
327
|
+
|
328
|
+
{$IFNDEF VER130}
|
329
|
+
function SameText(const S1, S2: string): Boolean;
|
330
|
+
begin
|
331
|
+
Result := CompareText(S1, S2) = 0;
|
332
|
+
end;
|
333
|
+
{$ENDIF}
|
334
|
+
|
335
|
+
procedure Report(const ReportName, Text: string);
|
336
|
+
var
|
337
|
+
F: TextFile;
|
338
|
+
FileName: string;
|
339
|
+
begin
|
340
|
+
FileName := MyDir + ReportName + '.rep';
|
341
|
+
Assign(F, FileName);
|
342
|
+
try
|
343
|
+
if not FileExists(FileName) then
|
344
|
+
Rewrite(F)
|
345
|
+
else
|
346
|
+
Append(F);
|
347
|
+
WriteLn(F, Text);
|
348
|
+
finally
|
349
|
+
Close(F);
|
350
|
+
end;
|
351
|
+
end;
|
352
|
+
|
353
|
+
procedure ClearReport(const ReportName: string);
|
354
|
+
var
|
355
|
+
FileName: string;
|
356
|
+
begin
|
357
|
+
FileName := MyDir + ReportName + '.rep';
|
358
|
+
DeleteFile(FileName);
|
359
|
+
end;
|
360
|
+
|
361
|
+
procedure ReportFmt(const ReportName, Fmt: string; const Args: array of const);
|
362
|
+
begin
|
363
|
+
Report(ReportName, Format(Fmt, Args));
|
364
|
+
end;
|
365
|
+
|
366
|
+
procedure GetParams(Strings: TStrings);
|
367
|
+
var
|
368
|
+
P: PChar;
|
369
|
+
Param: string;
|
370
|
+
|
371
|
+
function GetParamStr(var P: PChar; var Param: string): Boolean;
|
372
|
+
var
|
373
|
+
Quoted: Boolean;
|
374
|
+
begin
|
375
|
+
Param := '';
|
376
|
+
|
377
|
+
repeat
|
378
|
+
while (P[0] <> #0) and (P[0] <= ' ') do
|
379
|
+
Inc(P);
|
380
|
+
|
381
|
+
Quoted := False;
|
382
|
+
while P[0] <> #0 do begin
|
383
|
+
if P[0] = '"' then begin
|
384
|
+
Quoted := not Quoted;
|
385
|
+
Inc(P);
|
386
|
+
Continue; end;
|
387
|
+
if (P[0] <= ' ') and not Quoted then
|
388
|
+
Break;
|
389
|
+
Param := Param + P[0];
|
390
|
+
Inc(P);
|
391
|
+
end;
|
392
|
+
until (Param <> '') or (P[0] = #0);
|
393
|
+
|
394
|
+
Result := Param <> '';
|
395
|
+
end;
|
396
|
+
|
397
|
+
begin
|
398
|
+
Strings.Clear;
|
399
|
+
P := GetCommandLine;
|
400
|
+
GetParamStr(P, Param);
|
401
|
+
while GetParamStr(P, Param) do
|
402
|
+
Strings.Add(Param);
|
403
|
+
end;
|
404
|
+
|
405
|
+
function GetParams(const Separator: string = ' '): string;
|
406
|
+
var
|
407
|
+
SL: TStringList;
|
408
|
+
begin
|
409
|
+
SL := TStringList.Create;
|
410
|
+
GetParams(SL);
|
411
|
+
Result := Join(SL, Separator);
|
412
|
+
SL.Free;
|
413
|
+
end;
|
414
|
+
|
415
|
+
function Switch(const Switch: string; const PrefixChars: TCharSet = SwitchChars;
|
416
|
+
IgnoreCase: Boolean = True): Boolean;
|
417
|
+
//= SysUtils.FindCmdLineSwitch
|
418
|
+
var
|
419
|
+
i: Integer;
|
420
|
+
s: string;
|
421
|
+
begin
|
422
|
+
Result := True;
|
423
|
+
|
424
|
+
for i := 1 to ParamCount do begin
|
425
|
+
s := ParamStr(i);
|
426
|
+
|
427
|
+
if (s <> '') and (s[1] in PrefixChars) then begin
|
428
|
+
//i know that always s <> '', but this is saver
|
429
|
+
s := Copy(s, 2, MaxInt);
|
430
|
+
if (s = Switch) or (IgnoreCase and (0=AnsiCompareText(s, Switch))) then
|
431
|
+
Exit;
|
432
|
+
end;
|
433
|
+
end;
|
434
|
+
|
435
|
+
Result := False;
|
436
|
+
end;
|
437
|
+
|
438
|
+
function ParamNum(const S: string): Integer;
|
439
|
+
begin
|
440
|
+
for Result := 1 to ParamCount do
|
441
|
+
if 0=AnsiCompareText(ParamStr(Result), S) then
|
442
|
+
Exit;
|
443
|
+
|
444
|
+
Result := 0;
|
445
|
+
end;
|
446
|
+
|
447
|
+
function ParamPrefixNum(const Prefix: string): Integer;
|
448
|
+
var
|
449
|
+
Len: Integer;
|
450
|
+
begin
|
451
|
+
Len := Length(Prefix);
|
452
|
+
for Result := 1 to ParamCount do
|
453
|
+
if 0=AnsiCompareText(Copy(ParamStr(Result), 1, Len), Prefix) then
|
454
|
+
Exit;
|
455
|
+
|
456
|
+
Result := 0;
|
457
|
+
end;
|
458
|
+
|
459
|
+
function Param(const S: string): Boolean;
|
460
|
+
begin
|
461
|
+
Result := ParamNum(S) > 0;
|
462
|
+
end;
|
463
|
+
|
464
|
+
function ParamPrefix(const Prefix: string): Boolean;
|
465
|
+
begin
|
466
|
+
Result := ParamPrefixNum(Prefix) > 0;
|
467
|
+
end;
|
468
|
+
|
469
|
+
function GetParam(const Prefix: string = ''; const Default: string = ''): string;
|
470
|
+
var
|
471
|
+
i: Integer;
|
472
|
+
begin
|
473
|
+
Result := Default;
|
474
|
+
|
475
|
+
if Prefix = '' then begin
|
476
|
+
Result := ParamStr(1);
|
477
|
+
Exit; end;
|
478
|
+
|
479
|
+
i := ParamPrefixNum(Prefix);
|
480
|
+
if i > 0 then
|
481
|
+
Result := Copy(ParamStr(i), Length(Prefix) + 1, MaxInt);
|
482
|
+
end;
|
483
|
+
|
484
|
+
function GetMyDir(FullPath: Boolean = False): string;
|
485
|
+
var
|
486
|
+
Buffer: array[0..260] of Char;
|
487
|
+
begin
|
488
|
+
Result := '';
|
489
|
+
SetString(Result, Buffer, GetModuleFileName(0, Buffer, SizeOf(Buffer)));
|
490
|
+
if FullPath then
|
491
|
+
Result := GetFileNew(Result);
|
492
|
+
Result := ExtractPath(Result);
|
493
|
+
end;
|
494
|
+
|
495
|
+
function WinDir: string;
|
496
|
+
var
|
497
|
+
Res: PChar;
|
498
|
+
begin
|
499
|
+
Result := '\';
|
500
|
+
GetMem(Res, MAX_PATH);
|
501
|
+
GetWindowsDirectory(Res, MAX_PATH);
|
502
|
+
Result := Res + '\';
|
503
|
+
FreeMem(Res, MAX_PATH);
|
504
|
+
end;
|
505
|
+
|
506
|
+
function SysDir: string;
|
507
|
+
var
|
508
|
+
Res: PChar;
|
509
|
+
begin
|
510
|
+
Result := '\';
|
511
|
+
GetMem(Res, MAX_PATH);
|
512
|
+
GetSystemDirectory(Res, MAX_PATH);
|
513
|
+
Result := Res + '\';
|
514
|
+
FreeMem(Res, MAX_PATH);
|
515
|
+
end;
|
516
|
+
|
517
|
+
function UserName: string;
|
518
|
+
var
|
519
|
+
Len: Cardinal;
|
520
|
+
Res: PChar;
|
521
|
+
begin
|
522
|
+
Result := '';
|
523
|
+
GetMem(Res, MAX_PATH);
|
524
|
+
Len := MAX_PATH;
|
525
|
+
GetUserName(Res, Len);
|
526
|
+
Result := Res;
|
527
|
+
FreeMem(Res, MAX_PATH);
|
528
|
+
end;
|
529
|
+
|
530
|
+
function FirstChar(const S: string): Char;
|
531
|
+
begin
|
532
|
+
if s = '' then
|
533
|
+
Result := #0
|
534
|
+
else
|
535
|
+
Result := s[1];
|
536
|
+
end;
|
537
|
+
|
538
|
+
function LastChar(const S: string): Char;
|
539
|
+
begin
|
540
|
+
if s = '' then
|
541
|
+
Result := #0
|
542
|
+
else
|
543
|
+
Result := s[Length(s)];
|
544
|
+
end;
|
545
|
+
|
546
|
+
function CharPos(C: Char; const S: string; Offset: Integer = 1): Integer;
|
547
|
+
var
|
548
|
+
MaxPosToSearch: Integer;
|
549
|
+
begin
|
550
|
+
Result := Offset;
|
551
|
+
MaxPosToSearch := Length(S);
|
552
|
+
|
553
|
+
while Result <= MaxPosToSearch do begin
|
554
|
+
if S[Result] = C then
|
555
|
+
Exit;
|
556
|
+
Inc(Result);
|
557
|
+
end;
|
558
|
+
|
559
|
+
Result := 0;
|
560
|
+
end;
|
561
|
+
|
562
|
+
function CharPos(C: TCharSet; const S: string; Offset: Integer = 1): Integer;
|
563
|
+
var
|
564
|
+
MaxPosToSearch: Integer;
|
565
|
+
begin
|
566
|
+
Result := Offset;
|
567
|
+
MaxPosToSearch := Length(S);
|
568
|
+
|
569
|
+
while Result <= MaxPosToSearch do begin
|
570
|
+
if S[Result] in C then
|
571
|
+
Exit;
|
572
|
+
Inc(Result);
|
573
|
+
end;
|
574
|
+
|
575
|
+
Result := 0;
|
576
|
+
end;
|
577
|
+
|
578
|
+
function CharPosR(C: Char; const S: string; Offset: Integer = -1): Integer;
|
579
|
+
begin
|
580
|
+
if Offset < 0 then
|
581
|
+
Result := Length(S) + 1 - Offset
|
582
|
+
else
|
583
|
+
Result := Offset;
|
584
|
+
if Result > Length(S) then
|
585
|
+
Result := Length(S);
|
586
|
+
|
587
|
+
while Result > 0 do begin
|
588
|
+
if S[Result] = C then
|
589
|
+
Exit;
|
590
|
+
Dec(Result);
|
591
|
+
end;
|
592
|
+
end;
|
593
|
+
|
594
|
+
function PosEx(const SubStr, S: string; Offset: Integer = 1): Integer;
|
595
|
+
var
|
596
|
+
MaxPosToSearch, LenSubStr, i: Integer;
|
597
|
+
begin
|
598
|
+
if SubStr = '' then begin
|
599
|
+
Result := 0;
|
600
|
+
Exit; end;
|
601
|
+
|
602
|
+
if Offset < 1 then
|
603
|
+
Result := 1
|
604
|
+
else
|
605
|
+
Result := Offset;
|
606
|
+
|
607
|
+
LenSubStr := Length(SubStr);
|
608
|
+
MaxPosToSearch := Length(S) - LenSubStr + 1;
|
609
|
+
|
610
|
+
while Result <= MaxPosToSearch do begin
|
611
|
+
if S[Result] = SubStr[1] then begin
|
612
|
+
i := 1;
|
613
|
+
|
614
|
+
while (i < LenSubStr)
|
615
|
+
and (S[Result + i] = SubStr[i + 1]) do
|
616
|
+
Inc(i);
|
617
|
+
|
618
|
+
if i = LenSubStr then
|
619
|
+
Exit;
|
620
|
+
end;
|
621
|
+
Inc(Result);
|
622
|
+
end;
|
623
|
+
|
624
|
+
Result := 0;
|
625
|
+
end;
|
626
|
+
|
627
|
+
function PosExText(const SubStr, S: string; Offset: Integer = 1): Integer;
|
628
|
+
var
|
629
|
+
MaxPosToSearch, LenSubStr, i: Integer;
|
630
|
+
|
631
|
+
function SameChar(a, b: Char): Boolean;
|
632
|
+
begin
|
633
|
+
Result := UpCase(a) = UpCase(b)
|
634
|
+
end;
|
635
|
+
|
636
|
+
begin
|
637
|
+
if SubStr = '' then begin
|
638
|
+
Result := 0;
|
639
|
+
Exit; end;
|
640
|
+
|
641
|
+
if Offset < 1 then
|
642
|
+
Result := 1
|
643
|
+
else
|
644
|
+
Result := Offset;
|
645
|
+
|
646
|
+
LenSubStr := Length(SubStr);
|
647
|
+
MaxPosToSearch := Length(S) - LenSubStr + 1;
|
648
|
+
|
649
|
+
while Result <= MaxPosToSearch do begin
|
650
|
+
if SameChar(S[Result], SubStr[1]) then begin
|
651
|
+
i := 1;
|
652
|
+
|
653
|
+
while (i < LenSubStr)
|
654
|
+
and (SameChar(S[Result + i], SubStr[i + 1])) do
|
655
|
+
Inc(i);
|
656
|
+
|
657
|
+
if i = LenSubStr then
|
658
|
+
Exit;
|
659
|
+
end;
|
660
|
+
Inc(Result);
|
661
|
+
end;
|
662
|
+
|
663
|
+
Result := 0;
|
664
|
+
end;
|
665
|
+
|
666
|
+
function PosExAnsiText(const SubStr, S: string; Offset: Integer = 1): Integer;
|
667
|
+
var
|
668
|
+
MaxPosToSearch, LenSubStr, i: Integer;
|
669
|
+
|
670
|
+
function SameChar(a, b: Char): Boolean;
|
671
|
+
begin
|
672
|
+
Result := CharLower(PChar(a)) = CharLower(PChar(b));
|
673
|
+
end;
|
674
|
+
|
675
|
+
begin
|
676
|
+
if SubStr = '' then begin
|
677
|
+
Result := 0;
|
678
|
+
Exit; end;
|
679
|
+
|
680
|
+
if Offset < 1 then
|
681
|
+
Result := 1
|
682
|
+
else
|
683
|
+
Result := Offset;
|
684
|
+
|
685
|
+
LenSubStr := Length(SubStr);
|
686
|
+
MaxPosToSearch := Length(S) - LenSubStr + 1;
|
687
|
+
|
688
|
+
while Result <= MaxPosToSearch do begin
|
689
|
+
if SameChar(S[Result], SubStr[1]) then begin
|
690
|
+
i := 1;
|
691
|
+
|
692
|
+
while (i < LenSubStr)
|
693
|
+
and (SameChar(S[Result + i], SubStr[i + 1])) do
|
694
|
+
Inc(i);
|
695
|
+
|
696
|
+
if i = LenSubStr then
|
697
|
+
Exit;
|
698
|
+
end;
|
699
|
+
Inc(Result);
|
700
|
+
end;
|
701
|
+
|
702
|
+
Result := 0;
|
703
|
+
end;
|
704
|
+
|
705
|
+
function UntilChar(const S: string; Brake: Char): string;
|
706
|
+
var
|
707
|
+
p: Integer;
|
708
|
+
begin
|
709
|
+
p := CharPos(Brake, S);
|
710
|
+
|
711
|
+
if p > 0 then
|
712
|
+
Result := Copy(S, 1, p - 1)
|
713
|
+
else
|
714
|
+
Result := S;
|
715
|
+
end;
|
716
|
+
|
717
|
+
function UntilChar(const S: string; Brake: TCharSet): string;
|
718
|
+
var
|
719
|
+
p: Integer;
|
720
|
+
begin
|
721
|
+
Result := '';
|
722
|
+
p := CharPos(Brake, S);
|
723
|
+
|
724
|
+
if p > 0 then
|
725
|
+
Result := Copy(S, 1, p - 1)
|
726
|
+
else
|
727
|
+
Result := S;
|
728
|
+
end;
|
729
|
+
|
730
|
+
function UntilLastChar(const S: string; Brake: Char;
|
731
|
+
IgnoreNoBrake: Boolean = True): string;
|
732
|
+
var
|
733
|
+
p: Integer;
|
734
|
+
begin
|
735
|
+
Result := '';
|
736
|
+
p := CharPosR(Brake, S);
|
737
|
+
|
738
|
+
if p > 0 then
|
739
|
+
Result := Copy(S, 1, p - 1)
|
740
|
+
else if IgnoreNoBrake then
|
741
|
+
Result := S;
|
742
|
+
end;
|
743
|
+
|
744
|
+
function FromChar(const S: string; Brake: Char): string;
|
745
|
+
var
|
746
|
+
p: Integer;
|
747
|
+
begin
|
748
|
+
Result := '';
|
749
|
+
p := CharPos(Brake, S);
|
750
|
+
|
751
|
+
if p > 0 then
|
752
|
+
Result := Copy(S, p + 1, Length(S) - p);
|
753
|
+
end;
|
754
|
+
|
755
|
+
function FromChar(const S: string; Brake: TCharSet): string;
|
756
|
+
var
|
757
|
+
p: Integer;
|
758
|
+
begin
|
759
|
+
Result := '';
|
760
|
+
p := CharPos(Brake, S);
|
761
|
+
|
762
|
+
if p > 0 then
|
763
|
+
Result := Copy(S, p + 1, Length(S) - p);
|
764
|
+
end;
|
765
|
+
|
766
|
+
function FromLastChar(const S: string; Brake: Char;
|
767
|
+
IgnoreNoBrake: Boolean = False): string;
|
768
|
+
var
|
769
|
+
p: Integer;
|
770
|
+
begin
|
771
|
+
Result := '';
|
772
|
+
p := CharPosR(Brake, S);
|
773
|
+
|
774
|
+
if p > 0 then
|
775
|
+
Result := Copy(S, p + 1, Length(S) - p)
|
776
|
+
else if IgnoreNoBrake then
|
777
|
+
Result := S;
|
778
|
+
end;
|
779
|
+
|
780
|
+
function BetweenChars(const S: string; Start, Finish: Char;
|
781
|
+
Inclusive: Boolean = False): string;
|
782
|
+
var
|
783
|
+
p, fin: Integer;
|
784
|
+
begin
|
785
|
+
Result := '';
|
786
|
+
|
787
|
+
p := CharPos(Start, S);
|
788
|
+
if p = 0 then
|
789
|
+
Exit;
|
790
|
+
|
791
|
+
fin := CharPos(Finish, S, p + 1);
|
792
|
+
if fin = 0 then
|
793
|
+
Exit;
|
794
|
+
|
795
|
+
if not Inclusive then begin
|
796
|
+
Inc(p);
|
797
|
+
Dec(fin);
|
798
|
+
end;
|
799
|
+
|
800
|
+
Result := Copy(S, p, fin - p + 1);
|
801
|
+
end;
|
802
|
+
|
803
|
+
function UntilStr(const S: string; Brake: string): string;
|
804
|
+
var
|
805
|
+
p: Integer;
|
806
|
+
begin
|
807
|
+
if Length(Brake) = 1 then begin
|
808
|
+
Result := UntilChar(S, Brake[1]);
|
809
|
+
Exit; end;
|
810
|
+
|
811
|
+
p := PosEx(Brake, S);
|
812
|
+
|
813
|
+
if p > 0 then
|
814
|
+
Result := Copy(S, 1, p - 1)
|
815
|
+
else
|
816
|
+
Result := S;
|
817
|
+
end;
|
818
|
+
|
819
|
+
function FromStr(const S: string; Brake: string): string;
|
820
|
+
var
|
821
|
+
p: Integer;
|
822
|
+
begin
|
823
|
+
if Length(Brake) = 1 then begin
|
824
|
+
Result := FromChar(S, Brake[1]);
|
825
|
+
Exit; end;
|
826
|
+
|
827
|
+
Result := '';
|
828
|
+
p := PosEx(Brake, s);
|
829
|
+
|
830
|
+
if p > 0 then begin
|
831
|
+
Inc(p, Length(Brake));
|
832
|
+
Result := Copy(S, p, Length(S) - p + 1);
|
833
|
+
end;
|
834
|
+
end;
|
835
|
+
|
836
|
+
function StringWrap(const S: string; Width: Integer; const LineEnd: string = EOL): string;
|
837
|
+
var
|
838
|
+
i: Integer;
|
839
|
+
begin
|
840
|
+
Result := '';
|
841
|
+
if (S = '') or (Width < 1) then
|
842
|
+
Exit;
|
843
|
+
|
844
|
+
i := 1;
|
845
|
+
while True do begin
|
846
|
+
Result := Result + Copy(S, i, Width);
|
847
|
+
Inc(i, Width);
|
848
|
+
if i <= Length(S) then
|
849
|
+
Result := Result + LineEnd
|
850
|
+
else
|
851
|
+
Exit;
|
852
|
+
end;
|
853
|
+
end;
|
854
|
+
|
855
|
+
function Split(const S, Separator: string; IgnoreMultiSep: Boolean = True;
|
856
|
+
MinCount: Integer = 0): TStrA;
|
857
|
+
var
|
858
|
+
p, fin, SepLen: Integer;
|
859
|
+
|
860
|
+
procedure Add(const S: string);
|
861
|
+
begin
|
862
|
+
if IgnoreMultiSep and (S = '') then
|
863
|
+
Exit;
|
864
|
+
SetLength(Result, Length(Result) + 1);
|
865
|
+
Result[High(Result)] := S;
|
866
|
+
end;
|
867
|
+
|
868
|
+
begin
|
869
|
+
if S = '' then begin
|
870
|
+
if Length(Result) < MinCount then
|
871
|
+
SetLength(Result, MinCount);
|
872
|
+
Exit; end;
|
873
|
+
|
874
|
+
Result := nil;
|
875
|
+
SepLen := Length(Separator);
|
876
|
+
|
877
|
+
p := 1;
|
878
|
+
fin := PosEx(Separator, S);
|
879
|
+
while fin > 0 do begin
|
880
|
+
Add(Copy(S, p, fin - p));
|
881
|
+
p := fin + SepLen;
|
882
|
+
fin := PosEx(Separator, S, p);
|
883
|
+
end;
|
884
|
+
Add(Copy(S, p, Length(S) - p + 1));
|
885
|
+
|
886
|
+
if Length(Result) < MinCount then
|
887
|
+
SetLength(Result, MinCount);
|
888
|
+
end;
|
889
|
+
|
890
|
+
procedure Split(const S, Separator: string; Strings: TStrings;
|
891
|
+
IgnoreMultiSep: Boolean = True);
|
892
|
+
var
|
893
|
+
p, fin, SepLen: Integer;
|
894
|
+
|
895
|
+
procedure Add(const S: string);
|
896
|
+
begin
|
897
|
+
if IgnoreMultiSep and (S = '') then
|
898
|
+
Exit;
|
899
|
+
Strings.Add(S);
|
900
|
+
end;
|
901
|
+
|
902
|
+
begin
|
903
|
+
if S = '' then
|
904
|
+
Exit;
|
905
|
+
|
906
|
+
Strings.BeginUpdate;
|
907
|
+
SepLen := Length(Separator);
|
908
|
+
p := 1;
|
909
|
+
fin := PosEx(Separator, S);
|
910
|
+
while fin > 0 do begin
|
911
|
+
Add(Copy(S, p, fin - p));
|
912
|
+
p := fin + SepLen;
|
913
|
+
fin := PosEx(Separator, S, p);
|
914
|
+
end;
|
915
|
+
Add(Copy(S, p, Length(S) - p + 1));
|
916
|
+
Strings.EndUpdate;
|
917
|
+
end;
|
918
|
+
|
919
|
+
function Split(const S: string; Separators: TCharSet;
|
920
|
+
IgnoreMultiSep: Boolean = True; MinCount: Integer = 0): TStrA;
|
921
|
+
var
|
922
|
+
p, fin: Integer;
|
923
|
+
|
924
|
+
procedure Add(const S: string);
|
925
|
+
begin
|
926
|
+
if IgnoreMultiSep and (S = '') then
|
927
|
+
Exit;
|
928
|
+
SetLength(Result, Length(Result) + 1);
|
929
|
+
Result[High(Result)] := S;
|
930
|
+
end;
|
931
|
+
|
932
|
+
begin
|
933
|
+
if S = '' then begin
|
934
|
+
if Length(Result) < MinCount then
|
935
|
+
SetLength(Result, MinCount);
|
936
|
+
Exit; end;
|
937
|
+
|
938
|
+
Result := nil;
|
939
|
+
|
940
|
+
p := 1;
|
941
|
+
fin := CharPos(Separators, S);
|
942
|
+
while fin > 0 do begin
|
943
|
+
Add(Copy(S, p, fin - p));
|
944
|
+
p := fin + 1;
|
945
|
+
fin := CharPos(Separators, S, p);
|
946
|
+
end;
|
947
|
+
Add(Copy(S, p, Length(S) - p + 1));
|
948
|
+
|
949
|
+
if Length(Result) < MinCount then
|
950
|
+
SetLength(Result, MinCount);
|
951
|
+
end;
|
952
|
+
|
953
|
+
procedure TileStr(const S: string; BrakeStart: Integer; BrakeEnd: Integer;
|
954
|
+
out Left, Right: string);
|
955
|
+
begin
|
956
|
+
Left := Copy(S, 1, BrakeStart-1);
|
957
|
+
Right := Copy(S, BrakeEnd + 1, MaxInt);
|
958
|
+
end;
|
959
|
+
|
960
|
+
function Join(Strings: TStrings; Separator: string = ' '): string;
|
961
|
+
var
|
962
|
+
i, imax: Integer;
|
963
|
+
begin
|
964
|
+
Result := '';
|
965
|
+
imax := Strings.Count-1;
|
966
|
+
for i := 0 to imax do begin
|
967
|
+
Result := Result + Strings[i];
|
968
|
+
if i < imax then
|
969
|
+
Result := Result + Separator;
|
970
|
+
end;
|
971
|
+
end;
|
972
|
+
|
973
|
+
function Join(StrA: TStrA; Separator: string = ' '): string; overload;
|
974
|
+
var
|
975
|
+
i: Integer;
|
976
|
+
begin
|
977
|
+
Result := '';
|
978
|
+
for i := 0 to High(StrA) do begin
|
979
|
+
Result := Result + StrA[i];
|
980
|
+
if i < High(StrA) then
|
981
|
+
Result := Result + Separator;
|
982
|
+
end;
|
983
|
+
end;
|
984
|
+
|
985
|
+
function MulStr(const S: string; Count: Integer): string;
|
986
|
+
var
|
987
|
+
P: PChar;
|
988
|
+
Len, i: Integer;
|
989
|
+
begin
|
990
|
+
Result := '';
|
991
|
+
if Count = 0 then
|
992
|
+
Exit;
|
993
|
+
|
994
|
+
Len := Length(S);
|
995
|
+
SetLength(Result, Len * Count);
|
996
|
+
|
997
|
+
P := Pointer(Result);
|
998
|
+
for i := 1 to Count do begin
|
999
|
+
Move(Pointer(S)^, P^, Len);
|
1000
|
+
Inc(P, Len);
|
1001
|
+
end;
|
1002
|
+
end;
|
1003
|
+
|
1004
|
+
function AlignR(const S: string; Width: Integer; Filler: Char = ' '): string;
|
1005
|
+
begin
|
1006
|
+
Result := MulStr(Filler, Width - Length(S)) + S;
|
1007
|
+
end;
|
1008
|
+
|
1009
|
+
function MaxStr(const S: string; MaxLen: Integer): string;
|
1010
|
+
var
|
1011
|
+
Len: Integer;
|
1012
|
+
begin
|
1013
|
+
Len := Length(S);
|
1014
|
+
if Len <= MaxLen then begin
|
1015
|
+
Result := S;
|
1016
|
+
Exit end;
|
1017
|
+
|
1018
|
+
Result := Copy(S, 1, MaxLen - 3) + '...';
|
1019
|
+
end;
|
1020
|
+
|
1021
|
+
function TrimAll(const S: string): string;
|
1022
|
+
var
|
1023
|
+
i: Integer;
|
1024
|
+
begin
|
1025
|
+
for i := 1 to Length(S) do
|
1026
|
+
if S[i] > #32 then
|
1027
|
+
Result := Result + S[i];
|
1028
|
+
end;
|
1029
|
+
|
1030
|
+
function ControlChar(C: Char): Boolean;
|
1031
|
+
begin
|
1032
|
+
Result := C in StrangeChars;
|
1033
|
+
end;
|
1034
|
+
|
1035
|
+
function FriendlyChar(C: Char): Char;
|
1036
|
+
begin
|
1037
|
+
case C of
|
1038
|
+
#0: Result := '.';
|
1039
|
+
#1..#31: Result := '?';
|
1040
|
+
#255: Result := '#';
|
1041
|
+
else
|
1042
|
+
Result := C;
|
1043
|
+
end;
|
1044
|
+
end;
|
1045
|
+
|
1046
|
+
function FriendlyStr(const S: string): string;
|
1047
|
+
var
|
1048
|
+
i: Integer;
|
1049
|
+
begin
|
1050
|
+
SetLength(Result, Length(S));
|
1051
|
+
for i := 1 to Length(S) do
|
1052
|
+
Result[i] := FriendlyChar(S[i]);
|
1053
|
+
end;
|
1054
|
+
|
1055
|
+
function FriendlyStr(a: TByteA): string;
|
1056
|
+
var
|
1057
|
+
i: Integer;
|
1058
|
+
begin
|
1059
|
+
SetLength(Result, Length(a));
|
1060
|
+
for i := 0 to High(a) do
|
1061
|
+
Result[i + 1] := FriendlyChar(Char(a[i]));
|
1062
|
+
end;
|
1063
|
+
|
1064
|
+
function Quote(const S: string; Quoter: Char = '"'): string;
|
1065
|
+
begin
|
1066
|
+
Result := S;
|
1067
|
+
|
1068
|
+
if FirstChar(S) <> Quoter then
|
1069
|
+
Result := Quoter + Result;
|
1070
|
+
|
1071
|
+
if LastChar(S) <> Quoter then
|
1072
|
+
Result := Result + Quoter;
|
1073
|
+
end;
|
1074
|
+
|
1075
|
+
function DeQuote(const S: string): string;
|
1076
|
+
begin
|
1077
|
+
Result := '';
|
1078
|
+
if Length(S) > 2 then
|
1079
|
+
Result := Copy(S, 2, Length(S) - 2);
|
1080
|
+
end;
|
1081
|
+
|
1082
|
+
function UnQuote(const S: string): string;
|
1083
|
+
var
|
1084
|
+
Start, Len: Integer;
|
1085
|
+
begin
|
1086
|
+
Start := 1;
|
1087
|
+
Len := Length(S);
|
1088
|
+
|
1089
|
+
if (S <> '') and (S[1] in ([#0..#32] + QuoteChars)) then begin
|
1090
|
+
if (LastChar(S) = S[1]) then
|
1091
|
+
Dec(Len);
|
1092
|
+
Inc(Start);
|
1093
|
+
end;
|
1094
|
+
|
1095
|
+
Result := Copy(S, Start, Len - Start + 1);
|
1096
|
+
end;
|
1097
|
+
|
1098
|
+
function StrNumerus(const Value: Integer; const Singular, Plural: string;
|
1099
|
+
const Zero: string = '0'): string;
|
1100
|
+
begin
|
1101
|
+
if Abs(Value) = 1 then
|
1102
|
+
Result := IntToStr(Value) + ' ' + Singular
|
1103
|
+
else if Value = 0 then
|
1104
|
+
Result := Zero + ' ' + Plural
|
1105
|
+
else
|
1106
|
+
Result := IntToStr(Value) + ' ' + Plural;
|
1107
|
+
end;
|
1108
|
+
|
1109
|
+
function MakeStr(const Items: array of const; Separator: string = ''): string;
|
1110
|
+
const
|
1111
|
+
BoolStrings: array[Boolean] of string = ('False', 'True');
|
1112
|
+
|
1113
|
+
var
|
1114
|
+
i: Integer;
|
1115
|
+
|
1116
|
+
function StrOfP(P: Pointer): string;
|
1117
|
+
begin
|
1118
|
+
if P = nil then
|
1119
|
+
Result := '[nil]'
|
1120
|
+
else
|
1121
|
+
Result := '[' + IntToStr(Cardinal(P)) + ']';
|
1122
|
+
end;
|
1123
|
+
|
1124
|
+
procedure Add(const S: string);
|
1125
|
+
begin
|
1126
|
+
Result := Result + s + Separator;
|
1127
|
+
end;
|
1128
|
+
|
1129
|
+
begin
|
1130
|
+
Result := '';
|
1131
|
+
for i := 0 to High(Items) do
|
1132
|
+
with Items[i] do
|
1133
|
+
case VType of
|
1134
|
+
vtString: Add(VString^);
|
1135
|
+
vtInteger: Add(IntToStr(VInteger));
|
1136
|
+
vtBoolean: Add(BoolStrings[VBoolean]);
|
1137
|
+
vtChar: Add(VChar);
|
1138
|
+
vtPChar: Add(VPChar);
|
1139
|
+
vtExtended: Add(FloatToStr(VExtended^));
|
1140
|
+
vtObject: if VObject is TComponent then
|
1141
|
+
Add(TComponent(VObject).Name)
|
1142
|
+
else
|
1143
|
+
Add(VObject.ClassName);
|
1144
|
+
vtClass: Add(VClass.ClassName);
|
1145
|
+
vtAnsiString: Add(string(VAnsiString));
|
1146
|
+
vtCurrency: Add(CurrToStr(VCurrency^));
|
1147
|
+
vtInt64: Add(IntToStr(VInt64^));
|
1148
|
+
vtVariant: Add(string(VVariant^));
|
1149
|
+
|
1150
|
+
vtWideChar: Add(VWideChar);
|
1151
|
+
vtPWideChar: Add(VPWideChar);
|
1152
|
+
vtInterface: Add(StrOfP(VInterface));
|
1153
|
+
vtPointer: Add(StrOfP(VPointer));
|
1154
|
+
vtWideString: Add(WideString(VWideString));
|
1155
|
+
end;
|
1156
|
+
if Result <> '' then
|
1157
|
+
SetLength(result, Length(Result) - Length(Separator));
|
1158
|
+
end;
|
1159
|
+
|
1160
|
+
procedure ShowText(const Items: array of const; Separator: string = '');
|
1161
|
+
var
|
1162
|
+
Text: string;
|
1163
|
+
begin
|
1164
|
+
Text := MakeStr(Items, Separator);
|
1165
|
+
|
1166
|
+
MessageBox(0, PChar(Text), 'Info', MB_OK and MB_APPLMODAL);
|
1167
|
+
end;
|
1168
|
+
|
1169
|
+
function DeleteChars(const S: string; C: Char): string;
|
1170
|
+
var
|
1171
|
+
i: Integer;
|
1172
|
+
begin
|
1173
|
+
Result := '';
|
1174
|
+
for i := 1 to Length(S) do
|
1175
|
+
if S[i] <> C then
|
1176
|
+
Result := Result + S[i];
|
1177
|
+
end;
|
1178
|
+
|
1179
|
+
function DeleteChars(const S: string; C: TCharSet): string;
|
1180
|
+
var
|
1181
|
+
i: Integer;
|
1182
|
+
begin
|
1183
|
+
Result := '';
|
1184
|
+
for i := 1 to Length(S) do
|
1185
|
+
if not (S[i] in C) then
|
1186
|
+
Result := Result + S[i];
|
1187
|
+
end;
|
1188
|
+
|
1189
|
+
function ExtractChars(const S: string; C: TCharSet): string;
|
1190
|
+
var
|
1191
|
+
i: Integer;
|
1192
|
+
begin
|
1193
|
+
Result := '';
|
1194
|
+
for i := 1 to Length(S) do
|
1195
|
+
if S[i] in C then
|
1196
|
+
Result := Result + S[i];
|
1197
|
+
end;
|
1198
|
+
|
1199
|
+
function CharCount(const S: string; C: Char): Integer;
|
1200
|
+
var
|
1201
|
+
i: Integer;
|
1202
|
+
begin
|
1203
|
+
Result := 0;
|
1204
|
+
for i := 1 to Length(S) do
|
1205
|
+
if S[i] = C then
|
1206
|
+
Inc(Result);
|
1207
|
+
end;
|
1208
|
+
|
1209
|
+
function StrAtPos(const S: string; Pos: Integer; const Str: string): Boolean;
|
1210
|
+
begin
|
1211
|
+
Result := (Str <> '') and (Str = Copy(S, Pos, Length(Str)));
|
1212
|
+
end;
|
1213
|
+
|
1214
|
+
function TextAtPos(const S: string; Pos: Integer; const Text: string): Boolean;
|
1215
|
+
begin
|
1216
|
+
Result := (Text <> '') and SameText(Text, Copy(S, Pos, Length(Text)));
|
1217
|
+
end;
|
1218
|
+
|
1219
|
+
function StrAtBegin(const S, Str: string): Boolean;
|
1220
|
+
begin
|
1221
|
+
Result := StrAtPos(S, 1, Str);
|
1222
|
+
end;
|
1223
|
+
|
1224
|
+
function TextAtBegin(const S, Text: string): Boolean;
|
1225
|
+
begin
|
1226
|
+
Result := TextAtPos(S, 1, Text);
|
1227
|
+
end;
|
1228
|
+
|
1229
|
+
function CharIn(const S: string; C: Char): Boolean;
|
1230
|
+
var
|
1231
|
+
i: Integer;
|
1232
|
+
begin
|
1233
|
+
Result := True;
|
1234
|
+
for i := 1 to Length(S) do
|
1235
|
+
if S[i] = C then Exit;
|
1236
|
+
Result := False;
|
1237
|
+
end;
|
1238
|
+
|
1239
|
+
function CharIn(const S: string; C: TCharSet): Boolean;
|
1240
|
+
var
|
1241
|
+
i: Integer;
|
1242
|
+
begin
|
1243
|
+
Result := False;
|
1244
|
+
for i := 1 to Length(S) do begin
|
1245
|
+
Result := S[i] in C;
|
1246
|
+
if Result then
|
1247
|
+
Exit;
|
1248
|
+
end;
|
1249
|
+
end;
|
1250
|
+
|
1251
|
+
function StrIn(const S, SubStr: string): Boolean;
|
1252
|
+
begin
|
1253
|
+
Result := PosEx(SubStr, S) > 0;
|
1254
|
+
end;
|
1255
|
+
|
1256
|
+
function StrIn(SL: TStrings; const S: string): Boolean;
|
1257
|
+
var
|
1258
|
+
i: Integer;
|
1259
|
+
begin
|
1260
|
+
Result := False;
|
1261
|
+
for i := 0 to SL.Count-1 do begin
|
1262
|
+
Result := (S = SL[i]);
|
1263
|
+
if Result then
|
1264
|
+
Exit;
|
1265
|
+
end;
|
1266
|
+
end;
|
1267
|
+
|
1268
|
+
function StrIn(A: TStrA; const S: string): Boolean;
|
1269
|
+
var
|
1270
|
+
i: Integer;
|
1271
|
+
begin
|
1272
|
+
Result := False;
|
1273
|
+
for i := Low(A) to High(A) do begin
|
1274
|
+
Result := (S = A[i]);
|
1275
|
+
if Result then
|
1276
|
+
Exit;
|
1277
|
+
end;
|
1278
|
+
end;
|
1279
|
+
|
1280
|
+
function TextIn(const S, Text: string): Boolean;
|
1281
|
+
begin
|
1282
|
+
Result := PosExText(Text, S) > 0;
|
1283
|
+
end;
|
1284
|
+
|
1285
|
+
function TextIn(SL: TStrings; const Text: string): Boolean;
|
1286
|
+
var
|
1287
|
+
i: Integer;
|
1288
|
+
begin
|
1289
|
+
Result := False;
|
1290
|
+
for i := 0 to SL.Count-1 do begin
|
1291
|
+
Result := SameText(Text, SL[i]);
|
1292
|
+
if Result then
|
1293
|
+
Exit;
|
1294
|
+
end;
|
1295
|
+
end;
|
1296
|
+
|
1297
|
+
function TextIn(A: TStrA; const Text: string): Boolean;
|
1298
|
+
var
|
1299
|
+
i: Integer;
|
1300
|
+
begin
|
1301
|
+
Result := False;
|
1302
|
+
for i := Low(A) to High(A) do begin
|
1303
|
+
Result := SameText(Text, A[i]);
|
1304
|
+
if Result then
|
1305
|
+
Exit;
|
1306
|
+
end;
|
1307
|
+
end;
|
1308
|
+
|
1309
|
+
function StrIndex(SL: TStrings; const S: string): Integer;
|
1310
|
+
begin
|
1311
|
+
for Result := 0 to SL.Count-1 do
|
1312
|
+
if S = SL[Result] then
|
1313
|
+
Exit;
|
1314
|
+
Result := -1;
|
1315
|
+
end;
|
1316
|
+
|
1317
|
+
function StrIndex(A: TStrA; const S: string): Integer;
|
1318
|
+
begin
|
1319
|
+
for Result := Low(A) to High(A) do
|
1320
|
+
if S = A[Result] then
|
1321
|
+
Exit;
|
1322
|
+
Result := -1;
|
1323
|
+
end;
|
1324
|
+
|
1325
|
+
function TextIndex(SL: TStrings; const Text: string): Integer;
|
1326
|
+
begin
|
1327
|
+
for Result := 0 to SL.Count-1 do
|
1328
|
+
if SameText(Text, SL[Result]) then
|
1329
|
+
Exit;
|
1330
|
+
Result := -1;
|
1331
|
+
end;
|
1332
|
+
|
1333
|
+
function TextIndex(A: TStrA; const Text: string): Integer;
|
1334
|
+
begin
|
1335
|
+
for Result := Low(A) to High(A) do
|
1336
|
+
if SameText(Text, A[Result]) then
|
1337
|
+
Exit;
|
1338
|
+
Result := -1;
|
1339
|
+
end;
|
1340
|
+
|
1341
|
+
function ReplaceChars(const S: string; Old, New: Char): string;
|
1342
|
+
var
|
1343
|
+
i: Integer;
|
1344
|
+
begin
|
1345
|
+
Result := S;
|
1346
|
+
for i := 1 to Length(Result) do
|
1347
|
+
if Result[i] = Old then
|
1348
|
+
Result[i] := New;
|
1349
|
+
end;
|
1350
|
+
|
1351
|
+
function ReplaceChars(const S: string; Old: TCharSet; New: Char): string;
|
1352
|
+
var
|
1353
|
+
i: Integer;
|
1354
|
+
begin
|
1355
|
+
Result := S;
|
1356
|
+
for i := 1 to Length(Result) do
|
1357
|
+
if Result[i] in Old then
|
1358
|
+
Result[i] := New;
|
1359
|
+
end;
|
1360
|
+
|
1361
|
+
function Replace(const S, Old, New: string): string;
|
1362
|
+
var
|
1363
|
+
oldp, ps: Integer;
|
1364
|
+
begin
|
1365
|
+
ps := 1;
|
1366
|
+
Result := '';
|
1367
|
+
while True do begin
|
1368
|
+
oldp := ps;
|
1369
|
+
ps := PosEx(Old, S, oldp);
|
1370
|
+
if ps = 0 then begin
|
1371
|
+
Result := Result + Copy(S, oldp, Length(S) - oldp + 1);
|
1372
|
+
Exit; end;
|
1373
|
+
Result := Result + Copy(S, oldp, ps - oldp) + New;
|
1374
|
+
Inc(ps, Length(Old));
|
1375
|
+
end;
|
1376
|
+
end;
|
1377
|
+
|
1378
|
+
function SLOfFile(const FileName: string): TStringList;
|
1379
|
+
begin
|
1380
|
+
Result := TStringList.Create;
|
1381
|
+
if FileExists(FileName) then
|
1382
|
+
Result.LoadFromFile(FileName);
|
1383
|
+
end;
|
1384
|
+
|
1385
|
+
function ContainsEmptyLines(SL: TStrings): Boolean;
|
1386
|
+
begin
|
1387
|
+
Result := StrIn(SL, '');
|
1388
|
+
end;
|
1389
|
+
|
1390
|
+
procedure DeleteEmptyLines(SL: TStrings);
|
1391
|
+
var
|
1392
|
+
i: Integer;
|
1393
|
+
begin
|
1394
|
+
i := 0;
|
1395
|
+
while i < SL.Count do begin
|
1396
|
+
if SL[i] = '' then
|
1397
|
+
SL.Delete(i)
|
1398
|
+
else
|
1399
|
+
Inc(i);
|
1400
|
+
end;
|
1401
|
+
end;
|
1402
|
+
|
1403
|
+
procedure DeleteCommentLines(SL: TStrings; const CommentSign: string = '//');
|
1404
|
+
var
|
1405
|
+
i: Integer;
|
1406
|
+
begin
|
1407
|
+
i := 0;
|
1408
|
+
while i < SL.Count do begin
|
1409
|
+
if (SL[i] = '') or (StrAtBegin(TrimLeft(SL[i]), CommentSign)) then
|
1410
|
+
SL.Delete(i)
|
1411
|
+
else
|
1412
|
+
Inc(i);
|
1413
|
+
end;
|
1414
|
+
end;
|
1415
|
+
|
1416
|
+
function FindLine(SL: TStrings; const S: string): Integer;
|
1417
|
+
begin
|
1418
|
+
for Result := 0 to SL.Count-1 do
|
1419
|
+
if TextAtBegin(SL[Result], S) then
|
1420
|
+
Exit;
|
1421
|
+
Result := -1;
|
1422
|
+
end;
|
1423
|
+
|
1424
|
+
procedure QuickSortSL(SL: TStringList);
|
1425
|
+
|
1426
|
+
procedure Sort(l, r: Integer);
|
1427
|
+
var
|
1428
|
+
i,j: Integer;
|
1429
|
+
z,x: string;
|
1430
|
+
begin
|
1431
|
+
i := l;
|
1432
|
+
j := r;
|
1433
|
+
x := SL[(j + i) div 2];
|
1434
|
+
repeat
|
1435
|
+
while SL[i] < x do Inc(i);
|
1436
|
+
while SL[j] > x do Dec(j);
|
1437
|
+
if i <= j then begin
|
1438
|
+
z := SL[i];
|
1439
|
+
SL[i] := SL[j];
|
1440
|
+
SL[j] := z;
|
1441
|
+
Inc(i); Dec(j);
|
1442
|
+
end;
|
1443
|
+
until i > j;
|
1444
|
+
if j > l then Sort(l, j);
|
1445
|
+
if i < r then Sort(i, r);
|
1446
|
+
end;
|
1447
|
+
|
1448
|
+
begin
|
1449
|
+
if SL.Count > 0 then
|
1450
|
+
Sort(0, SL.Count-1);
|
1451
|
+
end;
|
1452
|
+
|
1453
|
+
function IncStrA(StrA: TStrA): Integer;
|
1454
|
+
begin
|
1455
|
+
SetLength(StrA, Length(StrA) + 1);
|
1456
|
+
Result := High(StrA);
|
1457
|
+
end;
|
1458
|
+
|
1459
|
+
function StrOfByteA(a: TByteA): string;
|
1460
|
+
begin
|
1461
|
+
Result := string(Copy(a, 0, Length(a)));
|
1462
|
+
end;
|
1463
|
+
|
1464
|
+
function ByteAOfStr(const S: string): TByteA;
|
1465
|
+
begin
|
1466
|
+
Result := TByteA(Copy(S, 1, Length(s)));
|
1467
|
+
end;
|
1468
|
+
|
1469
|
+
function ByteAOfInt(i: Integer): TByteA;
|
1470
|
+
begin
|
1471
|
+
SetLength(Result, SizeOf(Integer));
|
1472
|
+
Move(i, Pointer(Result)^, SizeOf(Integer));
|
1473
|
+
end;
|
1474
|
+
|
1475
|
+
function IntOfByteA(A: TByteA): Integer;
|
1476
|
+
begin
|
1477
|
+
Result := 0;
|
1478
|
+
Move(Pointer(A)^, Result, Min(Length(A), SizeOf(Integer)));
|
1479
|
+
end;
|
1480
|
+
|
1481
|
+
function ByteAOfHex(const Hex: string): TByteA;
|
1482
|
+
var
|
1483
|
+
i: Integer;
|
1484
|
+
h: string;
|
1485
|
+
begin
|
1486
|
+
h := ExtractChars(Hex, HexadecimalChars);
|
1487
|
+
SetLength(Result, Length(h) div 2);
|
1488
|
+
for i := 0 to High(Result) do
|
1489
|
+
Result[i] := ByteOfHex(Copy(h, (i shl 1) + 1, 2));
|
1490
|
+
end;
|
1491
|
+
|
1492
|
+
function SizeOfFile(const FileName: string): Integer;
|
1493
|
+
var
|
1494
|
+
F: file;
|
1495
|
+
begin
|
1496
|
+
AssignFile(F, FileName);
|
1497
|
+
{$I-}Reset(F, 1);{$I+}
|
1498
|
+
if IOResult = 0 then begin
|
1499
|
+
Result := FileSize(F);
|
1500
|
+
CloseFile(F);
|
1501
|
+
end else
|
1502
|
+
Result := 0;
|
1503
|
+
end;
|
1504
|
+
|
1505
|
+
function FileEx(const FileName: string; AllowFolders: Boolean = False): Boolean;
|
1506
|
+
var
|
1507
|
+
FindData: TWin32FindData;
|
1508
|
+
begin
|
1509
|
+
if FileName = '' then begin
|
1510
|
+
Result := False;
|
1511
|
+
Exit; end;
|
1512
|
+
|
1513
|
+
Result := (AllowFolders and DirectoryExists(FileName)) or
|
1514
|
+
(FindFirstFile(PChar(FileName), FindData) <> INVALID_HANDLE_VALUE);
|
1515
|
+
Result := Result and not CharIn(FileName, WildCards);
|
1516
|
+
Result := Result and (AllowFolders
|
1517
|
+
or ((FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0));
|
1518
|
+
end;
|
1519
|
+
|
1520
|
+
function LWPSolve(const Dir: string): string;
|
1521
|
+
begin
|
1522
|
+
if (Dir <> '') and (Dir[Length(Dir)] = '\') then begin
|
1523
|
+
Result := Copy(Dir, 1, Length(Dir) - 1);
|
1524
|
+
end else
|
1525
|
+
Result := Dir;
|
1526
|
+
end;
|
1527
|
+
|
1528
|
+
function LWPSlash(const Dir: string): string;
|
1529
|
+
begin
|
1530
|
+
if (Dir <> '') and (Dir[Length(Dir)] = '\') then begin
|
1531
|
+
Result := Copy(Dir, 1, Length(Dir));
|
1532
|
+
end else
|
1533
|
+
Result := Dir + '\';
|
1534
|
+
end;
|
1535
|
+
|
1536
|
+
function ExtractDrive(const FileName: string): string;
|
1537
|
+
begin
|
1538
|
+
Result := '';
|
1539
|
+
if (Length(FileName) >= 2) and (FileName[2] = ':') then
|
1540
|
+
Result := UpperCase(FileName[1] + ':\');
|
1541
|
+
end;
|
1542
|
+
|
1543
|
+
function ExtractPath(const FileName: string): string;
|
1544
|
+
var
|
1545
|
+
p: Integer;
|
1546
|
+
begin
|
1547
|
+
p := CharPosR('\', FileName);
|
1548
|
+
if P > 0 then
|
1549
|
+
Result := Copy(FileName, 1, p)
|
1550
|
+
else
|
1551
|
+
Result := FileName;
|
1552
|
+
end;
|
1553
|
+
|
1554
|
+
function ExtractPrefix(const FileName: string): string;
|
1555
|
+
begin
|
1556
|
+
Result := UntilLastChar(ExtractFileName(FileName), '.');
|
1557
|
+
end;
|
1558
|
+
|
1559
|
+
function ExtractSuffix(const FileName: string): string;
|
1560
|
+
begin
|
1561
|
+
Result := FromLastChar(ExtractFileName(FileName), '.');
|
1562
|
+
end;
|
1563
|
+
|
1564
|
+
function SameByteA(const A, B: TByteA): Boolean;
|
1565
|
+
begin
|
1566
|
+
Result := (A = B) or ((Length(A) = Length(B)) and CompareMem(A, B, Length(A)));
|
1567
|
+
end;
|
1568
|
+
|
1569
|
+
function Reverse(A: TByteA): TByteA;
|
1570
|
+
var
|
1571
|
+
i: Integer;
|
1572
|
+
begin
|
1573
|
+
SetLength(Result, Length(A));
|
1574
|
+
|
1575
|
+
for i := 0 to High(A) do
|
1576
|
+
Result[High(Result) - i] := A[i];
|
1577
|
+
end;
|
1578
|
+
|
1579
|
+
function Endian(i: Integer): Integer;
|
1580
|
+
type
|
1581
|
+
EndianArray = packed array[0..3] of Byte;
|
1582
|
+
var
|
1583
|
+
a, b: EndianArray;
|
1584
|
+
begin
|
1585
|
+
a := EndianArray(i);
|
1586
|
+
b[0] := a[3];
|
1587
|
+
b[1] := a[2];
|
1588
|
+
b[2] := a[1];
|
1589
|
+
b[3] := a[0];
|
1590
|
+
Result := Integer(b);
|
1591
|
+
end;
|
1592
|
+
|
1593
|
+
function SaveByteA(Data: TByteA; const FileName: string;
|
1594
|
+
Overwrite: Boolean = True): Boolean;
|
1595
|
+
var
|
1596
|
+
F: file;
|
1597
|
+
begin
|
1598
|
+
if FileExists(FileName) and not Overwrite then begin
|
1599
|
+
Result := False;
|
1600
|
+
Exit end;
|
1601
|
+
|
1602
|
+
AssignFile(F, FileName);
|
1603
|
+
{$I-}Rewrite(F, 1);{$I+}
|
1604
|
+
if IOResult = 0 then begin
|
1605
|
+
if Length(Data) > 0 then
|
1606
|
+
BlockWrite(F, Data[0], Length(Data));
|
1607
|
+
CloseFile(F);
|
1608
|
+
Result := True;
|
1609
|
+
end else
|
1610
|
+
Result := False;
|
1611
|
+
end;
|
1612
|
+
|
1613
|
+
function LoadByteA(const FileName: string): TByteA;
|
1614
|
+
var
|
1615
|
+
F: file;
|
1616
|
+
begin
|
1617
|
+
AssignFile(F, FileName);
|
1618
|
+
{$I-}Reset(F, 1);{$I+}
|
1619
|
+
if IOResult = 0 then begin
|
1620
|
+
SetLength(Result, FileSize(F));
|
1621
|
+
if Length(Result) > 0 then
|
1622
|
+
BlockRead(F, Result[0], FileSize(F));
|
1623
|
+
CloseFile(F);
|
1624
|
+
end else
|
1625
|
+
SetLength(Result, 0);
|
1626
|
+
end;
|
1627
|
+
|
1628
|
+
function IsValidFileName(const FileName: string): Boolean;
|
1629
|
+
begin
|
1630
|
+
Result := (FileName <> '') and not CharIn(FileName, FileNameEnemies)
|
1631
|
+
and CharIn(Trim(FileName), AllChars - ['.']);
|
1632
|
+
end;
|
1633
|
+
|
1634
|
+
function MakeValidFileName(FileName: string; const Default: string = 'File'): string;
|
1635
|
+
begin
|
1636
|
+
if FileName = '' then
|
1637
|
+
FileName := Default;
|
1638
|
+
|
1639
|
+
if CharIn(FileName, FileNameEnemies) then
|
1640
|
+
Result := ReplaceChars(FileName, FileNameEnemies, '_')
|
1641
|
+
else if not CharIn(Trim(FileName), AllChars - ['.']) then
|
1642
|
+
Result := Default
|
1643
|
+
else
|
1644
|
+
Result := FileName;
|
1645
|
+
end;
|
1646
|
+
|
1647
|
+
function IsValidInteger(const S: string): Boolean;
|
1648
|
+
{const
|
1649
|
+
LowInt = '2147483648';
|
1650
|
+
HighInt = '2147483647';
|
1651
|
+
var
|
1652
|
+
len, RealLen, i, o: Integer;
|
1653
|
+
c: Char;
|
1654
|
+
begin
|
1655
|
+
Result := False;
|
1656
|
+
if S = '' then
|
1657
|
+
Exit;
|
1658
|
+
|
1659
|
+
len := Length(S);
|
1660
|
+
o := 1;
|
1661
|
+
|
1662
|
+
if S[1] = '-' then begin
|
1663
|
+
if len = 1 then
|
1664
|
+
Exit;
|
1665
|
+
Inc(o);
|
1666
|
+
while (o <= len) and (S[o] = '0') do
|
1667
|
+
Inc(o);
|
1668
|
+
if o > len then
|
1669
|
+
Exit;
|
1670
|
+
if o < len then begin
|
1671
|
+
RealLen := len - o + 1;
|
1672
|
+
if RealLen > Length(LowInt) then
|
1673
|
+
Exit
|
1674
|
+
else if RealLen = Length(LowInt) then begin
|
1675
|
+
for i := 1 to Length(LowInt) do begin
|
1676
|
+
c := S[i + o - 1];
|
1677
|
+
if (c < '0') or (c > LowInt[i]) then
|
1678
|
+
Exit;
|
1679
|
+
if c in ['0'..Char((Byte(LowInt[i])-1))] then
|
1680
|
+
Break;
|
1681
|
+
end;
|
1682
|
+
Inc(o, i);
|
1683
|
+
end;
|
1684
|
+
end;
|
1685
|
+
end else begin
|
1686
|
+
while (o <= len) and (S[o] = '0') do
|
1687
|
+
Inc(o);
|
1688
|
+
if o <= len then begin
|
1689
|
+
RealLen := len - o + 1;
|
1690
|
+
if RealLen > Length(HighInt) then
|
1691
|
+
Exit
|
1692
|
+
else if RealLen = Length(HighInt) then begin
|
1693
|
+
for i := 1 to Length(HighInt) do begin
|
1694
|
+
c := S[i + o - 1];
|
1695
|
+
if (c < '0') or (c > HighInt[i]) then
|
1696
|
+
Exit;
|
1697
|
+
if c in ['0'..Char((Byte(HighInt[i])-1))] then
|
1698
|
+
Break;
|
1699
|
+
end;
|
1700
|
+
Inc(o, i);
|
1701
|
+
end;
|
1702
|
+
end;
|
1703
|
+
end;
|
1704
|
+
|
1705
|
+
for i := o to len do
|
1706
|
+
if not (S[i] in ['0'..'9']) then
|
1707
|
+
Exit;
|
1708
|
+
|
1709
|
+
Result := True; }
|
1710
|
+
var
|
1711
|
+
i: Int64;
|
1712
|
+
begin
|
1713
|
+
i := StrToInt64Def(S, High(Int64));
|
1714
|
+
Result := (i >= Low(Integer)) and (i <= High(Integer));
|
1715
|
+
end;
|
1716
|
+
|
1717
|
+
function IsValidCardinal(const S: string): Boolean;
|
1718
|
+
{const
|
1719
|
+
HighCard = '4294967295';
|
1720
|
+
var
|
1721
|
+
len, RealLen, i, o: Integer;
|
1722
|
+
begin
|
1723
|
+
Result := False;
|
1724
|
+
if S = '' then
|
1725
|
+
Exit;
|
1726
|
+
|
1727
|
+
len := Length(S);
|
1728
|
+
o := 1;
|
1729
|
+
|
1730
|
+
while (o <= len) and (S[o] = '0') do
|
1731
|
+
Inc(o);
|
1732
|
+
if o <= len then begin
|
1733
|
+
RealLen := len - o + 1;
|
1734
|
+
if RealLen > Length(HighCard) then
|
1735
|
+
Exit
|
1736
|
+
else if RealLen = Length(HighCard) then begin
|
1737
|
+
for i := 1 to Length(HighCard) do begin
|
1738
|
+
if S[i + o - 1] > HighCard[i] then
|
1739
|
+
Exit;
|
1740
|
+
if S[i + o - 1] in ['0'..Char((Byte(HighCard[i])-1))] then
|
1741
|
+
Break;
|
1742
|
+
end;
|
1743
|
+
Inc(o, i);
|
1744
|
+
end;
|
1745
|
+
end;
|
1746
|
+
|
1747
|
+
for i := o to len do
|
1748
|
+
if not (S[i] in ['0'..'9']) then
|
1749
|
+
Exit;
|
1750
|
+
|
1751
|
+
Result := True; }
|
1752
|
+
var
|
1753
|
+
i: Int64;
|
1754
|
+
begin
|
1755
|
+
i := StrToInt64Def(S, -1);
|
1756
|
+
Result := (i >= 0) and (i <= High(Cardinal));
|
1757
|
+
end;
|
1758
|
+
|
1759
|
+
function StrOfBool(flag: Boolean; const TrueStr: string = 'True';
|
1760
|
+
const FalseStr: string = 'False'): string;
|
1761
|
+
begin
|
1762
|
+
if Flag then
|
1763
|
+
Result := TrueStr
|
1764
|
+
else
|
1765
|
+
Result := FalseStr;
|
1766
|
+
end;
|
1767
|
+
|
1768
|
+
function StrOfInt(i: Integer): string;
|
1769
|
+
begin
|
1770
|
+
{ if i = 0 then begin
|
1771
|
+
Result := '0';
|
1772
|
+
Exit end;
|
1773
|
+
|
1774
|
+
while i > 0 do begin
|
1775
|
+
Result := Char(Byte('0') + (i mod 10)) + Result;
|
1776
|
+
i := i div 10;
|
1777
|
+
end;}
|
1778
|
+
Result := IntToStr(i);
|
1779
|
+
end;
|
1780
|
+
|
1781
|
+
function CardOfStr(const S: string): Cardinal;
|
1782
|
+
var
|
1783
|
+
Res: Int64;
|
1784
|
+
begin
|
1785
|
+
Res := StrToInt64Def(S, -1);
|
1786
|
+
if Res > High(Cardinal) then
|
1787
|
+
Res := High(Cardinal)
|
1788
|
+
else if Res < 0 then
|
1789
|
+
Res := 0;
|
1790
|
+
Result := Cardinal(Res);
|
1791
|
+
end;
|
1792
|
+
|
1793
|
+
function HexOrd(Hex: Char): THex;
|
1794
|
+
begin
|
1795
|
+
case Hex of
|
1796
|
+
'0'..'9':
|
1797
|
+
Result := Byte(Hex) - 48;
|
1798
|
+
'A'..'F':
|
1799
|
+
Result := Byte(Hex) - 55;
|
1800
|
+
'a'..'f':
|
1801
|
+
Result := Byte(Hex) - 87;
|
1802
|
+
else
|
1803
|
+
Result := 0;
|
1804
|
+
end;
|
1805
|
+
end;
|
1806
|
+
|
1807
|
+
function ByteOfHex(Hex: THexByteStr): Byte;
|
1808
|
+
begin
|
1809
|
+
Result := (HexOrd(Hex[1]) shl 4) + HexOrd(Hex[2]);
|
1810
|
+
end;
|
1811
|
+
|
1812
|
+
function DecOfHex(const Hex: string): string;
|
1813
|
+
begin
|
1814
|
+
Result := IntToStr(CardOfHex(Hex));
|
1815
|
+
end;
|
1816
|
+
|
1817
|
+
function HexOfByte(b: Byte): THexByteStr;
|
1818
|
+
begin
|
1819
|
+
Result := HexChar[(b and $F0) shr 4]
|
1820
|
+
+ HexChar[ b and $0F ];
|
1821
|
+
end;
|
1822
|
+
|
1823
|
+
{function HexOfCard2(c: Cardinal): string;
|
1824
|
+
var
|
1825
|
+
Data: array[0..(1 shl 4) - 1] of Char;
|
1826
|
+
i: Integer;
|
1827
|
+
begin
|
1828
|
+
for i := 0 to (1 shl 4) - 1 do
|
1829
|
+
if i < 10 then
|
1830
|
+
Data[i] := Char(Ord('0') + i)
|
1831
|
+
else
|
1832
|
+
Data[i] := Char(Ord('A') + i - 10);
|
1833
|
+
|
1834
|
+
Result := Data[(c and (((1 shl (1 shl 2)) - 1) shl (7 shl 2))) shr (7 shl 2)]
|
1835
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (6 shl 2))) shr (6 shl 2)]
|
1836
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (5 shl 2))) shr (5 shl 2)]
|
1837
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (4 shl 2))) shr (4 shl 2)]
|
1838
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (3 shl 2))) shr (3 shl 2)]
|
1839
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (2 shl 2))) shr (2 shl 2)]
|
1840
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (1 shl 2))) shr (1 shl 2)]
|
1841
|
+
+ Data[(c and (((1 shl (1 shl 2)) - 1) shl (0 shl 2))) shr (0 shl 2)];
|
1842
|
+
end; }
|
1843
|
+
|
1844
|
+
function HexOfCard(i: Cardinal): string;
|
1845
|
+
var
|
1846
|
+
a: Cardinal;
|
1847
|
+
begin
|
1848
|
+
Result := '';
|
1849
|
+
while i > 0 do begin
|
1850
|
+
a := i and $F;
|
1851
|
+
Result := HexChar[a] + Result;
|
1852
|
+
i := i shr 4;
|
1853
|
+
end;
|
1854
|
+
end;
|
1855
|
+
|
1856
|
+
function HexOfCard(i: Cardinal; Digits: Integer): string;
|
1857
|
+
var
|
1858
|
+
a: Cardinal;
|
1859
|
+
begin
|
1860
|
+
Result := '';
|
1861
|
+
while i > 0 do begin
|
1862
|
+
a := i and $F;
|
1863
|
+
Result := HexChar[a] + Result;
|
1864
|
+
i := i shr 4;
|
1865
|
+
end;
|
1866
|
+
Result := MulStr('0', Digits - Length(Result)) + Result;
|
1867
|
+
end;
|
1868
|
+
|
1869
|
+
function PascalHexArray(a: TByteA; Name: string): string;
|
1870
|
+
var
|
1871
|
+
i, len: Integer;
|
1872
|
+
begin
|
1873
|
+
Result := 'const' + EOL +
|
1874
|
+
' ' + Name + ': array[0..' + IntToStr(High(a)) + '] of Byte = (';
|
1875
|
+
|
1876
|
+
len := Length(a);
|
1877
|
+
for i := 0 to len-1 do begin
|
1878
|
+
if (i mod 19) = 0 then
|
1879
|
+
Result := Result + EOL + ' ' + ' ';
|
1880
|
+
Result := Result + '$' + HexOfByte(a[i]);
|
1881
|
+
if i < len-1 then
|
1882
|
+
Result := Result + ',';
|
1883
|
+
end;
|
1884
|
+
Result := Result + EOL + ' );';
|
1885
|
+
end;
|
1886
|
+
|
1887
|
+
function HexOfByteA(a: TByteA; Blocks: Integer = 1;
|
1888
|
+
const Splitter: string = ' '): string;
|
1889
|
+
var
|
1890
|
+
i: Integer;
|
1891
|
+
begin
|
1892
|
+
Result := '';
|
1893
|
+
|
1894
|
+
if Blocks > 0 then
|
1895
|
+
for i := 0 to High(a) do begin
|
1896
|
+
Result := Result + HexOfByte(a[i]);
|
1897
|
+
if i < High(a) then
|
1898
|
+
if ((i+1) mod Blocks) = 0 then
|
1899
|
+
Result := Result + Splitter;
|
1900
|
+
end
|
1901
|
+
else
|
1902
|
+
for i := 0 to High(a) do
|
1903
|
+
Result := Result + HexOfByte(a[i]);
|
1904
|
+
end;
|
1905
|
+
|
1906
|
+
function BinOfByteA(a: TByteA; Blocks: Integer = 4;
|
1907
|
+
const Splitter: string = ' '): string;
|
1908
|
+
var
|
1909
|
+
i, max: Integer;
|
1910
|
+
Bit: Boolean;
|
1911
|
+
begin
|
1912
|
+
Result := '';
|
1913
|
+
|
1914
|
+
if Blocks > 0 then begin
|
1915
|
+
max := 8 * (High(a)) + 7;
|
1916
|
+
for i := 0 to max do begin
|
1917
|
+
Bit := 7-(i mod 8) in TBitSet(a[i div 8]);
|
1918
|
+
Result := Result + Char(Byte('0') + Byte(Bit));
|
1919
|
+
if i < max then
|
1920
|
+
if ((i+1) mod Blocks) = 0 then
|
1921
|
+
Result := Result + Splitter;
|
1922
|
+
end;
|
1923
|
+
end else
|
1924
|
+
for i := 0 to High(a) do
|
1925
|
+
Result := Result + Char(Byte('0') + a[i] shr (i and 8));
|
1926
|
+
end;
|
1927
|
+
|
1928
|
+
function CardOfHex(Hex: string): Cardinal;
|
1929
|
+
var
|
1930
|
+
i: Integer;
|
1931
|
+
begin
|
1932
|
+
Result := 0;
|
1933
|
+
Hex := Copy(ExtractChars(Hex, HexadecimalChars), 1, 8);
|
1934
|
+
|
1935
|
+
for i := 1 to Length(Hex) do
|
1936
|
+
if Hex[i] <> '0' then
|
1937
|
+
Inc(Result, HexOrd(Hex[i]) shl ((Length(Hex) - i) shl 2));
|
1938
|
+
end;
|
1939
|
+
|
1940
|
+
function IntOfBin(Bin: string): Cardinal;
|
1941
|
+
var
|
1942
|
+
i: Integer;
|
1943
|
+
begin
|
1944
|
+
Result := 0;
|
1945
|
+
Bin := Copy(ExtractChars(Bin, BinaryChars), 1, 32);
|
1946
|
+
|
1947
|
+
for i := Length(Bin) downto 1 do
|
1948
|
+
if Bin[i] = '1' then
|
1949
|
+
Inc(Result, 1 shl (Length(Bin) - i));
|
1950
|
+
end;
|
1951
|
+
|
1952
|
+
function BinOfInt(n: Cardinal): string;
|
1953
|
+
var
|
1954
|
+
a: Integer;
|
1955
|
+
begin
|
1956
|
+
if n = 0 then begin
|
1957
|
+
Result := '0';
|
1958
|
+
exit; end;
|
1959
|
+
|
1960
|
+
Result := '';
|
1961
|
+
while n > 0 do begin
|
1962
|
+
a := n and 1;
|
1963
|
+
Result := Char(a + Byte('0')) + Result;
|
1964
|
+
n := n shr 1;
|
1965
|
+
end;
|
1966
|
+
end;
|
1967
|
+
|
1968
|
+
function BinOfIntFill(n: Cardinal; MinCount: Integer = 8): string;
|
1969
|
+
var
|
1970
|
+
a: Integer;
|
1971
|
+
begin
|
1972
|
+
if n = 0 then begin
|
1973
|
+
Result := MulStr('0', MinCount);
|
1974
|
+
Exit; end;
|
1975
|
+
|
1976
|
+
Result := '';
|
1977
|
+
while n > 0 do begin
|
1978
|
+
a := n and 1;
|
1979
|
+
Result := Char(a + Byte('0')) + Result;
|
1980
|
+
n := n shr 1;
|
1981
|
+
end;
|
1982
|
+
Result := MulStr('0', MinCount - Length(Result)) + Result;
|
1983
|
+
end;
|
1984
|
+
|
1985
|
+
function BaseNOfInt(I: Cardinal; B: TBaseN): string;
|
1986
|
+
var
|
1987
|
+
a: Integer;
|
1988
|
+
begin
|
1989
|
+
if (B < 2) or (i = 0) then begin
|
1990
|
+
Result := '0';
|
1991
|
+
Exit; end;
|
1992
|
+
|
1993
|
+
Result := '';
|
1994
|
+
while i > 0 do begin
|
1995
|
+
a := i mod B;
|
1996
|
+
Result := BaseNChar[a] + Result;
|
1997
|
+
i := i div B;
|
1998
|
+
end;
|
1999
|
+
end;
|
2000
|
+
|
2001
|
+
function IntOfBaseN(V: string; B: TBaseN): Cardinal;
|
2002
|
+
var
|
2003
|
+
i: Integer;
|
2004
|
+
F: Cardinal;
|
2005
|
+
c: Byte;
|
2006
|
+
begin
|
2007
|
+
Result := 0;
|
2008
|
+
V := TrimAll(V);
|
2009
|
+
F := 1;
|
2010
|
+
for i := Length(V) downto 1 do begin
|
2011
|
+
c := Byte(UpCase(V[i]));
|
2012
|
+
case Char(c) of
|
2013
|
+
'0'..'9': c := c - 48;
|
2014
|
+
'A'..'Z': c := c - 55;
|
2015
|
+
end;
|
2016
|
+
if c < B then
|
2017
|
+
Result := Result + Byte(c) * F;
|
2018
|
+
F := F * B;
|
2019
|
+
end;
|
2020
|
+
end;
|
2021
|
+
|
2022
|
+
function KeepIn(i, Bottom, Top: Variant): Variant;
|
2023
|
+
begin
|
2024
|
+
Result := i;
|
2025
|
+
if Result > Top then
|
2026
|
+
Result := Top
|
2027
|
+
else if Result < Bottom then
|
2028
|
+
Result := Bottom;
|
2029
|
+
end;
|
2030
|
+
|
2031
|
+
function InRange(Value, Bottom, Top: Variant): Boolean;
|
2032
|
+
begin
|
2033
|
+
Result := (Value >= Bottom) and (Value <= Top);
|
2034
|
+
end;
|
2035
|
+
|
2036
|
+
function InStrictRange(Value, Bottom, Top: Variant): Boolean;
|
2037
|
+
begin
|
2038
|
+
Result := (Value > Bottom) and (Value < Top);
|
2039
|
+
end;
|
2040
|
+
|
2041
|
+
function Min(const A, B: Integer): Integer;
|
2042
|
+
begin
|
2043
|
+
if A < B then
|
2044
|
+
Result := A
|
2045
|
+
else
|
2046
|
+
Result := B;
|
2047
|
+
end;
|
2048
|
+
|
2049
|
+
function Min(const A: TIntA): Integer;
|
2050
|
+
var
|
2051
|
+
i: Integer;
|
2052
|
+
begin
|
2053
|
+
Result := 0;
|
2054
|
+
if Length(A) = 0 then
|
2055
|
+
Exit;
|
2056
|
+
|
2057
|
+
Result := A[0];
|
2058
|
+
for i := 1 to High(A) do
|
2059
|
+
if A[i] < Result then
|
2060
|
+
Result := A[i];
|
2061
|
+
end;
|
2062
|
+
|
2063
|
+
function Max(const A, B: Integer): Integer;
|
2064
|
+
begin
|
2065
|
+
if A > B then
|
2066
|
+
Result := A
|
2067
|
+
else
|
2068
|
+
Result := B;
|
2069
|
+
end;
|
2070
|
+
|
2071
|
+
function Max(const A: TIntA): Integer;
|
2072
|
+
var
|
2073
|
+
i: Integer;
|
2074
|
+
begin
|
2075
|
+
Result := 0;
|
2076
|
+
if Length(A) = 0 then
|
2077
|
+
Exit;
|
2078
|
+
|
2079
|
+
Result := A[0];
|
2080
|
+
for i := 1 to High(A) do
|
2081
|
+
if A[i] > Result then
|
2082
|
+
Result := A[i];
|
2083
|
+
end;
|
2084
|
+
|
2085
|
+
function RangesOfStr(const S: string): TRanges;
|
2086
|
+
var
|
2087
|
+
SL: TStringList;
|
2088
|
+
r, b, t: string;
|
2089
|
+
i, p: Integer;
|
2090
|
+
|
2091
|
+
function TryStrToCard(const S: string; out Value: Cardinal): Boolean;
|
2092
|
+
var
|
2093
|
+
E: Integer;
|
2094
|
+
begin
|
2095
|
+
Val(S, Value, E);
|
2096
|
+
Result := E = 0;
|
2097
|
+
end;
|
2098
|
+
|
2099
|
+
begin
|
2100
|
+
Result := nil;
|
2101
|
+
SL := TStringList.Create;
|
2102
|
+
try
|
2103
|
+
Split(S, RangesSeparator, SL);
|
2104
|
+
SetLength(Result, SL.Count);
|
2105
|
+
for i := 0 to SL.Count-1 do begin
|
2106
|
+
r := SL[i];
|
2107
|
+
with Result[i] do begin
|
2108
|
+
p := CharPos(RangeInnerSeparator, r);
|
2109
|
+
Simple := p = 0; // no '-' found
|
2110
|
+
if Simple then begin
|
2111
|
+
if r = RangeInfinite then begin // * --> *-*
|
2112
|
+
Simple := False;
|
2113
|
+
Bottom := Low(Bottom);
|
2114
|
+
Top := High(Top);
|
2115
|
+
end else if not TryStrToCard(r, Value) then
|
2116
|
+
Break;
|
2117
|
+
|
2118
|
+
end else begin
|
2119
|
+
TileStr(r, p, p, b, t);
|
2120
|
+
|
2121
|
+
if b = RangeInfinite then
|
2122
|
+
Bottom := Low(Bottom)
|
2123
|
+
else if not TryStrToCard(b, Bottom) then
|
2124
|
+
Break;
|
2125
|
+
|
2126
|
+
if t = RangeInfinite then
|
2127
|
+
Top := High(Top)
|
2128
|
+
else if not TryStrToCard(t, Top) then
|
2129
|
+
Break;
|
2130
|
+
if Bottom > Top then begin
|
2131
|
+
p := Bottom; Bottom := Top; Top := p;
|
2132
|
+
end;
|
2133
|
+
end;
|
2134
|
+
end;
|
2135
|
+
end;
|
2136
|
+
|
2137
|
+
if i <> SL.Count then
|
2138
|
+
Result := nil;
|
2139
|
+
|
2140
|
+
finally
|
2141
|
+
SL.Free;
|
2142
|
+
end;
|
2143
|
+
end;
|
2144
|
+
|
2145
|
+
function InRanges(Ranges: TRanges; TestValue: Cardinal): Boolean;
|
2146
|
+
var
|
2147
|
+
i: Integer;
|
2148
|
+
begin
|
2149
|
+
Result := True;
|
2150
|
+
|
2151
|
+
for i := 0 to High(Ranges) do
|
2152
|
+
with Ranges[i] do
|
2153
|
+
if Simple then begin
|
2154
|
+
if TestValue = Value then
|
2155
|
+
Exit;
|
2156
|
+
end else begin
|
2157
|
+
if InRange(TestValue, Bottom, Top) then
|
2158
|
+
Exit;
|
2159
|
+
end;
|
2160
|
+
|
2161
|
+
Result := False;
|
2162
|
+
end;
|
2163
|
+
|
2164
|
+
procedure WriteSL(Strings: TStrings; const Prefix: string = '';
|
2165
|
+
const Suffix: string = '');
|
2166
|
+
var
|
2167
|
+
i: Integer;
|
2168
|
+
begin
|
2169
|
+
for i := 0 to Strings.Count-1 do
|
2170
|
+
WriteLn(Prefix + Strings[i] + Suffix);
|
2171
|
+
end;
|
2172
|
+
|
2173
|
+
function Success(Res: Integer; ResultOnSuccess: Integer = ERROR_SUCCESS): Boolean;
|
2174
|
+
begin
|
2175
|
+
Result := (Res = ResultOnSuccess);
|
2176
|
+
LastSuccessRes := Res;
|
2177
|
+
end;
|
2178
|
+
|
2179
|
+
function Failure(Res: Integer; ResultOnSuccess: Integer = ERROR_SUCCESS): Boolean;
|
2180
|
+
begin
|
2181
|
+
Result := not Success(Res, ResultOnSuccess);
|
2182
|
+
end;
|
2183
|
+
|
2184
|
+
function ExpandString(const S: string): string;
|
2185
|
+
var
|
2186
|
+
Len: Integer;
|
2187
|
+
P, Res: PChar;
|
2188
|
+
begin
|
2189
|
+
Result := '';
|
2190
|
+
P := PChar(S);
|
2191
|
+
Len := ExpandEnvironmentStrings(P, nil, 0);
|
2192
|
+
if Len = 0 then
|
2193
|
+
Exit;
|
2194
|
+
|
2195
|
+
GetMem(Res, Len);
|
2196
|
+
ExpandEnvironmentStrings(P, Res, Len);
|
2197
|
+
|
2198
|
+
Result := Res;
|
2199
|
+
FreeMem(Res, Len);
|
2200
|
+
end;
|
2201
|
+
|
2202
|
+
function FindAll(Strings: TStrings; const Mask: string;
|
2203
|
+
ScanSubDirs: Boolean = True; Attributes: Integer = faFindEveryFile;
|
2204
|
+
FileReturn: TFileNameFunc = nil): Boolean;
|
2205
|
+
var
|
2206
|
+
Path, FileName: string;
|
2207
|
+
|
2208
|
+
procedure ScanDir(const Path, FileName: string);
|
2209
|
+
var
|
2210
|
+
PSR: TSearchRec;
|
2211
|
+
Res: Integer;
|
2212
|
+
|
2213
|
+
procedure Add(const S: string);
|
2214
|
+
begin
|
2215
|
+
if S <> '' then
|
2216
|
+
Strings.Add(S);
|
2217
|
+
end;
|
2218
|
+
|
2219
|
+
begin
|
2220
|
+
Res := FindFirst(Path + FileName, Attributes, PSR);
|
2221
|
+
while Success(Res, 0) do begin
|
2222
|
+
if Assigned(FileReturn) then
|
2223
|
+
Add(FileReturn(Path + PSR.Name))
|
2224
|
+
else
|
2225
|
+
Add(Path + PSR.Name);
|
2226
|
+
Res := FindNext(PSR);
|
2227
|
+
end;
|
2228
|
+
FindClose(PSR);
|
2229
|
+
if not ScanSubDirs then
|
2230
|
+
Exit;
|
2231
|
+
|
2232
|
+
Res := FindFirst(Path + '*', faDirectory, PSR);
|
2233
|
+
while Success(Res, 0) do begin
|
2234
|
+
if (PSR.Attr and faDirectory > 0)
|
2235
|
+
and (PSR.Name <> '.') and (PSR.Name <> '..') then
|
2236
|
+
ScanDir(Path + PSR.Name + '\', FileName);
|
2237
|
+
Res := FindNext(PSR);
|
2238
|
+
end;
|
2239
|
+
FindClose(PSR);
|
2240
|
+
end;
|
2241
|
+
|
2242
|
+
begin
|
2243
|
+
Strings.Clear;
|
2244
|
+
Path := ExtractPath(Mask);
|
2245
|
+
FileName := ExtractFileName(Mask);
|
2246
|
+
ScanDir(Path, FileName);
|
2247
|
+
Result := Strings.Count > 0;
|
2248
|
+
end;
|
2249
|
+
|
2250
|
+
function FindAllFirst(const Mask: string; ScanSubDirs: Boolean = True;
|
2251
|
+
Attributes: Integer = faFindEveryFile): string;
|
2252
|
+
var
|
2253
|
+
Path, FileName: string;
|
2254
|
+
|
2255
|
+
function ScanDir(const Path, FileName: string): Boolean;
|
2256
|
+
var
|
2257
|
+
PSR: TSearchRec;
|
2258
|
+
Res: Integer;
|
2259
|
+
begin
|
2260
|
+
Result := False;
|
2261
|
+
if Success(FindFirst(Path + FileName, Attributes, PSR), 0) then begin
|
2262
|
+
FindAllFirst := Path + PSR.Name;
|
2263
|
+
Result := True;
|
2264
|
+
FindClose(PSR);
|
2265
|
+
Exit; end;
|
2266
|
+
if not ScanSubDirs then
|
2267
|
+
Exit;
|
2268
|
+
|
2269
|
+
Res := FindFirst(Path + '*', faDirectory, PSR);
|
2270
|
+
while not Result and Success(Res, 0) do begin
|
2271
|
+
if (PSR.Attr and faDirectory > 0)
|
2272
|
+
and (PSR.Name <> '.') and (PSR.Name <> '..') then
|
2273
|
+
Result := ScanDir(Path + PSR.Name + '\', FileName);
|
2274
|
+
Res := FindNext(PSR);
|
2275
|
+
end;
|
2276
|
+
FindClose(PSR);
|
2277
|
+
end;
|
2278
|
+
begin
|
2279
|
+
Result := '';
|
2280
|
+
Path := ExtractPath(Mask);
|
2281
|
+
FileName := ExtractFileName(Mask);
|
2282
|
+
ScanDir(Path, FileName);
|
2283
|
+
end;
|
2284
|
+
|
2285
|
+
procedure DeleteFiles(const Mask: string; ScanSubDirs: Boolean = True;
|
2286
|
+
Attributes: Integer = faFindEveryFile);
|
2287
|
+
var
|
2288
|
+
Path, FileName: string;
|
2289
|
+
|
2290
|
+
procedure ScanDir(const Path, FileName: string);
|
2291
|
+
var
|
2292
|
+
PSR: TSearchRec;
|
2293
|
+
Res: Integer;
|
2294
|
+
|
2295
|
+
procedure TryDeleteFile(const FileName: string);
|
2296
|
+
begin
|
2297
|
+
try
|
2298
|
+
DeleteFile(Path + PSR.Name);
|
2299
|
+
except
|
2300
|
+
end;
|
2301
|
+
end;
|
2302
|
+
|
2303
|
+
begin
|
2304
|
+
Res := FindFirst(Path + FileName, Attributes, PSR);
|
2305
|
+
while Success(Res, 0) do begin
|
2306
|
+
TryDeleteFile(Path + PSR.Name);
|
2307
|
+
Res := FindNext(PSR);
|
2308
|
+
end;
|
2309
|
+
FindClose(PSR);
|
2310
|
+
if not ScanSubDirs then
|
2311
|
+
Exit;
|
2312
|
+
|
2313
|
+
Res := FindFirst(Path + '*', faDirectory, PSR);
|
2314
|
+
while Success(Res, 0) do begin
|
2315
|
+
if (PSR.Attr and faDirectory > 0)
|
2316
|
+
and (PSR.Name <> '.') and (PSR.Name <> '..') then begin
|
2317
|
+
ScanDir(Path + PSR.Name + '\', FileName);
|
2318
|
+
TryDeleteFile(Path + PSR.Name);
|
2319
|
+
end;
|
2320
|
+
Res := FindNext(PSR);
|
2321
|
+
end;
|
2322
|
+
FindClose(PSR);
|
2323
|
+
end;
|
2324
|
+
begin
|
2325
|
+
Path := ExtractPath(Mask);
|
2326
|
+
FileName := ExtractFileName(Mask);
|
2327
|
+
ScanDir(Path, FileName);
|
2328
|
+
end;
|
2329
|
+
|
2330
|
+
function GetFileNew(FileName: string; NoFloppyDrives: Boolean = True): string;
|
2331
|
+
var
|
2332
|
+
Drive: string;
|
2333
|
+
pf, pd, Len: Integer;
|
2334
|
+
PSR: TSearchRec;
|
2335
|
+
begin
|
2336
|
+
Result := '';
|
2337
|
+
FileName := Trim(FileName);
|
2338
|
+
if Length(FileName) < 2 then
|
2339
|
+
Exit;
|
2340
|
+
|
2341
|
+
Drive := ExtractDrive(FileName);
|
2342
|
+
if not DirectoryExists(Drive) then
|
2343
|
+
Exit;
|
2344
|
+
|
2345
|
+
if NoFloppyDrives and (Drive[1] in ['A', 'B']) then
|
2346
|
+
Exit;
|
2347
|
+
|
2348
|
+
Len := Length(FileName);
|
2349
|
+
Result := Drive;
|
2350
|
+
pf := Length(Drive) + 1;
|
2351
|
+
while pf <= Len do begin
|
2352
|
+
if FileName[pf] = '\' then begin
|
2353
|
+
Result := Result + '\';
|
2354
|
+
Inc(pf);
|
2355
|
+
Continue; end;
|
2356
|
+
|
2357
|
+
pd := CharPos('\', FileName, pf);
|
2358
|
+
if pd = 0 then begin
|
2359
|
+
if 0=FindFirst(Result + Copy(FileName, pf, MaxInt), faFindEveryFile, PSR) then begin
|
2360
|
+
Result := Result + PSR.Name;
|
2361
|
+
Break; end else begin
|
2362
|
+
FindClose(PSR);
|
2363
|
+
if 0=FindFirst(Result + Copy(FileName, pf, MaxInt), faDirectory, PSR) then
|
2364
|
+
Result := Result + PSR.Name + '\'
|
2365
|
+
else
|
2366
|
+
Result := '';
|
2367
|
+
FindClose(PSR);
|
2368
|
+
if Result = '' then
|
2369
|
+
Break;
|
2370
|
+
end;
|
2371
|
+
end;
|
2372
|
+
|
2373
|
+
if 0=FindFirst(Result + Copy(FileName, pf, pd - pf), faDirectory, PSR) then
|
2374
|
+
Result := Result + PSR.Name + '\'
|
2375
|
+
else
|
2376
|
+
Result := '';
|
2377
|
+
FindClose(PSR);
|
2378
|
+
if Result = '' then
|
2379
|
+
Break;
|
2380
|
+
|
2381
|
+
pf := pd + 1;
|
2382
|
+
end;
|
2383
|
+
|
2384
|
+
if (Result <> '') and not FileEx(Result, True) then
|
2385
|
+
Result := '';
|
2386
|
+
end;
|
2387
|
+
|
2388
|
+
function DateTimeOfFileTime(const FileTime: TFileTime): TDateTime;
|
2389
|
+
var
|
2390
|
+
LocalFileTime: TFileTime;
|
2391
|
+
Res: Integer;
|
2392
|
+
begin
|
2393
|
+
Result := 0;
|
2394
|
+
|
2395
|
+
FileTimeToLocalFileTime(FileTime, LocalFileTime);
|
2396
|
+
if not FileTimeToDosDateTime(LocalFileTime, LongRec(Res).Hi,
|
2397
|
+
LongRec(Res).Lo) then
|
2398
|
+
Res := -1;
|
2399
|
+
|
2400
|
+
if (Res = -1) or (Res = 0) then
|
2401
|
+
Exit;
|
2402
|
+
try
|
2403
|
+
Result := FileDateToDateTime(Res);
|
2404
|
+
except
|
2405
|
+
end;
|
2406
|
+
end;
|
2407
|
+
|
2408
|
+
procedure FileNew(const FileName: string);
|
2409
|
+
var
|
2410
|
+
Handle: Integer;
|
2411
|
+
begin
|
2412
|
+
Handle := FileCreate(FileName);
|
2413
|
+
FileClose(Handle);
|
2414
|
+
end;
|
2415
|
+
|
2416
|
+
function Win32PlatformStr: string;
|
2417
|
+
const
|
2418
|
+
PlatformStrings: array[VER_PLATFORM_WIN32s..VER_PLATFORM_WIN32_NT] of string =
|
2419
|
+
('VER_PLATFORM_WIN32s', 'VER_PLATFORM_WIN32_WINDOWS', 'VER_PLATFORM_WIN32_NT');
|
2420
|
+
begin
|
2421
|
+
Result := PlatformStrings[Win32Platform];
|
2422
|
+
end;
|
2423
|
+
|
2424
|
+
function FullOSInfo: string;
|
2425
|
+
begin
|
2426
|
+
Result := Format(
|
2427
|
+
'Platform: %s' + EOL +
|
2428
|
+
'Version: %d.%d Build %d' + EOL +
|
2429
|
+
'CSD: %s',
|
2430
|
+
[
|
2431
|
+
Win32PlatformStr,
|
2432
|
+
Win32MajorVersion, Win32MinorVersion, Win32BuildNumber,
|
2433
|
+
Win32CSDVersion
|
2434
|
+
]
|
2435
|
+
);
|
2436
|
+
end;
|
2437
|
+
|
2438
|
+
function Win9x: Boolean;
|
2439
|
+
begin
|
2440
|
+
Result := Win32Platform = VER_PLATFORM_WIN32_WINDOWS;
|
2441
|
+
end;
|
2442
|
+
|
2443
|
+
function WinNT: Boolean;
|
2444
|
+
begin
|
2445
|
+
Result := Win32Platform = VER_PLATFORM_WIN32_NT;
|
2446
|
+
end;
|
2447
|
+
|
2448
|
+
function Win2000: Boolean;
|
2449
|
+
begin
|
2450
|
+
Result := (Win32Platform = VER_PLATFORM_WIN32_NT)
|
2451
|
+
and (Win32MajorVersion = 4);
|
2452
|
+
end;
|
2453
|
+
|
2454
|
+
function WinXP: Boolean;
|
2455
|
+
begin
|
2456
|
+
Result := Win32MajorVersion >= 5;
|
2457
|
+
end;
|
2458
|
+
|
2459
|
+
initialization
|
2460
|
+
MyDir := GetMyDir;
|
2461
|
+
|
2462
|
+
end.
|
2463
|
+
|
2464
|
+
unit FifoStream;
|
2465
|
+
|
2466
|
+
interface
|
2467
|
+
|
2468
|
+
uses Classes, windows, Dialogs;
|
2469
|
+
|
2470
|
+
const
|
2471
|
+
DefaultChunksize = 32768; // 32kb per chunk as default.
|
2472
|
+
|
2473
|
+
type
|
2474
|
+
PMemChunk = ^TMemChunk;
|
2475
|
+
TMemChunk = record
|
2476
|
+
Filled: Longword;
|
2477
|
+
Read: Longword;
|
2478
|
+
Data: pointer;
|
2479
|
+
end;
|
2480
|
+
|
2481
|
+
TFifo = class
|
2482
|
+
private
|
2483
|
+
FBuffers: TList;
|
2484
|
+
FChunksize: Longword;
|
2485
|
+
FCritSect: TRTLCriticalSection;
|
2486
|
+
FIsWinNT: boolean;
|
2487
|
+
FBytesInFifo: LongWord;
|
2488
|
+
protected
|
2489
|
+
function GetBytesInFifo: LongWord;
|
2490
|
+
public
|
2491
|
+
constructor Create;
|
2492
|
+
destructor Destroy; override;
|
2493
|
+
procedure Write(Data: pointer; Size: LongWord);
|
2494
|
+
procedure Read(Buff: pointer; var ReqSize: LongWord);
|
2495
|
+
procedure PeekData(Buff: pointer; var ReqSize: LongWord);
|
2496
|
+
published
|
2497
|
+
property BytesInFifo: LongWord read FBytesInFifo;
|
2498
|
+
end;
|
2499
|
+
|
2500
|
+
implementation
|
2501
|
+
|
2502
|
+
constructor TFifo.Create;
|
2503
|
+
begin
|
2504
|
+
inherited;
|
2505
|
+
FBuffers := TList.Create;
|
2506
|
+
// set default chunksize...
|
2507
|
+
FChunksize := DefaultChunksize;
|
2508
|
+
InitializeCriticalSection(FCritSect);
|
2509
|
+
end;
|
2510
|
+
|
2511
|
+
destructor TFifo.Destroy;
|
2512
|
+
var
|
2513
|
+
I: Integer;
|
2514
|
+
begin
|
2515
|
+
EnterCriticalSection(FCritSect);
|
2516
|
+
for I := 0 to FBuffers.count - 1 do
|
2517
|
+
begin
|
2518
|
+
FreeMem(PMemChunk(Fbuffers[I]).Data);
|
2519
|
+
Dispose(PMemChunk(Fbuffers[I]));
|
2520
|
+
end;
|
2521
|
+
FBuffers.Clear;
|
2522
|
+
FBuffers.Free;
|
2523
|
+
LeaveCriticalSection(FCritSect);
|
2524
|
+
|
2525
|
+
DeleteCriticalSection(FCritSect);
|
2526
|
+
inherited;
|
2527
|
+
end;
|
2528
|
+
|
2529
|
+
function TFifo.GetBytesInFifo: LongWord;
|
2530
|
+
begin
|
2531
|
+
Result := 0;
|
2532
|
+
if FBuffers.Count = 0 then
|
2533
|
+
begin
|
2534
|
+
exit;
|
2535
|
+
end
|
2536
|
+
else
|
2537
|
+
begin
|
2538
|
+
if FBuffers.Count > 1 then
|
2539
|
+
Inc(Result, (FBuffers.Count - 1) * FChunkSize);
|
2540
|
+
Inc(Result, PMemChunk(FBuffers[Fbuffers.Count - 1]).Filled);
|
2541
|
+
Dec(Result, PMemChunk(FBuffers[0]).Read);
|
2542
|
+
end;
|
2543
|
+
end;
|
2544
|
+
|
2545
|
+
procedure TFifo.Write(Data: pointer; Size: LongWord);
|
2546
|
+
var
|
2547
|
+
Privpointer: pointer;
|
2548
|
+
PrivSize: LongWord;
|
2549
|
+
Chunk: PMemChunk;
|
2550
|
+
PosInChunk: pointer;
|
2551
|
+
begin
|
2552
|
+
if LongWord(Data) = 0 then
|
2553
|
+
begin
|
2554
|
+
// null pointer? somebody is trying to fool us, get out...
|
2555
|
+
Exit;
|
2556
|
+
end;
|
2557
|
+
EnterCriticalSection(FCritSect);
|
2558
|
+
PrivPointer := Data;
|
2559
|
+
PrivSize := 0;
|
2560
|
+
// are already buffers there?
|
2561
|
+
if FBuffers.count > 0 then
|
2562
|
+
begin
|
2563
|
+
// is the last one of them not completely filled?
|
2564
|
+
if PMemChunk(FBuffers[FBuffers.count - 1]).filled < FChunksize then
|
2565
|
+
// not completely filled, so fill up the buffer.
|
2566
|
+
begin
|
2567
|
+
Chunk := PMemChunk(FBuffers[FBuffers.count - 1]);
|
2568
|
+
// fetch chunkdata.
|
2569
|
+
PosInChunk := Chunk.Data;
|
2570
|
+
// move to current fill pos...
|
2571
|
+
Inc(LongWord(PosInChunk), Chunk.Filled);
|
2572
|
+
// can we fill the chunk completely?
|
2573
|
+
if Size > FChunksize - Chunk.Filled then
|
2574
|
+
begin
|
2575
|
+
// yes we can.
|
2576
|
+
Move(PrivPointer^, PosInChunk^, FChunksize - Chunk.Filled);
|
2577
|
+
Inc(PrivSize, FChunksize - Chunk.Filled);
|
2578
|
+
Inc(LongWord(PrivPointer), FChunksize - Chunk.Filled);
|
2579
|
+
Chunk.Filled := FChunkSize;
|
2580
|
+
end
|
2581
|
+
else
|
2582
|
+
// we have to less data for filling the chunk completely,
|
2583
|
+
// just put everything in.
|
2584
|
+
begin
|
2585
|
+
Move(PrivPointer^, PosInChunk^, Size);
|
2586
|
+
Inc(PrivSize, Size);
|
2587
|
+
Inc(Chunk.Filled, Size);
|
2588
|
+
end;
|
2589
|
+
end;
|
2590
|
+
end;
|
2591
|
+
// as long as we have remaining stuff put it into new chunks.
|
2592
|
+
while (PrivSize < Size) do
|
2593
|
+
begin
|
2594
|
+
new(Chunk);
|
2595
|
+
GetMem(Chunk.Data, FChunksize);
|
2596
|
+
Chunk.Read := 0;
|
2597
|
+
// can we fill an entire chunk with the remaining data?
|
2598
|
+
if Privsize + FChunksize < Size then
|
2599
|
+
begin
|
2600
|
+
// yes we can, so put the stuff in.
|
2601
|
+
Move(Privpointer^, Chunk.Data^, FChunksize);
|
2602
|
+
Inc(LongWord(PrivPointer), FChunksize);
|
2603
|
+
Inc(PrivSize, FChunksize);
|
2604
|
+
Chunk.Filled := FChunksize;
|
2605
|
+
end
|
2606
|
+
else // we have to less data to fill the entire chunk, just put the remaining stuff in.
|
2607
|
+
begin
|
2608
|
+
Move(Privpointer^, Chunk.Data^, Size - Privsize);
|
2609
|
+
Chunk.Filled := Size - Privsize;
|
2610
|
+
Inc(PrivSize, Size - Privsize);
|
2611
|
+
end;
|
2612
|
+
Fbuffers.Add(Chunk);
|
2613
|
+
end;
|
2614
|
+
if Size <> Privsize then
|
2615
|
+
Showmessage('miscalculation in TFifo.write');
|
2616
|
+
FBytesInFifo := GetBytesInFifo;
|
2617
|
+
LeaveCriticalSection(FCritSect);
|
2618
|
+
end;
|
2619
|
+
|
2620
|
+
procedure TFifo.Read(Buff: pointer; var ReqSize: LongWord);
|
2621
|
+
var
|
2622
|
+
PrivSize: Integer;
|
2623
|
+
Privpos: pointer;
|
2624
|
+
Chunk: PMemChunk;
|
2625
|
+
ChunkPos: pointer;
|
2626
|
+
begin
|
2627
|
+
if LongWord(Buff) = 0 then
|
2628
|
+
begin
|
2629
|
+
// null pointer? somebody is trying to fool us, get out...
|
2630
|
+
Exit;
|
2631
|
+
end;
|
2632
|
+
EnterCriticalSection(FCritSect);
|
2633
|
+
PrivSize := 0;
|
2634
|
+
Privpos := Buff;
|
2635
|
+
while FBuffers.Count > 0 do
|
2636
|
+
begin
|
2637
|
+
Chunk := PMemChunk(FBuffers[0]);
|
2638
|
+
ChunkPos := Chunk.data;
|
2639
|
+
Inc(LongWord(ChunkPos), Chunk.Read);
|
2640
|
+
// does the remaining part of the chunk fit into the buffer?
|
2641
|
+
if PrivSize + (Chunk.Filled - Chunk.read) < ReqSize then
|
2642
|
+
begin // yep, it fits
|
2643
|
+
Move(ChunkPos^, Privpos^, Chunk.Filled - Chunk.read);
|
2644
|
+
Inc(PrivSize, Chunk.Filled - Chunk.read);
|
2645
|
+
FreeMem(Chunk.Data);
|
2646
|
+
Dispose(Chunk);
|
2647
|
+
FBuffers.Delete(0);
|
2648
|
+
end
|
2649
|
+
else // remaining part didn't fit, get as much as we can and increment the
|
2650
|
+
// read attribute.
|
2651
|
+
begin
|
2652
|
+
Move(ChunkPos^, Privpos^, ReqSize - PrivSize);
|
2653
|
+
Inc(Chunk.read, ReqSize - PrivSize);
|
2654
|
+
Inc(PrivSize, ReqSize - PrivSize);
|
2655
|
+
// as we filled the buffer, we'll have to break here.
|
2656
|
+
break;
|
2657
|
+
end;
|
2658
|
+
end;
|
2659
|
+
FBytesInFifo := GetBytesInFifo;
|
2660
|
+
LeaveCriticalSection(FCritSect);
|
2661
|
+
ReqSize := PrivSize;
|
2662
|
+
end;
|
2663
|
+
|
2664
|
+
// read Data from Stream without removing it from the Stream...
|
2665
|
+
|
2666
|
+
procedure TFifo.PeekData(Buff: pointer; var ReqSize: LongWord);
|
2667
|
+
var
|
2668
|
+
PrivSize: Integer;
|
2669
|
+
Privpos: pointer;
|
2670
|
+
Chunk: PMemChunk;
|
2671
|
+
ChunkPos: pointer;
|
2672
|
+
ChunkNr: Integer;
|
2673
|
+
begin
|
2674
|
+
if LongWord(Buff) = 0 then
|
2675
|
+
begin
|
2676
|
+
// null pointer? somebody is trying to fool us, get out...
|
2677
|
+
Exit;
|
2678
|
+
end;
|
2679
|
+
EnterCriticalSection(FCritSect);
|
2680
|
+
PrivSize := 0;
|
2681
|
+
Privpos := Buff;
|
2682
|
+
ChunkNr := 0;
|
2683
|
+
while FBuffers.Count > ChunkNr do
|
2684
|
+
begin
|
2685
|
+
Chunk := PMemChunk(FBuffers[ChunkNr]);
|
2686
|
+
ChunkPos := Chunk.data;
|
2687
|
+
Inc(LongWord(ChunkPos), Chunk.Read);
|
2688
|
+
// does the remaining part of the chunk fit into the buffer?
|
2689
|
+
if PrivSize + (Chunk.Filled - Chunk.read) < ReqSize then
|
2690
|
+
begin // yep, it fits
|
2691
|
+
Move(ChunkPos^, Privpos^, Chunk.Filled - Chunk.read);
|
2692
|
+
Inc(PrivSize, Chunk.Filled - Chunk.read);
|
2693
|
+
Inc(ChunkNr);
|
2694
|
+
end
|
2695
|
+
else // remaining part didn't fit, get as much as we can and increment the
|
2696
|
+
// read attribute.
|
2697
|
+
begin
|
2698
|
+
Move(ChunkPos^, Privpos^, ReqSize - PrivSize);
|
2699
|
+
Inc(PrivSize, ReqSize - PrivSize);
|
2700
|
+
// as we filled the buffer, we'll have to break here.
|
2701
|
+
break;
|
2702
|
+
end;
|
2703
|
+
end;
|
2704
|
+
LeaveCriticalSection(FCritSect);
|
2705
|
+
ReqSize := PrivSize;
|
2706
|
+
end;
|
2707
|
+
|
2708
|
+
end.
|