sedtest.mak

来自「开放源码的编译器open watcom 1.6.0版的源代码」· MAK 代码 · 共 1,240 行 · 第 1/3 页

MAK
1,240
字号

set: .symbolic listto.exe
    > afore echo hello
    > xpect echo haaaa
    $(sed) "s/[^h]/a/g"       $(axdiff)
    > xpect echo sed: garbled command /[h
    $(sed) /[h                $(a2xdiff)
    > afore echo h-llo
    > xpect echo haaao
    $(sed) s/[-l]/a/g         $(axdiff)
    > afore echo hello
    > xpect echo aaaao
    $(sed) s/[e-l]/a/g        $(axdiff)
    > xpect echo sed: garbled command s/[l-e]/a/g
    $(sed) s/[l-e]/a/g        $(a2xdiff)
    > xpect echo sed: garbled command /[e-l-o]/p
    $(sed) -n /[e-l-o]/p      $(a2xdiff)
    # fgets() quietly swallows \r on NT.
    > afore $(here)listto.exe $(q)hello\nwor\tld$q
    > xpect echo halloaworald
    $(sed) "N;s/[\e\n\t]/a/g" $(axdiff)
    > afore echo h]llo
    > xpect echo a]aaa
    $(sed) "s/[^]]/a/g"       $(axdiff)
    $(sed) -n /[[:alpha:]]/p  $(aadiff)
    > xpect echo sed: invalid character class name /[[:foo:]]/p
    $(sed) /[[:foo:]]/p       $(a2xdiff)

handle_cket: .symbolic
    > afore echo hello
    $(sed) -n /a*/p                 $(aadiff) # CCHR
    $(sed) -n /.*/p                 $(aadiff) # CDOT
    $(sed) -n /[aeiou]*/p           $(aadiff) # CCL
    $(sed) -n /^*/!p                $(aadiff) # * is literal after special ^
    $(sed) -n $q/$$*/p$q            $(aadiff) # $ is literal if not last
    > xpect echo $(e)sed: garbled address /\(*\)/p$e
    $(sed) -n $q/\(*\)/p$q          $(a2xdiff)       # CBRA
    $(sed) -n $q/\([aeiou]\)*/p$q   $(aadiff) # CKET
    $(sed) -n $q/\([aeiou]\)\1*/p$q $(aadiff) # CBACK
    > xpect echo sed: no such command as 1*p
    $(sed) -n 1*p                   $(a2xdiff) # * after line number is not special
    # By definition, CEND* can't happen CEND is always followed by CEOF
    # By definition, CEOF* can't happen

cmdline: .symbolic
    > afore echo hello
    > xpect echo sed: error processing: -e
    $(sed) -e      <    $(a2xdiff)
    > xpect $(here)listto.exe $(q)sed: garbled command s/h/b\\\n\n$q
    # This used to seize. WFB 20040803
    $(sed) -f <<        $(a2xdiff)
s/h/b\
<<
    # This used to seize. WFB 20040813
    > xpect echo bello
    $(sed) $(q)s/h/b/$q $(axdiff)

address: .symbolic
    > afore echo hello
    $(sed) -n $(q)$$p$q       $(aadiff)
    $(sed) -n $(q)$$p$q afore $(aadiff)
    $(sed) -n $(q)\hehp$q     $(aadiff)
    $(sed) -n /e/p            $(aadiff)
    $(sed) -n 1p              $(aadiff)
    $(sed) -n p               $(aadiff)

gettext: .symbolic listto.exe
    > afore echo hello
    > scrip $(here)listto.exe $(q)a\\\n    world\n$q
    > xpect echo hello
    >>xpect echo     world
    $(sed) -f scrip $(axdiff)
    > scrip $(here)listto.exe $(q)a\\\n     w\\or \\\\ ld\\\nuniverse\n$q
    > xpect $(here)listto.exe $(q)hello\n     wor \\ ld\nuniverse\n$q
    $(sed) -f scrip $(axdiff)

resolve: .symbolic
    > afore echo hello
    > xpect echo $(e)sed: undefined label ":label"$e
    $(sed) blabel              $(a2xdiff)
    $(sed) -e blabel -e :label $(aadiff)

ycomp: .symbolic
    > afore echo $(e)he\lo$e
    > scrip echo y/h
    > xpect echo sed: garbled command y/h
    $(sed) -f scrip                 $(a2xdiff)
    > xpect echo abclo
    $(sed) $(q)y/he\\/abc/$q        $(axdiff)
    > afore echo hello
    >>afore echo world
    > xpect echo hello world
    # "If a backslash followed by an 'n' appear in string1 or string2,
    # the two characters shall be handled as a single <newline>."
    $(sed) "N;y/\n/ /"              $(axdiff)
    > afore echo hello
    > xpect echo h
    >>xpect echo llo
    $(sed) $(q)y/e/\n/$q            $(axdiff)
    # "If the number of characters in string1 and string2 are not equal,
    # or if any of the characters in string1 appear more than once,
    # the results are undefined."
    > afore echo hello
    > xpect echo sed: garbled command y/a//
    $(sed) y/a//                    $(a2xdiff)
    > xpect echo sed: garbled command y//a/
    $(sed) y//a/                    $(a2xdiff)
    > xpect echo sed: garbled command y/hh/el/
    $(sed) y/hh/el/                 $(a2xdiff)
    # Any character other than backslash or <newline>
    # can be used instead of slash to delimit the strings.
    > xpect echo HELLO
    $(sed) yaheloaHELOa             $(axdiff)
    > xpect $(here)listto.exe $(q)sed: garbled command y\\helo\\HELO\\\n\n$q
    $(sed) -f <<                    $(a2xdiff)
y\helo\HELO\
<<
    > xpect $(here)listto.exe $(q)sed: garbled command y\\\\helo\\\\HELO\\\\\n$q
    # >>xpect echo afore
    $(sed) -f <<                    $(a2xdiff)
y\\helo\\HELO\\
<<
    > xpect echo sed: garbled command y
    # "If the delimiter is not 'n' , within string1 and string2,
    # the delimiter itself can be used as a literal character
    # if it is preceded by a backslash."
    # [ "If the delimiter is not 'n'" because \n has a special meaning.]
    > xpect echo HELLh
    $(sed) $(q)yh\helohHEL\hh$q     $(axdiff)
    # "If a backslash character is immediately followed by a backslash
    # character in string1 or string2, the two backslash characters shall be
    # counted as a single literal backslash character. The meaning of a
    # backslash followed by any character that is not 'n' , a backslash, or the
    # delimiter character is undefined."
    >>afore echo $(e)w\rld$e
    > xpect echo h
    >>xpect echo $(e)llo wo\ld$e
    $(sed) $(q)N;y/\\r\ne/o\\ \n/$q $(axdiff)
    > xpect echo $(e)sed: garbled command yh\h\?elohHEL\hh$e
    $(sed) $(q)yh\h\?elohHEL\hh$q   $(a2xdiff)
    > xpect echo $(e)sed: garbled command yh\helohH\?L\hh$e
    $(sed) $(q)yh\helohH\?L\hh$q    $(a2xdiff)
    > xpect echo sed: garbled command y
    > scrip echo y
    >>scrip echo helo
    >>scrip echo HELO
    $(sed) -f scrip                 $(a2xdiff)
    > xpect echo sed: garbled command y/a/
    $(sed) y/a/                     $(a2xdiff)
    > xpect echo sed: garbled command y/a/b
    $(sed) y/a/b                    $(a2xdiff)
    > xpect echo $(e)sed: garbled command y/\h/\h/$e
    $(sed) $(q)y/\h/\h/$q           $(a2xdiff)

execute: .symbolic selected command match
    > afore echo hello
    %write xpect sed: can't open nosuch
    $(sed) -n p nosuch                 afore 2>&1 > after | diff xpect -
    diff afore after
    > xpect echo hello hello
    $(sed) -n $(q)N;$$s/\n/ /p$q afore $(axdiff)
    >>afore echo world
    > xpect echo world
    $(sed) "N;D"                       $(axdiff)
    $(sed) -e b -e p                   $(aadiff)
    $(sed) -e blab -e "p;:lab"         $(aadiff)
    > afore echo hello
    > scrip echo $(e)a\$e
    >>scrip echo world
    > xpect echo hello
    >>xpect echo world
    $(sed) -f scrip                    $(axdiff)

selected: .symbolic
    > afore echo hello
    $(sed) -n $(q)1{p;}$q  $(aadiff)
    >>afore echo world
    > xpect echo world
    $(sed) -n $(q)1!{p;}$q $(axdiff)
    $(sed) -n $(q)$$p$q    $(axdiff)
    >>afore echo universe
    $(sed) -n 2,2p         $(axdiff)
    $(sed) -n /world/,2p   $(axdiff)

match: .symbolic advance
    > afore echo hello
    > xpect echo heLLo
    $(sed) -g s/l/L/ $(axdiff)
    > xpect echo heLlo
    $(sed) s/l/L/    $(axdiff)
    > xpect echo hellO
    $(sed) s/./O/5   $(axdiff)

advance: .symbolic mtype memeql
    > afore echo hello
    > xpect echo Hello
    $(sed) s/h/H/                $(axdiff) # CCHR
    $(sed) s/./H/                $(axdiff) # CDOT
    >>afore echo world
    > xpect echo HHHHHHHHHHH
    $(sed) "N;s/./H/g"           $(axdiff) # CDOT, CDOT | STAR # . should match \n as well as other characters
    > afore echo heho
    >>afore echo horld
    > xpect echo Hehonhorld
    $(sed) "N;s/^h/H/g;s/\n/n/"  $(axdiff) # CNL
    > afore echo delld
    >>afore echo hodld
    > xpect echo delldnhodlD
    $(sed) "N;s/d$$/D/g;s/\n/n/" $(axdiff) # CDOL
    > afore echo hello
    > xpect echo hellO
    $(sed) s/o/O/                $(axdiff) # CEOF
    $(sed) "s/[o][o]*/O/"        $(axdiff) # CCL, CCL | STAR, star
    $(sed) "s/\(o\)/O/"          $(axdiff) # CBRA, CKET
    > xpect echo helo
    $(sed) "s/\(l\)\1/\1/"       $(axdiff) # CBACK
    $(sed) "s/\(o\)\1/\1/"       $(aadiff) # CBACK
    $(sed) "s/\(l\)\1/\1/"       $(axdiff) # CBACK
    > afore echo abababg
    > xpect echo abg
    $(sed) "s/\(..\)\1*/\1/"     $(axdiff) # CBACK | STAR
    $(sed) -n "/\(c*\)\1*/p"     $(aadiff) # CBACK | STAR - zero width \1
    # \(...\)* sets \n to last match
    > afore echo abcdefg
    > xpect echo efg
    $(sed) "s/\(..\)*/\1/"       $(axdiff) # CBRA | STAR, CKET | STAR
    $(sed) -n "/\(foo\)*/p"      $(aadiff) # CBRA | STAR, CKET | STAR
    $(sed) -n "/\(foo\)*\1*/p"   $(aadiff) # CBRA | STAR, CKET | STAR

mtype: .symbolic
    > afore echo aaaaaaa
    > xpect echo b
    $(sed) -n "s/a\{0,\}/b/p"        $(axdiff) # CCHR | MTYPE
    $(sed) -n "s/a\{1,\}/b/p"        $(axdiff)
    > xpect echo baaaaaa
    $(sed) -n "s/a\{1,1\}/b/p"       $(axdiff)
    > xpect echo baa
    $(sed) -n "s/a\{3,5\}/b/p"       $(axdiff)
    > xpect echo b
    $(sed) -n "s/a\{3,8\}/b/p"       $(axdiff)
    $(sed) -n "/a\{8,\}/!p"          $(aadiff)
    > xpect echo baaaaaaa
    $(sed) -n "s/b\{0,\}/b/p"        $(axdiff)
    > afore echo abcdefg
    > xpect echo b
    $(sed) -n "s/.\{0,\}/b/p"        $(axdiff) # CDOT | MTYPE
    $(sed) -n "s/.\{1,\}/b/p"        $(axdiff)
    > xpect echo bbcdefg
    $(sed) -n "s/.\{1,1\}/b/p"       $(axdiff)
    > xpect echo bfg
    $(sed) -n "s/.\{3,5\}/b/p"       $(axdiff)
    > xpect echo b
    $(sed) -n "s/.\{3,8\}/b/p"       $(axdiff)
    $(sed) -n "/.\{8,\}/!p"          $(aadiff)
    > xpect echo b
    $(sed) -n "s/.\{0,\}/b/p"        $(axdiff)
    > afore echo abcdefg
    > xpect echo b
    $(sed) -n "s/[a-g]\{0,\}/b/p"    $(axdiff) # CCL | MTYPE
    $(sed) -n "s/[a-g]\{1,\}/b/p"    $(axdiff)
    > xpect echo bbcdefg
    $(sed) -n "s/[a-g]\{1,1\}/b/p"   $(axdiff)
    > xpect echo bfg
    $(sed) -n "s/[a-g]\{3,5\}/b/p"   $(axdiff)
    > xpect echo b
    $(sed) -n "s/[a-g]\{3,8\}/b/p"   $(axdiff)
    $(sed) -n "/[a-g]\{8,\}/!p"      $(aadiff)
    > xpect echo b
    $(sed) -n "s/[a-g]\{0,\}/b/p"    $(axdiff)
    > afore echo aaaaaaa
    > xpect echo b
    $(sed) -n "s/\(.\)\1\{0,\}/b/p"  $(axdiff) # CBACK | MTYPE
    $(sed) -n "s/\(.\)\1\{1,\}/b/p"  $(axdiff)
    > xpect echo baaaaa
    $(sed) -n "s/\(.\)\1\{1,1\}/b/p" $(axdiff)
    > xpect echo ba
    $(sed) -n "s/\(.\)\1\{3,5\}/b/p" $(axdiff)
    > xpect echo b
    $(sed) -n "s/\(.\)\1\{3,8\}/b/p" $(axdiff)
    $(sed) -n "/\(.\)\1\{8,\}/!p"    $(aadiff)
    > xpect echo b
    $(sed) -n "s/\(.\)\1\{0,\}/b/p"  $(axdiff)
    > afore echo aaaaaa
    > xpect echo b
    $(sed) -n "s/\(.\)\{0,\}/b/p"    $(axdiff) # CKET | MTYPE
    $(sed) -n "s/\(.\)\{1,\}/b/p"    $(axdiff)
    > xpect echo baaaaa
    $(sed) -n "s/\(.\)\{1,1\}/b/p"   $(axdiff)
    > xpect echo ba
    $(sed) -n "s/\(.\)\{3,5\}/b/p"   $(axdiff)
    > xpect echo b
    $(sed) -n "s/\(.\)\{3,8\}/b/p"   $(axdiff)
    $(sed) -n "/\(.\)\{8,\}/!p"      $(aadiff)
    > xpect echo b
    $(sed) -n "s/\(.\)\{0,\}/b/p"    $(axdiff)

substitute: .symbolic dosub
    > afore echo hello
    $(sed) s/a/b/    $(aadiff)
    > xpect echo heLLo
    $(sed) -g s/l/L/ $(axdiff)

dosub: .symbolic place
    > afore echo hello
    > xpect echo hellooa
    $(sed) "s/.*\(.\)/&\1a/" $(axdiff)

place: .symbolic # already tested by dosub
    @%null

listto: .symbolic listto.exe
    # BS gets "Illegal character value 08H in file" from wmake
    # ESC gets "Illegal character value 1bH in file" from wmake
    # CR completes the command list
    > afore $(here)listto.exe $(q)hello TAB\tNL\nline end$q
    > xpect echo $(e)hello TAB\tNL$e
    >>xpect echo $(e)line end$$$e
    $(sed) -n "N;l" $(axdiff)
!ifndef __UNIX__
    > xpect cat <<
$$
This sed quietly terminates a line with a decimal 26 character$$
\01\02\03\04\05\06\a\b\t$$
\v\f\0e\0f\10\11\12\13\14\15\16\17\18\19$$
\1b\1c\1d\1e\1f !"$#$$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO\
PQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\7f\80\81\82\83\
\84\85\86\87\88\89\8a\8b\8c\8d\8e\8f\90\91\92\93\94\95\96\97\98\
\99\9a\9b\9c\9d\9e\9f\a0\a1\a2\a3\a4\a5\a6\a7\a8\a9\aa\ab\ac\ad\
\ae\af\b0\b1\b2\b3\b4\b5\b6\b7\b8\b9\ba\bb\bc\bd\be\bf\c0\c1\c2\
\c3\c4\c5\c6\c7\c8\c9\ca\cb\cc\cd\ce\cf\d0\d1\d2\d3\d4\d5\d6\d7\
\d8\d9\da\db\dc\dd\de\df\e0\e1\e2\e3\e4\e5\e6\e7\e8\e9\ea\eb\ec\
\ed\ee\ef\f0\f1\f2\f3\f4\f5\f6\f7\f8\f9\fa\fb\fc\fd\fe\ff$$
<<
!else
    > xpect cat <<
$$
This sed does not treat a decimal 26 character as special\1a\01\
\02\03\04\05\06\a\b\t$$
\v\f\r\0e\0f\10\11\12\13\14\15\16\17\18\19\1a\1b\1c\1d\1e\1f !"\
$#$$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`\
abcdefghijklmnopqrstuvwxyz{|}~\7f\80\81\82\83\84\85\86\87\88\89\
\8a\8b\8c\8d\8e\8f\90\91\92\93\94\95\96\97\98\99\9a\9b\9c\9d\9e\
\9f\a0\a1\a2\a3\a4\a5\a6\a7\a8\a9\aa\ab\ac\ad\ae\af\b0\b1\b2\b3\
\b4\b5\b6\b7\b8\b9\ba\bb\bc\bd\be\bf\c0\c1\c2\c3\c4\c5\c6\c7\c8\
\c9\ca\cb\cc\cd\ce\cf\d0\d1\d2\d3\d4\d5\d6\d7\d8\d9\da\db\dc\dd\
\de\df\e0\e1\e2\e3\e4\e5\e6\e7\e8\e9\ea\eb\ec\ed\ee\ef\f0\f1\f2\
\f3\f4\f5\f6\f7\f8\f9\fa\fb\fc\fd\fe\ff$$
<<
!endif
    $(here)listto.exe | $(sed) -n l 2>> stray | diff xpect -

listto.exe: $(__MAKEFILES__)
    > listto.c cat <<
$#include <stdio.h>
int main( int argc, char *argv[] ) {
    int i = 0;

    if( argc <= 1 ) {
        putc( i, stdout );
        fprintf( stdout, "%c%s\n", 0, "This sed silently ignores data between NUL and NL" );
        fprintf( stdout, "%s%c", "This sed quietly terminates a line with a decimal 26 character", 26 );
        while( ++i != 256 ) {
            putc( i, stdout );
        }
    } else {
        char const *cp = argv[1];

        while( ( i = *cp++ ) != 0 ) {
            if( i == '\\' ) {
                i = *cp++;
                switch( i ) {
                case 'n': i = '\n'; break;
                case 'r': i = '\r'; break;
                case 't': i = '\t'; break;
                }
            }
            fprintf( stdout, "%c", i );
        }
    }
    return( 0 );
}
<<
!ifdef __UNIX__
    cp listto.c afore
    sed "s/quietly.*character/does not treat a decimal 26 character as special/" afore > listto.c
!endif
    $(bld_cl) -zq -fe=listto.exe listto.c $(wcl_util_opts)

command: .symbolic substitute listto readout getline
    > afore echo hello
    > scrip echo $(e)a\$e
    >>scrip echo world
    > xpect echo hello
    >>xpect echo world
    $(sed) -f scrip              $(axdiff)
    > scrip echo $(e)c\$e
    >>scrip echo world
    > xpect echo world
    $(sed) -f scrip              $(axdiff)
    >   afore echo hello
    >>  afore echo world
    > xpect echo world
    $(sed) 1d                    $(axdiff)
    $(sed) "N;D"                 $(axdiff)
    > xpect echo 2
    $(sed) -n $$=                $(axdiff)
    > xpect echo hello
    $(sed) -n "1h;2{g;p;}"       $(axdiff)
    > xpect echo world
    >>xpect echo hello
    $(sed) -n "1h;2{G;p;}"       $(axdiff)
    > xpect echo\
    >>xpect echo hello
    $(sed) -n "1H;2{g;p;}"       $(axdiff)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?