sedtest.mak
来自「开放源码的编译器open watcom 1.6.0版的源代码」· MAK 代码 · 共 1,240 行 · 第 1/3 页
MAK
1,240 行
# testsed.mak
#
# Makefile to test sed. Portable among NT, OS/2 and UNIX
!include cproj.mif
!ifndef __UNIX__
blackhole=nul
q=" # quote for shell
E= # quote for echo - can not use Q as wmake macros are case insensitive
here=.\
!else
blackhole=/dev/null
q='
E='
here=./
!endif
!ifdef %TESTSED
sed = $(%TESTSED)
!else
!ifndef __UNIX__
sed = sed # $(here)sed here is .\sed but in sed itself .\sed is .sed. ;(
!else
sed = $(here)sed
!endif
!endif
# Shorthands for "standard" operations
axdiff =afore 2>> stray | diff xpect -
a2xdiff=afore 2>&1 >> stray | diff xpect -
aadiff =afore 2>> stray | diff afore -
.before
@rm -f stray
@wtouch stray
.after
# stray should be empty
@diff stray $(blackhole) > $(blackhole) || echo Some stray output was written
@diff stray $(blackhole) | $(sed) $(q)1d;s/..//$q
@diff stray $(blackhole) > $(blackhole)
@rm -f stray
all: .symbolic sedcomp sedexec susv3 bre dospencer
dospencer: .symbolic spencer.cmd
$(here)spencer.cmd 2>&1 | tee spencer.log
# spencer.log should be empty
@diff spencer.log $(blackhole) > $(blackhole)
sedcomp: .symbolic main
@%null
sedexec: .symbolic execute
@%null
clean: .symbolic
rm -f afore after xpect scrip scr0p scr1p
rm -f spencer.cmd spencer.log spen?.??? listto* a b c d e f g h i written
main: .symbolic badarg enarg fgarg noef badsquig labels resolve compile recomp
@%null
badarg: .symbolic noargs
> afore echo hello
> xpect echo sed: error processing: -e
$(sed) -e < $(a2xdiff)
> xpect echo sed: error processing: -f
$(sed) -f < $(a2xdiff)
> xpect cat <<
sed: unknown flag ?
Usage: sed [-g] [-n] script file ...
sed [-g] [-n] -e script ... -f script_file ... file ...
-g: global substitute -n: no default copy,
script: append to commands, script_file: append contents to commands
file: a text file - lines of upto 8K bytes, \n not needed on last line
default is to read from standard input
General command format:
[addr1][,addr2] [!]function [arguments]
[addr1][,addr2] [!]s/[RE]/replace/[p|P][g][w file]
Command list:
a: append, b: branch, c: change, d/D: delete,
g/G: get, h/H: hold, i: insert, l: list,
n/N: next, p/P: print, q: quit, r: read,
s: substitute, t/T: test, w/W: write, x: xchange,
y: translate, :label, =: number, {}: grouping
Regular expression elements:
\n, and \t: newline, and tab
^: line begin, $$: line end,
[a-z$$0-9]: class, [^a-z$$]: inverse-class,
.: one character, *: 0 or more repeats,
+: one or more repeats, \{n,m\} n to m repeats,
\(..\): subexpression, \1..\9: matched subexpression,
Substitution patterns:
\n,\t: newline and tab
&: match pattern, \1..\9: matched subexpression
<<
$(sed) -? < $(a2xdiff)
# Response very similar to long "unknown flag" response above.
noargs: .symbolic
-$(sed) 2> after
enarg: .symbolic
> afore echo hello
$(sed) -e p -n $(aadiff)
fgarg: .symbolic
> afore echo hello
> xpect echo heLlo
>>xpect echo heLLo
> scrip echo s/l/L/
# -g only applies to subsequent arguments
$(sed) -e "s/l/L/p;s/L/l/" -g -f scrip $(axdiff)
noef: .symbolic
> afore echo hello
$(sed) -n p $(aadiff)
$(sed) -e "" $(aadiff)
badsquig: .symbolic
> afore echo hello
%write xpect sed: too many }'s
$(sed) -e "}" $(a2xdiff)
%write xpect sed: too many {'s
$(sed) -e "{p" $(a2xdiff)
labels: .symbolic
# labels can be unused or duplicated.
# One can jump forward to a defined label, forward to the end of the script,
# forward to a missing label or backward.
# unused
> afore echo hello
$(sed) -e :label -e p -n $(aadiff)
# duplicated
> xpect echo $(e)sed: duplicate label ":label"$e
$(sed) -e :label -e :label $(a2xdiff)
# forward to a defined label
$(sed) -neblabel "-ep;:label" -ep $(aadiff)
# forward to the end of the script
$(sed) -eb -ep $(aadiff)
# forward to a missing label
> xpect echo $(e)sed: undefined label ":label"$e
$(sed) -eblabel $(a2xdiff)
# backward
$(sed) -eblabel1 -e:label "-eq;:label1" -eblabel $(aadiff)
compile: .symbolic semicolon AGMSG emptyre TRAIL cmdcomp cmdline address
@%null
semicolon: .symbolic
> afore echo hello
$(sed) -e "$# This is a comment" -e "; p" -n $(aadiff)
AGMSG: .symbolic
> afore echo hello
# "$Esed:" does not mean "$(E)sed:" in wmake. Probably means "$(ESED):".
> xpect echo $(E)sed: garbled address /\)/p$E
$(sed) -e "/\)/p" $(a2xdiff)
dummy: .symbolic
$(sed) -e //p $(a2xdiff)
emptyre: .symbolic
> afore echo hello
> xpect echo sed: first RE must be non-null
$(sed) -e //p $(a2xdiff)
$(sed) -e /hello/!d -e //p -n $(aadiff)
$(sed) -e 1!d -e //p -n $(a2xdiff)
# last regular expression is dynamic rather than analysable at compile time
$(sed) -n -e b1 -e:0 -e "//p;q;:1" -e /h/b0 $(aadiff)
$(sed) -n -e $(q)$$p$q $(aadiff)
>>afore echo world
$(sed) -n -e "1,2 p" $(aadiff)
# Curiously, this scenario should not give a diagnostic WFB 20040815
> xpect echo world
$(sed) -n -e "2,1 p" $(axdiff)
$(sed) -n -e "1;2p" $(aadiff)
> xpect echo $(E)sed: garbled address 1;p$E
$(sed) -n -e "1;p" $(a2xdiff)
> xpect echo hello
$(sed) -n -e " $$ ! p" $(axdiff)
TRAIL: .symbolic
> afore echo hello
> xpect echo $(e)sed: command "pq" has trailing garbage$e
$(sed) -e pq $(a2xdiff)
$(sed) -n -e "/foo/d;p" $(aadiff)
$(sed) -n -e "/foo/d;p$# This is a comment" $(aadiff)
cmdcomp: .symbolic brace equals q label branch airc D s l wW y
> afore echo hello # Quick test of all commands
$(sed) -e "q;{p;};=;:label" -e b -e t -e T -e "a;i;r;c;D;s/a/a/l;w;W;y/a/b/" $(aadiff)
brace: .symbolic
> afore echo hello
>>afore echo world
$(sed) -n "{p;}" $(aadiff)
$(sed) -n -e "{" -e p -e "}" $(aadiff)
> xpect echo hello
$(sed) -n "1{p;}" $(axdiff)
$(sed) -n "1,2!{p;};p" $(aadiff)
> xpect echo world
$(sed) -n "1!{p;}" $(axdiff)
> xpect echo sed: no addresses allowed for 1}
$(sed) -n "1}" $(a2xdiff)
%write xpect sed: too many }'s
$(sed) -n "}" $(a2xdiff)
equals: .symbolic
> afore echo hello
>>afore echo world
> xpect echo 1
>>xpect echo 2
$(sed) -n /h/,/l/= $(axdiff)
q: .symbolic
> afore echo hello
>>afore echo world
> xpect echo sed: only one address allowed for /h/,/l/q
$(sed) /h/,/l/q $(a2xdiff)
> xpect echo hello
$(sed) /h/q $(axdiff)
label: .symbolic gettext
> afore echo hello
> xpect echo sed: no addresses allowed for 1:label
$(sed) 1:label $(a2xdiff)
> xpect echo $(E)sed: duplicate label ":label"$E
$(sed) -e :label -e :label $(a2xdiff)
$(sed) :label $(aadiff)
branch: .symbolic
> afore echo hello
$(sed) -n -e "/d/ blabel" -e "p;:label" $(aadiff)
$(sed) -e "/d/ ! blabel" -e "p;:label" $(aadiff)
airc: .symbolic
> afore echo hello
> xpect echo sed: only one address allowed for 1,2a
# 1addr on air seems restrictive but complies with SUSV3 WFB 20040731
$(sed) 1,2a $(a2xdiff)
> xpect echo sed: only one address allowed for 1,2i
$(sed) 1,2i $(a2xdiff)
> xpect echo sed: only one address allowed for 1,2r
$(sed) 1,2r $(a2xdiff)
# Impossibly? difficult to do multi-line -e command portably WFB 20040731
> scrip echo $(e)c\$e
>>scrip echo world
> xpect echo world
$(sed) -f scrip $(axdiff)
D: .symbolic
> afore echo hello
>>afore echo world
> xpect echo world
$(sed) "N;D" $(axdiff)
s: .symbolic rhscomp badshare
> afore echo hello
> xpect echo $(E)sed: garbled command s/\)//$E
$(sed) $(q)s/\)//$q $(a2xdiff)
> xpect echo $(E)sed: garbled command s/a/\1/$E
$(sed) $(q)s/a/\1/$q $(a2xdiff)
> xpect echo heLLo
$(sed) -g s/l/L/ $(axdiff)
$(sed) s/l/L/g $(axdiff)
>>afore echo world
> xpect echo heLlo
$(sed) -n "N;s/l/L/P" $(axdiff)
>>xpect echo world
$(sed) -n "N;s/l/L/p" $(axdiff)
> xpect echo heLlo
>>xpect echo world
>>xpect echo heLlo
>>xpect echo world
$(sed) -n "N;s/l/L/pw" $(axdiff)
# Seems strange that s supports w flag but not W WFB 20040803
%write xpect sed: command "N;s/l/L/W" has trailing garbage
$(sed) -n "N;s/l/L/W" $(a2xdiff)
> xpect echo heLlo
>>xpect echo heLlo
>>xpect echo world
$(sed) -n "N;s/l/L/Pw" $(axdiff)
> xpect echo helLo
$(sed) -n s/l/L/2p $(axdiff)
> xpect echo sed: bad value for match count on s command s/l/L/0
$(sed) s/l/L/0 $(a2xdiff)
> xpect echo sed: bad value for match count on s command s/l/L/2048
$(sed) s/l/L/2047 $(aadiff)
$(sed) s/l/L/2048 $(a2xdiff)
badshare: .symbolic
!ifndef __UNIX__
# fails with share conflict between stdout redirection and file WFB 20040803
> xpect echo sed: cannot create after
-$(sed) -n "N;s/l/L/pwafter" afore 2> after
diff after xpect
!else
@%null
!endif
l: .symbolic
> afore echo hello
>>afore echo world
> xpect echo hello
>>xpect echo world$$
$(sed) -n "N;l" $(axdiff)
$(sed) -n "N;lwafter" afore
diff after xpect
wW: .symbolic
> afore echo hello
>>afore echo world
> xpect echo sed: too many w files
rm -f a b c d e f g h i
$(sed) -n -e w -e wa -e wb -e wc -e wd -e we -e wf -e wg -e wh -e wi -e Wj $(a2xdiff)
> xpect echo hello
$(sed) -n "N;Wafter" afore && diff after xpect
>>xpect echo world
$(sed) -n "N;wafter" afore && diff after xpect
y: .symbolic ycomp
> afore echo hello
> xpect echo sed: garbled command y/abcdefghijklmnopqrstuvwxyz/A-Z/
$(sed) y/abcdefghijklmnopqrstuvwxyz/A-Z/ $(a2xdiff)
> xpect echo HELLO
$(sed) y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ $(axdiff)
rhscomp: .symbolic
> afore echo hello
> xpect echo $(E)sed: garbled command s/l/\1/$E
$(sed) $(q)s/l/\1/$q after $(a2xdiff)
> xpect echo helo
$(sed) $(q)s/\(l\)\1/\1/$q $(axdiff)
> xpect echo sed: garbled command s/l/l
$(sed) s/l/l $(a2xdiff)
recomp: .symbolic starplusdol set handle_cket listto.exe
> afore echo hello
> xpect echo heLo
$(sed) /ll*/s//L/ $(axdiff)
$(sed) /l+/s//L/ $(axdiff)
> xpect echo ello
$(sed) s/^h// $(axdiff)
> xpect echo $(e)sed: garbled command s/\(h//$e
$(sed) "s/\(h//" $(a2xdiff)
> afore echo hello world
> xpect echo row ollehld
$(sed) "s/\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\9\8\7\6\5\4\3\2\1/" $(axdiff)
> xpect echo row ollehd
$(sed) "s/\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\9\8\7\6\5\4\3\2\1/" $(axdiff)
> xpect echo $(e)sed: garbled command s/\(.\)\)//$e
$(sed) "s/\(.\)\)//" $(a2xdiff)
> xpect echo $(e)sed: garbled command s/\(.\)/\2/$e
$(sed) "s/\(.\)/\2/" $(a2xdiff)
> xpect echo $(e)sed: garbled address /\{1,2\}/p$e
$(sed) "/\{1,2\}/p" $(a2xdiff)
> xpect echo $(e)sed: garbled address /.\{,2\}/p$e
$(sed) "/.\{,2\}/p" $(a2xdiff)
> xpect echo $(e)sed: garbled address /.\{256\}/p$e
$(sed) "/.\{256\}/p" $(a2xdiff)
> xpect echo $(e)sed: garbled address /.\{1,256\}/p$e
$(sed) "/.\{1,256\}/p" $(a2xdiff)
> xpect echo hello world
$(sed) "/.\{255\}!/p" $(aadiff)
$(sed) "/.\{255,\}!/p" $(aadiff)
> xpect echo $(e)sed: garbled address /.\{255,2a\}!/p$e
$(sed) "/.\{255,2a\}!/p" $(a2xdiff)
> xpect echo $(e)sed: garbled address /.\{2,1\}/p$e
$(sed) "/.\{2,1\}/p" $(a2xdiff)
> xpect echo $(e)sed: garbled address /.\{2a\}/p$e
$(sed) "/.\{2a\}/p" $(a2xdiff)
> xpect $(here)listto.exe $(q)sed: garbled command s/h\\\nello//\n$q
> scrip echo $(e)s/h\$e
>>scrip echo ello//
$(sed) -f scrip $(a2xdiff)
# Some editors turn tab into a sequence of spaces
> afore $(here)listto.exe $(q)hello\nwor\tld$q
> xpect echo hello world
$(sed) "N;s/o\nw/o w/;s/\t//" $(axdiff)
> xpect echo $(e)sed: garbled address /h$e
> scrip echo /h
$(sed) -f scrip $(a2xdiff)
> afore echo hello
>>afore echo world
> xpect echo hello world
$(sed) "N;s/o.w/o w/" $(axdiff)
> afore echo $(e)\hello$e
> xpect echo $(e)sed: garbled address /\h/p$e
$(sed) -n "/\h/p" $(aadiff) # \<non-special> is erroneous in IEEE, <non-special> here
$(sed) -n "/\\h/p" $(aadiff)
starplusdol: .symbolic
> afore echo ++aa
> xpect echo hello world
$(sed) -f << $(axdiff)
s/++a+/hello world/
<<
> xpect echo $(e)sed: garbled command s/\(+a+/hello world/$e
$(sed) $(q)s/\(+a+/hello world/$q $(a2xdiff)
> afore echo $(e)**$e
> xpect echo hello world
$(sed) "s/**a*/hello world/" $(axdiff)
> xpect echo $(e)sed: garbled command s/\(*a+/hello world/$e
$(sed) "s/\(*a+/hello world/" $(a2xdiff)
> xpect echo *hello world
$(sed) "s/*$$/hello world/" $(axdiff)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?