From fd70c1f4f8e8ce47e3c54756e25255008ffe3722 Mon Sep 17 00:00:00 2001 From: Kim Jin Su Date: Sun, 22 Nov 2015 00:28:39 +0900 Subject: Aheui Lexer and test cases --- pygments/lexers/_mapping.py | 1 + pygments/lexers/esoteric.py | 45 +++++++++++++++++++++++++++- tests/examplefiles/durexmania.aheui | 4 +++ tests/examplefiles/fibonacci.tokigun.aheui | 4 +++ tests/examplefiles/hello-world.puzzlet.aheui | 10 +++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/examplefiles/durexmania.aheui create mode 100644 tests/examplefiles/fibonacci.tokigun.aheui create mode 100644 tests/examplefiles/hello-world.puzzlet.aheui diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 03a3c96e..747d0d2a 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -23,6 +23,7 @@ LEXERS = { 'AdaLexer': ('pygments.lexers.pascal', 'Ada', ('ada', 'ada95', 'ada2005'), ('*.adb', '*.ads', '*.ada'), ('text/x-ada',)), 'AdlLexer': ('pygments.lexers.archetype', 'ADL', ('adl',), ('*.adl', '*.adls', '*.adlf', '*.adlx'), ()), 'AgdaLexer': ('pygments.lexers.haskell', 'Agda', ('agda',), ('*.agda',), ('text/x-agda',)), + 'AheuiLexer': ('pygments.lexers.esoteric', 'Aheui', ('aheui',), ('*.aheui',), ()), 'AlloyLexer': ('pygments.lexers.dsls', 'Alloy', ('alloy',), ('*.als',), ('text/x-alloy',)), 'AmbientTalkLexer': ('pygments.lexers.ambient', 'AmbientTalk', ('at', 'ambienttalk', 'ambienttalk/2'), ('*.at',), ('text/x-ambienttalk',)), 'AntlrActionScriptLexer': ('pygments.lexers.parsers', 'ANTLR With ActionScript Target', ('antlr-as', 'antlr-actionscript'), ('*.G', '*.g'), ()), diff --git a/pygments/lexers/esoteric.py b/pygments/lexers/esoteric.py index fc80c1e3..c9bad973 100644 --- a/pygments/lexers/esoteric.py +++ b/pygments/lexers/esoteric.py @@ -13,7 +13,8 @@ from pygments.lexer import RegexLexer, include, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Error, Whitespace -__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer'] +__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', + 'AheuiLexer'] class BrainfuckLexer(RegexLexer): @@ -157,3 +158,45 @@ class BoogieLexer(RegexLexer): (r'[0-9]+', Number.Integer), ], } + + +class AheuiLexer(RegexLexer): + """ + Aheui_ Lexer. + + Aheui_ is esoteric language based on Korean alphabets. + + .. _Aheui:: http://aheui.github.io/ + + """ + + name = u'Aheui' + aliases = ['aheui'] + filenames = ['*.aheui'] + + tokens = { + 'root': [ + (u'[' + u'가-갛갸-걓거-겋겨-곃고-곻교-궇규-긯' + u'까-깧꺄-꺟꺼-껗껴-꼏꼬-꽇꾜-꿓뀨-끻' + u'나-낳냐-냫너-넣녀-녛노-놓뇨-눟뉴-닇' + u'다-닿댜-댷더-덯뎌-뎧도-돟됴-둫듀-딓' + u'따-땋땨-떃떠-떻뗘-뗳또-똫뚀-뚷뜌-띟' + u'라-랗랴-럏러-렇려-렿로-롷료-뤃류-릫' + u'마-맣먀-먛머-멓며-몋모-뫃묘-뭏뮤-믷' + u'바-밯뱌-뱧버-벟벼-볗보-봏뵤-붛뷰-빃' + u'빠-빻뺘-뺳뻐-뻫뼈-뼣뽀-뽛뾰-뿧쀼-삏' + u'사-샇샤-샿서-섷셔-셯소-솧쇼-숳슈-싛' + u'싸-쌓쌰-썋써-쎃쎠-쎻쏘-쏳쑈-쑿쓔-씧' + u'아-앟야-얗어-엏여-옇오-옿요-웋유-읳' + u'자-잫쟈-쟣저-젛져-졓조-좋죠-줗쥬-즿' + u'짜-짷쨔-쨯쩌-쩧쪄-쪟쪼-쫗쬬-쭣쮸-찋' + u'차-챃챠-챻처-첳쳐-쳫초-촣쵸-춯츄-칗' + u'카-캏캬-컇커-컿켜-켷코-콯쿄-쿻큐-킣' + u'타-탛탸-턓터-텋텨-톃토-톻툐-퉇튜-틯' + u'파-팧퍄-퍟퍼-펗펴-폏포-퐇표-풓퓨-픻' + u'하-핳햐-햫허-헣혀-혛호-홓효-훟휴-힇' + u']', Operator), + ('.', Comment), + ], + } diff --git a/tests/examplefiles/durexmania.aheui b/tests/examplefiles/durexmania.aheui new file mode 100644 index 00000000..89654c00 --- /dev/null +++ b/tests/examplefiles/durexmania.aheui @@ -0,0 +1,4 @@ +우주메이저☆듀렉스전도사♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♂♀♡먊 +삶은밥과야근밥샤주세양♡밥사밥사밥사밥사밥사땅땅땅빵☆따밦내발따밦다빵맣밥밥밥내놔밥줘밥밥밥밗땅땅땅박밝땅땅딻타밟타맣밦밣따박타맣밦밣따박타맣밦밣따박타맣박빵빵빵빵따따따따맣삶몲 +Original Source by @harunene // Run it on AheuiChem(http://yoo2001818.github.io/AheuiChem/) +https://gist.github.com/item4/ca870a63b390da6cc6f1 diff --git a/tests/examplefiles/fibonacci.tokigun.aheui b/tests/examplefiles/fibonacci.tokigun.aheui new file mode 100644 index 00000000..afa2ca05 --- /dev/null +++ b/tests/examplefiles/fibonacci.tokigun.aheui @@ -0,0 +1,4 @@ +바싹반박나싼순 +뿌멓떠벌번멍뻐 +쌀삭쌀살다순옭 +어어선썬설썩옭 diff --git a/tests/examplefiles/hello-world.puzzlet.aheui b/tests/examplefiles/hello-world.puzzlet.aheui new file mode 100644 index 00000000..e7ef3a62 --- /dev/null +++ b/tests/examplefiles/hello-world.puzzlet.aheui @@ -0,0 +1,10 @@ +밤밣따빠밣밟따뿌 +빠맣파빨받밤뚜뭏 +돋밬탕빠맣붏두붇 +볻뫃박발뚷투뭏붖 +뫃도뫃희멓뭏뭏붘 +뫃봌토범더벌뿌뚜 +뽑뽀멓멓더벓뻐뚠 +뽀덩벐멓뻐덕더벅 + +https://github.com/aheui/snippets/blob/master/hello-world/hello-world.puzzlet.aheui -- cgit v1.2.1 From 472821f0835924275521cd910e281085a75a7440 Mon Sep 17 00:00:00 2001 From: Kim Jin Su Date: Sun, 22 Nov 2015 00:34:48 +0900 Subject: fix confilct --- pygments/lexers/esoteric.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygments/lexers/esoteric.py b/pygments/lexers/esoteric.py index c9bad973..06c1de8d 100644 --- a/pygments/lexers/esoteric.py +++ b/pygments/lexers/esoteric.py @@ -13,8 +13,7 @@ from pygments.lexer import RegexLexer, include, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Error, Whitespace -__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', - 'AheuiLexer'] +__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', 'CAmkESLexer', 'AheuiLexer'] class BrainfuckLexer(RegexLexer): -- cgit v1.2.1 From 99e94cd4f9479f57f879ceae12a2c8f7d4970770 Mon Sep 17 00:00:00 2001 From: Kim Jin Su Date: Sun, 22 Nov 2015 00:41:39 +0900 Subject: merge --- AUTHORS | 23 +- CHANGES | 12 + doc/languages.rst | 1 + pygments/formatters/_mapping.py | 9 +- pygments/lexer.py | 2 + pygments/lexers/_csound_builtins.py | 3 +- pygments/lexers/_mapping.py | 26 +- pygments/lexers/algebra.py | 40 +- pygments/lexers/c_cpp.py | 5 +- pygments/lexers/configs.py | 212 ++++- pygments/lexers/csound.py | 107 ++- pygments/lexers/dsls.py | 110 ++- pygments/lexers/esoteric.py.orig | 201 +++++ pygments/lexers/ezhil.py | 68 ++ pygments/lexers/grammar_notation.py | 131 +++ pygments/lexers/hexdump.py | 97 ++ pygments/lexers/javascript.py | 2 + pygments/lexers/python.py | 6 +- pygments/lexers/qvt.py | 150 ++++ pygments/token.py | 1 + pygments/util.py | 2 +- tests/examplefiles/abnf_example1.abnf | 22 + tests/examplefiles/abnf_example2.abnf | 9 + tests/examplefiles/bnf_example1.bnf | 15 + tests/examplefiles/demo.thrift | 14 + tests/examplefiles/example.bc | 53 ++ tests/examplefiles/example.ts | 11 + tests/examplefiles/ezhil_primefactors.n | 152 ++++ tests/examplefiles/hexdump_debugexe | 309 +++++++ tests/examplefiles/hexdump_hd | 310 +++++++ tests/examplefiles/hexdump_hexcat | 247 +++++ tests/examplefiles/hexdump_hexdump | 310 +++++++ tests/examplefiles/hexdump_od | 310 +++++++ tests/examplefiles/hexdump_xxd | 309 +++++++ tests/examplefiles/noexcept.cpp | 8 + tests/examplefiles/pacman.conf | 49 + tests/examplefiles/pkgconfig_example.pc | 18 + tests/examplefiles/pycon_ctrlc_traceback | 118 +++ tests/examplefiles/sample.qvto | 4 + tests/examplefiles/simple.camkes | 38 + tests/examplefiles/termcap | 1340 +++++++++++++++++++++++++++ tests/examplefiles/terminfo | 1445 ++++++++++++++++++++++++++++++ tests/examplefiles/test.csd | 260 ++++++ tests/examplefiles/test.ecl | 58 -- tests/examplefiles/test.sco | 10 + tests/test_clexer.py | 23 + tests/test_ezhil.py | 182 ++++ 47 files changed, 6699 insertions(+), 133 deletions(-) create mode 100644 pygments/lexers/esoteric.py.orig create mode 100644 pygments/lexers/ezhil.py create mode 100644 pygments/lexers/grammar_notation.py create mode 100644 pygments/lexers/hexdump.py create mode 100644 pygments/lexers/qvt.py create mode 100644 tests/examplefiles/abnf_example1.abnf create mode 100644 tests/examplefiles/abnf_example2.abnf create mode 100644 tests/examplefiles/bnf_example1.bnf create mode 100644 tests/examplefiles/demo.thrift create mode 100644 tests/examplefiles/example.bc create mode 100644 tests/examplefiles/ezhil_primefactors.n create mode 100644 tests/examplefiles/hexdump_debugexe create mode 100644 tests/examplefiles/hexdump_hd create mode 100644 tests/examplefiles/hexdump_hexcat create mode 100644 tests/examplefiles/hexdump_hexdump create mode 100644 tests/examplefiles/hexdump_od create mode 100644 tests/examplefiles/hexdump_xxd create mode 100644 tests/examplefiles/noexcept.cpp create mode 100644 tests/examplefiles/pacman.conf create mode 100644 tests/examplefiles/pkgconfig_example.pc create mode 100644 tests/examplefiles/pycon_ctrlc_traceback create mode 100644 tests/examplefiles/sample.qvto create mode 100644 tests/examplefiles/simple.camkes create mode 100644 tests/examplefiles/termcap create mode 100644 tests/examplefiles/terminfo create mode 100644 tests/examplefiles/test.csd delete mode 100644 tests/examplefiles/test.ecl create mode 100644 tests/examplefiles/test.sco create mode 100644 tests/test_ezhil.py diff --git a/AUTHORS b/AUTHORS index 30b88082..9318d438 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Other contributors, listed alphabetically, are: * Sam Aaron -- Ioke lexer * Ali Afshar -- image formatter * Thomas Aglassinger -- Easytrieve, JCL and Rexx lexers +* Muthiah Annamalai -- Ezhil lexer * Kumar Appaiah -- Debian control lexer * Andreas Amann -- AppleScript lexer * Timothy Armstrong -- Dart lexer fixes @@ -27,16 +28,18 @@ Other contributors, listed alphabetically, are: * Trevor Bergeron -- mIRC formatter * Vincent Bernat -- LessCSS lexer * Christopher Bertels -- Fancy lexer +* Sébastien Bigaret -- QVT Operational lexer * Jarrett Billingsley -- MiniD lexer * Adam Blinkinsop -- Haskell, Redcode lexers * Frits van Bommel -- assembler lexers * Pierre Bourdon -- bugfixes +* chebee7i -- Python traceback lexer improvements * Hiram Chirino -- Scaml and Jade lexers * Ian Cooper -- VGL lexer * David Corbett -- Inform, Jasmin, and TADS 3 lexers * Leaf Corcoran -- MoonScript lexer * Christopher Creutzig -- MuPAD lexer -* Daniël W. Crompton - Pike lexer +* Daniël W. Crompton -- Pike lexer * Pete Curry -- bugfixes * Bryan Davis -- EBNF lexer * Bruno Deferrari -- Shen lexer @@ -47,6 +50,7 @@ Other contributors, listed alphabetically, are: * Nick Efford -- Python 3 lexer * Sven Efftinge -- Xtend lexer * Artem Egorkine -- terminal256 formatter +* Matthew Fernandez -- CAmkES lexer * Michael Ficarra -- CPSA lexer * James H. Fisher -- PostScript lexer * William S. Fulton -- SWIG lexer @@ -80,15 +84,15 @@ Other contributors, listed alphabetically, are: * Doug Hogan -- Mscgen lexer * Ben Hollis -- Mason lexer * Max Horn -- GAP lexer -* Dustin Howett -- Logos lexer * Alastair Houghton -- Lexer inheritance facility * Tim Howard -- BlitzMax lexer +* Dustin Howett -- Logos lexer * Ivan Inozemtsev -- Fantom lexer -* Hiroaki Itoh -- Shell console rewrite +* Hiroaki Itoh -- Shell console rewrite, Lexers for PowerShell session, MSDOS session, BC * Brian R. Jackson -- Tea lexer * Christian Jann -- ShellSession lexer * Dennis Kaarsemaker -- sources.list lexer -* Dmitri Kabak - Inferno Limbo lexer +* Dmitri Kabak -- Inferno Limbo lexer * Igor Kalnitsky -- vhdl lexer * Alexander Kit -- MaskJS lexer * Pekka Klärck -- Robot Framework lexer @@ -108,6 +112,7 @@ Other contributors, listed alphabetically, are: * Matt Layman -- TAP lexer * Sylvestre Ledru -- Scilab lexer * Mark Lee -- Vala lexer +* Valentin Lorentz -- C++ lexer improvements * Ben Mabey -- Gherkin lexer * Angus MacArthur -- QML lexer * Louis Mandel -- X10 lexer @@ -137,9 +142,9 @@ Other contributors, listed alphabetically, are: * Edward O'Callaghan -- Cryptol lexer * David Oliva -- Rebol lexer * Pat Pannuto -- nesC lexer -* Jon Parise -- Protocol buffers lexer -* Ronny Pfannschmidt -- BBCode lexer +* Jon Parise -- Protocol buffers and Thrift lexers * Benjamin Peterson -- Test suite refactoring +* Ronny Pfannschmidt -- BBCode lexer * Dominik Picheta -- Nimrod lexer * Andrew Pinkham -- RTF Formatter Refactoring * Clément Prévost -- UrbiScript lexer @@ -153,7 +158,7 @@ Other contributors, listed alphabetically, are: * Andre Roberge -- Tango style * Konrad Rudolph -- LaTeX formatter enhancements * Mario Ruggier -- Evoque lexers -* Miikka Salminen -- Lovelace style, lexer enhancements +* Miikka Salminen -- Lovelace style, Hexdump lexer, lexer enhancements * Stou Sandalski -- NumPy, FORTRAN, tcsh and XSLT lexers * Matteo Sasso -- Common Lisp lexer * Joe Schafer -- Ada lexer @@ -180,14 +185,14 @@ Other contributors, listed alphabetically, are: * Daniele Varrazzo -- PostgreSQL lexers * Abe Voelker -- OpenEdge ABL lexer * Pepijn de Vos -- HTML formatter CTags support -* Whitney Young -- ObjectiveC lexer * Matthias Vallentin -- Bro lexer * Linh Vu Hong -- RSL lexer * Nathan Weizenbaum -- Haml and Sass lexers -* Nathan Whetsell -- CSound lexers +* Nathan Whetsell -- Csound lexers * Dietmar Winkler -- Modelica lexer * Nils Winter -- Smalltalk lexer * Davy Wybiral -- Clojure lexer +* Whitney Young -- ObjectiveC lexer * Diego Zamboni -- CFengine3 lexer * Enrique Zamudio -- Ceylon lexer * Alex Zimin -- Nemerle lexer diff --git a/CHANGES b/CHANGES index 6a83a3e0..7d648bce 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,11 @@ Version 2.1 * Crmsh (PR#440) * Praat (PR#492) * CSound (PR#494) + * Ezhil (PR#443) + * Thrift (PR#469) + * QVT Operational (PR#204) + * Hexdump (PR#508) + * CAmkES Configuration (PR#462) - Added styles: @@ -66,6 +71,13 @@ Version 2.1 - Added option to pygmentize to show a full traceback on exceptions. +- Fixed incomplete output on Windows and Python 3 (e.g. when using iPython + Notebook). (#1153) + +- Allowed more traceback styles in Python console lexer. (PR#253) + +- Added decorators to TypeScript. (PR#509) + Version 2.0.3 ------------- diff --git a/doc/languages.rst b/doc/languages.rst index 683b8752..a495d15c 100644 --- a/doc/languages.rst +++ b/doc/languages.rst @@ -32,6 +32,7 @@ Programming languages * Delphi * Dylan * Erlang +* `Ezhil `_ Ezhil - A Tamil programming language * Factor * Fancy * Fortran diff --git a/pygments/formatters/_mapping.py b/pygments/formatters/_mapping.py index a2e612ad..569ae849 100755 --- a/pygments/formatters/_mapping.py +++ b/pygments/formatters/_mapping.py @@ -66,11 +66,18 @@ if __name__ == '__main__': # pragma: no cover # extract useful sourcecode from this file with open(__file__) as fp: content = fp.read() + # replace crnl to nl for Windows. + # + # Note that, originally, contributers should keep nl of master + # repository, for example by using some kind of automatic + # management EOL, like `EolExtension + # `. + content = content.replace("\r\n", "\n") header = content[:content.find('FORMATTERS = {')] footer = content[content.find("if __name__ == '__main__':"):] # write new file - with open(__file__, 'w') as fp: + with open(__file__, 'wb') as fp: fp.write(header) fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters)) fp.write(footer) diff --git a/pygments/lexer.py b/pygments/lexer.py index e846890e..dd6c01e4 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -654,6 +654,8 @@ class RegexLexer(Lexer): statetokens = tokendefs[statestack[-1]] break else: + # We are here only if all state tokens have been considered + # and there was not a match on any of them. try: if text[pos] == '\n': # at EOL, reset state to "root" diff --git a/pygments/lexers/_csound_builtins.py b/pygments/lexers/_csound_builtins.py index ddf87a64..5f7a798a 100644 --- a/pygments/lexers/_csound_builtins.py +++ b/pygments/lexers/_csound_builtins.py @@ -12,6 +12,7 @@ # endop # igoto +# instr # kgoto # loop_ge # loop_gt @@ -463,7 +464,7 @@ OPCODES = set(( 'ins', 'insglobal', 'insremot', - 'instr', + #'instr', 'int', 'integ', 'interp', diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 747d0d2a..4c26251a 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -17,6 +17,7 @@ from __future__ import print_function LEXERS = { 'ABAPLexer': ('pygments.lexers.business', 'ABAP', ('abap',), ('*.abap',), ('text/x-abap',)), + 'AbnfLexer': ('pygments.lexers.grammar_notation', 'ABNF', ('abnf',), ('*.abnf',), ('text/x-abnf',)), 'APLLexer': ('pygments.lexers.apl', 'APL', ('apl',), ('*.apl',), ()), 'ActionScript3Lexer': ('pygments.lexers.actionscript', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript3', 'text/x-actionscript3', 'text/actionscript3')), 'ActionScriptLexer': ('pygments.lexers.actionscript', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')), @@ -44,6 +45,7 @@ LEXERS = { 'AutohotkeyLexer': ('pygments.lexers.automation', 'autohotkey', ('ahk', 'autohotkey'), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)), 'AwkLexer': ('pygments.lexers.textedit', 'Awk', ('awk', 'gawk', 'mawk', 'nawk'), ('*.awk',), ('application/x-awk',)), 'BBCodeLexer': ('pygments.lexers.markup', 'BBCode', ('bbcode',), (), ('text/x-bbcode',)), + 'BCLexer': ('pygments.lexers.algebra', 'BC', ('bc',), ('*.bc',), ()), 'BaseMakefileLexer': ('pygments.lexers.make', 'Base Makefile', ('basemake',), (), ()), 'BashLexer': ('pygments.lexers.shell', 'Bash', ('bash', 'sh', 'ksh', 'shell'), ('*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*', 'PKGBUILD'), ('application/x-sh', 'application/x-shellscript')), 'BashSessionLexer': ('pygments.lexers.shell', 'Bash Session', ('console', 'shell-session'), ('*.sh-session', '*.shell-session'), ('application/x-shell-session', 'application/x-sh-session')), @@ -51,11 +53,13 @@ LEXERS = { 'BefungeLexer': ('pygments.lexers.esoteric', 'Befunge', ('befunge',), ('*.befunge',), ('application/x-befunge',)), 'BlitzBasicLexer': ('pygments.lexers.basic', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)), 'BlitzMaxLexer': ('pygments.lexers.basic', 'BlitzMax', ('blitzmax', 'bmax'), ('*.bmx',), ('text/x-bmx',)), + 'BnfLexer': ('pygments.lexers.grammar_notation', 'BNF', ('bnf',), ('*.bnf',), ('text/x-bnf',)), 'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)), 'BoogieLexer': ('pygments.lexers.esoteric', 'Boogie', ('boogie',), ('*.bpl',), ()), 'BrainfuckLexer': ('pygments.lexers.esoteric', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)), 'BroLexer': ('pygments.lexers.dsls', 'Bro', ('bro',), ('*.bro',), ()), 'BugsLexer': ('pygments.lexers.modeling', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bug',), ()), + 'CAmkESLexer': ('pygments.lexers.esoteric', 'CAmkES', ('camkes', 'idl4'), ('*.camkes', '*.idl4'), ()), 'CLexer': ('pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc'), ('text/x-chdr', 'text/x-csrc')), 'CMakeLexer': ('pygments.lexers.make', 'CMake', ('cmake',), ('*.cmake', 'CMakeLists.txt'), ('text/x-cmake',)), 'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)), @@ -91,8 +95,9 @@ LEXERS = { 'CrmshLexer': ('pygments.lexers.dsls', 'Crmsh', ('crmsh', 'pcmk'), ('*.crmsh', '*.pcmk'), ()), 'CrocLexer': ('pygments.lexers.d', 'Croc', ('croc',), ('*.croc',), ('text/x-crocsrc',)), 'CryptolLexer': ('pygments.lexers.haskell', 'Cryptol', ('cryptol', 'cry'), ('*.cry',), ('text/x-cryptol',)), - 'CsoundOrchestraLexer': ('pygments.lexers.csound', 'Csound Orchestra', (), ('*.orc',), ()), - 'CsoundScoreLexer': ('pygments.lexers.csound', 'Csound Score', (), ('*.sco',), ()), + 'CsoundDocumentLexer': ('pygments.lexers.csound', 'Csound Document', ('csound-document', 'csound-csd'), ('*.csd',), ()), + 'CsoundOrchestraLexer': ('pygments.lexers.csound', 'Csound Orchestra', ('csound', 'csound-orc'), ('*.orc',), ()), + 'CsoundScoreLexer': ('pygments.lexers.csound', 'Csound Score', ('csound-score', 'csound-sco'), ('*.sco',), ()), 'CssDjangoLexer': ('pygments.lexers.templates', 'CSS+Django/Jinja', ('css+django', 'css+jinja'), (), ('text/css+django', 'text/css+jinja')), 'CssErbLexer': ('pygments.lexers.templates', 'CSS+Ruby', ('css+erb', 'css+ruby'), (), ('text/css+ruby',)), 'CssGenshiLexer': ('pygments.lexers.templates', 'CSS+Genshi Text', ('css+genshitext', 'css+genshi'), (), ('text/css+genshi',)), @@ -133,6 +138,7 @@ LEXERS = { 'EvoqueHtmlLexer': ('pygments.lexers.templates', 'HTML+Evoque', ('html+evoque',), ('*.html',), ('text/html+evoque',)), 'EvoqueLexer': ('pygments.lexers.templates', 'Evoque', ('evoque',), ('*.evoque',), ('application/x-evoque',)), 'EvoqueXmlLexer': ('pygments.lexers.templates', 'XML+Evoque', ('xml+evoque',), ('*.xml',), ('application/xml+evoque',)), + 'EzhilLexer': ('pygments.lexers.ezhil', 'Ezhil', ('ezhil',), ('*.n',), ('text/x-ezhil',)), 'FSharpLexer': ('pygments.lexers.dotnet', 'FSharp', ('fsharp',), ('*.fs', '*.fsi'), ('text/x-fsharp',)), 'FactorLexer': ('pygments.lexers.factor', 'Factor', ('factor',), ('*.factor',), ('text/x-factor',)), 'FancyLexer': ('pygments.lexers.ruby', 'Fancy', ('fancy', 'fy'), ('*.fy', '*.fancypack'), ('text/x-fancysrc',)), @@ -162,6 +168,7 @@ LEXERS = { 'HandlebarsLexer': ('pygments.lexers.templates', 'Handlebars', ('handlebars',), (), ()), 'HaskellLexer': ('pygments.lexers.haskell', 'Haskell', ('haskell', 'hs'), ('*.hs',), ('text/x-haskell',)), 'HaxeLexer': ('pygments.lexers.haxe', 'Haxe', ('hx', 'haxe', 'hxsl'), ('*.hx', '*.hxsl'), ('text/haxe', 'text/x-haxe', 'text/x-hx')), + 'HexdumpLexer': ('pygments.lexers.hexdump', 'Hexdump', ('hexdump',), (), ()), 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja', 'htmldjango'), (), ('text/html+django', 'text/html+jinja')), 'HtmlGenshiLexer': ('pygments.lexers.templates', 'HTML+Genshi', ('html+genshi', 'html+kid'), (), ('text/html+genshi',)), 'HtmlLexer': ('pygments.lexers.html', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml', '*.xslt'), ('text/html', 'application/xhtml+xml')), @@ -280,6 +287,7 @@ LEXERS = { 'OocLexer': ('pygments.lexers.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)), 'OpaLexer': ('pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)), 'OpenEdgeLexer': ('pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')), + 'PacmanConfLexer': ('pygments.lexers.configs', 'PacmanConf', ('pacmanconf',), ('pacman.conf',), ()), 'PanLexer': ('pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()), 'ParaSailLexer': ('pygments.lexers.parasail', 'ParaSail', ('parasail',), ('*.psi', '*.psl'), ('text/x-parasail',)), 'PawnLexer': ('pygments.lexers.pawn', 'Pawn', ('pawn',), ('*.p', '*.pwn', '*.inc'), ('text/x-pawn',)), @@ -288,6 +296,7 @@ LEXERS = { 'PhpLexer': ('pygments.lexers.php', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]', '*.inc'), ('text/x-php',)), 'PigLexer': ('pygments.lexers.jvm', 'Pig', ('pig',), ('*.pig',), ('text/x-pig',)), 'PikeLexer': ('pygments.lexers.c_like', 'Pike', ('pike',), ('*.pike', '*.pmod'), ('text/x-pike',)), + 'PkgConfigLexer': ('pygments.lexers.configs', 'PkgConfig', ('pkgconfig',), ('*.pc',), ()), 'PlPgsqlLexer': ('pygments.lexers.sql', 'PL/pgSQL', ('plpgsql',), (), ('text/x-plpgsql',)), 'PostScriptLexer': ('pygments.lexers.graphics', 'PostScript', ('postscript', 'postscr'), ('*.ps', '*.eps'), ('application/postscript',)), 'PostgresConsoleLexer': ('pygments.lexers.sql', 'PostgreSQL console (psql)', ('psql', 'postgresql-console', 'postgres-console'), (), ('text/x-postgresql-psql',)), @@ -307,6 +316,7 @@ LEXERS = { 'PythonLexer': ('pygments.lexers.python', 'Python', ('python', 'py', 'sage'), ('*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'), ('text/x-python', 'application/x-python')), 'PythonTracebackLexer': ('pygments.lexers.python', 'Python Traceback', ('pytb',), ('*.pytb',), ('text/x-python-traceback',)), 'QBasicLexer': ('pygments.lexers.basic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ('text/basic',)), + 'QVToLexer': ('pygments.lexers.qvt', 'QVTO', ('qvto', 'qvt'), ('*.qvto',), ()), 'QmlLexer': ('pygments.lexers.webmisc', 'QML', ('qml', 'qbs'), ('*.qml', '*.qbs'), ('application/x-qml', 'application/x-qt.qbs+qml')), 'RConsoleLexer': ('pygments.lexers.r', 'RConsole', ('rconsole', 'rout'), ('*.Rout',), ()), 'RPMSpecLexer': ('pygments.lexers.installers', 'RPMSpec', ('spec',), ('*.spec',), ('text/x-rpm-spec',)), @@ -370,9 +380,12 @@ LEXERS = { 'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)), 'TcshSessionLexer': ('pygments.lexers.shell', 'Tcsh Session', ('tcshcon',), (), ()), 'TeaTemplateLexer': ('pygments.lexers.templates', 'Tea', ('tea',), ('*.tea',), ('text/x-tea',)), + 'TermcapLexer': ('pygments.lexers.configs', 'Termcap', ('termcap',), ('termcap', 'termcap.src'), ()), + 'TerminfoLexer': ('pygments.lexers.configs', 'Terminfo', ('terminfo',), ('terminfo', 'terminfo.src'), ()), 'TerraformLexer': ('pygments.lexers.configs', 'Terraform', ('terraform', 'tf'), ('*.tf',), ('application/x-tf', 'application/x-terraform')), 'TexLexer': ('pygments.lexers.markup', 'TeX', ('tex', 'latex'), ('*.tex', '*.aux', '*.toc'), ('text/x-tex', 'text/x-latex')), 'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',), ('text/plain',)), + 'ThriftLexer': ('pygments.lexers.dsls', 'Thrift', ('thrift',), ('*.thrift',), ('application/x-thrift',)), 'TodotxtLexer': ('pygments.lexers.textfmts', 'Todotxt', ('todotxt',), ('todo.txt', '*.todotxt'), ('text/x-todo',)), 'TreetopLexer': ('pygments.lexers.parsers', 'Treetop', ('treetop',), ('*.treetop', '*.tt'), ()), 'TurtleLexer': ('pygments.lexers.rdf', 'Turtle', ('turtle',), ('*.ttl',), ('text/turtle', 'application/x-turtle')), @@ -434,11 +447,18 @@ if __name__ == '__main__': # pragma: no cover # extract useful sourcecode from this file with open(__file__) as fp: content = fp.read() + # replace crnl to nl for Windows. + # + # Note that, originally, contributers should keep nl of master + # repository, for example by using some kind of automatic + # management EOL, like `EolExtension + # `. + content = content.replace("\r\n", "\n") header = content[:content.find('LEXERS = {')] footer = content[content.find("if __name__ == '__main__':"):] # write new file - with open(__file__, 'w') as fp: + with open(__file__, 'wb') as fp: fp.write(header) fp.write('LEXERS = {\n %s,\n}\n\n' % ',\n '.join(found_lexers)) fp.write(footer) diff --git a/pygments/lexers/algebra.py b/pygments/lexers/algebra.py index 873b1bf2..fc54c3c3 100644 --- a/pygments/lexers/algebra.py +++ b/pygments/lexers/algebra.py @@ -15,7 +15,7 @@ from pygments.lexer import RegexLexer, bygroups, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation -__all__ = ['GAPLexer', 'MathematicaLexer', 'MuPADLexer'] +__all__ = ['GAPLexer', 'MathematicaLexer', 'MuPADLexer', 'BCLexer'] class GAPLexer(RegexLexer): @@ -65,7 +65,7 @@ class GAPLexer(RegexLexer): (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number), (r'\.[0-9]+(?:e[0-9]+)?', Number), (r'.', Text) - ] + ], } @@ -183,5 +183,39 @@ class MuPADLexer(RegexLexer): (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline) - ] + ], + } + + +class BCLexer(RegexLexer): + """ + A `BC `_ lexer. + + .. versionadded:: 2.1 + """ + name = 'BC' + aliases = ['bc'] + filenames = ['*.bc'] + + tokens = { + 'root': [ + (r'/\*', Comment.Multiline, 'comment'), + (r'"(?:[^"\\]|\\.)*"', String), + (r'[{}();,]', Punctuation), + (words(('if', 'else', 'while', 'for', 'break', 'continue', + 'halt', 'return', 'define', 'auto', 'print', 'read', + 'length', 'scale', 'sqrt', 'limits', 'quit', + 'warranty'), suffix=r'\b'), Keyword), + (r'\+\+|--|\|\||&&|' + r'([-<>+*%\^/!=])=?', Operator), + # bc doesn't support exponential + (r'[0-9]+(\.[0-9]*)?', Number), + (r'\.[0-9]+', Number), + (r'.', Text) + ], + 'comment': [ + (r'[^*/]+', Comment.Multiline), + (r'\*/', Comment.Multiline, '#pop'), + (r'[*/]', Comment.Multiline) + ], } diff --git a/pygments/lexers/c_cpp.py b/pygments/lexers/c_cpp.py index 2b875093..5a7137ea 100644 --- a/pygments/lexers/c_cpp.py +++ b/pygments/lexers/c_cpp.py @@ -88,7 +88,7 @@ class CFamilyLexer(RegexLexer): (r'((?:[\w*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_]\w*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')?(\{)', + r'([^;{]*)(\{)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation), 'function'), @@ -96,7 +96,7 @@ class CFamilyLexer(RegexLexer): (r'((?:[\w*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_]\w*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')?(;)', + r'([^;]*)(;)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation)), default('statement'), @@ -123,6 +123,7 @@ class CFamilyLexer(RegexLexer): (r'\\', String), # stray backslash ], 'macro': [ + (r'(include)(' + _ws1 + ')([^\n]+)', bygroups(Comment.Preproc, Text, Comment.PreprocFile)), (r'[^/\n]+', Comment.Preproc), (r'/[*](.|\n)*?[*]/', Comment.Multiline), (r'//.*?\n', Comment.Single, '#pop'), diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index f5a67bc4..c46d8bb8 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -13,13 +13,14 @@ import re from pygments.lexer import RegexLexer, default, words, bygroups, include, using from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Whitespace + Number, Punctuation, Whitespace, Literal from pygments.lexers.shell import BashLexer __all__ = ['IniLexer', 'RegeditLexer', 'PropertiesLexer', 'KconfigLexer', 'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer', 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer', - 'TerraformLexer'] + 'TerraformLexer', 'TermcapLexer', 'TerminfoLexer', + 'PkgConfigLexer', 'PacmanConfLexer'] class IniLexer(RegexLexer): @@ -617,3 +618,210 @@ class TerraformLexer(RegexLexer): (r'\\\n', Text), ], } + + +class TermcapLexer(RegexLexer): + """ + Lexer for termcap database source. + + This is very simple and minimal. + + .. versionadded:: 2.1 + """ + name = 'Termcap' + aliases = ['termcap',] + + filenames = ['termcap', 'termcap.src',] + mimetypes = [] + + # NOTE: + # * multiline with trailing backslash + # * separator is ':' + # * to embed colon as data, we must use \072 + # * space after separator is not allowed (mayve) + tokens = { + 'root': [ + (r'^#.*$', Comment), + (r'^[^\s#:\|]+', Name.Tag, 'names'), + ], + 'names': [ + (r'\n', Text, '#pop'), + (r':', Punctuation, 'defs'), + (r'\|', Punctuation), + (r'[^:\|]+', Name.Attribute), + ], + 'defs': [ + (r'\\\n[ \t]*', Text), + (r'\n[ \t]*', Text, '#pop:2'), + (r'(#)([0-9]+)', bygroups(Operator, Number)), + (r'=', Operator, 'data'), + (r':', Punctuation), + (r'[^\s:=#]+', Name.Class), + ], + 'data': [ + (r'\\072', Literal), + (r':', Punctuation, '#pop'), + (r'[^:\\]+', Literal), # for performance + (r'.', Literal), + ], + } + + +class TerminfoLexer(RegexLexer): + """ + Lexer for terminfo database source. + + This is very simple and minimal. + + .. versionadded:: 2.1 + """ + name = 'Terminfo' + aliases = ['terminfo',] + + filenames = ['terminfo', 'terminfo.src',] + mimetypes = [] + + # NOTE: + # * multiline with leading whitespace + # * separator is ',' + # * to embed comma as data, we can use \, + # * space after separator is allowed + tokens = { + 'root': [ + (r'^#.*$', Comment), + (r'^[^\s#,\|]+', Name.Tag, 'names'), + ], + 'names': [ + (r'\n', Text, '#pop'), + (r'(,)([ \t]*)', bygroups(Punctuation, Text), 'defs'), + (r'\|', Punctuation), + (r'[^,\|]+', Name.Attribute), + ], + 'defs': [ + (r'\n[ \t]+', Text), + (r'\n', Text, '#pop:2'), + (r'(#)([0-9]+)', bygroups(Operator, Number)), + (r'=', Operator, 'data'), + (r'(,)([ \t]*)', bygroups(Punctuation, Text)), + (r'[^\s,=#]+', Name.Class), + ], + 'data': [ + (r'\\[,\\]', Literal), + (r'(,)([ \t]*)', bygroups(Punctuation, Text), '#pop'), + (r'[^\\,]+', Literal), # for performance + (r'.', Literal), + ], + } + + +class PkgConfigLexer(RegexLexer): + """ + Lexer for `pkg-config + `_ + (see also `manual page `_). + + .. versionadded:: 2.1 + """ + + name = 'PkgConfig' + aliases = ['pkgconfig',] + filenames = ['*.pc',] + mimetypes = [] + + tokens = { + 'root': [ + (r'#.*$', Comment.Single), + + # variable definitions + (r'^(\w+)(=)', bygroups(Name.Attribute, Operator)), + + # keyword lines + (r'^([\w.]+)(:)', + bygroups(Name.Tag, Punctuation), 'spvalue'), + + # variable references + include('interp'), + + # fallback + (r'[^${}#=:\n.]+', Text), + (r'.', Text), + ], + 'interp': [ + # you can escape literal "$" as "$$" + (r'\$\$', Text), + + # variable references + (r'\$\{', String.Interpol, 'curly'), + ], + 'curly': [ + (r'\}', String.Interpol, '#pop'), + (r'\w+', Name.Attribute), + ], + 'spvalue': [ + include('interp'), + + (r'#.*$', Comment.Single, '#pop'), + (r'\n', Text, '#pop'), + + # fallback + (r'[^${}#\n]+', Text), + (r'.', Text), + ], + } + + +class PacmanConfLexer(RegexLexer): + """ + Lexer for `pacman.conf + `_. + + Actually, IniLexer works almost fine for this format, + but it yield error token. It is because pacman.conf has + a form without assignment like: + + UseSyslog + Color + TotalDownload + CheckSpace + VerbosePkgLists + + These are flags to switch on. + + .. versionadded:: 2.1 + """ + + name = 'PacmanConf' + aliases = ['pacmanconf',] + filenames = ['pacman.conf',] + mimetypes = [] + + tokens = { + 'root': [ + # comment + (r'#.*$', Comment.Single), + + # section header + (r'^\s*\[.*?\]\s*$', Keyword), + + # variable definitions + # (Leading space is allowed...) + (r'(\w+)(\s*)(=)', + bygroups(Name.Attribute, Text, Operator)), + + # flags to on + (r'^(\s*)(\w+)(\s*)$', + bygroups(Text, Name.Attribute, Text)), + + # built-in special values + (words(( + '$repo', # repository + '$arch', # architecture + '%o', # outfile + '%u', # url + ), suffix=r'\b'), + Name.Variable), + + # fallback + (r'.', Text), + ], + } diff --git a/pygments/lexers/csound.py b/pygments/lexers/csound.py index 361f048a..51414073 100644 --- a/pygments/lexers/csound.py +++ b/pygments/lexers/csound.py @@ -9,17 +9,17 @@ :license: BSD, see LICENSE for details. """ -import re +import copy, re from pygments.lexer import RegexLexer, bygroups, default, include, using, words from pygments.token import Comment, Keyword, Name, Number, Operator, Punctuation, \ String, Text from pygments.lexers._csound_builtins import OPCODES +from pygments.lexers.html import HtmlLexer from pygments.lexers.python import PythonLexer from pygments.lexers.scripting import LuaLexer -# The CsoundDocumentLexer casuses a Pygments test to fail. -__all__ = ['CsoundScoreLexer', 'CsoundOrchestraLexer'] # , 'CsoundDocumentLexer'] +__all__ = ['CsoundScoreLexer', 'CsoundOrchestraLexer', 'CsoundDocumentLexer'] newline = (r'((?:;|//).*)*(\n)', bygroups(Comment.Single, Text)) @@ -98,6 +98,7 @@ class CsoundScoreLexer(CsoundLexer): """ name = 'Csound Score' + aliases = ['csound-score', 'csound-sco'] filenames = ['*.sco'] tokens = { @@ -140,6 +141,7 @@ class CsoundOrchestraLexer(CsoundLexer): """ name = 'Csound Orchestra' + aliases = ['csound', 'csound-orc'] filenames = ['*.orc'] user_defined_opcodes = set() @@ -309,49 +311,56 @@ class CsoundOrchestraLexer(CsoundLexer): } -# Below is a lexer for Csound documents, but it causes a Pygments test to fail. - -# import copy -# from pygments.lexers.html import HtmlLexer, XmlLexer -# -# class CsoundDocumentLexer(XmlLexer): -# """ -# For `Csound `_ documents. -# """ -# -# name = 'Csound Document' -# aliases = ['csound'] -# filenames = ['*.csd'] -# -# tokens = copy.deepcopy(XmlLexer.tokens) -# for i, item in enumerate(tokens['root']): -# if len(item) > 2 and item[2] == 'tag': -# (tokens['root']).insert(i, (r'(<)(\s*)(CsInstruments)(\s*)', -# bygroups(Name.Tag, Text, Name.Tag, Text), -# ('orchestra content', 'tag'))) -# (tokens['root']).insert(i, (r'(<)(\s*)(CsScore)(\s*)', -# bygroups(Name.Tag, Text, Name.Tag, Text), -# ('score content', 'tag'))) -# (tokens['root']).insert(i, (r'(<)(\s*)(html)(\s*)', -# bygroups(Name.Tag, Text, Name.Tag, Text), -# ('HTML', 'tag'))) -# break -# -# tokens['orchestra content'] = [ -# (r'(<)(\s*)(/)(\s*)(CsInstruments)(\s*)(>)', -# bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), -# '#pop'), -# (r'.+?(?=<\s*/\s*CsInstruments\s*>)', using(CsoundOrchestraLexer)) -# ] -# tokens['score content'] = [ -# (r'(<)(\s*)(/)(\s*)(CsScore)(\s*)(>)', -# bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), -# '#pop'), -# (r'.+?(?=<\s*/\s*CsScore\s*>)', using(CsoundScoreLexer)) -# ] -# tokens['HTML'] = [ -# (r'(<)(\s*)(/)(\s*)(html)(\s*)(>)', -# bygroups(Name.Tag, Text, Name.Tag, Text, Name.Tag, Text, Name.Tag), -# '#pop'), -# (r'.+?(?=<\s*/\s*html\s*>)', using(HtmlLexer)) -# ] +class CsoundDocumentLexer(RegexLexer): + """ + For `Csound `_ documents. + + + """ + + name = 'Csound Document' + aliases = ['csound-document', 'csound-csd'] + filenames = ['*.csd'] + + # These tokens are based on those in XmlLexer in pygments/lexers/html.py. Making + # CsoundDocumentLexer a subclass of XmlLexer rather than RegexLexer may seem like a + # better idea, since Csound Document files look like XML files. However, Csound + # Documents can contain Csound comments (preceded by //, for example) before and + # after the root element, unescaped bitwise AND & and less than < operators, etc. In + # other words, while Csound Document files look like XML files, they may not actually + # be XML files. + tokens = { + 'root': [ + newline, + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + (r'[^<&;/]+', Text), + (r'<\s*CsInstruments', Name.Tag, ('orchestra', 'tag')), + (r'<\s*CsScore', Name.Tag, ('score', 'tag')), + (r'<\s*[hH][tT][mM][lL]', Name.Tag, ('HTML', 'tag')), + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag) + ], + 'orchestra': [ + (r'<\s*/\s*CsInstruments\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*CsInstruments\s*>)', using(CsoundOrchestraLexer)) + ], + 'score': [ + (r'<\s*/\s*CsScore\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*CsScore\s*>)', using(CsoundScoreLexer)) + ], + 'HTML': [ + (r'<\s*/\s*[hH][tT][mM][lL]\s*>', Name.Tag, '#pop'), + (r'(.|\n)+?(?=<\s*/\s*[hH][tT][mM][lL]\s*>)', using(HtmlLexer)) + ], + 'tag': [ + (r'\s+', Text), + (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), + (r'/?\s*>', Name.Tag, '#pop') + ], + 'attr': [ + (r'\s+', Text), + (r'".*?"', String, '#pop'), + (r"'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop') + ] + } diff --git a/pygments/lexers/dsls.py b/pygments/lexers/dsls.py index c0671130..24fda2a2 100644 --- a/pygments/lexers/dsls.py +++ b/pygments/lexers/dsls.py @@ -11,13 +11,14 @@ import re -from pygments.lexer import RegexLexer, bygroups, words, include, default +from pygments.lexer import RegexLexer, bygroups, words, include, default, \ + this, using, combined from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Literal, Whitespace __all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer', 'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer', - 'CrmshLexer'] + 'CrmshLexer', 'ThriftLexer'] class ProtoBufLexer(RegexLexer): @@ -82,6 +83,111 @@ class ProtoBufLexer(RegexLexer): } +class ThriftLexer(RegexLexer): + """ + For `Thrift `__ interface definitions. + + .. versionadded:: 2.1 + """ + name = 'Thrift' + aliases = ['thrift'] + filenames = ['*.thrift'] + mimetypes = ['application/x-thrift'] + + tokens = { + 'root': [ + include('whitespace'), + include('comments'), + (r'"', String.Double, combined('stringescape', 'dqs')), + (r'\'', String.Single, combined('stringescape', 'sqs')), + (r'(namespace)(\s+)', + bygroups(Keyword.Namespace, Text.Whitespace), 'namespace'), + (r'(enum|union|struct|service|exception)(\s+)', + bygroups(Keyword.Declaration, Text.Whitespace), 'class'), + (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)' # return arguments + r'((?:[^\W\d]|\$)[\w$]*)' # method name + r'(\s*)(\()', # signature start + bygroups(using(this), Name.Function, Text, Operator)), + include('keywords'), + include('numbers'), + (r'[&=]', Operator), + (r'[:;\,\{\}\(\)\<>\[\]]', Punctuation), + (r'[a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*', Name), + ], + 'whitespace': [ + (r'\n', Text.Whitespace), + (r'\s+', Text.Whitespace), + ], + 'comments': [ + (r'#.*$', Comment), + (r'//.*?\n', Comment), + (r'/\*[\w\W]*?\*/', Comment.Multiline), + ], + 'stringescape': [ + (r'\\([\\nrt"\'])', String.Escape), + ], + 'dqs': [ + (r'"', String.Double, '#pop'), + (r'[^\\"\n]+', String.Double), + ], + 'sqs': [ + (r"'", String.Single, '#pop'), + (r'[^\\\'\n]+', String.Single), + ], + 'namespace': [ + (r'[a-z\*](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*', Name.Namespace, '#pop'), + default('#pop'), + ], + 'class': [ + (r'[a-zA-Z_]\w*', Name.Class, '#pop'), + default('#pop'), + ], + 'keywords': [ + (r'(async|oneway|extends|throws|required|optional)\b', Keyword), + (r'(true|false)\b', Keyword.Constant), + (r'(const|typedef)\b', Keyword.Declaration), + (words(( + 'cpp_namespace', 'cpp_include', 'cpp_type', 'java_package', + 'cocoa_prefix', 'csharp_namespace', 'delphi_namespace', + 'php_namespace', 'py_module', 'perl_package', + 'ruby_namespace', 'smalltalk_category', 'smalltalk_prefix', + 'xsd_all', 'xsd_optional', 'xsd_nillable', 'xsd_namespace', + 'xsd_attrs', 'include'), suffix=r'\b'), + Keyword.Namespace), + (words(( + 'void', 'bool', 'byte', 'i16', 'i32', 'i64', 'double', + 'string', 'binary', 'void', 'map', 'list', 'set', 'slist', + 'senum'), suffix=r'\b'), + Keyword.Type), + (words(( + 'BEGIN', 'END', '__CLASS__', '__DIR__', '__FILE__', + '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', + 'abstract', 'alias', 'and', 'args', 'as', 'assert', 'begin', + 'break', 'case', 'catch', 'class', 'clone', 'continue', + 'declare', 'def', 'default', 'del', 'delete', 'do', 'dynamic', + 'elif', 'else', 'elseif', 'elsif', 'end', 'enddeclare', + 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', + 'ensure', 'except', 'exec', 'finally', 'float', 'for', + 'foreach', 'function', 'global', 'goto', 'if', 'implements', + 'import', 'in', 'inline', 'instanceof', 'interface', 'is', + 'lambda', 'module', 'native', 'new', 'next', 'nil', 'not', + 'or', 'pass', 'public', 'print', 'private', 'protected', + 'raise', 'redo', 'rescue', 'retry', 'register', 'return', + 'self', 'sizeof', 'static', 'super', 'switch', 'synchronized', + 'then', 'this', 'throw', 'transient', 'try', 'undef', + 'unless', 'unsigned', 'until', 'use', 'var', 'virtual', + 'volatile', 'when', 'while', 'with', 'xor', 'yield'), + prefix=r'\b', suffix=r'\b'), + Keyword.Reserved), + ], + 'numbers': [ + (r'[+-]?(\d+\.\d+([eE][+-]?\d+)?|\.?\d+[eE][+-]?\d+)', Number.Float), + (r'[+-]?0x[0-9A-Fa-f]+', Number.Hex), + (r'[+-]?[0-9]+', Number.Integer), + ], + } + + class BroLexer(RegexLexer): """ For `Bro `_ scripts. diff --git a/pygments/lexers/esoteric.py.orig b/pygments/lexers/esoteric.py.orig new file mode 100644 index 00000000..06c1de8d --- /dev/null +++ b/pygments/lexers/esoteric.py.orig @@ -0,0 +1,201 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.esoteric + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for esoteric languages. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, include, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Error, Whitespace + +__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', 'CAmkESLexer', 'AheuiLexer'] + + +class BrainfuckLexer(RegexLexer): + """ + Lexer for the esoteric `BrainFuck `_ + language. + """ + + name = 'Brainfuck' + aliases = ['brainfuck', 'bf'] + filenames = ['*.bf', '*.b'] + mimetypes = ['application/x-brainfuck'] + + tokens = { + 'common': [ + # use different colors for different instruction types + (r'[.,]+', Name.Tag), + (r'[+-]+', Name.Builtin), + (r'[<>]+', Name.Variable), + (r'[^.,+\-<>\[\]]+', Comment), + ], + 'root': [ + (r'\[', Keyword, 'loop'), + (r'\]', Error), + include('common'), + ], + 'loop': [ + (r'\[', Keyword, '#push'), + (r'\]', Keyword, '#pop'), + include('common'), + ] + } + + +class BefungeLexer(RegexLexer): + """ + Lexer for the esoteric `Befunge `_ + language. + + .. versionadded:: 0.7 + """ + name = 'Befunge' + aliases = ['befunge'] + filenames = ['*.befunge'] + mimetypes = ['application/x-befunge'] + + tokens = { + 'root': [ + (r'[0-9a-f]', Number), + (r'[+*/%!`-]', Operator), # Traditional math + (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives + (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives + (r'[|_mw]', Keyword), + (r'[{}]', Name.Tag), # Befunge-98 stack ops + (r'".*?"', String.Double), # Strings don't appear to allow escapes + (r'\'.', String.Single), # Single character + (r'[#;]', Comment), # Trampoline... depends on direction hit + (r'[pg&~=@iotsy]', Keyword), # Misc + (r'[()A-Z]', Comment), # Fingerprints + (r'\s+', Text), # Whitespace doesn't matter + ], + } + + +class RedcodeLexer(RegexLexer): + """ + A simple Redcode lexer based on ICWS'94. + Contributed by Adam Blinkinsop . + + .. versionadded:: 0.8 + """ + name = 'Redcode' + aliases = ['redcode'] + filenames = ['*.cw'] + + opcodes = ('DAT', 'MOV', 'ADD', 'SUB', 'MUL', 'DIV', 'MOD', + 'JMP', 'JMZ', 'JMN', 'DJN', 'CMP', 'SLT', 'SPL', + 'ORG', 'EQU', 'END') + modifiers = ('A', 'B', 'AB', 'BA', 'F', 'X', 'I') + + tokens = { + 'root': [ + # Whitespace: + (r'\s+', Text), + (r';.*$', Comment.Single), + # Lexemes: + # Identifiers + (r'\b(%s)\b' % '|'.join(opcodes), Name.Function), + (r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator), + (r'[A-Za-z_]\w+', Name), + # Operators + (r'[-+*/%]', Operator), + (r'[#$@<>]', Operator), # mode + (r'[.,]', Punctuation), # mode + # Numbers + (r'[-+]?\d+', Number.Integer), + ], + } + + +class BoogieLexer(RegexLexer): + """ + For `Boogie `_ source code. + + .. versionadded:: 2.1 + """ + name = 'Boogie' + aliases = ['boogie'] + filenames = ['*.bpl'] + + tokens = { + 'root': [ + # Whitespace and Comments + (r'\n', Whitespace), + (r'\s+', Whitespace), + (r'//[/!](.*?)\n', Comment.Doc), + (r'//(.*?)\n', Comment.Single), + (r'/\*', Comment.Multiline, 'comment'), + + (words(( + 'axiom', 'break', 'call', 'ensures', 'else', 'exists', 'function', + 'forall', 'if', 'invariant', 'modifies', 'procedure', 'requires', + 'then', 'var', 'while'), + suffix=r'\b'), Keyword), + (words(('const',), suffix=r'\b'), Keyword.Reserved), + + (words(('bool', 'int', 'ref'), suffix=r'\b'), Keyword.Type), + include('numbers'), + (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator), + (r"([{}():;,.])", Punctuation), + # Identifier + (r'[a-zA-Z_]\w*', Name), + ], + 'comment': [ + (r'[^*/]+', Comment.Multiline), + (r'/\*', Comment.Multiline, '#push'), + (r'\*/', Comment.Multiline, '#pop'), + (r'[*/]', Comment.Multiline), + ], + 'numbers': [ + (r'[0-9]+', Number.Integer), + ], + } + + +class AheuiLexer(RegexLexer): + """ + Aheui_ Lexer. + + Aheui_ is esoteric language based on Korean alphabets. + + .. _Aheui:: http://aheui.github.io/ + + """ + + name = u'Aheui' + aliases = ['aheui'] + filenames = ['*.aheui'] + + tokens = { + 'root': [ + (u'[' + u'가-갛갸-걓거-겋겨-곃고-곻교-궇규-긯' + u'까-깧꺄-꺟꺼-껗껴-꼏꼬-꽇꾜-꿓뀨-끻' + u'나-낳냐-냫너-넣녀-녛노-놓뇨-눟뉴-닇' + u'다-닿댜-댷더-덯뎌-뎧도-돟됴-둫듀-딓' + u'따-땋땨-떃떠-떻뗘-뗳또-똫뚀-뚷뜌-띟' + u'라-랗랴-럏러-렇려-렿로-롷료-뤃류-릫' + u'마-맣먀-먛머-멓며-몋모-뫃묘-뭏뮤-믷' + u'바-밯뱌-뱧버-벟벼-볗보-봏뵤-붛뷰-빃' + u'빠-빻뺘-뺳뻐-뻫뼈-뼣뽀-뽛뾰-뿧쀼-삏' + u'사-샇샤-샿서-섷셔-셯소-솧쇼-숳슈-싛' + u'싸-쌓쌰-썋써-쎃쎠-쎻쏘-쏳쑈-쑿쓔-씧' + u'아-앟야-얗어-엏여-옇오-옿요-웋유-읳' + u'자-잫쟈-쟣저-젛져-졓조-좋죠-줗쥬-즿' + u'짜-짷쨔-쨯쩌-쩧쪄-쪟쪼-쫗쬬-쭣쮸-찋' + u'차-챃챠-챻처-첳쳐-쳫초-촣쵸-춯츄-칗' + u'카-캏캬-컇커-컿켜-켷코-콯쿄-쿻큐-킣' + u'타-탛탸-턓터-텋텨-톃토-톻툐-퉇튜-틯' + u'파-팧퍄-퍟퍼-펗펴-폏포-퐇표-풓퓨-픻' + u'하-핳햐-햫허-헣혀-혛호-홓효-훟휴-힇' + u']', Operator), + ('.', Comment), + ], + } diff --git a/pygments/lexers/ezhil.py b/pygments/lexers/ezhil.py new file mode 100644 index 00000000..713541ee --- /dev/null +++ b/pygments/lexers/ezhil.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.ezhil + ~~~~~~~~~~~~~~~~~~~~~~ + + Pygments lexers for Ezhil language. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re +from pygments.lexer import RegexLexer, include, words +from pygments.token import Keyword, Text, Comment, Name +from pygments.token import String, Number, Punctuation, Operator + +__all__ = ['EzhilLexer'] + +class EzhilLexer(RegexLexer): + """ + Lexer for `Ezhil, a Tamil script-based programming language `_ + + .. versionadded:: 2.1 + """ + name = 'Ezhil' + aliases = ['ezhil'] + filenames = ['*.n'] + mimetypes = ['text/x-ezhil'] + flags = re.MULTILINE | re.UNICODE + # Refer to tamil.utf8.tamil_letters from open-tamil for a stricter version of this. + # This much simpler version is close enough, and includes combining marks. + _TALETTERS = u'[a-zA-Z_]|[\u0b80-\u0bff]' + tokens = { + 'root': [ + include('keywords'), + (r'#.*\n', Comment.Single), + (r'[@+/*,^\-%]|[!<>=]=?|&&?|\|\|?', Operator), + (u'இல்', Operator.Word), + (words(('assert', 'max', 'min', + 'நீளம்','சரம்_இடமாற்று','சரம்_கண்டுபிடி', + 'பட்டியல்','பின்இணை','வரிசைப்படுத்து', + 'எடு','தலைகீழ்','நீட்டிக்க','நுழைக்க','வை', + 'கோப்பை_திற','கோப்பை_எழுது','கோப்பை_மூடு', + 'pi','sin','cos','tan','sqrt','hypot','pow','exp','log','log10' + 'min','max','exit', + ), suffix=r'\b'), Name.Builtin), + (r'(True|False)\b', Keyword.Constant), + (r'[^\S\n]+', Text), + include('identifier'), + include('literal'), + (r'[(){}\[\]:;.]', Punctuation), + ], + 'keywords': [ + (u'பதிப்பி|தேர்ந்தெடு|தேர்வு|ஏதேனில்|ஆனால்|இல்லைஆனால்|இல்லை|ஆக|ஒவ்வொன்றாக|இல்|வரை|செய்|முடியேனில்|பின்கொடு|முடி|நிரல்பாகம்|தொடர்|நிறுத்து|நிரல்பாகம்', Keyword), + ], + 'identifier': [ + (u'(?:'+_TALETTERS+u')(?:[0-9]|'+_TALETTERS+u')*', Name), + ], + 'literal': [ + (r'".*?"', String), + (r'(?u)\d+((\.\d*)?[eE][+-]?\d+|\.\d*)', Number.Float), + (r'(?u)\d+', Number.Integer), + ] + } + + def __init__(self, **options): + super(EzhilLexer, self).__init__(**options) + self.encoding = options.get('encoding', 'utf-8') diff --git a/pygments/lexers/grammar_notation.py b/pygments/lexers/grammar_notation.py new file mode 100644 index 00000000..460914f4 --- /dev/null +++ b/pygments/lexers/grammar_notation.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.grammar_notation + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for grammer notations like BNF. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, bygroups, words +from pygments.token import Punctuation, Text, Comment, Operator, \ + Keyword, Name, Literal + +__all__ = ['BnfLexer', 'AbnfLexer'] + + +class BnfLexer(RegexLexer): + """ + This lexer is for grammer notations which are similar to + original BNF. + + In order to maximize a number of targets of this lexer, + let's decide some designs: + + * We don't distinguish `Terminal Symbol`. + + * We do assume that `NonTerminal Symbol` are always enclosed + with arrow brackets. + + * We do assume that `NonTerminal Symbol` may include + any printable characters except arrow brackets and ASCII 0x20. + This assumption is for `RBNF `_. + + * We do assume that target notation doesn't support comment. + + * We don't distinguish any operators and punctuation except + `::=`. + + Though these desision making might cause too minimal highlighting + and you might be disappointed, but it is reasonable for us. + + .. versionadded:: 2.1 + """ + + name = 'BNF' + aliases = ['bnf'] + filenames = ['*.bnf'] + mimetypes = ['text/x-bnf'] + + tokens = { + 'root': [ + (r'(<)([ -;=?-~]+)(>)', + bygroups(Punctuation, Name.Class, Punctuation)), + + # an only operator + (r'::=', Operator), + + # fallback + (r'[^<>:]+', Text), # for performance + (r'.', Text), + ], + } + + +class AbnfLexer(RegexLexer): + """ + Lexer for `IETF 7405 ABNF + `_ + (Updates `5234 `_) + grammars. + + .. versionadded:: 2.1 + """ + + name = 'ABNF' + aliases = ['abnf'] + filenames = ['*.abnf'] + mimetypes = ['text/x-abnf'] + + _core_rules = ( + 'ALPHA', 'BIT', 'CHAR', 'CR', 'CRLF', 'CTL', 'DIGIT', + 'DQUOTE', 'HEXDIG', 'HTAB', 'LF', 'LWSP', 'OCTET', + 'SP', 'VCHAR', 'WSP') + + tokens = { + 'root': [ + # comment + (r';.*$', Comment.Single), + + # quoted + # double quote itself in this state, it is as '%x22'. + (r'(%[si])?"[^"]*"', Literal), + + # binary (but i have never seen...) + (r'%b[01]+\-[01]+\b', Literal), # range + (r'%b[01]+(\.[01]+)*\b', Literal), # concat + + # decimal + (r'%d[0-9]+\-[0-9]+\b', Literal), # range + (r'%d[0-9]+(\.[0-9]+)*\b', Literal), # concat + + # hexadecimal + (r'%x[0-9a-fA-F]+\-[0-9a-fA-F]+\b', Literal), # range + (r'%x[0-9a-fA-F]+(\.[0-9a-fA-F]+)*\b', Literal), # concat + + # repetition (*element) including nRule + (r'\b[0-9]+\*[0-9]+', Operator), + (r'\b[0-9]+\*', Operator), + (r'\b[0-9]+', Operator), + (r'\*', Operator), + + # Strictly speaking, these are not keyword but + # are called `Core Rule'. + (words(_core_rules, suffix=r'\b'), Keyword), + + # nonterminals (ALPHA *(ALPHA / DIGIT / "-")) + (r'[a-zA-Z][a-zA-Z0-9-]+\b', Name.Class), + + # operators + (r'(=/|=|/)', Operator), + + # punctuation + (r'[\[\]()]', Punctuation), + + # fallback + (r'\s+', Text), + (r'.', Text), + ], + } diff --git a/pygments/lexers/hexdump.py b/pygments/lexers/hexdump.py new file mode 100644 index 00000000..efe16fa7 --- /dev/null +++ b/pygments/lexers/hexdump.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.hexdump + ~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for hexadecimal dumps. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, bygroups, include +from pygments.token import Text, Name, Number, String, Punctuation + +__all__ = ['HexdumpLexer'] + + +class HexdumpLexer(RegexLexer): + """ + For typical hex dump output formats by the UNIX and GNU/Linux tools ``hexdump``, + ``hd``, ``hexcat``, ``od`` and ``xxd``, and the DOS tool ``DEBUG``. For example: + + .. sourcecode:: hexdump + + 00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| + 00000010 02 00 3e 00 01 00 00 00 c5 48 40 00 00 00 00 00 |..>......H@.....| + + The specific supported formats are the outputs of: + + * ``hexdump FILE`` + * ``hexdump -C FILE`` -- the `canonical` format used in the example. + * ``hd FILE`` -- same as ``hexdump -C FILE``. + * ``hexcat FILE`` + * ``od -t x1z FILE`` + * ``xxd FILE`` + * ``DEBUG.EXE FILE.COM`` and entering ``d`` to the prompt. + + .. versionadded:: 2.1 + """ + name = 'Hexdump' + aliases = ['hexdump'] + + hd = r'[0-9A-Ha-h]' + + tokens = { + 'root': [ + (r'\n', Text), + include('offset'), + (r'('+hd+r'{2})(\-)('+hd+r'{2})', bygroups(Number.Hex, Punctuation, Number.Hex)), + (hd+r'{2}', Number.Hex), + (r'(\s{2,3})(\>)(.{16})(\<)$', bygroups(Text, Punctuation, String, Punctuation), 'bracket-strings'), + (r'(\s{2,3})(\|)(.{16})(\|)$', bygroups(Text, Punctuation, String, Punctuation), 'piped-strings'), + (r'(\s{2,3})(\>)(.{1,15})(\<)$', bygroups(Text, Punctuation, String, Punctuation)), + (r'(\s{2,3})(\|)(.{1,15})(\|)$', bygroups(Text, Punctuation, String, Punctuation)), + (r'(\s{2,3})(.{1,15})$', bygroups(Text, String)), + (r'(\s{2,3})(.{16}|.{20})$', bygroups(Text, String), 'nonpiped-strings'), + (r'\s', Text), + (r'^\*', Punctuation), + ], + 'offset': [ + (r'^('+hd+'+)(:)', bygroups(Name.Label, Punctuation), 'offset-mode'), + (r'^'+hd+'+', Name.Label), + ], + 'offset-mode': [ + (r'\s', Text, '#pop'), + (hd+'+', Name.Label), + (r':', Punctuation) + ], + 'piped-strings': [ + (r'\n', Text), + include('offset'), + (hd+r'{2}', Number.Hex), + (r'(\s{2,3})(\|)(.{1,16})(\|)$', bygroups(Text, Punctuation, String, Punctuation)), + (r'\s', Text), + (r'^\*', Punctuation), + ], + 'bracket-strings': [ + (r'\n', Text), + include('offset'), + (hd+r'{2}', Number.Hex), + (r'(\s{2,3})(\>)(.{1,16})(\<)$', bygroups(Text, Punctuation, String, Punctuation)), + (r'\s', Text), + (r'^\*', Punctuation), + ], + 'nonpiped-strings': [ + (r'\n', Text), + include('offset'), + (r'('+hd+r'{2})(\-)('+hd+r'{2})', bygroups(Number.Hex, Punctuation, Number.Hex)), + (hd+r'{2}', Number.Hex), + (r'(\s{19,})(.{1,20}?)$', bygroups(Text, String)), + (r'(\s{2,3})(.{1,20})$', bygroups(Text, String)), + (r'\s', Text), + (r'^\*', Punctuation), + ], + } diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 3982c91e..8e2d9797 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -511,6 +511,8 @@ class TypeScriptLexer(RegexLexer): (r'[0-9]+', Number.Integer), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single), + # Match stuff like: Decorators + (r'@\w+', Keyword.Declaration), ] } diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py index ccbd4c15..dee8e6c7 100644 --- a/pygments/lexers/python.py +++ b/pygments/lexers/python.py @@ -419,8 +419,10 @@ class PythonTracebackLexer(RegexLexer): tokens = { 'root': [ - (r'^Traceback \(most recent call last\):\n', - Generic.Traceback, 'intb'), + # Cover both (most recent call last) and (innermost last) + # The optional ^C allows us to catch keyboard interrupt signals. + (r'^(\^C)?(Traceback.*\n)', + bygroups(Text, Generic.Traceback), 'intb'), # SyntaxError starts with this. (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'), (r'^.*\n', Other), diff --git a/pygments/lexers/qvt.py b/pygments/lexers/qvt.py new file mode 100644 index 00000000..5bc61310 --- /dev/null +++ b/pygments/lexers/qvt.py @@ -0,0 +1,150 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.qvt + ~~~~~~~~~~~~~~~~~~~ + + Lexer for QVT Operational language. + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, bygroups, include, combined +from pygments.token import Text, Comment, Operator, Keyword, Punctuation, \ + Name, String, Number + +__all__ = ['QVToLexer'] + + +class QVToLexer(RegexLexer): + """ + For the `QVT Operational Mapping language `_. + + Reference for implementing this: «Meta Object Facility (MOF) 2.0 + Query/View/Transformation Specification», Version 1.1 - January 2011 + (http://www.omg.org/spec/QVT/1.1/), see §8.4, «Concrete Syntax» in + particular. + + Notable tokens assignments: + + - Name.Class is assigned to the identifier following any of the following + keywords: metamodel, class, exception, primitive, enum, transformation + or library + + - Name.Function is assigned to the names of mappings and queries + + - Name.Builtin.Pseudo is assigned to the pre-defined variables 'this', + 'self' and 'result'. + """ + # With obvious borrowings & inspiration from the Java, Python and C lexers + + name = 'QVTO' + aliases = ['qvto', 'qvt'] + filenames = ['*.qvto'] + + tokens = { + 'root': [ + (r'\n', Text), + (r'[^\S\n]+', Text), + (r'(--|//)(\s*)(directive:)?(.*)$', + bygroups(Comment, Comment, Comment.Preproc, Comment)), + # Uncomment the following if you want to distinguish between + # '/*' and '/**', à la javadoc + #(r'/[*]{2}(.|\n)*?[*]/', Comment.Multiline), + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + (r'\\\n', Text), + (r'(and|not|or|xor|##?)\b', Operator.Word), + (r'([:]{1-2}=|[-+]=)\b', Operator.Word), + (r'(@|<<|>>)\b', Keyword), # stereotypes + (r'!=|<>|=|==|!->|->|>=|<=|[.]{3}|[+/*%=<>&|.~]', Operator), + (r'[]{}:(),;[]', Punctuation), + (r'(true|false|unlimited|null)\b', Keyword.Constant), + (r'(this|self|result)\b', Name.Builtin.Pseudo), + (r'(var)\b', Keyword.Declaration), + (r'(from|import)\b', Keyword.Namespace, 'fromimport'), + (r'(metamodel|class|exception|primitive|enum|transformation|library)(\s+)([a-zA-Z0-9_]+)', + bygroups(Keyword.Word, Text, Name.Class)), + (r'(exception)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Word, Text, Name.Exception)), + (r'(main)\b', Name.Function), + (r'(mapping|helper|query)(\s+)', bygroups(Keyword.Declaration, Text), 'operation'), + (r'(assert)(\s+)\b', bygroups(Keyword, Text), 'assert'), + (r'(Bag|Collection|Dict|OrderedSet|Sequence|Set|Tuple|List)\b', + Keyword.Type), + include('keywords'), + ('"', String, combined('stringescape', 'dqs')), + ("'", String, combined('stringescape', 'sqs')), + include('name'), + include('numbers'), + # (r'([a-zA-Z_][a-zA-Z0-9_]*)(::)([a-zA-Z_][a-zA-Z0-9_]*)', + # bygroups(Text, Text, Text)), + ], + + 'fromimport': [ + (r'(?:[ \t]|\\\n)+', Text), + (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace), + (r'', Text, '#pop'), + ], + + 'operation': [ + (r'::', Text), + (r'(.*::)([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*(\()', bygroups(Text,Name.Function, Text), '#pop') + ], + + 'assert': [ + (r'(warning|error|fatal)\b', Keyword, '#pop'), + (r'', Text, '#pop') # all else: go back + ], + + 'keywords': [ + (r'(abstract|access|any|assert|' + r'blackbox|break|case|collect|collectNested|' + r'collectOne|collectselect|collectselectOne|composes|' + r'compute|configuration|constructor|continue|datatype|' + r'default|derived|disjuncts|do|elif|else|end|' + r'endif|except|exists|extends|' + r'forAll|forEach|forOne|from|if|' + r'implies|in|inherits|init|inout|' + r'intermediate|invresolve|invresolveIn|invresolveone|' + r'invresolveoneIn|isUnique|iterate|late|let|' + r'literal|log|map|merges|' + r'modeltype|new|object|one|' + r'ordered|out|package|population|' + r'property|raise|readonly|references|refines|' + r'reject|resolve|resolveIn|resolveone|resolveoneIn|' + r'return|select|selectOne|sortedBy|static|switch|' + r'tag|then|try|typedef|' + r'unlimited|uses|when|where|while|with|' + r'xcollect|xmap|xselect)\b', Keyword), + ], + + # There is no need to distinguish between String.Single and + # String.Double: 'strings' is factorised for 'dqs' and 'sqs' + 'strings': [ + (r'[^\\\'"\n]+', String), + # quotes, percents and backslashes must be parsed one at a time + (r'[\'"\\]', String), + ], + 'stringescape': [ + (r'\\([\\btnfr"\']|u[0-3][0-7]{2}|u[0-7]{1,2})', String.Escape) + ], + 'dqs': [ # double-quoted string + (r'"', String, '#pop'), + (r'\\\\|\\"', String.Escape), + include('strings') + ], + 'sqs': [ # single-quoted string + (r"'", String, '#pop'), + (r"\\\\|\\'", String.Escape), + include('strings') + ], + 'name': [ + ('[a-zA-Z_][a-zA-Z0-9_]*', Name), + ], + # numbers: excerpt taken from the python lexer + 'numbers': [ + (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), + (r'\d+[eE][+-]?[0-9]+', Number.Float), + (r'\d+', Number.Integer) + ], + } + diff --git a/pygments/token.py b/pygments/token.py index bfdfc114..f31625ed 100644 --- a/pygments/token.py +++ b/pygments/token.py @@ -182,6 +182,7 @@ STANDARD_TYPES = { Comment.Hashbang: 'ch', Comment.Multiline: 'cm', Comment.Preproc: 'cp', + Comment.PreprocFile: 'cpf', Comment.Single: 'c1', Comment.Special: 'cs', diff --git a/pygments/util.py b/pygments/util.py index 0859c05d..07b662d0 100644 --- a/pygments/util.py +++ b/pygments/util.py @@ -372,7 +372,7 @@ else: class UnclosingTextIOWrapper(TextIOWrapper): # Don't close underlying buffer on destruction. def close(self): - pass + self.flush() def add_metaclass(metaclass): diff --git a/tests/examplefiles/abnf_example1.abnf b/tests/examplefiles/abnf_example1.abnf new file mode 100644 index 00000000..5cd9cd25 --- /dev/null +++ b/tests/examplefiles/abnf_example1.abnf @@ -0,0 +1,22 @@ +; This examples from WikiPedia . + + postal-address = name-part street zip-part + + name-part = *(personal-part SP) last-name [SP suffix] CRLF + name-part =/ personal-part CRLF + + personal-part = first-name / (initial ".") + first-name = *ALPHA + initial = ALPHA + last-name = *ALPHA + suffix = ("Jr." / "Sr." / 1*("I" / "V" / "X")) + + street = [apt SP] house-num SP street-name CRLF + apt = 1*4DIGIT + house-num = 1*8(DIGIT / ALPHA) + street-name = 1*VCHAR + + zip-part = town-name "," SP state 1*2SP zip-code CRLF + town-name = 1*(ALPHA / SP) + state = 2ALPHA + zip-code = 5DIGIT ["-" 4DIGIT] diff --git a/tests/examplefiles/abnf_example2.abnf b/tests/examplefiles/abnf_example2.abnf new file mode 100644 index 00000000..8781adfb --- /dev/null +++ b/tests/examplefiles/abnf_example2.abnf @@ -0,0 +1,9 @@ +crlf = %d13.10 + +command = "command string" + +char-line = %x0D.0A *(%x20-7E) %x0D.0A + +without-ws-and-ctl = %d1-8 / %d11 / %d12 / %d14-31 / %d127 + +three-blank-lines = %x0D.0A.0D.0A.0D.0A diff --git a/tests/examplefiles/bnf_example1.bnf b/tests/examplefiles/bnf_example1.bnf new file mode 100644 index 00000000..fe041a6e --- /dev/null +++ b/tests/examplefiles/bnf_example1.bnf @@ -0,0 +1,15 @@ +; This examples from WikiPedia . + + ::= + + ::= + | + + ::= "." | + + ::= + + ::= "," + + ::= "Sr." | "Jr." | | "" + ::= | "" diff --git a/tests/examplefiles/demo.thrift b/tests/examplefiles/demo.thrift new file mode 100644 index 00000000..e50544d5 --- /dev/null +++ b/tests/examplefiles/demo.thrift @@ -0,0 +1,14 @@ +/* comment */ +/** doc comment */ + +namespace cpp shared // inline comment + +struct Foo1 { + 1: i32 key + 2: string value +} + +service Foo2 { + Foo1 bar(1: i32 key) +} + diff --git a/tests/examplefiles/example.bc b/tests/examplefiles/example.bc new file mode 100644 index 00000000..6604cd31 --- /dev/null +++ b/tests/examplefiles/example.bc @@ -0,0 +1,53 @@ +/* + * Calculate the Greatest Common Divisor of a and b. + */ +define gcd(a, b) { + auto tmp; + + /* + * Euclidean algorithm + */ + while (b != 0) { + tmp = a % b; + a = b; + b = tmp; + } + return a; +} +"gcd(225, 150) = " ; gcd(225, 150) + +/* assign operators */ +a = 10 +a += 1 +a++ +++a +a-- +--a +a += 5 +a -= 5 +a *= 2 +a /= 3 +a ^= 2 +a %= 2 + +/* comparison */ +if (a > 2) { +} +if (a >= 2) { +} +if (a == 2) { +} +if (a != 2) { +} +if (a <= 2) { +} +if (a < 2) { +} + +a /* /*/ * 2 /* == a * 2 */ +a //* /*/ 1.5 /* == a / 1.5 */ +a /*/*/ * 3 /* == a * 3 */ +a * 3 /**/ * 4 /* == a * 3 * 4 */ +a / 3 //*//*/ .4 /* == a / 3 / 0.4 */ +a / 3 //*//*/ 1.3 /* == a / 3 / 1.4 */ +a / 3 /*//*// 1.3 /* == a / 3 / 1.4 */ diff --git a/tests/examplefiles/example.ts b/tests/examplefiles/example.ts index 545c6cf5..760e2543 100644 --- a/tests/examplefiles/example.ts +++ b/tests/examplefiles/example.ts @@ -21,6 +21,17 @@ class Horse extends Animal { } } +@View({ + templateUrl: "app/components/LoginForm.html", + directives: [FORM_DIRECTIVES, NgIf] +}) +@Component({ + selector: "login-form" +}) +class LoginForm { + +} + var sam = new Snake("Sammy the Python") var tom: Animal = new Horse("Tommy the Palomino") diff --git a/tests/examplefiles/ezhil_primefactors.n b/tests/examplefiles/ezhil_primefactors.n new file mode 100644 index 00000000..13390611 --- /dev/null +++ b/tests/examplefiles/ezhil_primefactors.n @@ -0,0 +1,152 @@ +# (C) முத்தையா அண்ணாமலை 2013 +# (A) என். சொக்கன் +# எழில் தமிழ் நிரலாக்க மொழி உதாரணம் +# Muthu A granted permission for this to be included under the BSD license +# https://bitbucket.org/birkenfeld/pygments-main/pull-requests/443/ezhil-language-lexer-for-pygments/diff + +## Prime Factors Example +## பகா எண் கூறுகளைக் கண்டறியும் உதாரணம் + +## இது நிரல் தரப்பட்ட எண்ணின் பகாஎண் கூறுகளைக் கண்டறியும் + +நிரல்பாகம் பகாஎண்ணா(எண்1) + + ## இது நிரல்பாகம் தரப்பட்ட எண் பகு எண்ணா அல்லது பகா எண்ணா என்று கண்டறிந்து சொல்லும் + ## பகுஎண் என்றால் 0 திரும்பத் தரப்படும் + ## பகாஎண் என்றால் 1 திரும்பத் தரப்படும் + + @(எண்1 < 0) ஆனால் + + ## எதிர்மறை எண்களை நேராக்குதல் + + எண்1 = எண்1 * (-1) + + முடி + + @(எண்1 < 2) ஆனால் + + ## பூஜ்ஜியம், ஒன்று ஆகியவை பகா எண்கள் அல்ல + + பின்கொடு 0 + + முடி + + @(எண்1 == 2) ஆனால் + + ## இரண்டு என்ற எண் ஒரு பகா எண் + + பின்கொடு 1 + + முடி + + மீதம் = எண்1%2 + + @(மீதம் == 0) ஆனால் + + ## இரட்டைப்படை எண், ஆகவே, இது பகா எண் அல்ல + + பின்கொடு 0 + + முடி + + எண்1வர்க்கமூலம் = எண்1^0.5 + + @(எண்2 = 3, எண்2 <= எண்1வர்க்கமூலம், எண்2 = எண்2 + 2) ஆக + + மீதம்1 = எண்1%எண்2 + + @(மீதம்1 == 0) ஆனால் + + ## ஏதேனும் ஓர் எண்ணால் முழுமையாக வகுபட்டுவிட்டது, ஆகவே அது பகா எண் அல்ல + + பின்கொடு 0 + + முடி + + முடி + + பின்கொடு 1 + +முடி + +நிரல்பாகம் பகுத்தெடு(எண்1) + + ## இது எண் தரப்பட்ட எண்ணின் பகா எண் கூறுகளைக் கண்டறிந்து பட்டியல் இடும் + + கூறுகள் = பட்டியல்() + + @(எண்1 < 0) ஆனால் + + ## எதிர்மறை எண்களை நேராக்குதல் + + எண்1 = எண்1 * (-1) + + முடி + + @(எண்1 <= 1) ஆனால் + + ## ஒன்று அல்லது அதற்குக் குறைவான எண்களுக்குப் பகா எண் விகிதம் கண்டறியமுடியாது + + பின்கொடு கூறுகள் + + முடி + + @(பகாஎண்ணா(எண்1) == 1) ஆனால் + + ## தரப்பட்ட எண்ணே பகா எண்ணாக அமைந்துவிட்டால், அதற்கு அதுவே பகாஎண் கூறு ஆகும் + + பின்இணை(கூறுகள், எண்1) + பின்கொடு கூறுகள் + + முடி + + தாற்காலிகஎண் = எண்1 + + எண்2 = 2 + + @(எண்2 <= தாற்காலிகஎண்) வரை + + விடை1 = பகாஎண்ணா(எண்2) + மீண்டும்தொடங்கு = 0 + + @(விடை1 == 1) ஆனால் + + விடை2 = தாற்காலிகஎண்%எண்2 + + @(விடை2 == 0) ஆனால் + + ## பகா எண்ணால் முழுமையாக வகுபட்டுள்ளது, அதனைப் பட்டியலில் இணைக்கிறோம் + + பின்இணை(கூறுகள், எண்2) + தாற்காலிகஎண் = தாற்காலிகஎண்/எண்2 + + ## மீண்டும் இரண்டில் தொடங்கி இதே கணக்கிடுதலைத் தொடரவேண்டும் + + எண்2 = 2 + மீண்டும்தொடங்கு = 1 + + முடி + + முடி + + @(மீண்டும்தொடங்கு == 0) ஆனால் + + ## அடுத்த எண்ணைத் தேர்ந்தெடுத்துக் கணக்கிடுதலைத் தொடரவேண்டும் + + எண்2 = எண்2 + 1 + + முடி + + முடி + + பின்கொடு கூறுகள் + +முடி + +அ = int(உள்ளீடு("உங்களுக்குப் பிடித்த ஓர் எண்ணைத் தாருங்கள்: ")) + +பகாஎண்கூறுகள் = பட்டியல்() + +பகாஎண்கூறுகள் = பகுத்தெடு(அ) + +பதிப்பி "நீங்கள் தந்த எண்ணின் பகா எண் கூறுகள் இவை: ", பகாஎண்கூறுகள் diff --git a/tests/examplefiles/hexdump_debugexe b/tests/examplefiles/hexdump_debugexe new file mode 100644 index 00000000..31fefdb7 --- /dev/null +++ b/tests/examplefiles/hexdump_debugexe @@ -0,0 +1,309 @@ +0000:0000 2F 2F 20 43 72 65 61 74-65 64 20 62 79 20 4C 69 // Created by Li +0000:0010 6F 6E 65 6C 6C 6F 20 4C-75 6E 65 73 75 20 61 6E onello Lunesu an +0000:0020 64 20 70 6C 61 63 65 64-20 69 6E 20 74 68 65 20 d placed in the +0000:0030 70 75 62 6C 69 63 20 64-6F 6D 61 69 6E 2E 0A 2F public domain.◙/ +0000:0040 2F 20 54 68 69 73 20 66-69 6C 65 20 68 61 73 20 / This file has +0000:0050 62 65 65 6E 20 6D 6F 64-69 66 69 65 64 20 66 72 been modified fr +0000:0060 6F 6D 20 69 74 73 20 6F-72 69 67 69 6E 61 6C 20 om its original +0000:0070 76 65 72 73 69 6F 6E 2E-0A 2F 2F 20 49 74 20 68 version.◙// It h +0000:0080 61 73 20 62 65 65 6E 20-66 6F 72 6D 61 74 74 65 as been formatte +0000:0090 64 20 74 6F 20 66 69 74-20 79 6F 75 72 20 73 63 d to fit your sc +0000:00A0 72 65 65 6E 2E 0A 6D 6F-64 75 6C 65 20 70 68 6F reen.◙module pho +0000:00B0 6E 65 6E 6F 3B 20 20 20-20 20 2F 2F 20 6F 70 74 neno; // opt +0000:00C0 69 6F 6E 61 6C 0A 69 6D-70 6F 72 74 20 73 74 64 ional◙import std +0000:00D0 2E 73 74 64 69 6F 3B 20-20 20 2F 2F 20 77 72 69 .stdio; // wri +0000:00E0 74 65 66 6C 6E 20 20 20-20 20 0A 69 6D 70 6F 72 tefln ◙impor +0000:00F0 74 20 73 74 64 2E 63 74-79 70 65 3B 20 20 20 2F t std.ctype; / +0000:0100 2F 20 69 73 64 69 67 69-74 20 20 20 20 20 0A 69 / isdigit ◙i +0000:0110 6D 70 6F 72 74 20 73 74-64 2E 73 74 72 65 61 6D mport std.stream +0000:0120 3B 20 20 2F 2F 20 42 75-66 66 65 72 65 64 46 69 ; // BufferedFi +0000:0130 6C 65 0A 0A 2F 2F 20 4A-75 73 74 20 66 6F 72 20 le◙◙// Just for +0000:0140 72 65 61 64 61 62 69 6C-69 74 79 20 28 69 6D 61 readability (ima +0000:0150 67 69 6E 65 20 63 68 61-72 5B 5D 5B 5D 5B 63 68 gine char[][][ch +0000:0160 61 72 5B 5D 5D 29 20 20-20 20 0A 61 6C 69 61 73 ar[]]) ◙alias +0000:0170 20 63 68 61 72 5B 5D 20-73 74 72 69 6E 67 3B 0A char[] string;◙ +0000:0180 61 6C 69 61 73 20 73 74-72 69 6E 67 5B 5D 20 73 alias string[] s +0000:0190 74 72 69 6E 67 61 72 72-61 79 3B 0A 0A 2F 2F 2F tringarray;◙◙/// +0000:01A0 20 53 74 72 69 70 73 20-6E 6F 6E 2D 64 69 67 69 Strips non-digi +0000:01B0 74 20 63 68 61 72 61 63-74 65 72 73 20 66 72 6F t characters fro +0000:01C0 6D 20 74 68 65 20 73 74-72 69 6E 67 20 28 43 4F m the string (CO +0000:01D0 57 29 0A 73 74 72 69 6E-67 20 73 74 72 69 70 4E W)◙string stripN +0000:01E0 6F 6E 44 69 67 69 74 28-20 69 6E 20 73 74 72 69 onDigit( in stri +0000:01F0 6E 67 20 6C 69 6E 65 20-29 20 0A 7B 0A 20 20 20 ng line ) ◙{◙ +0000:0200 20 73 74 72 69 6E 67 20-72 65 74 3B 0A 20 20 20 string ret;◙ +0000:0210 20 66 6F 72 65 61 63 68-28 75 69 6E 74 20 69 2C foreach(uint i, +0000:0220 20 63 3B 20 6C 69 6E 65-29 20 7B 0A 20 20 20 20 c; line) {◙ +0000:0230 20 20 20 20 2F 2F 20 45-72 72 6F 72 3A 20 73 74 // Error: st +0000:0240 64 2E 63 74 79 70 65 2E-69 73 64 69 67 69 74 20 d.ctype.isdigit +0000:0250 61 74 20 43 3A 5C 64 6D-64 5C 73 72 63 5C 70 68 at C:\dmd\src\ph +0000:0260 6F 62 6F 73 5C 73 74 64-5C 63 74 79 70 65 2E 64 obos\std\ctype.d +0000:0270 28 33 37 29 20 0A 20 20-20 20 20 20 20 20 2F 2F (37) ◙ // +0000:0280 20 63 6F 6E 66 6C 69 63-74 73 20 77 69 74 68 20 conflicts with +0000:0290 73 74 64 2E 73 74 72 65-61 6D 2E 69 73 64 69 67 std.stream.isdig +0000:02A0 69 74 20 61 74 20 43 3A-5C 64 6D 64 5C 73 72 63 it at C:\dmd\src +0000:02B0 5C 70 68 6F 62 6F 73 5C-73 74 64 5C 73 74 72 65 \phobos\std\stre +0000:02C0 61 6D 2E 64 28 32 39 32-34 29 0A 20 20 20 20 20 am.d(2924)◙ +0000:02D0 20 20 20 69 66 20 28 21-73 74 64 2E 63 74 79 70 if (!std.ctyp +0000:02E0 65 2E 69 73 64 69 67 69-74 28 63 29 29 20 7B 0A e.isdigit(c)) {◙ +0000:02F0 20 20 20 20 20 20 20 20-20 20 20 20 69 66 20 28 if ( +0000:0300 21 72 65 74 29 0A 20 20-20 20 20 20 20 20 20 20 !ret)◙ +0000:0310 20 20 20 20 20 20 72 65-74 20 3D 20 6C 69 6E 65 ret = line +0000:0320 5B 30 2E 2E 69 5D 3B 20-20 20 20 0A 20 20 20 20 [0..i]; ◙ +0000:0330 20 20 20 20 7D 20 20 20-20 0A 20 20 20 20 20 20 } ◙ +0000:0340 20 20 65 6C 73 65 20 69-66 20 28 72 65 74 29 0A else if (ret)◙ +0000:0350 20 20 20 20 20 20 20 20-20 20 20 20 72 65 74 20 ret +0000:0360 7E 3D 20 63 3B 20 20 20-20 0A 20 20 20 20 7D 20 ~= c; ◙ } +0000:0370 20 20 20 0A 20 20 20 20-72 65 74 75 72 6E 20 72 ◙ return r +0000:0380 65 74 3F 72 65 74 3A 6C-69 6E 65 3B 0A 7D 0A 0A et?ret:line;◙}◙◙ +0000:0390 75 6E 69 74 74 65 73 74-20 7B 0A 20 20 20 20 61 unittest {◙ a +0000:03A0 73 73 65 72 74 28 20 73-74 72 69 70 4E 6F 6E 44 ssert( stripNonD +0000:03B0 69 67 69 74 28 22 61 73-64 66 22 29 20 3D 3D 20 igit("asdf") == +0000:03C0 22 22 20 20 29 3B 0A 20-20 20 20 61 73 73 65 72 "" );◙ asser +0000:03D0 74 28 20 73 74 72 69 70-4E 6F 6E 44 69 67 69 74 t( stripNonDigit +0000:03E0 28 22 5C 27 31 33 2D 3D-32 20 34 6B 6F 70 22 29 ("\'13-=2 4kop") +0000:03F0 20 3D 3D 20 20 22 31 33-32 34 22 20 20 29 3B 0A == "1324" );◙ +0000:0400 7D 0A 0A 2F 2F 2F 20 43-6F 6E 76 65 72 74 73 20 }◙◙/// Converts +0000:0410 61 20 77 6F 72 64 20 69-6E 74 6F 20 61 20 6E 75 a word into a nu +0000:0420 6D 62 65 72 2C 20 69 67-6E 6F 72 69 6E 67 20 61 mber, ignoring a +0000:0430 6C 6C 20 6E 6F 6E 20 61-6C 70 68 61 20 63 68 61 ll non alpha cha +0000:0440 72 61 63 74 65 72 73 20-20 0A 73 74 72 69 6E 67 racters ◙string +0000:0450 20 77 6F 72 64 54 6F 4E-75 6D 28 20 69 6E 20 73 wordToNum( in s +0000:0460 74 72 69 6E 67 20 77 6F-72 64 20 29 0A 7B 0A 2F tring word )◙{◙/ +0000:0470 2F 20 74 72 61 6E 73 6C-61 74 69 6F 6E 20 74 61 / translation ta +0000:0480 62 6C 65 20 66 6F 72 20-74 68 65 20 74 61 73 6B ble for the task +0000:0490 20 61 74 20 68 61 6E 64-0A 63 6F 6E 73 74 20 63 at hand◙const c +0000:04A0 68 61 72 5B 32 35 36 5D-20 54 52 41 4E 53 4C 41 har[256] TRANSLA +0000:04B0 54 45 20 3D 20 20 20 20-0A 20 20 20 20 22 20 20 TE = ◙ " +0000:04C0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:04D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 22 20 " +0000:04E0 20 2F 2F 20 30 20 20 20-0A 20 20 20 20 22 20 20 // 0 ◙ " +0000:04F0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 30 31 01 +0000:0500 32 33 34 35 36 37 38 39-20 20 20 20 20 20 22 20 23456789 " +0000:0510 20 2F 2F 20 33 32 20 20-20 20 20 0A 20 20 20 20 // 32 ◙ +0000:0520 22 20 35 37 36 33 30 34-39 39 36 31 37 38 35 31 " 57630499617851 +0000:0530 38 38 31 32 33 34 37 36-32 32 33 39 20 20 20 20 881234762239 +0000:0540 20 22 20 20 2F 2F 20 36-34 20 20 20 0A 20 20 20 " // 64 ◙ +0000:0550 20 22 20 35 37 36 33 30-34 39 39 36 31 37 38 35 " 5763049961785 +0000:0560 31 38 38 31 32 33 34 37-36 32 32 33 39 20 20 20 1881234762239 +0000:0570 20 20 22 0A 20 20 20 20-22 20 20 20 20 20 20 20 "◙ " +0000:0580 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:0590 20 20 20 20 20 20 20 20-20 22 0A 20 20 20 20 22 "◙ " +0000:05A0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:05B0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:05C0 22 0A 20 20 20 20 22 20-20 20 20 20 20 20 20 20 "◙ " +0000:05D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:05E0 20 20 20 20 20 20 20 22-20 20 20 20 0A 20 20 20 " ◙ +0000:05F0 20 22 20 20 20 20 20 20-20 20 20 20 20 20 20 20 " +0000:0600 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:0610 20 20 22 3B 0A 20 20 20-20 73 74 72 69 6E 67 20 ";◙ string +0000:0620 72 65 74 3B 0A 20 20 20-20 66 6F 72 65 61 63 68 ret;◙ foreach +0000:0630 28 63 3B 20 63 61 73 74-28 75 62 79 74 65 5B 5D (c; cast(ubyte[] +0000:0640 29 77 6F 72 64 29 0A 20-20 20 20 20 20 20 20 69 )word)◙ i +0000:0650 66 20 28 54 52 41 4E 53-4C 41 54 45 5B 63 5D 20 f (TRANSLATE[c] +0000:0660 21 3D 20 27 20 27 29 0A-20 20 20 20 20 20 20 20 != ' ')◙ +0000:0670 20 20 20 20 72 65 74 20-7E 3D 20 54 52 41 4E 53 ret ~= TRANS +0000:0680 4C 41 54 45 5B 63 5D 3B-0A 20 20 20 20 72 65 74 LATE[c];◙ ret +0000:0690 75 72 6E 20 72 65 74 3B-0A 7D 0A 0A 75 6E 69 74 urn ret;◙}◙◙unit +0000:06A0 74 65 73 74 20 7B 0A 20-2F 2F 20 54 65 73 74 20 test {◙ // Test +0000:06B0 77 6F 72 64 54 6F 4E 75-6D 20 75 73 69 6E 67 20 wordToNum using +0000:06C0 74 68 65 20 74 61 62 6C-65 20 66 72 6F 6D 20 74 the table from t +0000:06D0 68 65 20 74 61 73 6B 20-64 65 73 63 72 69 70 74 he task descript +0000:06E0 69 6F 6E 2E 0A 20 61 73-73 65 72 74 28 20 22 30 ion.◙ assert( "0 +0000:06F0 31 31 31 32 32 32 33 33-33 34 34 35 35 36 36 36 1112223334455666 +0000:0700 37 37 37 38 38 38 39 39-39 22 20 3D 3D 0A 20 20 777888999" ==◙ +0000:0710 20 77 6F 72 64 54 6F 4E-75 6D 28 22 45 20 7C 20 wordToNum("E | +0000:0720 4A 20 4E 20 51 20 7C 20-52 20 57 20 58 20 7C 20 J N Q | R W X | +0000:0730 44 20 53 20 59 20 7C 20-46 20 54 20 7C 20 41 20 D S Y | F T | A +0000:0740 4D 20 7C 20 43 20 49 20-56 20 7C 20 42 20 4B 20 M | C I V | B K +0000:0750 55 20 7C 20 4C 20 4F 20-50 20 7C 20 47 20 48 20 U | L O P | G H +0000:0760 5A 22 29 29 3B 0A 20 61-73 73 65 72 74 28 20 22 Z"));◙ assert( " +0000:0770 30 31 31 31 32 32 32 33-33 33 34 34 35 35 36 36 0111222333445566 +0000:0780 36 37 37 37 38 38 38 39-39 39 22 20 3D 3D 20 0A 6777888999" == ◙ +0000:0790 20 20 20 77 6F 72 64 54-6F 4E 75 6D 28 22 65 20 wordToNum("e +0000:07A0 7C 20 6A 20 6E 20 71 20-7C 20 72 20 77 20 78 20 | j n q | r w x +0000:07B0 7C 20 64 20 73 20 79 20-7C 20 66 20 74 20 7C 20 | d s y | f t | +0000:07C0 61 20 6D 20 7C 20 63 20-69 20 76 20 7C 20 62 20 a m | c i v | b +0000:07D0 6B 20 75 20 7C 20 6C 20-6F 20 70 20 7C 20 67 20 k u | l o p | g +0000:07E0 68 20 7A 22 29 29 3B 0A-20 61 73 73 65 72 74 28 h z"));◙ assert( +0000:07F0 20 22 30 31 32 33 34 35-36 37 38 39 22 20 3D 3D "0123456789" == +0000:0800 20 0A 20 20 20 77 6F 72-64 54 6F 4E 75 6D 28 22 ◙ wordToNum(" +0000:0810 30 20 7C 20 20 20 31 20-20 20 7C 20 20 20 32 20 0 | 1 | 2 +0000:0820 20 20 7C 20 20 20 33 20-20 20 7C 20 20 34 20 20 | 3 | 4 +0000:0830 7C 20 20 35 20 20 7C 20-20 20 36 20 20 20 7C 20 | 5 | 6 | +0000:0840 20 20 37 20 20 20 7C 20-20 20 38 20 20 20 7C 20 7 | 8 | +0000:0850 20 20 39 22 29 29 3B 0A-7D 0A 0A 76 6F 69 64 20 9"));◙}◙◙void +0000:0860 6D 61 69 6E 28 20 73 74-72 69 6E 67 5B 5D 20 61 main( string[] a +0000:0870 72 67 73 20 29 0A 7B 0A-20 20 20 20 2F 2F 20 54 rgs )◙{◙ // T +0000:0880 68 69 73 20 61 73 73 6F-63 69 61 74 69 76 65 20 his associative +0000:0890 61 72 72 61 79 20 6D 61-70 73 20 61 20 6E 75 6D array maps a num +0000:08A0 62 65 72 20 74 6F 20 61-6E 20 61 72 72 61 79 20 ber to an array +0000:08B0 6F 66 20 77 6F 72 64 73-2E 20 20 20 20 0A 20 20 of words. ◙ +0000:08C0 20 20 73 74 72 69 6E 67-61 72 72 61 79 5B 73 74 stringarray[st +0000:08D0 72 69 6E 67 5D 20 20 20-20 6E 75 6D 32 77 6F 72 ring] num2wor +0000:08E0 64 73 3B 0A 0A 20 20 20-20 66 6F 72 65 61 63 68 ds;◙◙ foreach +0000:08F0 28 73 74 72 69 6E 67 20-77 6F 72 64 3B 20 6E 65 (string word; ne +0000:0900 77 20 42 75 66 66 65 72-65 64 46 69 6C 65 28 22 w BufferedFile(" +0000:0910 64 69 63 74 69 6F 6E 61-72 79 2E 74 78 74 22 20 dictionary.txt" +0000:0920 29 20 29 0A 20 20 20 20-20 20 20 20 6E 75 6D 32 ) )◙ num2 +0000:0930 77 6F 72 64 73 5B 20 77-6F 72 64 54 6F 4E 75 6D words[ wordToNum +0000:0940 28 77 6F 72 64 29 20 5D-20 7E 3D 20 77 6F 72 64 (word) ] ~= word +0000:0950 2E 64 75 70 3B 20 20 20-20 20 20 20 20 2F 2F 20 .dup; // +0000:0960 6D 75 73 74 20 64 75 70-0A 0A 20 20 20 20 2F 2F must dup◙◙ // +0000:0970 2F 20 46 69 6E 64 73 20-61 6C 6C 20 61 6C 74 65 / Finds all alte +0000:0980 72 6E 61 74 69 76 65 73-20 66 6F 72 20 74 68 65 rnatives for the +0000:0990 20 67 69 76 65 6E 20 6E-75 6D 62 65 72 0A 20 20 given number◙ +0000:09A0 20 20 2F 2F 2F 20 28 73-68 6F 75 6C 64 20 68 61 /// (should ha +0000:09B0 76 65 20 62 65 65 6E 20-73 74 72 69 70 70 65 64 ve been stripped +0000:09C0 20 66 72 6F 6D 20 6E 6F-6E 2D 64 69 67 69 74 20 from non-digit +0000:09D0 63 68 61 72 61 63 74 65-72 73 29 0A 20 20 20 20 characters)◙ +0000:09E0 73 74 72 69 6E 67 61 72-72 61 79 20 5F 46 69 6E stringarray _Fin +0000:09F0 64 57 6F 72 64 73 28 20-73 74 72 69 6E 67 20 6E dWords( string n +0000:0A00 75 6D 62 65 72 73 2C 20-62 6F 6F 6C 20 64 69 67 umbers, bool dig +0000:0A10 69 74 6F 6B 20 29 0A 20-20 20 20 69 6E 20 7B 0A itok )◙ in {◙ +0000:0A20 20 20 20 20 20 20 20 20-61 73 73 65 72 74 28 6E assert(n +0000:0A30 75 6D 62 65 72 73 2E 6C-65 6E 67 74 68 20 3E 20 umbers.length > +0000:0A40 20 30 29 3B 20 20 20 20-0A 20 20 20 20 7D 20 20 0); ◙ } +0000:0A50 20 20 0A 20 20 20 20 6F-75 74 28 72 65 73 75 6C ◙ out(resul +0000:0A60 74 29 20 7B 0A 20 20 20-20 20 20 20 20 66 6F 72 t) {◙ for +0000:0A70 65 61 63 68 20 28 61 3B-20 72 65 73 75 6C 74 29 each (a; result) +0000:0A80 0A 20 20 20 20 20 20 20-20 20 20 20 20 61 73 73 ◙ ass +0000:0A90 65 72 74 28 20 77 6F 72-64 54 6F 4E 75 6D 28 61 ert( wordToNum(a +0000:0AA0 29 20 3D 3D 20 6E 75 6D-62 65 72 73 20 29 3B 0A ) == numbers );◙ +0000:0AB0 20 20 20 20 7D 20 20 20-20 0A 20 20 20 20 62 6F } ◙ bo +0000:0AC0 64 79 20 7B 0A 20 20 20-20 20 20 20 20 73 74 72 dy {◙ str +0000:0AD0 69 6E 67 61 72 72 61 79-20 72 65 74 3B 0A 20 20 ingarray ret;◙ +0000:0AE0 20 20 20 20 20 20 62 6F-6F 6C 20 66 6F 75 6E 64 bool found +0000:0AF0 77 6F 72 64 20 3D 20 66-61 6C 73 65 3B 0A 20 20 word = false;◙ +0000:0B00 20 20 20 20 20 20 66 6F-72 20 28 75 69 6E 74 20 for (uint +0000:0B10 74 3D 31 3B 20 74 3C 3D-6E 75 6D 62 65 72 73 2E t=1; t<=numbers. +0000:0B20 6C 65 6E 67 74 68 3B 20-2B 2B 74 29 20 7B 0A 20 length; ++t) {◙ +0000:0B30 20 20 20 20 20 20 20 20-20 20 20 61 75 74 6F 20 auto +0000:0B40 61 6C 74 65 72 6E 61 74-69 76 65 73 20 3D 20 6E alternatives = n +0000:0B50 75 6D 62 65 72 73 5B 30-2E 2E 74 5D 20 69 6E 20 umbers[0..t] in +0000:0B60 6E 75 6D 32 77 6F 72 64-73 3B 0A 20 20 20 20 20 num2words;◙ +0000:0B70 20 20 20 20 20 20 20 69-66 20 28 21 61 6C 74 65 if (!alte +0000:0B80 72 6E 61 74 69 76 65 73-29 0A 20 20 20 20 20 20 rnatives)◙ +0000:0B90 20 20 20 20 20 20 20 20-20 20 63 6F 6E 74 69 6E contin +0000:0BA0 75 65 3B 0A 20 20 20 20-20 20 20 20 20 20 20 20 ue;◙ +0000:0BB0 66 6F 75 6E 64 77 6F 72-64 20 3D 20 74 72 75 65 foundword = true +0000:0BC0 3B 0A 20 20 20 20 20 20-20 20 20 20 20 20 69 66 ;◙ if +0000:0BD0 20 28 6E 75 6D 62 65 72-73 2E 6C 65 6E 67 74 68 (numbers.length +0000:0BE0 20 3E 20 20 74 29 20 7B-0A 20 20 20 20 20 20 20 > t) {◙ +0000:0BF0 20 20 20 20 20 20 20 20-20 2F 2F 20 43 6F 6D 62 // Comb +0000:0C00 69 6E 65 20 61 6C 6C 20-63 75 72 72 65 6E 74 20 ine all current +0000:0C10 61 6C 74 65 72 6E 61 74-69 76 65 73 20 77 69 74 alternatives wit +0000:0C20 68 20 61 6C 6C 20 61 6C-74 65 72 6E 61 74 69 76 h all alternativ +0000:0C30 65 73 20 20 20 20 20 0A-20 20 20 20 20 20 20 20 es ◙ +0000:0C40 20 20 20 20 20 20 20 20-2F 2F 20 6F 66 20 74 68 // of th +0000:0C50 65 20 72 65 73 74 20 28-6E 65 78 74 20 70 69 65 e rest (next pie +0000:0C60 63 65 20 63 61 6E 20 73-74 61 72 74 20 77 69 74 ce can start wit +0000:0C70 68 20 61 20 64 69 67 69-74 29 20 20 20 20 20 20 h a digit) +0000:0C80 20 20 20 20 20 20 20 20-0A 20 20 20 20 20 20 20 ◙ +0000:0C90 20 20 20 20 20 20 20 20-20 66 6F 72 65 61 63 68 foreach +0000:0CA0 20 28 61 32 3B 20 5F 46-69 6E 64 57 6F 72 64 73 (a2; _FindWords +0000:0CB0 28 20 6E 75 6D 62 65 72-73 5B 74 2E 2E 24 5D 2C ( numbers[t..$], +0000:0CC0 20 74 72 75 65 20 20 20-20 20 29 20 29 0A 20 20 true ) )◙ +0000:0CD0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:0CE0 20 20 66 6F 72 65 61 63-68 28 61 31 3B 20 2A 61 foreach(a1; *a +0000:0CF0 6C 74 65 72 6E 61 74 69-76 65 73 29 0A 20 20 20 lternatives)◙ +0000:0D00 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:0D10 20 20 20 20 72 65 74 20-7E 3D 20 61 31 20 7E 20 ret ~= a1 ~ +0000:0D20 22 20 22 20 7E 20 61 32-3B 0A 20 20 20 20 20 20 " " ~ a2;◙ +0000:0D30 20 20 20 20 20 20 7D 0A-20 20 20 20 20 20 20 20 }◙ +0000:0D40 20 20 20 20 65 6C 73 65-20 20 20 20 0A 20 20 20 else ◙ +0000:0D50 20 20 20 20 20 20 20 20-20 20 20 20 20 72 65 74 ret +0000:0D60 20 7E 3D 20 2A 61 6C 74-65 72 6E 61 74 69 76 65 ~= *alternative +0000:0D70 73 3B 20 20 20 20 2F 2F-20 61 70 70 65 6E 64 20 s; // append +0000:0D80 74 68 65 73 65 20 61 6C-74 65 72 6E 61 74 69 76 these alternativ +0000:0D90 65 73 0A 20 20 20 20 20-20 20 20 7D 0A 20 20 20 es◙ }◙ +0000:0DA0 20 20 20 20 20 2F 2F 20-54 72 79 20 74 6F 20 6B // Try to k +0000:0DB0 65 65 70 20 31 20 64 69-67 69 74 2C 20 6F 6E 6C eep 1 digit, onl +0000:0DC0 79 20 69 66 20 77 65 27-72 65 20 61 6C 6C 6F 77 y if we're allow +0000:0DD0 65 64 20 61 6E 64 20 6E-6F 20 6F 74 68 65 72 0A ed and no other◙ +0000:0DE0 20 20 20 20 20 20 20 20-2F 2F 20 61 6C 74 65 72 // alter +0000:0DF0 6E 61 74 69 76 65 73 20-77 65 72 65 20 66 6F 75 natives were fou +0000:0E00 6E 64 0A 20 20 20 20 20-20 20 20 2F 2F 20 54 65 nd◙ // Te +0000:0E10 73 74 69 6E 67 20 22 72-65 74 2E 6C 65 6E 67 74 sting "ret.lengt +0000:0E20 68 22 20 6D 61 6B 65 73-20 6D 6F 72 65 20 73 65 h" makes more se +0000:0E30 6E 73 65 20 74 68 61 6E-20 74 65 73 74 69 6E 67 nse than testing +0000:0E40 20 22 66 6F 75 6E 64 77-6F 72 64 22 2C 0A 20 20 "foundword",◙ +0000:0E50 20 20 20 20 20 20 2F 2F-20 62 75 74 20 74 68 65 // but the +0000:0E60 20 6F 74 68 65 72 20 69-6D 70 6C 65 6D 65 6E 74 other implement +0000:0E70 61 74 69 6F 6E 73 20 73-65 65 6D 20 74 6F 20 64 ations seem to d +0000:0E80 6F 20 6A 75 73 74 20 74-68 69 73 2E 0A 20 20 20 o just this.◙ +0000:0E90 20 20 20 20 20 69 66 20-28 64 69 67 69 74 6F 6B if (digitok +0000:0EA0 20 26 26 20 21 66 6F 75-6E 64 77 6F 72 64 29 20 && !foundword) +0000:0EB0 7B 20 2F 2F 72 65 74 2E-6C 65 6E 67 74 68 20 3D { //ret.length = +0000:0EC0 3D 20 30 20 20 0A 20 20-20 20 20 20 20 20 20 20 = 0 ◙ +0000:0ED0 20 20 69 66 28 6E 75 6D-62 65 72 73 2E 6C 65 6E if(numbers.len +0000:0EE0 67 74 68 20 3E 20 20 31-29 20 7B 0A 20 20 20 20 gth > 1) {◙ +0000:0EF0 20 20 20 20 20 20 20 20-20 20 20 20 2F 2F 20 43 // C +0000:0F00 6F 6D 62 69 6E 65 20 31-20 64 69 67 69 74 20 77 ombine 1 digit w +0000:0F10 69 74 68 20 61 6C 6C 20-61 6C 74 65 6E 61 74 69 ith all altenati +0000:0F20 76 65 73 20 66 72 6F 6D-20 74 68 65 20 72 65 73 ves from the res +0000:0F30 74 20 20 20 20 0A 20 20-20 20 20 20 20 20 20 20 t ◙ +0000:0F40 20 20 20 20 20 20 2F 2F-20 28 6E 65 78 74 20 70 // (next p +0000:0F50 69 65 63 65 20 63 61 6E-20 6E 6F 74 20 73 74 61 iece can not sta +0000:0F60 72 74 20 77 69 74 68 20-61 20 64 69 67 69 74 29 rt with a digit) +0000:0F70 20 20 20 20 20 20 20 20-20 20 0A 20 20 20 20 20 ◙ +0000:0F80 20 20 20 20 20 20 20 20-20 20 20 66 6F 72 65 61 forea +0000:0F90 63 68 20 28 61 3B 20 5F-46 69 6E 64 57 6F 72 64 ch (a; _FindWord +0000:0FA0 73 28 20 6E 75 6D 62 65-72 73 5B 31 2E 2E 24 5D s( numbers[1..$] +0000:0FB0 2C 20 66 61 6C 73 65 20-29 20 29 0A 20 20 20 20 , false ) )◙ +0000:0FC0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 +0000:0FD0 72 65 74 20 7E 3D 20 6E-75 6D 62 65 72 73 5B 30 ret ~= numbers[0 +0000:0FE0 2E 2E 31 5D 20 7E 20 22-20 22 20 7E 20 61 3B 0A ..1] ~ " " ~ a;◙ +0000:0FF0 20 20 20 20 20 20 20 20-20 20 20 20 7D 20 20 20 } +0000:1000 20 0A 20 20 20 20 20 20-20 20 20 20 20 20 65 6C ◙ el +0000:1010 73 65 20 20 20 20 0A 20-20 20 20 20 20 20 20 20 se ◙ +0000:1020 20 20 20 20 20 20 20 72-65 74 20 7E 3D 20 6E 75 ret ~= nu +0000:1030 6D 62 65 72 73 5B 30 2E-2E 31 5D 3B 20 20 20 20 mbers[0..1]; +0000:1040 2F 2F 20 6A 75 73 74 20-61 70 70 65 6E 64 20 74 // just append t +0000:1050 68 69 73 20 64 69 67 69-74 20 20 20 20 20 20 20 his digit +0000:1060 20 20 20 20 20 20 0A 20-20 20 20 20 20 20 20 7D ◙ } +0000:1070 20 20 20 20 0A 20 20 20-20 20 20 20 20 72 65 74 ◙ ret +0000:1080 75 72 6E 20 72 65 74 3B-0A 20 20 20 20 7D 0A 0A urn ret;◙ }◙◙ +0000:1090 20 20 20 20 2F 2F 2F 20-28 54 68 69 73 20 66 75 /// (This fu +0000:10A0 6E 63 74 69 6F 6E 20 77-61 73 20 69 6E 6C 69 6E nction was inlin +0000:10B0 65 64 20 69 6E 20 74 68-65 20 6F 72 69 67 69 6E ed in the origin +0000:10C0 61 6C 20 70 72 6F 67 72-61 6D 29 20 0A 20 20 20 al program) ◙ +0000:10D0 20 2F 2F 2F 20 46 69 6E-64 73 20 61 6C 6C 20 61 /// Finds all a +0000:10E0 6C 74 65 72 6E 61 74 69-76 65 73 20 66 6F 72 20 lternatives for +0000:10F0 74 68 65 20 67 69 76 65-6E 20 70 68 6F 6E 65 20 the given phone +0000:1100 6E 75 6D 62 65 72 20 0A-20 20 20 20 2F 2F 2F 20 number ◙ /// +0000:1110 52 65 74 75 72 6E 73 3A-20 61 72 72 61 79 20 6F Returns: array o +0000:1120 66 20 73 74 72 69 6E 67-73 20 0A 20 20 20 20 73 f strings ◙ s +0000:1130 74 72 69 6E 67 61 72 72-61 79 20 46 69 6E 64 57 tringarray FindW +0000:1140 6F 72 64 73 28 20 73 74-72 69 6E 67 20 70 68 6F ords( string pho +0000:1150 6E 65 5F 6E 75 6D 62 65-72 20 29 0A 20 20 20 20 ne_number )◙ +0000:1160 7B 0A 20 20 20 20 20 20-20 20 69 66 20 28 21 70 {◙ if (!p +0000:1170 68 6F 6E 65 5F 6E 75 6D-62 65 72 2E 6C 65 6E 67 hone_number.leng +0000:1180 74 68 29 0A 20 20 20 20-20 20 20 20 20 20 20 20 th)◙ +0000:1190 72 65 74 75 72 6E 20 6E-75 6C 6C 3B 0A 20 20 20 return null;◙ +0000:11A0 20 20 20 20 20 2F 2F 20-53 74 72 69 70 20 74 68 // Strip th +0000:11B0 65 20 6E 6F 6E 2D 64 69-67 69 74 20 63 68 61 72 e non-digit char +0000:11C0 61 63 74 65 72 73 20 66-72 6F 6D 20 74 68 65 20 acters from the +0000:11D0 70 68 6F 6E 65 20 6E 75-6D 62 65 72 2C 20 61 6E phone number, an +0000:11E0 64 0A 20 20 20 20 20 20-20 20 2F 2F 20 70 61 73 d◙ // pas +0000:11F0 73 20 69 74 20 74 6F 20-74 68 65 20 72 65 63 75 s it to the recu +0000:1200 72 73 69 76 65 20 66 75-6E 63 74 69 6F 6E 20 28 rsive function ( +0000:1210 6C 65 61 64 69 6E 67 20-64 69 67 69 74 20 69 73 leading digit is +0000:1220 20 61 6C 6C 6F 77 65 64-29 0A 20 20 20 20 20 20 allowed)◙ +0000:1230 20 20 72 65 74 75 72 6E-20 5F 46 69 6E 64 57 6F return _FindWo +0000:1240 72 64 73 28 20 73 74 72-69 70 4E 6F 6E 44 69 67 rds( stripNonDig +0000:1250 69 74 28 70 68 6F 6E 65-5F 6E 75 6D 62 65 72 29 it(phone_number) +0000:1260 2C 20 74 72 75 65 20 29-3B 20 20 20 20 0A 20 20 , true ); ◙ +0000:1270 20 20 7D 20 20 20 20 0A-20 20 20 20 0A 20 20 20 } ◙ ◙ +0000:1280 20 2F 2F 20 52 65 61 64-20 74 68 65 20 70 68 6F // Read the pho +0000:1290 6E 65 20 6E 75 6D 62 65-72 73 20 20 20 20 20 0A ne numbers ◙ +0000:12A0 20 20 20 20 66 6F 72 65-61 63 68 28 73 74 72 69 foreach(stri +0000:12B0 6E 67 20 70 68 6F 6E 65-3B 20 6E 65 77 20 42 75 ng phone; new Bu +0000:12C0 66 66 65 72 65 64 46 69-6C 65 28 22 69 6E 70 75 fferedFile("inpu +0000:12D0 74 2E 74 78 74 22 20 20-20 29 20 29 0A 20 20 20 t.txt" ) )◙ +0000:12E0 20 20 20 20 20 66 6F 72-65 61 63 68 28 61 6C 74 foreach(alt +0000:12F0 65 72 6E 61 74 69 76 65-3B 20 46 69 6E 64 57 6F ernative; FindWo +0000:1300 72 64 73 28 20 70 68 6F-6E 65 20 29 20 29 0A 20 rds( phone ) )◙ +0000:1310 20 20 20 20 20 20 20 20-20 20 20 77 72 69 74 65 write +0000:1320 66 6C 6E 28 70 68 6F 6E-65 2C 20 22 3A 20 22 2C fln(phone, ": ", +0000:1330 20 61 6C 74 65 72 6E 61-74 69 76 65 20 29 3B 0A alternative );◙ +0000:1340 7D 0A 0A }◙◙ diff --git a/tests/examplefiles/hexdump_hd b/tests/examplefiles/hexdump_hd new file mode 100644 index 00000000..4af46fcb --- /dev/null +++ b/tests/examplefiles/hexdump_hd @@ -0,0 +1,310 @@ +00000000 2f 2f 20 43 72 65 61 74 65 64 20 62 79 20 4c 69 |// Created by Li| +00000010 6f 6e 65 6c 6c 6f 20 4c 75 6e 65 73 75 20 61 6e |onello Lunesu an| +00000020 64 20 70 6c 61 63 65 64 20 69 6e 20 74 68 65 20 |d placed in the | +00000030 70 75 62 6c 69 63 20 64 6f 6d 61 69 6e 2e 0a 2f |public domain../| +00000040 2f 20 54 68 69 73 20 66 69 6c 65 20 68 61 73 20 |/ This file has | +00000050 62 65 65 6e 20 6d 6f 64 69 66 69 65 64 20 66 72 |been modified fr| +00000060 6f 6d 20 69 74 73 20 6f 72 69 67 69 6e 61 6c 20 |om its original | +00000070 76 65 72 73 69 6f 6e 2e 0a 2f 2f 20 49 74 20 68 |version..// It h| +00000080 61 73 20 62 65 65 6e 20 66 6f 72 6d 61 74 74 65 |as been formatte| +00000090 64 20 74 6f 20 66 69 74 20 79 6f 75 72 20 73 63 |d to fit your sc| +000000a0 72 65 65 6e 2e 0a 6d 6f 64 75 6c 65 20 70 68 6f |reen..module pho| +000000b0 6e 65 6e 6f 3b 20 20 20 20 20 2f 2f 20 6f 70 74 |neno; // opt| +000000c0 69 6f 6e 61 6c 0a 69 6d 70 6f 72 74 20 73 74 64 |ional.import std| +000000d0 2e 73 74 64 69 6f 3b 20 20 20 2f 2f 20 77 72 69 |.stdio; // wri| +000000e0 74 65 66 6c 6e 20 20 20 20 20 0a 69 6d 70 6f 72 |tefln .impor| +000000f0 74 20 73 74 64 2e 63 74 79 70 65 3b 20 20 20 2f |t std.ctype; /| +00000100 2f 20 69 73 64 69 67 69 74 20 20 20 20 20 0a 69 |/ isdigit .i| +00000110 6d 70 6f 72 74 20 73 74 64 2e 73 74 72 65 61 6d |mport std.stream| +00000120 3b 20 20 2f 2f 20 42 75 66 66 65 72 65 64 46 69 |; // BufferedFi| +00000130 6c 65 0a 0a 2f 2f 20 4a 75 73 74 20 66 6f 72 20 |le..// Just for | +00000140 72 65 61 64 61 62 69 6c 69 74 79 20 28 69 6d 61 |readability (ima| +00000150 67 69 6e 65 20 63 68 61 72 5b 5d 5b 5d 5b 63 68 |gine char[][][ch| +00000160 61 72 5b 5d 5d 29 20 20 20 20 0a 61 6c 69 61 73 |ar[]]) .alias| +00000170 20 63 68 61 72 5b 5d 20 73 74 72 69 6e 67 3b 0a | char[] string;.| +00000180 61 6c 69 61 73 20 73 74 72 69 6e 67 5b 5d 20 73 |alias string[] s| +00000190 74 72 69 6e 67 61 72 72 61 79 3b 0a 0a 2f 2f 2f |tringarray;..///| +000001a0 20 53 74 72 69 70 73 20 6e 6f 6e 2d 64 69 67 69 | Strips non-digi| +000001b0 74 20 63 68 61 72 61 63 74 65 72 73 20 66 72 6f |t characters fro| +000001c0 6d 20 74 68 65 20 73 74 72 69 6e 67 20 28 43 4f |m the string (CO| +000001d0 57 29 0a 73 74 72 69 6e 67 20 73 74 72 69 70 4e |W).string stripN| +000001e0 6f 6e 44 69 67 69 74 28 20 69 6e 20 73 74 72 69 |onDigit( in stri| +000001f0 6e 67 20 6c 69 6e 65 20 29 20 0a 7b 0a 20 20 20 |ng line ) .{. | +00000200 20 73 74 72 69 6e 67 20 72 65 74 3b 0a 20 20 20 | string ret;. | +00000210 20 66 6f 72 65 61 63 68 28 75 69 6e 74 20 69 2c | foreach(uint i,| +00000220 20 63 3b 20 6c 69 6e 65 29 20 7b 0a 20 20 20 20 | c; line) {. | +00000230 20 20 20 20 2f 2f 20 45 72 72 6f 72 3a 20 73 74 | // Error: st| +00000240 64 2e 63 74 79 70 65 2e 69 73 64 69 67 69 74 20 |d.ctype.isdigit | +00000250 61 74 20 43 3a 5c 64 6d 64 5c 73 72 63 5c 70 68 |at C:\dmd\src\ph| +00000260 6f 62 6f 73 5c 73 74 64 5c 63 74 79 70 65 2e 64 |obos\std\ctype.d| +00000270 28 33 37 29 20 0a 20 20 20 20 20 20 20 20 2f 2f |(37) . //| +00000280 20 63 6f 6e 66 6c 69 63 74 73 20 77 69 74 68 20 | conflicts with | +00000290 73 74 64 2e 73 74 72 65 61 6d 2e 69 73 64 69 67 |std.stream.isdig| +000002a0 69 74 20 61 74 20 43 3a 5c 64 6d 64 5c 73 72 63 |it at C:\dmd\src| +000002b0 5c 70 68 6f 62 6f 73 5c 73 74 64 5c 73 74 72 65 |\phobos\std\stre| +000002c0 61 6d 2e 64 28 32 39 32 34 29 0a 20 20 20 20 20 |am.d(2924). | +000002d0 20 20 20 69 66 20 28 21 73 74 64 2e 63 74 79 70 | if (!std.ctyp| +000002e0 65 2e 69 73 64 69 67 69 74 28 63 29 29 20 7b 0a |e.isdigit(c)) {.| +000002f0 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 | if (| +00000300 21 72 65 74 29 0a 20 20 20 20 20 20 20 20 20 20 |!ret). | +00000310 20 20 20 20 20 20 72 65 74 20 3d 20 6c 69 6e 65 | ret = line| +00000320 5b 30 2e 2e 69 5d 3b 20 20 20 20 0a 20 20 20 20 |[0..i]; . | +00000330 20 20 20 20 7d 20 20 20 20 0a 20 20 20 20 20 20 | } . | +00000340 20 20 65 6c 73 65 20 69 66 20 28 72 65 74 29 0a | else if (ret).| +00000350 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 20 | ret | +00000360 7e 3d 20 63 3b 20 20 20 20 0a 20 20 20 20 7d 20 |~= c; . } | +00000370 20 20 20 0a 20 20 20 20 72 65 74 75 72 6e 20 72 | . return r| +00000380 65 74 3f 72 65 74 3a 6c 69 6e 65 3b 0a 7d 0a 0a |et?ret:line;.}..| +00000390 75 6e 69 74 74 65 73 74 20 7b 0a 20 20 20 20 61 |unittest {. a| +000003a0 73 73 65 72 74 28 20 73 74 72 69 70 4e 6f 6e 44 |ssert( stripNonD| +000003b0 69 67 69 74 28 22 61 73 64 66 22 29 20 3d 3d 20 |igit("asdf") == | +000003c0 22 22 20 20 29 3b 0a 20 20 20 20 61 73 73 65 72 |"" );. asser| +000003d0 74 28 20 73 74 72 69 70 4e 6f 6e 44 69 67 69 74 |t( stripNonDigit| +000003e0 28 22 5c 27 31 33 2d 3d 32 20 34 6b 6f 70 22 29 |("\'13-=2 4kop")| +000003f0 20 3d 3d 20 20 22 31 33 32 34 22 20 20 29 3b 0a | == "1324" );.| +00000400 7d 0a 0a 2f 2f 2f 20 43 6f 6e 76 65 72 74 73 20 |}../// Converts | +00000410 61 20 77 6f 72 64 20 69 6e 74 6f 20 61 20 6e 75 |a word into a nu| +00000420 6d 62 65 72 2c 20 69 67 6e 6f 72 69 6e 67 20 61 |mber, ignoring a| +00000430 6c 6c 20 6e 6f 6e 20 61 6c 70 68 61 20 63 68 61 |ll non alpha cha| +00000440 72 61 63 74 65 72 73 20 20 0a 73 74 72 69 6e 67 |racters .string| +00000450 20 77 6f 72 64 54 6f 4e 75 6d 28 20 69 6e 20 73 | wordToNum( in s| +00000460 74 72 69 6e 67 20 77 6f 72 64 20 29 0a 7b 0a 2f |tring word ).{./| +00000470 2f 20 74 72 61 6e 73 6c 61 74 69 6f 6e 20 74 61 |/ translation ta| +00000480 62 6c 65 20 66 6f 72 20 74 68 65 20 74 61 73 6b |ble for the task| +00000490 20 61 74 20 68 61 6e 64 0a 63 6f 6e 73 74 20 63 | at hand.const c| +000004a0 68 61 72 5b 32 35 36 5d 20 54 52 41 4e 53 4c 41 |har[256] TRANSLA| +000004b0 54 45 20 3d 20 20 20 20 0a 20 20 20 20 22 20 20 |TE = . " | +000004c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +000004d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 | " | +000004e0 20 2f 2f 20 30 20 20 20 0a 20 20 20 20 22 20 20 | // 0 . " | +000004f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 31 | 01| +00000500 32 33 34 35 36 37 38 39 20 20 20 20 20 20 22 20 |23456789 " | +00000510 20 2f 2f 20 33 32 20 20 20 20 20 0a 20 20 20 20 | // 32 . | +00000520 22 20 35 37 36 33 30 34 39 39 36 31 37 38 35 31 |" 57630499617851| +00000530 38 38 31 32 33 34 37 36 32 32 33 39 20 20 20 20 |881234762239 | +00000540 20 22 20 20 2f 2f 20 36 34 20 20 20 0a 20 20 20 | " // 64 . | +00000550 20 22 20 35 37 36 33 30 34 39 39 36 31 37 38 35 | " 5763049961785| +00000560 31 38 38 31 32 33 34 37 36 32 32 33 39 20 20 20 |1881234762239 | +00000570 20 20 22 0a 20 20 20 20 22 20 20 20 20 20 20 20 | ". " | +00000580 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +00000590 20 20 20 20 20 20 20 20 20 22 0a 20 20 20 20 22 | ". "| +000005a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +* +000005c0 22 0a 20 20 20 20 22 20 20 20 20 20 20 20 20 20 |". " | +000005d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +000005e0 20 20 20 20 20 20 20 22 20 20 20 20 0a 20 20 20 | " . | +000005f0 20 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | " | +00000600 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +00000610 20 20 22 3b 0a 20 20 20 20 73 74 72 69 6e 67 20 | ";. string | +00000620 72 65 74 3b 0a 20 20 20 20 66 6f 72 65 61 63 68 |ret;. foreach| +00000630 28 63 3b 20 63 61 73 74 28 75 62 79 74 65 5b 5d |(c; cast(ubyte[]| +00000640 29 77 6f 72 64 29 0a 20 20 20 20 20 20 20 20 69 |)word). i| +00000650 66 20 28 54 52 41 4e 53 4c 41 54 45 5b 63 5d 20 |f (TRANSLATE[c] | +00000660 21 3d 20 27 20 27 29 0a 20 20 20 20 20 20 20 20 |!= ' '). | +00000670 20 20 20 20 72 65 74 20 7e 3d 20 54 52 41 4e 53 | ret ~= TRANS| +00000680 4c 41 54 45 5b 63 5d 3b 0a 20 20 20 20 72 65 74 |LATE[c];. ret| +00000690 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 75 6e 69 74 |urn ret;.}..unit| +000006a0 74 65 73 74 20 7b 0a 20 2f 2f 20 54 65 73 74 20 |test {. // Test | +000006b0 77 6f 72 64 54 6f 4e 75 6d 20 75 73 69 6e 67 20 |wordToNum using | +000006c0 74 68 65 20 74 61 62 6c 65 20 66 72 6f 6d 20 74 |the table from t| +000006d0 68 65 20 74 61 73 6b 20 64 65 73 63 72 69 70 74 |he task descript| +000006e0 69 6f 6e 2e 0a 20 61 73 73 65 72 74 28 20 22 30 |ion.. assert( "0| +000006f0 31 31 31 32 32 32 33 33 33 34 34 35 35 36 36 36 |1112223334455666| +00000700 37 37 37 38 38 38 39 39 39 22 20 3d 3d 0a 20 20 |777888999" ==. | +00000710 20 77 6f 72 64 54 6f 4e 75 6d 28 22 45 20 7c 20 | wordToNum("E | | +00000720 4a 20 4e 20 51 20 7c 20 52 20 57 20 58 20 7c 20 |J N Q | R W X | | +00000730 44 20 53 20 59 20 7c 20 46 20 54 20 7c 20 41 20 |D S Y | F T | A | +00000740 4d 20 7c 20 43 20 49 20 56 20 7c 20 42 20 4b 20 |M | C I V | B K | +00000750 55 20 7c 20 4c 20 4f 20 50 20 7c 20 47 20 48 20 |U | L O P | G H | +00000760 5a 22 29 29 3b 0a 20 61 73 73 65 72 74 28 20 22 |Z"));. assert( "| +00000770 30 31 31 31 32 32 32 33 33 33 34 34 35 35 36 36 |0111222333445566| +00000780 36 37 37 37 38 38 38 39 39 39 22 20 3d 3d 20 0a |6777888999" == .| +00000790 20 20 20 77 6f 72 64 54 6f 4e 75 6d 28 22 65 20 | wordToNum("e | +000007a0 7c 20 6a 20 6e 20 71 20 7c 20 72 20 77 20 78 20 || j n q | r w x | +000007b0 7c 20 64 20 73 20 79 20 7c 20 66 20 74 20 7c 20 || d s y | f t | | +000007c0 61 20 6d 20 7c 20 63 20 69 20 76 20 7c 20 62 20 |a m | c i v | b | +000007d0 6b 20 75 20 7c 20 6c 20 6f 20 70 20 7c 20 67 20 |k u | l o p | g | +000007e0 68 20 7a 22 29 29 3b 0a 20 61 73 73 65 72 74 28 |h z"));. assert(| +000007f0 20 22 30 31 32 33 34 35 36 37 38 39 22 20 3d 3d | "0123456789" ==| +00000800 20 0a 20 20 20 77 6f 72 64 54 6f 4e 75 6d 28 22 | . wordToNum("| +00000810 30 20 7c 20 20 20 31 20 20 20 7c 20 20 20 32 20 |0 | 1 | 2 | +00000820 20 20 7c 20 20 20 33 20 20 20 7c 20 20 34 20 20 | | 3 | 4 | +00000830 7c 20 20 35 20 20 7c 20 20 20 36 20 20 20 7c 20 || 5 | 6 | | +00000840 20 20 37 20 20 20 7c 20 20 20 38 20 20 20 7c 20 | 7 | 8 | | +00000850 20 20 39 22 29 29 3b 0a 7d 0a 0a 76 6f 69 64 20 | 9"));.}..void | +00000860 6d 61 69 6e 28 20 73 74 72 69 6e 67 5b 5d 20 61 |main( string[] a| +00000870 72 67 73 20 29 0a 7b 0a 20 20 20 20 2f 2f 20 54 |rgs ).{. // T| +00000880 68 69 73 20 61 73 73 6f 63 69 61 74 69 76 65 20 |his associative | +00000890 61 72 72 61 79 20 6d 61 70 73 20 61 20 6e 75 6d |array maps a num| +000008a0 62 65 72 20 74 6f 20 61 6e 20 61 72 72 61 79 20 |ber to an array | +000008b0 6f 66 20 77 6f 72 64 73 2e 20 20 20 20 0a 20 20 |of words. . | +000008c0 20 20 73 74 72 69 6e 67 61 72 72 61 79 5b 73 74 | stringarray[st| +000008d0 72 69 6e 67 5d 20 20 20 20 6e 75 6d 32 77 6f 72 |ring] num2wor| +000008e0 64 73 3b 0a 0a 20 20 20 20 66 6f 72 65 61 63 68 |ds;.. foreach| +000008f0 28 73 74 72 69 6e 67 20 77 6f 72 64 3b 20 6e 65 |(string word; ne| +00000900 77 20 42 75 66 66 65 72 65 64 46 69 6c 65 28 22 |w BufferedFile("| +00000910 64 69 63 74 69 6f 6e 61 72 79 2e 74 78 74 22 20 |dictionary.txt" | +00000920 29 20 29 0a 20 20 20 20 20 20 20 20 6e 75 6d 32 |) ). num2| +00000930 77 6f 72 64 73 5b 20 77 6f 72 64 54 6f 4e 75 6d |words[ wordToNum| +00000940 28 77 6f 72 64 29 20 5d 20 7e 3d 20 77 6f 72 64 |(word) ] ~= word| +00000950 2e 64 75 70 3b 20 20 20 20 20 20 20 20 2f 2f 20 |.dup; // | +00000960 6d 75 73 74 20 64 75 70 0a 0a 20 20 20 20 2f 2f |must dup.. //| +00000970 2f 20 46 69 6e 64 73 20 61 6c 6c 20 61 6c 74 65 |/ Finds all alte| +00000980 72 6e 61 74 69 76 65 73 20 66 6f 72 20 74 68 65 |rnatives for the| +00000990 20 67 69 76 65 6e 20 6e 75 6d 62 65 72 0a 20 20 | given number. | +000009a0 20 20 2f 2f 2f 20 28 73 68 6f 75 6c 64 20 68 61 | /// (should ha| +000009b0 76 65 20 62 65 65 6e 20 73 74 72 69 70 70 65 64 |ve been stripped| +000009c0 20 66 72 6f 6d 20 6e 6f 6e 2d 64 69 67 69 74 20 | from non-digit | +000009d0 63 68 61 72 61 63 74 65 72 73 29 0a 20 20 20 20 |characters). | +000009e0 73 74 72 69 6e 67 61 72 72 61 79 20 5f 46 69 6e |stringarray _Fin| +000009f0 64 57 6f 72 64 73 28 20 73 74 72 69 6e 67 20 6e |dWords( string n| +00000a00 75 6d 62 65 72 73 2c 20 62 6f 6f 6c 20 64 69 67 |umbers, bool dig| +00000a10 69 74 6f 6b 20 29 0a 20 20 20 20 69 6e 20 7b 0a |itok ). in {.| +00000a20 20 20 20 20 20 20 20 20 61 73 73 65 72 74 28 6e | assert(n| +00000a30 75 6d 62 65 72 73 2e 6c 65 6e 67 74 68 20 3e 20 |umbers.length > | +00000a40 20 30 29 3b 20 20 20 20 0a 20 20 20 20 7d 20 20 | 0); . } | +00000a50 20 20 0a 20 20 20 20 6f 75 74 28 72 65 73 75 6c | . out(resul| +00000a60 74 29 20 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 |t) {. for| +00000a70 65 61 63 68 20 28 61 3b 20 72 65 73 75 6c 74 29 |each (a; result)| +00000a80 0a 20 20 20 20 20 20 20 20 20 20 20 20 61 73 73 |. ass| +00000a90 65 72 74 28 20 77 6f 72 64 54 6f 4e 75 6d 28 61 |ert( wordToNum(a| +00000aa0 29 20 3d 3d 20 6e 75 6d 62 65 72 73 20 29 3b 0a |) == numbers );.| +00000ab0 20 20 20 20 7d 20 20 20 20 0a 20 20 20 20 62 6f | } . bo| +00000ac0 64 79 20 7b 0a 20 20 20 20 20 20 20 20 73 74 72 |dy {. str| +00000ad0 69 6e 67 61 72 72 61 79 20 72 65 74 3b 0a 20 20 |ingarray ret;. | +00000ae0 20 20 20 20 20 20 62 6f 6f 6c 20 66 6f 75 6e 64 | bool found| +00000af0 77 6f 72 64 20 3d 20 66 61 6c 73 65 3b 0a 20 20 |word = false;. | +00000b00 20 20 20 20 20 20 66 6f 72 20 28 75 69 6e 74 20 | for (uint | +00000b10 74 3d 31 3b 20 74 3c 3d 6e 75 6d 62 65 72 73 2e |t=1; t<=numbers.| +00000b20 6c 65 6e 67 74 68 3b 20 2b 2b 74 29 20 7b 0a 20 |length; ++t) {. | +00000b30 20 20 20 20 20 20 20 20 20 20 20 61 75 74 6f 20 | auto | +00000b40 61 6c 74 65 72 6e 61 74 69 76 65 73 20 3d 20 6e |alternatives = n| +00000b50 75 6d 62 65 72 73 5b 30 2e 2e 74 5d 20 69 6e 20 |umbers[0..t] in | +00000b60 6e 75 6d 32 77 6f 72 64 73 3b 0a 20 20 20 20 20 |num2words;. | +00000b70 20 20 20 20 20 20 20 69 66 20 28 21 61 6c 74 65 | if (!alte| +00000b80 72 6e 61 74 69 76 65 73 29 0a 20 20 20 20 20 20 |rnatives). | +00000b90 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e | contin| +00000ba0 75 65 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 |ue;. | +00000bb0 66 6f 75 6e 64 77 6f 72 64 20 3d 20 74 72 75 65 |foundword = true| +00000bc0 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 |;. if| +00000bd0 20 28 6e 75 6d 62 65 72 73 2e 6c 65 6e 67 74 68 | (numbers.length| +00000be0 20 3e 20 20 74 29 20 7b 0a 20 20 20 20 20 20 20 | > t) {. | +00000bf0 20 20 20 20 20 20 20 20 20 2f 2f 20 43 6f 6d 62 | // Comb| +00000c00 69 6e 65 20 61 6c 6c 20 63 75 72 72 65 6e 74 20 |ine all current | +00000c10 61 6c 74 65 72 6e 61 74 69 76 65 73 20 77 69 74 |alternatives wit| +00000c20 68 20 61 6c 6c 20 61 6c 74 65 72 6e 61 74 69 76 |h all alternativ| +00000c30 65 73 20 20 20 20 20 0a 20 20 20 20 20 20 20 20 |es . | +00000c40 20 20 20 20 20 20 20 20 2f 2f 20 6f 66 20 74 68 | // of th| +00000c50 65 20 72 65 73 74 20 28 6e 65 78 74 20 70 69 65 |e rest (next pie| +00000c60 63 65 20 63 61 6e 20 73 74 61 72 74 20 77 69 74 |ce can start wit| +00000c70 68 20 61 20 64 69 67 69 74 29 20 20 20 20 20 20 |h a digit) | +00000c80 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 20 20 | . | +00000c90 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 63 68 | foreach| +00000ca0 20 28 61 32 3b 20 5f 46 69 6e 64 57 6f 72 64 73 | (a2; _FindWords| +00000cb0 28 20 6e 75 6d 62 65 72 73 5b 74 2e 2e 24 5d 2c |( numbers[t..$],| +00000cc0 20 74 72 75 65 20 20 20 20 20 29 20 29 0a 20 20 | true ) ). | +00000cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +00000ce0 20 20 66 6f 72 65 61 63 68 28 61 31 3b 20 2a 61 | foreach(a1; *a| +00000cf0 6c 74 65 72 6e 61 74 69 76 65 73 29 0a 20 20 20 |lternatives). | +00000d00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +00000d10 20 20 20 20 72 65 74 20 7e 3d 20 61 31 20 7e 20 | ret ~= a1 ~ | +00000d20 22 20 22 20 7e 20 61 32 3b 0a 20 20 20 20 20 20 |" " ~ a2;. | +00000d30 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 | }. | +00000d40 20 20 20 20 65 6c 73 65 20 20 20 20 0a 20 20 20 | else . | +00000d50 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 | ret| +00000d60 20 7e 3d 20 2a 61 6c 74 65 72 6e 61 74 69 76 65 | ~= *alternative| +00000d70 73 3b 20 20 20 20 2f 2f 20 61 70 70 65 6e 64 20 |s; // append | +00000d80 74 68 65 73 65 20 61 6c 74 65 72 6e 61 74 69 76 |these alternativ| +00000d90 65 73 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 |es. }. | +00000da0 20 20 20 20 20 2f 2f 20 54 72 79 20 74 6f 20 6b | // Try to k| +00000db0 65 65 70 20 31 20 64 69 67 69 74 2c 20 6f 6e 6c |eep 1 digit, onl| +00000dc0 79 20 69 66 20 77 65 27 72 65 20 61 6c 6c 6f 77 |y if we're allow| +00000dd0 65 64 20 61 6e 64 20 6e 6f 20 6f 74 68 65 72 0a |ed and no other.| +00000de0 20 20 20 20 20 20 20 20 2f 2f 20 61 6c 74 65 72 | // alter| +00000df0 6e 61 74 69 76 65 73 20 77 65 72 65 20 66 6f 75 |natives were fou| +00000e00 6e 64 0a 20 20 20 20 20 20 20 20 2f 2f 20 54 65 |nd. // Te| +00000e10 73 74 69 6e 67 20 22 72 65 74 2e 6c 65 6e 67 74 |sting "ret.lengt| +00000e20 68 22 20 6d 61 6b 65 73 20 6d 6f 72 65 20 73 65 |h" makes more se| +00000e30 6e 73 65 20 74 68 61 6e 20 74 65 73 74 69 6e 67 |nse than testing| +00000e40 20 22 66 6f 75 6e 64 77 6f 72 64 22 2c 0a 20 20 | "foundword",. | +00000e50 20 20 20 20 20 20 2f 2f 20 62 75 74 20 74 68 65 | // but the| +00000e60 20 6f 74 68 65 72 20 69 6d 70 6c 65 6d 65 6e 74 | other implement| +00000e70 61 74 69 6f 6e 73 20 73 65 65 6d 20 74 6f 20 64 |ations seem to d| +00000e80 6f 20 6a 75 73 74 20 74 68 69 73 2e 0a 20 20 20 |o just this.. | +00000e90 20 20 20 20 20 69 66 20 28 64 69 67 69 74 6f 6b | if (digitok| +00000ea0 20 26 26 20 21 66 6f 75 6e 64 77 6f 72 64 29 20 | && !foundword) | +00000eb0 7b 20 2f 2f 72 65 74 2e 6c 65 6e 67 74 68 20 3d |{ //ret.length =| +00000ec0 3d 20 30 20 20 0a 20 20 20 20 20 20 20 20 20 20 |= 0 . | +00000ed0 20 20 69 66 28 6e 75 6d 62 65 72 73 2e 6c 65 6e | if(numbers.len| +00000ee0 67 74 68 20 3e 20 20 31 29 20 7b 0a 20 20 20 20 |gth > 1) {. | +00000ef0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 43 | // C| +00000f00 6f 6d 62 69 6e 65 20 31 20 64 69 67 69 74 20 77 |ombine 1 digit w| +00000f10 69 74 68 20 61 6c 6c 20 61 6c 74 65 6e 61 74 69 |ith all altenati| +00000f20 76 65 73 20 66 72 6f 6d 20 74 68 65 20 72 65 73 |ves from the res| +00000f30 74 20 20 20 20 0a 20 20 20 20 20 20 20 20 20 20 |t . | +00000f40 20 20 20 20 20 20 2f 2f 20 28 6e 65 78 74 20 70 | // (next p| +00000f50 69 65 63 65 20 63 61 6e 20 6e 6f 74 20 73 74 61 |iece can not sta| +00000f60 72 74 20 77 69 74 68 20 61 20 64 69 67 69 74 29 |rt with a digit)| +00000f70 20 20 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 | . | +00000f80 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 | forea| +00000f90 63 68 20 28 61 3b 20 5f 46 69 6e 64 57 6f 72 64 |ch (a; _FindWord| +00000fa0 73 28 20 6e 75 6d 62 65 72 73 5b 31 2e 2e 24 5d |s( numbers[1..$]| +00000fb0 2c 20 66 61 6c 73 65 20 29 20 29 0a 20 20 20 20 |, false ) ). | +00000fc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | +00000fd0 72 65 74 20 7e 3d 20 6e 75 6d 62 65 72 73 5b 30 |ret ~= numbers[0| +00000fe0 2e 2e 31 5d 20 7e 20 22 20 22 20 7e 20 61 3b 0a |..1] ~ " " ~ a;.| +00000ff0 20 20 20 20 20 20 20 20 20 20 20 20 7d 20 20 20 | } | +00001000 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 65 6c | . el| +00001010 73 65 20 20 20 20 0a 20 20 20 20 20 20 20 20 20 |se . | +00001020 20 20 20 20 20 20 20 72 65 74 20 7e 3d 20 6e 75 | ret ~= nu| +00001030 6d 62 65 72 73 5b 30 2e 2e 31 5d 3b 20 20 20 20 |mbers[0..1]; | +00001040 2f 2f 20 6a 75 73 74 20 61 70 70 65 6e 64 20 74 |// just append t| +00001050 68 69 73 20 64 69 67 69 74 20 20 20 20 20 20 20 |his digit | +00001060 20 20 20 20 20 20 0a 20 20 20 20 20 20 20 20 7d | . }| +00001070 20 20 20 20 0a 20 20 20 20 20 20 20 20 72 65 74 | . ret| +00001080 75 72 6e 20 72 65 74 3b 0a 20 20 20 20 7d 0a 0a |urn ret;. }..| +00001090 20 20 20 20 2f 2f 2f 20 28 54 68 69 73 20 66 75 | /// (This fu| +000010a0 6e 63 74 69 6f 6e 20 77 61 73 20 69 6e 6c 69 6e |nction was inlin| +000010b0 65 64 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e |ed in the origin| +000010c0 61 6c 20 70 72 6f 67 72 61 6d 29 20 0a 20 20 20 |al program) . | +000010d0 20 2f 2f 2f 20 46 69 6e 64 73 20 61 6c 6c 20 61 | /// Finds all a| +000010e0 6c 74 65 72 6e 61 74 69 76 65 73 20 66 6f 72 20 |lternatives for | +000010f0 74 68 65 20 67 69 76 65 6e 20 70 68 6f 6e 65 20 |the given phone | +00001100 6e 75 6d 62 65 72 20 0a 20 20 20 20 2f 2f 2f 20 |number . /// | +00001110 52 65 74 75 72 6e 73 3a 20 61 72 72 61 79 20 6f |Returns: array o| +00001120 66 20 73 74 72 69 6e 67 73 20 0a 20 20 20 20 73 |f strings . s| +00001130 74 72 69 6e 67 61 72 72 61 79 20 46 69 6e 64 57 |tringarray FindW| +00001140 6f 72 64 73 28 20 73 74 72 69 6e 67 20 70 68 6f |ords( string pho| +00001150 6e 65 5f 6e 75 6d 62 65 72 20 29 0a 20 20 20 20 |ne_number ). | +00001160 7b 0a 20 20 20 20 20 20 20 20 69 66 20 28 21 70 |{. if (!p| +00001170 68 6f 6e 65 5f 6e 75 6d 62 65 72 2e 6c 65 6e 67 |hone_number.leng| +00001180 74 68 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 |th). | +00001190 72 65 74 75 72 6e 20 6e 75 6c 6c 3b 0a 20 20 20 |return null;. | +000011a0 20 20 20 20 20 2f 2f 20 53 74 72 69 70 20 74 68 | // Strip th| +000011b0 65 20 6e 6f 6e 2d 64 69 67 69 74 20 63 68 61 72 |e non-digit char| +000011c0 61 63 74 65 72 73 20 66 72 6f 6d 20 74 68 65 20 |acters from the | +000011d0 70 68 6f 6e 65 20 6e 75 6d 62 65 72 2c 20 61 6e |phone number, an| +000011e0 64 0a 20 20 20 20 20 20 20 20 2f 2f 20 70 61 73 |d. // pas| +000011f0 73 20 69 74 20 74 6f 20 74 68 65 20 72 65 63 75 |s it to the recu| +00001200 72 73 69 76 65 20 66 75 6e 63 74 69 6f 6e 20 28 |rsive function (| +00001210 6c 65 61 64 69 6e 67 20 64 69 67 69 74 20 69 73 |leading digit is| +00001220 20 61 6c 6c 6f 77 65 64 29 0a 20 20 20 20 20 20 | allowed). | +00001230 20 20 72 65 74 75 72 6e 20 5f 46 69 6e 64 57 6f | return _FindWo| +00001240 72 64 73 28 20 73 74 72 69 70 4e 6f 6e 44 69 67 |rds( stripNonDig| +00001250 69 74 28 70 68 6f 6e 65 5f 6e 75 6d 62 65 72 29 |it(phone_number)| +00001260 2c 20 74 72 75 65 20 29 3b 20 20 20 20 0a 20 20 |, true ); . | +00001270 20 20 7d 20 20 20 20 0a 20 20 20 20 0a 20 20 20 | } . . | +00001280 20 2f 2f 20 52 65 61 64 20 74 68 65 20 70 68 6f | // Read the pho| +00001290 6e 65 20 6e 75 6d 62 65 72 73 20 20 20 20 20 0a |ne numbers .| +000012a0 20 20 20 20 66 6f 72 65 61 63 68 28 73 74 72 69 | foreach(stri| +000012b0 6e 67 20 70 68 6f 6e 65 3b 20 6e 65 77 20 42 75 |ng phone; new Bu| +000012c0 66 66 65 72 65 64 46 69 6c 65 28 22 69 6e 70 75 |fferedFile("inpu| +000012d0 74 2e 74 78 74 22 20 20 20 29 20 29 0a 20 20 20 |t.txt" ) ). | +000012e0 20 20 20 20 20 66 6f 72 65 61 63 68 28 61 6c 74 | foreach(alt| +000012f0 65 72 6e 61 74 69 76 65 3b 20 46 69 6e 64 57 6f |ernative; FindWo| +00001300 72 64 73 28 20 70 68 6f 6e 65 20 29 20 29 0a 20 |rds( phone ) ). | +00001310 20 20 20 20 20 20 20 20 20 20 20 77 72 69 74 65 | write| +00001320 66 6c 6e 28 70 68 6f 6e 65 2c 20 22 3a 20 22 2c |fln(phone, ": ",| +00001330 20 61 6c 74 65 72 6e 61 74 69 76 65 20 29 3b 0a | alternative );.| +00001340 7d 0a 0a |}..| +00001343 diff --git a/tests/examplefiles/hexdump_hexcat b/tests/examplefiles/hexdump_hexcat new file mode 100644 index 00000000..522074cf --- /dev/null +++ b/tests/examplefiles/hexdump_hexcat @@ -0,0 +1,247 @@ +00000000 2F 2F 20 43 72 65 61 74 65 64 20 62 79 20 4C 69 6F 6E 65 6C //.Created.by.Lionel +00000014 6C 6F 20 4C 75 6E 65 73 75 20 61 6E 64 20 70 6C 61 63 65 64 lo.Lunesu.and.placed +00000028 20 69 6E 20 74 68 65 20 70 75 62 6C 69 63 20 64 6F 6D 61 69 .in.the.public.domai +0000003C 6E 2E 0A 2F 2F 20 54 68 69 73 20 66 69 6C 65 20 68 61 73 20 n..//.This.file.has. +00000050 62 65 65 6E 20 6D 6F 64 69 66 69 65 64 20 66 72 6F 6D 20 69 been.modified.from.i +00000064 74 73 20 6F 72 69 67 69 6E 61 6C 20 76 65 72 73 69 6F 6E 2E ts.original.version. +00000078 0A 2F 2F 20 49 74 20 68 61 73 20 62 65 65 6E 20 66 6F 72 6D .//.It.has.been.form +0000008C 61 74 74 65 64 20 74 6F 20 66 69 74 20 79 6F 75 72 20 73 63 atted.to.fit.your.sc +000000A0 72 65 65 6E 2E 0A 6D 6F 64 75 6C 65 20 70 68 6F 6E 65 6E 6F reen..module.phoneno +000000B4 3B 20 20 20 20 20 2F 2F 20 6F 70 74 69 6F 6E 61 6C 0A 69 6D ;.....//.optional.im +000000C8 70 6F 72 74 20 73 74 64 2E 73 74 64 69 6F 3B 20 20 20 2F 2F port.std.stdio;...// +000000DC 20 77 72 69 74 65 66 6C 6E 20 20 20 20 20 0A 69 6D 70 6F 72 .writefln......impor +000000F0 74 20 73 74 64 2E 63 74 79 70 65 3B 20 20 20 2F 2F 20 69 73 t.std.ctype;...//.is +00000104 64 69 67 69 74 20 20 20 20 20 0A 69 6D 70 6F 72 74 20 73 74 digit......import.st +00000118 64 2E 73 74 72 65 61 6D 3B 20 20 2F 2F 20 42 75 66 66 65 72 d.stream;..//.Buffer +0000012C 65 64 46 69 6C 65 0A 0A 2F 2F 20 4A 75 73 74 20 66 6F 72 20 edFile..//.Just.for. +00000140 72 65 61 64 61 62 69 6C 69 74 79 20 28 69 6D 61 67 69 6E 65 readability.(imagine +00000154 20 63 68 61 72 5B 5D 5B 5D 5B 63 68 61 72 5B 5D 5D 29 20 20 .char[][][char[]]).. +00000168 20 20 0A 61 6C 69 61 73 20 63 68 61 72 5B 5D 20 73 74 72 69 ...alias.char[].stri +0000017C 6E 67 3B 0A 61 6C 69 61 73 20 73 74 72 69 6E 67 5B 5D 20 73 ng;.alias.string[].s +00000190 74 72 69 6E 67 61 72 72 61 79 3B 0A 0A 2F 2F 2F 20 53 74 72 tringarray;..///.Str +000001A4 69 70 73 20 6E 6F 6E 2D 64 69 67 69 74 20 63 68 61 72 61 63 ips.non-digit.charac +000001B8 74 65 72 73 20 66 72 6F 6D 20 74 68 65 20 73 74 72 69 6E 67 ters.from.the.string +000001CC 20 28 43 4F 57 29 0A 73 74 72 69 6E 67 20 73 74 72 69 70 4E .(COW).string.stripN +000001E0 6F 6E 44 69 67 69 74 28 20 69 6E 20 73 74 72 69 6E 67 20 6C onDigit(.in.string.l +000001F4 69 6E 65 20 29 20 0A 7B 0A 20 20 20 20 73 74 72 69 6E 67 20 ine.)..{.....string. +00000208 72 65 74 3B 0A 20 20 20 20 66 6F 72 65 61 63 68 28 75 69 6E ret;.....foreach(uin +0000021C 74 20 69 2C 20 63 3B 20 6C 69 6E 65 29 20 7B 0A 20 20 20 20 t.i,.c;.line).{..... +00000230 20 20 20 20 2F 2F 20 45 72 72 6F 72 3A 20 73 74 64 2E 63 74 ....//.Error:.std.ct +00000244 79 70 65 2E 69 73 64 69 67 69 74 20 61 74 20 43 3A 5C 64 6D ype.isdigit.at.C:\dm +00000258 64 5C 73 72 63 5C 70 68 6F 62 6F 73 5C 73 74 64 5C 63 74 79 d\src\phobos\std\cty +0000026C 70 65 2E 64 28 33 37 29 20 0A 20 20 20 20 20 20 20 20 2F 2F pe.d(37)..........// +00000280 20 63 6F 6E 66 6C 69 63 74 73 20 77 69 74 68 20 73 74 64 2E .conflicts.with.std. +00000294 73 74 72 65 61 6D 2E 69 73 64 69 67 69 74 20 61 74 20 43 3A stream.isdigit.at.C: +000002A8 5C 64 6D 64 5C 73 72 63 5C 70 68 6F 62 6F 73 5C 73 74 64 5C \dmd\src\phobos\std\ +000002BC 73 74 72 65 61 6D 2E 64 28 32 39 32 34 29 0A 20 20 20 20 20 stream.d(2924)...... +000002D0 20 20 20 69 66 20 28 21 73 74 64 2E 63 74 79 70 65 2E 69 73 ...if.(!std.ctype.is +000002E4 64 69 67 69 74 28 63 29 29 20 7B 0A 20 20 20 20 20 20 20 20 digit(c)).{......... +000002F8 20 20 20 20 69 66 20 28 21 72 65 74 29 0A 20 20 20 20 20 20 ....if.(!ret)....... +0000030C 20 20 20 20 20 20 20 20 20 20 72 65 74 20 3D 20 6C 69 6E 65 ..........ret.=.line +00000320 5B 30 2E 2E 69 5D 3B 20 20 20 20 0A 20 20 20 20 20 20 20 20 [0..i];............. +00000334 7D 20 20 20 20 0A 20 20 20 20 20 20 20 20 65 6C 73 65 20 69 }.............else.i +00000348 66 20 28 72 65 74 29 0A 20 20 20 20 20 20 20 20 20 20 20 20 f.(ret)............. +0000035C 72 65 74 20 7E 3D 20 63 3B 20 20 20 20 0A 20 20 20 20 7D 20 ret.~=.c;.........}. +00000370 20 20 20 0A 20 20 20 20 72 65 74 75 72 6E 20 72 65 74 3F 72 ........return.ret?r +00000384 65 74 3A 6C 69 6E 65 3B 0A 7D 0A 0A 75 6E 69 74 74 65 73 74 et:line;.}..unittest +00000398 20 7B 0A 20 20 20 20 61 73 73 65 72 74 28 20 73 74 72 69 70 .{.....assert(.strip +000003AC 4E 6F 6E 44 69 67 69 74 28 22 61 73 64 66 22 29 20 3D 3D 20 NonDigit("asdf").==. +000003C0 22 22 20 20 29 3B 0A 20 20 20 20 61 73 73 65 72 74 28 20 73 ""..);.....assert(.s +000003D4 74 72 69 70 4E 6F 6E 44 69 67 69 74 28 22 5C 27 31 33 2D 3D tripNonDigit("\'13-= +000003E8 32 20 34 6B 6F 70 22 29 20 3D 3D 20 20 22 31 33 32 34 22 20 2.4kop").==.."1324". +000003FC 20 29 3B 0A 7D 0A 0A 2F 2F 2F 20 43 6F 6E 76 65 72 74 73 20 .);.}..///.Converts. +00000410 61 20 77 6F 72 64 20 69 6E 74 6F 20 61 20 6E 75 6D 62 65 72 a.word.into.a.number +00000424 2C 20 69 67 6E 6F 72 69 6E 67 20 61 6C 6C 20 6E 6F 6E 20 61 ,.ignoring.all.non.a +00000438 6C 70 68 61 20 63 68 61 72 61 63 74 65 72 73 20 20 0A 73 74 lpha.characters...st +0000044C 72 69 6E 67 20 77 6F 72 64 54 6F 4E 75 6D 28 20 69 6E 20 73 ring.wordToNum(.in.s +00000460 74 72 69 6E 67 20 77 6F 72 64 20 29 0A 7B 0A 2F 2F 20 74 72 tring.word.).{.//.tr +00000474 61 6E 73 6C 61 74 69 6F 6E 20 74 61 62 6C 65 20 66 6F 72 20 anslation.table.for. +00000488 74 68 65 20 74 61 73 6B 20 61 74 20 68 61 6E 64 0A 63 6F 6E the.task.at.hand.con +0000049C 73 74 20 63 68 61 72 5B 32 35 36 5D 20 54 52 41 4E 53 4C 41 st.char[256].TRANSLA +000004B0 54 45 20 3D 20 20 20 20 0A 20 20 20 20 22 20 20 20 20 20 20 TE.=........."...... +000004C4 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .................... +000004D8 20 20 20 20 20 20 22 20 20 2F 2F 20 30 20 20 20 0A 20 20 20 ......"..//.0....... +000004EC 20 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 31 ."................01 +00000500 32 33 34 35 36 37 38 39 20 20 20 20 20 20 22 20 20 2F 2F 20 23456789......"..//. +00000514 33 32 20 20 20 20 20 0A 20 20 20 20 22 20 35 37 36 33 30 34 32..........".576304 +00000528 39 39 36 31 37 38 35 31 38 38 31 32 33 34 37 36 32 32 33 39 99617851881234762239 +0000053C 20 20 20 20 20 22 20 20 2F 2F 20 36 34 20 20 20 0A 20 20 20 ....."..//.64....... +00000550 20 22 20 35 37 36 33 30 34 39 39 36 31 37 38 35 31 38 38 31 .".57630499617851881 +00000564 32 33 34 37 36 32 32 33 39 20 20 20 20 20 22 0A 20 20 20 20 234762239....."..... +00000578 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "................... +0000058C 20 20 20 20 20 20 20 20 20 20 20 20 20 22 0A 20 20 20 20 22 ............."....." +000005A0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .................... +000005B4 20 20 20 20 20 20 20 20 20 20 20 20 22 0A 20 20 20 20 22 20 ............".....". +000005C8 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .................... +000005DC 20 20 20 20 20 20 20 20 20 20 20 22 20 20 20 20 0A 20 20 20 ..........."........ +000005F0 20 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .".................. +00000604 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 3B 0A 20 20 20 ..............";.... +00000618 20 73 74 72 69 6E 67 20 72 65 74 3B 0A 20 20 20 20 66 6F 72 .string.ret;.....for +0000062C 65 61 63 68 28 63 3B 20 63 61 73 74 28 75 62 79 74 65 5B 5D each(c;.cast(ubyte[] +00000640 29 77 6F 72 64 29 0A 20 20 20 20 20 20 20 20 69 66 20 28 54 )word).........if.(T +00000654 52 41 4E 53 4C 41 54 45 5B 63 5D 20 21 3D 20 27 20 27 29 0A RANSLATE[c].!=.'.'). +00000668 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 20 7E 3D 20 54 ............ret.~=.T +0000067C 52 41 4E 53 4C 41 54 45 5B 63 5D 3B 0A 20 20 20 20 72 65 74 RANSLATE[c];.....ret +00000690 75 72 6E 20 72 65 74 3B 0A 7D 0A 0A 75 6E 69 74 74 65 73 74 urn.ret;.}..unittest +000006A4 20 7B 0A 20 2F 2F 20 54 65 73 74 20 77 6F 72 64 54 6F 4E 75 .{..//.Test.wordToNu +000006B8 6D 20 75 73 69 6E 67 20 74 68 65 20 74 61 62 6C 65 20 66 72 m.using.the.table.fr +000006CC 6F 6D 20 74 68 65 20 74 61 73 6B 20 64 65 73 63 72 69 70 74 om.the.task.descript +000006E0 69 6F 6E 2E 0A 20 61 73 73 65 72 74 28 20 22 30 31 31 31 32 ion...assert(."01112 +000006F4 32 32 33 33 33 34 34 35 35 36 36 36 37 37 37 38 38 38 39 39 22333445566677788899 +00000708 39 22 20 3D 3D 0A 20 20 20 77 6F 72 64 54 6F 4E 75 6D 28 22 9".==....wordToNum(" +0000071C 45 20 7C 20 4A 20 4E 20 51 20 7C 20 52 20 57 20 58 20 7C 20 E.|.J.N.Q.|.R.W.X.|. +00000730 44 20 53 20 59 20 7C 20 46 20 54 20 7C 20 41 20 4D 20 7C 20 D.S.Y.|.F.T.|.A.M.|. +00000744 43 20 49 20 56 20 7C 20 42 20 4B 20 55 20 7C 20 4C 20 4F 20 C.I.V.|.B.K.U.|.L.O. +00000758 50 20 7C 20 47 20 48 20 5A 22 29 29 3B 0A 20 61 73 73 65 72 P.|.G.H.Z"));..asser +0000076C 74 28 20 22 30 31 31 31 32 32 32 33 33 33 34 34 35 35 36 36 t(."0111222333445566 +00000780 36 37 37 37 38 38 38 39 39 39 22 20 3D 3D 20 0A 20 20 20 77 6777888999".==.....w +00000794 6F 72 64 54 6F 4E 75 6D 28 22 65 20 7C 20 6A 20 6E 20 71 20 ordToNum("e.|.j.n.q. +000007A8 7C 20 72 20 77 20 78 20 7C 20 64 20 73 20 79 20 7C 20 66 20 |.r.w.x.|.d.s.y.|.f. +000007BC 74 20 7C 20 61 20 6D 20 7C 20 63 20 69 20 76 20 7C 20 62 20 t.|.a.m.|.c.i.v.|.b. +000007D0 6B 20 75 20 7C 20 6C 20 6F 20 70 20 7C 20 67 20 68 20 7A 22 k.u.|.l.o.p.|.g.h.z" +000007E4 29 29 3B 0A 20 61 73 73 65 72 74 28 20 22 30 31 32 33 34 35 ));..assert(."012345 +000007F8 36 37 38 39 22 20 3D 3D 20 0A 20 20 20 77 6F 72 64 54 6F 4E 6789".==.....wordToN +0000080C 75 6D 28 22 30 20 7C 20 20 20 31 20 20 20 7C 20 20 20 32 20 um("0.|...1...|...2. +00000820 20 20 7C 20 20 20 33 20 20 20 7C 20 20 34 20 20 7C 20 20 35 ..|...3...|..4..|..5 +00000834 20 20 7C 20 20 20 36 20 20 20 7C 20 20 20 37 20 20 20 7C 20 ..|...6...|...7...|. +00000848 20 20 38 20 20 20 7C 20 20 20 39 22 29 29 3B 0A 7D 0A 0A 76 ..8...|...9"));.}..v +0000085C 6F 69 64 20 6D 61 69 6E 28 20 73 74 72 69 6E 67 5B 5D 20 61 oid.main(.string[].a +00000870 72 67 73 20 29 0A 7B 0A 20 20 20 20 2F 2F 20 54 68 69 73 20 rgs.).{.....//.This. +00000884 61 73 73 6F 63 69 61 74 69 76 65 20 61 72 72 61 79 20 6D 61 associative.array.ma +00000898 70 73 20 61 20 6E 75 6D 62 65 72 20 74 6F 20 61 6E 20 61 72 ps.a.number.to.an.ar +000008AC 72 61 79 20 6F 66 20 77 6F 72 64 73 2E 20 20 20 20 0A 20 20 ray.of.words........ +000008C0 20 20 73 74 72 69 6E 67 61 72 72 61 79 5B 73 74 72 69 6E 67 ..stringarray[string +000008D4 5D 20 20 20 20 6E 75 6D 32 77 6F 72 64 73 3B 0A 0A 20 20 20 ]....num2words;..... +000008E8 20 66 6F 72 65 61 63 68 28 73 74 72 69 6E 67 20 77 6F 72 64 .foreach(string.word +000008FC 3B 20 6E 65 77 20 42 75 66 66 65 72 65 64 46 69 6C 65 28 22 ;.new.BufferedFile(" +00000910 64 69 63 74 69 6F 6E 61 72 79 2E 74 78 74 22 20 29 20 29 0A dictionary.txt".).). +00000924 20 20 20 20 20 20 20 20 6E 75 6D 32 77 6F 72 64 73 5B 20 77 ........num2words[.w +00000938 6F 72 64 54 6F 4E 75 6D 28 77 6F 72 64 29 20 5D 20 7E 3D 20 ordToNum(word).].~=. +0000094C 77 6F 72 64 2E 64 75 70 3B 20 20 20 20 20 20 20 20 2F 2F 20 word.dup;........//. +00000960 6D 75 73 74 20 64 75 70 0A 0A 20 20 20 20 2F 2F 2F 20 46 69 must.dup......///.Fi +00000974 6E 64 73 20 61 6C 6C 20 61 6C 74 65 72 6E 61 74 69 76 65 73 nds.all.alternatives +00000988 20 66 6F 72 20 74 68 65 20 67 69 76 65 6E 20 6E 75 6D 62 65 .for.the.given.numbe +0000099C 72 0A 20 20 20 20 2F 2F 2F 20 28 73 68 6F 75 6C 64 20 68 61 r.....///.(should.ha +000009B0 76 65 20 62 65 65 6E 20 73 74 72 69 70 70 65 64 20 66 72 6F ve.been.stripped.fro +000009C4 6D 20 6E 6F 6E 2D 64 69 67 69 74 20 63 68 61 72 61 63 74 65 m.non-digit.characte +000009D8 72 73 29 0A 20 20 20 20 73 74 72 69 6E 67 61 72 72 61 79 20 rs).....stringarray. +000009EC 5F 46 69 6E 64 57 6F 72 64 73 28 20 73 74 72 69 6E 67 20 6E _FindWords(.string.n +00000A00 75 6D 62 65 72 73 2C 20 62 6F 6F 6C 20 64 69 67 69 74 6F 6B umbers,.bool.digitok +00000A14 20 29 0A 20 20 20 20 69 6E 20 7B 0A 20 20 20 20 20 20 20 20 .).....in.{......... +00000A28 61 73 73 65 72 74 28 6E 75 6D 62 65 72 73 2E 6C 65 6E 67 74 assert(numbers.lengt +00000A3C 68 20 3E 20 20 30 29 3B 20 20 20 20 0A 20 20 20 20 7D 20 20 h.>..0);.........}.. +00000A50 20 20 0A 20 20 20 20 6F 75 74 28 72 65 73 75 6C 74 29 20 7B .......out(result).{ +00000A64 0A 20 20 20 20 20 20 20 20 66 6F 72 65 61 63 68 20 28 61 3B .........foreach.(a; +00000A78 20 72 65 73 75 6C 74 29 0A 20 20 20 20 20 20 20 20 20 20 20 .result)............ +00000A8C 20 61 73 73 65 72 74 28 20 77 6F 72 64 54 6F 4E 75 6D 28 61 .assert(.wordToNum(a +00000AA0 29 20 3D 3D 20 6E 75 6D 62 65 72 73 20 29 3B 0A 20 20 20 20 ).==.numbers.);..... +00000AB4 7D 20 20 20 20 0A 20 20 20 20 62 6F 64 79 20 7B 0A 20 20 20 }.........body.{.... +00000AC8 20 20 20 20 20 73 74 72 69 6E 67 61 72 72 61 79 20 72 65 74 .....stringarray.ret +00000ADC 3B 0A 20 20 20 20 20 20 20 20 62 6F 6F 6C 20 66 6F 75 6E 64 ;.........bool.found +00000AF0 77 6F 72 64 20 3D 20 66 61 6C 73 65 3B 0A 20 20 20 20 20 20 word.=.false;....... +00000B04 20 20 66 6F 72 20 28 75 69 6E 74 20 74 3D 31 3B 20 74 3C 3D ..for.(uint.t=1;.t<= +00000B18 6E 75 6D 62 65 72 73 2E 6C 65 6E 67 74 68 3B 20 2B 2B 74 29 numbers.length;.++t) +00000B2C 20 7B 0A 20 20 20 20 20 20 20 20 20 20 20 20 61 75 74 6F 20 .{.............auto. +00000B40 61 6C 74 65 72 6E 61 74 69 76 65 73 20 3D 20 6E 75 6D 62 65 alternatives.=.numbe +00000B54 72 73 5B 30 2E 2E 74 5D 20 69 6E 20 6E 75 6D 32 77 6F 72 64 rs[0..t].in.num2word +00000B68 73 3B 0A 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 21 s;.............if.(! +00000B7C 61 6C 74 65 72 6E 61 74 69 76 65 73 29 0A 20 20 20 20 20 20 alternatives)....... +00000B90 20 20 20 20 20 20 20 20 20 20 63 6F 6E 74 69 6E 75 65 3B 0A ..........continue;. +00000BA4 20 20 20 20 20 20 20 20 20 20 20 20 66 6F 75 6E 64 77 6F 72 ............foundwor +00000BB8 64 20 3D 20 74 72 75 65 3B 0A 20 20 20 20 20 20 20 20 20 20 d.=.true;........... +00000BCC 20 20 69 66 20 28 6E 75 6D 62 65 72 73 2E 6C 65 6E 67 74 68 ..if.(numbers.length +00000BE0 20 3E 20 20 74 29 20 7B 0A 20 20 20 20 20 20 20 20 20 20 20 .>..t).{............ +00000BF4 20 20 20 20 20 2F 2F 20 43 6F 6D 62 69 6E 65 20 61 6C 6C 20 .....//.Combine.all. +00000C08 63 75 72 72 65 6E 74 20 61 6C 74 65 72 6E 61 74 69 76 65 73 current.alternatives +00000C1C 20 77 69 74 68 20 61 6C 6C 20 61 6C 74 65 72 6E 61 74 69 76 .with.all.alternativ +00000C30 65 73 20 20 20 20 20 0A 20 20 20 20 20 20 20 20 20 20 20 20 es.................. +00000C44 20 20 20 20 2F 2F 20 6F 66 20 74 68 65 20 72 65 73 74 20 28 ....//.of.the.rest.( +00000C58 6E 65 78 74 20 70 69 65 63 65 20 63 61 6E 20 73 74 61 72 74 next.piece.can.start +00000C6C 20 77 69 74 68 20 61 20 64 69 67 69 74 29 20 20 20 20 20 20 .with.a.digit)...... +00000C80 20 20 20 20 20 20 20 20 0A 20 20 20 20 20 20 20 20 20 20 20 .................... +00000C94 20 20 20 20 20 66 6F 72 65 61 63 68 20 28 61 32 3B 20 5F 46 .....foreach.(a2;._F +00000CA8 69 6E 64 57 6F 72 64 73 28 20 6E 75 6D 62 65 72 73 5B 74 2E indWords(.numbers[t. +00000CBC 2E 24 5D 2C 20 74 72 75 65 20 20 20 20 20 29 20 29 0A 20 20 .$],.true.....).)... +00000CD0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 6F ..................fo +00000CE4 72 65 61 63 68 28 61 31 3B 20 2A 61 6C 74 65 72 6E 61 74 69 reach(a1;.*alternati +00000CF8 76 65 73 29 0A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ves)................ +00000D0C 20 20 20 20 20 20 20 20 72 65 74 20 7E 3D 20 61 31 20 7E 20 ........ret.~=.a1.~. +00000D20 22 20 22 20 7E 20 61 32 3B 0A 20 20 20 20 20 20 20 20 20 20 ".".~.a2;........... +00000D34 20 20 7D 0A 20 20 20 20 20 20 20 20 20 20 20 20 65 6C 73 65 ..}.............else +00000D48 20 20 20 20 0A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .................... +00000D5C 20 72 65 74 20 7E 3D 20 2A 61 6C 74 65 72 6E 61 74 69 76 65 .ret.~=.*alternative +00000D70 73 3B 20 20 20 20 2F 2F 20 61 70 70 65 6E 64 20 74 68 65 73 s;....//.append.thes +00000D84 65 20 61 6C 74 65 72 6E 61 74 69 76 65 73 0A 20 20 20 20 20 e.alternatives...... +00000D98 20 20 20 7D 0A 20 20 20 20 20 20 20 20 2F 2F 20 54 72 79 20 ...}.........//.Try. +00000DAC 74 6F 20 6B 65 65 70 20 31 20 64 69 67 69 74 2C 20 6F 6E 6C to.keep.1.digit,.onl +00000DC0 79 20 69 66 20 77 65 27 72 65 20 61 6C 6C 6F 77 65 64 20 61 y.if.we're.allowed.a +00000DD4 6E 64 20 6E 6F 20 6F 74 68 65 72 0A 20 20 20 20 20 20 20 20 nd.no.other......... +00000DE8 2F 2F 20 61 6C 74 65 72 6E 61 74 69 76 65 73 20 77 65 72 65 //.alternatives.were +00000DFC 20 66 6F 75 6E 64 0A 20 20 20 20 20 20 20 20 2F 2F 20 54 65 .found.........//.Te +00000E10 73 74 69 6E 67 20 22 72 65 74 2E 6C 65 6E 67 74 68 22 20 6D sting."ret.length".m +00000E24 61 6B 65 73 20 6D 6F 72 65 20 73 65 6E 73 65 20 74 68 61 6E akes.more.sense.than +00000E38 20 74 65 73 74 69 6E 67 20 22 66 6F 75 6E 64 77 6F 72 64 22 .testing."foundword" +00000E4C 2C 0A 20 20 20 20 20 20 20 20 2F 2F 20 62 75 74 20 74 68 65 ,.........//.but.the +00000E60 20 6F 74 68 65 72 20 69 6D 70 6C 65 6D 65 6E 74 61 74 69 6F .other.implementatio +00000E74 6E 73 20 73 65 65 6D 20 74 6F 20 64 6F 20 6A 75 73 74 20 74 ns.seem.to.do.just.t +00000E88 68 69 73 2E 0A 20 20 20 20 20 20 20 20 69 66 20 28 64 69 67 his..........if.(dig +00000E9C 69 74 6F 6B 20 26 26 20 21 66 6F 75 6E 64 77 6F 72 64 29 20 itok.&&.!foundword). +00000EB0 7B 20 2F 2F 72 65 74 2E 6C 65 6E 67 74 68 20 3D 3D 20 30 20 {.//ret.length.==.0. +00000EC4 20 0A 20 20 20 20 20 20 20 20 20 20 20 20 69 66 28 6E 75 6D ..............if(num +00000ED8 62 65 72 73 2E 6C 65 6E 67 74 68 20 3E 20 20 31 29 20 7B 0A bers.length.>..1).{. +00000EEC 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2F 2F 20 43 ................//.C +00000F00 6F 6D 62 69 6E 65 20 31 20 64 69 67 69 74 20 77 69 74 68 20 ombine.1.digit.with. +00000F14 61 6C 6C 20 61 6C 74 65 6E 61 74 69 76 65 73 20 66 72 6F 6D all.altenatives.from +00000F28 20 74 68 65 20 72 65 73 74 20 20 20 20 0A 20 20 20 20 20 20 .the.rest........... +00000F3C 20 20 20 20 20 20 20 20 20 20 2F 2F 20 28 6E 65 78 74 20 70 ..........//.(next.p +00000F50 69 65 63 65 20 63 61 6E 20 6E 6F 74 20 73 74 61 72 74 20 77 iece.can.not.start.w +00000F64 69 74 68 20 61 20 64 69 67 69 74 29 20 20 20 20 20 20 20 20 ith.a.digit)........ +00000F78 20 20 0A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66 ...................f +00000F8C 6F 72 65 61 63 68 20 28 61 3B 20 5F 46 69 6E 64 57 6F 72 64 oreach.(a;._FindWord +00000FA0 73 28 20 6E 75 6D 62 65 72 73 5B 31 2E 2E 24 5D 2C 20 66 61 s(.numbers[1..$],.fa +00000FB4 6C 73 65 20 29 20 29 0A 20 20 20 20 20 20 20 20 20 20 20 20 lse.).)............. +00000FC8 20 20 20 20 20 20 20 20 72 65 74 20 7E 3D 20 6E 75 6D 62 65 ........ret.~=.numbe +00000FDC 72 73 5B 30 2E 2E 31 5D 20 7E 20 22 20 22 20 7E 20 61 3B 0A rs[0..1].~.".".~.a;. +00000FF0 20 20 20 20 20 20 20 20 20 20 20 20 7D 20 20 20 20 0A 20 20 ............}....... +00001004 20 20 20 20 20 20 20 20 20 20 65 6C 73 65 20 20 20 20 0A 20 ..........else...... +00001018 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 20 7E ...............ret.~ +0000102C 3D 20 6E 75 6D 62 65 72 73 5B 30 2E 2E 31 5D 3B 20 20 20 20 =.numbers[0..1];.... +00001040 2F 2F 20 6A 75 73 74 20 61 70 70 65 6E 64 20 74 68 69 73 20 //.just.append.this. +00001054 64 69 67 69 74 20 20 20 20 20 20 20 20 20 20 20 20 20 0A 20 digit............... +00001068 20 20 20 20 20 20 20 7D 20 20 20 20 0A 20 20 20 20 20 20 20 .......}............ +0000107C 20 72 65 74 75 72 6E 20 72 65 74 3B 0A 20 20 20 20 7D 0A 0A .return.ret;.....}.. +00001090 20 20 20 20 2F 2F 2F 20 28 54 68 69 73 20 66 75 6E 63 74 69 ....///.(This.functi +000010A4 6F 6E 20 77 61 73 20 69 6E 6C 69 6E 65 64 20 69 6E 20 74 68 on.was.inlined.in.th +000010B8 65 20 6F 72 69 67 69 6E 61 6C 20 70 72 6F 67 72 61 6D 29 20 e.original.program). +000010CC 0A 20 20 20 20 2F 2F 2F 20 46 69 6E 64 73 20 61 6C 6C 20 61 .....///.Finds.all.a +000010E0 6C 74 65 72 6E 61 74 69 76 65 73 20 66 6F 72 20 74 68 65 20 lternatives.for.the. +000010F4 67 69 76 65 6E 20 70 68 6F 6E 65 20 6E 75 6D 62 65 72 20 0A given.phone.number.. +00001108 20 20 20 20 2F 2F 2F 20 52 65 74 75 72 6E 73 3A 20 61 72 72 ....///.Returns:.arr +0000111C 61 79 20 6F 66 20 73 74 72 69 6E 67 73 20 0A 20 20 20 20 73 ay.of.strings......s +00001130 74 72 69 6E 67 61 72 72 61 79 20 46 69 6E 64 57 6F 72 64 73 tringarray.FindWords +00001144 28 20 73 74 72 69 6E 67 20 70 68 6F 6E 65 5F 6E 75 6D 62 65 (.string.phone_numbe +00001158 72 20 29 0A 20 20 20 20 7B 0A 20 20 20 20 20 20 20 20 69 66 r.).....{.........if +0000116C 20 28 21 70 68 6F 6E 65 5F 6E 75 6D 62 65 72 2E 6C 65 6E 67 .(!phone_number.leng +00001180 74 68 29 0A 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 th).............retu +00001194 72 6E 20 6E 75 6C 6C 3B 0A 20 20 20 20 20 20 20 20 2F 2F 20 rn.null;.........//. +000011A8 53 74 72 69 70 20 74 68 65 20 6E 6F 6E 2D 64 69 67 69 74 20 Strip.the.non-digit. +000011BC 63 68 61 72 61 63 74 65 72 73 20 66 72 6F 6D 20 74 68 65 20 characters.from.the. +000011D0 70 68 6F 6E 65 20 6E 75 6D 62 65 72 2C 20 61 6E 64 0A 20 20 phone.number,.and... +000011E4 20 20 20 20 20 20 2F 2F 20 70 61 73 73 20 69 74 20 74 6F 20 ......//.pass.it.to. +000011F8 74 68 65 20 72 65 63 75 72 73 69 76 65 20 66 75 6E 63 74 69 the.recursive.functi +0000120C 6F 6E 20 28 6C 65 61 64 69 6E 67 20 64 69 67 69 74 20 69 73 on.(leading.digit.is +00001220 20 61 6C 6C 6F 77 65 64 29 0A 20 20 20 20 20 20 20 20 72 65 .allowed).........re +00001234 74 75 72 6E 20 5F 46 69 6E 64 57 6F 72 64 73 28 20 73 74 72 turn._FindWords(.str +00001248 69 70 4E 6F 6E 44 69 67 69 74 28 70 68 6F 6E 65 5F 6E 75 6D ipNonDigit(phone_num +0000125C 62 65 72 29 2C 20 74 72 75 65 20 29 3B 20 20 20 20 0A 20 20 ber),.true.);....... +00001270 20 20 7D 20 20 20 20 0A 20 20 20 20 0A 20 20 20 20 2F 2F 20 ..}..............//. +00001284 52 65 61 64 20 74 68 65 20 70 68 6F 6E 65 20 6E 75 6D 62 65 Read.the.phone.numbe +00001298 72 73 20 20 20 20 20 0A 20 20 20 20 66 6F 72 65 61 63 68 28 rs..........foreach( +000012AC 73 74 72 69 6E 67 20 70 68 6F 6E 65 3B 20 6E 65 77 20 42 75 string.phone;.new.Bu +000012C0 66 66 65 72 65 64 46 69 6C 65 28 22 69 6E 70 75 74 2E 74 78 fferedFile("input.tx +000012D4 74 22 20 20 20 29 20 29 0A 20 20 20 20 20 20 20 20 66 6F 72 t"...).).........for +000012E8 65 61 63 68 28 61 6C 74 65 72 6E 61 74 69 76 65 3B 20 46 69 each(alternative;.Fi +000012FC 6E 64 57 6F 72 64 73 28 20 70 68 6F 6E 65 20 29 20 29 0A 20 ndWords(.phone.).).. +00001310 20 20 20 20 20 20 20 20 20 20 20 77 72 69 74 65 66 6C 6E 28 ...........writefln( +00001324 70 68 6F 6E 65 2C 20 22 3A 20 22 2C 20 61 6C 74 65 72 6E 61 phone,.":.",.alterna +00001338 74 69 76 65 20 29 3B 0A 7D 0A 0A tive.);.}.. diff --git a/tests/examplefiles/hexdump_hexdump b/tests/examplefiles/hexdump_hexdump new file mode 100644 index 00000000..06c2e861 --- /dev/null +++ b/tests/examplefiles/hexdump_hexdump @@ -0,0 +1,310 @@ +0000000 2f2f 4320 6572 7461 6465 6220 2079 694c +0000010 6e6f 6c65 6f6c 4c20 6e75 7365 2075 6e61 +0000020 2064 6c70 6361 6465 6920 206e 6874 2065 +0000030 7570 6c62 6369 6420 6d6f 6961 2e6e 2f0a +0000040 202f 6854 7369 6620 6c69 2065 6168 2073 +0000050 6562 6e65 6d20 646f 6669 6569 2064 7266 +0000060 6d6f 6920 7374 6f20 6972 6967 616e 206c +0000070 6576 7372 6f69 2e6e 2f0a 202f 7449 6820 +0000080 7361 6220 6565 206e 6f66 6d72 7461 6574 +0000090 2064 6f74 6620 7469 7920 756f 2072 6373 +00000a0 6572 6e65 0a2e 6f6d 7564 656c 7020 6f68 +00000b0 656e 6f6e 203b 2020 2020 2f2f 6f20 7470 +00000c0 6f69 616e 0a6c 6d69 6f70 7472 7320 6474 +00000d0 732e 6474 6f69 203b 2020 2f2f 7720 6972 +00000e0 6574 6c66 206e 2020 2020 690a 706d 726f +00000f0 2074 7473 2e64 7463 7079 3b65 2020 2f20 +0000100 202f 7369 6964 6967 2074 2020 2020 690a +0000110 706d 726f 2074 7473 2e64 7473 6572 6d61 +0000120 203b 2f20 202f 7542 6666 7265 6465 6946 +0000130 656c 0a0a 2f2f 4a20 7375 2074 6f66 2072 +0000140 6572 6461 6261 6c69 7469 2079 6928 616d +0000150 6967 656e 6320 6168 5b72 5b5d 5b5d 6863 +0000160 7261 5d5b 295d 2020 2020 610a 696c 7361 +0000170 6320 6168 5b72 205d 7473 6972 676e 0a3b +0000180 6c61 6169 2073 7473 6972 676e 5d5b 7320 +0000190 7274 6e69 6167 7272 7961 0a3b 2f0a 2f2f +00001a0 5320 7274 7069 2073 6f6e 2d6e 6964 6967 +00001b0 2074 6863 7261 6361 6574 7372 6620 6f72 +00001c0 206d 6874 2065 7473 6972 676e 2820 4f43 +00001d0 2957 730a 7274 6e69 2067 7473 6972 4e70 +00001e0 6e6f 6944 6967 2874 6920 206e 7473 6972 +00001f0 676e 6c20 6e69 2065 2029 7b0a 200a 2020 +0000200 7320 7274 6e69 2067 6572 3b74 200a 2020 +0000210 6620 726f 6165 6863 7528 6e69 2074 2c69 +0000220 6320 203b 696c 656e 2029 0a7b 2020 2020 +0000230 2020 2020 2f2f 4520 7272 726f 203a 7473 +0000240 2e64 7463 7079 2e65 7369 6964 6967 2074 +0000250 7461 4320 5c3a 6d64 5c64 7273 5c63 6870 +0000260 626f 736f 735c 6474 635c 7974 6570 642e +0000270 3328 2937 0a20 2020 2020 2020 2020 2f2f +0000280 6320 6e6f 6c66 6369 7374 7720 7469 2068 +0000290 7473 2e64 7473 6572 6d61 692e 6473 6769 +00002a0 7469 6120 2074 3a43 645c 646d 735c 6372 +00002b0 705c 6f68 6f62 5c73 7473 5c64 7473 6572 +00002c0 6d61 642e 3228 3239 2934 200a 2020 2020 +00002d0 2020 6920 2066 2128 7473 2e64 7463 7079 +00002e0 2e65 7369 6964 6967 2874 2963 2029 0a7b +00002f0 2020 2020 2020 2020 2020 2020 6669 2820 +0000300 7221 7465 0a29 2020 2020 2020 2020 2020 +0000310 2020 2020 2020 6572 2074 203d 696c 656e +0000320 305b 2e2e 5d69 203b 2020 0a20 2020 2020 +0000330 2020 2020 207d 2020 0a20 2020 2020 2020 +0000340 2020 6c65 6573 6920 2066 7228 7465 0a29 +0000350 2020 2020 2020 2020 2020 2020 6572 2074 +0000360 3d7e 6320 203b 2020 0a20 2020 2020 207d +0000370 2020 0a20 2020 2020 6572 7574 6e72 7220 +0000380 7465 723f 7465 6c3a 6e69 3b65 7d0a 0a0a +0000390 6e75 7469 6574 7473 7b20 200a 2020 6120 +00003a0 7373 7265 2874 7320 7274 7069 6f4e 446e +00003b0 6769 7469 2228 7361 6664 2922 3d20 203d +00003c0 2222 2020 3b29 200a 2020 6120 7373 7265 +00003d0 2874 7320 7274 7069 6f4e 446e 6769 7469 +00003e0 2228 275c 3331 3d2d 2032 6b34 706f 2922 +00003f0 3d20 203d 2220 3331 3432 2022 2920 0a3b +0000400 0a7d 2f0a 2f2f 4320 6e6f 6576 7472 2073 +0000410 2061 6f77 6472 6920 746e 206f 2061 756e +0000420 626d 7265 202c 6769 6f6e 6972 676e 6120 +0000430 6c6c 6e20 6e6f 6120 706c 6168 6320 6168 +0000440 6172 7463 7265 2073 0a20 7473 6972 676e +0000450 7720 726f 5464 4e6f 6d75 2028 6e69 7320 +0000460 7274 6e69 2067 6f77 6472 2920 7b0a 2f0a +0000470 202f 7274 6e61 6c73 7461 6f69 206e 6174 +0000480 6c62 2065 6f66 2072 6874 2065 6174 6b73 +0000490 6120 2074 6168 646e 630a 6e6f 7473 6320 +00004a0 6168 5b72 3532 5d36 5420 4152 534e 414c +00004b0 4554 3d20 2020 2020 200a 2020 2220 2020 +00004c0 2020 2020 2020 2020 2020 2020 2020 2020 +00004d0 2020 2020 2020 2020 2020 2020 2020 2022 +00004e0 2f20 202f 2030 2020 200a 2020 2220 2020 +00004f0 2020 2020 2020 2020 2020 2020 2020 3130 +0000500 3332 3534 3736 3938 2020 2020 2020 2022 +0000510 2f20 202f 3233 2020 2020 0a20 2020 2020 +0000520 2022 3735 3336 3430 3939 3136 3837 3135 +0000530 3838 3231 3433 3637 3232 3933 2020 2020 +0000540 2220 2020 2f2f 3620 2034 2020 200a 2020 +0000550 2220 3520 3637 3033 3934 3639 3731 3538 +0000560 3831 3138 3332 3734 3236 3332 2039 2020 +0000570 2020 0a22 2020 2020 2022 2020 2020 2020 +0000580 2020 2020 2020 2020 2020 2020 2020 2020 +0000590 2020 2020 2020 2020 2220 200a 2020 2220 +00005a0 2020 2020 2020 2020 2020 2020 2020 2020 +* +00005c0 0a22 2020 2020 2022 2020 2020 2020 2020 +00005d0 2020 2020 2020 2020 2020 2020 2020 2020 +00005e0 2020 2020 2020 2220 2020 2020 200a 2020 +00005f0 2220 2020 2020 2020 2020 2020 2020 2020 +0000600 2020 2020 2020 2020 2020 2020 2020 2020 +0000610 2020 3b22 200a 2020 7320 7274 6e69 2067 +0000620 6572 3b74 200a 2020 6620 726f 6165 6863 +0000630 6328 203b 6163 7473 7528 7962 6574 5d5b +0000640 7729 726f 2964 200a 2020 2020 2020 6920 +0000650 2066 5428 4152 534e 414c 4554 635b 205d +0000660 3d21 2720 2720 0a29 2020 2020 2020 2020 +0000670 2020 2020 6572 2074 3d7e 5420 4152 534e +0000680 414c 4554 635b 3b5d 200a 2020 7220 7465 +0000690 7275 206e 6572 3b74 7d0a 0a0a 6e75 7469 +00006a0 6574 7473 7b20 200a 2f2f 5420 7365 2074 +00006b0 6f77 6472 6f54 754e 206d 7375 6e69 2067 +00006c0 6874 2065 6174 6c62 2065 7266 6d6f 7420 +00006d0 6568 7420 7361 206b 6564 6373 6972 7470 +00006e0 6f69 2e6e 200a 7361 6573 7472 2028 3022 +00006f0 3131 3231 3232 3333 3433 3534 3635 3636 +0000700 3737 3837 3838 3939 2239 3d20 0a3d 2020 +0000710 7720 726f 5464 4e6f 6d75 2228 2045 207c +0000720 204a 204e 2051 207c 2052 2057 2058 207c +0000730 2044 2053 2059 207c 2046 2054 207c 2041 +0000740 204d 207c 2043 2049 2056 207c 2042 204b +0000750 2055 207c 204c 204f 2050 207c 2047 2048 +0000760 225a 2929 0a3b 6120 7373 7265 2874 2220 +0000770 3130 3131 3232 3332 3333 3434 3535 3636 +0000780 3736 3737 3838 3938 3939 2022 3d3d 0a20 +0000790 2020 7720 726f 5464 4e6f 6d75 2228 2065 +00007a0 207c 206a 206e 2071 207c 2072 2077 2078 +00007b0 207c 2064 2073 2079 207c 2066 2074 207c +00007c0 2061 206d 207c 2063 2069 2076 207c 2062 +00007d0 206b 2075 207c 206c 206f 2070 207c 2067 +00007e0 2068 227a 2929 0a3b 6120 7373 7265 2874 +00007f0 2220 3130 3332 3534 3736 3938 2022 3d3d +0000800 0a20 2020 7720 726f 5464 4e6f 6d75 2228 +0000810 2030 207c 2020 2031 2020 207c 2020 2032 +0000820 2020 207c 2020 2033 2020 207c 3420 2020 +0000830 207c 3520 2020 207c 2020 2036 2020 207c +0000840 2020 2037 2020 207c 2020 2038 2020 207c +0000850 2020 2239 2929 0a3b 0a7d 760a 696f 2064 +0000860 616d 6e69 2028 7473 6972 676e 5d5b 6120 +0000870 6772 2073 0a29 0a7b 2020 2020 2f2f 5420 +0000880 6968 2073 7361 6f73 6963 7461 7669 2065 +0000890 7261 6172 2079 616d 7370 6120 6e20 6d75 +00008a0 6562 2072 6f74 6120 206e 7261 6172 2079 +00008b0 666f 7720 726f 7364 202e 2020 0a20 2020 +00008c0 2020 7473 6972 676e 7261 6172 5b79 7473 +00008d0 6972 676e 205d 2020 6e20 6d75 7732 726f +00008e0 7364 0a3b 200a 2020 6620 726f 6165 6863 +00008f0 7328 7274 6e69 2067 6f77 6472 203b 656e +0000900 2077 7542 6666 7265 6465 6946 656c 2228 +0000910 6964 7463 6f69 616e 7972 742e 7478 2022 +0000920 2029 0a29 2020 2020 2020 2020 756e 326d +0000930 6f77 6472 5b73 7720 726f 5464 4e6f 6d75 +0000940 7728 726f 2964 5d20 7e20 203d 6f77 6472 +0000950 642e 7075 203b 2020 2020 2020 2f20 202f +0000960 756d 7473 6420 7075 0a0a 2020 2020 2f2f +0000970 202f 6946 646e 2073 6c61 206c 6c61 6574 +0000980 6e72 7461 7669 7365 6620 726f 7420 6568 +0000990 6720 7669 6e65 6e20 6d75 6562 0a72 2020 +00009a0 2020 2f2f 202f 7328 6f68 6c75 2064 6168 +00009b0 6576 6220 6565 206e 7473 6972 7070 6465 +00009c0 6620 6f72 206d 6f6e 2d6e 6964 6967 2074 +00009d0 6863 7261 6361 6574 7372 0a29 2020 2020 +00009e0 7473 6972 676e 7261 6172 2079 465f 6e69 +00009f0 5764 726f 7364 2028 7473 6972 676e 6e20 +0000a00 6d75 6562 7372 202c 6f62 6c6f 6420 6769 +0000a10 7469 6b6f 2920 200a 2020 6920 206e 0a7b +0000a20 2020 2020 2020 2020 7361 6573 7472 6e28 +0000a30 6d75 6562 7372 6c2e 6e65 7467 2068 203e +0000a40 3020 3b29 2020 2020 200a 2020 7d20 2020 +0000a50 2020 200a 2020 6f20 7475 7228 7365 6c75 +0000a60 2974 7b20 200a 2020 2020 2020 6620 726f +0000a70 6165 6863 2820 3b61 7220 7365 6c75 2974 +0000a80 200a 2020 2020 2020 2020 2020 6120 7373 +0000a90 7265 2874 7720 726f 5464 4e6f 6d75 6128 +0000aa0 2029 3d3d 6e20 6d75 6562 7372 2920 0a3b +0000ab0 2020 2020 207d 2020 0a20 2020 2020 6f62 +0000ac0 7964 7b20 200a 2020 2020 2020 7320 7274 +0000ad0 6e69 6167 7272 7961 7220 7465 0a3b 2020 +0000ae0 2020 2020 2020 6f62 6c6f 6620 756f 646e +0000af0 6f77 6472 3d20 6620 6c61 6573 0a3b 2020 +0000b00 2020 2020 2020 6f66 2072 7528 6e69 2074 +0000b10 3d74 3b31 7420 3d3c 756e 626d 7265 2e73 +0000b20 656c 676e 6874 203b 2b2b 2974 7b20 200a +0000b30 2020 2020 2020 2020 2020 6120 7475 206f +0000b40 6c61 6574 6e72 7461 7669 7365 3d20 6e20 +0000b50 6d75 6562 7372 305b 2e2e 5d74 6920 206e +0000b60 756e 326d 6f77 6472 3b73 200a 2020 2020 +0000b70 2020 2020 2020 6920 2066 2128 6c61 6574 +0000b80 6e72 7461 7669 7365 0a29 2020 2020 2020 +0000b90 2020 2020 2020 2020 2020 6f63 746e 6e69 +0000ba0 6575 0a3b 2020 2020 2020 2020 2020 2020 +0000bb0 6f66 6e75 7764 726f 2064 203d 7274 6575 +0000bc0 0a3b 2020 2020 2020 2020 2020 2020 6669 +0000bd0 2820 756e 626d 7265 2e73 656c 676e 6874 +0000be0 3e20 2020 2974 7b20 200a 2020 2020 2020 +0000bf0 2020 2020 2020 2020 2f20 202f 6f43 626d +0000c00 6e69 2065 6c61 206c 7563 7272 6e65 2074 +0000c10 6c61 6574 6e72 7461 7669 7365 7720 7469 +0000c20 2068 6c61 206c 6c61 6574 6e72 7461 7669 +0000c30 7365 2020 2020 0a20 2020 2020 2020 2020 +0000c40 2020 2020 2020 2020 2f2f 6f20 2066 6874 +0000c50 2065 6572 7473 2820 656e 7478 7020 6569 +0000c60 6563 6320 6e61 7320 6174 7472 7720 7469 +0000c70 2068 2061 6964 6967 2974 2020 2020 2020 +0000c80 2020 2020 2020 2020 200a 2020 2020 2020 +0000c90 2020 2020 2020 2020 6620 726f 6165 6863 +0000ca0 2820 3261 203b 465f 6e69 5764 726f 7364 +0000cb0 2028 756e 626d 7265 5b73 2e74 242e 2c5d +0000cc0 7420 7572 2065 2020 2020 2029 0a29 2020 +0000cd0 2020 2020 2020 2020 2020 2020 2020 2020 +0000ce0 2020 6f66 6572 6361 2868 3161 203b 612a +0000cf0 746c 7265 616e 6974 6576 2973 200a 2020 +0000d00 2020 2020 2020 2020 2020 2020 2020 2020 +0000d10 2020 2020 6572 2074 3d7e 6120 2031 207e +0000d20 2022 2022 207e 3261 0a3b 2020 2020 2020 +0000d30 2020 2020 2020 0a7d 2020 2020 2020 2020 +0000d40 2020 2020 6c65 6573 2020 2020 200a 2020 +0000d50 2020 2020 2020 2020 2020 2020 7220 7465 +0000d60 7e20 203d 612a 746c 7265 616e 6974 6576 +0000d70 3b73 2020 2020 2f2f 6120 7070 6e65 2064 +0000d80 6874 7365 2065 6c61 6574 6e72 7461 7669 +0000d90 7365 200a 2020 2020 2020 7d20 200a 2020 +0000da0 2020 2020 2f20 202f 7254 2079 6f74 6b20 +0000db0 6565 2070 2031 6964 6967 2c74 6f20 6c6e +0000dc0 2079 6669 7720 2765 6572 6120 6c6c 776f +0000dd0 6465 6120 646e 6e20 206f 746f 6568 0a72 +0000de0 2020 2020 2020 2020 2f2f 6120 746c 7265 +0000df0 616e 6974 6576 2073 6577 6572 6620 756f +0000e00 646e 200a 2020 2020 2020 2f20 202f 6554 +0000e10 7473 6e69 2067 7222 7465 6c2e 6e65 7467 +0000e20 2268 6d20 6b61 7365 6d20 726f 2065 6573 +0000e30 736e 2065 6874 6e61 7420 7365 6974 676e +0000e40 2220 6f66 6e75 7764 726f 2264 0a2c 2020 +0000e50 2020 2020 2020 2f2f 6220 7475 7420 6568 +0000e60 6f20 6874 7265 6920 706d 656c 656d 746e +0000e70 7461 6f69 736e 7320 6565 206d 6f74 6420 +0000e80 206f 756a 7473 7420 6968 2e73 200a 2020 +0000e90 2020 2020 6920 2066 6428 6769 7469 6b6f +0000ea0 2620 2026 6621 756f 646e 6f77 6472 2029 +0000eb0 207b 2f2f 6572 2e74 656c 676e 6874 3d20 +0000ec0 203d 2030 0a20 2020 2020 2020 2020 2020 +0000ed0 2020 6669 6e28 6d75 6562 7372 6c2e 6e65 +0000ee0 7467 2068 203e 3120 2029 0a7b 2020 2020 +0000ef0 2020 2020 2020 2020 2020 2020 2f2f 4320 +0000f00 6d6f 6962 656e 3120 6420 6769 7469 7720 +0000f10 7469 2068 6c61 206c 6c61 6574 616e 6974 +0000f20 6576 2073 7266 6d6f 7420 6568 7220 7365 +0000f30 2074 2020 0a20 2020 2020 2020 2020 2020 +0000f40 2020 2020 2020 2f2f 2820 656e 7478 7020 +0000f50 6569 6563 6320 6e61 6e20 746f 7320 6174 +0000f60 7472 7720 7469 2068 2061 6964 6967 2974 +0000f70 2020 2020 2020 2020 2020 200a 2020 2020 +0000f80 2020 2020 2020 2020 2020 6620 726f 6165 +0000f90 6863 2820 3b61 5f20 6946 646e 6f57 6472 +0000fa0 2873 6e20 6d75 6562 7372 315b 2e2e 5d24 +0000fb0 202c 6166 736c 2065 2029 0a29 2020 2020 +0000fc0 2020 2020 2020 2020 2020 2020 2020 2020 +0000fd0 6572 2074 3d7e 6e20 6d75 6562 7372 305b +0000fe0 2e2e 5d31 7e20 2220 2220 7e20 6120 0a3b +0000ff0 2020 2020 2020 2020 2020 2020 207d 2020 +0001000 0a20 2020 2020 2020 2020 2020 2020 6c65 +0001010 6573 2020 2020 200a 2020 2020 2020 2020 +0001020 2020 2020 2020 7220 7465 7e20 203d 756e +0001030 626d 7265 5b73 2e30 312e 3b5d 2020 2020 +0001040 2f2f 6a20 7375 2074 7061 6570 646e 7420 +0001050 6968 2073 6964 6967 2074 2020 2020 2020 +0001060 2020 2020 2020 200a 2020 2020 2020 7d20 +0001070 2020 2020 200a 2020 2020 2020 7220 7465 +0001080 7275 206e 6572 3b74 200a 2020 7d20 0a0a +0001090 2020 2020 2f2f 202f 5428 6968 2073 7566 +00010a0 636e 6974 6e6f 7720 7361 6920 6c6e 6e69 +00010b0 6465 6920 206e 6874 2065 726f 6769 6e69 +00010c0 6c61 7020 6f72 7267 6d61 2029 200a 2020 +00010d0 2f20 2f2f 4620 6e69 7364 6120 6c6c 6120 +00010e0 746c 7265 616e 6974 6576 2073 6f66 2072 +00010f0 6874 2065 6967 6576 206e 6870 6e6f 2065 +0001100 756e 626d 7265 0a20 2020 2020 2f2f 202f +0001110 6552 7574 6e72 3a73 6120 7272 7961 6f20 +0001120 2066 7473 6972 676e 2073 200a 2020 7320 +0001130 7274 6e69 6167 7272 7961 4620 6e69 5764 +0001140 726f 7364 2028 7473 6972 676e 7020 6f68 +0001150 656e 6e5f 6d75 6562 2072 0a29 2020 2020 +0001160 0a7b 2020 2020 2020 2020 6669 2820 7021 +0001170 6f68 656e 6e5f 6d75 6562 2e72 656c 676e +0001180 6874 0a29 2020 2020 2020 2020 2020 2020 +0001190 6572 7574 6e72 6e20 6c75 3b6c 200a 2020 +00011a0 2020 2020 2f20 202f 7453 6972 2070 6874 +00011b0 2065 6f6e 2d6e 6964 6967 2074 6863 7261 +00011c0 6361 6574 7372 6620 6f72 206d 6874 2065 +00011d0 6870 6e6f 2065 756e 626d 7265 202c 6e61 +00011e0 0a64 2020 2020 2020 2020 2f2f 7020 7361 +00011f0 2073 7469 7420 206f 6874 2065 6572 7563 +0001200 7372 7669 2065 7566 636e 6974 6e6f 2820 +0001210 656c 6461 6e69 2067 6964 6967 2074 7369 +0001220 6120 6c6c 776f 6465 0a29 2020 2020 2020 +0001230 2020 6572 7574 6e72 5f20 6946 646e 6f57 +0001240 6472 2873 7320 7274 7069 6f4e 446e 6769 +0001250 7469 7028 6f68 656e 6e5f 6d75 6562 2972 +0001260 202c 7274 6575 2920 203b 2020 0a20 2020 +0001270 2020 207d 2020 0a20 2020 2020 200a 2020 +0001280 2f20 202f 6552 6461 7420 6568 7020 6f68 +0001290 656e 6e20 6d75 6562 7372 2020 2020 0a20 +00012a0 2020 2020 6f66 6572 6361 2868 7473 6972 +00012b0 676e 7020 6f68 656e 203b 656e 2077 7542 +00012c0 6666 7265 6465 6946 656c 2228 6e69 7570 +00012d0 2e74 7874 2274 2020 2920 2920 200a 2020 +00012e0 2020 2020 6620 726f 6165 6863 6128 746c +00012f0 7265 616e 6974 6576 203b 6946 646e 6f57 +0001300 6472 2873 7020 6f68 656e 2920 2920 200a +0001310 2020 2020 2020 2020 2020 7720 6972 6574 +0001320 6c66 286e 6870 6e6f 2c65 2220 203a 2c22 +0001330 6120 746c 7265 616e 6974 6576 2920 0a3b +0001340 0a7d 000a +0001343 diff --git a/tests/examplefiles/hexdump_od b/tests/examplefiles/hexdump_od new file mode 100644 index 00000000..a407aef0 --- /dev/null +++ b/tests/examplefiles/hexdump_od @@ -0,0 +1,310 @@ +0000000 2f 2f 20 43 72 65 61 74 65 64 20 62 79 20 4c 69 >// Created by Li< +0000020 6f 6e 65 6c 6c 6f 20 4c 75 6e 65 73 75 20 61 6e >onello Lunesu an< +0000040 64 20 70 6c 61 63 65 64 20 69 6e 20 74 68 65 20 >d placed in the < +0000060 70 75 62 6c 69 63 20 64 6f 6d 61 69 6e 2e 0a 2f >public domain../< +0000100 2f 20 54 68 69 73 20 66 69 6c 65 20 68 61 73 20 >/ This file has < +0000120 62 65 65 6e 20 6d 6f 64 69 66 69 65 64 20 66 72 >been modified fr< +0000140 6f 6d 20 69 74 73 20 6f 72 69 67 69 6e 61 6c 20 >om its original < +0000160 76 65 72 73 69 6f 6e 2e 0a 2f 2f 20 49 74 20 68 >version..// It h< +0000200 61 73 20 62 65 65 6e 20 66 6f 72 6d 61 74 74 65 >as been formatte< +0000220 64 20 74 6f 20 66 69 74 20 79 6f 75 72 20 73 63 >d to fit your sc< +0000240 72 65 65 6e 2e 0a 6d 6f 64 75 6c 65 20 70 68 6f >reen..module pho< +0000260 6e 65 6e 6f 3b 20 20 20 20 20 2f 2f 20 6f 70 74 >neno; // opt< +0000300 69 6f 6e 61 6c 0a 69 6d 70 6f 72 74 20 73 74 64 >ional.import std< +0000320 2e 73 74 64 69 6f 3b 20 20 20 2f 2f 20 77 72 69 >.stdio; // wri< +0000340 74 65 66 6c 6e 20 20 20 20 20 0a 69 6d 70 6f 72 >tefln .impor< +0000360 74 20 73 74 64 2e 63 74 79 70 65 3b 20 20 20 2f >t std.ctype; /< +0000400 2f 20 69 73 64 69 67 69 74 20 20 20 20 20 0a 69 >/ isdigit .i< +0000420 6d 70 6f 72 74 20 73 74 64 2e 73 74 72 65 61 6d >mport std.stream< +0000440 3b 20 20 2f 2f 20 42 75 66 66 65 72 65 64 46 69 >; // BufferedFi< +0000460 6c 65 0a 0a 2f 2f 20 4a 75 73 74 20 66 6f 72 20 >le..// Just for < +0000500 72 65 61 64 61 62 69 6c 69 74 79 20 28 69 6d 61 >readability (ima< +0000520 67 69 6e 65 20 63 68 61 72 5b 5d 5b 5d 5b 63 68 >gine char[][][ch< +0000540 61 72 5b 5d 5d 29 20 20 20 20 0a 61 6c 69 61 73 >ar[]]) .alias< +0000560 20 63 68 61 72 5b 5d 20 73 74 72 69 6e 67 3b 0a > char[] string;.< +0000600 61 6c 69 61 73 20 73 74 72 69 6e 67 5b 5d 20 73 >alias string[] s< +0000620 74 72 69 6e 67 61 72 72 61 79 3b 0a 0a 2f 2f 2f >tringarray;..///< +0000640 20 53 74 72 69 70 73 20 6e 6f 6e 2d 64 69 67 69 > Strips non-digi< +0000660 74 20 63 68 61 72 61 63 74 65 72 73 20 66 72 6f >t characters fro< +0000700 6d 20 74 68 65 20 73 74 72 69 6e 67 20 28 43 4f >m the string (CO< +0000720 57 29 0a 73 74 72 69 6e 67 20 73 74 72 69 70 4e >W).string stripN< +0000740 6f 6e 44 69 67 69 74 28 20 69 6e 20 73 74 72 69 >onDigit( in stri< +0000760 6e 67 20 6c 69 6e 65 20 29 20 0a 7b 0a 20 20 20 >ng line ) .{. < +0001000 20 73 74 72 69 6e 67 20 72 65 74 3b 0a 20 20 20 > string ret;. < +0001020 20 66 6f 72 65 61 63 68 28 75 69 6e 74 20 69 2c > foreach(uint i,< +0001040 20 63 3b 20 6c 69 6e 65 29 20 7b 0a 20 20 20 20 > c; line) {. < +0001060 20 20 20 20 2f 2f 20 45 72 72 6f 72 3a 20 73 74 > // Error: st< +0001100 64 2e 63 74 79 70 65 2e 69 73 64 69 67 69 74 20 >d.ctype.isdigit < +0001120 61 74 20 43 3a 5c 64 6d 64 5c 73 72 63 5c 70 68 >at C:\dmd\src\ph< +0001140 6f 62 6f 73 5c 73 74 64 5c 63 74 79 70 65 2e 64 >obos\std\ctype.d< +0001160 28 33 37 29 20 0a 20 20 20 20 20 20 20 20 2f 2f >(37) . //< +0001200 20 63 6f 6e 66 6c 69 63 74 73 20 77 69 74 68 20 > conflicts with < +0001220 73 74 64 2e 73 74 72 65 61 6d 2e 69 73 64 69 67 >std.stream.isdig< +0001240 69 74 20 61 74 20 43 3a 5c 64 6d 64 5c 73 72 63 >it at C:\dmd\src< +0001260 5c 70 68 6f 62 6f 73 5c 73 74 64 5c 73 74 72 65 >\phobos\std\stre< +0001300 61 6d 2e 64 28 32 39 32 34 29 0a 20 20 20 20 20 >am.d(2924). < +0001320 20 20 20 69 66 20 28 21 73 74 64 2e 63 74 79 70 > if (!std.ctyp< +0001340 65 2e 69 73 64 69 67 69 74 28 63 29 29 20 7b 0a >e.isdigit(c)) {.< +0001360 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 > if (< +0001400 21 72 65 74 29 0a 20 20 20 20 20 20 20 20 20 20 >!ret). < +0001420 20 20 20 20 20 20 72 65 74 20 3d 20 6c 69 6e 65 > ret = line< +0001440 5b 30 2e 2e 69 5d 3b 20 20 20 20 0a 20 20 20 20 >[0..i]; . < +0001460 20 20 20 20 7d 20 20 20 20 0a 20 20 20 20 20 20 > } . < +0001500 20 20 65 6c 73 65 20 69 66 20 28 72 65 74 29 0a > else if (ret).< +0001520 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 20 > ret < +0001540 7e 3d 20 63 3b 20 20 20 20 0a 20 20 20 20 7d 20 >~= c; . } < +0001560 20 20 20 0a 20 20 20 20 72 65 74 75 72 6e 20 72 > . return r< +0001600 65 74 3f 72 65 74 3a 6c 69 6e 65 3b 0a 7d 0a 0a >et?ret:line;.}..< +0001620 75 6e 69 74 74 65 73 74 20 7b 0a 20 20 20 20 61 >unittest {. a< +0001640 73 73 65 72 74 28 20 73 74 72 69 70 4e 6f 6e 44 >ssert( stripNonD< +0001660 69 67 69 74 28 22 61 73 64 66 22 29 20 3d 3d 20 >igit("asdf") == < +0001700 22 22 20 20 29 3b 0a 20 20 20 20 61 73 73 65 72 >"" );. asser< +0001720 74 28 20 73 74 72 69 70 4e 6f 6e 44 69 67 69 74 >t( stripNonDigit< +0001740 28 22 5c 27 31 33 2d 3d 32 20 34 6b 6f 70 22 29 >("\'13-=2 4kop")< +0001760 20 3d 3d 20 20 22 31 33 32 34 22 20 20 29 3b 0a > == "1324" );.< +0002000 7d 0a 0a 2f 2f 2f 20 43 6f 6e 76 65 72 74 73 20 >}../// Converts < +0002020 61 20 77 6f 72 64 20 69 6e 74 6f 20 61 20 6e 75 >a word into a nu< +0002040 6d 62 65 72 2c 20 69 67 6e 6f 72 69 6e 67 20 61 >mber, ignoring a< +0002060 6c 6c 20 6e 6f 6e 20 61 6c 70 68 61 20 63 68 61 >ll non alpha cha< +0002100 72 61 63 74 65 72 73 20 20 0a 73 74 72 69 6e 67 >racters .string< +0002120 20 77 6f 72 64 54 6f 4e 75 6d 28 20 69 6e 20 73 > wordToNum( in s< +0002140 74 72 69 6e 67 20 77 6f 72 64 20 29 0a 7b 0a 2f >tring word ).{./< +0002160 2f 20 74 72 61 6e 73 6c 61 74 69 6f 6e 20 74 61 >/ translation ta< +0002200 62 6c 65 20 66 6f 72 20 74 68 65 20 74 61 73 6b >ble for the task< +0002220 20 61 74 20 68 61 6e 64 0a 63 6f 6e 73 74 20 63 > at hand.const c< +0002240 68 61 72 5b 32 35 36 5d 20 54 52 41 4e 53 4c 41 >har[256] TRANSLA< +0002260 54 45 20 3d 20 20 20 20 0a 20 20 20 20 22 20 20 >TE = . " < +0002300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0002320 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 > " < +0002340 20 2f 2f 20 30 20 20 20 0a 20 20 20 20 22 20 20 > // 0 . " < +0002360 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 31 > 01< +0002400 32 33 34 35 36 37 38 39 20 20 20 20 20 20 22 20 >23456789 " < +0002420 20 2f 2f 20 33 32 20 20 20 20 20 0a 20 20 20 20 > // 32 . < +0002440 22 20 35 37 36 33 30 34 39 39 36 31 37 38 35 31 >" 57630499617851< +0002460 38 38 31 32 33 34 37 36 32 32 33 39 20 20 20 20 >881234762239 < +0002500 20 22 20 20 2f 2f 20 36 34 20 20 20 0a 20 20 20 > " // 64 . < +0002520 20 22 20 35 37 36 33 30 34 39 39 36 31 37 38 35 > " 5763049961785< +0002540 31 38 38 31 32 33 34 37 36 32 32 33 39 20 20 20 >1881234762239 < +0002560 20 20 22 0a 20 20 20 20 22 20 20 20 20 20 20 20 > ". " < +0002600 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0002620 20 20 20 20 20 20 20 20 20 22 0a 20 20 20 20 22 > ". "< +0002640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +* +0002700 22 0a 20 20 20 20 22 20 20 20 20 20 20 20 20 20 >". " < +0002720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0002740 20 20 20 20 20 20 20 22 20 20 20 20 0a 20 20 20 > " . < +0002760 20 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > " < +0003000 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0003020 20 20 22 3b 0a 20 20 20 20 73 74 72 69 6e 67 20 > ";. string < +0003040 72 65 74 3b 0a 20 20 20 20 66 6f 72 65 61 63 68 >ret;. foreach< +0003060 28 63 3b 20 63 61 73 74 28 75 62 79 74 65 5b 5d >(c; cast(ubyte[]< +0003100 29 77 6f 72 64 29 0a 20 20 20 20 20 20 20 20 69 >)word). i< +0003120 66 20 28 54 52 41 4e 53 4c 41 54 45 5b 63 5d 20 >f (TRANSLATE[c] < +0003140 21 3d 20 27 20 27 29 0a 20 20 20 20 20 20 20 20 >!= ' '). < +0003160 20 20 20 20 72 65 74 20 7e 3d 20 54 52 41 4e 53 > ret ~= TRANS< +0003200 4c 41 54 45 5b 63 5d 3b 0a 20 20 20 20 72 65 74 >LATE[c];. ret< +0003220 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 75 6e 69 74 >urn ret;.}..unit< +0003240 74 65 73 74 20 7b 0a 20 2f 2f 20 54 65 73 74 20 >test {. // Test < +0003260 77 6f 72 64 54 6f 4e 75 6d 20 75 73 69 6e 67 20 >wordToNum using < +0003300 74 68 65 20 74 61 62 6c 65 20 66 72 6f 6d 20 74 >the table from t< +0003320 68 65 20 74 61 73 6b 20 64 65 73 63 72 69 70 74 >he task descript< +0003340 69 6f 6e 2e 0a 20 61 73 73 65 72 74 28 20 22 30 >ion.. assert( "0< +0003360 31 31 31 32 32 32 33 33 33 34 34 35 35 36 36 36 >1112223334455666< +0003400 37 37 37 38 38 38 39 39 39 22 20 3d 3d 0a 20 20 >777888999" ==. < +0003420 20 77 6f 72 64 54 6f 4e 75 6d 28 22 45 20 7c 20 > wordToNum("E | < +0003440 4a 20 4e 20 51 20 7c 20 52 20 57 20 58 20 7c 20 >J N Q | R W X | < +0003460 44 20 53 20 59 20 7c 20 46 20 54 20 7c 20 41 20 >D S Y | F T | A < +0003500 4d 20 7c 20 43 20 49 20 56 20 7c 20 42 20 4b 20 >M | C I V | B K < +0003520 55 20 7c 20 4c 20 4f 20 50 20 7c 20 47 20 48 20 >U | L O P | G H < +0003540 5a 22 29 29 3b 0a 20 61 73 73 65 72 74 28 20 22 >Z"));. assert( "< +0003560 30 31 31 31 32 32 32 33 33 33 34 34 35 35 36 36 >0111222333445566< +0003600 36 37 37 37 38 38 38 39 39 39 22 20 3d 3d 20 0a >6777888999" == .< +0003620 20 20 20 77 6f 72 64 54 6f 4e 75 6d 28 22 65 20 > wordToNum("e < +0003640 7c 20 6a 20 6e 20 71 20 7c 20 72 20 77 20 78 20 >| j n q | r w x < +0003660 7c 20 64 20 73 20 79 20 7c 20 66 20 74 20 7c 20 >| d s y | f t | < +0003700 61 20 6d 20 7c 20 63 20 69 20 76 20 7c 20 62 20 >a m | c i v | b < +0003720 6b 20 75 20 7c 20 6c 20 6f 20 70 20 7c 20 67 20 >k u | l o p | g < +0003740 68 20 7a 22 29 29 3b 0a 20 61 73 73 65 72 74 28 >h z"));. assert(< +0003760 20 22 30 31 32 33 34 35 36 37 38 39 22 20 3d 3d > "0123456789" ==< +0004000 20 0a 20 20 20 77 6f 72 64 54 6f 4e 75 6d 28 22 > . wordToNum("< +0004020 30 20 7c 20 20 20 31 20 20 20 7c 20 20 20 32 20 >0 | 1 | 2 < +0004040 20 20 7c 20 20 20 33 20 20 20 7c 20 20 34 20 20 > | 3 | 4 < +0004060 7c 20 20 35 20 20 7c 20 20 20 36 20 20 20 7c 20 >| 5 | 6 | < +0004100 20 20 37 20 20 20 7c 20 20 20 38 20 20 20 7c 20 > 7 | 8 | < +0004120 20 20 39 22 29 29 3b 0a 7d 0a 0a 76 6f 69 64 20 > 9"));.}..void < +0004140 6d 61 69 6e 28 20 73 74 72 69 6e 67 5b 5d 20 61 >main( string[] a< +0004160 72 67 73 20 29 0a 7b 0a 20 20 20 20 2f 2f 20 54 >rgs ).{. // T< +0004200 68 69 73 20 61 73 73 6f 63 69 61 74 69 76 65 20 >his associative < +0004220 61 72 72 61 79 20 6d 61 70 73 20 61 20 6e 75 6d >array maps a num< +0004240 62 65 72 20 74 6f 20 61 6e 20 61 72 72 61 79 20 >ber to an array < +0004260 6f 66 20 77 6f 72 64 73 2e 20 20 20 20 0a 20 20 >of words. . < +0004300 20 20 73 74 72 69 6e 67 61 72 72 61 79 5b 73 74 > stringarray[st< +0004320 72 69 6e 67 5d 20 20 20 20 6e 75 6d 32 77 6f 72 >ring] num2wor< +0004340 64 73 3b 0a 0a 20 20 20 20 66 6f 72 65 61 63 68 >ds;.. foreach< +0004360 28 73 74 72 69 6e 67 20 77 6f 72 64 3b 20 6e 65 >(string word; ne< +0004400 77 20 42 75 66 66 65 72 65 64 46 69 6c 65 28 22 >w BufferedFile("< +0004420 64 69 63 74 69 6f 6e 61 72 79 2e 74 78 74 22 20 >dictionary.txt" < +0004440 29 20 29 0a 20 20 20 20 20 20 20 20 6e 75 6d 32 >) ). num2< +0004460 77 6f 72 64 73 5b 20 77 6f 72 64 54 6f 4e 75 6d >words[ wordToNum< +0004500 28 77 6f 72 64 29 20 5d 20 7e 3d 20 77 6f 72 64 >(word) ] ~= word< +0004520 2e 64 75 70 3b 20 20 20 20 20 20 20 20 2f 2f 20 >.dup; // < +0004540 6d 75 73 74 20 64 75 70 0a 0a 20 20 20 20 2f 2f >must dup.. //< +0004560 2f 20 46 69 6e 64 73 20 61 6c 6c 20 61 6c 74 65 >/ Finds all alte< +0004600 72 6e 61 74 69 76 65 73 20 66 6f 72 20 74 68 65 >rnatives for the< +0004620 20 67 69 76 65 6e 20 6e 75 6d 62 65 72 0a 20 20 > given number. < +0004640 20 20 2f 2f 2f 20 28 73 68 6f 75 6c 64 20 68 61 > /// (should ha< +0004660 76 65 20 62 65 65 6e 20 73 74 72 69 70 70 65 64 >ve been stripped< +0004700 20 66 72 6f 6d 20 6e 6f 6e 2d 64 69 67 69 74 20 > from non-digit < +0004720 63 68 61 72 61 63 74 65 72 73 29 0a 20 20 20 20 >characters). < +0004740 73 74 72 69 6e 67 61 72 72 61 79 20 5f 46 69 6e >stringarray _Fin< +0004760 64 57 6f 72 64 73 28 20 73 74 72 69 6e 67 20 6e >dWords( string n< +0005000 75 6d 62 65 72 73 2c 20 62 6f 6f 6c 20 64 69 67 >umbers, bool dig< +0005020 69 74 6f 6b 20 29 0a 20 20 20 20 69 6e 20 7b 0a >itok ). in {.< +0005040 20 20 20 20 20 20 20 20 61 73 73 65 72 74 28 6e > assert(n< +0005060 75 6d 62 65 72 73 2e 6c 65 6e 67 74 68 20 3e 20 >umbers.length > < +0005100 20 30 29 3b 20 20 20 20 0a 20 20 20 20 7d 20 20 > 0); . } < +0005120 20 20 0a 20 20 20 20 6f 75 74 28 72 65 73 75 6c > . out(resul< +0005140 74 29 20 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 >t) {. for< +0005160 65 61 63 68 20 28 61 3b 20 72 65 73 75 6c 74 29 >each (a; result)< +0005200 0a 20 20 20 20 20 20 20 20 20 20 20 20 61 73 73 >. ass< +0005220 65 72 74 28 20 77 6f 72 64 54 6f 4e 75 6d 28 61 >ert( wordToNum(a< +0005240 29 20 3d 3d 20 6e 75 6d 62 65 72 73 20 29 3b 0a >) == numbers );.< +0005260 20 20 20 20 7d 20 20 20 20 0a 20 20 20 20 62 6f > } . bo< +0005300 64 79 20 7b 0a 20 20 20 20 20 20 20 20 73 74 72 >dy {. str< +0005320 69 6e 67 61 72 72 61 79 20 72 65 74 3b 0a 20 20 >ingarray ret;. < +0005340 20 20 20 20 20 20 62 6f 6f 6c 20 66 6f 75 6e 64 > bool found< +0005360 77 6f 72 64 20 3d 20 66 61 6c 73 65 3b 0a 20 20 >word = false;. < +0005400 20 20 20 20 20 20 66 6f 72 20 28 75 69 6e 74 20 > for (uint < +0005420 74 3d 31 3b 20 74 3c 3d 6e 75 6d 62 65 72 73 2e >t=1; t<=numbers.< +0005440 6c 65 6e 67 74 68 3b 20 2b 2b 74 29 20 7b 0a 20 >length; ++t) {. < +0005460 20 20 20 20 20 20 20 20 20 20 20 61 75 74 6f 20 > auto < +0005500 61 6c 74 65 72 6e 61 74 69 76 65 73 20 3d 20 6e >alternatives = n< +0005520 75 6d 62 65 72 73 5b 30 2e 2e 74 5d 20 69 6e 20 >umbers[0..t] in < +0005540 6e 75 6d 32 77 6f 72 64 73 3b 0a 20 20 20 20 20 >num2words;. < +0005560 20 20 20 20 20 20 20 69 66 20 28 21 61 6c 74 65 > if (!alte< +0005600 72 6e 61 74 69 76 65 73 29 0a 20 20 20 20 20 20 >rnatives). < +0005620 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e > contin< +0005640 75 65 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 >ue;. < +0005660 66 6f 75 6e 64 77 6f 72 64 20 3d 20 74 72 75 65 >foundword = true< +0005700 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 >;. if< +0005720 20 28 6e 75 6d 62 65 72 73 2e 6c 65 6e 67 74 68 > (numbers.length< +0005740 20 3e 20 20 74 29 20 7b 0a 20 20 20 20 20 20 20 > > t) {. < +0005760 20 20 20 20 20 20 20 20 20 2f 2f 20 43 6f 6d 62 > // Comb< +0006000 69 6e 65 20 61 6c 6c 20 63 75 72 72 65 6e 74 20 >ine all current < +0006020 61 6c 74 65 72 6e 61 74 69 76 65 73 20 77 69 74 >alternatives wit< +0006040 68 20 61 6c 6c 20 61 6c 74 65 72 6e 61 74 69 76 >h all alternativ< +0006060 65 73 20 20 20 20 20 0a 20 20 20 20 20 20 20 20 >es . < +0006100 20 20 20 20 20 20 20 20 2f 2f 20 6f 66 20 74 68 > // of th< +0006120 65 20 72 65 73 74 20 28 6e 65 78 74 20 70 69 65 >e rest (next pie< +0006140 63 65 20 63 61 6e 20 73 74 61 72 74 20 77 69 74 >ce can start wit< +0006160 68 20 61 20 64 69 67 69 74 29 20 20 20 20 20 20 >h a digit) < +0006200 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 20 20 > . < +0006220 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 63 68 > foreach< +0006240 20 28 61 32 3b 20 5f 46 69 6e 64 57 6f 72 64 73 > (a2; _FindWords< +0006260 28 20 6e 75 6d 62 65 72 73 5b 74 2e 2e 24 5d 2c >( numbers[t..$],< +0006300 20 74 72 75 65 20 20 20 20 20 29 20 29 0a 20 20 > true ) ). < +0006320 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0006340 20 20 66 6f 72 65 61 63 68 28 61 31 3b 20 2a 61 > foreach(a1; *a< +0006360 6c 74 65 72 6e 61 74 69 76 65 73 29 0a 20 20 20 >lternatives). < +0006400 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0006420 20 20 20 20 72 65 74 20 7e 3d 20 61 31 20 7e 20 > ret ~= a1 ~ < +0006440 22 20 22 20 7e 20 61 32 3b 0a 20 20 20 20 20 20 >" " ~ a2;. < +0006460 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 > }. < +0006500 20 20 20 20 65 6c 73 65 20 20 20 20 0a 20 20 20 > else . < +0006520 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 > ret< +0006540 20 7e 3d 20 2a 61 6c 74 65 72 6e 61 74 69 76 65 > ~= *alternative< +0006560 73 3b 20 20 20 20 2f 2f 20 61 70 70 65 6e 64 20 >s; // append < +0006600 74 68 65 73 65 20 61 6c 74 65 72 6e 61 74 69 76 >these alternativ< +0006620 65 73 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 >es. }. < +0006640 20 20 20 20 20 2f 2f 20 54 72 79 20 74 6f 20 6b > // Try to k< +0006660 65 65 70 20 31 20 64 69 67 69 74 2c 20 6f 6e 6c >eep 1 digit, onl< +0006700 79 20 69 66 20 77 65 27 72 65 20 61 6c 6c 6f 77 >y if we're allow< +0006720 65 64 20 61 6e 64 20 6e 6f 20 6f 74 68 65 72 0a >ed and no other.< +0006740 20 20 20 20 20 20 20 20 2f 2f 20 61 6c 74 65 72 > // alter< +0006760 6e 61 74 69 76 65 73 20 77 65 72 65 20 66 6f 75 >natives were fou< +0007000 6e 64 0a 20 20 20 20 20 20 20 20 2f 2f 20 54 65 >nd. // Te< +0007020 73 74 69 6e 67 20 22 72 65 74 2e 6c 65 6e 67 74 >sting "ret.lengt< +0007040 68 22 20 6d 61 6b 65 73 20 6d 6f 72 65 20 73 65 >h" makes more se< +0007060 6e 73 65 20 74 68 61 6e 20 74 65 73 74 69 6e 67 >nse than testing< +0007100 20 22 66 6f 75 6e 64 77 6f 72 64 22 2c 0a 20 20 > "foundword",. < +0007120 20 20 20 20 20 20 2f 2f 20 62 75 74 20 74 68 65 > // but the< +0007140 20 6f 74 68 65 72 20 69 6d 70 6c 65 6d 65 6e 74 > other implement< +0007160 61 74 69 6f 6e 73 20 73 65 65 6d 20 74 6f 20 64 >ations seem to d< +0007200 6f 20 6a 75 73 74 20 74 68 69 73 2e 0a 20 20 20 >o just this.. < +0007220 20 20 20 20 20 69 66 20 28 64 69 67 69 74 6f 6b > if (digitok< +0007240 20 26 26 20 21 66 6f 75 6e 64 77 6f 72 64 29 20 > && !foundword) < +0007260 7b 20 2f 2f 72 65 74 2e 6c 65 6e 67 74 68 20 3d >{ //ret.length =< +0007300 3d 20 30 20 20 0a 20 20 20 20 20 20 20 20 20 20 >= 0 . < +0007320 20 20 69 66 28 6e 75 6d 62 65 72 73 2e 6c 65 6e > if(numbers.len< +0007340 67 74 68 20 3e 20 20 31 29 20 7b 0a 20 20 20 20 >gth > 1) {. < +0007360 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 43 > // C< +0007400 6f 6d 62 69 6e 65 20 31 20 64 69 67 69 74 20 77 >ombine 1 digit w< +0007420 69 74 68 20 61 6c 6c 20 61 6c 74 65 6e 61 74 69 >ith all altenati< +0007440 76 65 73 20 66 72 6f 6d 20 74 68 65 20 72 65 73 >ves from the res< +0007460 74 20 20 20 20 0a 20 20 20 20 20 20 20 20 20 20 >t . < +0007500 20 20 20 20 20 20 2f 2f 20 28 6e 65 78 74 20 70 > // (next p< +0007520 69 65 63 65 20 63 61 6e 20 6e 6f 74 20 73 74 61 >iece can not sta< +0007540 72 74 20 77 69 74 68 20 61 20 64 69 67 69 74 29 >rt with a digit)< +0007560 20 20 20 20 20 20 20 20 20 20 0a 20 20 20 20 20 > . < +0007600 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 65 61 > forea< +0007620 63 68 20 28 61 3b 20 5f 46 69 6e 64 57 6f 72 64 >ch (a; _FindWord< +0007640 73 28 20 6e 75 6d 62 65 72 73 5b 31 2e 2e 24 5d >s( numbers[1..$]< +0007660 2c 20 66 61 6c 73 65 20 29 20 29 0a 20 20 20 20 >, false ) ). < +0007700 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 > < +0007720 72 65 74 20 7e 3d 20 6e 75 6d 62 65 72 73 5b 30 >ret ~= numbers[0< +0007740 2e 2e 31 5d 20 7e 20 22 20 22 20 7e 20 61 3b 0a >..1] ~ " " ~ a;.< +0007760 20 20 20 20 20 20 20 20 20 20 20 20 7d 20 20 20 > } < +0010000 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 65 6c > . el< +0010020 73 65 20 20 20 20 0a 20 20 20 20 20 20 20 20 20 >se . < +0010040 20 20 20 20 20 20 20 72 65 74 20 7e 3d 20 6e 75 > ret ~= nu< +0010060 6d 62 65 72 73 5b 30 2e 2e 31 5d 3b 20 20 20 20 >mbers[0..1]; < +0010100 2f 2f 20 6a 75 73 74 20 61 70 70 65 6e 64 20 74 >// just append t< +0010120 68 69 73 20 64 69 67 69 74 20 20 20 20 20 20 20 >his digit < +0010140 20 20 20 20 20 20 0a 20 20 20 20 20 20 20 20 7d > . }< +0010160 20 20 20 20 0a 20 20 20 20 20 20 20 20 72 65 74 > . ret< +0010200 75 72 6e 20 72 65 74 3b 0a 20 20 20 20 7d 0a 0a >urn ret;. }..< +0010220 20 20 20 20 2f 2f 2f 20 28 54 68 69 73 20 66 75 > /// (This fu< +0010240 6e 63 74 69 6f 6e 20 77 61 73 20 69 6e 6c 69 6e >nction was inlin< +0010260 65 64 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e >ed in the origin< +0010300 61 6c 20 70 72 6f 67 72 61 6d 29 20 0a 20 20 20 >al program) . < +0010320 20 2f 2f 2f 20 46 69 6e 64 73 20 61 6c 6c 20 61 > /// Finds all a< +0010340 6c 74 65 72 6e 61 74 69 76 65 73 20 66 6f 72 20 >lternatives for < +0010360 74 68 65 20 67 69 76 65 6e 20 70 68 6f 6e 65 20 >the given phone < +0010400 6e 75 6d 62 65 72 20 0a 20 20 20 20 2f 2f 2f 20 >number . /// < +0010420 52 65 74 75 72 6e 73 3a 20 61 72 72 61 79 20 6f >Returns: array o< +0010440 66 20 73 74 72 69 6e 67 73 20 0a 20 20 20 20 73 >f strings . s< +0010460 74 72 69 6e 67 61 72 72 61 79 20 46 69 6e 64 57 >tringarray FindW< +0010500 6f 72 64 73 28 20 73 74 72 69 6e 67 20 70 68 6f >ords( string pho< +0010520 6e 65 5f 6e 75 6d 62 65 72 20 29 0a 20 20 20 20 >ne_number ). < +0010540 7b 0a 20 20 20 20 20 20 20 20 69 66 20 28 21 70 >{. if (!p< +0010560 68 6f 6e 65 5f 6e 75 6d 62 65 72 2e 6c 65 6e 67 >hone_number.leng< +0010600 74 68 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 >th). < +0010620 72 65 74 75 72 6e 20 6e 75 6c 6c 3b 0a 20 20 20 >return null;. < +0010640 20 20 20 20 20 2f 2f 20 53 74 72 69 70 20 74 68 > // Strip th< +0010660 65 20 6e 6f 6e 2d 64 69 67 69 74 20 63 68 61 72 >e non-digit char< +0010700 61 63 74 65 72 73 20 66 72 6f 6d 20 74 68 65 20 >acters from the < +0010720 70 68 6f 6e 65 20 6e 75 6d 62 65 72 2c 20 61 6e >phone number, an< +0010740 64 0a 20 20 20 20 20 20 20 20 2f 2f 20 70 61 73 >d. // pas< +0010760 73 20 69 74 20 74 6f 20 74 68 65 20 72 65 63 75 >s it to the recu< +0011000 72 73 69 76 65 20 66 75 6e 63 74 69 6f 6e 20 28 >rsive function (< +0011020 6c 65 61 64 69 6e 67 20 64 69 67 69 74 20 69 73 >leading digit is< +0011040 20 61 6c 6c 6f 77 65 64 29 0a 20 20 20 20 20 20 > allowed). < +0011060 20 20 72 65 74 75 72 6e 20 5f 46 69 6e 64 57 6f > return _FindWo< +0011100 72 64 73 28 20 73 74 72 69 70 4e 6f 6e 44 69 67 >rds( stripNonDig< +0011120 69 74 28 70 68 6f 6e 65 5f 6e 75 6d 62 65 72 29 >it(phone_number)< +0011140 2c 20 74 72 75 65 20 29 3b 20 20 20 20 0a 20 20 >, true ); . < +0011160 20 20 7d 20 20 20 20 0a 20 20 20 20 0a 20 20 20 > } . . < +0011200 20 2f 2f 20 52 65 61 64 20 74 68 65 20 70 68 6f > // Read the pho< +0011220 6e 65 20 6e 75 6d 62 65 72 73 20 20 20 20 20 0a >ne numbers .< +0011240 20 20 20 20 66 6f 72 65 61 63 68 28 73 74 72 69 > foreach(stri< +0011260 6e 67 20 70 68 6f 6e 65 3b 20 6e 65 77 20 42 75 >ng phone; new Bu< +0011300 66 66 65 72 65 64 46 69 6c 65 28 22 69 6e 70 75 >fferedFile("inpu< +0011320 74 2e 74 78 74 22 20 20 20 29 20 29 0a 20 20 20 >t.txt" ) ). < +0011340 20 20 20 20 20 66 6f 72 65 61 63 68 28 61 6c 74 > foreach(alt< +0011360 65 72 6e 61 74 69 76 65 3b 20 46 69 6e 64 57 6f >ernative; FindWo< +0011400 72 64 73 28 20 70 68 6f 6e 65 20 29 20 29 0a 20 >rds( phone ) ). < +0011420 20 20 20 20 20 20 20 20 20 20 20 77 72 69 74 65 > write< +0011440 66 6c 6e 28 70 68 6f 6e 65 2c 20 22 3a 20 22 2c >fln(phone, ": ",< +0011460 20 61 6c 74 65 72 6e 61 74 69 76 65 20 29 3b 0a > alternative );.< +0011500 7d 0a 0a >}..< +0011503 diff --git a/tests/examplefiles/hexdump_xxd b/tests/examplefiles/hexdump_xxd new file mode 100644 index 00000000..33a8a6e1 --- /dev/null +++ b/tests/examplefiles/hexdump_xxd @@ -0,0 +1,309 @@ +0000000: 2f2f 2043 7265 6174 6564 2062 7920 4c69 // Created by Li +0000010: 6f6e 656c 6c6f 204c 756e 6573 7520 616e onello Lunesu an +0000020: 6420 706c 6163 6564 2069 6e20 7468 6520 d placed in the +0000030: 7075 626c 6963 2064 6f6d 6169 6e2e 0a2f public domain../ +0000040: 2f20 5468 6973 2066 696c 6520 6861 7320 / This file has +0000050: 6265 656e 206d 6f64 6966 6965 6420 6672 been modified fr +0000060: 6f6d 2069 7473 206f 7269 6769 6e61 6c20 om its original +0000070: 7665 7273 696f 6e2e 0a2f 2f20 4974 2068 version..// It h +0000080: 6173 2062 6565 6e20 666f 726d 6174 7465 as been formatte +0000090: 6420 746f 2066 6974 2079 6f75 7220 7363 d to fit your sc +00000a0: 7265 656e 2e0a 6d6f 6475 6c65 2070 686f reen..module pho +00000b0: 6e65 6e6f 3b20 2020 2020 2f2f 206f 7074 neno; // opt +00000c0: 696f 6e61 6c0a 696d 706f 7274 2073 7464 ional.import std +00000d0: 2e73 7464 696f 3b20 2020 2f2f 2077 7269 .stdio; // wri +00000e0: 7465 666c 6e20 2020 2020 0a69 6d70 6f72 tefln .impor +00000f0: 7420 7374 642e 6374 7970 653b 2020 202f t std.ctype; / +0000100: 2f20 6973 6469 6769 7420 2020 2020 0a69 / isdigit .i +0000110: 6d70 6f72 7420 7374 642e 7374 7265 616d mport std.stream +0000120: 3b20 202f 2f20 4275 6666 6572 6564 4669 ; // BufferedFi +0000130: 6c65 0a0a 2f2f 204a 7573 7420 666f 7220 le..// Just for +0000140: 7265 6164 6162 696c 6974 7920 2869 6d61 readability (ima +0000150: 6769 6e65 2063 6861 725b 5d5b 5d5b 6368 gine char[][][ch +0000160: 6172 5b5d 5d29 2020 2020 0a61 6c69 6173 ar[]]) .alias +0000170: 2063 6861 725b 5d20 7374 7269 6e67 3b0a char[] string;. +0000180: 616c 6961 7320 7374 7269 6e67 5b5d 2073 alias string[] s +0000190: 7472 696e 6761 7272 6179 3b0a 0a2f 2f2f tringarray;../// +00001a0: 2053 7472 6970 7320 6e6f 6e2d 6469 6769 Strips non-digi +00001b0: 7420 6368 6172 6163 7465 7273 2066 726f t characters fro +00001c0: 6d20 7468 6520 7374 7269 6e67 2028 434f m the string (CO +00001d0: 5729 0a73 7472 696e 6720 7374 7269 704e W).string stripN +00001e0: 6f6e 4469 6769 7428 2069 6e20 7374 7269 onDigit( in stri +00001f0: 6e67 206c 696e 6520 2920 0a7b 0a20 2020 ng line ) .{. +0000200: 2073 7472 696e 6720 7265 743b 0a20 2020 string ret;. +0000210: 2066 6f72 6561 6368 2875 696e 7420 692c foreach(uint i, +0000220: 2063 3b20 6c69 6e65 2920 7b0a 2020 2020 c; line) {. +0000230: 2020 2020 2f2f 2045 7272 6f72 3a20 7374 // Error: st +0000240: 642e 6374 7970 652e 6973 6469 6769 7420 d.ctype.isdigit +0000250: 6174 2043 3a5c 646d 645c 7372 635c 7068 at C:\dmd\src\ph +0000260: 6f62 6f73 5c73 7464 5c63 7479 7065 2e64 obos\std\ctype.d +0000270: 2833 3729 200a 2020 2020 2020 2020 2f2f (37) . // +0000280: 2063 6f6e 666c 6963 7473 2077 6974 6820 conflicts with +0000290: 7374 642e 7374 7265 616d 2e69 7364 6967 std.stream.isdig +00002a0: 6974 2061 7420 433a 5c64 6d64 5c73 7263 it at C:\dmd\src +00002b0: 5c70 686f 626f 735c 7374 645c 7374 7265 \phobos\std\stre +00002c0: 616d 2e64 2832 3932 3429 0a20 2020 2020 am.d(2924). +00002d0: 2020 2069 6620 2821 7374 642e 6374 7970 if (!std.ctyp +00002e0: 652e 6973 6469 6769 7428 6329 2920 7b0a e.isdigit(c)) {. +00002f0: 2020 2020 2020 2020 2020 2020 6966 2028 if ( +0000300: 2172 6574 290a 2020 2020 2020 2020 2020 !ret). +0000310: 2020 2020 2020 7265 7420 3d20 6c69 6e65 ret = line +0000320: 5b30 2e2e 695d 3b20 2020 200a 2020 2020 [0..i]; . +0000330: 2020 2020 7d20 2020 200a 2020 2020 2020 } . +0000340: 2020 656c 7365 2069 6620 2872 6574 290a else if (ret). +0000350: 2020 2020 2020 2020 2020 2020 7265 7420 ret +0000360: 7e3d 2063 3b20 2020 200a 2020 2020 7d20 ~= c; . } +0000370: 2020 200a 2020 2020 7265 7475 726e 2072 . return r +0000380: 6574 3f72 6574 3a6c 696e 653b 0a7d 0a0a et?ret:line;.}.. +0000390: 756e 6974 7465 7374 207b 0a20 2020 2061 unittest {. a +00003a0: 7373 6572 7428 2073 7472 6970 4e6f 6e44 ssert( stripNonD +00003b0: 6967 6974 2822 6173 6466 2229 203d 3d20 igit("asdf") == +00003c0: 2222 2020 293b 0a20 2020 2061 7373 6572 "" );. asser +00003d0: 7428 2073 7472 6970 4e6f 6e44 6967 6974 t( stripNonDigit +00003e0: 2822 5c27 3133 2d3d 3220 346b 6f70 2229 ("\'13-=2 4kop") +00003f0: 203d 3d20 2022 3133 3234 2220 2029 3b0a == "1324" );. +0000400: 7d0a 0a2f 2f2f 2043 6f6e 7665 7274 7320 }../// Converts +0000410: 6120 776f 7264 2069 6e74 6f20 6120 6e75 a word into a nu +0000420: 6d62 6572 2c20 6967 6e6f 7269 6e67 2061 mber, ignoring a +0000430: 6c6c 206e 6f6e 2061 6c70 6861 2063 6861 ll non alpha cha +0000440: 7261 6374 6572 7320 200a 7374 7269 6e67 racters .string +0000450: 2077 6f72 6454 6f4e 756d 2820 696e 2073 wordToNum( in s +0000460: 7472 696e 6720 776f 7264 2029 0a7b 0a2f tring word ).{./ +0000470: 2f20 7472 616e 736c 6174 696f 6e20 7461 / translation ta +0000480: 626c 6520 666f 7220 7468 6520 7461 736b ble for the task +0000490: 2061 7420 6861 6e64 0a63 6f6e 7374 2063 at hand.const c +00004a0: 6861 725b 3235 365d 2054 5241 4e53 4c41 har[256] TRANSLA +00004b0: 5445 203d 2020 2020 0a20 2020 2022 2020 TE = . " +00004c0: 2020 2020 2020 2020 2020 2020 2020 2020 +00004d0: 2020 2020 2020 2020 2020 2020 2020 2220 " +00004e0: 202f 2f20 3020 2020 0a20 2020 2022 2020 // 0 . " +00004f0: 2020 2020 2020 2020 2020 2020 2020 3031 01 +0000500: 3233 3435 3637 3839 2020 2020 2020 2220 23456789 " +0000510: 202f 2f20 3332 2020 2020 200a 2020 2020 // 32 . +0000520: 2220 3537 3633 3034 3939 3631 3738 3531 " 57630499617851 +0000530: 3838 3132 3334 3736 3232 3339 2020 2020 881234762239 +0000540: 2022 2020 2f2f 2036 3420 2020 0a20 2020 " // 64 . +0000550: 2022 2035 3736 3330 3439 3936 3137 3835 " 5763049961785 +0000560: 3138 3831 3233 3437 3632 3233 3920 2020 1881234762239 +0000570: 2020 220a 2020 2020 2220 2020 2020 2020 ". " +0000580: 2020 2020 2020 2020 2020 2020 2020 2020 +0000590: 2020 2020 2020 2020 2022 0a20 2020 2022 ". " +00005a0: 2020 2020 2020 2020 2020 2020 2020 2020 +00005b0: 2020 2020 2020 2020 2020 2020 2020 2020 +00005c0: 220a 2020 2020 2220 2020 2020 2020 2020 ". " +00005d0: 2020 2020 2020 2020 2020 2020 2020 2020 +00005e0: 2020 2020 2020 2022 2020 2020 0a20 2020 " . +00005f0: 2022 2020 2020 2020 2020 2020 2020 2020 " +0000600: 2020 2020 2020 2020 2020 2020 2020 2020 +0000610: 2020 223b 0a20 2020 2073 7472 696e 6720 ";. string +0000620: 7265 743b 0a20 2020 2066 6f72 6561 6368 ret;. foreach +0000630: 2863 3b20 6361 7374 2875 6279 7465 5b5d (c; cast(ubyte[] +0000640: 2977 6f72 6429 0a20 2020 2020 2020 2069 )word). i +0000650: 6620 2854 5241 4e53 4c41 5445 5b63 5d20 f (TRANSLATE[c] +0000660: 213d 2027 2027 290a 2020 2020 2020 2020 != ' '). +0000670: 2020 2020 7265 7420 7e3d 2054 5241 4e53 ret ~= TRANS +0000680: 4c41 5445 5b63 5d3b 0a20 2020 2072 6574 LATE[c];. ret +0000690: 7572 6e20 7265 743b 0a7d 0a0a 756e 6974 urn ret;.}..unit +00006a0: 7465 7374 207b 0a20 2f2f 2054 6573 7420 test {. // Test +00006b0: 776f 7264 546f 4e75 6d20 7573 696e 6720 wordToNum using +00006c0: 7468 6520 7461 626c 6520 6672 6f6d 2074 the table from t +00006d0: 6865 2074 6173 6b20 6465 7363 7269 7074 he task descript +00006e0: 696f 6e2e 0a20 6173 7365 7274 2820 2230 ion.. assert( "0 +00006f0: 3131 3132 3232 3333 3334 3435 3536 3636 1112223334455666 +0000700: 3737 3738 3838 3939 3922 203d 3d0a 2020 777888999" ==. +0000710: 2077 6f72 6454 6f4e 756d 2822 4520 7c20 wordToNum("E | +0000720: 4a20 4e20 5120 7c20 5220 5720 5820 7c20 J N Q | R W X | +0000730: 4420 5320 5920 7c20 4620 5420 7c20 4120 D S Y | F T | A +0000740: 4d20 7c20 4320 4920 5620 7c20 4220 4b20 M | C I V | B K +0000750: 5520 7c20 4c20 4f20 5020 7c20 4720 4820 U | L O P | G H +0000760: 5a22 2929 3b0a 2061 7373 6572 7428 2022 Z"));. assert( " +0000770: 3031 3131 3232 3233 3333 3434 3535 3636 0111222333445566 +0000780: 3637 3737 3838 3839 3939 2220 3d3d 200a 6777888999" == . +0000790: 2020 2077 6f72 6454 6f4e 756d 2822 6520 wordToNum("e +00007a0: 7c20 6a20 6e20 7120 7c20 7220 7720 7820 | j n q | r w x +00007b0: 7c20 6420 7320 7920 7c20 6620 7420 7c20 | d s y | f t | +00007c0: 6120 6d20 7c20 6320 6920 7620 7c20 6220 a m | c i v | b +00007d0: 6b20 7520 7c20 6c20 6f20 7020 7c20 6720 k u | l o p | g +00007e0: 6820 7a22 2929 3b0a 2061 7373 6572 7428 h z"));. assert( +00007f0: 2022 3031 3233 3435 3637 3839 2220 3d3d "0123456789" == +0000800: 200a 2020 2077 6f72 6454 6f4e 756d 2822 . wordToNum(" +0000810: 3020 7c20 2020 3120 2020 7c20 2020 3220 0 | 1 | 2 +0000820: 2020 7c20 2020 3320 2020 7c20 2034 2020 | 3 | 4 +0000830: 7c20 2035 2020 7c20 2020 3620 2020 7c20 | 5 | 6 | +0000840: 2020 3720 2020 7c20 2020 3820 2020 7c20 7 | 8 | +0000850: 2020 3922 2929 3b0a 7d0a 0a76 6f69 6420 9"));.}..void +0000860: 6d61 696e 2820 7374 7269 6e67 5b5d 2061 main( string[] a +0000870: 7267 7320 290a 7b0a 2020 2020 2f2f 2054 rgs ).{. // T +0000880: 6869 7320 6173 736f 6369 6174 6976 6520 his associative +0000890: 6172 7261 7920 6d61 7073 2061 206e 756d array maps a num +00008a0: 6265 7220 746f 2061 6e20 6172 7261 7920 ber to an array +00008b0: 6f66 2077 6f72 6473 2e20 2020 200a 2020 of words. . +00008c0: 2020 7374 7269 6e67 6172 7261 795b 7374 stringarray[st +00008d0: 7269 6e67 5d20 2020 206e 756d 3277 6f72 ring] num2wor +00008e0: 6473 3b0a 0a20 2020 2066 6f72 6561 6368 ds;.. foreach +00008f0: 2873 7472 696e 6720 776f 7264 3b20 6e65 (string word; ne +0000900: 7720 4275 6666 6572 6564 4669 6c65 2822 w BufferedFile(" +0000910: 6469 6374 696f 6e61 7279 2e74 7874 2220 dictionary.txt" +0000920: 2920 290a 2020 2020 2020 2020 6e75 6d32 ) ). num2 +0000930: 776f 7264 735b 2077 6f72 6454 6f4e 756d words[ wordToNum +0000940: 2877 6f72 6429 205d 207e 3d20 776f 7264 (word) ] ~= word +0000950: 2e64 7570 3b20 2020 2020 2020 202f 2f20 .dup; // +0000960: 6d75 7374 2064 7570 0a0a 2020 2020 2f2f must dup.. // +0000970: 2f20 4669 6e64 7320 616c 6c20 616c 7465 / Finds all alte +0000980: 726e 6174 6976 6573 2066 6f72 2074 6865 rnatives for the +0000990: 2067 6976 656e 206e 756d 6265 720a 2020 given number. +00009a0: 2020 2f2f 2f20 2873 686f 756c 6420 6861 /// (should ha +00009b0: 7665 2062 6565 6e20 7374 7269 7070 6564 ve been stripped +00009c0: 2066 726f 6d20 6e6f 6e2d 6469 6769 7420 from non-digit +00009d0: 6368 6172 6163 7465 7273 290a 2020 2020 characters). +00009e0: 7374 7269 6e67 6172 7261 7920 5f46 696e stringarray _Fin +00009f0: 6457 6f72 6473 2820 7374 7269 6e67 206e dWords( string n +0000a00: 756d 6265 7273 2c20 626f 6f6c 2064 6967 umbers, bool dig +0000a10: 6974 6f6b 2029 0a20 2020 2069 6e20 7b0a itok ). in {. +0000a20: 2020 2020 2020 2020 6173 7365 7274 286e assert(n +0000a30: 756d 6265 7273 2e6c 656e 6774 6820 3e20 umbers.length > +0000a40: 2030 293b 2020 2020 0a20 2020 207d 2020 0); . } +0000a50: 2020 0a20 2020 206f 7574 2872 6573 756c . out(resul +0000a60: 7429 207b 0a20 2020 2020 2020 2066 6f72 t) {. for +0000a70: 6561 6368 2028 613b 2072 6573 756c 7429 each (a; result) +0000a80: 0a20 2020 2020 2020 2020 2020 2061 7373 . ass +0000a90: 6572 7428 2077 6f72 6454 6f4e 756d 2861 ert( wordToNum(a +0000aa0: 2920 3d3d 206e 756d 6265 7273 2029 3b0a ) == numbers );. +0000ab0: 2020 2020 7d20 2020 200a 2020 2020 626f } . bo +0000ac0: 6479 207b 0a20 2020 2020 2020 2073 7472 dy {. str +0000ad0: 696e 6761 7272 6179 2072 6574 3b0a 2020 ingarray ret;. +0000ae0: 2020 2020 2020 626f 6f6c 2066 6f75 6e64 bool found +0000af0: 776f 7264 203d 2066 616c 7365 3b0a 2020 word = false;. +0000b00: 2020 2020 2020 666f 7220 2875 696e 7420 for (uint +0000b10: 743d 313b 2074 3c3d 6e75 6d62 6572 732e t=1; t<=numbers. +0000b20: 6c65 6e67 7468 3b20 2b2b 7429 207b 0a20 length; ++t) {. +0000b30: 2020 2020 2020 2020 2020 2061 7574 6f20 auto +0000b40: 616c 7465 726e 6174 6976 6573 203d 206e alternatives = n +0000b50: 756d 6265 7273 5b30 2e2e 745d 2069 6e20 umbers[0..t] in +0000b60: 6e75 6d32 776f 7264 733b 0a20 2020 2020 num2words;. +0000b70: 2020 2020 2020 2069 6620 2821 616c 7465 if (!alte +0000b80: 726e 6174 6976 6573 290a 2020 2020 2020 rnatives). +0000b90: 2020 2020 2020 2020 2020 636f 6e74 696e contin +0000ba0: 7565 3b0a 2020 2020 2020 2020 2020 2020 ue;. +0000bb0: 666f 756e 6477 6f72 6420 3d20 7472 7565 foundword = true +0000bc0: 3b0a 2020 2020 2020 2020 2020 2020 6966 ;. if +0000bd0: 2028 6e75 6d62 6572 732e 6c65 6e67 7468 (numbers.length +0000be0: 203e 2020 7429 207b 0a20 2020 2020 2020 > t) {. +0000bf0: 2020 2020 2020 2020 202f 2f20 436f 6d62 // Comb +0000c00: 696e 6520 616c 6c20 6375 7272 656e 7420 ine all current +0000c10: 616c 7465 726e 6174 6976 6573 2077 6974 alternatives wit +0000c20: 6820 616c 6c20 616c 7465 726e 6174 6976 h all alternativ +0000c30: 6573 2020 2020 200a 2020 2020 2020 2020 es . +0000c40: 2020 2020 2020 2020 2f2f 206f 6620 7468 // of th +0000c50: 6520 7265 7374 2028 6e65 7874 2070 6965 e rest (next pie +0000c60: 6365 2063 616e 2073 7461 7274 2077 6974 ce can start wit +0000c70: 6820 6120 6469 6769 7429 2020 2020 2020 h a digit) +0000c80: 2020 2020 2020 2020 0a20 2020 2020 2020 . +0000c90: 2020 2020 2020 2020 2066 6f72 6561 6368 foreach +0000ca0: 2028 6132 3b20 5f46 696e 6457 6f72 6473 (a2; _FindWords +0000cb0: 2820 6e75 6d62 6572 735b 742e 2e24 5d2c ( numbers[t..$], +0000cc0: 2074 7275 6520 2020 2020 2920 290a 2020 true ) ). +0000cd0: 2020 2020 2020 2020 2020 2020 2020 2020 +0000ce0: 2020 666f 7265 6163 6828 6131 3b20 2a61 foreach(a1; *a +0000cf0: 6c74 6572 6e61 7469 7665 7329 0a20 2020 lternatives). +0000d00: 2020 2020 2020 2020 2020 2020 2020 2020 +0000d10: 2020 2020 7265 7420 7e3d 2061 3120 7e20 ret ~= a1 ~ +0000d20: 2220 2220 7e20 6132 3b0a 2020 2020 2020 " " ~ a2;. +0000d30: 2020 2020 2020 7d0a 2020 2020 2020 2020 }. +0000d40: 2020 2020 656c 7365 2020 2020 0a20 2020 else . +0000d50: 2020 2020 2020 2020 2020 2020 2072 6574 ret +0000d60: 207e 3d20 2a61 6c74 6572 6e61 7469 7665 ~= *alternative +0000d70: 733b 2020 2020 2f2f 2061 7070 656e 6420 s; // append +0000d80: 7468 6573 6520 616c 7465 726e 6174 6976 these alternativ +0000d90: 6573 0a20 2020 2020 2020 207d 0a20 2020 es. }. +0000da0: 2020 2020 202f 2f20 5472 7920 746f 206b // Try to k +0000db0: 6565 7020 3120 6469 6769 742c 206f 6e6c eep 1 digit, onl +0000dc0: 7920 6966 2077 6527 7265 2061 6c6c 6f77 y if we're allow +0000dd0: 6564 2061 6e64 206e 6f20 6f74 6865 720a ed and no other. +0000de0: 2020 2020 2020 2020 2f2f 2061 6c74 6572 // alter +0000df0: 6e61 7469 7665 7320 7765 7265 2066 6f75 natives were fou +0000e00: 6e64 0a20 2020 2020 2020 202f 2f20 5465 nd. // Te +0000e10: 7374 696e 6720 2272 6574 2e6c 656e 6774 sting "ret.lengt +0000e20: 6822 206d 616b 6573 206d 6f72 6520 7365 h" makes more se +0000e30: 6e73 6520 7468 616e 2074 6573 7469 6e67 nse than testing +0000e40: 2022 666f 756e 6477 6f72 6422 2c0a 2020 "foundword",. +0000e50: 2020 2020 2020 2f2f 2062 7574 2074 6865 // but the +0000e60: 206f 7468 6572 2069 6d70 6c65 6d65 6e74 other implement +0000e70: 6174 696f 6e73 2073 6565 6d20 746f 2064 ations seem to d +0000e80: 6f20 6a75 7374 2074 6869 732e 0a20 2020 o just this.. +0000e90: 2020 2020 2069 6620 2864 6967 6974 6f6b if (digitok +0000ea0: 2026 2620 2166 6f75 6e64 776f 7264 2920 && !foundword) +0000eb0: 7b20 2f2f 7265 742e 6c65 6e67 7468 203d { //ret.length = +0000ec0: 3d20 3020 200a 2020 2020 2020 2020 2020 = 0 . +0000ed0: 2020 6966 286e 756d 6265 7273 2e6c 656e if(numbers.len +0000ee0: 6774 6820 3e20 2031 2920 7b0a 2020 2020 gth > 1) {. +0000ef0: 2020 2020 2020 2020 2020 2020 2f2f 2043 // C +0000f00: 6f6d 6269 6e65 2031 2064 6967 6974 2077 ombine 1 digit w +0000f10: 6974 6820 616c 6c20 616c 7465 6e61 7469 ith all altenati +0000f20: 7665 7320 6672 6f6d 2074 6865 2072 6573 ves from the res +0000f30: 7420 2020 200a 2020 2020 2020 2020 2020 t . +0000f40: 2020 2020 2020 2f2f 2028 6e65 7874 2070 // (next p +0000f50: 6965 6365 2063 616e 206e 6f74 2073 7461 iece can not sta +0000f60: 7274 2077 6974 6820 6120 6469 6769 7429 rt with a digit) +0000f70: 2020 2020 2020 2020 2020 0a20 2020 2020 . +0000f80: 2020 2020 2020 2020 2020 2066 6f72 6561 forea +0000f90: 6368 2028 613b 205f 4669 6e64 576f 7264 ch (a; _FindWord +0000fa0: 7328 206e 756d 6265 7273 5b31 2e2e 245d s( numbers[1..$] +0000fb0: 2c20 6661 6c73 6520 2920 290a 2020 2020 , false ) ). +0000fc0: 2020 2020 2020 2020 2020 2020 2020 2020 +0000fd0: 7265 7420 7e3d 206e 756d 6265 7273 5b30 ret ~= numbers[0 +0000fe0: 2e2e 315d 207e 2022 2022 207e 2061 3b0a ..1] ~ " " ~ a;. +0000ff0: 2020 2020 2020 2020 2020 2020 7d20 2020 } +0001000: 200a 2020 2020 2020 2020 2020 2020 656c . el +0001010: 7365 2020 2020 0a20 2020 2020 2020 2020 se . +0001020: 2020 2020 2020 2072 6574 207e 3d20 6e75 ret ~= nu +0001030: 6d62 6572 735b 302e 2e31 5d3b 2020 2020 mbers[0..1]; +0001040: 2f2f 206a 7573 7420 6170 7065 6e64 2074 // just append t +0001050: 6869 7320 6469 6769 7420 2020 2020 2020 his digit +0001060: 2020 2020 2020 0a20 2020 2020 2020 207d . } +0001070: 2020 2020 0a20 2020 2020 2020 2072 6574 . ret +0001080: 7572 6e20 7265 743b 0a20 2020 207d 0a0a urn ret;. }.. +0001090: 2020 2020 2f2f 2f20 2854 6869 7320 6675 /// (This fu +00010a0: 6e63 7469 6f6e 2077 6173 2069 6e6c 696e nction was inlin +00010b0: 6564 2069 6e20 7468 6520 6f72 6967 696e ed in the origin +00010c0: 616c 2070 726f 6772 616d 2920 0a20 2020 al program) . +00010d0: 202f 2f2f 2046 696e 6473 2061 6c6c 2061 /// Finds all a +00010e0: 6c74 6572 6e61 7469 7665 7320 666f 7220 lternatives for +00010f0: 7468 6520 6769 7665 6e20 7068 6f6e 6520 the given phone +0001100: 6e75 6d62 6572 200a 2020 2020 2f2f 2f20 number . /// +0001110: 5265 7475 726e 733a 2061 7272 6179 206f Returns: array o +0001120: 6620 7374 7269 6e67 7320 0a20 2020 2073 f strings . s +0001130: 7472 696e 6761 7272 6179 2046 696e 6457 tringarray FindW +0001140: 6f72 6473 2820 7374 7269 6e67 2070 686f ords( string pho +0001150: 6e65 5f6e 756d 6265 7220 290a 2020 2020 ne_number ). +0001160: 7b0a 2020 2020 2020 2020 6966 2028 2170 {. if (!p +0001170: 686f 6e65 5f6e 756d 6265 722e 6c65 6e67 hone_number.leng +0001180: 7468 290a 2020 2020 2020 2020 2020 2020 th). +0001190: 7265 7475 726e 206e 756c 6c3b 0a20 2020 return null;. +00011a0: 2020 2020 202f 2f20 5374 7269 7020 7468 // Strip th +00011b0: 6520 6e6f 6e2d 6469 6769 7420 6368 6172 e non-digit char +00011c0: 6163 7465 7273 2066 726f 6d20 7468 6520 acters from the +00011d0: 7068 6f6e 6520 6e75 6d62 6572 2c20 616e phone number, an +00011e0: 640a 2020 2020 2020 2020 2f2f 2070 6173 d. // pas +00011f0: 7320 6974 2074 6f20 7468 6520 7265 6375 s it to the recu +0001200: 7273 6976 6520 6675 6e63 7469 6f6e 2028 rsive function ( +0001210: 6c65 6164 696e 6720 6469 6769 7420 6973 leading digit is +0001220: 2061 6c6c 6f77 6564 290a 2020 2020 2020 allowed). +0001230: 2020 7265 7475 726e 205f 4669 6e64 576f return _FindWo +0001240: 7264 7328 2073 7472 6970 4e6f 6e44 6967 rds( stripNonDig +0001250: 6974 2870 686f 6e65 5f6e 756d 6265 7229 it(phone_number) +0001260: 2c20 7472 7565 2029 3b20 2020 200a 2020 , true ); . +0001270: 2020 7d20 2020 200a 2020 2020 0a20 2020 } . . +0001280: 202f 2f20 5265 6164 2074 6865 2070 686f // Read the pho +0001290: 6e65 206e 756d 6265 7273 2020 2020 200a ne numbers . +00012a0: 2020 2020 666f 7265 6163 6828 7374 7269 foreach(stri +00012b0: 6e67 2070 686f 6e65 3b20 6e65 7720 4275 ng phone; new Bu +00012c0: 6666 6572 6564 4669 6c65 2822 696e 7075 fferedFile("inpu +00012d0: 742e 7478 7422 2020 2029 2029 0a20 2020 t.txt" ) ). +00012e0: 2020 2020 2066 6f72 6561 6368 2861 6c74 foreach(alt +00012f0: 6572 6e61 7469 7665 3b20 4669 6e64 576f ernative; FindWo +0001300: 7264 7328 2070 686f 6e65 2029 2029 0a20 rds( phone ) ). +0001310: 2020 2020 2020 2020 2020 2077 7269 7465 write +0001320: 666c 6e28 7068 6f6e 652c 2022 3a20 222c fln(phone, ": ", +0001330: 2061 6c74 6572 6e61 7469 7665 2029 3b0a alternative );. +0001340: 7d0a 0a }.. diff --git a/tests/examplefiles/noexcept.cpp b/tests/examplefiles/noexcept.cpp new file mode 100644 index 00000000..f83e50db --- /dev/null +++ b/tests/examplefiles/noexcept.cpp @@ -0,0 +1,8 @@ +void* operator new (std::size_t size); +void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept; +void* operator new (std::size_t size, const std::nothrow_t& nothrow_value)noexcept; +void* operator new (std::size_t size, const std::nothrow_t& nothrow_value); +void* operator new (std::size_t size); +void* operator new (std::size_t size) noexcept; +void* operator new (std::size_t size)noexcept; + diff --git a/tests/examplefiles/pacman.conf b/tests/examplefiles/pacman.conf new file mode 100644 index 00000000..78dbf5e1 --- /dev/null +++ b/tests/examplefiles/pacman.conf @@ -0,0 +1,49 @@ +# +# /etc/pacman.conf +# +# This example file has no relation to `pacman.ijs` +# but is of configuration of Arch Linux's package manager `pacman`. +# + +# +# GENERAL OPTIONS +# +[options] +RootDir = /opt/local/site-private +#DBPath = /var/lib/pacman/ +#CacheDir = /var/cache/pacman/pkg/ +LogFile = /opt/local/site-private/var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +HoldPkg = pacman +#XferCommand = /usr/bin/curl -C - -f %u > %o +XferCommand = /usr/local/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +#UseDelta = 0.7 +Architecture = auto + +#IgnorePkg = +#IgnoreGroup = + +NoUpgrade = etc/passwd etc/group etc/shadow +NoUpgrade = etc/fstab +#NoExtract = + +#UseSyslog +Color +#TotalDownload +CheckSpace +#VerbosePkgLists + +#SigLevel = Never +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +RemoteFileSigLevel = Required + +Server = ftp://ftp9.yaphatchpotchgen.net/$repo/os/$arch + +[fubar32] +Include = /etc/pacman.d/mirrorlist.fubar32 # comment is allowed here + +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs diff --git a/tests/examplefiles/pkgconfig_example.pc b/tests/examplefiles/pkgconfig_example.pc new file mode 100644 index 00000000..2a59204e --- /dev/null +++ b/tests/examplefiles/pkgconfig_example.pc @@ -0,0 +1,18 @@ +# This is for a fictional package `yet another portable hatchpotch generator'. +prefix=/usr/local/opt/site/private # define variable `prefix` +exec_prefix=${prefix} # using variable reference +libdir=${exec_prefix}/lib +includedir=${prefix}/include +just_for_test=$${this is not a part of variable reference} # escape with `$$` + +Name: YAPHatchPotchGen +Description: Yet Another Portable HatchPotch GENerator. +Version: 352.9.3 +URL: http://www9.yaphatchpotchgen.net # Don't access. +Requires: piyohogelib-9.0 = 9.5.3 +Requires.private: nyorolib-3.0 = 3.0.9 +Conflicts: apiyohoge <= 8.3 +Libs: -L${libdir} -lyaphatchpotchgen-352.9 # using variable reference +Libs.private: -ll -ly +Cflags: -I${includedir}/piyohogelib-9.0 -I${libdir}/yaphatchpotchgen/include + diff --git a/tests/examplefiles/pycon_ctrlc_traceback b/tests/examplefiles/pycon_ctrlc_traceback new file mode 100644 index 00000000..4998fd9c --- /dev/null +++ b/tests/examplefiles/pycon_ctrlc_traceback @@ -0,0 +1,118 @@ +x = r""" +>>> import os +>>> print os + +>>> for x in range(10): +... y = x + 2 +... print(x) +... if x > 5: +... raise Exception +... +0 +1 +2 +3 +4 +5 +6 +Traceback (most recent call last): + File "", line 5, in +Exception +>>> +>>> while True: +... pass +... +^CTraceback (most recent call last): + File "", line 1, in +KeyboardInterrupt + +>>> class A(Exception):pass +... +>>> class B(Exception):pass +... +>>> try: +... try: +... raise A('first') +... finally: +... raise B('second') +... except A as c: +... print(c) +... +Traceback (most recent call last): + File "", line 3, in +__main__.A: first + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "", line 5, in +__main__.B: second + +>>> x = + File "", line 1 + x = + ^ +SyntaxError: invalid syntax +>>> + +>>> x = 3 +>>> with 5 as y: +... print(x + y) +... +8 + +# TODO +#>>> raise ValueError('multi\n line\ndetail') +#Traceback (most recent call last): +#........ +#ValueError: multi +# line +#detail + +>>> raise ValueError('multi\n line\ndetail') +Traceback (most recent call last): + .123 +ValueError: multi + line +detail + +>>> raise ValueError('multi\n line\ndetail') +Traceback (most recent call last): + ... +ValueError: multi + line +detail + +>>> raise ValueError('multi\n line\ndetail') +Traceback (most recent call last): + .... +ValueError: multi + line +detail + +>>> raise ValueError('multi\n line\ndetail') +Traceback (most recent call last): + .... +ValueError: multi + line +detail + +>>> raise ValueError('multi\n line\ndetail') +Traceback (most recent call last): + ... +ValueError: multi + line +detail + +>>> raise Exception +Traceback (most recent call last): + File "", line 1, in +Exception +>>> import somemodule +>>> somemodule.blah() +Traceback (most recent call last): + File "", line 1, in + File "/path/to/stuff/somemodule/blah.py", line 658, in blah + raise Exception('Hi.') +Exception: Hi. + diff --git a/tests/examplefiles/sample.qvto b/tests/examplefiles/sample.qvto new file mode 100644 index 00000000..6241ee23 --- /dev/null +++ b/tests/examplefiles/sample.qvto @@ -0,0 +1,4 @@ +transformation Foo(uml: SimpleUML, + rdbms : SimpleRDBMS) { +} +/* comment */ diff --git a/tests/examplefiles/simple.camkes b/tests/examplefiles/simple.camkes new file mode 100644 index 00000000..43e11732 --- /dev/null +++ b/tests/examplefiles/simple.camkes @@ -0,0 +1,38 @@ +/* + * Example input for CAmkES lexer. + */ + +import ; + +// A single-line comment. + +import "components/Client/Client.camkes"; +import "components/Echo/Echo.camkes"; + +component Foo { + include "proc_defn.h"; + control; + dataport Buf my_port; +} + +#ifdef BAR_AVAILABLE + component Bar { + provides CharAccess ca; + } +#endif + + #define HASH_DEF_WITH_LEADING_SPACE + +assembly { /* Another multiline comment. */ + composition { + component Echo echo; + component Client client; + + connection seL4RPC simple(from client.s, to echo.s); + } + + configuration { + echo.dma_pool = 4096; + } +} + diff --git a/tests/examplefiles/termcap b/tests/examplefiles/termcap new file mode 100644 index 00000000..e20adaba --- /dev/null +++ b/tests/examplefiles/termcap @@ -0,0 +1,1340 @@ +######## This example from excerpt of : +# +# Version 11.0.1 +# $Date: 2000/03/02 15:51:11 $ +# termcap syntax +# + +######## ANSI, UNIX CONSOLE, AND SPECIAL TYPES +# +# This section describes terminal classes and brands that are still +# quite common. +# + +#### Specials +# +# Special "terminals". These are used to label tty lines when you don't +# know what kind of terminal is on it. The characteristics of an unknown +# terminal are the lowest common denominator - they look about like a ti 700. +# + +dumb|80-column dumb tty:\ + :am:\ + :co#80:\ + :bl=^G:cr=^M:do=^J:sf=^J: +unknown|unknown terminal type:\ + :gn:tc=dumb: +lpr|printer|line printer:\ + :bs:hc:os:\ + :co#132:li#66:\ + :bl=^G:cr=^M:do=^J:ff=^L:le=^H:sf=^J: +glasstty|classic glass tty interpreting ASCII control characters:\ + :am:bs:\ + :co#80:\ + :bl=^G:cl=^L:cr=^M:do=^J:kd=^J:kl=^H:le=^H:nw=^M^J:ta=^I: +vanilla:\ + :bs:\ + :bl=^G:cr=^M:do=^J:sf=^J: + +#### ANSI.SYS/ISO 6429/ECMA-48 Capabilities +# +# See the end-of-file comment for more on these. +# + +# ANSI capabilities are broken up into pieces, so that a terminal +# implementing some ANSI subset can use many of them. +ansi+local1:\ + :do=\E[B:le=\E[D:nd=\E[C:up=\E[A: +ansi+local:\ + :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:tc=ansi+local1: +ansi+tabs:\ + :bt=\E[Z:ct=\E[2g:st=\EH:ta=^I: +ansi+inittabs:\ + :it#8:tc=ansi+tabs: +ansi+erase:\ + :cd=\E[J:ce=\E[K:cl=\E[H\E[J: +ansi+rca:\ + :ch=\E[%+^AG:cv=\E[%+^Ad: +ansi+cup:\ + :cm=\E[%i%d;%dH:ho=\E[H: +ansi+rep:\ + :..rp=%p1%c\E[%p2%{1}%-%db: +ansi+idl1:\ + :al=\E[L:dl=\E[M: +ansi+idl:\ + :AL=\E[%dL:DL=\E[%dM:tc=ansi+idl1: +ansi+idc:\ + :IC=\E[%d@:dc=\E[P:ei=\E6:ic=\E[@:im=\E6: +ansi+arrows:\ + :kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A: +ansi+sgr|ansi graphic renditions:\ + :mb=\E[5m:me=\E[0m:mk=\E[8m:mr=\E[7m: +ansi+sgrso|ansi standout only:\ + :se=\E[m:so=\E[7m: +ansi+sgrul|ansi underline only:\ + :ue=\E[m:us=\E[4m: +ansi+sgrbold|ansi graphic renditions; assuming terminal has bold; not dim:\ + :md=\E[1m:\ + :..sa=\E[%?%p1%t7;%;%?%p2%t4;%;%?%p3%t7;%;%?%p4%t5;%;%?%p6%t1;%;m:tc=ansi+sgr:tc=ansi+sgrso:tc=ansi+sgrul: +ansi+sgrdim|ansi graphic renditions; assuming terminal has dim; not bold:\ + :mh=\E[2m:\ + :..sa=\E[%?%p1%t7;%;%?%p2%t4;%;%?%p3%t7;%;%?%p4%t5;%;%?%p5%t2;%;m:tc=ansi+sgr:tc=ansi+sgrso:tc=ansi+sgrul: +ansi+pp|ansi printer port:\ + :pf=\E[4i:po=\E[5i:ps=\E[0i: +ansi+csr|ansi scroll-region plus cursor save & restore:\ + :cs=\E[%i%d;%dr:rc=\E8:sc=\E7: + +# The IBM PC alternate character set. Plug this into any Intel console entry. +# We use \E[11m for rmacs rather than \E[12m so the string can use the +# ROM graphics for control characters such as the diamond, up- and down-arrow. +# This works with the System V, Linux, and BSDI consoles. It's a safe bet this +# will work with any Intel console, they all seem to have inherited \E[11m +# from the ANSI.SYS de-facto standard. +klone+acs|alternate character set for ansi.sys displays:\ + :ac=+\020\054\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376:\ + :ae=\E[10m:as=\E[11m: + +# Highlight controls corresponding to the ANSI.SYS standard. Most +# console drivers for Intel boxes obey these. Makes the same assumption +# about \E[11m as klone+acs. True ANSI/ECMA-48 would have :se=\E[27m:, +# :ue=\E[24m:, but this isn't a documented feature of ANSI.SYS. +klone+sgr|attribute control for ansi.sys displays:\ + :S2=\E[11m:S3=\E[10m:mb=\E[5m:md=\E[1m:me=\E[0;10m:\ + :mk=\E[8m:mr=\E[7m:\ + :..sa=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m:\ + :se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:\ + :tc=klone+acs: + +# Highlight controls corresponding to the ANSI.SYS standard. *All* +# console drivers for Intel boxes obey these. Does not assume \E[11m will +# work; uses \E[12m instead, which is pretty bulletproof but loses you the ACS +# diamond and arrow characters under curses. +klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\ + :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\ + :mr=\E[7m:\ + :..sa=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;12%;m:\ + :se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:\ + :tc=klone+acs: + +# KOI8-R (RFC1489) acs (alternate character set) +# From: Qing Long , 24 Feb 1996. +klone+koi8acs|alternate character set for ansi.sys displays with KOI8 charset:\ + :ac=+\020\054\021-\036.^_0\215`\004a\237f\234g\232h\222i\220j\205k\203l\202m\204n\212o\213p\216q\0r\217s\214t\206u\207v\210w\211x\201y\230z\231{\267|\274}L~\225:\ + :ae=\E[10m:as=\E[11m: + +# ANSI.SYS color control. The setab/setaf caps depend on the coincidence +# between SVr4/XPG4's color numbers and ANSI.SYS attributes. Here are longer +# but equivalent strings that don't rely on that coincidence: +# setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, +# setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, +# The DOS 5 manual asserts that these sequences meet the ISO 6429 standard. +# They match a subset of ECMA-48. +klone+color|color control for ansi.sys and ISO6429-compatible displays:\ + :Co#8:NC#3:pa#64:\ + :AB=\E[4%p1%dm:AF=\E[3%p1%dm:op=\E[37;40m: + +# This is better than klone+color, it doesn't assume white-on-black as the +# default color pair, but many `ANSI' terminals don't grok the cap. +ecma+color|color control for ECMA-48-compatible terminals:\ + :Co#8:NC#3:pa#64:\ + :AB=\E[4%p1%dm:AF=\E[3%p1%dm:op=\E[39;49m: + +# Attribute control for ECMA-48-compatible terminals +ecma+sgr|attribute capabilities for true ECMA-48 terminals:\ + :se=\E[27m:ue=\E[24m:\ + :tc=klone+sgr: + +# For comparison, here are all the capabilities implied by the Intel +# Binary Compatibility Standard (level 2) that fit within terminfo. +# For more detail on this rather pathetic standard, see the comments +# near the end of this file. +ibcs2|Intel Binary Compatibility Standard prescriptions:\ + :AL=\E[%dL:DC=\E[%dP:DO=\E[%dB:IC=\E[%d@:LE=\E[%dD:\ + :RA=\E[?7l:RI=\E[%dC:S1=\E=%p1%dg:SA=\E[?7h:SF=\E[%dS:\ + :SR=\E[%dT:UP=\E[%dA:bt=\E[Z:ch=\E[%i%dG:cl=\Ec:\ + :cm=\E[%i%d;%dH:ct=\E[g:cv=\E[%i%dd:ec=\E[%dX:ei=:im=:\ + :rc=\E7:sc=\E7:st=\EH: + +#### ANSI/ECMA-48 terminals and terminal emulators +# +# See near the end of this file for details on ANSI conformance. +# Don't mess with these entries! Lots of other entries depend on them! +# +# This section lists entries in a least-capable to most-capable order. +# if you're in doubt about what `ANSI' matches yours, try them in that +# order and back off from the first that breaks. + +# ansi-mr is for ANSI terminals with ONLY relative cursor addressing +# and more than one page of memory. It uses local motions instead of +# direct cursor addressing, and makes almost no assumptions. It does +# assume auto margins, no padding and/or xon/xoff, and a 24x80 screen. +ansi-mr|mem rel cup ansi:\ + :am:xo:\ + :co#80:li#24:tc=vanilla:tc=ansi+erase:tc=ansi+local1: + +# ansi-mini is a bare minimum ANSI terminal. This should work on anything, but +# beware of screen size problems and memory relative cursor addressing. +ansi-mini|minimum ansi standard terminal:\ + :am:xo:\ + :co#80:li#24:tc=vanilla:tc=ansi+cup:tc=ansi+erase: + +# ansi-mtabs adds relative addressing and minimal tab support +ansi-mtabs|any ansi terminal with pessimistic assumptions:\ + :it#8:\ + :ta=^I:tc=ansi+local1:tc=ansi-mini: + +# ANSI X3.64 from emory!mlhhh (Hugh Hansard) via BRL +# +# The following is an entry for the full ANSI 3.64 (1977). It lacks +# padding, but most terminals using the standard are "fast" enough +# not to require any -- even at 9600 bps. If you encounter problems, +# try including the padding specifications. +# +# Note: the :as: and :ae: specifications are not implemented here, for +# the available termcap documentation does not make clear WHICH alternate +# character set to specify. ANSI 3.64 seems to make allowances for several. +# Please make the appropriate adjustments to fit your needs -- that is +# if you will be using alternate character sets. +# +# There are very few terminals running the full ANSI 3.64 standard, +# so I could only test this entry on one verified terminal (Visual 102). +# I would appreciate the results on other terminals sent to me. +# +# Please report comments, changes, and problems to: +# +# U.S. MAIL: Hugh Hansard +# Box: 22830 +# Emory University +# Atlanta, GA. 30322. +# +# USENET {akgua,msdc,sb1,sb6,gatech}!emory!mlhhh. +# +# (Added vt100 :rc:,:sc: to quiet a tic warning --esr) +ansi77|ansi 3.64 standard 1977 version:\ + :am:bs:mi:\ + :co#80:it#8:li#24:\ + :al=5*\E[L:bl=^G:cd=\E[J:ce=\E[K:cl=\E[;H\E[2J:\ + :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:dc=\E[P:dl=5*\E[M:\ + :do=\E[B:ei=\E[4l:ho=\E[H:im=\E[4h:k1=\EOP:k2=\EOR:k4=\EOS:\ + :kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:\ + :nd=\E[C:nw=^M\ED:rc=\E8:sc=\E7:se=\E[m:sf=\ED:so=\E[7m:\ + :sr=\EM:ta=^I:ue=\E[m:up=\E[A:us=\E[4m: + +# Procomm and some other ANSI emulations don't recognize all of the ANSI- +# standard capabilities. This entry deletes :UP:, :RI:, :DO:, :LE:, and +# / capabilities, forcing curses to use repetitions of :up:, +# :nd:, :do: and :le:. Also deleted :IC: and :ic:, as QModem up to +# 5.03 doesn't recognize these. Finally, we delete :rp: and :sr:, which seem +# to confuse many emulators. On the other hand, we can count on these programs +# doing :ae:/:as:/:sa:. Older versions of this entry featured +# , but now seems to be more common under +# ANSI.SYS influence. +# From: Eric S. Raymond Oct 30 1995 +pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\ + :am:bs:mi:ms:\ + :co#80:it#8:li#24:\ + :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\ + :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\ + :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\ + :tc=klone+sgr-dumb: +pcansi-25-m|pcansi25m|ibm-pc terminal programs with 25 lines (mono mode):\ + :li#25:tc=pcansi-m: +pcansi-33-m|pcansi33m|ibm-pc terminal programs with 33 lines (mono mode):\ + :li#33:tc=pcansi-m: +pcansi-43-m|ansi43m|ibm-pc terminal programs with 43 lines (mono mode):\ + :li#43:tc=pcansi-m: +# The color versions. All PC emulators do color... +pcansi|ibm-pc terminal programs claiming to be ansi:\ + :tc=klone+color:tc=pcansi-m: +pcansi-25|pcansi25|ibm-pc terminal programs with 25 lines:\ + :li#25:tc=pcansi: +pcansi-33|pcansi33|ibm-pc terminal programs with 33 lines:\ + :li#33:tc=pcansi: +pcansi-43|pcansi43|ibm-pc terminal programs with 43 lines:\ + :li#43:tc=pcansi: + +# ansi-m -- full ANSI X3.64 with ANSI.SYS-compatible attributes, no color. +# If you want pound signs rather than dollars, replace `B' with `A' +# in the , , , and capabilities. +# From: Eric S. Raymond Nov 6 1995 +ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\ + :5i:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\ + :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\ + :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\ + :nw=\r\E[S:pf=\E[4i:po=\E[5i:..rp=%p1%c\E[%p2%{1}%-%db:\ + :s0=\E(B:s1=\E)B:s2=\E*B:s3=\E+B:ta=\E[I:\ + :tc=pcansi-m: + +# ansi -- this terminfo expresses the largest subset of X3.64 that will fit in +# standard terminfo. Assumes ANSI.SYS-compatible attributes and color. +# From: Eric S. Raymond Nov 6 1995 +ansi|ansi/pc-term compatible with color:\ + :u6=\E[%i%d;%dR:u7=\E[6n:..u8=\E[?%[;0123456789]c:\ + :u9=\E[c:\ + :tc=ecma+color:tc=klone+sgr:tc=ansi-m: + +# ansi-generic is a vanilla ANSI terminal. This is assumed to implement +# all the normal ANSI stuff with no extensions. It assumes +# insert/delete line/char is there, so it won't work with +# vt100 clones. It assumes video attributes for bold, blink, +# underline, and reverse, which won't matter much if the terminal +# can't do some of those. Padding is assumed to be zero, which +# shouldn't hurt since xon/xoff is assumed. +ansi-generic|generic ansi standard terminal:\ + :am:xo:\ + :co#80:li#24:tc=vanilla:tc=ansi+csr:tc=ansi+cup:\ + :tc=ansi+rca:tc=ansi+erase:tc=ansi+tabs:tc=ansi+local:\ + :tc=ansi+idc:tc=ansi+idl:tc=ansi+rep:tc=ansi+sgrbold:\ + :tc=ansi+arrows: + +#### Linux consoles +# + +# This entry is good for the 1.2.13 or later version of the Linux console. +# +# *************************************************************************** +# * * +# * WARNING: * +# * Linuxes come with a default keyboard mapping kcbt=^I. This entry, in * +# * response to user requests, assumes kcbt=\E[Z, the ANSI/ECMA reverse-tab * +# * character. Here are the keymap replacement lines that will set this up: * +# * * +# keycode 15 = Tab Tab +# alt keycode 15 = Meta_Tab +# shift keycode 15 = F26 +# string F26 ="\033[Z" +# * * +# * This has to use a key slot which is unfortunate (any unused one will * +# * do, F26 is the higher-numbered one). The change ought to be built * +# * into the kernel tables. * +# * * +# *************************************************************************** +# +# The 1.3.x kernels add color-change capabilities; if yours doesn't have this +# and it matters, turn off . The %02x escape used to implement this is +# not back-portable to SV curses and not supported in ncurses versions before +# 1.9.9. All linux kernels since 1.2.13 (at least) set the screen size +# themselves; this entry assumes that capability. +# +# This entry is good for the 1.2.13 or later version of the Linux console. +# +# *************************************************************************** +# * * +# * WARNING: * +# * Linuxes come with a default keyboard mapping kcbt=^I. This entry, in * +# * response to user requests, assumes kcbt=\E[Z, the ANSI/ECMA reverse-tab * +# * character. Here are the keymap replacement lines that will set this up: * +# * * +# keycode 15 = Tab Tab +# alt keycode 15 = Meta_Tab +# shift keycode 15 = F26 +# string F26 ="\033[Z" +# * * +# * This has to use a key slot which is unfortunate (any unused one will * +# * do, F26 is the higher-numbered one). The change ought to be built * +# * into the kernel tables. * +# * * +# *************************************************************************** +# +# The 1.3.x kernels add color-change capabilities; if yours doesn't have this +# and it matters, turn off . The %02x escape used to implement this is +# not back-portable to SV curses and not supported in ncurses versions before +# 1.9.9. All linux kernels since 1.2.13 (at least) set the screen size +# themselves; this entry assumes that capability. +# +# The 2.2.x kernels add a private mode that sets the cursor type; use that to +# get a block cursor for cvvis. +# reported by Frank Heckenbach . +# (untranslatable capabilities removed to fit entry within 1023 bytes) +# (sgr removed to fit entry within 1023 bytes) +# (terminfo-only capabilities suppressed to fit entry within 1023 bytes) +linux|linux console:\ + :am:eo:mi:ms:xn:xo:\ + :it#8:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:IC=\E[%d@:K2=\E[G:al=\E[L:\ + :bl=^G:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:\ + :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:ec=\E[%dX:\ + :ei=\E[4l:ho=\E[H:ic=\E[@:im=\E[4h:k1=\E[[A:k2=\E[[B:\ + :k3=\E[[C:k4=\E[[D:k5=\E[[E:k6=\E[17~:k7=\E[18~:k8=\E[19~:\ + :k9=\E[20~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=\177:\ + :kd=\E[B:kh=\E[1~:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mh=\E[2m:\ + :mr=\E[7m:nd=\E[C:nw=^M^J:rc=\E8:sc=\E7:se=\E[27m:sf=^J:\ + :sr=\EM:st=\EH:ta=^I:ue=\E[24m:up=\E[A:us=\E[4m:\ + :vb=200\E[?5h\E[?5l:ve=\E[?25h\E[?0c:vi=\E[?25l\E[?1c:\ + :vs=\E[?25h\E[?8c:\ + :tc=klone+sgr:tc=ecma+color: +linux-m|Linux console no color:\ + :Co@:pa@:\ + :AB@:AF@:Sb@:Sf@:tc=linux: +linux-c-nc|linux console 1.3.x hack for ncurses only:\ + :cc:\ + :..Ic=\E]P%p1%x%p2%{255}%*%{1000}%/%02x%p3%{255}%*%{1000}%/%02x%p4%{255}%*%{1000}%/%02x:\ + :oc=\E]R:\ + :tc=linux: +# From: Dennis Henriksen , 9 July 1996 +linux-c|linux console 1.3.6+ with private palette for each virtual console:\ + :cc:\ + :Co#8:pa#64:\ + :..Ic=\E]P%?%p1%{9}%>%t%p1%{10}%-%'a'%+%c%e%p1%d%;%p2%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%p3%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%p4%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;:\ + :oc=\E]R:\ + :tc=linux: + +# See the note on ICH/ICH1 VERSUS RMIR/SMIR near the end of file +linux-nic|linux with ich/ich1 suppressed for non-curses programs:\ + :IC@:ei=:ic@:im=:\ + :tc=linux: + +# This assumes you have used setfont(8) to load one of the Linux koi8-r fonts. +# acsc entry from Pavel Roskin" , 29 Sep 1997. +linux-koi8|linux with koi8 alternate character set:\ + :ac=+\020\054\021-\030.^Y0\215`\004a\221f\234g\237h\220i\276j\205k\203l\202m\204n\212o~p\0q\0r\0s_t\206u\207v\211w\210x\201y\230z\231{\267|\274~\224:tc=linux:\ + :tc=klone+koi8acs: + +# Another entry for KOI8-r with Qing Long's acsc. +# (which one better complies with the standard?) +linux-koi8r|linux with koi8-r alternate character set:\ + :tc=linux:tc=klone+koi8acs: + +# Entry for the latin1 and latin2 fonts +linux-lat|linux with latin1 or latin2 alternate character set:\ + :ac=+\020\054\021-\030.^Y0\333`\004a\013f\370g\361h\260i\316j\211k\214l\206m\203n\305o~p\304q\212r\304s_t\207u\215v\301w\302x\205y\363z\362{\343|\330}\234~\376:\ + :tc=linux: + +#### NetBSD consoles +# +# pcvt termcap database entries (corresponding to release 3.31) +# Author's last edit-date: [Fri Sep 15 20:29:10 1995] +# +# (For the terminfo master file, I translated these into terminfo syntax. +# Then I dropped all the pseudo-HP entries. we don't want and can't use +# the :Xs: flag. Then I split :is: into a size-independent :i1: and a +# size-dependent :is:. Finally, I added / -- esr) + +# NOTE: :ic: has been taken out of this entry. for reference, it should +# be . For discussion, see ICH/ICH1 VERSUS RMIR/SMIR below. +# (esr: added :vi: and :ve: to resolve NetBSD Problem Report #4583) +pcvtXX|pcvt vt200 emulator (DEC VT220):\ + :am:km:mi:ms:xn:\ + :it#8:vt#3:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:SF=\E[%dS:\ + :SR=\E[%dT:UP=\E[%dA:\ + :ac=++\054\054--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz~~:\ + :ae=\E(B:al=\E[L:as=\E(0:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:\ + :cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :ct=\E[3g:dc=\E[P:dl=\E[M:do=\E[B:ei=\E[4l:ho=\E[H:\ + :i1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:im=\E[4h:\ + :k1=\E[17~:k2=\E[18~:k3=\E[19~:k4=\E[20~:k5=\E[21~:\ + :k6=\E[23~:k7=\E[24~:k8=\E[25~:kD=\E[3~:kH=\E[4~:kI=\E[2~:\ + :kN=\E[6~:kP=\E[5~:kb=\177:kd=\EOB:ke=\E[?1l\E>:kh=\E[1~:\ + :kl=\EOD:kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:\ + :md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:nw=\EE:\ + :r1=\Ec\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:rc=\E8:\ + :rf=/usr/share/tabset/vt100:sc=\E7:se=\E[27m:sf=\ED:\ + :so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[24m:up=\E[A:us=\E[4m:\ + :ve=\E[?25h:vi=\E[?25l: + +# NetBSD/FreeBSD vt220 terminal emulator console (pc keyboard & monitor) +# termcap entries for pure VT220-Emulation and 25, 28, 35, 40, 43 and +# 50 lines entries; 80 columns +pcvt25|dec vt220 emulation with 25 lines:\ + :co#80:li#25:\ + :is=\E[1;25r\E[25;1H:tc=pcvtXX: +pcvt28|dec vt220 emulation with 28 lines:\ + :co#80:li#28:\ + :is=\E[1;28r\E[28;1H:tc=pcvtXX: +pcvt35|dec vt220 emulation with 35 lines:\ + :co#80:li#35:\ + :is=\E[1;35r\E[35;1H:tc=pcvtXX: +pcvt40|dec vt220 emulation with 40 lines:\ + :co#80:li#40:\ + :is=\E[1;40r\E[40;1H:tc=pcvtXX: +pcvt43|dec vt220 emulation with 43 lines:\ + :co#80:li#43:\ + :is=\E[1;43r\E[43;1H:tc=pcvtXX: +pcvt50|dec vt220 emulation with 50 lines:\ + :co#80:li#50:\ + :is=\E[1;50r\E[50;1H:tc=pcvtXX: + +# NetBSD/FreeBSD vt220 terminal emulator console (pc keyboard & monitor) +# termcap entries for pure VT220-Emulation and 25, 28, 35, 40, 43 and +# 50 lines entries; 132 columns +pcvt25w|dec vt220 emulation with 25 lines and 132 cols:\ + :co#132:li#25:\ + :is=\E[1;25r\E[25;1H:tc=pcvtXX: +pcvt28w|dec vt220 emulation with 28 lines and 132 cols:\ + :co#132:li#28:\ + :is=\E[1;28r\E[28;1H:tc=pcvtXX: +pcvt35w|dec vt220 emulation with 35 lines and 132 cols:\ + :co#132:li#35:\ + :is=\E[1;35r\E[35;1H:tc=pcvtXX: +pcvt40w|dec vt220 emulation with 40 lines and 132 cols:\ + :co#132:li#40:\ + :is=\E[1;40r\E[40;1H:tc=pcvtXX: +pcvt43w|dec vt220 emulation with 43 lines and 132 cols:\ + :co#132:li#43:\ + :is=\E[1;43r\E[43;1H:tc=pcvtXX: +pcvt50w|dec vt220 emulation with 50 lines and 132 cols:\ + :co#132:li#50:\ + :is=\E[1;50r\E[50;1H:tc=pcvtXX: + +# Terminfo entries to enable the use of the ncurses library in colour on a +# NetBSD-arm32 console (only tested on a RiscPC). +# Created by Dave Millen 22.07.98 +# modified codes for setf/setb to setaf/setab, then to klone+color, corrected +# typo in invis - TD +arm100|arm100-am|Arm(RiscPC) ncurses compatible (for 640x480):\ + :am:ms:ut:xn:xo:\ + :co#80:it#8:li#30:\ + :@8=\E[M:DO=\E[%dB:K1=\E[q:K2=\E[r:K3=\E[s:K4=\E[p:K5=\E[n:\ + :LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:UP=\E[%dA:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\ + :eA=\E(B\E)0:ho=\E[H:k0=\E[y:k1=\E[P:k2=\E[Q:k3=\E[R:\ + :k4=\E[S:k5=\E[t:k6=\E[u:k7=\E[v:k8=\E[l:k9=\E[w:k;=\E[x:\ + :kb=^H:kd=\E[B:ke=\E[?1l\E>:kl=\E[D:kr=\E[C:ks=\E[?1h\E=:\ + :ku=\E[A:le=^H:mb=\E[5m:md=\E[1m:me=\E[m\017:mk=\E[8m:\ + :mr=\E[6m:nd=\E[C:r2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\ + :rc=\E8:\ + :..sa=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;:\ + :sc=\E7:se=\E[m:sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:\ + :up=\E[A:us=\E[4m:\ + :tc=ecma+sgr:tc=klone+color: +arm100-w|arm100-wam|Arm(RiscPC) ncurses compatible (for 1024x768):\ + :co#132:li#50:tc=arm100: + +# NetBSD/x68k console vt200 emulator. This port runs on a 68K machine +# manufactured by Sharp for the Japenese market. +# From Minoura Makoto , 12 May 1996 +x68k|x68k-ite|NetBSD/x68k ITE:\ + :co#96:li#32:\ + :%1=\E[28~:kC=\E[9~:tc=vt220: + +# : +# Entry for the DNARD OpenFirmware console, close to ANSI but not quite. +# +# (still unfinished, but good enough so far.) +ofcons:\ + :bw:\ + :co#80:li#30:\ + :AL=\233%dL:DC=\233%dP:DL=\233%dM:DO=\233%dB:IC=\233%d@:\ + :LE=\233%dD:RI=\233%dC:UP=\233%dA:al=\233L:bl=^G:cd=\233J:\ + :ce=\233K:cl=^L:cm=\233%i%d;%dH:cr=^M:dc=\233P:dl=\233M:\ + :do=\233B:ei=:ic=\233@:im=:k1=\2330P:k2=\2330Q:k3=\2330W:\ + :k4=\2330x:k5=\2330t:k6=\2330u:k7=\2330q:k8=\2330r:\ + :k9=\2330p:k;=\2330M:kD=\233P:kN=\233/:kP=\233?:kb=^H:\ + :kd=\233B:kl=\233D:kr=\233C:ku=\233A:le=\233D:mb=\2337;2m:\ + :md=\2331m:me=\2330m:mh=\2332m:mk=\2338m:mr=\2337m:\ + :nd=\233C:nw=^M^J:se=\2330m:sf=^J:ta=^I:ue=\2330m:up=\233A:\ + :vb=^G: + +# NetBSD "wscons" emulator in vt220 mode +# These are micro-minimal and probably need to be redone for real +# after the manner of the pcvt entries. +wsvt25|NetBSD wscons in 25 line DEC VT220 mode:\ + :co#80:li#25:tc=vt220: + +wsvt25m|NetBSD wscons in 25 line DEC VT220 mode with Meta:\ + :km:\ + :co#80:li#25:tc=vt220: + +# `rasterconsole' provided by 4.4BSD, NetBSD and OpenBSD on SPARC, and +# DECstation/pmax. +rcons|BSD rasterconsole:\ + :tc=sun-il: +# Color version of above. Color currenly only provided by NetBSD. +rcons-color|BSD rasterconsole with ANSI color:\ + :ut:\ + :Co#8:pa#64:\ + :AB=\E[4%dm:AF=\E[3%dm:op=\E[m:tc=rcons: + +#### FreeBSD console entries +# +# From: Andrey Chernov 29 Mar 1996 +# Andrey Chernov maintains the FreeBSD termcap distributions. +# +# Note: Users of FreeBSD 2.1.0 and older versions must either upgrade +# or comment out the :cb: capability in the console entry. +# +# Alexander Lukyanov reports: +# I have seen FreeBSD-2.1.5R... The old el1 bug changed, but it is still there. +# Now el1 clears not only to the line beginning, but also a large chunk +# of previous line. But there is another bug - ech does not work at all. +# + +# for syscons +# common entry without semigraphics +# Bug: The capability resets attributes. +# Bug? The ech and el1 attributes appear to move the cursor in some cases; for +# instance el1 does if the cursor is moved to the right margin first. Removed +# by T.Dickey 97/5/3 (ech=\E[%p1%dX, el1=\E[1K) +# +# Setting colors turns off reverse; we cannot guarantee order, so use ncv. +# Note that this disables standout with color. +cons25w|ansiw|ansi80x25-raw|freebsd console (25-line raw mode):\ + :NP:am:bw:eo:ms:ut:\ + :Co#8:NC#21:co#80:it#8:li#25:pa#64:\ + :@7=\E[F:AB=\E[4%p1%dm:AF=\E[3%p1%dm:AL=\E[%dL:DC=\E[%dP:\ + :DL=\E[%dM:DO=\E[%dB:F1=\E[W:F2=\E[X:IC=\E[%d@:K2=\E[E:\ + :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\ + :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:ch=\E[%i%d`:\ + :cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:cv=\E[%i%dd:dc=\E[P:\ + :dl=\E[M:do=\E[B:ei=:ho=\E[H:ic=\E[@:im=:k1=\E[M:k2=\E[N:\ + :k3=\E[O:k4=\E[P:k5=\E[Q:k6=\E[R:k7=\E[S:k8=\E[T:k9=\E[U:\ + :k;=\E[V:kB=\E[Z:kD=\177:kI=\E[L:kN=\E[G:kP=\E[I:kb=^H:\ + :kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mb=\E[5m:\ + :md=\E[1m:me=\E[m:mh=\E[30;1m:mr=\E[7m:nd=\E[C:nw=\E[E:\ + :op=\E[x:r1=\E[x\E[m\Ec:se=\E[m:sf=\E[S:so=\E[7m:sr=\E[T:\ + :ta=^I:up=\E[A:ve=\E[=0C:vs=\E[=1C: +cons25|ansis|ansi80x25|freebsd console (25-line ansi mode):\ + :ac=-\030.^Y0\333`\004a\260f\370g\361h\261i\025j\331k\277l\332m\300n\305q\304t\303u\264v\301w\302x\263y\363z\362~\371:\ + :tc=cons25w: +cons25-m|ansis-mono|ansi80x25-mono|freebsd console (25-line mono ansi mode):\ + :Co@:pa@:\ + :AB@:AF@:md@:mh@:op@:ue=\E[m:us=\E[4m:tc=cons25: +cons30|ansi80x30|freebsd console (30-line ansi mode):\ + :li#30:tc=cons25: +cons30-m|ansi80x30-mono|freebsd console (30-line mono ansi mode):\ + :li#30:tc=cons25-m: +cons43|ansi80x43|freebsd console (43-line ansi mode):\ + :li#43:tc=cons25: +cons43-m|ansi80x43-mono|freebsd console (43-line mono ansi mode):\ + :li#43:tc=cons25-m: +cons50|ansil|ansi80x50|freebsd console (50-line ansi mode):\ + :li#50:tc=cons25: +cons50-m|ansil-mono|ansi80x50-mono|freebsd console (50-line mono ansi mode):\ + :li#50:tc=cons25-m: +cons60|ansi80x60|freebsd console (60-line ansi mode):\ + :li#60:tc=cons25: +cons60-m|ansi80x60-mono|freebsd console (60-line mono ansi mode):\ + :li#60:tc=cons25-m: +cons25r|pc3r|ibmpc3r|cons25-koi8-r|freebsd console w/koi8-r cyrillic:\ + :ac=-\030.^Y0\215`\004a\220f\234h\221i\025j\205k\203l\202m\204n\212q\0t\206u\207v\211w\210x\201y\230z\231~\225:\ + :tc=cons25w: +cons25r-m|pc3r-m|ibmpc3r-mono|cons25-koi8r-m|freebsd console w/koi8-r cyrillic (mono):\ + :Co@:pa@:\ + :AB@:AF@:op@:ue=\E[m:us=\E[4m:tc=cons25r: +cons50r|cons50-koi8r|freebsd console w/koi8-r cyrillic (50 lines):\ + :li#50:tc=cons25r: +cons50r-m|cons50-koi8r-m|freebsd console w/koi8-r cyrillic (50-line mono):\ + :li#50:tc=cons25r-m: +cons60r|cons60-koi8r|freebsd console w/koi8-r cyrillic (60 lines):\ + :li#60:tc=cons25r: +cons60r-m|cons60-koi8r-m|freebsd console w/koi8-r cyrillic (60-line mono):\ + :li#60:tc=cons25r-m: +# ISO 8859-1 FreeBSD console +cons25l1|cons25-iso8859|freebsd console w/iso 8859-1 chars:\ + :ac=+\253\054\273-\030.\031`\201a\202f\207g\210i\247j\213k\214l\215m\216n\217o\220p\221q\222r\223s\224t\225u\226v\227w\230x\231y\232z\233~\237:\ + :tc=cons25w: +cons25l1-m|cons25-iso-m|freebsd console w/iso 8859-1 chars (mono):\ + :Co@:pa@:\ + :AB@:AF@:md@:mh@:op@:ue=\E[m:us=\E[4m:tc=cons25l1: +cons50l1|cons50-iso8859|freebsd console w/iso 8859-1 chars (50 lines):\ + :li#50:tc=cons25l1: +cons50l1-m|cons50-iso-m|freebsd console w/iso 8859-1 chars (50-line mono):\ + :li#50:tc=cons25l1-m: +cons60l1|cons60-iso|freebsd console w/iso 8859-1 chars (60 lines):\ + :li#60:tc=cons25l1: +cons60l1-m|cons60-iso-m|freebsd console w/iso 8859-1 chars (60-line mono):\ + :li#60:tc=cons25l1-m: + +#### 386BSD and BSD/OS Consoles +# + +# This was the original 386BSD console entry (I think). +# Some places it's named oldpc3|oldibmpc3. +# From: Alex R.N. Wetmore +origpc3|origibmpc3|IBM PC 386BSD Console:\ + :am:bw:eo:xo:\ + :co#80:li#25:\ + :ac=j\331k\277l\332m\300n\305q\304t\303u\264v\301w\302x\263:\ + :cd=\E[J:ce=\E[K:cl=\Ec:cm=\E[%i%2;%2H:do=\E[B:ho=\E[H:\ + :kd=\E[B:kh=\E[Y:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:md=\E[7m:\ + :me=\E[m\E[1;0x\E[2;7x:nd=\E[C:se=\E[1;0x\E[2;7x:\ + :sf=\E[S:so=\E[1;7x\E[2;0x:sr=\E[T:ue=\E[1;0x\E[2;7x:\ + :up=\E[A:us=\E[1;7x\E[2;0x: + +# description of BSD/386 console emulator in version 1.0 (supplied by BSDI) +oldpc3|oldibmpc3|old IBM PC BSD/386 Console:\ + :km:\ + :li#25:\ + :al=\E[L:bl=^G:cr=^M:dl=\E[M:do=^J:kH=\E[F:kI=\E[L:kN=\E[G:\ + :kP=\E[I:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\ + :md=\E[=15F:me=\E[=R:mh=\E[=8F:nw=^M^J:sf=^J:ta=^I: + +# Description of BSD/OS console emulator in version 1.1, 2.0, 2.1 +# Note, the emulator supports many of the additional console features +# listed in the iBCS2 (e.g. character-set selection) though not all +# are described here. This entry really ought to be upgraded. +# Also note, the console will also work with fewer lines after doing +# "stty rows NN", e.g. to use 24 lines. +# (Color support from Kevin Rosenberg , 2 May 1996) +# Bug: The capability resets attributes. +bsdos-pc-nobold|BSD/OS PC console w/o bold:\ + :am:eo:km:xo:\ + :co#80:it#8:li#25:\ + :AL=\E[%dL:DL=\E[%dM:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:\ + :UP=\E[%dA:al=\E[L:bl=^G:cd=\E[J:ce=\E[K:cl=\Ec:\ + :cm=\E[%i%d;%dH:cr=^M:dl=\E[M:do=^J:ho=\E[H:kH=\E[F:\ + :kI=\E[L:kN=\E[G:kP=\E[I:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:\ + :kr=\E[C:ku=\E[A:le=^H:nd=\E[C:nw=^M^J:rc=\E8:\ + :..sa=\E[0;10%?%p1%t;7%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m%?%p5%t\E[=8F%;:\ + :sc=\E7:sf=^J:ta=^I:up=\E[A:\ + :tc=klone+sgr:tc=klone+color: +bsdos-pc|IBM PC BSD/OS Console:\ + :..sa=\E[0;10%?%p1%t;7%;%?%p2%t;1%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m:tc=bsdos-pc-nobold: + +# Old names for BSD/OS PC console used in releases before 4.1. +pc3|BSD/OS on the PC Console:\ + :tc=bsdos-pc-nobold: +ibmpc3|pc3-bold|BSD/OS on the PC Console with bold instead of underline:\ + :tc=bsdos-pc: + +# BSD/OS on the SPARC +bsdos-sparc|Sun SPARC BSD/OS Console:\ + :tc=sun: + +# BSD/OS on the PowerPC +bsdos-ppc|PowerPC BSD/OS Console:\ + :tc=bsdos-pc: + +#### DEC VT100 and compatibles +# +# DEC terminals from the vt100 forward are collected here. Older DEC terminals +# and micro consoles can be found in the `obsolete' section. More details on +# the relationship between the VT100 and ANSI X3.64/ISO 6429/ECMA-48 may be +# found near the end of this file. +# +# Except where noted, these entries are DEC's official terminfos. +# Contact Bill Hedberg of Terminal Support +# Engineering for more information. Updated terminfos and termcaps +# are kept available at ftp://gatekeeper.dec.com/pub/DEC/termcaps. +# +# In October 1995 DEC sold its terminals business, including the VT and Dorio +# line and trademark, to SunRiver Data Systems. SunRiver has since changed +# its name to Boundless Technologies; see http://www.boundless.com. +# + +# NOTE: Any VT100 emulation, whether in hardware or software, almost +# certainly includes what DEC called the `Level 1 editing extension' codes; +# only the very oldest VT100s lacked these and there probably aren't any of +# those left alive. To capture these, use one of the VT102 entries. +# +# Note that the :xn: glitch in vt100 is not quite the same as on the Concept, +# since the cursor is left in a different position while in the +# weird state (concept at beginning of next line, vt100 at end +# of this line) so all versions of vi before 3.7 don't handle +# :xn: right on vt100. The correct way to handle :xn: is when +# you output the char in column 80, immediately output CR LF +# and then assume you are in column 1 of the next line. If :xn: +# is on, am should be on too. +# +# I assume you have smooth scroll off or are at a slow enough baud +# rate that it doesn't matter (1200? or less). Also this assumes +# that you set auto-nl to "on", if you set it off use vt100-nam +# below. +# +# The padding requirements listed here are guesses. It is strongly +# recommended that xon/xoff be enabled, as this is assumed here. +# +# The vt100 uses and rather than :is:/:ct:/:st: because the +# tab settings are in non-volatile memory and don't need to be +# reset upon login. Also setting the number of columns glitches +# the screen annoyingly. You can type "reset" to get them set. +# +# The VT100 series terminals have cursor ("arrows") keys which can operate +# in two different modes: Cursor Mode and Application Mode. Cursor Mode +# is the reset state, and is assumed to be the normal state. Application +# Mode is the "set" state. In Cursor Mode, the cursor keys transmit +# "Esc [ {code}" sequences, conforming to ANSI standards. In Application +# Mode, the cursor keys transmit "Esc O " sequences. Application Mode +# was provided primarily as an aid to the porting of VT52 applications. It is +# assumed that the cursor keys are normally in Cursor Mode, and expected that +# applications such as vi will always transmit the :ks: string. Therefore, +# the definitions for the cursor keys are made to match what the terminal +# transmits after the :ks: string is transmitted. If the :ks: string +# is a null string or is not defined, then cursor keys are assumed to be in +# "Cursor Mode", and the cursor keys definitions should match that assumption, +# else the appication may fail. It is also expected that applications will +# always transmit the :ke: string to the terminal before they exit. +# +# The VT100 series terminals have an auxilliary keypad, commonly referred to as +# the "Numeric Keypad", because it is a cluster of numeric and function keys. +# The Numeric Keypad which can operate in two different modes: Numeric Mode and +# Application Mode. Numeric Mode is the reset state, and is assumed to be +# the normal state. Application Mode is the "set" state. In Numeric Mode, +# the numeric and punctuation keys transmit ASCII 7-bit characters, and the +# Enter key transmits the same as the Return key (Note: the Return key +# can be configured to send either LF (\015) or CR LF). In Application Mode, +# all the keypad keys transmit "Esc O {code}" sequences. The PF1 - PF4 keys +# always send the same "Esc O {code}" sequences. It is assumed that the keypad +# is normally in Numeric Mode. If an application requires that the keypad be +# in Application Mode then it is expected that the user, or the application, +# will set the TERM environment variable to point to a terminfo entry which has +# defined the :ks: string to include the codes that switch the keypad into +# Application Mode, and the terminfo entry will also define function key +# fields to match the Application Mode control codes. If the :ks: string +# is a null string or is not defined, then the keypad is assumed to be in +# Numeric Mode. If the :ks: string switches the keypad into Application +# Mode, it is expected that the :ke: string will contain the control codes +# necessary to reset the keypad to "Normal" mode, and it is also expected that +# applications which transmit the :ks: string will also always transmit the +# :ke: string to the terminal before they exit. +# +# Here's a diagram of the VT100 keypad keys with their bindings. +# The top line is the name of the key (some DEC keyboards have the keys +# labelled somewhat differently, like GOLD instead of PF1, but this is +# the most "official" name). The second line is the escape sequence it +# generates in Application Keypad mode (where "$" means the ESC +# character). The third line contains two items, first the mapping of +# the key in terminfo, and then in termcap. +# _______________________________________ +# | PF1 | PF2 | PF3 | PF4 | +# | $OP | $OQ | $OR | $OS | +# |_kf1__k1_|_kf2__k2_|_kf3__k3_|_kf4__k4_| +# | 7 8 9 - | +# | $Ow | $Ox | $Oy | $Om | +# |_kf9__k9_|_kf10_k;_|_kf0__k0_|_________| +# | 4 | 5 | 6 | , | +# | $Ot | $Ou | $Ov | $Ol | +# |_kf5__k5_|_kf6__k6_|_kf7__k7_|_kf8__k8_| +# | 1 | 2 | 3 | | +# | $Oq | $Or | $Os | enter | +# |_ka1__K1_|_kb2__K2_|_ka3__K3_| $OM | +# | 0 | . | | +# | $Op | $On | | +# |___kc1_______K4____|_kc3__K5_|_kent_@8_| +# +# And here, for those of you with orphaned VT100s lacking documentation, is +# a description of the soft switches invoked when you do `Set Up'. +# +# Scroll 0-Jump Shifted 3 0-# +# | 1-Smooth | 1-British pound sign +# | Autorepeat 0-Off | Wrap Around 0-Off +# | | 1-On | | 1-On +# | | Screen 0-Dark Bkg | | New Line 0-Off +# | | | 1-Light Bkg | | | 1-On +# | | | Cursor 0-Underline | | | Interlace 0-Off +# | | | | 1-Block | | | | 1-On +# | | | | | | | | +# 1 1 0 1 1 1 1 1 0 1 0 0 0 0 1 0 <--Standard Settings +# | | | | | | | | +# | | | Auto XON/XOFF 0-Off | | | Power 0-60 Hz +# | | | 1-On | | | 1-50 Hz +# | | Ansi/VT52 0-VT52 | | Bits Per Char. 0-7 Bits +# | | 1-ANSI | | 1-8 Bits +# | Keyclick 0-Off | Parity 0-Off +# | 1-On | 1-On +# Margin Bell 0-Off Parity Sense 0-Odd +# 1-On 1-Even +# +# The following SET-UP modes are assumed for normal operation: +# ANSI_MODE AUTO_XON/XOFF_ON NEWLINE_OFF 80_COLUMNS +# WRAP_AROUND_ON JUMP_SCROLL_OFF +# Other SET-UP modes may be set for operator convenience or communication +# requirements; I recommend +# AUTOREPEAT_ON BLOCK_CURSOR MARGIN_BELL_OFF SHIFTED_3_# +# Unless you have a graphics add-on such as Digital Engineering's VT640 +# (and even then, whenever it can be arranged!) you should set +# INTERLACE_OFF +# +# (vt100: I added / based on the init string, also :bs:. -- esr) +vt100|vt100-am|dec vt100 (w/advanced video):\ + :am:bs:ms:xn:xo:\ + :co#80:it#8:li#24:vt#3:\ + :@8=\EOM:DO=\E[%dB:K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:\ + :LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:UP=\E[%dA:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\ + :eA=\E(B\E)0:ho=\E[H:k0=\EOy:k1=\EOP:k2=\EOQ:k3=\EOR:\ + :k4=\EOS:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\ + :kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:kr=\EOC:ks=\E[?1h\E=:\ + :ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:me=\E[m\017:mr=\E[7m:\ + :nd=\E[C:r2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:rc=\E8:\ + :..sa=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;:\ + :sc=\E7:se=\E[m:sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:\ + :up=\E[A:us=\E[4m: +vt100nam|vt100-nam|vt100 no automargins:\ + :am@:xn@:tc=vt100-am: +vt100-vb|dec vt100 (w/advanced video) & no beep:\ + :bl@:vb=\E[?5h\E[?5l:tc=vt100: + +# Ordinary vt100 in 132 column ("wide") mode. +vt100-w|vt100-w-am|dec vt100 132 cols (w/advanced video):\ + :co#132:li#24:\ + :r2=\E>\E[?3h\E[?4l\E[?5l\E[?8h:tc=vt100-am: +vt100-w-nam|vt100-nam-w|dec vt100 132 cols (w/advanced video no automargin):\ + :co#132:li#14:vt@:\ + :r2=\E>\E[?3h\E[?4l\E[?5l\E[?8h:tc=vt100-nam: + +# vt100 with no advanced video. +vt100-nav|vt100 without advanced video option:\ + :sg#1:\ + :mb@:md@:me@:mr@:sa@:se=\E[m:so=\E[7m:ue@:us@:tc=vt100: +vt100-nav-w|vt100-w-nav|dec vt100 132 cols 14 lines (no advanced video option):\ + :co#132:li#14:tc=vt100-nav: + +# vt100 with one of the 24 lines used as a status line. +# We put the status line on the top. +vt100-s|vt100-s-top|vt100-top-s|vt100 for use with top sysline:\ + :es:hs:\ + :li#23:\ + :cl=\E[2;1H\E[J:cm=\E[%i%+^A;%dH:cs=\E[%i%i%d;%dr:\ + :ds=\E7\E[1;24r\E8:fs=\E8:ho=\E[2;1H:is=\E7\E[2;24r\E8:\ + :ts=\E7\E[1;%p1%dH\E[1K:\ + :tc=vt100-am: + +# Status line at bottom. +# Clearing the screen will clobber status line. +vt100-s-bot|vt100-bot-s|vt100 for use with bottom sysline:\ + :es:hs:\ + :li#23:\ + :ds=\E7\E[1;24r\E8:fs=\E8:is=\E[1;23r\E[23;1H:\ + :ts=\E7\E[24;%p1%dH\E[1K:\ + :tc=vt100-am: + +# Most of the `vt100' emulators out there actually emulate a vt102 +# This entry (or vt102-nsgr) is probably the right thing to use for +# these. +vt102|dec vt102:\ + :mi:\ + :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100: +vt102-w|dec vt102 in wide mode:\ + :co#132:\ + :r3=\E[?3h:tc=vt102: + +# Many brain-dead PC comm programs that pretend to be `vt100-compatible' +# fail to interpret the ^O and ^N escapes properly. Symptom: the :me: +# string in the canonical vt100 entry above leaves the screen littered +# with little snowflake or star characters (IBM PC ROM character \017 = ^O) +# after highlight turnoffs. This entry should fix that, and even leave +# ACS support working, at the cost of making multiple-highlight changes +# slightly more expensive. +# From: Eric S. Raymond July 22 1995 +vt102-nsgr|vt102 no sgr (use if you see snowflakes after highlight changes):\ + :me=\E[m:sa@:\ + :tc=vt102: + +# VT125 Graphics CRT. Clear screen also erases graphics +vt125|vt125 graphics terminal:\ + :cl=\E[H\E[2J\EPpS(E)\E\:tc=vt100: + +# This isn't a DEC entry, it came from University of Wisconsin. +# (vt131: I added / based on the init string, also :bs: -- esr) +vt131|dec vt131:\ + :am:bs:xn:\ + :co#80:it#8:li#24:vt#3:\ + :RA=\E[?7h:SA=\E[?7h:bl=^G:cd=50\E[J:ce=3\E[K:\ + :cl=50\E[;H\E[2J:cm=5\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :do=^J:ho=\E[H:is=\E[1;24r\E[24;1H:k1=\EOP:k2=\EOQ:\ + :k3=\EOR:k4=\EOS:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\ + :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=2\E[5m:md=2\E[1m:\ + :me=2\E[m:mr=2\E[7m:nd=2\E[C:nw=^M^J:\ + :r1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:rc=\E8:sc=\E7:\ + :se=2\E[m:so=2\E[7m:sr=5\EM:ta=^I:ue=2\E[m:up=2\E[A:\ + :us=2\E[4m: + +# vt132 - like vt100 but slower and has ins/del line and such. +# I'm told that :im:/:ei: are backwards in the terminal from the +# manual and from the ANSI standard, this describes the actual +# terminal. I've never actually used a vt132 myself, so this +# is untested. +# +vt132|DEC vt132:\ + :xn:\ + :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4h:im=\E[4l:ip=:sf=\n:tc=vt100: + +# This vt220 description maps F5--F9 to the second block of function keys +# at the top of the keyboard. The "DO" key is used as F10 to avoid conflict +# with the key marked (ESC) on the vt220. See vt220d for an alternate mapping. +# PF1--PF4 are used as F1--F4. +# +vt220-old|vt200-old|DEC VT220 in vt100 emulation mode:\ + :am:bs:mi:pt:xn:xo:\ + :co#80:li#24:vt#3:\ + :@7=\E[4~:RA=\E[?7l:SA=\E[?7h:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:ce=\E[K:\ + :cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :dc=\E[P:dl=\E[M:do=\E[B:ei=\E[4l:ho=\E[H:\ + :if=/usr/share/tabset/vt100:im=\E[4h:\ + :is=\E[1;24r\E[24;1H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:\ + :k5=\E[17~:k6=\E[18~:k7=\E[19~:k8=\E[20~:k9=\E[21~:\ + :k;=\E[29~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:kb=^H:\ + :kd=\E[B:kh=\E[1~:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mb=\E[5m:\ + :md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:nl=^J:\ + :r2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:rc=\E8:\ + :rf=/usr/share/tabset/vt100:\ + :..sa=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;:\ + :sc=\E7:se=\E[27m:sf=20\ED:so=\E[7m:sr=14\EM:ta=^I:\ + :ue=\E[24m:up=\E[A:us=\E[4m:ve=\E[?25h:vi=\E[?25l: + +# A much better description of the VT200/220; used to be vt220-8 +# (untranslatable capabilities removed to fit entry within 1023 bytes) +# (sgr removed to fit entry within 1023 bytes) +# (terminfo-only capabilities suppressed to fit entry within 1023 bytes) +vt220|vt200|dec vt220:\ + :am:bs:mi:ms:xn:xo:\ + :co#80:it#8:li#24:vt#3:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:ae=^O:al=\E[L:as=^N:bl=^G:\ + :cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:\ + :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:ec=\E[%dX:\ + :ei=\E[4l:ho=\E[H:if=/usr/share/tabset/vt100:im=\E[4h:\ + :is=\E[?7h\E[>\E[?1h\E F\E[?4l:k1=\EOP:k2=\EOQ:k3=\EOR:\ + :k4=\EOS:k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:kI=\E[2~:\ + :kN=\E[6~:kP=\E[5~:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:\ + :ku=\E[A:le=^H:mb=\E[5m:md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:\ + :nw=\EE:rc=\E8:sc=\E7:se=\E[27m:sf=\ED:so=\E[7m:sr=\EM:\ + :st=\EH:ta=^I:ue=\E[24m:up=\E[A:us=\E[4m:vb=\E[?5h\E[?5l: +vt220-w|vt200-w|DEC vt220 in wide mode:\ + :co#132:\ + :r3=\E[?3h:tc=vt220: +# (untranslatable capabilities removed to fit entry within 1023 bytes) +# (sgr removed to fit entry within 1023 bytes) +# (terminfo-only capabilities suppressed to fit entry within 1023 bytes) +vt220-8bit|vt220-8|vt200-8bit|vt200-8|dec vt220/200 in 8-bit mode:\ + :am:bs:mi:ms:xn:xo:\ + :co#80:it#8:li#24:vt#3:\ + :AL=\233%dL:DC=\233%dP:DL=\233%dM:DO=\233%dB:IC=\233%d@:\ + :LE=\233%dD:RI=\233%dC:UP=\233%dA:ae=^O:al=\233L:as=^N:\ + :bl=^G:cd=\233J:ce=\233K:cl=\233H\233J:cm=\233%i%d;%dH:\ + :cr=^M:cs=\233%i%d;%dr:ct=\2333g:dc=\233P:dl=\233M:do=^J:\ + :ec=\233%dX:ei=\2334l:ho=\233H:\ + :if=/usr/share/tabset/vt100:im=\2334h:\ + :is=\233?7h\233>\233?1h\E F\233?4l:k1=\EOP:k2=\EOQ:\ + :k3=\EOR:k4=\EOS:k6=\23317~:k7=\23318~:k8=\23319~:\ + :k9=\23320~:kI=\2332~:kN=\2336~:kP=\2335~:kb=^H:kd=\233B:\ + :kh=\233H:kl=\233D:kr=\233C:ku=\233A:le=^H:mb=\2335m:\ + :md=\2331m:me=\233m:mr=\2337m:nd=\233C:nw=\EE:rc=\E8:\ + :sc=\E7:se=\23327m:sf=\ED:so=\2337m:sr=\EM:st=\EH:ta=^I:\ + :ue=\23324m:up=\233A:us=\2334m:vb=\233?5h\233?5l: + +# +# vt220d: +# This vt220 description regards F6--F10 as the second block of function keys +# at the top of the keyboard. This mapping follows the description given +# in the VT220 Programmer Reference Manual and agrees with the labeling +# on some terminals that emulate the vt220. There is no support for an F5. +# See vt220 for an alternate mapping. +# +vt220d|DEC VT220 in vt100 mode with DEC function key labeling:\ + :F1=\E[23~:F2=\E[24~:F3=\E[25~:F4=\E[26~:F5=\E[28~:\ + :F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:k5@:\ + :k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:\ + :tc=vt220-old: + +vt220-nam|v200-nam|VT220 in vt100 mode with no auto margins:\ + :am@:\ + :r2=\E>\E[?3l\E[?4l\E[?5l\E[?7l\E[?8h:tc=vt220: + +# vt220 termcap written Tue Oct 25 20:41:10 1988 by Alex Latzko +# (not an official DEC entry!) +# The problem with real vt220 terminals is they don't send escapes when in +# in vt220 mode. This can be gotten around two ways. 1> don't send +# escapes or 2> put the vt220 into vt100 mode and use all the nifty +# features of vt100 advanced video which it then has. +# +# This entry takes the view of putting a vt220 into vt100 mode so +# you can use the escape key in emacs and everything else which needs it. +# +# You probably don't want to use this on a VMS machine since VMS will think +# it has a vt220 and will get fouled up coming out of emacs +# +# From: Alexander Latzko , 30 Dec 1996 +# (Added vt100 :rc:,:sc: to quiet a tic warning -- esr) +vt200-js|vt220-js|dec vt200 series with jump scroll:\ + :am:\ + :co#80:\ + :al=\E[L:bl=^G:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:\ + :cr=^M:cs=\E[%i%d;%dr:dc=\E[P:dl=\E[M:dm=:do=^J:ed=:\ + :ei=\E[4l:ho=\E[H:im=\E[4h:\ + :is=\E[61"p\E[H\E[?3l\E[?4l\E[?1l\E[?5l\E[?6l\E[?7h\E[?8h\E[?25h\E>\E[m:\ + :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:kb=^H:kd=\EOB:\ + :ke=\E[?1l\E>:kl=\EOD:kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:\ + :nw=^M\ED:r1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:rc=\E8:\ + :rf=/usr/lib/tabset/vt100:sc=\E7:se=5\E[27m:sf=\ED:\ + :so=5\E[7m:sr=\EM:ta=^I:ue=\E[24m:up=\E[A:us=\E[4m: + + +# This was DEC's vt320. Use the purpose-built one below instead +#vt320|DEC VT320 in vt100 emulation mode, +# use=vt220, + +# +# Use v320n for SCO's LYRIX. Otherwise, use Adam Thompson's vt320-nam. +# +vt320nam|v320n|DEC VT320 in vt100 emul. mode with NO AUTO WRAP mode:\ + :am@:\ + :r2=\E>\E[?3l\E[?4l\E[?5l\E[?7l\E[?8h:tc=vt220: + +# These entries are not DEC's official ones, they were purpose-built for the +# VT320. Here are the designer's notes: +# is end on a PC kbd. Actually 'select' on a VT. Mapped to +# 'Erase to End of Field'... since nothing seems to use 'end' anyways... +# khome is Home on a PC kbd. Actually 'FIND' on a VT. +# Things that use usually use tab anyways... and things that don't use +# tab usually use instead... +# kprv is same as tab - Backtab is useless... +# I left out :sa: because of its RIDICULOUS complexity, +# and the resulting fact that it causes the termcap translation of the entry +# to SMASH the 1k-barrier... +# From: Adam Thompson Sept 10 1995 +# (vt320: uncommented :fs:, comnmmented out to avoid a conflict --esr) +# (untranslatable capabilities removed to fit entry within 1023 bytes) +# (sgr removed to fit entry within 1023 bytes) +# (terminfo-only capabilities suppressed to fit entry within 1023 bytes) +vt320|vt300|dec vt320 7 bit terminal:\ + :am:es:hs:mi:ms:xn:\ + :co#80:li#24:ws#80:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :K1=\EOw:K2=\EOu:K3=\EOy:K4=\EOq:K5=\EOs:LE=\E[%dD:\ + :RI=\E[%dC:UP=\E[%dA:ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:\ + :ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:\ + :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:ec=\E[%dX:\ + :ei=\E[4l:fs=\E[0$}:ho=\E[H:im=\E[4h:\ + :is=\E>\E[?3l\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H:\ + :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k6=\E[17~:k7=\E[18~:\ + :k8=\E[19~:k9=\E[20~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:\ + :kb=\177:kd=\EOB:ke=\E[?1l\E>:kh=\E[1~:kl=\EOD:kr=\EOC:\ + :ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:me=\E[m:\ + :mr=\E[7m:nd=\E[C:nw=\EE:rc=\E8:sc=\E7:se=\E[m:sf=\ED:\ + :so=\E[7m:sr=\EM:st=\EH:ta=^I:ts=\E[1$}\E[H\E[K:ue=\E[m:\ + :up=\E[A:us=\E[4m:ve=\E[?25h:vi=\E[?25l: +vt320-nam|vt300-nam|dec vt320 7 bit terminal with no am to make SAS happy:\ + :am@:\ + :is=\E>\E[?3l\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H:\ + :r2=\E>\E[?3l\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H:\ + :tc=vt320: +# We have to init 132-col mode, not 80-col mode. +vt320-w|vt300-w|dec vt320 wide 7 bit terminal:\ + :co#132:ws#132:\ + :is=\E>\E[?3h\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H:\ + :r2=\E>\E[?3h\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H:\ + :tc=vt320: +vt320-w-nam|vt300-w-nam|dec vt320 wide 7 bit terminal with no am:\ + :am@:\ + :is=\E>\E[?3h\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H:\ + :r2=\E>\E[?3h\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H:\ + :tc=vt320-w: + +# VT330 and VT340 -- These are ReGIS and SIXEL graphics terminals +# which are pretty much a superset of the VT320. They have the +# host writable status line, yet another different DRCS matrix size, +# and such, but they add the DEC Technical character set, Multiple text +# pages, selectable length pages, and the like. The difference between +# the vt330 and vt340 is that the latter has only 2 planes and a monochrome +# monitor, the former has 4 planes and a color monitor. These terminals +# support VT131 and ANSI block mode, but as with much of these things, +# termcap/terminfo doesn't deal with these features. +# +# Note that this entry is are set up in what was the standard way for GNU +# Emacs v18 terminal modes to deal with the cursor keys in that the arrow +# keys were switched into application mode at the same time the numeric pad +# is switched into application mode. This changes the definitions of the +# arrow keys. Emacs v19 is smarter and mines its keys directly out of +# your termcap or terminfo entry, +# +# From: Daniel Glasser , 13 Oct 1993 +# (vt340: string capability "sb=\E[M" corrected to "sr"; +# also, added / based on the init string -- esr) +vt340|dec-vt340|vt330|dec-vt330|dec vt340 graphics terminal with 24 line page:\ + :am:es:hs:mi:ms:xn:xo:\ + :co#80:it#8:li#24:vt#3:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:UP=\E[%dA:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=^O:al=\E[L:as=^N:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:\ + :dl=\E[M:do=^J:ds=\E[2$~\r\E[1$}\E[K\E[$}:ei=\E[4l:\ + :fs=\E[$}:ho=\E[H:im=\E[4h:\ + :is=\E<\E F\E>\E[?1h\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E[1;24r\E[24;1H:\ + :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k6=\E[17~:k7=\E[18~:\ + :k8=\E[19~:k9=\E[20~:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\ + :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:l1=pf1:l2=pf2:l3=pf3:l4=pf4:\ + :le=^H:mb=\E[5m:md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:nw=^M\ED:\ + :r1=\E[?3l:rc=\E8:rf=/usr/share/tabset/vt300:sc=\E7:\ + :se=\E[27m:sf=\ED:so=\E[7m:sr=\EM:st=\EH:ta=^I:\ + :ts=\E[2$~\E[1$}\E[1;%dH:ue=\E[24m:up=\E[A:us=\E[4m:\ + :vb=200\E[?5h\E[?5l:ve=\E[?25h:vi=\E[?25l:vs=\E[?25h: + +# DEC doesn't supply a vt400 description, so we add Daniel Glasser's +# (originally written with vt420 as its primary name, and usable for it). +# +# VT400/420 -- This terminal is a superset of the vt320. It adds the multiple +# text pages and long text pages with selectable length of the vt340, along +# with left and right margins, rectangular area text copy, fill, and erase +# operations, selected region character attribute change operations, +# page memory and rectangle checksums, insert/delete column, reception +# macros, and other features too numerous to remember right now. TERMCAP +# can only take advantage of a few of these added features. +# +# Note that this entry is are set up in what was the standard way for GNU +# Emacs v18 terminal modes to deal with the cursor keys in that the arrow +# keys were switched into application mode at the same time the numeric pad +# is switched into application mode. This changes the definitions of the +# arrow keys. Emacs v19 is smarter and mines its keys directly out of +# your termcap entry, +# +# From: Daniel Glasser , 13 Oct 1993 +# (vt400: string capability ":sb=\E[M:" corrected to ":sr=\E[M:"; +# also, added / based on the init string -- esr) +# (untranslatable capabilities removed to fit entry within 1023 bytes) +# (sgr removed to fit entry within 1023 bytes) +# (terminfo-only capabilities suppressed to fit entry within 1023 bytes) +vt400|vt400-24|dec-vt400|dec vt400 24x80 column autowrap:\ + :am:es:hs:mi:ms:xn:xo:\ + :co#80:it#8:li#24:vt#3:\ + :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + :LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:ae=^O:al=\E[L:as=^N:\ + :cd=10\E[J:ce=4\E[K:cl=10\E[H\E[J:cm=\E[%i%d;%dH:cr=^M:\ + :cs=\E[%i%d;%dr:ct=\E[3g:dc=\E[P:dl=\E[M:do=^J:\ + :ds=\E[2$~\r\E[1$}\E[K\E[$}:ei=\E[4l:fs=\E[$}:ho=\E[H:\ + :ic=\E[@:im=\E[4h:\ + :is=\E<\E F\E>\E[?1h\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E[1;24r\E[24;1H:\ + :k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k6=\E[17~:k7=\E[18~:\ + :k8=\E[19~:k9=\E[20~:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\ + :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\ + :me=\E[m:mr=\E[7m:nd=\E[C:nw=^M\ED:rc=\E8:sc=\E7:se=\E[27m:\ + :sf=\ED:so=\E[7m:sr=\EM:st=\EH:ta=^I:\ + :ts=\E[2$~\E[1$}\E[1;%dH:ue=\E[24m:up=\E[A:us=\E[4m:\ + :vb=200\E[?5h\E[?5l:ve=\E[?25h:vi=\E[?25l:vs=\E[?25h: + +# (vt420: I removed :k0:, it collided with . I also restored +# a missing :sc: -- esr) +vt420|DEC VT420:\ + :am:mi:xn:xo:\ + :co#80:li#24:vt#3:\ + :*6=\E[4~:@0=\E[1~:RA=\E[?7l:\ + :S5=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\ + :SA=\E[?7h:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:ce=\E[K:\ + :cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :dc=\E[P:dl=\E[M:do=\E[B:ei=\E[4l:ho=\E[H:\ + :i2=\E[?67h\E[64;1"p:if=/usr/share/tabset/vt300:\ + :im=\E[4h:is=\E[1;24r\E[24;1H:k1=\EOP:k2=\EOQ:k3=\EOR:\ + :k4=\EOS:k5=\E[17~:k6=\E[18~:k7=\E[19~:k8=\E[20~:\ + :k9=\E[21~:k;=\E[29~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:\ + :kb=^H:kd=\E[B:ke=\E>:kl=\E[D:kr=\E[C:ks=\E=:ku=\E[A:le=^H:\ + :mb=\E[5m:md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:\ + :r3=\E[?67h\E[64;1"p:rc=\E8:rf=/usr/share/tabset/vt300:\ + :..sa=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;:\ + :sc=\E7:se=\E[m:sf=\ED:so=\E[7m:sr=\EM:ta=^I:ue=\E[m:\ + :up=\E[A:us=\E[4m: + +# +# DEC VT220 and up support DECUDK (user-defined keys). DECUDK (i.e., pfx) +# takes two parameters, the key and the string. Translating the key is +# straightforward (keys 1-5 are not defined on real terminals, though some +# emulators define these): +# +# if (key < 16) then value = key; +# else if (key < 21) then value = key + 1; +# else if (key < 25) then value = key + 2; +# else if (key < 27) then value = key + 3; +# else if (key < 30) then value = key + 4; +# else value = key + 5; +# +# The string must be the hexadecimal equivalent, e.g., "5052494E" for "PRINT". +# There's no provision in terminfo for emitting a string in this format, so the +# application has to know it. +# +vt420pc|DEC VT420 w/PC keyboard:\ + :@7=\E[4~:F1=\E[23~:F2=\E[24~:F3=\E[11;2~:F4=\E[12;2~:\ + :F5=\E[13;2~:F6=\E[14;2~:F7=\E[15;2~:F8=\E[17;2~:\ + :F9=\E[18;2~:FA=\E[19;2~:FB=\E[20;2~:FC=\E[21;2~:\ + :FD=\E[23;2~:FE=\E[24;2~:FF=\E[23~:FG=\E[24~:FH=\E[25~:\ + :FI=\E[26~:FJ=\E[28~:FK=\E[29~:FL=\E[31~:FM=\E[32~:\ + :FN=\E[33~:FO=\E[34~:FP=\E[35~:FQ=\E[36~:FR=\E[23;2~:\ + :FS=\E[24;2~:FT=\E[25;2~:FU=\E[26;2~:FV=\E[28;2~:\ + :FW=\E[29;2~:FX=\E[31;2~:FY=\E[32;2~:FZ=\E[33;2~:\ + :Fa=\E[34;2~:Fb=\E[35;2~:Fc=\E[36;2~:\ + :S6=USR_TERM\072vt420pcdos\072:k1=\E[11~:k2=\E[12~:\ + :k3=\E[13~:k4=\E[14~:k5=\E[15~:k6=\E[17~:k7=\E[18~:\ + :k8=\E[19~:k9=\E[20~:k;=\E[21~:kD=\177:kh=\E[H:\ + :..px=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\:tc=vt420: + +vt420pcdos|DEC VT420 w/PC for DOS Merge:\ + :li#25:\ + :S1=%?%p2%{19}%=%t\E\023\021%e%p2%{32}%<%t\E%p2%c%e%p2%{127}%=%t\E\177%e%p2%c%;:\ + :S4=\E[?1;2r\E[34h:\ + :S5=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:S6@:\ + :me=\E[m:sa@:\ + :tc=vt420pc: + +vt420f|DEC VT420 with VT kbd; VT400 mode; F1-F5 used as Fkeys:\ + :F1=\E[23~:F2=\E[24~:F3=\E[25~:F4=\E[26~:F5=\E[28~:\ + :F6=\E[29~:F7=\E[31~:F8=\E[32~:F9=\E[33~:FA=\E[34~:\ + :k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~:k5=\E[15~:\ + :k6=\E[17~:k7=\E[18~:k8=\E[19~:k9=\E[20~:k;=\E[21~:\ + :kD=\177:kh=\E[H:l1=\EOP:l2=\EOQ:l3=\EOR:l4=\EOS:\ + :tc=vt420: + +vt510|DEC VT510:\ + :tc=vt420: +vt510pc|DEC VT510 w/PC keyboard:\ + :tc=vt420pc: +vt510pcdos|DEC VT510 w/PC for DOS Merge:\ + :tc=vt420pcdos: + +# VT520/VT525 +# +# The VT520 is a monochrome text terminal capable of managing up to +# four independent sessions in the terminal. It has multiple ANSI +# emulations (VT520, VT420, VT320, VT220, VT100, VT PCTerm, SCO Console) +# and ASCII emulations (WY160/60, PCTerm, 50/50+, 150/120, TVI 950, +# 925 910+, ADDS A2). This terminfo data is for the ANSI emulations only. +# +# Terminal Set-Up is entered by pressing [F3], [Caps Lock]/[F3] or +# [Alt]/[Print Screen] depending upon which keyboard and which +# terminal mode is being used. If Set-Up has been disabled or +# assigned to an unknown key, Set-Up may be entered by pressing +# [F3] as the first key after power up, regardless of keyboard type. +# (vt520: I added / based on the init string, also :sc: -- esr) +# (untranslatable capabilities removed to fit entry within 1023 bytes) +vt520|DEC VT520:\ + :am:mi:xn:xo:\ + :co#80:li#24:vt#3:\ + :*6=\E[4~:@0=\E[1~:RA=\E[?7l:\ + :S5=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\ + :SA=\E[?7h:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:ce=\E[K:\ + :cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :dc=\E[P:dl=\E[M:do=\E[B:ei=\E[4l:ho=\E[H:\ + :i2=\E[?67h\E[64;1"p:if=/usr/share/tabset/vt300:\ + :im=\E[4h:is=\E[1;24r\E[24;1H:k0=\E[29~:k1=\EOP:k2=\EOQ:\ + :k3=\EOR:k4=\EOS:k5=\E[17~:k6=\E[18~:k7=\E[19~:k8=\E[20~:\ + :k9=\E[21~:k;=\E[29~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:\ + :kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mb=\E[5m:\ + :md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:r3=\E[?67h\E[64;1"p:\ + :rc=\E8:rf=/usr/share/tabset/vt300:sc=\E7:se=\E[m:sf=\ED:\ + :so=\E[7m:sr=\EM:ta=^I:ue=\E[m:up=\E[A:us=\E[4m: + +# (vt525: I added / based on the init string; +# removed :se:=\E[m, :ue:=\E[m, added :sc: -- esr) +# (untranslatable capabilities removed to fit entry within 1023 bytes) +vt525|DEC VT525:\ + :am:mi:xn:xo:\ + :co#80:li#24:vt#3:\ + :*6=\E[4~:@0=\E[1~:RA=\E[?7l:\ + :S5=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\ + :SA=\E[?7h:\ + :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + :ae=\E(B:al=\E[L:as=\E(0:bl=^G:cd=\E[J:ce=\E[K:\ + :cl=\E[H\E[2J:cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:\ + :dc=\E[P:dl=\E[M:do=\E[B:ei=\E[4l:ho=\E[H:\ + :i2=\E[?67h\E[64;1"p:if=/usr/share/tabset/vt300:\ + :im=\E[4h:is=\E[1;24r\E[24;1H:k0=\E[29~:k1=\EOP:k2=\EOQ:\ + :k3=\EOR:k4=\EOS:k5=\E[17~:k6=\E[18~:k7=\E[19~:k8=\E[20~:\ + :k9=\E[21~:k;=\E[29~:kD=\E[3~:kI=\E[2~:kN=\E[6~:kP=\E[5~:\ + :kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:le=^H:mb=\E[5m:\ + :md=\E[1m:me=\E[m:mr=\E[7m:nd=\E[C:r3=\E[?67h\E[64;1"p:\ + :rc=\E8:rf=/usr/share/tabset/vt300:sc=\E7:se=\E[m:sf=\ED:\ + :so=\E[7m:sr=\EM:ta=^I:ue=\E[m:up=\E[A:us=\E[4m: diff --git a/tests/examplefiles/terminfo b/tests/examplefiles/terminfo new file mode 100644 index 00000000..2b68d035 --- /dev/null +++ b/tests/examplefiles/terminfo @@ -0,0 +1,1445 @@ +######## This example from excerpt of : +# +# Version 11.0.1 +# $Date: 2000/03/02 15:51:11 $ +# terminfo syntax +# + +######## ANSI, UNIX CONSOLE, AND SPECIAL TYPES +# +# This section describes terminal classes and brands that are still +# quite common. +# + +#### Specials +# +# Special "terminals". These are used to label tty lines when you don't +# know what kind of terminal is on it. The characteristics of an unknown +# terminal are the lowest common denominator - they look about like a ti 700. +# + +dumb|80-column dumb tty, + am, + cols#80, + bel=^G, cr=^M, cud1=^J, ind=^J, +unknown|unknown terminal type, + gn, use=dumb, +lpr|printer|line printer, + hc, os, + cols#132, lines#66, + bel=^G, cr=^M, cub1=^H, cud1=^J, ff=^L, ind=^J, +glasstty|classic glass tty interpreting ASCII control characters, + am, + cols#80, + bel=^G, clear=^L, cr=^M, cub1=^H, cud1=^J, ht=^I, kcub1=^H, + kcud1=^J, nel=^M^J, +vanilla, + bel=^G, cr=^M, cud1=^J, ind=^J, + +#### ANSI.SYS/ISO 6429/ECMA-48 Capabilities +# +# See the end-of-file comment for more on these. +# + +# ANSI capabilities are broken up into pieces, so that a terminal +# implementing some ANSI subset can use many of them. +ansi+local1, + cub1=\E[D, cud1=\E[B, cuf1=\E[C, cuu1=\E[A, +ansi+local, + cub=\E[%p1%dD, cud=\E[%p1%dB, cuf=\E[%p1%dC, + cuu=\E[%p1%dA, + use=ansi+local1, +ansi+tabs, + cbt=\E[Z, ht=^I, hts=\EH, tbc=\E[2g, +ansi+inittabs, + it#8, use=ansi+tabs, +ansi+erase, + clear=\E[H\E[J, ed=\E[J, el=\E[K, +ansi+rca, + hpa=\E[%p1%{1}%+%dG, vpa=\E[%p1%{1}%+%dd, +ansi+cup, + cup=\E[%i%p1%d;%p2%dH, home=\E[H, +ansi+rep, + rep=%p1%c\E[%p2%{1}%-%db, +ansi+idl1, + dl1=\E[M, il1=\E[L, +ansi+idl, + dl=\E[%p1%dM, il=\E[%p1%dL, use=ansi+idl1, +ansi+idc, + dch1=\E[P, ich=\E[%p1%d@, ich1=\E[@, rmir=\E6, smir=\E6, +ansi+arrows, + kbs=^H, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + khome=\E[H, +ansi+sgr|ansi graphic renditions, + blink=\E[5m, invis=\E[8m, rev=\E[7m, sgr0=\E[0m, +ansi+sgrso|ansi standout only, + rmso=\E[m, smso=\E[7m, +ansi+sgrul|ansi underline only, + rmul=\E[m, smul=\E[4m, +ansi+sgrbold|ansi graphic renditions; assuming terminal has bold; not dim, + bold=\E[1m, + sgr=\E[%?%p1%t7;%;%?%p2%t4;%;%?%p3%t7;%;%?%p4%t5;%;%?%p6%t1;%;m, use=ansi+sgr, use=ansi+sgrso, use=ansi+sgrul, +ansi+sgrdim|ansi graphic renditions; assuming terminal has dim; not bold, + dim=\E[2m, + sgr=\E[%?%p1%t7;%;%?%p2%t4;%;%?%p3%t7;%;%?%p4%t5;%;%?%p5%t2;%;m, use=ansi+sgr, use=ansi+sgrso, use=ansi+sgrul, +ansi+pp|ansi printer port, + mc0=\E[0i, mc4=\E[4i, mc5=\E[5i, +ansi+csr|ansi scroll-region plus cursor save & restore, + csr=\E[%i%p1%d;%p2%dr, rc=\E8, sc=\E7, + +# The IBM PC alternate character set. Plug this into any Intel console entry. +# We use \E[11m for rmacs rather than \E[12m so the string can use the +# ROM graphics for control characters such as the diamond, up- and down-arrow. +# This works with the System V, Linux, and BSDI consoles. It's a safe bet this +# will work with any Intel console, they all seem to have inherited \E[11m +# from the ANSI.SYS de-facto standard. +klone+acs|alternate character set for ansi.sys displays, + acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, + rmacs=\E[10m, smacs=\E[11m, + +# Highlight controls corresponding to the ANSI.SYS standard. Most +# console drivers for Intel boxes obey these. Makes the same assumption +# about \E[11m as klone+acs. True ANSI/ECMA-48 would have , +# , but this isn't a documented feature of ANSI.SYS. +klone+sgr|attribute control for ansi.sys displays, + blink=\E[5m, bold=\E[1m, invis=\E[8m, rev=\E[7m, + rmpch=\E[10m, rmso=\E[m, rmul=\E[m, + sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, + sgr0=\E[0;10m, smpch=\E[11m, smso=\E[7m, smul=\E[4m, + use=klone+acs, + +# Highlight controls corresponding to the ANSI.SYS standard. *All* +# console drivers for Intel boxes obey these. Does not assume \E[11m will +# work; uses \E[12m instead, which is pretty bulletproof but loses you the ACS +# diamond and arrow characters under curses. +klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m), + blink=\E[5m, bold=\E[1m, invis=\E[8m, rev=\E[7m, rmso=\E[m, + rmul=\E[m, + sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;12%;m, + sgr0=\E[0;10m, smacs=\E[12m, smso=\E[7m, smul=\E[4m, + use=klone+acs, + +# KOI8-R (RFC1489) acs (alternate character set) +# From: Qing Long , 24 Feb 1996. +klone+koi8acs|alternate character set for ansi.sys displays with KOI8 charset, + acsc=+\020\,\021-\036.^_0\215`\004a\237f\234g\232h\222i\220j\205k\203l\202m\204n\212o\213p\216q\0r\217s\214t\206u\207v\210w\211x\201y\230z\231{\267|\274}L~\225, + rmacs=\E[10m, smacs=\E[11m, + +# ANSI.SYS color control. The setab/setaf caps depend on the coincidence +# between SVr4/XPG4's color numbers and ANSI.SYS attributes. Here are longer +# but equivalent strings that don't rely on that coincidence: +# setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, +# setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m, +# The DOS 5 manual asserts that these sequences meet the ISO 6429 standard. +# They match a subset of ECMA-48. +klone+color|color control for ansi.sys and ISO6429-compatible displays, + colors#8, ncv#3, pairs#64, + op=\E[37;40m, setab=\E[4%p1%dm, setaf=\E[3%p1%dm, + +# This is better than klone+color, it doesn't assume white-on-black as the +# default color pair, but many `ANSI' terminals don't grok the cap. +ecma+color|color control for ECMA-48-compatible terminals, + colors#8, ncv#3, pairs#64, + op=\E[39;49m, setab=\E[4%p1%dm, setaf=\E[3%p1%dm, + +# Attribute control for ECMA-48-compatible terminals +ecma+sgr|attribute capabilities for true ECMA-48 terminals, + rmso=\E[27m, rmul=\E[24m, + use=klone+sgr, + +# For comparison, here are all the capabilities implied by the Intel +# Binary Compatibility Standard (level 2) that fit within terminfo. +# For more detail on this rather pathetic standard, see the comments +# near the end of this file. +ibcs2|Intel Binary Compatibility Standard prescriptions, + cbt=\E[Z, clear=\Ec, cub=\E[%p1%dD, cud=\E[%p1%dB, + cuf=\E[%p1%dC, cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, + dch=\E[%p1%dP, dispc=\E=%p1%dg, ech=\E[%p1%dX, + hpa=\E[%i%p1%dG, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, + indn=\E[%p1%dS, rc=\E7, rin=\E[%p1%dT, rmam=\E[?7l, sc=\E7, + smam=\E[?7h, tbc=\E[g, vpa=\E[%i%p1%dd, + +#### ANSI/ECMA-48 terminals and terminal emulators +# +# See near the end of this file for details on ANSI conformance. +# Don't mess with these entries! Lots of other entries depend on them! +# +# This section lists entries in a least-capable to most-capable order. +# if you're in doubt about what `ANSI' matches yours, try them in that +# order and back off from the first that breaks. + +# ansi-mr is for ANSI terminals with ONLY relative cursor addressing +# and more than one page of memory. It uses local motions instead of +# direct cursor addressing, and makes almost no assumptions. It does +# assume auto margins, no padding and/or xon/xoff, and a 24x80 screen. +ansi-mr|mem rel cup ansi, + am, xon, + cols#80, lines#24, use=vanilla, use=ansi+erase, + use=ansi+local1, + +# ansi-mini is a bare minimum ANSI terminal. This should work on anything, but +# beware of screen size problems and memory relative cursor addressing. +ansi-mini|minimum ansi standard terminal, + am, xon, + cols#80, lines#24, use=vanilla, use=ansi+cup, + use=ansi+erase, + +# ansi-mtabs adds relative addressing and minimal tab support +ansi-mtabs|any ansi terminal with pessimistic assumptions, + it#8, + ht=^I, use=ansi+local1, use=ansi-mini, + +# ANSI X3.64 from emory!mlhhh (Hugh Hansard) via BRL +# +# The following is an entry for the full ANSI 3.64 (1977). It lacks +# padding, but most terminals using the standard are "fast" enough +# not to require any -- even at 9600 bps. If you encounter problems, +# try including the padding specifications. +# +# Note: the :as: and :ae: specifications are not implemented here, for +# the available termcap documentation does not make clear WHICH alternate +# character set to specify. ANSI 3.64 seems to make allowances for several. +# Please make the appropriate adjustments to fit your needs -- that is +# if you will be using alternate character sets. +# +# There are very few terminals running the full ANSI 3.64 standard, +# so I could only test this entry on one verified terminal (Visual 102). +# I would appreciate the results on other terminals sent to me. +# +# Please report comments, changes, and problems to: +# +# U.S. MAIL: Hugh Hansard +# Box: 22830 +# Emory University +# Atlanta, GA. 30322. +# +# USENET {akgua,msdc,sb1,sb6,gatech}!emory!mlhhh. +# +# (Added vt100 , to quiet a tic warning --esr) +ansi77|ansi 3.64 standard 1977 version, + am, mir, + cols#80, it#8, lines#24, + bel=^G, clear=\E[;H\E[2J, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=\E[B, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, + cuu1=\E[A, dch1=\E[P, dl1=\E[M$<5*/>, ed=\E[J, el=\E[K, + home=\E[H, ht=^I, il1=\E[L$<5*/>, ind=\ED, kbs=^H, + kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, kf1=\EOP, + kf2=\EOR, kf4=\EOS, khome=\E[H, nel=^M\ED, rc=\E8, ri=\EM, + rmir=\E[4l, rmso=\E[m, rmul=\E[m, sc=\E7, smir=\E[4h, + smso=\E[7m, smul=\E[4m, + +# Procomm and some other ANSI emulations don't recognize all of the ANSI- +# standard capabilities. This entry deletes , , , , and +# / capabilities, forcing curses to use repetitions of , +# , and . Also deleted and , as QModem up to +# 5.03 doesn't recognize these. Finally, we delete and , which seem +# to confuse many emulators. On the other hand, we can count on these programs +# doing //. Older versions of this entry featured +# , but now seems to be more common under +# ANSI.SYS influence. +# From: Eric S. Raymond Oct 30 1995 +pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode), + am, mir, msgr, + cols#80, it#8, lines#24, + bel=^G, cbt=\E[Z, clear=\E[H\E[J, cr=^M, cub1=\E[D, + cud1=\E[B, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, + dch1=\E[P, dl1=\E[M, ed=\E[J, el=\E[K, home=\E[H, ht=^I, + hts=\EH, il1=\E[L, ind=^J, kbs=^H, kcub1=\E[D, kcud1=\E[B, + kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, tbc=\E[2g, + use=klone+sgr-dumb, +pcansi-25-m|pcansi25m|ibm-pc terminal programs with 25 lines (mono mode), + lines#25, use=pcansi-m, +pcansi-33-m|pcansi33m|ibm-pc terminal programs with 33 lines (mono mode), + lines#33, use=pcansi-m, +pcansi-43-m|ansi43m|ibm-pc terminal programs with 43 lines (mono mode), + lines#43, use=pcansi-m, +# The color versions. All PC emulators do color... +pcansi|ibm-pc terminal programs claiming to be ansi, + use=klone+color, use=pcansi-m, +pcansi-25|pcansi25|ibm-pc terminal programs with 25 lines, + lines#25, use=pcansi, +pcansi-33|pcansi33|ibm-pc terminal programs with 33 lines, + lines#33, use=pcansi, +pcansi-43|pcansi43|ibm-pc terminal programs with 43 lines, + lines#43, use=pcansi, + +# ansi-m -- full ANSI X3.64 with ANSI.SYS-compatible attributes, no color. +# If you want pound signs rather than dollars, replace `B' with `A' +# in the , , , and capabilities. +# From: Eric S. Raymond Nov 6 1995 +ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes, + mc5i, + cub=\E[%p1%dD, cud=\E[%p1%dB, cuf=\E[%p1%dC, + cuu=\E[%p1%dA, dch=\E[%p1%dP, dl=\E[%p1%dM, + ech=\E[%p1%dX, el1=\E[1K, hpa=\E[%i%p1%dG, ht=\E[I, + ich=\E[%p1%d@, il=\E[%p1%dL, indn=\E[%p1%dS, kbs=^H, + kcbt=\E[Z, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kich1=\E[L, mc4=\E[4i, mc5=\E[5i, nel=\r\E[S, + rep=%p1%c\E[%p2%{1}%-%db, rin=\E[%p1%dT, s0ds=\E(B, + s1ds=\E)B, s2ds=\E*B, s3ds=\E+B, tbc=\E[2g, + vpa=\E[%i%p1%dd, use=pcansi-m, + +# ansi -- this terminfo expresses the largest subset of X3.64 that will fit in +# standard terminfo. Assumes ANSI.SYS-compatible attributes and color. +# From: Eric S. Raymond Nov 6 1995 +ansi|ansi/pc-term compatible with color, + u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?%[;0123456789]c, + u9=\E[c, + use=ecma+color, use=klone+sgr, use=ansi-m, + +# ansi-generic is a vanilla ANSI terminal. This is assumed to implement +# all the normal ANSI stuff with no extensions. It assumes +# insert/delete line/char is there, so it won't work with +# vt100 clones. It assumes video attributes for bold, blink, +# underline, and reverse, which won't matter much if the terminal +# can't do some of those. Padding is assumed to be zero, which +# shouldn't hurt since xon/xoff is assumed. +ansi-generic|generic ansi standard terminal, + am, xon, + cols#80, lines#24, use=vanilla, use=ansi+csr, use=ansi+cup, + use=ansi+rca, use=ansi+erase, use=ansi+tabs, + use=ansi+local, use=ansi+idc, use=ansi+idl, use=ansi+rep, + use=ansi+sgrbold, use=ansi+arrows, + +#### Linux consoles +# + +# This entry is good for the 1.2.13 or later version of the Linux console. +# +# *************************************************************************** +# * * +# * WARNING: * +# * Linuxes come with a default keyboard mapping kcbt=^I. This entry, in * +# * response to user requests, assumes kcbt=\E[Z, the ANSI/ECMA reverse-tab * +# * character. Here are the keymap replacement lines that will set this up: * +# * * +# keycode 15 = Tab Tab +# alt keycode 15 = Meta_Tab +# shift keycode 15 = F26 +# string F26 ="\033[Z" +# * * +# * This has to use a key slot which is unfortunate (any unused one will * +# * do, F26 is the higher-numbered one). The change ought to be built * +# * into the kernel tables. * +# * * +# *************************************************************************** +# +# The 1.3.x kernels add color-change capabilities; if yours doesn't have this +# and it matters, turn off . The %02x escape used to implement this is +# not back-portable to SV curses and not supported in ncurses versions before +# 1.9.9. All linux kernels since 1.2.13 (at least) set the screen size +# themselves; this entry assumes that capability. +# +# This entry is good for the 1.2.13 or later version of the Linux console. +# +# *************************************************************************** +# * * +# * WARNING: * +# * Linuxes come with a default keyboard mapping kcbt=^I. This entry, in * +# * response to user requests, assumes kcbt=\E[Z, the ANSI/ECMA reverse-tab * +# * character. Here are the keymap replacement lines that will set this up: * +# * * +# keycode 15 = Tab Tab +# alt keycode 15 = Meta_Tab +# shift keycode 15 = F26 +# string F26 ="\033[Z" +# * * +# * This has to use a key slot which is unfortunate (any unused one will * +# * do, F26 is the higher-numbered one). The change ought to be built * +# * into the kernel tables. * +# * * +# *************************************************************************** +# +# The 1.3.x kernels add color-change capabilities; if yours doesn't have this +# and it matters, turn off . The %02x escape used to implement this is +# not back-portable to SV curses and not supported in ncurses versions before +# 1.9.9. All linux kernels since 1.2.13 (at least) set the screen size +# themselves; this entry assumes that capability. +# +# The 2.2.x kernels add a private mode that sets the cursor type; use that to +# get a block cursor for cvvis. +# reported by Frank Heckenbach . +linux|linux console, + am, bce, eo, mir, msgr, xenl, xon, + it#8, ncv#2, + acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, + bel=^G, civis=\E[?25l\E[?1c, clear=\E[H\E[J, + cnorm=\E[?25h\E[?0c, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=^J, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, + cuu1=\E[A, cvvis=\E[?25h\E[?8c, dch=\E[%p1%dP, dch1=\E[P, + dim=\E[2m, dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, + el=\E[K, el1=\E[1K, flash=\E[?5h\E[?5l$<200/>, home=\E[H, + hpa=\E[%i%p1%dG, ht=^I, hts=\EH, ich=\E[%p1%d@, ich1=\E[@, + il=\E[%p1%dL, il1=\E[L, ind=^J, kb2=\E[G, kbs=\177, + kcbt=\E[Z, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kdch1=\E[3~, kend=\E[4~, kf1=\E[[A, kf10=\E[21~, + kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, + kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, + kf19=\E[33~, kf2=\E[[B, kf20=\E[34~, kf3=\E[[C, kf4=\E[[D, + kf5=\E[[E, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, + khome=\E[1~, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, kspd=^Z, + nel=^M^J, rc=\E8, rev=\E[7m, ri=\EM, rmir=\E[4l, rmso=\E[27m, + rmul=\E[24m, rs1=\Ec\E]R, sc=\E7, + sgr=\E[0;10%?%p1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p5%t;2%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, + smir=\E[4h, smul=\E[4m, tbc=\E[3g, u6=\E[%i%d;%dR, + u7=\E[6n, u8=\E[?6c, u9=\E[c, vpa=\E[%i%p1%dd, + use=klone+sgr, use=ecma+color, +linux-m|Linux console no color, + colors@, pairs@, + setab@, setaf@, setb@, setf@, use=linux, +linux-c-nc|linux console 1.3.x hack for ncurses only, + ccc, + initc=\E]P%p1%x%p2%{255}%*%{1000}%/%02x%p3%{255}%*%{1000}%/%02x%p4%{255}%*%{1000}%/%02x, + oc=\E]R, + use=linux, +# From: Dennis Henriksen , 9 July 1996 +linux-c|linux console 1.3.6+ with private palette for each virtual console, + ccc, + colors#8, pairs#64, + initc=\E]P%?%p1%{9}%>%t%p1%{10}%-%'a'%+%c%e%p1%d%;%p2%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%p3%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%p4%{255}%&%Pr%gr%{16}%/%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;%gr%{15}%&%Px%?%gx%{9}%>%t%gx%{10}%-%'A'%+%c%e%gx%d%;, + oc=\E]R, + use=linux, + +# See the note on ICH/ICH1 VERSUS RMIR/SMIR near the end of file +linux-nic|linux with ich/ich1 suppressed for non-curses programs, + ich@, ich1@, + use=linux, + +# This assumes you have used setfont(8) to load one of the Linux koi8-r fonts. +# acsc entry from Pavel Roskin" , 29 Sep 1997. +linux-koi8|linux with koi8 alternate character set, + acsc=+\020\,\021-\030.^Y0\215`\004a\221f\234g\237h\220i\276j\205k\203l\202m\204n\212o~p\0q\0r\0s_t\206u\207v\211w\210x\201y\230z\231{\267|\274~\224, + use=linux, use=klone+koi8acs, + +# Another entry for KOI8-r with Qing Long's acsc. +# (which one better complies with the standard?) +linux-koi8r|linux with koi8-r alternate character set, + use=linux, use=klone+koi8acs, + +# Entry for the latin1 and latin2 fonts +linux-lat|linux with latin1 or latin2 alternate character set, + acsc=+\020\,\021-\030.^Y0\333`\004a\013f\370g\361h\260i\316j\211k\214l\206m\203n\305o~p\304q\212r\304s_t\207u\215v\301w\302x\205y\363z\362{\343|\330}\234~\376, + use=linux, + +#### NetBSD consoles +# +# pcvt termcap database entries (corresponding to release 3.31) +# Author's last edit-date: [Fri Sep 15 20:29:10 1995] +# +# (For the terminfo master file, I translated these into terminfo syntax. +# Then I dropped all the pseudo-HP entries. we don't want and can't use +# the :Xs: flag. Then I split :is: into a size-independent and a +# size-dependent . Finally, I added / -- esr) + +# NOTE: has been taken out of this entry. for reference, it should +# be . For discussion, see ICH/ICH1 VERSUS RMIR/SMIR below. +# (esr: added and to resolve NetBSD Problem Report #4583) +pcvtXX|pcvt vt200 emulator (DEC VT220), + am, km, mir, msgr, xenl, + it#8, vt#3, + acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz~~, + bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l, + clear=\E[H\E[J, cnorm=\E[?25h, cr=^M, + csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, + cud=\E[%p1%dB, cud1=\E[B, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, + el=\E[K, el1=\E[1K, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, + il=\E[%p1%dL, il1=\E[L, ind=\ED, indn=\E[%p1%dS, + is1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, kbs=\177, + kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, + kdch1=\E[3~, kf1=\E[17~, kf2=\E[18~, kf3=\E[19~, + kf4=\E[20~, kf5=\E[21~, kf6=\E[23~, kf7=\E[24~, kf8=\E[25~, + khome=\E[1~, kich1=\E[2~, kll=\E[4~, knp=\E[6~, kpp=\E[5~, + nel=\EE, rc=\E8, rev=\E[7m, rf=/usr/share/tabset/vt100, + ri=\EM, rin=\E[%p1%dT, rmacs=\E(B, rmam=\E[?7l, rmir=\E[4l, + rmkx=\E[?1l\E>, rmso=\E[27m, rmul=\E[24m, + rs1=\Ec\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, + sgr0=\E[m, smacs=\E(0, smam=\E[?7h, smir=\E[4h, + smkx=\E[?1h\E=, smso=\E[7m, smul=\E[4m, tbc=\E[3g, + +# NetBSD/FreeBSD vt220 terminal emulator console (pc keyboard & monitor) +# termcap entries for pure VT220-Emulation and 25, 28, 35, 40, 43 and +# 50 lines entries; 80 columns +pcvt25|dec vt220 emulation with 25 lines, + cols#80, lines#25, + is2=\E[1;25r\E[25;1H, use=pcvtXX, +pcvt28|dec vt220 emulation with 28 lines, + cols#80, lines#28, + is2=\E[1;28r\E[28;1H, use=pcvtXX, +pcvt35|dec vt220 emulation with 35 lines, + cols#80, lines#35, + is2=\E[1;35r\E[35;1H, use=pcvtXX, +pcvt40|dec vt220 emulation with 40 lines, + cols#80, lines#40, + is2=\E[1;40r\E[40;1H, use=pcvtXX, +pcvt43|dec vt220 emulation with 43 lines, + cols#80, lines#43, + is2=\E[1;43r\E[43;1H, use=pcvtXX, +pcvt50|dec vt220 emulation with 50 lines, + cols#80, lines#50, + is2=\E[1;50r\E[50;1H, use=pcvtXX, + +# NetBSD/FreeBSD vt220 terminal emulator console (pc keyboard & monitor) +# termcap entries for pure VT220-Emulation and 25, 28, 35, 40, 43 and +# 50 lines entries; 132 columns +pcvt25w|dec vt220 emulation with 25 lines and 132 cols, + cols#132, lines#25, + is2=\E[1;25r\E[25;1H, use=pcvtXX, +pcvt28w|dec vt220 emulation with 28 lines and 132 cols, + cols#132, lines#28, + is2=\E[1;28r\E[28;1H, use=pcvtXX, +pcvt35w|dec vt220 emulation with 35 lines and 132 cols, + cols#132, lines#35, + is2=\E[1;35r\E[35;1H, use=pcvtXX, +pcvt40w|dec vt220 emulation with 40 lines and 132 cols, + cols#132, lines#40, + is2=\E[1;40r\E[40;1H, use=pcvtXX, +pcvt43w|dec vt220 emulation with 43 lines and 132 cols, + cols#132, lines#43, + is2=\E[1;43r\E[43;1H, use=pcvtXX, +pcvt50w|dec vt220 emulation with 50 lines and 132 cols, + cols#132, lines#50, + is2=\E[1;50r\E[50;1H, use=pcvtXX, + +# Terminfo entries to enable the use of the ncurses library in colour on a +# NetBSD-arm32 console (only tested on a RiscPC). +# Created by Dave Millen 22.07.98 +# modified codes for setf/setb to setaf/setab, then to klone+color, corrected +# typo in invis - TD +arm100|arm100-am|Arm(RiscPC) ncurses compatible (for 640x480), + am, bce, msgr, xenl, xon, + cols#80, it#8, lines#30, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, + clear=\E[H\E[J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, + cuf=\E[%p1%dC, cuf1=\E[C$<2>, + cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, + cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>, + enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=^J, + invis=\E[8m$<2>, ka1=\E[q, ka3=\E[s, kb2=\E[r, kbs=^H, + kc1=\E[p, kc3=\E[n, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, + kcuu1=\E[A, kent=\E[M, kf0=\E[y, kf1=\E[P, kf10=\E[x, + kf2=\E[Q, kf3=\E[R, kf4=\E[S, kf5=\E[t, kf6=\E[u, kf7=\E[v, + kf8=\E[l, kf9=\E[w, rc=\E8, rev=\E[6m$<2>, ri=\EM$<5>, + rmacs=^O, rmam=\E[?7l, rmkx=\E[?1l\E>, rmso=\E[m$<2>, + rmul=\E[m$<2>, rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, + sc=\E7, + sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;, + sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=, + smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g, + use=ecma+sgr, use=klone+color, +arm100-w|arm100-wam|Arm(RiscPC) ncurses compatible (for 1024x768), + cols#132, lines#50, use=arm100, + +# NetBSD/x68k console vt200 emulator. This port runs on a 68K machine +# manufactured by Sharp for the Japenese market. +# From Minoura Makoto , 12 May 1996 +x68k|x68k-ite|NetBSD/x68k ITE, + cols#96, lines#32, + kclr=\E[9~, khlp=\E[28~, use=vt220, + +# : +# Entry for the DNARD OpenFirmware console, close to ANSI but not quite. +# +# (still unfinished, but good enough so far.) +ofcons, + bw, + cols#80, lines#30, + bel=^G, blink=\2337;2m, bold=\2331m, clear=^L, cr=^M, + cub=\233%p1%dD, cub1=\233D, cud=\233%p1%dB, cud1=\233B, + cuf=\233%p1%dC, cuf1=\233C, cup=\233%i%p1%d;%p2%dH, + cuu=\233%p1%dA, cuu1=\233A, dch=\233%p1%dP, dch1=\233P, + dim=\2332m, dl=\233%p1%dM, dl1=\233M, ed=\233J, el=\233K, + flash=^G, ht=^I, ich=\233%p1%d@, ich1=\233@, il=\233%p1%dL, + il1=\233L, ind=^J, invis=\2338m, kbs=^H, kcub1=\233D, + kcud1=\233B, kcuf1=\233C, kcuu1=\233A, kdch1=\233P, + kf1=\2330P, kf10=\2330M, kf2=\2330Q, kf3=\2330W, + kf4=\2330x, kf5=\2330t, kf6=\2330u, kf7=\2330q, kf8=\2330r, + kf9=\2330p, knp=\233/, kpp=\233?, nel=^M^J, rev=\2337m, + rmso=\2330m, rmul=\2330m, sgr0=\2330m, + +# NetBSD "wscons" emulator in vt220 mode +# These are micro-minimal and probably need to be redone for real +# after the manner of the pcvt entries. +wsvt25|NetBSD wscons in 25 line DEC VT220 mode, + cols#80, lines#25, use=vt220, + +wsvt25m|NetBSD wscons in 25 line DEC VT220 mode with Meta, + km, + cols#80, lines#25, use=vt220, + +# `rasterconsole' provided by 4.4BSD, NetBSD and OpenBSD on SPARC, and +# DECstation/pmax. +rcons|BSD rasterconsole, + use=sun-il, +# Color version of above. Color currenly only provided by NetBSD. +rcons-color|BSD rasterconsole with ANSI color, + bce, + colors#8, pairs#64, + op=\E[m, setab=\E[4%dm, setaf=\E[3%dm, use=rcons, + +#### FreeBSD console entries +# +# From: Andrey Chernov 29 Mar 1996 +# Andrey Chernov maintains the FreeBSD termcap distributions. +# +# Note: Users of FreeBSD 2.1.0 and older versions must either upgrade +# or comment out the :cb: capability in the console entry. +# +# Alexander Lukyanov reports: +# I have seen FreeBSD-2.1.5R... The old el1 bug changed, but it is still there. +# Now el1 clears not only to the line beginning, but also a large chunk +# of previous line. But there is another bug - ech does not work at all. +# + +# for syscons +# common entry without semigraphics +# Bug: The capability resets attributes. +# Bug? The ech and el1 attributes appear to move the cursor in some cases; for +# instance el1 does if the cursor is moved to the right margin first. Removed +# by T.Dickey 97/5/3 (ech=\E[%p1%dX, el1=\E[1K) +# +# Setting colors turns off reverse; we cannot guarantee order, so use ncv. +# Note that this disables standout with color. +cons25w|ansiw|ansi80x25-raw|freebsd console (25-line raw mode), + am, bce, bw, eo, msgr, npc, + colors#8, cols#80, it#8, lines#25, ncv#21, pairs#64, + bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, clear=\E[H\E[J, + cnorm=\E[=0C, cr=^M, cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, + cud1=\E[B, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + cvvis=\E[=1C, dch=\E[%p1%dP, dch1=\E[P, dim=\E[30;1m, + dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, home=\E[H, + hpa=\E[%i%p1%d`, ht=^I, ich=\E[%p1%d@, ich1=\E[@, + il=\E[%p1%dL, il1=\E[L, ind=\E[S, indn=\E[%p1%dS, kb2=\E[E, + kbs=^H, kcbt=\E[Z, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, + kcuu1=\E[A, kdch1=\177, kend=\E[F, kf1=\E[M, kf10=\E[V, + kf11=\E[W, kf12=\E[X, kf2=\E[N, kf3=\E[O, kf4=\E[P, kf5=\E[Q, + kf6=\E[R, kf7=\E[S, kf8=\E[T, kf9=\E[U, khome=\E[H, + kich1=\E[L, knp=\E[G, kpp=\E[I, nel=\E[E, op=\E[x, rev=\E[7m, + ri=\E[T, rin=\E[%p1%dT, rmso=\E[m, rs1=\E[x\E[m\Ec, + setab=\E[4%p1%dm, setaf=\E[3%p1%dm, sgr0=\E[m, + smso=\E[7m, vpa=\E[%i%p1%dd, +cons25|ansis|ansi80x25|freebsd console (25-line ansi mode), + acsc=-\030.^Y0\333`\004a\260f\370g\361h\261i\025j\331k\277l\332m\300n\305q\304t\303u\264v\301w\302x\263y\363z\362~\371, + use=cons25w, +cons25-m|ansis-mono|ansi80x25-mono|freebsd console (25-line mono ansi mode), + colors@, pairs@, + bold@, dim@, op@, rmul=\E[m, setab@, setaf@, smul=\E[4m, use=cons25, +cons30|ansi80x30|freebsd console (30-line ansi mode), + lines#30, use=cons25, +cons30-m|ansi80x30-mono|freebsd console (30-line mono ansi mode), + lines#30, use=cons25-m, +cons43|ansi80x43|freebsd console (43-line ansi mode), + lines#43, use=cons25, +cons43-m|ansi80x43-mono|freebsd console (43-line mono ansi mode), + lines#43, use=cons25-m, +cons50|ansil|ansi80x50|freebsd console (50-line ansi mode), + lines#50, use=cons25, +cons50-m|ansil-mono|ansi80x50-mono|freebsd console (50-line mono ansi mode), + lines#50, use=cons25-m, +cons60|ansi80x60|freebsd console (60-line ansi mode), + lines#60, use=cons25, +cons60-m|ansi80x60-mono|freebsd console (60-line mono ansi mode), + lines#60, use=cons25-m, +cons25r|pc3r|ibmpc3r|cons25-koi8-r|freebsd console w/koi8-r cyrillic, + acsc=-\030.^Y0\215`\004a\220f\234h\221i\025j\205k\203l\202m\204n\212q\0t\206u\207v\211w\210x\201y\230z\231~\225, + use=cons25w, +cons25r-m|pc3r-m|ibmpc3r-mono|cons25-koi8r-m|freebsd console w/koi8-r cyrillic (mono), + colors@, pairs@, + op@, rmul=\E[m, setab@, setaf@, smul=\E[4m, use=cons25r, +cons50r|cons50-koi8r|freebsd console w/koi8-r cyrillic (50 lines), + lines#50, use=cons25r, +cons50r-m|cons50-koi8r-m|freebsd console w/koi8-r cyrillic (50-line mono), + lines#50, use=cons25r-m, +cons60r|cons60-koi8r|freebsd console w/koi8-r cyrillic (60 lines), + lines#60, use=cons25r, +cons60r-m|cons60-koi8r-m|freebsd console w/koi8-r cyrillic (60-line mono), + lines#60, use=cons25r-m, +# ISO 8859-1 FreeBSD console +cons25l1|cons25-iso8859|freebsd console w/iso 8859-1 chars, + acsc=+\253\,\273-\030.\031`\201a\202f\207g\210i\247j\213k\214l\215m\216n\217o\220p\221q\222r\223s\224t\225u\226v\227w\230x\231y\232z\233~\237, + use=cons25w, +cons25l1-m|cons25-iso-m|freebsd console w/iso 8859-1 chars (mono), + colors@, pairs@, + bold@, dim@, op@, rmul=\E[m, setab@, setaf@, smul=\E[4m, use=cons25l1, +cons50l1|cons50-iso8859|freebsd console w/iso 8859-1 chars (50 lines), + lines#50, use=cons25l1, +cons50l1-m|cons50-iso-m|freebsd console w/iso 8859-1 chars (50-line mono), + lines#50, use=cons25l1-m, +cons60l1|cons60-iso|freebsd console w/iso 8859-1 chars (60 lines), + lines#60, use=cons25l1, +cons60l1-m|cons60-iso-m|freebsd console w/iso 8859-1 chars (60-line mono), + lines#60, use=cons25l1-m, + +#### 386BSD and BSD/OS Consoles +# + +# This was the original 386BSD console entry (I think). +# Some places it's named oldpc3|oldibmpc3. +# From: Alex R.N. Wetmore +origpc3|origibmpc3|IBM PC 386BSD Console, + am, bw, eo, xon, + cols#80, lines#25, + acsc=j\331k\277l\332m\300n\305q\304t\303u\264v\301w\302x\263, + bold=\E[7m, clear=\Ec, cub1=^H, cud1=\E[B, cuf1=\E[C, + cup=\E[%i%p1%2d;%p2%2dH, cuu1=\E[A, ed=\E[J, el=\E[K, + home=\E[H, ind=\E[S, kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, + kcuu1=\E[A, khome=\E[Y, ri=\E[T, rmso=\E[1;0x\E[2;7x, + rmul=\E[1;0x\E[2;7x, sgr0=\E[m\E[1;0x\E[2;7x, + smso=\E[1;7x\E[2;0x, smul=\E[1;7x\E[2;0x, + +# description of BSD/386 console emulator in version 1.0 (supplied by BSDI) +oldpc3|oldibmpc3|old IBM PC BSD/386 Console, + km, + lines#25, + bel=^G, bold=\E[=15F, cr=^M, cud1=^J, dim=\E[=8F, dl1=\E[M, + ht=^I, il1=\E[L, ind=^J, kbs=^H, kcub1=\E[D, kcud1=\E[B, + kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L, kll=\E[F, + knp=\E[G, kpp=\E[I, nel=^M^J, sgr0=\E[=R, + +# Description of BSD/OS console emulator in version 1.1, 2.0, 2.1 +# Note, the emulator supports many of the additional console features +# listed in the iBCS2 (e.g. character-set selection) though not all +# are described here. This entry really ought to be upgraded. +# Also note, the console will also work with fewer lines after doing +# "stty rows NN", e.g. to use 24 lines. +# (Color support from Kevin Rosenberg , 2 May 1996) +# Bug: The capability resets attributes. +bsdos-pc-nobold|BSD/OS PC console w/o bold, + am, eo, km, xon, + cols#80, it#8, lines#25, + bel=^G, clear=\Ec, cr=^M, cub=\E[%p1%dD, cub1=^H, + cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, home=\E[H, ht=^I, + il=\E[%p1%dL, il1=\E[L, ind=^J, kbs=^H, kcub1=\E[D, + kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, khome=\E[H, kich1=\E[L, + kll=\E[F, knp=\E[G, kpp=\E[I, nel=^M^J, rc=\E8, sc=\E7, + sgr=\E[0;10%?%p1%t;7%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m%?%p5%t\E[=8F%;, + use=klone+sgr, use=klone+color, +bsdos-pc|IBM PC BSD/OS Console, + sgr=\E[0;10%?%p1%t;7%;%?%p2%t;1%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m, use=bsdos-pc-nobold, + +# Old names for BSD/OS PC console used in releases before 4.1. +pc3|BSD/OS on the PC Console, + use=bsdos-pc-nobold, +ibmpc3|pc3-bold|BSD/OS on the PC Console with bold instead of underline, + use=bsdos-pc, + +# BSD/OS on the SPARC +bsdos-sparc|Sun SPARC BSD/OS Console, + use=sun, + +# BSD/OS on the PowerPC +bsdos-ppc|PowerPC BSD/OS Console, + use=bsdos-pc, + +#### DEC VT100 and compatibles +# +# DEC terminals from the vt100 forward are collected here. Older DEC terminals +# and micro consoles can be found in the `obsolete' section. More details on +# the relationship between the VT100 and ANSI X3.64/ISO 6429/ECMA-48 may be +# found near the end of this file. +# +# Except where noted, these entries are DEC's official terminfos. +# Contact Bill Hedberg of Terminal Support +# Engineering for more information. Updated terminfos and termcaps +# are kept available at ftp://gatekeeper.dec.com/pub/DEC/termcaps. +# +# In October 1995 DEC sold its terminals business, including the VT and Dorio +# line and trademark, to SunRiver Data Systems. SunRiver has since changed +# its name to Boundless Technologies; see http://www.boundless.com. +# + +# NOTE: Any VT100 emulation, whether in hardware or software, almost +# certainly includes what DEC called the `Level 1 editing extension' codes; +# only the very oldest VT100s lacked these and there probably aren't any of +# those left alive. To capture these, use one of the VT102 entries. +# +# Note that the glitch in vt100 is not quite the same as on the Concept, +# since the cursor is left in a different position while in the +# weird state (concept at beginning of next line, vt100 at end +# of this line) so all versions of vi before 3.7 don't handle +# right on vt100. The correct way to handle is when +# you output the char in column 80, immediately output CR LF +# and then assume you are in column 1 of the next line. If +# is on, am should be on too. +# +# I assume you have smooth scroll off or are at a slow enough baud +# rate that it doesn't matter (1200? or less). Also this assumes +# that you set auto-nl to "on", if you set it off use vt100-nam +# below. +# +# The padding requirements listed here are guesses. It is strongly +# recommended that xon/xoff be enabled, as this is assumed here. +# +# The vt100 uses and rather than // because the +# tab settings are in non-volatile memory and don't need to be +# reset upon login. Also setting the number of columns glitches +# the screen annoyingly. You can type "reset" to get them set. +# +# The VT100 series terminals have cursor ("arrows") keys which can operate +# in two different modes: Cursor Mode and Application Mode. Cursor Mode +# is the reset state, and is assumed to be the normal state. Application +# Mode is the "set" state. In Cursor Mode, the cursor keys transmit +# "Esc [ {code}" sequences, conforming to ANSI standards. In Application +# Mode, the cursor keys transmit "Esc O " sequences. Application Mode +# was provided primarily as an aid to the porting of VT52 applications. It is +# assumed that the cursor keys are normally in Cursor Mode, and expected that +# applications such as vi will always transmit the string. Therefore, +# the definitions for the cursor keys are made to match what the terminal +# transmits after the string is transmitted. If the string +# is a null string or is not defined, then cursor keys are assumed to be in +# "Cursor Mode", and the cursor keys definitions should match that assumption, +# else the appication may fail. It is also expected that applications will +# always transmit the string to the terminal before they exit. +# +# The VT100 series terminals have an auxilliary keypad, commonly referred to as +# the "Numeric Keypad", because it is a cluster of numeric and function keys. +# The Numeric Keypad which can operate in two different modes: Numeric Mode and +# Application Mode. Numeric Mode is the reset state, and is assumed to be +# the normal state. Application Mode is the "set" state. In Numeric Mode, +# the numeric and punctuation keys transmit ASCII 7-bit characters, and the +# Enter key transmits the same as the Return key (Note: the Return key +# can be configured to send either LF (\015) or CR LF). In Application Mode, +# all the keypad keys transmit "Esc O {code}" sequences. The PF1 - PF4 keys +# always send the same "Esc O {code}" sequences. It is assumed that the keypad +# is normally in Numeric Mode. If an application requires that the keypad be +# in Application Mode then it is expected that the user, or the application, +# will set the TERM environment variable to point to a terminfo entry which has +# defined the string to include the codes that switch the keypad into +# Application Mode, and the terminfo entry will also define function key +# fields to match the Application Mode control codes. If the string +# is a null string or is not defined, then the keypad is assumed to be in +# Numeric Mode. If the string switches the keypad into Application +# Mode, it is expected that the string will contain the control codes +# necessary to reset the keypad to "Normal" mode, and it is also expected that +# applications which transmit the string will also always transmit the +# string to the terminal before they exit. +# +# Here's a diagram of the VT100 keypad keys with their bindings. +# The top line is the name of the key (some DEC keyboards have the keys +# labelled somewhat differently, like GOLD instead of PF1, but this is +# the most "official" name). The second line is the escape sequence it +# generates in Application Keypad mode (where "$" means the ESC +# character). The third line contains two items, first the mapping of +# the key in terminfo, and then in termcap. +# _______________________________________ +# | PF1 | PF2 | PF3 | PF4 | +# | $OP | $OQ | $OR | $OS | +# |_kf1__k1_|_kf2__k2_|_kf3__k3_|_kf4__k4_| +# | 7 8 9 - | +# | $Ow | $Ox | $Oy | $Om | +# |_kf9__k9_|_kf10_k;_|_kf0__k0_|_________| +# | 4 | 5 | 6 | , | +# | $Ot | $Ou | $Ov | $Ol | +# |_kf5__k5_|_kf6__k6_|_kf7__k7_|_kf8__k8_| +# | 1 | 2 | 3 | | +# | $Oq | $Or | $Os | enter | +# |_ka1__K1_|_kb2__K2_|_ka3__K3_| $OM | +# | 0 | . | | +# | $Op | $On | | +# |___kc1_______K4____|_kc3__K5_|_kent_@8_| +# +# And here, for those of you with orphaned VT100s lacking documentation, is +# a description of the soft switches invoked when you do `Set Up'. +# +# Scroll 0-Jump Shifted 3 0-# +# | 1-Smooth | 1-British pound sign +# | Autorepeat 0-Off | Wrap Around 0-Off +# | | 1-On | | 1-On +# | | Screen 0-Dark Bkg | | New Line 0-Off +# | | | 1-Light Bkg | | | 1-On +# | | | Cursor 0-Underline | | | Interlace 0-Off +# | | | | 1-Block | | | | 1-On +# | | | | | | | | +# 1 1 0 1 1 1 1 1 0 1 0 0 0 0 1 0 <--Standard Settings +# | | | | | | | | +# | | | Auto XON/XOFF 0-Off | | | Power 0-60 Hz +# | | | 1-On | | | 1-50 Hz +# | | Ansi/VT52 0-VT52 | | Bits Per Char. 0-7 Bits +# | | 1-ANSI | | 1-8 Bits +# | Keyclick 0-Off | Parity 0-Off +# | 1-On | 1-On +# Margin Bell 0-Off Parity Sense 0-Odd +# 1-On 1-Even +# +# The following SET-UP modes are assumed for normal operation: +# ANSI_MODE AUTO_XON/XOFF_ON NEWLINE_OFF 80_COLUMNS +# WRAP_AROUND_ON JUMP_SCROLL_OFF +# Other SET-UP modes may be set for operator convenience or communication +# requirements; I recommend +# AUTOREPEAT_ON BLOCK_CURSOR MARGIN_BELL_OFF SHIFTED_3_# +# Unless you have a graphics add-on such as Digital Engineering's VT640 +# (and even then, whenever it can be arranged!) you should set +# INTERLACE_OFF +# +# (vt100: I added / based on the init string, also . -- esr) +vt100|vt100-am|dec vt100 (w/advanced video), + am, msgr, xenl, xon, + cols#80, it#8, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, + clear=\E[H\E[J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, + cuf=\E[%p1%dC, cuf1=\E[C$<2>, + cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, + cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>, + enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=^J, ka1=\EOq, + ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOp, kc3=\EOn, kcub1=\EOD, + kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM, kf0=\EOy, + kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\EOt, + kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, rc=\E8, + rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l, + rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>, + rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, + sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;, + sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=, + smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g, +vt100nam|vt100-nam|vt100 no automargins, + am@, xenl@, use=vt100-am, +vt100-vb|dec vt100 (w/advanced video) & no beep, + bel@, flash=\E[?5h\E[?5l, use=vt100, + +# Ordinary vt100 in 132 column ("wide") mode. +vt100-w|vt100-w-am|dec vt100 132 cols (w/advanced video), + cols#132, lines#24, + rs2=\E>\E[?3h\E[?4l\E[?5l\E[?8h, use=vt100-am, +vt100-w-nam|vt100-nam-w|dec vt100 132 cols (w/advanced video no automargin), + cols#132, lines#14, vt@, + rs2=\E>\E[?3h\E[?4l\E[?5l\E[?8h, use=vt100-nam, + +# vt100 with no advanced video. +vt100-nav|vt100 without advanced video option, + xmc#1, + blink@, bold@, rev@, rmso=\E[m, rmul@, sgr@, sgr0@, smso=\E[7m, + smul@, + use=vt100, +vt100-nav-w|vt100-w-nav|dec vt100 132 cols 14 lines (no advanced video option), + cols#132, lines#14, use=vt100-nav, + +# vt100 with one of the 24 lines used as a status line. +# We put the status line on the top. +vt100-s|vt100-s-top|vt100-top-s|vt100 for use with top sysline, + eslok, hs, + lines#23, + clear=\E[2;1H\E[J$<50>, csr=\E[%i%i%p1%d;%p2%dr, + cup=\E[%i%p1%{1}%+%d;%p2%dH$<5>, dsl=\E7\E[1;24r\E8, + fsl=\E8, home=\E[2;1H, is2=\E7\E[2;24r\E8, + tsl=\E7\E[1;%p1%dH\E[1K, use=vt100-am, + +# Status line at bottom. +# Clearing the screen will clobber status line. +vt100-s-bot|vt100-bot-s|vt100 for use with bottom sysline, + eslok, hs, + lines#23, + dsl=\E7\E[1;24r\E8, fsl=\E8, is2=\E[1;23r\E[23;1H, + tsl=\E7\E[24;%p1%dH\E[1K, + use=vt100-am, + +# Most of the `vt100' emulators out there actually emulate a vt102 +# This entry (or vt102-nsgr) is probably the right thing to use for +# these. +vt102|dec vt102, + mir, + dch1=\E[P, dl1=\E[M, il1=\E[L, rmir=\E[4l, smir=\E[4h, use=vt100, +vt102-w|dec vt102 in wide mode, + cols#132, + rs3=\E[?3h, use=vt102, + +# Many brain-dead PC comm programs that pretend to be `vt100-compatible' +# fail to interpret the ^O and ^N escapes properly. Symptom: the +# string in the canonical vt100 entry above leaves the screen littered +# with little snowflake or star characters (IBM PC ROM character \017 = ^O) +# after highlight turnoffs. This entry should fix that, and even leave +# ACS support working, at the cost of making multiple-highlight changes +# slightly more expensive. +# From: Eric S. Raymond July 22 1995 +vt102-nsgr|vt102 no sgr (use if you see snowflakes after highlight changes), + sgr@, sgr0=\E[m, + use=vt102, + +# VT125 Graphics CRT. Clear screen also erases graphics +vt125|vt125 graphics terminal, + clear=\E[H\E[2J\EPpS(E)\E\\$<50>, use=vt100, + +# This isn't a DEC entry, it came from University of Wisconsin. +# (vt131: I added / based on the init string, also -- esr) +vt131|dec vt131, + am, xenl, + cols#80, it#8, lines#24, vt#3, + bel=^G, blink=\E[5m$<2/>, bold=\E[1m$<2/>, + clear=\E[;H\E[2J$<50/>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=^J, cuf1=\E[C$<2/>, + cup=\E[%i%p1%d;%p2%dH$<5/>, cuu1=\E[A$<2/>, + ed=\E[J$<50/>, el=\E[K$<3/>, home=\E[H, ht=^I, + is2=\E[1;24r\E[24;1H, kbs=^H, kcub1=\EOD, kcud1=\EOB, + kcuf1=\EOC, kcuu1=\EOA, kf1=\EOP, kf2=\EOQ, kf3=\EOR, + kf4=\EOS, nel=^M^J, rc=\E8, rev=\E[7m$<2/>, ri=\EM$<5/>, + rmam=\E[?7h, rmkx=\E[?1l\E>, rmso=\E[m$<2/>, + rmul=\E[m$<2/>, + rs1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, + sgr0=\E[m$<2/>, smam=\E[?7h, smkx=\E[?1h\E=, + smso=\E[7m$<2/>, smul=\E[4m$<2/>, + +# vt132 - like vt100 but slower and has ins/del line and such. +# I'm told that / are backwards in the terminal from the +# manual and from the ANSI standard, this describes the actual +# terminal. I've never actually used a vt132 myself, so this +# is untested. +# +vt132|DEC vt132, + xenl, + dch1=\E[P$<7>, dl1=\E[M$<99>, il1=\E[L$<99>, ind=\n$<30>, + ip=$<7>, rmir=\E[4h, smir=\E[4l, + use=vt100, + +# This vt220 description maps F5--F9 to the second block of function keys +# at the top of the keyboard. The "DO" key is used as F10 to avoid conflict +# with the key marked (ESC) on the vt220. See vt220d for an alternate mapping. +# PF1--PF4 are used as F1--F4. +# +vt220-old|vt200-old|DEC VT220 in vt100 emulation mode, + am, mir, xenl, xon, + cols#80, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, civis=\E[?25l, + clear=\E[H\E[2J$<50>, cnorm=\E[?25h, cr=^M, + csr=\E[%i%p1%d;%p2%dr, cub1=^H, cud1=\E[B, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH$<10>, cuu1=\E[A, dch1=\E[P, + dl1=\E[M, ed=\E[J$<50>, el=\E[K$<3>, home=\E[H, ht=^I, + if=/usr/share/tabset/vt100, il1=\E[L, ind=\ED$<20/>, + is2=\E[1;24r\E[24;1H, kbs=^H, kcub1=\E[D, kcud1=\E[B, + kcuf1=\E[C, kcuu1=\E[A, kdch1=\E[3~, kend=\E[4~, kf1=\EOP, + kf10=\E[29~, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\E[17~, + kf6=\E[18~, kf7=\E[19~, kf8=\E[20~, kf9=\E[21~, + khome=\E[1~, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, rc=\E8, + rev=\E[7m$<2>, rf=/usr/share/tabset/vt100, + ri=\EM$<14/>, rmacs=\E(B$<4>, rmam=\E[?7l, rmir=\E[4l, + rmso=\E[27m, rmul=\E[24m, + rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, + sgr=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;, + sgr0=\E[m$<2>, smacs=\E(0$<2>, smam=\E[?7h, smir=\E[4h, + smso=\E[7m, smul=\E[4m, + +# A much better description of the VT200/220; used to be vt220-8 +vt220|vt200|dec vt220, + am, mc5i, mir, msgr, xenl, xon, + cols#80, it#8, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m, bold=\E[1m, clear=\E[H\E[J, cr=^M, + csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, + cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, + ech=\E[%p1%dX, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E)0, + flash=\E[?5h$<200/>\E[?5l, home=\E[H, ht=^I, hts=\EH, + ich=\E[%p1%d@, if=/usr/share/tabset/vt100, + il=\E[%p1%dL, il1=\E[L, ind=\ED, + is2=\E[?7h\E[>\E[?1h\E F\E[?4l, kbs=^H, kcub1=\E[D, + kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, kf1=\EOP, kf10=\E[21~, + kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, + kf17=\E[31~, kf18=\E[32~, kf19=\E[33~, kf2=\EOQ, + kf20=\E[34~, kf3=\EOR, kf4=\EOS, kf6=\E[17~, kf7=\E[18~, + kf8=\E[19~, kf9=\E[20~, kfnd=\E[1~, khlp=\E[28~, + khome=\E[H, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, krdo=\E[29~, + kslt=\E[4~, lf1=pf1, lf2=pf2, lf3=pf3, lf4=pf4, mc0=\E[i, + mc4=\E[4i, mc5=\E[5i, nel=\EE, rc=\E8, rev=\E[7m, ri=\EM, + rmacs=^O, rmam=\E[?7l, rmir=\E[4l, rmso=\E[27m, + rmul=\E[24m, rs1=\E[?3l, sc=\E7, sgr0=\E[m, smacs=^N, + smam=\E[?7h, smir=\E[4h, smso=\E[7m, smul=\E[4m, tbc=\E[3g, +vt220-w|vt200-w|DEC vt220 in wide mode, + cols#132, + rs3=\E[?3h, use=vt220, +vt220-8bit|vt220-8|vt200-8bit|vt200-8|dec vt220/200 in 8-bit mode, + am, mc5i, mir, msgr, xenl, xon, + cols#80, it#8, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\2335m, bold=\2331m, clear=\233H\233J, cr=^M, + csr=\233%i%p1%d;%p2%dr, cub=\233%p1%dD, cub1=^H, + cud=\233%p1%dB, cud1=^J, cuf=\233%p1%dC, cuf1=\233C, + cup=\233%i%p1%d;%p2%dH, cuu=\233%p1%dA, cuu1=\233A, + dch=\233%p1%dP, dch1=\233P, dl=\233%p1%dM, dl1=\233M, + ech=\233%p1%dX, ed=\233J, el=\233K, el1=\2331K, enacs=\E)0, + flash=\233?5h$<200/>\233?5l, home=\233H, ht=^I, hts=\EH, + ich=\233%p1%d@, if=/usr/share/tabset/vt100, + il=\233%p1%dL, il1=\233L, ind=\ED, + is2=\233?7h\233>\233?1h\E F\233?4l, kbs=^H, + kcub1=\233D, kcud1=\233B, kcuf1=\233C, kcuu1=\233A, + kf1=\EOP, kf10=\23321~, kf11=\23323~, kf12=\23324~, + kf13=\23325~, kf14=\23326~, kf17=\23331~, kf18=\23332~, + kf19=\23333~, kf2=\EOQ, kf20=\23334~, kf3=\EOR, kf4=\EOS, + kf6=\23317~, kf7=\23318~, kf8=\23319~, kf9=\23320~, + kfnd=\2331~, khlp=\23328~, khome=\233H, kich1=\2332~, + knp=\2336~, kpp=\2335~, krdo=\23329~, kslt=\2334~, lf1=pf1, + lf2=pf2, lf3=pf3, lf4=pf4, mc0=\233i, mc4=\2334i, mc5=\2335i, + nel=\EE, rc=\E8, rev=\2337m, ri=\EM, rmacs=^O, rmam=\233?7l, + rmir=\2334l, rmso=\23327m, rmul=\23324m, rs1=\233?3l, + sc=\E7, sgr0=\233m, smacs=^N, smam=\233?7h, smir=\2334h, + smso=\2337m, smul=\2334m, tbc=\2333g, + +# +# vt220d: +# This vt220 description regards F6--F10 as the second block of function keys +# at the top of the keyboard. This mapping follows the description given +# in the VT220 Programmer Reference Manual and agrees with the labeling +# on some terminals that emulate the vt220. There is no support for an F5. +# See vt220 for an alternate mapping. +# +vt220d|DEC VT220 in vt100 mode with DEC function key labeling, + kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, + kf14=\E[26~, kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, + kf18=\E[32~, kf19=\E[33~, kf20=\E[34~, kf5@, kf6=\E[17~, + kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, + use=vt220-old, + +vt220-nam|v200-nam|VT220 in vt100 mode with no auto margins, + am@, + rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7l\E[?8h, use=vt220, + +# vt220 termcap written Tue Oct 25 20:41:10 1988 by Alex Latzko +# (not an official DEC entry!) +# The problem with real vt220 terminals is they don't send escapes when in +# in vt220 mode. This can be gotten around two ways. 1> don't send +# escapes or 2> put the vt220 into vt100 mode and use all the nifty +# features of vt100 advanced video which it then has. +# +# This entry takes the view of putting a vt220 into vt100 mode so +# you can use the escape key in emacs and everything else which needs it. +# +# You probably don't want to use this on a VMS machine since VMS will think +# it has a vt220 and will get fouled up coming out of emacs +# +# From: Alexander Latzko , 30 Dec 1996 +# (Added vt100 , to quiet a tic warning -- esr) +vt200-js|vt220-js|dec vt200 series with jump scroll, + am, + cols#80, + bel=^G, clear=\E[H\E[J, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=^J, cup=\E[%i%p1%d;%p2%dH, cuu1=\E[A, + dch1=\E[P, dl1=\E[M, ed=\E[J, el=\E[K, home=\E[H, ht=^I, + il1=\E[L, ind=\ED, + is2=\E[61"p\E[H\E[?3l\E[?4l\E[?1l\E[?5l\E[?6l\E[?7h\E[?8h\E[?25h\E>\E[m, + kbs=^H, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, + kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, nel=^M\ED, rc=\E8, + rf=/usr/lib/tabset/vt100, ri=\EM, rmdc=, rmir=\E[4l, + rmkx=\E[?1l\E>, rmso=\E[27m$<5/>, rmul=\E[24m, + rs1=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, smdc=, + smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m$<5/>, smul=\E[4m, + + +# This was DEC's vt320. Use the purpose-built one below instead +#vt320|DEC VT320 in vt100 emulation mode, +# use=vt220, + +# +# Use v320n for SCO's LYRIX. Otherwise, use Adam Thompson's vt320-nam. +# +vt320nam|v320n|DEC VT320 in vt100 emul. mode with NO AUTO WRAP mode, + am@, + rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7l\E[?8h, use=vt220, + +# These entries are not DEC's official ones, they were purpose-built for the +# VT320. Here are the designer's notes: +# is end on a PC kbd. Actually 'select' on a VT. Mapped to +# 'Erase to End of Field'... since nothing seems to use 'end' anyways... +# khome is Home on a PC kbd. Actually 'FIND' on a VT. +# Things that use usually use tab anyways... and things that don't use +# tab usually use instead... +# kprv is same as tab - Backtab is useless... +# I left out because of its RIDICULOUS complexity, +# and the resulting fact that it causes the termcap translation of the entry +# to SMASH the 1k-barrier... +# From: Adam Thompson Sept 10 1995 +# (vt320: uncommented , comnmmented out to avoid a conflict --esr) +vt320|vt300|dec vt320 7 bit terminal, + am, eslok, hs, mir, msgr, xenl, + cols#80, lines#24, wsl#80, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l, + clear=\E[H\E[2J, cnorm=\E[?25h, cr=^M, + csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, + cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, + ech=\E[%p1%dX, ed=\E[J, el=\E[K, el1=\E[1K, fsl=\E[0$}, + home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, + il1=\E[L, ind=\ED, + is2=\E>\E[?3l\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H, + ka1=\EOw, ka3=\EOy, kb2=\EOu, kbs=\177, kc1=\EOq, kc3=\EOs, + kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, + kdch1=\E[3~, kel=\E[4~, kent=\EOM, kf1=\EOP, kf10=\E[21~, + kf11=\E[23~, kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, + kf15=\E[28~, kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, + kf19=\E[33~, kf2=\EOQ, kf20=\E[34~, kf3=\EOR, kf4=\EOS, + kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, + khome=\E[1~, kich1=\E[2~, knp=\E[6~, knxt=^I, kpp=\E[5~, + kprv=\E[Z, mc0=\E[i, mc4=\E[?4i, mc5=\E[?5i, nel=\EE, rc=\E8, + rev=\E[7m, rf=/usr/share/tabset/vt300, ri=\EM, + rmacs=\E(B, rmam=\E[?7l, rmir=\E[4l, rmkx=\E[?1l\E>, + rmso=\E[m, rmul=\E[m, + rs2=\E>\E[?3l\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H, + sc=\E7, sgr0=\E[m, smacs=\E(0, smam=\E[?7h, smir=\E[4h, + smkx=\E[?1h\E=, smso=\E[7m, smul=\E[4m, tbc=\E[3g, + tsl=\E[1$}\E[H\E[K, +vt320-nam|vt300-nam|dec vt320 7 bit terminal with no am to make SAS happy, + am@, + is2=\E>\E[?3l\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H, + rs2=\E>\E[?3l\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H, + use=vt320, +# We have to init 132-col mode, not 80-col mode. +vt320-w|vt300-w|dec vt320 wide 7 bit terminal, + cols#132, wsl#132, + is2=\E>\E[?3h\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H, + rs2=\E>\E[?3h\E[?4l\E[5?l\E[?7h\E[?8h\E[1;24r\E[24;1H, + use=vt320, +vt320-w-nam|vt300-w-nam|dec vt320 wide 7 bit terminal with no am, + am@, + is2=\E>\E[?3h\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H, + rs2=\E>\E[?3h\E[?4l\E[5?l\E[?7l\E[?8h\E[1;24r\E[24;1H, + use=vt320-w, + +# VT330 and VT340 -- These are ReGIS and SIXEL graphics terminals +# which are pretty much a superset of the VT320. They have the +# host writable status line, yet another different DRCS matrix size, +# and such, but they add the DEC Technical character set, Multiple text +# pages, selectable length pages, and the like. The difference between +# the vt330 and vt340 is that the latter has only 2 planes and a monochrome +# monitor, the former has 4 planes and a color monitor. These terminals +# support VT131 and ANSI block mode, but as with much of these things, +# termcap/terminfo doesn't deal with these features. +# +# Note that this entry is are set up in what was the standard way for GNU +# Emacs v18 terminal modes to deal with the cursor keys in that the arrow +# keys were switched into application mode at the same time the numeric pad +# is switched into application mode. This changes the definitions of the +# arrow keys. Emacs v19 is smarter and mines its keys directly out of +# your termcap or terminfo entry, +# +# From: Daniel Glasser , 13 Oct 1993 +# (vt340: string capability "sb=\E[M" corrected to "sr"; +# also, added / based on the init string -- esr) +vt340|dec-vt340|vt330|dec-vt330|dec vt340 graphics terminal with 24 line page, + am, eslok, hs, mir, msgr, xenl, xon, + cols#80, it#8, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + blink=\E[5m, bold=\E[1m, civis=\E[?25l, clear=\E[H\E[J, + cnorm=\E[?25h, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, + cuf=\E[%p1%dC, cuf1=\E[C, cup=\E[%i%p1%d;%p2%dH, + cuu=\E[%p1%dA, cuu1=\E[A, cvvis=\E[?25h, dch=\E[%p1%dP, + dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M, + dsl=\E[2$~\r\E[1$}\E[K\E[$}, ed=\E[J, el=\E[K, + flash=\E[?5h\E[?5l$<200/>, fsl=\E[$}, home=\E[H, ht=^I, + hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=\ED, + is2=\E<\E F\E>\E[?1h\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E[1;24r\E[24;1H, + kbs=^H, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, + kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf6=\E[17~, + kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, lf1=pf1, lf2=pf2, + lf3=pf3, lf4=pf4, nel=^M\ED, rc=\E8, rev=\E[7m, + rf=/usr/share/tabset/vt300, ri=\EM, rmacs=^O, + rmam=\E[?7l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[27m, + rmul=\E[24m, rs1=\E[?3l, sc=\E7, sgr0=\E[m, smacs=^N, + smam=\E[?7h, smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m, + smul=\E[4m, tbc=\E[3g, tsl=\E[2$~\E[1$}\E[1;%dH, + +# DEC doesn't supply a vt400 description, so we add Daniel Glasser's +# (originally written with vt420 as its primary name, and usable for it). +# +# VT400/420 -- This terminal is a superset of the vt320. It adds the multiple +# text pages and long text pages with selectable length of the vt340, along +# with left and right margins, rectangular area text copy, fill, and erase +# operations, selected region character attribute change operations, +# page memory and rectangle checksums, insert/delete column, reception +# macros, and other features too numerous to remember right now. TERMCAP +# can only take advantage of a few of these added features. +# +# Note that this entry is are set up in what was the standard way for GNU +# Emacs v18 terminal modes to deal with the cursor keys in that the arrow +# keys were switched into application mode at the same time the numeric pad +# is switched into application mode. This changes the definitions of the +# arrow keys. Emacs v19 is smarter and mines its keys directly out of +# your termcap entry, +# +# From: Daniel Glasser , 13 Oct 1993 +# (vt400: string capability ":sb=\E[M:" corrected to ":sr=\E[M:"; +# also, added / based on the init string -- esr) +vt400|vt400-24|dec-vt400|dec vt400 24x80 column autowrap, + am, eslok, hs, mir, msgr, xenl, xon, + cols#80, it#8, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + blink=\E[5m, bold=\E[1m, civis=\E[?25l, + clear=\E[H\E[J$<10/>, cnorm=\E[?25h, cr=^M, + csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, + cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A, + cvvis=\E[?25h, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, + dl1=\E[M, dsl=\E[2$~\r\E[1$}\E[K\E[$}, ed=\E[J$<10/>, + el=\E[K$<4/>, flash=\E[?5h\E[?5l$<200/>, fsl=\E[$}, + home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@, ich1=\E[@, + il=\E[%p1%dL, il1=\E[L, ind=\ED, + is2=\E<\E F\E>\E[?1h\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E[1;24r\E[24;1H, + kbs=^H, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, + kf1=\EOP, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf6=\E[17~, + kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, lf1=pf1, lf2=pf2, + lf3=pf3, lf4=pf4, nel=^M\ED, rc=\E8, rev=\E[7m, + rf=/usr/share/tabset/vt300, ri=\EM, rmacs=^O, + rmam=\E[?7l, rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[27m, + rmul=\E[24m, rs1=\E<\E[?3l\E[!p\E[?7h, sc=\E7, sgr0=\E[m, + smacs=^N, smam=\E[?7h, smir=\E[4h, smkx=\E[?1h\E=, + smso=\E[7m, smul=\E[4m, tbc=\E[3g, + tsl=\E[2$~\E[1$}\E[1;%dH, + +# (vt420: I removed , it collided with . I also restored +# a missing -- esr) +vt420|DEC VT420, + am, mir, xenl, xon, + cols#80, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, + clear=\E[H\E[2J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=\E[B, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH$<10>, cuu1=\E[A, dch1=\E[P, + dl1=\E[M, ed=\E[J$<50>, el=\E[K$<3>, home=\E[H, ht=^I, + if=/usr/share/tabset/vt300, il1=\E[L, ind=\ED, + is2=\E[1;24r\E[24;1H, is3=\E[?67h\E[64;1"p, kbs=^H, + kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kdch1=\E[3~, kf1=\EOP, kf10=\E[29~, kf2=\EOQ, kf3=\EOR, + kf4=\EOS, kf5=\E[17~, kf6=\E[18~, kf7=\E[19~, kf8=\E[20~, + kf9=\E[21~, kfnd=\E[1~, kich1=\E[2~, knp=\E[6~, kpp=\E[5~, + kslt=\E[4~, rc=\E8, rev=\E[7m$<2>, + rf=/usr/share/tabset/vt300, ri=\EM, rmacs=\E(B$<4>, + rmam=\E[?7l, rmir=\E[4l, rmkx=\E>, + rmsc=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, + rmso=\E[m, rmul=\E[m, rs3=\E[?67h\E[64;1"p, sc=\E7, + sgr=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;, + sgr0=\E[m$<2>, smacs=\E(0$<2>, smam=\E[?7h, smir=\E[4h, + smkx=\E=, smso=\E[7m, smul=\E[4m, + +# +# DEC VT220 and up support DECUDK (user-defined keys). DECUDK (i.e., pfx) +# takes two parameters, the key and the string. Translating the key is +# straightforward (keys 1-5 are not defined on real terminals, though some +# emulators define these): +# +# if (key < 16) then value = key; +# else if (key < 21) then value = key + 1; +# else if (key < 25) then value = key + 2; +# else if (key < 27) then value = key + 3; +# else if (key < 30) then value = key + 4; +# else value = key + 5; +# +# The string must be the hexadecimal equivalent, e.g., "5052494E" for "PRINT". +# There's no provision in terminfo for emitting a string in this format, so the +# application has to know it. +# +vt420pc|DEC VT420 w/PC keyboard, + kdch1=\177, kend=\E[4~, kf1=\E[11~, kf10=\E[21~, + kf11=\E[23~, kf12=\E[24~, kf13=\E[11;2~, kf14=\E[12;2~, + kf15=\E[13;2~, kf16=\E[14;2~, kf17=\E[15;2~, + kf18=\E[17;2~, kf19=\E[18;2~, kf2=\E[12~, kf20=\E[19;2~, + kf21=\E[20;2~, kf22=\E[21;2~, kf23=\E[23;2~, + kf24=\E[24;2~, kf25=\E[23~, kf26=\E[24~, kf27=\E[25~, + kf28=\E[26~, kf29=\E[28~, kf3=\E[13~, kf30=\E[29~, + kf31=\E[31~, kf32=\E[32~, kf33=\E[33~, kf34=\E[34~, + kf35=\E[35~, kf36=\E[36~, kf37=\E[23;2~, kf38=\E[24;2~, + kf39=\E[25;2~, kf4=\E[14~, kf40=\E[26;2~, kf41=\E[28;2~, + kf42=\E[29;2~, kf43=\E[31;2~, kf44=\E[32;2~, + kf45=\E[33;2~, kf46=\E[34;2~, kf47=\E[35;2~, + kf48=\E[36;2~, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, + kf8=\E[19~, kf9=\E[20~, khome=\E[H, + pctrm=USR_TERM\:vt420pcdos\:, + pfx=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\\, use=vt420, + +vt420pcdos|DEC VT420 w/PC for DOS Merge, + lines#25, + dispc=%?%p2%{19}%=%t\E\023\021%e%p2%{32}%<%t\E%p2%c%e%p2%{127}%=%t\E\177%e%p2%c%;, + pctrm@, + rmsc=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sgr@, + sgr0=\E[m, smsc=\E[?1;2r\E[34h, + use=vt420pc, + +vt420f|DEC VT420 with VT kbd; VT400 mode; F1-F5 used as Fkeys, + kdch1=\177, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~, + kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~, + kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~, + kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~, + kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, + khome=\E[H, lf1=\EOP, lf2=\EOQ, lf3=\EOR, lf4=\EOS, + use=vt420, + +vt510|DEC VT510, + use=vt420, +vt510pc|DEC VT510 w/PC keyboard, + use=vt420pc, +vt510pcdos|DEC VT510 w/PC for DOS Merge, + use=vt420pcdos, + +# VT520/VT525 +# +# The VT520 is a monochrome text terminal capable of managing up to +# four independent sessions in the terminal. It has multiple ANSI +# emulations (VT520, VT420, VT320, VT220, VT100, VT PCTerm, SCO Console) +# and ASCII emulations (WY160/60, PCTerm, 50/50+, 150/120, TVI 950, +# 925 910+, ADDS A2). This terminfo data is for the ANSI emulations only. +# +# Terminal Set-Up is entered by pressing [F3], [Caps Lock]/[F3] or +# [Alt]/[Print Screen] depending upon which keyboard and which +# terminal mode is being used. If Set-Up has been disabled or +# assigned to an unknown key, Set-Up may be entered by pressing +# [F3] as the first key after power up, regardless of keyboard type. +# (vt520: I added / based on the init string, also -- esr) +vt520|DEC VT520, + am, mir, xenl, xon, + cols#80, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, + clear=\E[H\E[2J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=\E[B, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH$<10>, cuu1=\E[A, dch1=\E[P, + dl1=\E[M, ed=\E[J$<50>, el=\E[K$<3>, home=\E[H, ht=^I, + if=/usr/share/tabset/vt300, il1=\E[L, ind=\ED, + is2=\E[1;24r\E[24;1H, is3=\E[?67h\E[64;1"p, kbs=^H, + kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kdch1=\E[3~, kf0=\E[29~, kf1=\EOP, kf10=\E[29~, kf2=\EOQ, + kf3=\EOR, kf4=\EOS, kf5=\E[17~, kf6=\E[18~, kf7=\E[19~, + kf8=\E[20~, kf9=\E[21~, kfnd=\E[1~, kich1=\E[2~, knp=\E[6~, + kpp=\E[5~, kslt=\E[4~, + pfx=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\\, + rc=\E8, rev=\E[7m$<2>, rf=/usr/share/tabset/vt300, + ri=\EM, rmacs=\E(B$<4>, rmam=\E[?7l, rmir=\E[4l, + rmsc=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, + rmso=\E[m, rmul=\E[m, rs3=\E[?67h\E[64;1"p, sc=\E7, + sgr=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;, + sgr0=\E[m$<2>, smacs=\E(0$<2>, smam=\E[?7h, smir=\E[4h, + smso=\E[7m, smul=\E[4m, + +# (vt525: I added / based on the init string; +# removed =\E[m, =\E[m, added -- esr) +vt525|DEC VT525, + am, mir, xenl, xon, + cols#80, lines#24, vt#3, + acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, + bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, + clear=\E[H\E[2J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, + cub1=^H, cud1=\E[B, cuf1=\E[C, + cup=\E[%i%p1%d;%p2%dH$<10>, cuu1=\E[A, dch1=\E[P, + dl1=\E[M, ed=\E[J$<50>, el=\E[K$<3>, home=\E[H, ht=^I, + if=/usr/share/tabset/vt300, il1=\E[L, ind=\ED, + is2=\E[1;24r\E[24;1H, is3=\E[?67h\E[64;1"p, kbs=^H, + kcub1=\E[D, kcud1=\E[B, kcuf1=\E[C, kcuu1=\E[A, + kdch1=\E[3~, kf0=\E[29~, kf1=\EOP, kf10=\E[29~, kf2=\EOQ, + kf3=\EOR, kf4=\EOS, kf5=\E[17~, kf6=\E[18~, kf7=\E[19~, + kf8=\E[20~, kf9=\E[21~, kfnd=\E[1~, kich1=\E[2~, knp=\E[6~, + kpp=\E[5~, kslt=\E[4~, + pfx=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\\, + rc=\E8, rev=\E[7m$<2>, rf=/usr/share/tabset/vt300, + ri=\EM, rmacs=\E(B$<4>, rmam=\E[?7l, rmir=\E[4l, + rmsc=\E[?0;0r\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, + rmso=\E[m, rmul=\E[m, rs3=\E[?67h\E[64;1"p, sc=\E7, + sgr=\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p4%t;5%;%?%p1%p3%|%t;7%;m%?%p9%t\E(0%e\E(B%;, + sgr0=\E[m$<2>, smacs=\E(0$<2>, smam=\E[?7h, smir=\E[4h, + smso=\E[7m, smul=\E[4m, diff --git a/tests/examplefiles/test.csd b/tests/examplefiles/test.csd new file mode 100644 index 00000000..9122309b --- /dev/null +++ b/tests/examplefiles/test.csd @@ -0,0 +1,260 @@ + + +// This is a Csound orchestra file for testing a Pygments +// lexer. Csound single-line comments can be preceded by a pair of forward +// slashes... +; ...or a semicolon. + +/* Block comments begin with /* and end with */ + +// Orchestras begin with a header of audio parameters. +nchnls = 1 +nchnls_i = 1 +sr = 44100 +0dbfs = 1 +ksmps = 10 + +// The control rate kr = sr / ksmps can be omitted when the number of audio +// samples in a control period (ksmps) is set, but kr may appear in older +// orchestras. +kr = 4410 + +// Orchestras contain instruments. These begin with the keyword instr followed +// by a comma-separated list of numbers or names of the instrument. Instruments +// end at the endin keyword and cannot be nested. +instr 1, N_a_M_e_, +Name + // Instruments contain statements. Here is a typical statement: + aSignal oscil 0dbfs, 440, 1 + // Statements are terminated with a newline (possibly preceded by a comment). + // To write a statement on several lines, precede the newline with a + // backslash. + prints \ + "hello, world\n";comment + + // Csound 6 introduced function syntax for opcodes with one or zero outputs. + // The oscil statement above is the same as + aSignal = oscil(0dbfs, 440, 1) + + // Instruments can contain control structures. + kNote = p3 + if (kNote == 0) then + kFrequency = 220 + elseif kNote == 1 then // Parentheses around binary expressions are optional. + kFrequency = 440 + endif + + // Csound 6 introduced looping structures. + iIndex = 0 + while iIndex < 5 do + print iIndex + iIndex += 1 + od + iIndex = 0 + until iIndex >= 5 do + print iIndex + iIndex += 1 + enduntil + // Both kinds of loops can be terminated by either od or enduntil. + + // Single-line strings are enclosed in double-quotes. + prints "string\\\r\n\t\"" + // Multi-line strings are enclosed in pairs of curly braces. + prints {{ + hello, + + world + }} + + // Instruments often end with a statement containing an output opcode. + outc aSignal +endin + +// Orchestras can also contain user-defined opcodes (UDOs). Here is an +// oscillator with one audio-rate output and two control-rate inputs: +opcode anOscillator, a, kk + kAmplitude, kFrequency xin + aSignal vco2 kAmplitude, kFrequency + xout aSignal +endop +instr TestOscillator + outc(anOscillator(0dbfs, 110)) +endin + +// Python can be executed in Csound +// . So can Lua +// . +pyruni {{ +import random + +pool = [(1 + i / 10.0) ** 1.2 for i in range(100)] + +def get_number_from_pool(n, p): + if random.random() < p: + i = int(random.random() * len(pool)) + pool[i] = n + return random.choice(pool) +}} + +// The Csound preprocessor supports conditional compilation and including files. +#ifdef DEBUG +#undef DEBUG +#include "filename.orc" +#endif + +// The preprocessor also supports object- and function-like macros. This is an +// object-like macro that defines a number: +#define A_HZ #440# + +// This is a function-like macro: +#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# + +// Bodies of macros are enclosed in # and can contain newlines. The arguments of +// function-like macros are separated by single-quotes. Uses of macros are +// prefixed with a dollar sign. +instr TestMacro + aSignal $OSCIL_MACRO(1'$A_HZ'1) + // Not unlike PHP, macros expand in double-quoted strings. + prints "The frequency of the oscillator is $A_HZ Hz.\n" + out aSignal +endin + +// Here are other things to note about Csound. + +// There are two bitwise NOT operators, ~ and ¬ (U+00AC). The latter is common +// on keyboards in the United Kingdom +// . +instr TestBitwiseNOT + print ~42 + print ¬42 +endin + +// Csound uses # for bitwise XOR, which the Csound manual calls bitwise +// non-equivalence . +instr TestBitwiseXOR + print 0 # 0 + print 0 # 1 + print 1 # 0 + print 1 # 1 +endin + +// Loops and if-then statements are relatively recent additions to Csound. There +// are many flow-control opcodes that involve goto and labels. +instr TestGoto + // This... + if p3 > 0 goto if_label + goto else_label +if_label: + prints "if branch\n" + goto endif_label +else_label: + prints "else branch\n" +endif_label: + + // ...is the same as this. + if p3 > 0 then + prints "if branch\n" + else + prints "else branch\n" + endif + + // This... + iIndex = 0 +loop_label: + print iIndex + iIndex += 1 + if iIndex < 10 goto loop_label + + // ...is the same as this... + iIndex = 0 +loop_lt_label: + print iIndex + loop_lt iIndex, 1, 10, loop_lt_label + + // ...and this. + iIndex = 0 + while iIndex < 10 do + print iIndex + iIndex += 1 + od +endin + +// The prints and printks opcodes +// , arguably +// the primary methods of logging output, treat certain sequences of characters +// different from printf in C. +instr TestPrints + // ^ prints an ESCAPE character (U+001B), not a CIRCUMFLEX ACCENT character + // (U+005E). ^^ prints a CIRCUMFLEX ACCENT. + prints "^^\n" + // ~ prints an ESCAPE character (U+001B) followed by a [, not a TILDE + // character (U+007E). ~~ prints a TILDE. + prints "~~\n" + // \A, \B, \N, \R, and \T correspond to the escaped lowercase characters (that + // is, BELL (U+0007), BACKSPACE (U+0008), new line (U+000A), CARRIAGE RETURN + // (U+000D), and tab (U+0009)). + prints "\T\R\N" + // %n, %r, and %t are the same as \n, \r, and \t, as are %N, %R, and %T. + prints "%t%r%n" + // %! prints a semicolon. This is a hold-over from old versions of Csound that + // allowed comments to begin in strings. + prints "; %!\n" +endin + +// The arguments of function-like macros can be separated by # instead of '. +// These two lines define the same macro. +#define OSCIL_MACRO(VOLUME'FREQUENCY'TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# +#define OSCIL_MACRO(VOLUME#FREQUENCY#TABLE) #oscil $VOLUME, $FREQUENCY, $TABLE# + +// Uses of macros can optionally be suffixed with a period. +instr TestMacroPeriodSuffix + aSignal $OSCIL_MACRO.(1'$A_HZ'1) + prints "The frequency of the oscillator is $A_HZ.Hz.\n" + out aSignal +endin + +// Csound has @ and @@ operator-like macros that, when followed by a literal +// non-negative integer, expand to the next power of 2 and the next power of 2 +// plus 1: +// @x = 2^(ceil(log2(x + 1))), x >= 0 +// @@0 = 2 +// @@x = 2^(ceil(log2(x))) + 1, x > 0 +// These macros are in +// (and +// ) +// and are described at . +instr TestAt + prints "%d %2d %2d\n", 0, @0, @@0 + prints "%d %2d %2d\n", 1, @1, @@1 + prints "%d %2d %2d\n", 2, @2, @@2 + prints "%d %2d %2d\n", 3, @3, @@3 + prints "%d %2d %2d\n", 4, @4, @@4 + prints "%d %2d %2d\n", 5, @5, @@5 + prints "%d %2d %2d\n", 6, @6, @@6 + prints "%d %2d %2d\n", 7, @7, @@7 + prints "%d %2d %2d\n", 8, @8, @@8 + prints "%d %2d %2d\n", 9, @9, @@9 +endin + +// Including newlines in macros can lead to confusing code, but it tests the +// lexer. +instr MacroAbuse + if 1 == 1 then + prints "on\n" +#define FOO# +BAR +#endif // This ends the if statement. It is not a preprocessor directive. +endin + + +f 1 0 16384 10 1 +i "N_a_M_e_" 0 2 +i "TestOscillator" 2 2 +i "TestBitwiseNOT" 0 1 +i "TestBitwiseXOR" 0 1 +i "TestGoto" 0 1 +i "TestMacroPeriodSuffix" 4 1 +i "TestAt" 0 1 +i "MacroAbuse" 0 1 +e + + diff --git a/tests/examplefiles/test.ecl b/tests/examplefiles/test.ecl deleted file mode 100644 index b686492a..00000000 --- a/tests/examplefiles/test.ecl +++ /dev/null @@ -1,58 +0,0 @@ -/*############################################################################## - - Copyright (C) 2011 HPCC Systems. - - All rights reserved. This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -############################################################################## */ - -#option ('slidingJoins', true); - -namesRecord := - RECORD -string20 surname; -string10 forename; -integer2 age; -integer2 dadAge; -integer2 mumAge; - END; - -namesRecord2 := - record -string10 extra; -namesRecord; - end; - -namesTable := dataset('x',namesRecord,FLAT); -namesTable2 := dataset('y',namesRecord2,FLAT); - -integer2 aveAgeL(namesRecord l) := (l.dadAge+l.mumAge)/2; -integer2 aveAgeR(namesRecord2 r) := (r.dadAge+r.mumAge)/2; - -// Standard join on a function of left and right -output(join(namesTable, namesTable2, aveAgeL(left) = aveAgeR(right))); - -//Several simple examples of sliding join syntax -output(join(namesTable, namesTable2, left.age >= right.age - 10 and left.age <= right.age +10)); -output(join(namesTable, namesTable2, left.age between right.age - 10 and right.age +10)); -output(join(namesTable, namesTable2, left.age between right.age + 10 and right.age +30)); -output(join(namesTable, namesTable2, left.age between (right.age + 20) - 10 and (right.age +20) + 10)); -output(join(namesTable, namesTable2, aveAgeL(left) between aveAgeR(right)+10 and aveAgeR(right)+40)); - -//Same, but on strings. Also includes age to ensure sort is done by non-sliding before sliding. -output(join(namesTable, namesTable2, left.surname between right.surname[1..10]+'AAAAAAAAAA' and right.surname[1..10]+'ZZZZZZZZZZ' and left.age=right.age)); -output(join(namesTable, namesTable2, left.surname between right.surname[1..10]+'AAAAAAAAAA' and right.surname[1..10]+'ZZZZZZZZZZ' and left.age=right.age,all)); - -//This should not generate a self join -output(join(namesTable, namesTable, left.age between right.age - 10 and right.age +10)); - diff --git a/tests/examplefiles/test.sco b/tests/examplefiles/test.sco new file mode 100644 index 00000000..a0b39251 --- /dev/null +++ b/tests/examplefiles/test.sco @@ -0,0 +1,10 @@ +f 1 0 16384 10 1 +i "N_a_M_e_" 0 2 +i "TestOscillator" 2 2 +i "TestBitwiseNOT" 0 1 +i "TestBitwiseXOR" 0 1 +i "TestGoto" 0 1 +i "TestMacroPeriodSuffix" 4 1 +i "TestAt" 0 1 +i "MacroAbuse" 0 1 +e diff --git a/tests/test_clexer.py b/tests/test_clexer.py index 6a3dcbce..fd7f58fc 100644 --- a/tests/test_clexer.py +++ b/tests/test_clexer.py @@ -234,3 +234,26 @@ class CLexerTest(unittest.TestCase): (Token.Text, u'\n'), ] self.assertEqual(tokens, list(self.lexer.get_tokens(textwrap.dedent(fragment)))) + + def testPreprocFile(self): + fragment = u'#include \n' + tokens = [ + (Token.Comment.Preproc, u'#'), + (Token.Comment.Preproc, u'include'), + (Token.Text, u' '), + (Token.Comment.PreprocFile, u''), + (Token.Comment.Preproc, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testPreprocFile2(self): + fragment = u'#include "foo.h"\n' + tokens = [ + (Token.Comment.Preproc, u'#'), + (Token.Comment.Preproc, u'include'), + (Token.Text, u' '), + (Token.Comment.PreprocFile, u'"foo.h"'), + (Token.Comment.Preproc, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + diff --git a/tests/test_ezhil.py b/tests/test_ezhil.py new file mode 100644 index 00000000..23b9cb41 --- /dev/null +++ b/tests/test_ezhil.py @@ -0,0 +1,182 @@ +# -*- coding: utf-8 -*- +""" + Basic EzhilLexer Test + ~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2015 Muthiah Annamalai + :license: BSD, see LICENSE for details. +""" + +import unittest + +from pygments.token import Operator, Number, Text, Token +from pygments.lexers import EzhilLexer + + +class EzhilTest(unittest.TestCase): + + def setUp(self): + self.lexer = EzhilLexer() + self.maxDiff = None + + def testSum(self): + fragment = u'1+3\n' + tokens = [ + (Number.Integer, u'1'), + (Operator, u'+'), + (Number.Integer, u'3'), + (Text, u'\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testGCDExpr(self): + fragment = u'1^3+(5-5)*gcd(a,b)\n' + tokens = [ + (Token.Number.Integer,u'1'), + (Token.Operator,u'^'), + (Token.Literal.Number.Integer, u'3'), + (Token.Operator, u'+'), + (Token.Punctuation, u'('), + (Token.Literal.Number.Integer, u'5'), + (Token.Operator, u'-'), + (Token.Literal.Number.Integer, u'5'), + (Token.Punctuation, u')'), + (Token.Operator, u'*'), + (Token.Name, u'gcd'), + (Token.Punctuation, u'('), + (Token.Name, u'a'), + (Token.Operator, u','), + (Token.Name, u'b'), + (Token.Punctuation, u')'), + (Token.Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testIfStatement(self): + fragment = u"""@( 0 > 3 ) ஆனால் + பதிப்பி "wont print" +முடி""" + tokens = [ + (Token.Operator, u'@'), + (Token.Punctuation, u'('), + (Token.Text, u' '), + (Token.Literal.Number.Integer,u'0'), + (Token.Text, u' '), + (Token.Operator,u'>'), + (Token.Text, u' '), + (Token.Literal.Number.Integer, u'3'), + (Token.Text, u' '), + (Token.Punctuation, u')'), + (Token.Text, u' '), + (Token.Keyword, u'ஆனால்'), + (Token.Text, u'\n'), + (Token.Text, u'\t'), + (Token.Keyword, u'பதிப்பி'), + (Token.Text, u' '), + (Token.Literal.String, u'"wont print"'), + (Token.Text, u'\t'), + (Token.Text, u'\n'), + (Token.Keyword, u'முடி'), + (Token.Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + + def testFunction(self): + fragment = u"""# (C) முத்தையா அண்ணாமலை 2013, 2015 +நிரல்பாகம் gcd ( x, y ) + மு = max(x,y) + q = min(x,y) + + @( q == 0 ) ஆனால் + பின்கொடு மு + முடி + பின்கொடு gcd( மு - q , q ) +முடி\n""" + tokens = [ + (Token.Comment.Single, + u'# (C) \u0bae\u0bc1\u0ba4\u0bcd\u0ba4\u0bc8\u0baf\u0bbe \u0b85\u0ba3\u0bcd\u0ba3\u0bbe\u0bae\u0bb2\u0bc8 2013, 2015\n'), + (Token.Keyword,u'நிரல்பாகம்'), + (Token.Text, u' '), + (Token.Name, u'gcd'), + (Token.Text, u' '), + (Token.Punctuation, u'('), + (Token.Text, u' '), + (Token.Name, u'x'), + (Token.Operator, u','), + (Token.Text, u' '), + (Token.Name, u'y'), + (Token.Text, u' '), + (Token.Punctuation, u')'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Name, u'\u0bae\u0bc1'), + (Token.Text, u' '), + (Token.Operator, u'='), + (Token.Text, u' '), + (Token.Name.Builtin, u'max'), + (Token.Punctuation, u'('), + (Token.Name, u'x'), + (Token.Operator, u','), + (Token.Name, u'y'), + (Token.Punctuation, u')'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Name, u'q'), + (Token.Text, u' '), + (Token.Operator, u'='), + (Token.Text, u' '), + (Token.Name.Builtin, u'min'), + (Token.Punctuation, u'('), + (Token.Name, u'x'), + (Token.Operator, u','), + (Token.Name, u'y'), + (Token.Punctuation, u')'), + (Token.Text, u'\n'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Operator, u'@'), + (Token.Punctuation, u'('), + (Token.Text, u' '), + (Token.Name, u'q'), + (Token.Text, u' '), + (Token.Operator, u'=='), + (Token.Text, u' '), + (Token.Literal.Number.Integer, u'0'), + (Token.Text, u' '), + (Token.Punctuation, u')'), + (Token.Text, u' '), + (Token.Keyword, u'ஆனால்'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Keyword, u'பின்கொடு'), + (Token.Text, u' '), + (Token.Name, u'\u0bae\u0bc1'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Keyword, u'முடி'), + (Token.Text, u'\n'), + (Token.Text, u' '), + (Token.Keyword, u'\u0baa\u0bbf\u0ba9\u0bcd\u0b95\u0bca\u0b9f\u0bc1'), + (Token.Text, u' '), + (Token.Name, u'gcd'), + (Token.Punctuation, u'('), + (Token.Text, u' '), + (Token.Name, u'\u0bae\u0bc1'), + (Token.Text, u' '), + (Token.Operator, u'-'), + (Token.Text, u' '), + (Token.Name, u'q'), + (Token.Text, u' '), + (Token.Operator, u','), + (Token.Text, u' '), + (Token.Name, u'q'), + (Token.Text, u' '), + (Token.Punctuation, u')'), + (Token.Text, u'\n'), + (Token.Keyword, u'முடி'), #u'\u0bae\u0bc1\u0b9f\u0bbf'), + (Token.Text, u'\n') + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.1 From 44553826aa36241f6428572513b58e0f4ac69d90 Mon Sep 17 00:00:00 2001 From: Kim Jin Su Date: Sun, 22 Nov 2015 00:43:21 +0900 Subject: remove trash --- pygments/lexers/esoteric.py.orig | 201 --------------------------------------- 1 file changed, 201 deletions(-) delete mode 100644 pygments/lexers/esoteric.py.orig diff --git a/pygments/lexers/esoteric.py.orig b/pygments/lexers/esoteric.py.orig deleted file mode 100644 index 06c1de8d..00000000 --- a/pygments/lexers/esoteric.py.orig +++ /dev/null @@ -1,201 +0,0 @@ -# -*- coding: utf-8 -*- -""" - pygments.lexers.esoteric - ~~~~~~~~~~~~~~~~~~~~~~~~ - - Lexers for esoteric languages. - - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -from pygments.lexer import RegexLexer, include, words -from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Error, Whitespace - -__all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', 'CAmkESLexer', 'AheuiLexer'] - - -class BrainfuckLexer(RegexLexer): - """ - Lexer for the esoteric `BrainFuck `_ - language. - """ - - name = 'Brainfuck' - aliases = ['brainfuck', 'bf'] - filenames = ['*.bf', '*.b'] - mimetypes = ['application/x-brainfuck'] - - tokens = { - 'common': [ - # use different colors for different instruction types - (r'[.,]+', Name.Tag), - (r'[+-]+', Name.Builtin), - (r'[<>]+', Name.Variable), - (r'[^.,+\-<>\[\]]+', Comment), - ], - 'root': [ - (r'\[', Keyword, 'loop'), - (r'\]', Error), - include('common'), - ], - 'loop': [ - (r'\[', Keyword, '#push'), - (r'\]', Keyword, '#pop'), - include('common'), - ] - } - - -class BefungeLexer(RegexLexer): - """ - Lexer for the esoteric `Befunge `_ - language. - - .. versionadded:: 0.7 - """ - name = 'Befunge' - aliases = ['befunge'] - filenames = ['*.befunge'] - mimetypes = ['application/x-befunge'] - - tokens = { - 'root': [ - (r'[0-9a-f]', Number), - (r'[+*/%!`-]', Operator), # Traditional math - (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives - (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives - (r'[|_mw]', Keyword), - (r'[{}]', Name.Tag), # Befunge-98 stack ops - (r'".*?"', String.Double), # Strings don't appear to allow escapes - (r'\'.', String.Single), # Single character - (r'[#;]', Comment), # Trampoline... depends on direction hit - (r'[pg&~=@iotsy]', Keyword), # Misc - (r'[()A-Z]', Comment), # Fingerprints - (r'\s+', Text), # Whitespace doesn't matter - ], - } - - -class RedcodeLexer(RegexLexer): - """ - A simple Redcode lexer based on ICWS'94. - Contributed by Adam Blinkinsop . - - .. versionadded:: 0.8 - """ - name = 'Redcode' - aliases = ['redcode'] - filenames = ['*.cw'] - - opcodes = ('DAT', 'MOV', 'ADD', 'SUB', 'MUL', 'DIV', 'MOD', - 'JMP', 'JMZ', 'JMN', 'DJN', 'CMP', 'SLT', 'SPL', - 'ORG', 'EQU', 'END') - modifiers = ('A', 'B', 'AB', 'BA', 'F', 'X', 'I') - - tokens = { - 'root': [ - # Whitespace: - (r'\s+', Text), - (r';.*$', Comment.Single), - # Lexemes: - # Identifiers - (r'\b(%s)\b' % '|'.join(opcodes), Name.Function), - (r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator), - (r'[A-Za-z_]\w+', Name), - # Operators - (r'[-+*/%]', Operator), - (r'[#$@<>]', Operator), # mode - (r'[.,]', Punctuation), # mode - # Numbers - (r'[-+]?\d+', Number.Integer), - ], - } - - -class BoogieLexer(RegexLexer): - """ - For `Boogie `_ source code. - - .. versionadded:: 2.1 - """ - name = 'Boogie' - aliases = ['boogie'] - filenames = ['*.bpl'] - - tokens = { - 'root': [ - # Whitespace and Comments - (r'\n', Whitespace), - (r'\s+', Whitespace), - (r'//[/!](.*?)\n', Comment.Doc), - (r'//(.*?)\n', Comment.Single), - (r'/\*', Comment.Multiline, 'comment'), - - (words(( - 'axiom', 'break', 'call', 'ensures', 'else', 'exists', 'function', - 'forall', 'if', 'invariant', 'modifies', 'procedure', 'requires', - 'then', 'var', 'while'), - suffix=r'\b'), Keyword), - (words(('const',), suffix=r'\b'), Keyword.Reserved), - - (words(('bool', 'int', 'ref'), suffix=r'\b'), Keyword.Type), - include('numbers'), - (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator), - (r"([{}():;,.])", Punctuation), - # Identifier - (r'[a-zA-Z_]\w*', Name), - ], - 'comment': [ - (r'[^*/]+', Comment.Multiline), - (r'/\*', Comment.Multiline, '#push'), - (r'\*/', Comment.Multiline, '#pop'), - (r'[*/]', Comment.Multiline), - ], - 'numbers': [ - (r'[0-9]+', Number.Integer), - ], - } - - -class AheuiLexer(RegexLexer): - """ - Aheui_ Lexer. - - Aheui_ is esoteric language based on Korean alphabets. - - .. _Aheui:: http://aheui.github.io/ - - """ - - name = u'Aheui' - aliases = ['aheui'] - filenames = ['*.aheui'] - - tokens = { - 'root': [ - (u'[' - u'가-갛갸-걓거-겋겨-곃고-곻교-궇규-긯' - u'까-깧꺄-꺟꺼-껗껴-꼏꼬-꽇꾜-꿓뀨-끻' - u'나-낳냐-냫너-넣녀-녛노-놓뇨-눟뉴-닇' - u'다-닿댜-댷더-덯뎌-뎧도-돟됴-둫듀-딓' - u'따-땋땨-떃떠-떻뗘-뗳또-똫뚀-뚷뜌-띟' - u'라-랗랴-럏러-렇려-렿로-롷료-뤃류-릫' - u'마-맣먀-먛머-멓며-몋모-뫃묘-뭏뮤-믷' - u'바-밯뱌-뱧버-벟벼-볗보-봏뵤-붛뷰-빃' - u'빠-빻뺘-뺳뻐-뻫뼈-뼣뽀-뽛뾰-뿧쀼-삏' - u'사-샇샤-샿서-섷셔-셯소-솧쇼-숳슈-싛' - u'싸-쌓쌰-썋써-쎃쎠-쎻쏘-쏳쑈-쑿쓔-씧' - u'아-앟야-얗어-엏여-옇오-옿요-웋유-읳' - u'자-잫쟈-쟣저-젛져-졓조-좋죠-줗쥬-즿' - u'짜-짷쨔-쨯쩌-쩧쪄-쪟쪼-쫗쬬-쭣쮸-찋' - u'차-챃챠-챻처-첳쳐-쳫초-촣쵸-춯츄-칗' - u'카-캏캬-컇커-컿켜-켷코-콯쿄-쿻큐-킣' - u'타-탛탸-턓터-텋텨-톃토-톻툐-퉇튜-틯' - u'파-팧퍄-퍟퍼-펗펴-폏포-퐇표-풓퓨-픻' - u'하-핳햐-햫허-헣혀-혛호-홓효-훟휴-힇' - u']', Operator), - ('.', Comment), - ], - } -- cgit v1.2.1 From c3b1f1ee15846dbef2609b8666cda2995ad38510 Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Sat, 2 Jan 2016 19:50:38 +0100 Subject: Lexer for Angular 2 template engine added --- pygments/lexers/_mapping.py | 2 ++ pygments/lexers/templates.py | 69 +++++++++++++++++++++++++++++++++++++++++- tests/examplefiles/example.ng2 | 11 +++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/examplefiles/example.ng2 diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 39d5e85a..f53cf83d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -26,6 +26,8 @@ LEXERS = { 'AgdaLexer': ('pygments.lexers.haskell', 'Agda', ('agda',), ('*.agda',), ('text/x-agda',)), 'AlloyLexer': ('pygments.lexers.dsls', 'Alloy', ('alloy',), ('*.als',), ('text/x-alloy',)), 'AmbientTalkLexer': ('pygments.lexers.ambient', 'AmbientTalk', ('at', 'ambienttalk', 'ambienttalk/2'), ('*.at',), ('text/x-ambienttalk',)), + 'Angular2Lexer': ('pygments.lexers.templates', 'Angular2', ('ng2',), (), ()), + 'Angular2HtmlLexer': ('pygments.lexers.templates', 'HTML + Angular2', ('html+ng2',), ('*.ng2',), ()), 'AntlrActionScriptLexer': ('pygments.lexers.parsers', 'ANTLR With ActionScript Target', ('antlr-as', 'antlr-actionscript'), ('*.G', '*.g'), ()), 'AntlrCSharpLexer': ('pygments.lexers.parsers', 'ANTLR With C# Target', ('antlr-csharp', 'antlr-c#'), ('*.G', '*.g'), ()), 'AntlrCppLexer': ('pygments.lexers.parsers', 'ANTLR With CPP Target', ('antlr-cpp',), ('*.G', '*.g'), ()), diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 71055a9f..097e2ef2 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -44,7 +44,7 @@ __all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer', 'TeaTemplateLexer', 'LassoHtmlLexer', 'LassoXmlLexer', 'LassoCssLexer', 'LassoJavascriptLexer', 'HandlebarsLexer', 'HandlebarsHtmlLexer', 'YamlJinjaLexer', 'LiquidLexer', - 'TwigLexer', 'TwigHtmlLexer'] + 'TwigLexer', 'TwigHtmlLexer', 'Angular2Lexer', 'Angular2HtmlLexer'] class ErbLexer(Lexer): @@ -2174,3 +2174,70 @@ class TwigHtmlLexer(DelegatingLexer): def __init__(self, **options): super(TwigHtmlLexer, self).__init__(HtmlLexer, TwigLexer, **options) + + +class Angular2Lexer(RegexLexer): + """ + Generic `angular ` template lexer. + + Highlights only the Angular template tags (stuff between `{{` and `}}`). + Everything else is left for a delegating lexer. + + .. versionadded:: 2.0 + """ + + name = "Angular2" + aliases = ['ng2'] + + tokens = { + 'root': [ + (r'[^{([*]+', Other), + + # {{meal.name}} + (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'ngExpression'), + + # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" + (r'([([]+)([\w:.-]+)([\])]+)(\s*)((=)(\s*))?', + bygroups(Punctuation, Name.Attribute, Punctuation, Operator, Operator), 'attr'), + # *ngIf="..." + (r'(\*)([\w:.-]+)(\s*)((=)(\s*))?', + bygroups(Punctuation, Name.Attribute, Punctuation, Operator), 'attr'), + ], + + 'ngExpression': [ + (r'\s+(\|\s+)?', Text), + (r'\}\}', Comment.Preproc, '#pop'), + + # Literals + (r':?(true|false)', String.Boolean), + (r':?"(\\\\|\\"|[^"])*"', String.Double), + (r":?'(\\\\|\\'|[^'])*'", String.Single), + (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" + r"0[xX][0-9a-fA-F]+[Ll]?", Number), + + # Variabletext + (r'[a-zA-Z][\w-]*', Name.Variable), + (r'\.[\w-]+', Name.Variable), + ], + 'attr': [ + ('".*?"', String, '#pop'), + ("'.*?'", String, '#pop'), + (r'[^\s>]+', String, '#pop'), + ], + } + + +class Angular2HtmlLexer(DelegatingLexer): + """ + Subclass of the `Angular2Lexer` that highlights unlexed data with the + `HtmlLexer`. + + .. versionadded:: 2.0 + """ + + name = "HTML + Angular2" + aliases = ["html+ng2"] + filenames = ['*.ng2'] + + def __init__(self, **options): + super(Angular2HtmlLexer, self).__init__(HtmlLexer, Angular2Lexer, **options) \ No newline at end of file diff --git a/tests/examplefiles/example.ng2 b/tests/examplefiles/example.ng2 new file mode 100644 index 00000000..0f424aca --- /dev/null +++ b/tests/examplefiles/example.ng2 @@ -0,0 +1,11 @@ +
+

{{order.DueTime | date:'d. MMMM yyyy HH:mm'}}

+

Status: {{order.OrderState}}

+ +
    +
  • + {{meal.Name}} +
  • +
+

Preis: {{order.TotalPrice | currency:'EUR':true:'1.2-2'}}

+
\ No newline at end of file -- cgit v1.2.1 From 25100648aaaf26a89c1ad5e1f346762bcea5dc25 Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Sat, 2 Jan 2016 18:55:54 +0000 Subject: templates.py edited online with Bitbucket --- pygments/lexers/templates.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 097e2ef2..eeafd2fc 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -2178,9 +2178,10 @@ class TwigHtmlLexer(DelegatingLexer): class Angular2Lexer(RegexLexer): """ - Generic `angular ` template lexer. + Generic `angular2 ` template lexer. - Highlights only the Angular template tags (stuff between `{{` and `}}`). + Highlights only the Angular template tags (stuff between `{{` and `}}` and + special attributes: '(event)=', '[property]=', '[(twoWayBinding)]='). Everything else is left for a delegating lexer. .. versionadded:: 2.0 -- cgit v1.2.1 From 6e2d68d3595b6f87b7b78e2d405264bc6d6cfdd1 Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Sun, 3 Jan 2016 13:21:35 +0100 Subject: Added rules for Function-calls in ngExpression and variable-definitions in html-attributes (#f="ngForm") --- pygments/lexers/templates.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index eeafd2fc..6988a0a1 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -2192,7 +2192,7 @@ class Angular2Lexer(RegexLexer): tokens = { 'root': [ - (r'[^{([*]+', Other), + (r'[^{([*#]+', Other), # {{meal.name}} (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'ngExpression'), @@ -2200,8 +2200,8 @@ class Angular2Lexer(RegexLexer): # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" (r'([([]+)([\w:.-]+)([\])]+)(\s*)((=)(\s*))?', bygroups(Punctuation, Name.Attribute, Punctuation, Operator, Operator), 'attr'), - # *ngIf="..." - (r'(\*)([\w:.-]+)(\s*)((=)(\s*))?', + # *ngIf="..."; #f="ngForm" + (r'([*#])([\w:.-]+)(\s*)((=)(\s*))?', bygroups(Punctuation, Name.Attribute, Punctuation, Operator), 'attr'), ], @@ -2217,8 +2217,8 @@ class Angular2Lexer(RegexLexer): r"0[xX][0-9a-fA-F]+[Ll]?", Number), # Variabletext - (r'[a-zA-Z][\w-]*', Name.Variable), - (r'\.[\w-]+', Name.Variable), + (r'[a-zA-Z][\w-]*(\(.*\))?', Name.Variable), + (r'\.[\w-]+(\(.*\))?', Name.Variable), ], 'attr': [ ('".*?"', String, '#pop'), -- cgit v1.2.1 From 31eb6237c4755cae2d49f1c87a8c50af9dfcad0f Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Sun, 3 Jan 2016 13:23:26 +0100 Subject: Normalized tabulator-whitespaces --- pygments/lexers/templates.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 6988a0a1..f5c599f8 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -2175,7 +2175,7 @@ class TwigHtmlLexer(DelegatingLexer): def __init__(self, **options): super(TwigHtmlLexer, self).__init__(HtmlLexer, TwigLexer, **options) - + class Angular2Lexer(RegexLexer): """ Generic `angular2 ` template lexer. @@ -2194,32 +2194,32 @@ class Angular2Lexer(RegexLexer): 'root': [ (r'[^{([*#]+', Other), - # {{meal.name}} + # {{meal.name}} (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'ngExpression'), - - # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" + + # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" (r'([([]+)([\w:.-]+)([\])]+)(\s*)((=)(\s*))?', bygroups(Punctuation, Name.Attribute, Punctuation, Operator, Operator), 'attr'), - # *ngIf="..."; #f="ngForm" + # *ngIf="..."; #f="ngForm" (r'([*#])([\w:.-]+)(\s*)((=)(\s*))?', bygroups(Punctuation, Name.Attribute, Punctuation, Operator), 'attr'), ], - - 'ngExpression': [ - (r'\s+(\|\s+)?', Text), + + 'ngExpression': [ + (r'\s+(\|\s+)?', Text), (r'\}\}', Comment.Preproc, '#pop'), - - # Literals + + # Literals (r':?(true|false)', String.Boolean), (r':?"(\\\\|\\"|[^"])*"', String.Double), (r":?'(\\\\|\\'|[^'])*'", String.Single), (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" r"0[xX][0-9a-fA-F]+[Ll]?", Number), - - # Variabletext + + # Variabletext (r'[a-zA-Z][\w-]*(\(.*\))?', Name.Variable), (r'\.[\w-]+(\(.*\))?', Name.Variable), - ], + ], 'attr': [ ('".*?"', String, '#pop'), ("'.*?'", String, '#pop'), -- cgit v1.2.1 From d1ac5fe3c40f34133972c09d559e9198a576f294 Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Sun, 3 Jan 2016 15:31:24 +0100 Subject: Added valueless attributes (e.g: *ngSwitchDefault) Added inline If for Expression {{ isBordered ? "ON" : "OFF" }} --- pygments/lexers/templates.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index f5c599f8..166c4f55 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -2198,11 +2198,16 @@ class Angular2Lexer(RegexLexer): (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'ngExpression'), # (click)="deleteOrder()"; [value]="test"; [(twoWayTest)]="foo.bar" - (r'([([]+)([\w:.-]+)([\])]+)(\s*)((=)(\s*))?', - bygroups(Punctuation, Name.Attribute, Punctuation, Operator, Operator), 'attr'), + (r'([([]+)([\w:.-]+)([\])]+)(\s*)(=)(\s*)', + bygroups(Punctuation, Name.Attribute, Punctuation, Text, Operator, Text), 'attr'), + (r'([([]+)([\w:.-]+)([\])]+)(\s*)', + bygroups(Punctuation, Name.Attribute, Punctuation, Text)), + # *ngIf="..."; #f="ngForm" - (r'([*#])([\w:.-]+)(\s*)((=)(\s*))?', + (r'([*#])([\w:.-]+)(\s*)(=)(\s*)', bygroups(Punctuation, Name.Attribute, Punctuation, Operator), 'attr'), + (r'([*#])([\w:.-]+)(\s*)', + bygroups(Punctuation, Name.Attribute, Punctuation)), ], 'ngExpression': [ @@ -2219,6 +2224,9 @@ class Angular2Lexer(RegexLexer): # Variabletext (r'[a-zA-Z][\w-]*(\(.*\))?', Name.Variable), (r'\.[\w-]+(\(.*\))?', Name.Variable), + + # inline If + (r'(\?)(\s*)([^}\s]+)(\s*)(:)(\s*)([^}\s]+)(\s*)', bygroups(Operator, Text, String, Text, Operator, Text, String, Text)), ], 'attr': [ ('".*?"', String, '#pop'), -- cgit v1.2.1 From d3e17ab04db15213e5922e54240733aa03dd463a Mon Sep 17 00:00:00 2001 From: fleischwolf Date: Wed, 6 Jan 2016 13:49:08 +0000 Subject: Link added and versionadded corrected --- pygments/lexers/templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 166c4f55..0a9209d0 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -2178,13 +2178,13 @@ class TwigHtmlLexer(DelegatingLexer): class Angular2Lexer(RegexLexer): """ - Generic `angular2 ` template lexer. + Generic `angular2 ` template lexer. Highlights only the Angular template tags (stuff between `{{` and `}}` and special attributes: '(event)=', '[property]=', '[(twoWayBinding)]='). Everything else is left for a delegating lexer. - .. versionadded:: 2.0 + .. versionadded:: 2.1a0 """ name = "Angular2" -- cgit v1.2.1 From 2eaf2b832db3a0535695c3fbc4a8bd3879b3e0d8 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 7 Jan 2016 14:30:26 +0100 Subject: Add tasm lexer. I copied the nasm lexer and added or removed things that are different. --- pygments/lexers/_mapping.py | 1 + pygments/lexers/asm.py | 82 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index a08e806c..10d53083 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -375,6 +375,7 @@ LEXERS = { 'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)), 'TAPLexer': ('pygments.lexers.testing', 'TAP', ('tap',), ('*.tap',), ()), 'Tads3Lexer': ('pygments.lexers.int_fiction', 'TADS 3', ('tads3',), ('*.t',), ()), + 'TasmLexer': ('pygments.lexers.asm', 'TASM', ('tasm',), ('*.asm', '*.ASM', '*.tasm'), ('text/x-tasm',)), 'TclLexer': ('pygments.lexers.tcl', 'Tcl', ('tcl',), ('*.tcl', '*.rvt'), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')), 'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)), 'TcshSessionLexer': ('pygments.lexers.shell', 'Tcsh Session', ('tcshcon',), (), ()), diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py index 918ed83b..893d7c37 100644 --- a/pygments/lexers/asm.py +++ b/pygments/lexers/asm.py @@ -19,7 +19,7 @@ from pygments.token import Text, Name, Number, String, Comment, Punctuation, \ __all__ = ['GasLexer', 'ObjdumpLexer', 'DObjdumpLexer', 'CppObjdumpLexer', 'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'NasmObjdumpLexer', - 'Ca65Lexer'] + 'TasmLexer', 'Ca65Lexer'] class GasLexer(RegexLexer): @@ -309,7 +309,6 @@ class LlvmLexer(RegexLexer): ] } - class NasmLexer(RegexLexer): """ For Nasm (Intel) assembly code. @@ -397,6 +396,85 @@ class NasmObjdumpLexer(ObjdumpLexer): tokens = _objdump_lexer_tokens(NasmLexer) +class TasmLexer(RegexLexer): + """ + For Tasm (Turbo Assembler) assembly code. + """ + name = 'TASM' + aliases = ['tasm'] + filenames = ['*.asm', '*.ASM', '*.tasm'] + mimetypes = ['text/x-tasm'] + + identifier = r'[@a-z$._?][\w$.?#@~]*' + hexn = r'(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)' + octn = r'[0-7]+q' + binn = r'[01]+b' + decn = r'[0-9]+' + floatn = decn + r'\.e?' + decn + string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`" + declkw = r'(?:res|d)[bwdqt]|times' + register = (r'r[0-9][0-5]?[bwd]|' + r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|' + r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') + wordop = r'seg|wrt|strict' + type = r'byte|[dq]?word' + directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' + r'ORG|ALIGN|STRUC|ENDSTRUC|ENDS|COMMON|CPU|GROUP|UPPERCASE|INCLUDE|' + r'EXPORT|LIBRARY|MODULE|PROC|ENDP|USES|ARG|DATASEG|UDATASEG|END|IDEAL|' + r'P386|MODEL|ASSUME|CODESEG|SIZE') + # T[A-Z][a-z] is more of a convention. Lexer should filter out STRUC definitions + # and then 'add' them to datatype somehow. + datatype = (r'db|dd|dw|T[A-Z][a-z]+') + + flags = re.IGNORECASE | re.MULTILINE + tokens = { + 'root': [ + (r'^\s*%', Comment.Preproc, 'preproc'), + include('whitespace'), + (identifier + ':', Name.Label), + (directives, Keyword, 'instruction-args'), + (r'(%s)(\s+)(%s)' % (identifier, datatype), + bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration), + 'instruction-args'), + (declkw, Keyword.Declaration, 'instruction-args'), + (identifier, Name.Function, 'instruction-args'), + (r'[\r\n]+', Text) + ], + 'instruction-args': [ + (string, String), + (hexn, Number.Hex), + (octn, Number.Oct), + (binn, Number.Bin), + (floatn, Number.Float), + (decn, Number.Integer), + include('punctuation'), + (register, Name.Builtin), + (identifier, Name.Variable), + (r'\\\s*;.*[\r\n]', Text), # Do not match newline when it's preceeded by a + (r'[\r\n]+', Text, '#pop'), + include('whitespace') + ], + 'preproc': [ + (r'[^;\n]+', Comment.Preproc), + (r';.*?\n', Comment.Single, '#pop'), + (r'\n', Comment.Preproc, '#pop'), + ], + 'whitespace': [ + (r'\n', Text), + (r'\\\n', Text), + (r'[ \t]+', Text), + (r';.*', Comment.Single) + ], + 'punctuation': [ + (r'[,():\[\]]+', Punctuation), + (r'[&|^<>+*=/%~-]+', Operator), + (r'[$]+', Keyword.Constant), + (wordop, Operator.Word), + (type, Keyword.Type) + ], + } + + class Ca65Lexer(RegexLexer): """ For ca65 assembler sources. -- cgit v1.2.1 From fdcee213674b941181892bf77807fba7e0d4b6c4 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 7 Jan 2016 14:31:42 +0100 Subject: Add tasm example file. This is a file I created for University. I release it under BSD license, so that it is compatible with Pygments licensing. --- tests/examplefiles/example.tasm | 527 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 527 insertions(+) create mode 100644 tests/examplefiles/example.tasm diff --git a/tests/examplefiles/example.tasm b/tests/examplefiles/example.tasm new file mode 100644 index 00000000..d7202ffb --- /dev/null +++ b/tests/examplefiles/example.tasm @@ -0,0 +1,527 @@ +;----------------------------------------------------------------------------; +; Does A* pathfinding for rockraiders and vehicles +; +; Copyright 2015 Ruben De Smet +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are +; met: +; +; (1) Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; +; (2) Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in +; the documentation and/or other materials provided with the +; distribution. +; +; (3) The name of the author may not be used to +; endorse or promote products derived from this software without +; specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +; DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +; IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +; POSSIBILITY OF SUCH DAMAGE. +; +;----------------------------------------------------------------------------; + +IDEAL +P386 +MODEL FLAT, C +ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT + +INCLUDE "ASTAR.INC" +INCLUDE "READLVL.INC" +INCLUDE "DEBUG.INC" + +STRUC TPriorityField + heuristic dd ? + distance dd ? + x db ? + y db ? + fromx db ? + fromy db ? +ENDS + +STRUC TField + distance dd ? + x db ? + y db ? +ENDS + +CODESEG + +PROC getPath + USES ecx + ARG @@tgtx:dword, \ + @@tgty:dword \ + RETURNS eax, ebx ; eax contains x, ebx contains y + + call getLevelWidth + imul eax, [@@tgty] + add eax, [@@tgtx] + imul eax, SIZE TField + add eax, offset backtraceGraph + mov ecx, eax + + xor eax, eax + xor ebx, ebx + + mov al, [(TField ptr ecx).x] + mov bl, [(TField ptr ecx).y] + + ret +ENDP getPath + +PROC findPath + ; eax will contain a 1 when a path has been found + ; 0 otherwise. + ARG @@srcx:dword, \ + @@srcy:dword, \ + @@tgtx:dword, \ + @@tgty:dword, \ + @@type:dword \ + RETURNS eax + + ; Check whether the target field is "allowed" for + ; the selected vehicle or rock raider + call getField, [@@tgtx], [@@tgty] + mov al, [byte ptr eax] + and eax, 0FFh + + add eax, offset actionTable + mov eax, [eax] + and eax, [@@type] ; TODO: for now, rock raider is hard coded + jnz @canGoToTarget + + mov eax, 0 + ret +@canGoToTarget: + + call cleanData + mov eax, [@@type] + mov [currentType], eax + + mov eax, [@@srcx] + mov [currentOpen.x], al + mov eax, [@@srcy] + mov [currentOpen.y], al + + call distance, [@@srcx], [@@srcy], [@@tgtx], [@@tgty] + ; eax <- distance + call addOpen, [@@srcx], [@@srcy], eax, 0 + +@openListNotEmpty: + call popOpen + cmp eax, 0 + je @openListEmpty + + call addToMap + + call addClosed + + mov eax, [@@tgtx] + cmp [currentOpen.x], al + jne @nextOpen + mov eax, [@@tgty] + cmp [currentOpen.y], al + jne @nextOpen + + jmp @routeFound + + @nextOpen: + call addNeighbours, [@@tgtx], [@@tgty] + + jmp @openListNotEmpty + +@openListEmpty: + mov eax, 0 + ret + +@routeFound: + mov eax, 1 + ret +ENDP findPath + +PROC addToMap + USES eax, ecx + + call getLevelWidth + xor ecx, ecx + mov cl, [currentOpen.y] + imul eax, ecx + mov cl, [currentOpen.x] + add eax, ecx + imul eax, SIZE TField + add eax, offset backtraceGraph + + mov ecx, [currentOpen.distance] + cmp [(TField ptr eax).distance], ecx + jbe @dontAdd + + mov [(TField ptr eax).distance], ecx + mov cl, [currentOpen.fromx] + mov [(TField ptr eax).x], cl + mov cl, [currentOpen.fromy] + mov [(TField ptr eax).y], cl + +@dontAdd: + ret +ENDP addToMap + +; Is closed checks whether the field considered is "closed" for being added to the open list. +; So, it also checks whether we can go on the selected field. +PROC isClosed + USES ebx, ecx, edx + ARG @@x:dword, \ + @@y:dword RETURNS eax + + ; Check bounds first: + + call getLevelWidth + cmp [@@x], eax + ja notWithinBounds ; ja considers -1 > 10 + + call getLevelHeight + cmp [@@y], eax + ja notWithinBounds + + ; Check whether this field is "allowed" for + ; the selected vehicle or rock raider + call getField, [@@x], [@@y] + mov al, [byte ptr eax] + and eax, 0FFh + + add eax, offset actionTable + mov eax, [eax] + and eax, [currentType] ; TODO: for now, rock raider is hard coded + jnz @canGoHere + + + inc eax ; mov eax, 1 + ret + +@canGoHere: + + ; Getting here means the field is okay to walk/fly/whatever on + + xor ecx, ecx + mov cx, [closedlistSize] + cmp cx, 0 ; If empty, return 0 + jne @closedNotEmpty + + mov eax, 0 + ret + +@closedNotEmpty: + mov ebx, offset closedlist + +@loopClosed: + mov edx, [@@x] + cmp [(TField ptr ebx).x], dl + jne @nextClosed + mov edx, [@@y] + cmp [(TField ptr ebx).y], dl + jne @nextClosed + + ; If reached here, yep, contained in closed list + mov eax, 1 + ret + + @nextClosed: + add ebx, SIZE TField + dec ecx + jnz @loopClosed + + mov eax, 0 + ret + +notWithinBounds: + mov eax, 1 + ret +ENDP isClosed + +PROC addNeighbours + USES eax, ebx, ecx, edx + ARG @@tgtx:dword, \ + @@tgty:dword + ; Push all neighbours of currentOpen on openList + + xor ebx, ebx + xor ecx, ecx + + mov bl, [currentOpen.x] + mov cl, [currentOpen.y] + mov edx, [currentOpen.distance] + inc edx ; Next distance is one more. + + ; Up + dec ecx + call isClosed, ebx, ecx + cmp eax, 0 + jne @noUp + call distance, ebx, ecx, [@@tgtx], [@@tgty] + add eax, edx + call addOpen, ebx, ecx, eax, edx + @noUp: + inc ecx + + ; Right + inc ebx + call isClosed, ebx, ecx + cmp eax, 0 + jne @noRight + call distance, ebx, ecx, [@@tgtx], [@@tgty] + add eax, edx + call addOpen, ebx, ecx, eax, edx + @noRight: + dec ebx + + ; Left + dec ebx + call isClosed, ebx, ecx + cmp eax, 0 + jne @noLeft + call distance, ebx, ecx, [@@tgtx], [@@tgty] + add eax, edx + call addOpen, ebx, ecx, eax, edx + @noLeft: + inc ebx + + ; Down + inc ecx + call isClosed, ebx, ecx + cmp eax, 0 + jne @noDown + call distance, ebx, ecx, [@@tgtx], [@@tgty] + add eax, edx + call addOpen, ebx, ecx, eax, edx + @noDown: + dec ecx + + ret +ENDP addNeighbours + +PROC popOpen + ARG RETURNS eax + USES ebx, ecx, edx, esi, edi + ; eax contains the smallest current heuristic + ; ebx contains the index of that field + + cmp [openlistSize], 0 ; If empty, return 0 + jne @goForth + + mov eax, 0 + ret + +@goForth: + + mov eax, 0FFFFFFFFh ; Longest distance possible in 32 bits. + xor ebx, ebx + xor ecx, ecx ; ecx contains the current index + +@searchFurther: + mov edx, ecx + imul edx, SIZE TPriorityField + cmp [(TPriorityField ptr (openlist + edx)).heuristic], eax + ja @notBetter + ; Better guess found, put right values in eax and ebx + mov eax, [(TPriorityField ptr (openlist + edx)).heuristic] + mov ebx, ecx + +@notBetter: + + inc ecx + cmp cx, [openlistSize] + jne @searchFurther + + ; By now, we have found the right item to pop from the priorityqueue. + + ; Move the correct item in currentOpen + mov ecx, SIZE TPriorityField + mov esi, ebx + imul esi, ecx + add esi, offset openlist + + mov edi, offset currentOpen + rep movsb + + ; Now make the remove the thing from the vector + + xor ecx, ecx + mov cx, [openlistSize] + sub ecx, ebx + dec ecx + imul ecx, SIZE TPriorityField + mov edi, esi + sub edi, SIZE TPriorityField + rep movsb + + dec [openlistSize] + mov eax, 1 + ret +ENDP popOpen + +PROC addClosed + USES eax, ebx + + xor ebx, ebx + xor eax, eax + + mov bx, [closedlistSize] + imul ebx, SIZE TField + add ebx, offset closedlist ; ebx contains the target TField + + mov al, [currentOpen.x] + mov [(TField ptr ebx).x], al + mov al, [currentOpen.y] + mov [(TField ptr ebx).y], al + mov eax, [currentOpen.distance] + mov [(TField ptr ebx).distance], eax + + inc [closedlistSize] + cmp [closedlistSize], CLOSED_LIST_SIZE_MAX + jne @noProblemWithClosedVector + + xor eax, eax + mov ax, [closedlistSize] + call crash, offset closedOutOfMemory, eax + +@noProblemWithClosedVector: + ret +ENDP addClosed + +PROC addOpen + USES eax, ebx + ARG @@x:dword, \ + @@y:dword, \ + @@priority:dword, \ + @@distance:dword + + xor eax, eax + mov ax, [openlistSize] + imul eax, SIZE TPriorityField + add eax, offset openlist + + mov ebx, [@@x] + mov [(TPriorityField ptr eax).x], bl + mov ebx, [@@y] + mov [(TPriorityField ptr eax).y], bl + + mov bl, [currentOpen.x] + mov [(TPriorityField ptr eax).fromx], bl + mov bl, [currentOpen.y] + mov [(TPriorityField ptr eax).fromy], bl + + mov ebx, [@@priority] + mov [(TPriorityField ptr eax).heuristic], ebx + mov ebx, [@@distance] + mov [(TPriorityField ptr eax).distance], ebx + + inc [openlistSize] + cmp [openlistSize], OPEN_LIST_SIZE_MAX + jne @noProblem + + xor eax, eax + mov ax, [openlistSize] + call crash, offset openOutOfMemory, eax + +@noProblem: + ret +ENDP + +PROC distance + USES ebx + ARG @@srcx:dword, \ + @@srcy:dword, \ + @@tgtx:dword, \ + @@tgty:dword \ + RETURNS eax + + mov eax, [@@srcx] + sub eax, [@@tgtx] + + jns @noSignChangex + neg eax + + @noSignChangex: + + mov ebx, [@@srcy] + sub ebx, [@@tgty] + + jns @noSignChangey + neg ebx + + @noSignChangey: + add eax, ebx + ret +ENDP distance + +PROC cleanData + USES eax, ecx + mov [openlistSize], 0 + mov [closedlistSize], 0 + + mov [currentOpen.x], -1 + mov [currentOpen.y], -1 + mov [currentOpen.distance], 0 + + call getLevelWidth + mov ecx, eax + call getLevelHeight + imul ecx, eax + + mov eax, offset backtraceGraph +@fieldIter: + mov [(TField ptr eax).distance], 0ffffffffh ; Set to approximately +inf + mov [(TField ptr eax).x], 0 + mov [(TField ptr eax).y], 0 + add eax, SIZE TField + dec ecx + jnz @fieldIter + + ret +ENDP cleanData + +DATASEG + +openOutOfMemory db "Out of openlistSize memory. Hi dev: Please increase$" +closedOutOfMemory db "Out of closedlistSize memory. Hi dev: Please increase$" + +; power | discover | walking | sailing | flying +actionTable db 00001101b, \ ;EMPTY + 00001101b, \ ;RUBBLE + 00000000b, \ ;GRAVEL + 00000000b, \ ;LOOSE ROCK + 00000000b, \ ;HARD ROCK + 00000000b, \ ;MASSIVE ROCK + 00000000b, \ ;KRISTAL SOURCE + 00000000b, \ ;OREROCK + 00001011b, \ ;WATER + 00001001b, \ ;LAVA + 00001101b, \ ;SNAIL HOLE + 00001101b, \ ;EROSION + 00011101b, \ ;POWER PATH + 00011101b, \ ;BUILDING POWER PATH + 00011000b \ ;BUILDING + +UDATASEG + +currentType dd ? +currentOpen TPriorityField ? + +openlist TPriorityField OPEN_LIST_SIZE_MAX dup(?) +openlistSize dw ? +closedlist TField CLOSED_LIST_SIZE_MAX dup(?) +closedlistSize dw ? +backtraceGraph TField MAX_LEVEL_SIZE dup(?) + +END -- cgit v1.2.1 From b40660135a8436fb1d0b2e9ad0b37a2625184140 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 7 Jan 2016 17:59:17 +0100 Subject: Lex comment as Comment when a newline gets escaped --- pygments/lexers/asm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py index 893d7c37..e7e165ed 100644 --- a/pygments/lexers/asm.py +++ b/pygments/lexers/asm.py @@ -450,7 +450,8 @@ class TasmLexer(RegexLexer): include('punctuation'), (register, Name.Builtin), (identifier, Name.Variable), - (r'\\\s*;.*[\r\n]', Text), # Do not match newline when it's preceeded by a + # Do not match newline when it's preceeded by a backslash + (r'(\\\s*)(;.*)([\r\n])', bygroups(Text, Comment.Single, Text)), (r'[\r\n]+', Text, '#pop'), include('whitespace') ], @@ -460,8 +461,8 @@ class TasmLexer(RegexLexer): (r'\n', Comment.Preproc, '#pop'), ], 'whitespace': [ - (r'\n', Text), - (r'\\\n', Text), + (r'[\n\r]', Text), + (r'\\[\n\r]', Text), (r'[ \t]+', Text), (r';.*', Comment.Single) ], -- cgit v1.2.1 From 3efc7cfd7504207ae0af632026be030987fde7ad Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Mon, 22 Feb 2016 10:48:28 -0600 Subject: add basic CLI support for custom lexers/formatters --- pygments/cmdline.py | 50 +++++++++++++++++++++++++++++++++++---------- pygments/lexers/__init__.py | 14 +++++++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 00745edc..43ffbfd4 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -18,7 +18,7 @@ from textwrap import dedent from pygments import __version__, highlight from pygments.util import ClassNotFound, OptionError, docstring_headline, \ guess_decode, guess_decode_from_terminal, terminal_encoding -from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, \ +from pygments.lexers import get_all_lexers, get_lexer_by_name, load_lexer_from_file, guess_lexer, \ get_lexer_for_filename, find_lexer_class_for_filename from pygments.lexers.special import TextLexer from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter @@ -320,11 +320,25 @@ def main_inner(popts, args, usage): # given by name? lexername = opts.pop('-l', None) if lexername: - try: - lexer = get_lexer_by_name(lexername, **parsed_opts) - except (OptionError, ClassNotFound) as err: - print('Error:', err, file=sys.stderr) - return 1 + # custom lexer, located relative to user's cwd + if lexername[-3:] == '.py': + try: + lexer = load_lexer_from_file(lexername, **parsed_opts) + except IOError as err: + print('Error: cannot read %s:' % lexername, err, file=sys.stderr) + return 1 + except ImportError as err: + print('Error: no CustomLexer class found in %s' % lexername, file=sys.stderr) + return 1 + except Exception as err: + print('Error:', err, file=sys.stderr) + return 1 + else: + try: + lexer = get_lexer_by_name(lexername, **parsed_opts) + except (OptionError, ClassNotFound) as err: + print('Error:', err, file=sys.stderr) + return 1 # read input code code = None @@ -401,11 +415,25 @@ def main_inner(popts, args, usage): outfn = opts.pop('-o', None) fmter = opts.pop('-f', None) if fmter: - try: - fmter = get_formatter_by_name(fmter, **parsed_opts) - except (OptionError, ClassNotFound) as err: - print('Error:', err, file=sys.stderr) - return 1 + # custom formatter, located relative to user's cwd + if fmter[-3:] == '.py': + try: + fmter = load_formatter_from_file(fmter, **parsed_opts) + except IOError as err: + print('Error: cannot read %s:' % fmter, err, file=sys.stderr) + return 1 + except ImportError as err: + print('Error: no CustomFormatter class found in %s' % fmter, file=sys.stderr) + return 1 + except Exception as err: + print('Error:', err, file=sys.stderr) + return 1 + else: + try: + fmter = get_formatter_by_name(fmter, **parsed_opts) + except (OptionError, ClassNotFound) as err: + print('Error:', err, file=sys.stderr) + return 1 if outfn: if not fmter: diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py index d64f163f..25a4cd17 100644 --- a/pygments/lexers/__init__.py +++ b/pygments/lexers/__init__.py @@ -14,6 +14,7 @@ import sys import types import fnmatch from os.path import basename +from imp import load_source from pygments.lexers._mapping import LEXERS from pygments.modeline import get_filetype_from_buffer @@ -114,6 +115,19 @@ def get_lexer_by_name(_alias, **options): return cls(**options) raise ClassNotFound('no lexer for alias %r found' % _alias) +def load_lexer_from_file(filename, **options): + """Load a lexer from a file. + + This method expects a file located relative to the current working + directory, which contains a class named CustomLexer. + + Raises ? under ? conditions + """ + # Load file as if calling import _ as customlexer + load_source('customlexer', filename) + # Instantiate the CustomLexer from that file + from customlexer import CustomLexer + return CustomLexer(**options) def find_lexer_class_for_filename(_fn, code=None): """Get a lexer for a filename. -- cgit v1.2.1 From 3d2e08fc9844f34d80577aa2444a852fb9cdefd7 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Mon, 22 Feb 2016 13:37:30 -0600 Subject: Add additional command line option to prevent users from using eval() on untrusted files Finish custom-formatter loading and fill in some docstrings Add load_?_from_file functions to API documentation pep8 compliance --- doc/docs/api.rst | 24 ++++++++++++++++++++++++ pygments/cmdline.py | 34 +++++++++++++++++++++++++--------- pygments/formatters/__init__.py | 21 +++++++++++++++++++++ pygments/lexers/__init__.py | 9 ++++++++- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/doc/docs/api.rst b/doc/docs/api.rst index dd831bd1..1b6ca668 100644 --- a/doc/docs/api.rst +++ b/doc/docs/api.rst @@ -62,6 +62,18 @@ Functions from :mod:`pygments.lexers`: Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype is found. +.. function:: load_lexer_from_file(filename, **options) + + Return a `Lexer` subclass instance loaded from the provided file, relative + to the current directory. The file is expected to contain a CustomLexer class + which matches Pygments' lexer definitions. Users should be very careful with + the input, because this method is equivalent to running eval on the input file. + The lexer is given the `options` at its instantiation. + + :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ImportError` is raised if the file doesn't have a CustomLexer class + :exc:`Exception` for any other error raised when evaluating filename + .. function:: guess_lexer(text, **options) Return a `Lexer` subclass instance that's guessed from the text in @@ -125,6 +137,18 @@ Functions from :mod:`pygments.formatters`: Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename is found. +.. function:: load_formatter_from_file(filename, **options) + + Return a `Formatter` subclass instance loaded from the provided file, relative + to the current directory. The file is expected to contain a CustomFormatter class + which matches Pygments' formatter definitions. Users should be very careful with + the input, because this method is equivalent to running eval on the input file. + The formatter is given the `options` at its instantiation. + + :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ImportError` is raised if the file doesn't have a CustomFormatter class + :exc:`Exception` for any other error raised when evaluating filename + .. module:: pygments.styles diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 43ffbfd4..f5fb2d0d 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -18,12 +18,12 @@ from textwrap import dedent from pygments import __version__, highlight from pygments.util import ClassNotFound, OptionError, docstring_headline, \ guess_decode, guess_decode_from_terminal, terminal_encoding -from pygments.lexers import get_all_lexers, get_lexer_by_name, load_lexer_from_file, guess_lexer, \ - get_lexer_for_filename, find_lexer_class_for_filename +from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, \ + load_lexer_from_file, get_lexer_for_filename, find_lexer_class_for_filename from pygments.lexers.special import TextLexer from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter from pygments.formatters import get_all_formatters, get_formatter_by_name, \ - get_formatter_for_filename, find_formatter_class + load_formatter_from_file, get_formatter_for_filename, find_formatter_class from pygments.formatters.terminal import TerminalFormatter from pygments.filters import get_all_filters, find_filter_class from pygments.styles import get_all_styles, get_style_by_name @@ -57,6 +57,13 @@ Likewise, is a formatter name, and will be guessed from the extension of the output file name. If no output file is given, the terminal formatter will be used by default. +The additional option --load-from-file allows custom lexers and formatters +to be loaded from a .py file relative to the current working directory. +For example, ``-l ./customlexer.py --load-from-file``. The file should +contain a CustomLexer or CustomFormatter class which matches the Pygments +lexer and formatter definitions. Users should be very careful not to use +this option with untrusted files, because it will eval() them. + With the -O option, you can give the lexer and formatter a comma- separated list of options, e.g. ``-O bg=light,python=cool``. @@ -314,6 +321,11 @@ def main_inner(popts, args, usage): F_opts = _parse_filters(F_opts) opts.pop('-F', None) + allow_custom_lexer_formatter = False + # --load-from-file: allow custom lexers and formatters + if opts.pop('--load-from-file', None) is not None: + allow_custom_lexer_formatter = True + # select lexer lexer = None @@ -321,14 +333,16 @@ def main_inner(popts, args, usage): lexername = opts.pop('-l', None) if lexername: # custom lexer, located relative to user's cwd - if lexername[-3:] == '.py': + if allow_custom_lexer_formatter and lexername[-3:] == '.py': try: lexer = load_lexer_from_file(lexername, **parsed_opts) except IOError as err: - print('Error: cannot read %s:' % lexername, err, file=sys.stderr) + print('Error: cannot read %s:' % lexername, err, + file=sys.stderr) return 1 except ImportError as err: - print('Error: no CustomLexer class found in %s' % lexername, file=sys.stderr) + print('Error: no CustomLexer class found in %s' % lexername, + file=sys.stderr) return 1 except Exception as err: print('Error:', err, file=sys.stderr) @@ -416,14 +430,15 @@ def main_inner(popts, args, usage): fmter = opts.pop('-f', None) if fmter: # custom formatter, located relative to user's cwd - if fmter[-3:] == '.py': + if allow_custom_lexer_formatter and fmter[-3:] == '.py': try: fmter = load_formatter_from_file(fmter, **parsed_opts) except IOError as err: print('Error: cannot read %s:' % fmter, err, file=sys.stderr) return 1 except ImportError as err: - print('Error: no CustomFormatter class found in %s' % fmter, file=sys.stderr) + print('Error: no CustomFormatter class found in %s' % fmter, + file=sys.stderr) return 1 except Exception as err: print('Error:', err, file=sys.stderr) @@ -523,7 +538,8 @@ def main(args=sys.argv): usage = USAGE % ((args[0],) * 6) try: - popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgs") + popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgs", + ["load-from-file"]) except getopt.GetoptError: print(usage, file=sys.stderr) return 2 diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py index 8ddf0ee3..369fb891 100644 --- a/pygments/formatters/__init__.py +++ b/pygments/formatters/__init__.py @@ -14,6 +14,7 @@ import sys import types import fnmatch from os.path import basename +from imp import load_source from pygments.formatters._mapping import FORMATTERS from pygments.plugin import find_plugin_formatters @@ -79,6 +80,26 @@ def get_formatter_by_name(_alias, **options): return cls(**options) +def load_formatter_from_file(filename, **options): + """Load a formatter from a file. + + This method expects a file located relative to the current working + directory, which contains a class named CustomFormatter. + + Users should be very careful with the input, because this method + is equivalent to running eval on the input file. + + Raises IOError if the file is not found/unreadable + Raises ImportError if the file doesn't have a CustomFormatter class + Raises whatever errors could happen when we eval(file) + """ + # Load file as if calling import _ as customformatter + load_source('customformatter', filename) + # Instantiate the CustomFormatter from that file + from customformatter import CustomFormatter + return CustomFormatter(**options) + + def get_formatter_for_filename(fn, **options): """Lookup and instantiate a formatter by filename pattern. diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py index 25a4cd17..ff4bfb34 100644 --- a/pygments/lexers/__init__.py +++ b/pygments/lexers/__init__.py @@ -115,13 +115,19 @@ def get_lexer_by_name(_alias, **options): return cls(**options) raise ClassNotFound('no lexer for alias %r found' % _alias) + def load_lexer_from_file(filename, **options): """Load a lexer from a file. This method expects a file located relative to the current working directory, which contains a class named CustomLexer. - Raises ? under ? conditions + Users should be very careful with the input, because this method + is equivalent to running eval on the input file. + + Raises IOError if the file is not found/unreadable + Raises ImportError if the file doesn't have a CustomLexer class + Raises whatever errors could happen when we eval(file) """ # Load file as if calling import _ as customlexer load_source('customlexer', filename) @@ -129,6 +135,7 @@ def load_lexer_from_file(filename, **options): from customlexer import CustomLexer return CustomLexer(**options) + def find_lexer_class_for_filename(_fn, code=None): """Get a lexer for a filename. -- cgit v1.2.1 From 4a8e158be9bdfa22f112f27ff62e83896ef5af86 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Mon, 22 Feb 2016 15:47:11 -0600 Subject: add tests for custom lexer/formatter loading from file --- tests/support/empty.py | 0 tests/support/python_lexer.py | 226 ++++++++++++++++++++++++++++++++++++++++++ tests/test_cmdline.py | 35 +++++++ 3 files changed, 261 insertions(+) create mode 100644 tests/support/empty.py create mode 100644 tests/support/python_lexer.py diff --git a/tests/support/empty.py b/tests/support/empty.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/support/python_lexer.py b/tests/support/python_lexer.py new file mode 100644 index 00000000..b1367715 --- /dev/null +++ b/tests/support/python_lexer.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.python (as CustomLexer) + ~~~~~~~~~~~~~~~~~~~~~~ + + For test_cmdline.py +""" + +import re + +from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ + default, words, combined, do_insertions +from pygments.util import get_bool_opt, shebang_matches +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Generic, Other, Error +from pygments import unistring as uni + +line_re = re.compile('.*?\n') + + +class CustomLexer(RegexLexer): + """ + For `Python `_ source code. + """ + + name = 'Python' + aliases = ['python', 'py', 'sage'] + filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'] + mimetypes = ['text/x-python', 'application/x-python'] + + def innerstring_rules(ttype): + return [ + # the old style '%s' % (...) string formatting + (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' + '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), + # backslashes, quotes and formatting signs must be parsed one at a time + (r'[^\\\'"%\n]+', ttype), + (r'[\'"\\]', ttype), + # unhandled string formatting sign + (r'%', ttype), + # newlines are an error (use "nl" state) + ] + + tokens = { + 'root': [ + (r'\n', Text), + (r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)), + (r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)), + (r'[^\S\n]+', Text), + (r'\A#!.+$', Comment.Hashbang), + (r'#.*$', Comment.Single), + (r'[]{}:(),;[]', Punctuation), + (r'\\\n', Text), + (r'\\', Text), + (r'(in|is|and|or|not)\b', Operator.Word), + (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator), + include('keywords'), + (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'), + (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'), + (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), + 'fromimport'), + (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), + 'import'), + include('builtins'), + include('magicfuncs'), + include('magicvars'), + include('backtick'), + ('(?:[rR]|[uU][rR]|[rR][uU])"""', String.Double, 'tdqs'), + ("(?:[rR]|[uU][rR]|[rR][uU])'''", String.Single, 'tsqs'), + ('(?:[rR]|[uU][rR]|[rR][uU])"', String.Double, 'dqs'), + ("(?:[rR]|[uU][rR]|[rR][uU])'", String.Single, 'sqs'), + ('[uU]?"""', String.Double, combined('stringescape', 'tdqs')), + ("[uU]?'''", String.Single, combined('stringescape', 'tsqs')), + ('[uU]?"', String.Double, combined('stringescape', 'dqs')), + ("[uU]?'", String.Single, combined('stringescape', 'sqs')), + include('name'), + include('numbers'), + ], + 'keywords': [ + (words(( + 'assert', 'break', 'continue', 'del', 'elif', 'else', 'except', + 'exec', 'finally', 'for', 'global', 'if', 'lambda', 'pass', + 'print', 'raise', 'return', 'try', 'while', 'yield', + 'yield from', 'as', 'with'), suffix=r'\b'), + Keyword), + ], + 'builtins': [ + (words(( + '__import__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', + 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', + 'cmp', 'coerce', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod', + 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', + 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', + 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', + 'list', 'locals', 'long', 'map', 'max', 'min', 'next', 'object', + 'oct', 'open', 'ord', 'pow', 'property', 'range', 'raw_input', 'reduce', + 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', + 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', + 'unichr', 'unicode', 'vars', 'xrange', 'zip'), + prefix=r'(?]*>', '', o) + # rstrip is necessary since HTML inserts a \n after the last + self.assertEqual(o.rstrip(), TESTCODE.rstrip()) + def test_stream_opt(self): o = self.check_success('-lpython', '-s', '-fterminal', stdin=TESTCODE) o = re.sub(r'\x1b\[.*?m', '', o) @@ -211,6 +218,20 @@ class CmdLineTest(unittest.TestCase): e = self.check_failure('-lfooo', TESTFILE) self.assertTrue('Error: no lexer for alias' in e) + # cannot load .py file without load_from_file flag + e = self.check_failure('-l', 'nonexistent.py', TESTFILE) + self.assertTrue('Error: no lexer for alias' in e) + + # lexer file is missing/unreadable + e = self.check_failure('-l', 'nonexistent.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: cannot read' in e) + + # lexer file is malformed + e = self.check_failure('-l', 'support/empty.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: no CustomLexer class found' in e) + # formatter not found e = self.check_failure('-lpython', '-ffoo', TESTFILE) self.assertTrue('Error: no formatter found for name' in e) @@ -219,6 +240,20 @@ class CmdLineTest(unittest.TestCase): e = self.check_failure('-ofoo.foo', TESTFILE) self.assertTrue('Error: no formatter found for file name' in e) + # cannot load .py file without load_from_file flag + e = self.check_failure('-f', 'nonexistent.py', TESTFILE) + self.assertTrue('Error: no formatter found for name' in e) + + # formatter file is missing/unreadable + e = self.check_failure('-f', 'nonexistent.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: cannot read' in e) + + # formatter file is malformed + e = self.check_failure('-f', 'support/empty.py', + '--load-from-file', TESTFILE) + self.assertTrue('Error: no CustomFormatter class found' in e) + # output file not writable e = self.check_failure('-o', os.path.join('nonexistent', 'dir', 'out.html'), '-lpython', TESTFILE) -- cgit v1.2.1 From cdec8b0e72a2716581d9e44174b754e2cb1b5c16 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Mon, 22 Feb 2016 16:34:46 -0600 Subject: Add api, command line, etc. documentation for custom lexer/formatter loading --- doc/docs/api.rst | 11 +++++++++-- doc/docs/cmdline.rst | 13 +++++++++++++ doc/docs/lexerdevelopment.rst | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/doc/docs/api.rst b/doc/docs/api.rst index 1b6ca668..ea158d65 100644 --- a/doc/docs/api.rst +++ b/doc/docs/api.rst @@ -71,8 +71,12 @@ Functions from :mod:`pygments.lexers`: The lexer is given the `options` at its instantiation. :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ImportError` is raised if the file doesn't have a CustomLexer class - :exc:`Exception` for any other error raised when evaluating filename + + Additionally, arbitrary exceptions could occur when evaluating the file + + .. versionadded:: ? .. function:: guess_lexer(text, **options) @@ -146,9 +150,12 @@ Functions from :mod:`pygments.formatters`: The formatter is given the `options` at its instantiation. :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ImportError` is raised if the file doesn't have a CustomFormatter class - :exc:`Exception` for any other error raised when evaluating filename + Additionally, arbitrary exceptions could occur when evaluating the file + + .. versionadded:: ? .. module:: pygments.styles diff --git a/doc/docs/cmdline.rst b/doc/docs/cmdline.rst index 165af969..8fcd3c8c 100644 --- a/doc/docs/cmdline.rst +++ b/doc/docs/cmdline.rst @@ -99,6 +99,19 @@ The ``-N`` option guesses a lexer name for a given filename, so that :: will print out ``python``. It won't highlight anything yet. If no specific lexer is known for that filename, ``text`` is printed. +Custom Lexers and Formatters +---------------------------- + +.. versionadded:: ? + +The ``--load-from-file`` flag enables custom lexers and formatters to be loaded +from files relative to the current directory. Create a file with a class named +CustomLexer or CustomFormatter, then specify it on the command line:: + + $ pygmentize -l your_lexer.py -f your_formatter.py --load-from-file + +For more information, see :doc:`the Pygments documentation on Lexer development +`. Getting help ------------ diff --git a/doc/docs/lexerdevelopment.rst b/doc/docs/lexerdevelopment.rst index 2c868440..8c9b7baa 100644 --- a/doc/docs/lexerdevelopment.rst +++ b/doc/docs/lexerdevelopment.rst @@ -88,8 +88,38 @@ one. Adding and testing a new lexer ============================== -To make Pygments aware of your new lexer, you have to perform the following -steps: +The easiest way to use a new lexer is to use Pygments' support for loading +the lexer from a file relative to your current directory. + +First, change the name of your lexer class to CustomLexer: + +.. code-block:: python + + from pygments.lexer import RegexLexer + from pygments.token import * + + class CustomLexer(RegexLexer): + """All your lexer code goes here!""" + +Then you can load the lexer from the command line with the additional +flag ``--load-from-file``: + +.. code-block:: console + + $ pygmentize -l your_lexer_file.py --load-from-file + +Or, using the Python API: + +.. code-block:: python + + your_lexer = load_lexer_from_file(filename, **options) + +When loading custom lexers and formatters, be extremely careful to use only +trusted files; Pygments will perform the equivalent of ``eval`` on them. + +For more complicated tasks, you should add your lexer to Pygments. If you +want to make Pygments aware of your new lexer, you have to perform the +following steps: First, change to the current directory containing the Pygments source code: -- cgit v1.2.1 From 1dcbeab604b4f6b9402a05895ceef1ce31177339 Mon Sep 17 00:00:00 2001 From: Tanner Prynn Date: Wed, 24 Feb 2016 17:46:32 -0600 Subject: Update pull request per comments by birkenfeld. Add optional function parameter for the class name to instantiate, and update cli to support this. Move error handling to within the loading functions; they now only raise ClassNotFound. Modify doc with these updates and the version number. Test case clean up and additions. --- doc/docs/api.rst | 32 +++++++++------------- doc/docs/cmdline.rst | 10 ++++--- doc/docs/lexerdevelopment.rst | 14 ++++++++-- pygments/cmdline.py | 59 +++++++++++++++++++---------------------- pygments/formatters/__init__.py | 34 +++++++++++++++++------- pygments/lexers/__init__.py | 33 ++++++++++++++++------- tests/support/html_formatter.py | 5 ++++ tests/support/python_lexer.py | 4 ++- tests/test_cmdline.py | 35 ++++++++++++++++++------ 9 files changed, 140 insertions(+), 86 deletions(-) create mode 100644 tests/support/html_formatter.py diff --git a/doc/docs/api.rst b/doc/docs/api.rst index ea158d65..a6b242dd 100644 --- a/doc/docs/api.rst +++ b/doc/docs/api.rst @@ -62,21 +62,17 @@ Functions from :mod:`pygments.lexers`: Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype is found. -.. function:: load_lexer_from_file(filename, **options) +.. function:: load_lexer_from_file(filename, lexername="CustomLexer", **options) Return a `Lexer` subclass instance loaded from the provided file, relative - to the current directory. The file is expected to contain a CustomLexer class - which matches Pygments' lexer definitions. Users should be very careful with + to the current directory. The file is expected to contain a Lexer class + named `lexername` (by default, CustomLexer). Users should be very careful with the input, because this method is equivalent to running eval on the input file. The lexer is given the `options` at its instantiation. - :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ClassNotFound` is raised if there are any errors loading the Lexer - :exc:`ImportError` is raised if the file doesn't have a CustomLexer class - - Additionally, arbitrary exceptions could occur when evaluating the file - - .. versionadded:: ? + .. versionadded:: 2.2 .. function:: guess_lexer(text, **options) @@ -141,21 +137,17 @@ Functions from :mod:`pygments.formatters`: Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename is found. -.. function:: load_formatter_from_file(filename, **options) +.. function:: load_formatter_from_file(filename, formattername="CustomFormatter", **options) Return a `Formatter` subclass instance loaded from the provided file, relative - to the current directory. The file is expected to contain a CustomFormatter class - which matches Pygments' formatter definitions. Users should be very careful with - the input, because this method is equivalent to running eval on the input file. - The formatter is given the `options` at its instantiation. + to the current directory. The file is expected to contain a Formatter class + named ``formattername`` (by default, CustomFormatter). Users should be very + careful with the input, because this method is equivalent to running eval + on the input file. The formatter is given the `options` at its instantiation. - :exc:`IOError` is raised if the file is not found or unreadable + :exc:`ClassNotFound` is raised if there are any errors loading the Formatter - :exc:`ImportError` is raised if the file doesn't have a CustomFormatter class - - Additionally, arbitrary exceptions could occur when evaluating the file - - .. versionadded:: ? + .. versionadded:: 2.2 .. module:: pygments.styles diff --git a/doc/docs/cmdline.rst b/doc/docs/cmdline.rst index 8fcd3c8c..e4f94ea5 100644 --- a/doc/docs/cmdline.rst +++ b/doc/docs/cmdline.rst @@ -102,13 +102,17 @@ lexer is known for that filename, ``text`` is printed. Custom Lexers and Formatters ---------------------------- -.. versionadded:: ? +.. versionadded:: 2.2 -The ``--load-from-file`` flag enables custom lexers and formatters to be loaded +The ``-x`` flag enables custom lexers and formatters to be loaded from files relative to the current directory. Create a file with a class named CustomLexer or CustomFormatter, then specify it on the command line:: - $ pygmentize -l your_lexer.py -f your_formatter.py --load-from-file + $ pygmentize -l your_lexer.py -f your_formatter.py -x + +You can also specify the name of your class with a colon:: + + $ pygmentize -l your_lexer.py:SomeLexer -x For more information, see :doc:`the Pygments documentation on Lexer development `. diff --git a/doc/docs/lexerdevelopment.rst b/doc/docs/lexerdevelopment.rst index 8c9b7baa..bba81d24 100644 --- a/doc/docs/lexerdevelopment.rst +++ b/doc/docs/lexerdevelopment.rst @@ -102,18 +102,28 @@ First, change the name of your lexer class to CustomLexer: """All your lexer code goes here!""" Then you can load the lexer from the command line with the additional -flag ``--load-from-file``: +flag ``-x``: .. code-block:: console - $ pygmentize -l your_lexer_file.py --load-from-file + $ pygmentize -l your_lexer_file.py -x + +To specify a class name other than CustomLexer, append it with a colon: + +.. code-block:: console + + $ pygmentize -l your_lexer.py:SomeLexer -x Or, using the Python API: .. code-block:: python + # For a lexer named CustomLexer your_lexer = load_lexer_from_file(filename, **options) + # For a lexer named MyNewLexer + your_named_lexer = load_lexer_from_file(filename, "MyNewLexer", **options) + When loading custom lexers and formatters, be extremely careful to use only trusted files; Pygments will perform the equivalent of ``eval`` on them. diff --git a/pygments/cmdline.py b/pygments/cmdline.py index f5fb2d0d..69604481 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -31,7 +31,7 @@ from pygments.styles import get_all_styles, get_style_by_name USAGE = """\ Usage: %s [-l | -g] [-F [:]] [-f ] - [-O ] [-P ] [-s] [-v] [-o ] [] + [-O ] [-P ] [-s] [-v] [-x] [-o ] [] %s -S