From 18f5c40b67396182551a26fc7e63327f3bee5a0f Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Sun, 1 Oct 2017 22:57:01 +0100 Subject: [PATCH] Mostly working however termcap is still throwing spanners --- lenses/getcap.aug | 15 +- lenses/tests/test_getcap.aug | 437 ++++++++++++++++++++++++++++++++--- 2 files changed, 412 insertions(+), 40 deletions(-) diff --git a/lenses/getcap.aug b/lenses/getcap.aug index a20c0e766..9d833d3e4 100644 --- a/lenses/getcap.aug +++ b/lenses/getcap.aug @@ -22,25 +22,26 @@ module Getcap = let eol = Util.eol - let comment = Util.comment + (* Comments cannot have any leading characters *) + let comment = Util.comment_generic /#[ \t]*/ "# " let empty = Util.empty (* field must not contain ':' unless quoted or '\'-escaped *) - let nfield = /[^:\\\n#|]+/ - (* let field = /[^:\\\n]+/ *) - let field = /([^:\\\n]|\\\\.)+|[^:\n]*(\"[^\n]+\"[^:\n]*)+/ + let nfield = /[^#:\\\\\t\n|][^:\\\\\t\n|]*/ + let cfield = /[*!#@.%&]*[a-zA-Z0-9-]+[;]?([%^$#]?@|[%^$#=]("[^"]*"|([^:\\\\"^]|\\\\.|\\^)([^:\\\\^]|\\\\.|\\^|")*)?)?/ - let sep = del /:([ \t]*\\\\\n[ \t]*:)?/ ":\\\n\t:" + let csep = del /:([ \t]*\\\\\n[ \t]*:)?/ ":\\\n\t:" let nsep = Util.del_str "|" let name = [ label "name" . store nfield ] - let capability = [ label "capability" . store field ] - let record = [ seq "record" . name . ( nsep . name )* . sep . capability . ( sep . capability )* . Sep.colon . eol ] + let capability = [ label "capability" . store cfield ] + let record = [ seq "record" . name . ( nsep . name )* . csep . capability . ( csep . capability )* . Sep.colon . eol ] let lns = ( empty | comment | record )* let filter = incl "/etc/login.conf" . incl "/etc/printcap" . incl "/etc/rtadvd.conf" + . incl "/etc/termcap" . incl "/usr/share/misc/termcap" . Util.stdexcl diff --git a/lenses/tests/test_getcap.aug b/lenses/tests/test_getcap.aug index 37843b117..e3e435aa6 100644 --- a/lenses/tests/test_getcap.aug +++ b/lenses/tests/test_getcap.aug @@ -1,9 +1,9 @@ module Test_getcap = - (* Example from getcap(3) *) - let getcap = "example|an example of binding multiple values to names:\ - :foo%bar:foo^blah:foo@:\ - :abc%xyz:abc^frap:abc$@:\ +(* Example from getcap(3) *) +let getcap = "example|an example of binding multiple values to names:\\ + :foo%bar:foo^blah:foo@:\\ + :abc%xyz:abc^frap:abc$@:\\ :tc=more: " @@ -20,8 +20,8 @@ test Getcap.lns get getcap = { "capability" = "tc=more" } } - (* Taken from the standard /etc/login.conf *) - let login_conf = "# Default allowed authentication styles +(* Taken from the standard /etc/login.conf *) +let login_conf = "# Default allowed authentication styles auth-defaults:auth=passwd,skey: # Default allowed authentication styles for authentication type ftp @@ -36,24 +36,24 @@ auth-ftp-defaults:auth-ftp=passwd: # Any value changed in the daemon class should be reset in default # class. # -default:\ - :path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin:\ - :umask=022:\ - :datasize-max=512M:\ - :datasize-cur=512M:\ - :maxproc-max=256:\ - :maxproc-cur=128:\ - :openfiles-cur=512:\ - :stacksize-cur=4M:\ - :localcipher=blowfish,8:\ - :ypcipher=old:\ - :tc=auth-defaults:\ +default:\\ + :path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin:\\ + :umask=022:\\ + :datasize-max=512M:\\ + :datasize-cur=512M:\\ + :maxproc-max=256:\\ + :maxproc-cur=128:\\ + :openfiles-cur=512:\\ + :stacksize-cur=4M:\\ + :localcipher=blowfish,8:\\ + :ypcipher=old:\\ + :tc=auth-defaults:\\ :tc=auth-ftp-defaults: " test Getcap.lns get login_conf = { "#comment" = "Default allowed authentication styles" } - { "1" + { "1" { "name" = "auth-defaults" } { "capability" = "auth=passwd,skey" } } @@ -73,7 +73,7 @@ test Getcap.lns get login_conf = { "#comment" = "Any value changed in the daemon class should be reset in default" } { "#comment" = "class." } { } - { "3" + { "3" { "name" = "default" } { "capability" = "path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin" } { "capability" = "umask=022" } @@ -89,16 +89,16 @@ test Getcap.lns get login_conf = { "capability" = "tc=auth-ftp-defaults" } } - (* Example from rtadvd.conf(5) *) -(* let rtadvd_conf = "default:\ - :chlim#64:raflags#0:rltime#1800:rtime#0:retrans#0:\ +(* Example from rtadvd.conf(5) *) +let rtadvd_conf = "default:\\ + :chlim#64:raflags#0:rltime#1800:rtime#0:retrans#0:\\ :pinfoflags=\"la\":vltime#2592000:pltime#604800:mtu#0: -ef0:\ +ef0:\\ :addr=\"2001:db8:ffff:1000::\":prefixlen#64:tc=default: " test Getcap.lns get rtadvd_conf = - { "1" + { "1" { "name" = "default" } { "capability" = "chlim#64" } { "capability" = "raflags#0" } @@ -110,27 +110,27 @@ test Getcap.lns get rtadvd_conf = { "capability" = "pltime#604800" } { "capability" = "mtu#0" } } - { "2" + { "2" { "name" = "ef0" } { "capability" = "addr=\"2001:db8:ffff:1000::\"" } { "capability" = "prefixlen#64" } { "capability" = "tc=default" } - } *) + } - (* Sample /etc/printcap *) - let printcap = "# $OpenBSD: printcap,v 1.1 2014/07/12 03:52:39 deraadt Exp $ +(* Sample /etc/printcap *) +let printcap = "# $OpenBSD: printcap,v 1.1 2014/07/12 03:52:39 deraadt Exp $ -lp|local line printer:\ +lp|local line printer:\\ :lp=/dev/lp:sd=/var/spool/output:lf=/var/log/lpd-errs: -rp|remote line printer:\ +rp|remote line printer:\\ :lp=:rm=printhost:rp=lp:sd=/var/spool/output:lf=/var/log/lpd-errs: " test Getcap.lns get printcap = { "#comment" = "$OpenBSD: printcap,v 1.1 2014/07/12 03:52:39 deraadt Exp $" } { } - { "1" + { "1" { "name" = "lp" } { "name" = "local line printer" } { "capability" = "lp=/dev/lp" } @@ -138,7 +138,7 @@ test Getcap.lns get printcap = { "capability" = "lf=/var/log/lpd-errs" } } { } - { "2" + { "2" { "name" = "rp" } { "name" = "remote line printer" } { "capability" = "lp=" } @@ -147,3 +147,374 @@ test Getcap.lns get printcap = { "capability" = "sd=/var/spool/output" } { "capability" = "lf=/var/log/lpd-errs" } } + +(* Sample termcap entry with escaped ':''s *) +let termcap = "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\\:vt420pcdos\\::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: +" + +let termcap2 = "tws-generic|dku7102|Bull Questar tws terminals:\\ + :am:es:hs:mi:ms:xn:xo:xs@:\\ + :co#80:it#8:li#24:ws#80:\\ + :AL=\\E[%d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ta=^I:te=\\Ev\\E. \\Ee\\Ez_:\\ + :ti=\\Ev\\Ee\\Ez_:ue=\\EzH:up=\\EA:us=\\EyH:ve=\\E. \\Ee:vi=\\Ef:\\ + :vs=\\E.\": +" + +let termcap4 = "rbcomm|IBM PC with RBcomm and EMACS keybindings:\\ + :am:bw:mi:ms:xn:\\ + :co#80:it#8:li#25:\\ + :AL=\\E[%dL:DL=\\E[%dM:al=^K:bl=^G:bt=\\E[Z:cd=^F5:ce=^P^P:\\ + :cl=^L:cm=\\037%r%+ %+ :cr=^M:cs=\\E[%i%d;%dr:dc=^W:dl=^Z:\\ + :dm=:do=^C:ec=\\E[%dX:ed=:ei=^]:im=^\\:\\ + :is=\\017\\035\\E(B\\E)0\\E[?7h\\E[?3l\\E[>8g:kb=^H:kd=^N:\\ + :ke=\\E>:kh=^A:kl=^B:kr=^F:ks=\\E=:ku=^P:le=^H:mb=\\E[5m:\\ + :md=\\E[1m:me=\\E[m:mk=\\E[8m:mr=^R:nd=^B:nw=^M\\ED:\\ + :r1=\\017\\E(B\\E)0\\025\\E[?3l\\E[>8g:rc=\\E8:rp=\\030%.%.:\\ + :sc=\\E7:se=^U:sf=\\ED:so=^R:sr=\\EM:ta=^I:te=:ti=:ue=^U:up=^^:\\ + :us=^T:ve=\\E[?25h:vi=\\E[?25l: +" + +let termcap5 = "rxvt+pcfkeys|fragment for PC-style fkeys:\\ + :#2=\\E[7$:#3=\\E[2$:#4=\\E[d:%c=\\E[6$:%e=\\E[5$:%i=\\E[c:\\ + :*4=\\E[3$:*6=\\E[4~:*7=\\E[8$:@0=\\E[1~:@7=\\E[8~: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~:FB=\\E[23$:\\ + :FC=\\E[24$:FD=\\E[11^:FE=\\E[12^:FF=\\E[13^:FG=\\E[14^:\\ + :FH=\\E[15^:FI=\\E[17^:FJ=\\E[18^:FK=\\E[19^:FL=\\E[20^:\\ + :FM=\\E[21^:FN=\\E[23^:FO=\\E[24^:FP=\\E[25^:FQ=\\E[26^:\\ + :FR=\\E[28^:FS=\\E[29^:FT=\\E[31^:FU=\\E[32^:FV=\\E[33^:\\ + :FW=\\E[34^:FX=\\E[23@:FY=\\E[24@: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=\\E[3~:kE=\\E[8^:kF=\\E[a:\\ + :kI=\\E[2~:kN=\\E[6~:kP=\\E[5~:kR=\\E[b:kd=\\E[B:kh=\\E[7~:\\ + :kl=\\E[D:kr=\\E[C:ku=\\E[A: +" + +test Getcap.lns get termcap = + { "1" + { "name" = "vt420pc" } + { "name" = "DEC VT420 w/PC keyboard" } + { "capability" = "@7=\\E[4~" } + { "capability" = "F1=\\E[23~" } + { "capability" = "F2=\\E[24~" } + { "capability" = "F3=\\E[11;2~" } + { "capability" = "F4=\\E[12;2~" } + { "capability" = "F5=\\E[13;2~" } + { "capability" = "F6=\\E[14;2~" } + { "capability" = "F7=\\E[15;2~" } + { "capability" = "F8=\\E[17;2~" } + { "capability" = "F9=\\E[18;2~" } + { "capability" = "FA=\\E[19;2~" } + { "capability" = "FB=\\E[20;2~" } + { "capability" = "FC=\\E[21;2~" } + { "capability" = "FD=\\E[23;2~" } + { "capability" = "FE=\\E[24;2~" } + { "capability" = "FF=\\E[23~" } + { "capability" = "FG=\\E[24~" } + { "capability" = "FH=\\E[25~" } + { "capability" = "FI=\\E[26~" } + { "capability" = "FJ=\\E[28~" } + { "capability" = "FK=\\E[29~" } + { "capability" = "FL=\\E[31~" } + { "capability" = "FM=\\E[32~" } + { "capability" = "FN=\\E[33~" } + { "capability" = "FO=\\E[34~" } + { "capability" = "FP=\\E[35~" } + { "capability" = "FQ=\\E[36~" } + { "capability" = "FR=\\E[23;2~" } + { "capability" = "FS=\\E[24;2~" } + { "capability" = "FT=\\E[25;2~" } + { "capability" = "FU=\\E[26;2~" } + { "capability" = "FV=\\E[28;2~" } + { "capability" = "FW=\\E[29;2~" } + { "capability" = "FX=\\E[31;2~" } + { "capability" = "FY=\\E[32;2~" } + { "capability" = "FZ=\\E[33;2~" } + { "capability" = "Fa=\\E[34;2~" } + { "capability" = "Fb=\\E[35;2~" } + { "capability" = "Fc=\\E[36;2~" } + { "capability" = "S6=USR_TERM\\:vt420pcdos\\:" } + { "capability" = "k1=\\E[11~" } + { "capability" = "k2=\\E[12~" } + { "capability" = "k3=\\E[13~" } + { "capability" = "k4=\\E[14~" } + { "capability" = "k5=\\E[15~" } + { "capability" = "k6=\\E[17~" } + { "capability" = "k7=\\E[18~" } + { "capability" = "k8=\\E[19~" } + { "capability" = "k9=\\E[20~" } + { "capability" = "k;=\\E[21~" } + { "capability" = "kD=\\177" } + { "capability" = "kh=\\E[H" } + { "capability" = "..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\\\\" } + { "capability" = "tc=vt420" } + } + +test Getcap.lns get termcap2 = + { "1" + { "name" = "tws-generic" } + { "name" = "dku7102" } + { "name" = "Bull Questar tws terminals" } + { "capability" = "am" } + { "capability" = "es" } + { "capability" = "hs" } + { "capability" = "mi" } + { "capability" = "ms" } + { "capability" = "xn" } + { "capability" = "xo" } + { "capability" = "xs@" } + { "capability" = "co#80" } + { "capability" = "it#8" } + { "capability" = "li#24" } + { "capability" = "ws#80" } + { "capability" = "AL=\\E[%dL" } + { "capability" = "DC=\\E[%dP" } + { "capability" = "DL=\\E[%dM" } + { "capability" = "DO=\\E[%dB" } + { "capability" = "LE=\\E[%dD" } + { "capability" = "RI=\\E[%dC" } + { "capability" = "UP=\\E[%dA" } + { "capability" = "al=\\E[L" } + { "capability" = "bl=^G" } + { "capability" = "bt=\\E[Z" } + { "capability" = "cd=\\E[J" } + { "capability" = "ce=\\E[K" } + { "capability" = "cl=\\E[2J" } + { "capability" = "cm=\\E[%i%d;%df" } + { "capability" = "cr=^M" } + { "capability" = "ct=\\E[3g" } + { "capability" = "dc=\\E[P" } + { "capability" = "dl=\\E[M" } + { "capability" = "do=^J" } + { "capability" = "ds=\\EPY99\\:98\\E\\\\\\E[0;98v\\E[2J\\E[v" } + { "capability" = "ei=\\E[4l" } + { "capability" = "fs=\\E[v" } + { "capability" = "ho=\\E[H" } + { "capability" = "i1=\\E[?=h\\Ec\\E`\\E[?>h\\EPY99\\:98\\E\\\\\\\\" } + { "capability" = "i2=\\Eb\\E[?