├── test ├── l.d ├── l.r ├── l.t ├── n.d ├── n.r ├── n.t ├── p.d ├── p.r ├── p.t ├── q.d ├── q.r ├── ascii.t ├── bang1.d ├── s3.d ├── d.err ├── e3.t ├── e4.t ├── g3.err ├── h.err ├── k2.err ├── nl.err ├── q1.err ├── r2.t ├── s6.err ├── t1.err ├── u.err ├── x.err ├── =.err ├── addr1.err ├── addr2.err ├── bang1.r ├── bang2.err ├── d.r ├── e1.r ├── e1.t ├── e3.err ├── f2.err ├── k1.err ├── k3.err ├── r3.d ├── r3.t ├── s1.err ├── s5.err ├── t2.err ├── t2.t ├── w2.err ├── w3.err ├── z.err ├── bang1.err ├── e1.d ├── e1.err ├── e2.err ├── e2.r ├── f1.err ├── g1.err ├── g2.err ├── g2.r ├── j.t ├── r1.err ├── s3.err ├── s3.r ├── addr.r ├── d.t ├── g5.t ├── r2.err ├── r3.r ├── s4.err ├── e2.d ├── e2.t ├── e3.d ├── e3.r ├── e4.d ├── e4.r ├── t.t ├── t1.t ├── w.t ├── a1.err ├── a2.err ├── c1.err ├── c2.err ├── g5.d ├── i1.err ├── i2.err ├── i3.err ├── s2.err ├── w1.err ├── g2.t ├── m.err ├── nl2.t ├── q.t ├── s8.err ├── s9.err ├── s10.err ├── g3.t ├── j.r ├── k4.err ├── s2.t ├── s7.err ├── a.d ├── c.d ├── d.d ├── g1.d ├── g2.d ├── g3.d ├── g3.r ├── g4.d ├── i.d ├── j.d ├── k.d ├── m.d ├── m.r ├── r1.d ├── r2.d ├── s1.d ├── s2.d ├── t.d ├── t1.d ├── t2.d ├── u.d ├── v.d ├── w.d ├── addr.t ├── bang1.t ├── k.r ├── nl1.d ├── nl1.t ├── nl2.d ├── r1.t ├── t2.r ├── m.t ├── s2.r ├── ascii.d ├── ascii.r ├── c.r ├── g4.r ├── nl2.r ├── s1.r ├── s3.t ├── g1.t ├── nl1.r ├── v.t ├── r1.r ├── s1.t ├── k.t ├── a.t ├── i.t ├── a.r ├── i.r ├── addr.d ├── g5.r ├── r2.r ├── u.r ├── w.r ├── g4.t ├── v.r ├── c.t ├── t.r ├── t1.r ├── g1.r ├── u.t ├── Makefile ├── TODO ├── ckscripts.sh ├── README └── mkscripts.sh ├── compat ├── pledge.c ├── compat.h └── reallocarray.c ├── USD.doc ├── 09.edtut │ ├── Makefile │ ├── e.mac │ ├── e0 │ ├── e7 │ ├── e6 │ ├── e5 │ ├── e1 │ ├── e4 │ ├── e3 │ └── e2 └── 10.edadv │ ├── Makefile │ ├── ae9 │ ├── ae.mac │ ├── ae0 │ ├── ae1 │ ├── ae4 │ ├── ae7 │ ├── ae5 │ ├── ae6 │ └── ae3 ├── Makefile ├── README ├── README.openbsd ├── POSIX ├── re.c ├── undo.c ├── ed.h ├── glbl.c ├── buf.c ├── sub.c └── io.c /test/l.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/l.r: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/l.t: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/n.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/n.r: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/n.t: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/p.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/p.r: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/p.t: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/q.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/q.r: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/ascii.t: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/bang1.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/s3.d: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/d.err: -------------------------------------------------------------------------------- 1 | dd 2 | -------------------------------------------------------------------------------- /test/e3.t: -------------------------------------------------------------------------------- 1 | E 2 | -------------------------------------------------------------------------------- /test/e4.t: -------------------------------------------------------------------------------- 1 | e 2 | -------------------------------------------------------------------------------- /test/g3.err: -------------------------------------------------------------------------------- 1 | g 2 | -------------------------------------------------------------------------------- /test/h.err: -------------------------------------------------------------------------------- 1 | .h 2 | -------------------------------------------------------------------------------- /test/k2.err: -------------------------------------------------------------------------------- 1 | kA 2 | -------------------------------------------------------------------------------- /test/nl.err: -------------------------------------------------------------------------------- 1 | ,1 2 | -------------------------------------------------------------------------------- /test/q1.err: -------------------------------------------------------------------------------- 1 | .q 2 | -------------------------------------------------------------------------------- /test/r2.t: -------------------------------------------------------------------------------- 1 | r 2 | -------------------------------------------------------------------------------- /test/s6.err: -------------------------------------------------------------------------------- 1 | s 2 | -------------------------------------------------------------------------------- /test/t1.err: -------------------------------------------------------------------------------- 1 | tt 2 | -------------------------------------------------------------------------------- /test/u.err: -------------------------------------------------------------------------------- 1 | .u 2 | -------------------------------------------------------------------------------- /test/x.err: -------------------------------------------------------------------------------- 1 | .x 2 | -------------------------------------------------------------------------------- /test/=.err: -------------------------------------------------------------------------------- 1 | 1,$= 2 | -------------------------------------------------------------------------------- /test/addr1.err: -------------------------------------------------------------------------------- 1 | 100 2 | -------------------------------------------------------------------------------- /test/addr2.err: -------------------------------------------------------------------------------- 1 | -100 2 | -------------------------------------------------------------------------------- /test/bang1.r: -------------------------------------------------------------------------------- 1 | okay 2 | -------------------------------------------------------------------------------- /test/bang2.err: -------------------------------------------------------------------------------- 1 | !! 2 | -------------------------------------------------------------------------------- /test/d.r: -------------------------------------------------------------------------------- 1 | line 2 2 | -------------------------------------------------------------------------------- /test/e1.r: -------------------------------------------------------------------------------- 1 | E e1.t 2 | -------------------------------------------------------------------------------- /test/e1.t: -------------------------------------------------------------------------------- 1 | E e1.t 2 | -------------------------------------------------------------------------------- /test/e3.err: -------------------------------------------------------------------------------- 1 | ee.err 2 | -------------------------------------------------------------------------------- /test/f2.err: -------------------------------------------------------------------------------- 1 | ff1.err 2 | -------------------------------------------------------------------------------- /test/k1.err: -------------------------------------------------------------------------------- 1 | 1,$ka 2 | -------------------------------------------------------------------------------- /test/k3.err: -------------------------------------------------------------------------------- 1 | 0ka 2 | -------------------------------------------------------------------------------- /test/r3.d: -------------------------------------------------------------------------------- 1 | r r3.t 2 | -------------------------------------------------------------------------------- /test/r3.t: -------------------------------------------------------------------------------- 1 | r r3.t 2 | -------------------------------------------------------------------------------- /test/s1.err: -------------------------------------------------------------------------------- 1 | s . x 2 | -------------------------------------------------------------------------------- /test/s5.err: -------------------------------------------------------------------------------- 1 | s//xyz/ 2 | -------------------------------------------------------------------------------- /test/t2.err: -------------------------------------------------------------------------------- 1 | t0;-1 2 | -------------------------------------------------------------------------------- /test/t2.t: -------------------------------------------------------------------------------- 1 | t0;/./ 2 | -------------------------------------------------------------------------------- /test/w2.err: -------------------------------------------------------------------------------- 1 | ww.o 2 | -------------------------------------------------------------------------------- /test/w3.err: -------------------------------------------------------------------------------- 1 | wqp w.o 2 | -------------------------------------------------------------------------------- /test/z.err: -------------------------------------------------------------------------------- 1 | z 2 | z 3 | -------------------------------------------------------------------------------- /test/bang1.err: -------------------------------------------------------------------------------- 1 | .!date 2 | -------------------------------------------------------------------------------- /test/e1.d: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /test/e1.err: -------------------------------------------------------------------------------- 1 | ee e1.err 2 | -------------------------------------------------------------------------------- /test/e2.err: -------------------------------------------------------------------------------- 1 | .e e2.err 2 | -------------------------------------------------------------------------------- /test/e2.r: -------------------------------------------------------------------------------- 1 | hello world- 2 | -------------------------------------------------------------------------------- /test/f1.err: -------------------------------------------------------------------------------- 1 | .f f1.err 2 | -------------------------------------------------------------------------------- /test/g1.err: -------------------------------------------------------------------------------- 1 | g/./s //x/ 2 | -------------------------------------------------------------------------------- /test/g2.err: -------------------------------------------------------------------------------- 1 | g//s/./x/ 2 | -------------------------------------------------------------------------------- /test/g2.r: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /test/j.t: -------------------------------------------------------------------------------- 1 | 1,1j 2 | 2,3j 3 | -------------------------------------------------------------------------------- /test/r1.err: -------------------------------------------------------------------------------- 1 | 1,$r r1.err 2 | -------------------------------------------------------------------------------- /test/s3.err: -------------------------------------------------------------------------------- 1 | s/[xyx/a/ 2 | -------------------------------------------------------------------------------- /test/s3.r: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /test/addr.r: -------------------------------------------------------------------------------- 1 | line 2 2 | line9 3 | -------------------------------------------------------------------------------- /test/d.t: -------------------------------------------------------------------------------- 1 | 1d 2 | 2;+1d 3 | $d 4 | -------------------------------------------------------------------------------- /test/g5.t: -------------------------------------------------------------------------------- 1 | g/./1,3t$\ 2 | 1d 3 | -------------------------------------------------------------------------------- /test/r2.err: -------------------------------------------------------------------------------- 1 | r a-good-book 2 | -------------------------------------------------------------------------------- /test/r3.r: -------------------------------------------------------------------------------- 1 | r r3.t 2 | r r3.t 3 | -------------------------------------------------------------------------------- /test/s4.err: -------------------------------------------------------------------------------- 1 | s/\a\b\c/xyz/ 2 | -------------------------------------------------------------------------------- /test/e2.d: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/e2.t: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/e3.d: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/e3.r: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/e4.d: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/e4.r: -------------------------------------------------------------------------------- 1 | E !echo hello world- 2 | -------------------------------------------------------------------------------- /test/t.t: -------------------------------------------------------------------------------- 1 | 1t1 2 | 2,3t2 3 | ,t$ 4 | -------------------------------------------------------------------------------- /test/t1.t: -------------------------------------------------------------------------------- 1 | 1t0 2 | 2,3t2 3 | ,t$ 4 | -------------------------------------------------------------------------------- /test/w.t: -------------------------------------------------------------------------------- 1 | w !cat >\!.z 2 | r \!.z 3 | -------------------------------------------------------------------------------- /test/a1.err: -------------------------------------------------------------------------------- 1 | 1,$a 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/a2.err: -------------------------------------------------------------------------------- 1 | aa 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/c1.err: -------------------------------------------------------------------------------- 1 | cc 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/c2.err: -------------------------------------------------------------------------------- 1 | 0c 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/g5.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | -------------------------------------------------------------------------------- /test/i1.err: -------------------------------------------------------------------------------- 1 | 1,$i 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/i2.err: -------------------------------------------------------------------------------- 1 | ii 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/i3.err: -------------------------------------------------------------------------------- 1 | 0i 2 | hello world 3 | . 4 | -------------------------------------------------------------------------------- /test/s2.err: -------------------------------------------------------------------------------- 1 | a 2 | a 3 | . 4 | s/x*/a/g 5 | -------------------------------------------------------------------------------- /test/w1.err: -------------------------------------------------------------------------------- 1 | w /to/some/far-away/place 2 | -------------------------------------------------------------------------------- /test/g2.t: -------------------------------------------------------------------------------- 1 | g/[2-4]/-1,+1c\ 2 | hello world 3 | -------------------------------------------------------------------------------- /test/m.err: -------------------------------------------------------------------------------- 1 | a 2 | hello world 3 | . 4 | 1,$m1 5 | -------------------------------------------------------------------------------- /test/nl2.t: -------------------------------------------------------------------------------- 1 | a 2 | hello world 3 | . 4 | 0;/./ 5 | -------------------------------------------------------------------------------- /test/q.t: -------------------------------------------------------------------------------- 1 | w q.o 2 | a 3 | hello 4 | . 5 | q 6 | -------------------------------------------------------------------------------- /test/s8.err: -------------------------------------------------------------------------------- 1 | a 2 | hello 3 | . 4 | s/[h[=]/x/ 5 | -------------------------------------------------------------------------------- /test/s9.err: -------------------------------------------------------------------------------- 1 | a 2 | hello 3 | . 4 | s/[h[:]/x/ 5 | -------------------------------------------------------------------------------- /test/s10.err: -------------------------------------------------------------------------------- 1 | a 2 | hello 3 | . 4 | s/[h[.]/x/ 5 | -------------------------------------------------------------------------------- /test/g3.t: -------------------------------------------------------------------------------- 1 | g/./s//x/\ 2 | 3m0 3 | g/./s/e/c/\ 4 | 2,3m1 5 | -------------------------------------------------------------------------------- /test/j.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2line 3 3 | line 4 4 | line5 5 | -------------------------------------------------------------------------------- /test/k4.err: -------------------------------------------------------------------------------- 1 | a 2 | hello 3 | . 4 | .ka 5 | 'ad 6 | 'ap 7 | -------------------------------------------------------------------------------- /test/s2.t: -------------------------------------------------------------------------------- 1 | ,s/./(&)/3 2 | s/$/00 3 | 2s//%/g 4 | s/^l 5 | -------------------------------------------------------------------------------- /test/s7.err: -------------------------------------------------------------------------------- 1 | a 2 | hello world 3 | . 4 | /./ 5 | sr 6 | -------------------------------------------------------------------------------- /test/a.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/c.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/d.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/g1.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/g2.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/g3.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/g3.r: -------------------------------------------------------------------------------- 1 | linc 3 2 | xine 1 3 | xine 2 4 | xinc 4 5 | xinc5 6 | -------------------------------------------------------------------------------- /test/g4.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/i.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/j.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/k.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/m.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/m.r: -------------------------------------------------------------------------------- 1 | line5 2 | line 1 3 | line 2 4 | line 3 5 | line 4 6 | -------------------------------------------------------------------------------- /test/r1.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/r2.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/s1.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/s2.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/t.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/t1.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/t2.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/u.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/v.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/w.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/addr.t: -------------------------------------------------------------------------------- 1 | 1 d 2 | 1 1 d 3 | 1,2,d 4 | 1;+ + ,d 5 | 1,2;., + 2d 6 | -------------------------------------------------------------------------------- /test/bang1.t: -------------------------------------------------------------------------------- 1 | !read one 2 | hello, world 3 | a 4 | okay 5 | . 6 | -------------------------------------------------------------------------------- /test/k.r: -------------------------------------------------------------------------------- 1 | line 3 2 | hello world 3 | line 4 4 | line5 5 | line 2 6 | -------------------------------------------------------------------------------- /test/nl1.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/nl1.t: -------------------------------------------------------------------------------- 1 | 1 2 | 3 | 4 | 0a 5 | 6 | 7 | hello world 8 | . 9 | -------------------------------------------------------------------------------- /test/nl2.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | -------------------------------------------------------------------------------- /test/r1.t: -------------------------------------------------------------------------------- 1 | 1;r !echo hello world 2 | 1 3 | r !echo hello world 4 | -------------------------------------------------------------------------------- /test/t2.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line5 3 | line 2 4 | line 3 5 | line 4 6 | line5 7 | -------------------------------------------------------------------------------- /test/m.t: -------------------------------------------------------------------------------- 1 | 1,2m$ 2 | 1,2m$ 3 | 1,2m$ 4 | $m0 5 | $m0 6 | 2,3m1 7 | 2,3m3 8 | -------------------------------------------------------------------------------- /test/s2.r: -------------------------------------------------------------------------------- 1 | li(n)e 1 2 | i(n)e 200 3 | li(n)e 3 4 | li(n)e 4 5 | li(n)e500 6 | -------------------------------------------------------------------------------- /test/ascii.d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ypnose/openbsd-ed/master/test/ascii.d -------------------------------------------------------------------------------- /test/ascii.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ypnose/openbsd-ed/master/test/ascii.r -------------------------------------------------------------------------------- /test/c.r: -------------------------------------------------------------------------------- 1 | at the top 2 | between top/middle 3 | in the middle 4 | at the bottom 5 | -------------------------------------------------------------------------------- /test/g4.r: -------------------------------------------------------------------------------- 1 | hello 2 | zine 1 3 | line 2 4 | line 3 5 | line 4 6 | line5 7 | world 8 | -------------------------------------------------------------------------------- /test/nl2.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | hello world 7 | -------------------------------------------------------------------------------- /test/s1.r: -------------------------------------------------------------------------------- 1 | liene 1 2 | (liene) (2) 3 | (liene) (3) 4 | liene (4) 5 | (()liene5) 6 | -------------------------------------------------------------------------------- /test/s3.t: -------------------------------------------------------------------------------- 1 | a 2 | hello/[]world 3 | . 4 | s/[/]/ / 5 | s/[[:digit:][]/ / 6 | s/[]]/ / 7 | -------------------------------------------------------------------------------- /test/g1.t: -------------------------------------------------------------------------------- 1 | g/./m0 2 | g/./s/$/\ 3 | hello world 4 | g/hello /s/lo/p!/\ 5 | a\ 6 | order 7 | -------------------------------------------------------------------------------- /test/nl1.r: -------------------------------------------------------------------------------- 1 | 2 | 3 | hello world 4 | line 1 5 | line 2 6 | line 3 7 | line 4 8 | line5 9 | -------------------------------------------------------------------------------- /test/v.t: -------------------------------------------------------------------------------- 1 | v/[ ]/m0 2 | v/[ ]/s/$/\ 3 | hello world 4 | v/hello /s/lo/p!/\ 5 | a\ 6 | order 7 | -------------------------------------------------------------------------------- /test/r1.r: -------------------------------------------------------------------------------- 1 | line 1 2 | hello world 3 | line 2 4 | line 3 5 | line 4 6 | line5 7 | hello world 8 | -------------------------------------------------------------------------------- /test/s1.t: -------------------------------------------------------------------------------- 1 | s/\([^ ][^ ]*\)/(\1)/g 2 | 2s 3 | /3/s 4 | /\(4\)/sr 5 | /\(.\)/srg 6 | %s/i/&e/ 7 | -------------------------------------------------------------------------------- /test/k.t: -------------------------------------------------------------------------------- 1 | 2ka 2 | 1d 3 | 'am$ 4 | 1ka 5 | 0a 6 | hello world 7 | . 8 | 'ad 9 | u 10 | 'am0 11 | -------------------------------------------------------------------------------- /test/a.t: -------------------------------------------------------------------------------- 1 | 0a 2 | hello world 3 | . 4 | 2a 5 | hello world! 6 | . 7 | $a 8 | hello world!! 9 | . 10 | -------------------------------------------------------------------------------- /test/i.t: -------------------------------------------------------------------------------- 1 | 1i 2 | hello world 3 | . 4 | 2i 5 | hello world! 6 | . 7 | $i 8 | hello world!! 9 | . 10 | -------------------------------------------------------------------------------- /test/a.r: -------------------------------------------------------------------------------- 1 | hello world 2 | line 1 3 | hello world! 4 | line 2 5 | line 3 6 | line 4 7 | line5 8 | hello world!! 9 | -------------------------------------------------------------------------------- /test/i.r: -------------------------------------------------------------------------------- 1 | hello world 2 | hello world! 3 | line 1 4 | line 2 5 | line 3 6 | line 4 7 | hello world!! 8 | line5 9 | -------------------------------------------------------------------------------- /test/addr.d: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | 1ine6 7 | line7 8 | line8 9 | line9 10 | -------------------------------------------------------------------------------- /test/g5.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 2 5 | line 3 6 | line 1 7 | line 3 8 | line 1 9 | line 2 10 | -------------------------------------------------------------------------------- /test/r2.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | line 1 7 | line 2 8 | line 3 9 | line 4 10 | line5 11 | -------------------------------------------------------------------------------- /test/u.r: -------------------------------------------------------------------------------- 1 | line 1 2 | hello 3 | hello world!! 4 | line 2 5 | line 3 6 | line 4 7 | line5 8 | hello 9 | hello world!! 10 | -------------------------------------------------------------------------------- /test/w.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 4 | line 4 5 | line5 6 | line 1 7 | line 2 8 | line 3 9 | line 4 10 | line5 11 | -------------------------------------------------------------------------------- /test/g4.t: -------------------------------------------------------------------------------- 1 | g/./s/./x/\ 2 | u\ 3 | s/./y/\ 4 | u\ 5 | s/./z/\ 6 | u 7 | u 8 | 0a 9 | hello 10 | . 11 | $a 12 | world 13 | . 14 | -------------------------------------------------------------------------------- /test/v.r: -------------------------------------------------------------------------------- 1 | line5 2 | order 3 | hello world 4 | line 1 5 | order 6 | line 2 7 | order 8 | line 3 9 | order 10 | line 4 11 | order 12 | -------------------------------------------------------------------------------- /test/c.t: -------------------------------------------------------------------------------- 1 | 1c 2 | at the top 3 | . 4 | 4c 5 | in the middle 6 | . 7 | $c 8 | at the bottom 9 | . 10 | 2,3c 11 | between top/middle 12 | . 13 | -------------------------------------------------------------------------------- /compat/pledge.c: -------------------------------------------------------------------------------- 1 | /* Placed in the public domain. */ 2 | /* Written by Damien Miller */ 3 | 4 | int 5 | pledge(const char *promises, const char *paths[]) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/t.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 1 3 | line 1 4 | line 2 5 | line 2 6 | line 3 7 | line 4 8 | line5 9 | line 1 10 | line 1 11 | line 1 12 | line 2 13 | line 2 14 | line 3 15 | line 4 16 | line5 17 | -------------------------------------------------------------------------------- /test/t1.r: -------------------------------------------------------------------------------- 1 | line 1 2 | line 1 3 | line 1 4 | line 2 5 | line 2 6 | line 3 7 | line 4 8 | line5 9 | line 1 10 | line 1 11 | line 1 12 | line 2 13 | line 2 14 | line 3 15 | line 4 16 | line5 17 | -------------------------------------------------------------------------------- /test/g1.r: -------------------------------------------------------------------------------- 1 | line5 2 | help! world 3 | order 4 | line 4 5 | help! world 6 | order 7 | line 3 8 | help! world 9 | order 10 | line 2 11 | help! world 12 | order 13 | line 1 14 | help! world 15 | order 16 | -------------------------------------------------------------------------------- /compat/compat.h: -------------------------------------------------------------------------------- 1 | /* compat.h for Linux and musl */ 2 | 3 | #include 4 | 5 | #define DEF_WEAK(x) 6 | #define REG_STARTEND 00004 7 | 8 | void *reallocarray(void *, size_t, size_t); 9 | int pledge(const char *promises, const char *paths[]); 10 | -------------------------------------------------------------------------------- /USD.doc/09.edtut/Makefile: -------------------------------------------------------------------------------- 1 | # $OpenBSD: Makefile,v 1.2 2004/02/01 15:21:55 jmc Exp $ 2 | 3 | DIR= usd/09.edtut 4 | SRCS= e.mac e0 e1 e2 e3 e4 e5 e6 e7 5 | MACROS= -ms 6 | 7 | paper.txt: ${SRCS} 8 | ${ROFF} -Tascii ${SRCS} > ${.TARGET} 9 | 10 | .include 11 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/Makefile: -------------------------------------------------------------------------------- 1 | # $OpenBSD: Makefile,v 1.2 2004/02/01 15:21:55 jmc Exp $ 2 | 3 | DIR= usd/10.edadv 4 | SRCS= ae.mac ae0 ae1 ae2 ae3 ae4 ae5 ae6 ae7 ae9 5 | MACROS= -ms 6 | 7 | paper.txt: ${SRCS} 8 | ${ROFF} -Tascii ${SRCS} > ${.TARGET} 9 | 10 | .include 11 | -------------------------------------------------------------------------------- /test/u.t: -------------------------------------------------------------------------------- 1 | 1;r u.t 2 | u 3 | a 4 | hello 5 | world 6 | . 7 | g/./s//x/\ 8 | a\ 9 | hello\ 10 | world 11 | u 12 | u 13 | u 14 | a 15 | hello world! 16 | . 17 | u 18 | 1,$d 19 | u 20 | 2,3d 21 | u 22 | c 23 | hello world!! 24 | . 25 | u 26 | u 27 | -1;.,+1j 28 | u 29 | u 30 | u 31 | .,+1t$ 32 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ED_BIN = ed 2 | ED_SRCS = buf.c glbl.c io.c main.c re.c sub.c undo.c 3 | ED_OBJS = $(ED_SRCS:.c=.o) 4 | ED_COMP = compat/reallocarray.o compat/pledge.o 5 | 6 | CPPFLAGS += -include compat/compat.h 7 | 8 | all: $(ED_BIN) 9 | 10 | $(ED_BIN): $(ED_COMP) $(ED_OBJS) 11 | $(CC) $(CFLAGS) -o $(ED_BIN) $(ED_COMP) $(ED_OBJS) $(LDFLAGS) 12 | 13 | clean: 14 | rm -f *.o compat/*.o $(ED_BIN) 15 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | openbsd-ed 2 | ========== 3 | 4 | openbsd-ed is a simple way to compile ed(1) from OpenBSD[1] project on 5 | Linux. It was only tested with musl libc[2]. 6 | 7 | Built with: 8 | 9 | * gcc 6.3.0 + musl 1.1.15 10 | * gcc 6.2.1 + musl 1.1.15 11 | * gcc 5.4.0 + musl 1.1.15 12 | * gcc 4.9.2 + musl 1.1.15 13 | * gcc 4.8.4 + musl 1.1.15 14 | * gcc 4.7.2 + musl 1.1.15 15 | 16 | For the copyright policy, you must visit the official page from the 17 | upstream project[3]. 18 | 19 | [1] https://www.openbsd.org/ 20 | [2] https://www.musl-libc.org/ 21 | [3] https://www.openbsd.org/policy.html 22 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # $OpenBSD: Makefile,v 1.2 1996/06/23 14:20:05 deraadt Exp $ 2 | # $NetBSD: Makefile,v 1.11 1995/03/21 09:05:14 cgd Exp $ 3 | 4 | SHELL= /bin/sh 5 | ED= ../obj/ed 6 | 7 | all: check 8 | @: 9 | 10 | check: build test 11 | @if grep -h '\*\*\*' errs.o scripts.o; then :; else \ 12 | echo "tests completed successfully."; \ 13 | fi 14 | 15 | build: mkscripts.sh 16 | @if [ -f errs.o ]; then :; else \ 17 | echo "building test scripts for $(ED) ..."; \ 18 | $(SHELL) mkscripts.sh $(ED); \ 19 | fi 20 | 21 | test: build ckscripts.sh 22 | @echo testing $(ED) ... 23 | @$(SHELL) ckscripts.sh $(ED) 24 | 25 | clean: 26 | rm -f *.ed *.red *.[oz] *~ 27 | -------------------------------------------------------------------------------- /test/TODO: -------------------------------------------------------------------------------- 1 | $OpenBSD: TODO,v 1.2 1996/06/23 14:20:06 deraadt Exp $ 2 | $NetBSD: TODO,v 1.3 1995/03/21 09:05:20 cgd Exp $ 3 | 4 | Some missing tests: 5 | 0) g/./s^@^@ - okay: NULs in commands 6 | 1) g/./s/^@/ - okay: NULs in patterns 7 | 2) a 8 | hello^V^Jworld 9 | . - okay: embedded newlines in insert mode 10 | 3) ed "" - error: invalid filename 11 | 4) red .. - error: restricted 12 | 5) red / - error: restricted 13 | 5) red !xx - error: restricted 14 | 6) ed -x - verify: 8-bit clean 15 | 7) ed - verify: long-line support 16 | 8) ed - verify: interactive/help mode 17 | 9) G/pat/ - verify: global interactive command 18 | 10) V/pat/ - verify: global interactive command 19 | -------------------------------------------------------------------------------- /README.openbsd: -------------------------------------------------------------------------------- 1 | $OpenBSD: README,v 1.5 2018/06/15 08:46:24 martijn Exp $ 2 | $NetBSD: README,v 1.9 1995/03/21 09:04:33 cgd Exp $ 3 | 4 | ed is an 8-bit-clean, POSIX-compliant line editor. It should work with 5 | any regular expression package that conforms to the POSIX interface 6 | standard, such as GNU regex(3). 7 | 8 | If reliable signals are supported (e.g., POSIX sigaction(2)), it should 9 | compile with little trouble. Otherwise, the macros SPL1() and SPL0() 10 | should be redefined to disable interrupts. 11 | 12 | The file `POSIX' describes extensions to and deviations from the POSIX 13 | standard. 14 | 15 | The ./test directory contains regression tests for ed. The README 16 | file in that directory explains how to run these. 17 | 18 | For a description of the ed algorithm, see Kernighan and Plauger's book 19 | "Software Tools in Pascal," Addison-Wesley, 1981. 20 | -------------------------------------------------------------------------------- /test/ckscripts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | # $OpenBSD: ckscripts.sh,v 1.3 1998/07/12 03:49:08 todd Exp $ 3 | # $NetBSD: ckscripts.sh,v 1.9 1995/04/23 10:07:34 cgd Exp $ 4 | # 5 | # This script runs the .ed scripts generated by mkscripts.sh 6 | # and compares their output against the .r files, which contain 7 | # the correct output 8 | 9 | PATH="/bin:/usr/bin:/usr/local/bin/:." 10 | ED=$1 11 | [ ! -x $ED ] && { echo "$ED: cannot execute"; exit 1; } 12 | 13 | # Run the *.red scripts first, since these don't generate output; 14 | # they exit with non-zero status 15 | for i in *.red; do 16 | echo $i 17 | if $i; then 18 | echo "*** The script $i exited abnormally ***" 19 | fi 20 | done >errs.o 2>&1 21 | 22 | # Run the remaining scripts; they exit with zero status 23 | for i in *.ed; do 24 | # base=`expr $i : '\([^.]*\)'` 25 | # base=`echo $i | sed 's/\..*//'` 26 | base=`$ED - \!"echo $i" <<-EOF 27 | s/\..* 28 | EOF` 29 | if $base.ed; then 30 | if cmp -s $base.o $base.r; then :; else 31 | echo "*** Output $base.o of script $i is incorrect ***" 32 | fi 33 | else 34 | echo "*** The script $i exited abnormally ***" 35 | fi 36 | done >scripts.o 2>&1 37 | 38 | grep -h '\*\*\*' errs.o scripts.o 39 | -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | $OpenBSD: README,v 1.2 1996/06/23 14:20:06 deraadt Exp $ 2 | $NetBSD: README,v 1.8 1995/03/21 09:05:18 cgd Exp $ 3 | 4 | The files in this directory with suffixes `.t', `.d', `.r' and `.err' are 5 | used for testing ed. To run the tests, set the ED variable in the Makefile 6 | for the path name of the program to be tested (e.g., /bin/ed), and type 7 | `make'. The tests do not exhaustively verify POSIX compliance nor do 8 | they verify correct 8-bit or long line support. 9 | 10 | The test file suffixes have the following meanings: 11 | .t Template - a list of ed commands from which an ed script is 12 | constructed 13 | .d Data - read by an ed script 14 | .r Result - the expected output after processing data via an ed 15 | script. 16 | .err Error - invalid ed commands that should generate an error 17 | 18 | The output of the tests is written to the two files err.o and scripts.o. 19 | At the end of the tests, these files are grep'ed for error messages, 20 | which look like: 21 | *** The script u.ed exited abnormally *** 22 | or: 23 | *** Output u.o of script u.ed is incorrect *** 24 | 25 | The POSIX requirement that an address range not be used where at most 26 | a single address is expected has been relaxed in this version of ed. 27 | Therefore, the following scripts which test for compliance with this 28 | POSIX rule exit abnormally: 29 | =-err.ed 30 | a1-err.ed 31 | i1-err.ed 32 | k1-err.ed 33 | r1-err.ed 34 | -------------------------------------------------------------------------------- /compat/reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | /* 24 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 25 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 26 | */ 27 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 28 | 29 | void * 30 | reallocarray(void *optr, size_t nmemb, size_t size) 31 | { 32 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 33 | nmemb > 0 && SIZE_MAX / nmemb < size) { 34 | errno = ENOMEM; 35 | return NULL; 36 | } 37 | return realloc(optr, size * nmemb); 38 | } 39 | DEF_WEAK(reallocarray); 40 | -------------------------------------------------------------------------------- /test/mkscripts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | # $OpenBSD: mkscripts.sh,v 1.2 1996/06/23 14:20:08 deraadt Exp $ 3 | # $NetBSD: mkscripts.sh,v 1.10 1995/04/23 10:07:36 cgd Exp $ 4 | # 5 | # This script generates ed test scripts (.ed) from .t files 6 | 7 | PATH="/bin:/usr/bin:/usr/local/bin/:." 8 | ED=$1 9 | [ ! -x $ED ] && { echo "$ED: cannot execute"; exit 1; } 10 | 11 | for i in *.t; do 12 | # base=${i%.*} 13 | # base=`echo $i | sed 's/\..*//'` 14 | # base=`expr $i : '\([^.]*\)'` 15 | # ( 16 | # echo "#!/bin/sh -" 17 | # echo "$ED - <<\EOT" 18 | # echo "r $base.d" 19 | # cat $i 20 | # echo "w $base.o" 21 | # echo EOT 22 | # ) >$base.ed 23 | # chmod +x $base.ed 24 | # The following is pretty ugly way of doing the above, and not appropriate 25 | # use of ed but the point is that it can be done... 26 | base=`$ED - \!"echo $i" <<-EOF 27 | s/\..* 28 | EOF` 29 | $ED - <<-EOF 30 | a 31 | #!/bin/sh - 32 | $ED - <<\EOT 33 | H 34 | r $base.d 35 | w $base.o 36 | EOT 37 | . 38 | -2r $i 39 | w $base.ed 40 | !chmod +x $base.ed 41 | EOF 42 | done 43 | 44 | for i in *.err; do 45 | # base=${i%.*} 46 | # base=`echo $i | sed 's/\..*//'` 47 | # base=`expr $i : '\([^.]*\)'` 48 | # ( 49 | # echo "#!/bin/sh -" 50 | # echo "$ED - <<\EOT" 51 | # echo H 52 | # echo "r $base.err" 53 | # cat $i 54 | # echo "w $base.o" 55 | # echo EOT 56 | # ) >$base-err.ed 57 | # chmod +x $base-err.ed 58 | # The following is pretty ugly way of doing the above, and not appropriate 59 | # use of ed but the point is that it can be done... 60 | base=`$ED - \!"echo $i" <<-EOF 61 | s/\..* 62 | EOF` 63 | $ED - <<-EOF 64 | a 65 | #!/bin/sh - 66 | $ED - <<\EOT 67 | H 68 | r $base.err 69 | w $base.o 70 | EOT 71 | . 72 | -2r $i 73 | w ${base}.red 74 | !chmod +x ${base}.red 75 | EOF 76 | done 77 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/ae9: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: ae9,v 1.3 2004/04/06 08:19:20 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)ae9 8.1 (Berkeley) 6/8/93 36 | .\" 37 | .SH 38 | Acknowledgement 39 | .PP 40 | I am grateful to Ted Dolotta 41 | for his careful reading and valuable suggestions. 42 | .SH 43 | References 44 | .IP [1] 45 | Brian W. Kernighan, 46 | .UL "A Tutorial Introduction to the UNIX Text Editor" , 47 | Bell Laboratories internal memorandum. 48 | .IP [2] 49 | Brian W. Kernighan, 50 | .UL "UNIX For Beginners" , 51 | Bell Laboratories internal memorandum. 52 | .IP [3] 53 | Ken L. Thompson and Dennis M. Ritchie, 54 | .UL "The UNIX Programmer's Manual" . 55 | Bell Laboratories. 56 | -------------------------------------------------------------------------------- /USD.doc/09.edtut/e.mac: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: e.mac,v 1.3 2004/04/05 16:06:01 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)e.mac 8.1 (Berkeley) 8/14/93 36 | .\" 37 | .ds . \&\s+2.\s0\& 38 | .de UC 39 | \&\\$3\s-1\\$1\s0\\$2 40 | .. 41 | .de UL 42 | \&\\$3\f2\\$1\f1\\$2 43 | .. 44 | .de IT 45 | \&\\$3\f2\\$1\fP\\$2 46 | .. 47 | .de UI 48 | \f3\\$1\fI\\$2\fR\\$3 49 | .. 50 | .de P1 51 | .if n .ls 1 52 | .nf 53 | .if n .ta 5 10 15 20 25 30 35 40 45 50 55 60 54 | .if t .ta .3i .6i .9i 1.2i 1.5i 1.8i 55 | .tr -\- 56 | .\" use first argument as indent if present 57 | .if \\n(.$ .DS I \\$1 58 | .if !\\n(.$ .DS I 5 59 | .bd 1 2 60 | .. 61 | .de P2 62 | .br 63 | .bd 1 2 64 | .DE 65 | .bd 1 66 | .tr -- 67 | .if n .ls 1 68 | .. 69 | .hy 14 70 | .\" 2=not last lines; 4= no -xx; 8=no xx- 71 | .tr *\(** 72 | .nr PI .2i 73 | -------------------------------------------------------------------------------- /USD.doc/09.edtut/e0: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: e0,v 1.3 2004/04/05 10:58:08 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)e0 8.1 (Berkeley) 8/14/93 36 | .\" 37 | .if n \{\ 38 | .po 5n 39 | .ll 70n 40 | .\} 41 | .EH 'USD:9-%''A Tutorial Introduction to the \s-2UNIX\s+2 Text Editor' 42 | .OH 'A Tutorial Introduction to the \s-2UNIX\s+2 Text Editor''USD:9-%' 43 | .\".RP 44 | .TL 45 | A Tutorial Introduction to the \s-2UNIX\s+2 Text Editor 46 | .AU 47 | Brian W. Kernighan 48 | .AI 49 | Murray Hill, NJ 50 | .AB 51 | .PP 52 | Almost all text input on 53 | the 54 | .UX 55 | operating system 56 | is done with 57 | the text-editor 58 | .IT ed . 59 | This memorandum is a tutorial guide 60 | to help beginners get started 61 | with text editing. 62 | .PP 63 | Although it does not cover everything, 64 | it does discuss enough for most users' 65 | day-to-day needs. 66 | This includes 67 | printing, appending, changing, deleting, moving, 68 | and inserting entire lines of text; 69 | reading and writing files; 70 | context searching and line addressing; 71 | the substitute command; 72 | the global commands; 73 | and the use of special characters for advanced editing. 74 | .AE 75 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/ae.mac: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: ae.mac,v 1.3 2004/04/05 16:27:21 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)ae.mac 8.1 (Berkeley) 8/14/93 36 | .\" 37 | .tr _\(em 38 | .de UL 39 | \&\\$3\f2\\$1\f1\\$2 40 | .. 41 | .de IT 42 | \&\\$3\f2\\$1\fP\\$2 43 | .. 44 | .de UI 45 | \f3\\$1\fI\\$2\fR\\$3 46 | .. 47 | .de P1 48 | .if n .ls 1 49 | .nf 50 | .if n .ta 5 10 15 20 25 30 35 40 45 50 55 60 51 | .if t .ta .3i .6i .9i 1.2i 1.5i 1.8i 52 | .tr -\- 53 | .\" use first argument as indent if present 54 | .if \\n(.$ .DS I \\$1 55 | .if !\\n(.$ .DS I 5 56 | .bd 1 2 57 | .. 58 | .de P2 59 | .br 60 | .bd 1 2 61 | .DE 62 | .bd 1 63 | .tr -- 64 | .if n .ls 1 65 | .. 66 | .if t .ds BL \s6\|\v'.1m'\(sq\v'-.1m'\|\s0 67 | .if n .ds BL [] 68 | .if t .ds m \(mi 69 | .if n .ds m - 70 | .if t .ds n \(no 71 | .if n .ds n - 72 | .if t .ds s \v'.41m'\s+4*\s-4\v'-.41m' 73 | .if n .ds s * 74 | .if t .ds S \(sl 75 | .if n .ds S / 76 | .if t .ds d \s+4\&.\&\s-4 77 | .if n .ds d \&.\& 78 | .if t .ds a \z@@ 79 | .if n .ds a @ 80 | .if t .ds . \s+2\fB.\fP\s-2 81 | .if n .ds . . 82 | .if t .ds e \z\e\h'1u'\e 83 | .if n .ds e \e 84 | .hy 14 85 | .\" 2=not last lines; 4= no -xx; 8=no xx- 86 | .tr *\(** 87 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/ae0: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: ae0,v 1.4 2004/04/06 08:19:20 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)ae0 8.1 (Berkeley) 8/14/93 36 | .\" 37 | .if n \{\ 38 | .po 5n 39 | .ll 70n 40 | .\} 41 | .nr P1 1 42 | .EH 'USD:10-%''Advanced Editing on \s-2UNIX\s+2' 43 | .OH 'Advanced Editing on \s-2UNIX\s+2''USD:10-%' 44 | .\" .....TM 76-1273-8 39199 39199-11 45 | .\".RP 46 | .TL 47 | Advanced Editing on \s-2UNIX\s+2 48 | .AU "MH 2C518" 6021 49 | Brian W. Kernighan 50 | .AI 51 | Murray Hill, NJ 52 | .AU 53 | (Updated for 4.3BSD by Mark Seiden) 54 | .AB 55 | This paper is meant to help 56 | secretaries, typists and programmers 57 | to make effective use of the 58 | .UX 59 | facilities 60 | for preparing and editing text. 61 | It provides explanations and examples of 62 | .IP \(bu 63 | special characters, line addressing, and global commands in the editor 64 | .UL ed ; 65 | .IP \(bu 66 | commands for ``cut and paste'' operations on files 67 | and parts of files, 68 | including the 69 | .UL mv , 70 | .UL cp , 71 | .UL cat , 72 | and 73 | .UL rm 74 | commands, 75 | and the 76 | .UL r , 77 | .UL w , 78 | .UL m , 79 | and 80 | .UL t 81 | commands of the editor; 82 | .IP \(bu 83 | editing scripts and 84 | editor-based programs like 85 | .UL grep 86 | and 87 | .UL sed . 88 | .PP 89 | Although the treatment is aimed 90 | at non-programmers, 91 | new 92 | UNIX 93 | users 94 | with any background 95 | should find helpful hints 96 | on how to get their jobs done 97 | more easily. 98 | .AE 99 | .\" .CS 16 0 16 0 0 3 100 | .\" .if n .ls 2 101 | .nr PS 9 102 | .nr VS 11 103 | -------------------------------------------------------------------------------- /POSIX: -------------------------------------------------------------------------------- 1 | $OpenBSD: POSIX,v 1.8 2014/05/24 01:35:55 daniel Exp $ 2 | $NetBSD: POSIX,v 1.9 1995/03/21 09:04:32 cgd Exp $ 3 | 4 | This version of ed(1) is not strictly POSIX compliant, as described in 5 | the POSIX 1003.2 document. The following is a summary of the omissions, 6 | extensions and possible deviations from POSIX 1003.2. 7 | 8 | OMISSIONS 9 | --------- 10 | 1) Locale(3) is not supported yet. 11 | 12 | 2) For backwards compatibility, the POSIX rule that says a range of 13 | addresses cannot be used where only a single address is expected has 14 | been relaxed. 15 | 16 | 3) To support the BSD `s' command (see extension [1] below), 17 | substitution patterns cannot be delimited by numbers or the characters 18 | `r', `g' and `p'. In contrast, POSIX specifies any character except 19 | space or newline can be used as a delimiter. 20 | 21 | EXTENSIONS 22 | ---------- 23 | 1) BSD commands have been implemented wherever they do not conflict with 24 | the POSIX standard. The BSD-ism's included are: 25 | i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution, 26 | ii) `W' for appending text to an existing file, 27 | iii) `wq' for exiting after a write, 28 | iv) `z' for scrolling through the buffer, and 29 | v) BSD line addressing syntax (i.e., `^' and `%') is recognized. 30 | 31 | 2) The POSIX interactive global commands `G' and `V' are extended to 32 | support multiple commands, including `a', `i' and `c'. The command 33 | format is the same as for the global commands `g' and `v', i.e., one 34 | command per line with each line, except for the last, ending in a 35 | backslash (\). 36 | 37 | 3) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is 38 | that arguments are processed for backslash escapes, i.e., any 39 | character preceded by a backslash is interpreted literally. If the 40 | first unescaped character of a argument is a bang (!), then the 41 | rest of the line is interpreted as a shell command, and no escape 42 | processing is performed by ed. 43 | 44 | DEVIATIONS 45 | ---------- 46 | 1) Though ed is not a stream editor, it can be used to edit binary files. 47 | To assist in binary editing, when a file containing at least one ASCII 48 | NUL character is written, a newline is not appended if it did not 49 | already contain one upon reading. In particular, reading /dev/null 50 | prior to writing prevents appending a newline to a binary file. 51 | 52 | For example, to create a file with ed containing a single NUL character: 53 | $ ed file 54 | a 55 | ^@ 56 | . 57 | r /dev/null 58 | wq 59 | 60 | Similarly, to remove a newline from the end of binary `file': 61 | $ ed file 62 | r /dev/null 63 | wq 64 | 65 | 2) Since the behavior of `u' (undo) within a `g' (global) command list is 66 | not specified by POSIX, it follows the behavior of the SunOS ed: 67 | undo forces a global command list to be executed only once, rather than 68 | for each line matching a global pattern. In addition, each instance of 69 | `u' within a global command undoes all previous commands (including 70 | undo's) in the command list. This seems the best way, since the 71 | alternatives are either too complicated to implement or too confusing 72 | to use. 73 | 74 | The global/undo combination is useful for masking errors that 75 | would otherwise cause a script to fail. For instance, an ed script 76 | to remove any occurrences of either `censor1' or `censor2' might be 77 | written as: 78 | ed - file < 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "ed.h" 39 | 40 | static char *extract_pattern(int); 41 | static char *parse_char_class(char *); 42 | 43 | extern int patlock; 44 | 45 | 46 | /* get_compiled_pattern: return pointer to compiled pattern from command 47 | buffer */ 48 | regex_t * 49 | get_compiled_pattern(void) 50 | { 51 | static regex_t *exp = NULL; 52 | char errbuf[128] = ""; 53 | 54 | char *exps; 55 | char delimiter; 56 | int n; 57 | 58 | if ((delimiter = *ibufp) == ' ') { 59 | seterrmsg("invalid pattern delimiter"); 60 | return NULL; 61 | } else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) { 62 | if (!exp) 63 | seterrmsg("no previous pattern"); 64 | return exp; 65 | } else if ((exps = extract_pattern(delimiter)) == NULL) 66 | return NULL; 67 | /* buffer alloc'd && not reserved */ 68 | if (exp && !patlock) 69 | regfree(exp); 70 | else if ((exp = malloc(sizeof(regex_t))) == NULL) { 71 | perror(NULL); 72 | seterrmsg("out of memory"); 73 | return NULL; 74 | } 75 | patlock = 0; 76 | if ((n = regcomp(exp, exps, 0)) != 0) { 77 | regerror(n, exp, errbuf, sizeof errbuf); 78 | seterrmsg(errbuf); 79 | free(exp); 80 | return exp = NULL; 81 | } 82 | return exp; 83 | } 84 | 85 | 86 | /* extract_pattern: copy a pattern string from the command buffer; return 87 | pointer to the copy */ 88 | static char * 89 | extract_pattern(int delimiter) 90 | { 91 | static char *lhbuf = NULL; /* buffer */ 92 | static int lhbufsz = 0; /* buffer size */ 93 | 94 | char *nd; 95 | int len; 96 | 97 | for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++) 98 | switch (*nd) { 99 | default: 100 | break; 101 | case '[': 102 | if ((nd = parse_char_class(++nd)) == NULL) { 103 | seterrmsg("unbalanced brackets ([])"); 104 | return NULL; 105 | } 106 | break; 107 | case '\\': 108 | if (*++nd == '\n') { 109 | seterrmsg("trailing backslash (\\)"); 110 | return NULL; 111 | } 112 | break; 113 | } 114 | len = nd - ibufp; 115 | REALLOC(lhbuf, lhbufsz, len + 1, NULL); 116 | memcpy(lhbuf, ibufp, len); 117 | lhbuf[len] = '\0'; 118 | ibufp = nd; 119 | return (isbinary) ? NUL_TO_NEWLINE(lhbuf, len) : lhbuf; 120 | } 121 | 122 | 123 | /* parse_char_class: expand a POSIX character class */ 124 | static char * 125 | parse_char_class(char *s) 126 | { 127 | int c, d; 128 | 129 | if (*s == '^') 130 | s++; 131 | if (*s == ']') 132 | s++; 133 | for (; *s != ']' && *s != '\n'; s++) 134 | if (*s == '[' && ((d = *(s+1)) == '.' || d == ':' || d == '=')) 135 | for (s++, c = *++s; *s != ']' || c != d; s++) 136 | if ((c = *s) == '\n') 137 | return NULL; 138 | return (*s == ']') ? s : NULL; 139 | } 140 | -------------------------------------------------------------------------------- /undo.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: undo.c,v 1.14 2016/03/22 17:58:28 mmcc Exp $ */ 2 | /* $NetBSD: undo.c,v 1.2 1995/03/21 09:04:52 cgd Exp $ */ 3 | 4 | /* undo.c: This file contains the undo routines for the ed line editor */ 5 | /*- 6 | * Copyright (c) 1993 Andrew Moore, Talke Studio. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "ed.h" 37 | 38 | #define USIZE 100 /* undo stack size */ 39 | static undo_t *ustack = NULL; /* undo stack */ 40 | static int usize = 0; /* stack size variable */ 41 | static int u_p = 0; /* undo stack pointer */ 42 | 43 | /* push_undo_stack: return pointer to initialized undo node */ 44 | undo_t * 45 | push_undo_stack(int type, int from, int to) 46 | { 47 | undo_t *t; 48 | 49 | t = ustack; 50 | if (u_p < usize || 51 | (t = reallocarray(ustack, (usize += USIZE), sizeof(undo_t))) != NULL) { 52 | ustack = t; 53 | ustack[u_p].type = type; 54 | ustack[u_p].t = get_addressed_line_node(to); 55 | ustack[u_p].h = get_addressed_line_node(from); 56 | return ustack + u_p++; 57 | } 58 | /* out of memory - release undo stack */ 59 | perror(NULL); 60 | seterrmsg("out of memory"); 61 | clear_undo_stack(); 62 | free(ustack); 63 | ustack = NULL; 64 | usize = 0; 65 | return NULL; 66 | } 67 | 68 | 69 | /* USWAP: swap undo nodes */ 70 | #define USWAP(x,y) { \ 71 | undo_t utmp; \ 72 | utmp = x, x = y, y = utmp; \ 73 | } 74 | 75 | 76 | int u_current_addr = -1; /* if >= 0, undo enabled */ 77 | int u_addr_last = -1; /* if >= 0, undo enabled */ 78 | 79 | /* pop_undo_stack: undo last change to the editor buffer */ 80 | int 81 | pop_undo_stack(void) 82 | { 83 | int n; 84 | int o_current_addr = current_addr; 85 | int o_addr_last = addr_last; 86 | 87 | if (u_current_addr == -1 || u_addr_last == -1) { 88 | seterrmsg("nothing to undo"); 89 | return ERR; 90 | } else if (u_p) 91 | modified = 1; 92 | get_addressed_line_node(0); /* this get_addressed_line_node last! */ 93 | SPL1(); 94 | for (n = u_p; n-- > 0;) { 95 | switch(ustack[n].type) { 96 | case UADD: 97 | REQUE(ustack[n].h->q_back, ustack[n].t->q_forw); 98 | break; 99 | case UDEL: 100 | REQUE(ustack[n].h->q_back, ustack[n].h); 101 | REQUE(ustack[n].t, ustack[n].t->q_forw); 102 | break; 103 | case UMOV: 104 | case VMOV: 105 | REQUE(ustack[n - 1].h, ustack[n].h->q_forw); 106 | REQUE(ustack[n].t->q_back, ustack[n - 1].t); 107 | REQUE(ustack[n].h, ustack[n].t); 108 | n--; 109 | break; 110 | default: 111 | /*NOTREACHED*/ 112 | ; 113 | } 114 | ustack[n].type ^= 1; 115 | } 116 | /* reverse undo stack order */ 117 | for (n = u_p; n-- > (u_p + 1)/ 2;) 118 | USWAP(ustack[n], ustack[u_p - 1 - n]); 119 | if (isglobal) 120 | clear_active_list(); 121 | current_addr = u_current_addr, u_current_addr = o_current_addr; 122 | addr_last = u_addr_last, u_addr_last = o_addr_last; 123 | SPL0(); 124 | return 0; 125 | } 126 | 127 | 128 | /* clear_undo_stack: clear the undo stack */ 129 | void 130 | clear_undo_stack(void) 131 | { 132 | line_t *lp, *ep, *tl; 133 | 134 | while (u_p--) 135 | if (ustack[u_p].type == UDEL) { 136 | ep = ustack[u_p].t->q_forw; 137 | for (lp = ustack[u_p].h; lp != ep; lp = tl) { 138 | unmark_line_node(lp); 139 | tl = lp->q_forw; 140 | free(lp); 141 | } 142 | } 143 | u_p = 0; 144 | u_current_addr = current_addr; 145 | u_addr_last = addr_last; 146 | } 147 | -------------------------------------------------------------------------------- /USD.doc/09.edtut/e7: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: e7,v 1.4 2004/04/05 10:58:08 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)e7 8.1 (Berkeley) 6/8/93 36 | .\" 37 | .sp 2 38 | .SH 39 | Summary of Commands and Line Numbers 40 | .PP 41 | The general form of 42 | .ul 43 | ed 44 | commands is the command name, 45 | perhaps preceded by one or two line numbers, and, 46 | in the case of 47 | .UL e , 48 | .UL r , 49 | and 50 | .UL w , 51 | followed by a file name. 52 | Only one command is allowed per line, 53 | but a 54 | .UL p 55 | command may follow any other command 56 | (except for 57 | .UL e , 58 | .UL r , 59 | .UL w , 60 | and 61 | .UL q ). 62 | .LP 63 | .UL a : 64 | Append, that is, 65 | add lines to the buffer (at line dot, unless 66 | a different line is specified). Appending continues until 67 | \*. 68 | is typed on a new line. 69 | Dot is set to the last line appended. 70 | .LP 71 | .UL c : 72 | Change the specified lines to the new text which follows. 73 | The new lines are terminated by a 74 | \*., 75 | as with 76 | .UL a . 77 | If no lines are specified, 78 | replace line dot. 79 | Dot is set to the last line changed. 80 | .LP 81 | .UL d : 82 | Delete the lines specified. 83 | If none are specified, delete line dot. 84 | Dot is set to the first undeleted line, 85 | unless 86 | .UL $ 87 | is deleted, 88 | in which case dot is set to 89 | .UL $ . 90 | .LP 91 | .UL e : 92 | Edit new file. 93 | Any previous 94 | contents of the buffer are thrown away, 95 | so issue a 96 | .UL w 97 | beforehand. 98 | .LP 99 | .UL f : 100 | Print remembered filename. 101 | If a name follows 102 | .UL f 103 | the remembered name will be set to it. 104 | .LP 105 | .UL g : 106 | The command 107 | .P1 108 | g/\(hy\(hy\(hy/commands 109 | .P2 110 | will execute the commands on those lines that contain 111 | .UL --- , 112 | which can be any context search expression. 113 | .LP 114 | .UL i : 115 | Insert lines before specified line (or dot) 116 | until a 117 | \*. 118 | is typed on a new line. 119 | Dot is set to last line inserted. 120 | .LP 121 | .UL m : 122 | Move lines specified to after the line 123 | named after 124 | .UL m . 125 | Dot is set to the last line moved. 126 | .LP 127 | .UL p : 128 | Print specified lines. 129 | If none specified, print 130 | line dot. 131 | A single line number is equivalent to 132 | .IT line-number 133 | .UL p . 134 | A single return prints 135 | .UL .+1 , 136 | the next line. 137 | .LP 138 | .UL q : 139 | Quit 140 | .IT ed . 141 | Wipes out all text in buffer 142 | if you give it twice in a row without first giving a 143 | .UL w 144 | command. 145 | .LP 146 | .UL r : 147 | Read a file into buffer (at end unless specified 148 | elsewhere.) Dot set to last line read. 149 | .LP 150 | .UL s : 151 | The command 152 | .P1 153 | s/string1/string2/ 154 | .P2 155 | substitutes the characters 156 | .UL string1 157 | into 158 | .UL string2 159 | in the specified lines. 160 | If no lines are specified, make the substitution in line dot. 161 | Dot is set to the last line in which a 162 | substitution took place, which means that if no substitution took place, dot is not changed. 163 | .UL s 164 | changes only the first occurrence of 165 | .UL string1 166 | on a line; 167 | to change all of them, type a 168 | .UL g 169 | after the final slash. 170 | .LP 171 | .UL v : 172 | The command 173 | .P1 174 | v/\(hy\(hy\(hy/commands 175 | .P2 176 | executes 177 | .UL commands 178 | on those lines that 179 | .ul 180 | do not 181 | contain 182 | .UL --- . 183 | .LP 184 | .UL w : 185 | Write out buffer onto a file. 186 | Dot is not changed. 187 | .LP 188 | .UL .= : 189 | Print value of dot. 190 | .UL = "" ( 191 | by itself prints the value of 192 | .UL $ .) 193 | .LP 194 | .UL ! : 195 | The line 196 | .P1 197 | !command\(hyline 198 | .P2 199 | causes 200 | .UL command-line 201 | to be executed as a 202 | .UC UNIX 203 | command. 204 | .LP 205 | .UL /-----/ : 206 | Context search. 207 | Search for next line which contains 208 | this string of characters. 209 | Print it. 210 | Dot is set to the line where string 211 | was found. 212 | Search starts at 213 | .UL .+1 , 214 | wraps around from 215 | .UL $ 216 | to 217 | 1, 218 | and continues to dot, if necessary. 219 | .LP 220 | .UL ?-----? : 221 | Context search in reverse direction. 222 | Start search 223 | at 224 | .UL .\-1 , 225 | scan to 1, 226 | wrap around to 227 | .UL $ . 228 | -------------------------------------------------------------------------------- /ed.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: ed.h,v 1.23 2024/07/16 05:01:10 deraadt Exp $ */ 2 | /* $NetBSD: ed.h,v 1.23 1995/03/21 09:04:40 cgd Exp $ */ 3 | 4 | /* ed.h: type and constant definitions for the ed editor. */ 5 | /* 6 | * Copyright (c) 1993 Andrew Moore 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | * 30 | * @(#)ed.h,v 1.5 1994/02/01 00:34:39 alm Exp 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #define ERR (-2) 38 | #define EMOD (-3) 39 | #define FATAL (-4) 40 | 41 | #define MINBUFSZ 512 /* minimum buffer size - must be > 0 */ 42 | #define SE_MAX 30 /* max subexpressions in a regular expression */ 43 | #define LINECHARS INT_MAX /* max chars per line */ 44 | 45 | /* gflags */ 46 | #define GLB 001 /* global command */ 47 | #define GPR 002 /* print after command */ 48 | #define GLS 004 /* list after command */ 49 | #define GNP 010 /* enumerate after command */ 50 | #define GSG 020 /* global substitute */ 51 | 52 | /* Line node */ 53 | typedef struct line { 54 | struct line *q_forw; 55 | struct line *q_back; 56 | off_t seek; /* address of line in scratch buffer */ 57 | int len; /* length of line */ 58 | } line_t; 59 | 60 | 61 | typedef struct undo { 62 | 63 | /* type of undo nodes */ 64 | #define UADD 0 65 | #define UDEL 1 66 | #define UMOV 2 67 | #define VMOV 3 68 | 69 | int type; /* command type */ 70 | line_t *h; /* head of list */ 71 | line_t *t; /* tail of list */ 72 | } undo_t; 73 | 74 | #ifndef max 75 | # define max(a,b) ((a) > (b) ? (a) : (b)) 76 | #endif 77 | #ifndef min 78 | # define min(a,b) ((a) < (b) ? (a) : (b)) 79 | #endif 80 | 81 | #define INC_MOD(l, k) ((l) + 1 > (k) ? 0 : (l) + 1) 82 | #define DEC_MOD(l, k) ((l) - 1 < 0 ? (k) : (l) - 1) 83 | 84 | /* SPL1: disable some interrupts (requires reliable signals) */ 85 | #define SPL1() mutex++ 86 | 87 | /* SPL0: enable all interrupts; check signal flags (requires reliable signals) */ 88 | #define SPL0() \ 89 | do { \ 90 | if (--mutex == 0) { \ 91 | if (sigint) \ 92 | handle_int(SIGINT); \ 93 | } \ 94 | } while (0) 95 | 96 | /* STRTOI: convert a string to int */ 97 | #define STRTOI(i, p) { \ 98 | long l = strtol(p, &p, 10); \ 99 | if (l <= INT_MIN || l >= INT_MAX) { \ 100 | seterrmsg("number out of range"); \ 101 | i = 0; \ 102 | return ERR; \ 103 | } else \ 104 | i = (int)l; \ 105 | } 106 | 107 | /* REALLOC: assure at least a minimum size for buffer b */ 108 | #define REALLOC(b,n,i,err) \ 109 | if ((i) > (n)) { \ 110 | int ti = (n); \ 111 | char *ts; \ 112 | SPL1(); \ 113 | if ((ts = realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \ 114 | perror(NULL); \ 115 | seterrmsg("out of memory"); \ 116 | SPL0(); \ 117 | return err; \ 118 | } \ 119 | (n) = ti; \ 120 | (b) = ts; \ 121 | SPL0(); \ 122 | } 123 | 124 | /* REQUE: link pred before succ */ 125 | #define REQUE(pred, succ) (pred)->q_forw = (succ), (succ)->q_back = (pred) 126 | 127 | /* INSQUE: insert elem in circular queue after pred */ 128 | #define INSQUE(elem, pred) \ 129 | { \ 130 | REQUE((elem), (pred)->q_forw); \ 131 | REQUE((pred), elem); \ 132 | } 133 | 134 | /* remque: remove_lines elem from circular queue */ 135 | #define REMQUE(elem) REQUE((elem)->q_back, (elem)->q_forw); 136 | 137 | /* NUL_TO_NEWLINE: overwrite ASCII NULs with newlines */ 138 | #define NUL_TO_NEWLINE(s, l) translit_text(s, l, '\0', '\n') 139 | 140 | /* NEWLINE_TO_NUL: overwrite newlines with ASCII NULs */ 141 | #define NEWLINE_TO_NUL(s, l) translit_text(s, l, '\n', '\0') 142 | 143 | /* Local Function Declarations */ 144 | void add_line_node(line_t *); 145 | int build_active_list(int); 146 | void clear_active_list(void); 147 | void clear_undo_stack(void); 148 | int close_sbuf(void); 149 | int delete_lines(int, int); 150 | int display_lines(int, int, int); 151 | int exec_command(void); 152 | int exec_global(int, int); 153 | int extract_addr_range(void); 154 | int extract_subst_tail(int *, int *); 155 | line_t *get_addressed_line_node(int); 156 | regex_t *get_compiled_pattern(void); 157 | char *get_extended_line(int *, int); 158 | int get_line_node_addr(line_t *); 159 | char *get_sbuf_line(line_t *); 160 | int get_tty_line(void); 161 | void handle_hup(void); 162 | void handle_int(int); 163 | int has_trailing_escape(char *, char *); 164 | void init_buffers(void); 165 | int open_sbuf(void); 166 | int pop_undo_stack(void); 167 | undo_t *push_undo_stack(int, int, int); 168 | char *put_sbuf_line(char *); 169 | int put_tty_line(char *, int, int, int); 170 | void quit(int); 171 | int read_file(char *, int); 172 | int search_and_replace(regex_t *, int, int); 173 | void seterrmsg(char *); 174 | char *strip_escapes(char *); 175 | char *translit_text(char *, int, int, int); 176 | void unmark_line_node(line_t *); 177 | void unset_active_nodes(line_t *, line_t *); 178 | int write_file(char *, char *, int, int); 179 | 180 | /* global buffers */ 181 | extern char *ibuf; 182 | extern char *ibufp; 183 | extern int ibufsz; 184 | 185 | /* global flags */ 186 | extern int isbinary; 187 | extern int isglobal; 188 | extern int modified; 189 | 190 | extern volatile sig_atomic_t mutex; 191 | extern volatile sig_atomic_t sighup; 192 | extern volatile sig_atomic_t sigint; 193 | 194 | /* global vars */ 195 | extern int addr_last; 196 | extern int current_addr; 197 | extern int first_addr; 198 | extern int lineno; 199 | extern int second_addr; 200 | -------------------------------------------------------------------------------- /glbl.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: glbl.c,v 1.20 2018/06/04 13:26:21 martijn Exp $ */ 2 | /* $NetBSD: glbl.c,v 1.2 1995/03/21 09:04:41 cgd Exp $ */ 3 | 4 | /* glob.c: This file contains the global command routines for the ed line 5 | editor */ 6 | /*- 7 | * Copyright (c) 1993 Andrew Moore, Talke Studio. 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "ed.h" 42 | 43 | static int set_active_node(line_t *); 44 | static line_t *next_active_node(void); 45 | 46 | /* build_active_list: add line matching a pattern to the global-active list */ 47 | int 48 | build_active_list(int isgcmd) 49 | { 50 | regex_t *pat; 51 | line_t *lp; 52 | int n; 53 | char *s; 54 | char delimiter; 55 | 56 | if ((delimiter = *ibufp) == ' ' || delimiter == '\n') { 57 | seterrmsg("invalid pattern delimiter"); 58 | return ERR; 59 | } else if ((pat = get_compiled_pattern()) == NULL) 60 | return ERR; 61 | else if (*ibufp == delimiter) 62 | ibufp++; 63 | clear_active_list(); 64 | lp = get_addressed_line_node(first_addr); 65 | for (n = first_addr; n <= second_addr; n++, lp = lp->q_forw) { 66 | if ((s = get_sbuf_line(lp)) == NULL) 67 | return ERR; 68 | if (isbinary) 69 | NUL_TO_NEWLINE(s, lp->len); 70 | if ((!regexec(pat, s, 0, NULL, 0)) == isgcmd && 71 | set_active_node(lp) < 0) 72 | return ERR; 73 | } 74 | return 0; 75 | } 76 | 77 | 78 | /* exec_global: apply command list in the command buffer to the active 79 | lines in a range; return command status */ 80 | int 81 | exec_global(int interact, int gflag) 82 | { 83 | static char *ocmd = NULL; 84 | static int ocmdsz = 0; 85 | 86 | line_t *lp = NULL; 87 | int status; 88 | int n; 89 | char *cmd = NULL; 90 | 91 | if (!interact) { 92 | if (!strcmp(ibufp, "\n")) 93 | cmd = "p\n"; /* null cmd-list == `p' */ 94 | else if ((cmd = get_extended_line(&n, 0)) == NULL) 95 | return ERR; 96 | } 97 | clear_undo_stack(); 98 | while ((lp = next_active_node()) != NULL) { 99 | if ((current_addr = get_line_node_addr(lp)) < 0) 100 | return ERR; 101 | if (interact) { 102 | /* print current_addr; get a command in global syntax */ 103 | if (display_lines(current_addr, current_addr, gflag) < 0) 104 | return ERR; 105 | while ((n = get_tty_line()) > 0 && 106 | ibuf[n - 1] != '\n') 107 | clearerr(stdin); 108 | if (n < 0) 109 | return ERR; 110 | else if (n == 0) { 111 | seterrmsg("unexpected end-of-file"); 112 | return ERR; 113 | } else if (n == 1 && !strcmp(ibuf, "\n")) 114 | continue; 115 | else if (n == 2 && !strcmp(ibuf, "&\n")) { 116 | if (cmd == NULL) { 117 | seterrmsg("no previous command"); 118 | return ERR; 119 | } else cmd = ocmd; 120 | } else if ((cmd = get_extended_line(&n, 0)) == NULL) 121 | return ERR; 122 | else { 123 | REALLOC(ocmd, ocmdsz, n + 1, ERR); 124 | memcpy(ocmd, cmd, n + 1); 125 | cmd = ocmd; 126 | } 127 | 128 | } 129 | ibufp = cmd; 130 | for (; *ibufp;) 131 | if ((status = extract_addr_range()) < 0 || 132 | (status = exec_command()) < 0 || 133 | (status > 0 && (status = display_lines( 134 | current_addr, current_addr, status)) < 0)) 135 | return status; 136 | } 137 | return 0; 138 | } 139 | 140 | 141 | static line_t **active_list; /* list of lines active in a global command */ 142 | static int active_last; /* index of last active line in active_list */ 143 | static int active_size; /* size of active_list */ 144 | static int active_ptr; /* active_list index (non-decreasing) */ 145 | static int active_ndx; /* active_list index (modulo active_last) */ 146 | 147 | /* set_active_node: add a line node to the global-active list */ 148 | static int 149 | set_active_node(line_t *lp) 150 | { 151 | if (active_last + 1 > active_size) { 152 | int ti = active_size; 153 | line_t **ts; 154 | SPL1(); 155 | if ((ts = reallocarray(active_list, 156 | (ti += MINBUFSZ), sizeof(line_t **))) == NULL) { 157 | perror(NULL); 158 | seterrmsg("out of memory"); 159 | SPL0(); 160 | return ERR; 161 | } 162 | active_size = ti; 163 | active_list = ts; 164 | SPL0(); 165 | } 166 | active_list[active_last++] = lp; 167 | return 0; 168 | } 169 | 170 | 171 | /* unset_active_nodes: remove a range of lines from the global-active list */ 172 | void 173 | unset_active_nodes(line_t *np, line_t *mp) 174 | { 175 | line_t *lp; 176 | int i; 177 | 178 | for (lp = np; lp != mp; lp = lp->q_forw) 179 | for (i = 0; i < active_last; i++) 180 | if (active_list[active_ndx] == lp) { 181 | active_list[active_ndx] = NULL; 182 | active_ndx = INC_MOD(active_ndx, active_last - 1); 183 | break; 184 | } else active_ndx = INC_MOD(active_ndx, active_last - 1); 185 | } 186 | 187 | 188 | /* next_active_node: return the next global-active line node */ 189 | static line_t * 190 | next_active_node(void) 191 | { 192 | while (active_ptr < active_last && active_list[active_ptr] == NULL) 193 | active_ptr++; 194 | return (active_ptr < active_last) ? active_list[active_ptr++] : NULL; 195 | } 196 | 197 | 198 | /* clear_active_list: clear the global-active list */ 199 | void 200 | clear_active_list(void) 201 | { 202 | SPL1(); 203 | active_size = active_last = active_ptr = active_ndx = 0; 204 | free(active_list); 205 | active_list = NULL; 206 | SPL0(); 207 | } 208 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/ae4: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: ae4,v 1.3 2004/04/06 08:19:20 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)ae4 8.1 (Berkeley) 6/8/93 36 | .\" 37 | .NH 38 | GLOBAL COMMANDS 39 | .PP 40 | The global commands 41 | .UL g 42 | and 43 | .UL v 44 | are used to perform one or more editing commands on all lines that either 45 | contain 46 | .UL g ) ( 47 | or don't contain 48 | .UL v ) ( 49 | a specified pattern. 50 | .PP 51 | As the simplest example, the command 52 | .P1 53 | g/UNIX/p 54 | .P2 55 | prints all lines that contain the word `UNIX'. 56 | The pattern that goes between the slashes can be anything 57 | that could be used in a line search or in a substitute command; 58 | exactly the same rules and limitations apply. 59 | .PP 60 | As another example, then, 61 | .P1 62 | g/^\*e\*./p 63 | .P2 64 | prints all the formatting commands in a file (lines that begin with `\*.'). 65 | .PP 66 | The 67 | .UL v 68 | command is identical to 69 | .UL g , 70 | except that it operates on those line that do 71 | .ul 72 | not 73 | contain an occurrence of the pattern. 74 | (Don't look too hard for mnemonic significance to 75 | the letter `v'.) 76 | So 77 | .P1 78 | v/^\*e\*./p 79 | .P2 80 | prints all the lines that don't begin with `\*.' _ 81 | the actual text lines. 82 | .PP 83 | The command that follows 84 | .UL g 85 | or 86 | .UL v 87 | can be anything: 88 | .P1 89 | g/^\*e\*./d 90 | .P2 91 | deletes all lines that begin with `\*.', 92 | and 93 | .P1 94 | g/^$/d 95 | .P2 96 | deletes all empty lines. 97 | .PP 98 | Probably the most useful command that can follow a global is the 99 | substitute command, for this can be used to make a change 100 | and print each affected line for verification. 101 | For example, we could change the word `Unix' to `UNIX' 102 | everywhere, and verify that 103 | it really worked, 104 | with 105 | .P1 106 | g/Unix/s//UNIX/gp 107 | .P2 108 | Notice that we used `//' in the substitute command to mean 109 | `the previous pattern', in this case, `Unix'. 110 | The 111 | .UL p 112 | command is done on every line 113 | that matches the pattern, 114 | not just those on which a substitution took place. 115 | .PP 116 | The global command operates by making 117 | two passes over the file. 118 | On the first pass, all lines that match the pattern are marked. 119 | On the second pass, each marked line in turn is examined, 120 | dot is set to that line, and the command executed. 121 | This means that it is possible for the command that follows a 122 | .UL g 123 | or 124 | .UL v 125 | to use addresses, set dot, and so on, quite freely. 126 | .P1 127 | g/^\*e\*.PP/+ 128 | .P2 129 | prints the line that follows each `.PP' command (the signal for 130 | a new paragraph in some formatting packages). 131 | Remember that `+' means `one line past dot'. 132 | And 133 | .P1 134 | g/topic/?^\*e\*.SH?1 135 | .P2 136 | searches for each line that contains `topic', scans backwards until it finds 137 | a line that begins `.SH' (a section heading) and prints the line 138 | that follows that, 139 | thus showing the section headings under which `topic' is mentioned. 140 | Finally, 141 | .P1 142 | g/^\*e\*.EQ/+,/^\*e\*.EN/-p 143 | .P2 144 | prints all the lines that lie between 145 | lines beginning with `.EQ' and `.EN' formatting commands. 146 | .PP 147 | The 148 | .UL g 149 | and 150 | .UL v 151 | commands can also be 152 | preceded by line numbers, in which case the lines searched 153 | are only those in the range specified. 154 | .SH 155 | Multi-line Global Commands 156 | .PP 157 | It is possible to do more than one command under the control of a 158 | global command, although the syntax for expressing the operation 159 | is not especially natural or pleasant. 160 | As an example, 161 | suppose the task is to change `x' to `y' and `a' to `b' on all lines 162 | that contain `thing'. 163 | Then 164 | .P1 165 | g/thing/s/x/y/\*e 166 | s/a/b/ 167 | .P2 168 | is sufficient. 169 | The `\*e' signals the 170 | .UL g 171 | command that the set of commands continues on the next line; 172 | it terminates on the first line that does not end with `\*e'. 173 | (As a minor blemish, you can't use a substitute command 174 | to insert a newline within a 175 | .UL g 176 | command.) 177 | .PP 178 | You should watch out for this problem: 179 | the command 180 | .P1 181 | g/x/s//y/\*e 182 | s/a/b/ 183 | .P2 184 | does 185 | .ul 186 | not 187 | work as you expect. 188 | The remembered pattern is the last pattern that was actually 189 | executed, 190 | so sometimes it will be 191 | `x' (as expected), and sometimes it will be `a' 192 | (not expected). 193 | You must spell it out, like this: 194 | .P1 195 | g/x/s/x/y/\*e 196 | s/a/b/ 197 | .P2 198 | .PP 199 | It is also possible to execute 200 | .UL a , 201 | .UL c , 202 | and 203 | .UL i 204 | commands under a global command; as with other multi-line constructions, 205 | all that is needed is to add a `\*e' at the end of each line except the last. 206 | Thus to add a `.nf' and `.sp' command before each `.EQ' line, type 207 | .P1 208 | g/^\*e\*.EQ/i\*e 209 | \&\*.nf\*e 210 | \&\*.sp 211 | .P2 212 | There is no need for a final line containing a 213 | `\*.' to terminate the 214 | .UL i 215 | command, 216 | unless there are further commands 217 | being done under the global. 218 | On the other hand, it does no harm to put it in either. 219 | -------------------------------------------------------------------------------- /USD.doc/09.edtut/e6: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: e6,v 1.3 2004/04/05 10:58:08 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)e6 8.1 (Berkeley) 6/8/93 36 | .\" 37 | .SH 38 | Special Characters 39 | .PP 40 | You may have noticed that things just don't work right when you used 41 | some characters like 42 | \*., 43 | .UL * , 44 | .UL $ , 45 | and others in 46 | context searches and the substitute command. 47 | The reason is rather complex, although the cure is simple. 48 | Basically, 49 | .ul 50 | ed 51 | treats these characters as special, with special meanings. 52 | For instance, 53 | .ul 54 | in a context search or the first string of the substitute command only, 55 | \*. 56 | means ``any character,'' not a period, so 57 | .P1 58 | /x\*.y/ 59 | .P2 60 | means ``a line with an 61 | .UL x , 62 | .UL "any character" , 63 | and a 64 | .UL y ,'' 65 | .ul 66 | not 67 | just ``a line with an 68 | .UL x , 69 | a period, and a 70 | .UL y .'' 71 | A complete list of the special characters 72 | that can cause trouble is the following: 73 | .P1 74 | ^ \*. $ [ * \e & 75 | .P2 76 | .ul 77 | Warning: 78 | The backslash character 79 | .UL \e 80 | is special to 81 | .UL ed . 82 | For safety's sake, 83 | avoid it where possible. 84 | If you have to use one of the special characters 85 | in a substitute command, 86 | you can turn off its magic meaning temporarily 87 | by preceding it with the backslash. 88 | Thus 89 | .P1 90 | s/\e\e\e\*.\e*/backslash dot star/ 91 | .P2 92 | will change 93 | .UL \e.* 94 | into ``backslash dot star''. 95 | .PP 96 | Here is a hurried synopsis of the other special characters. 97 | First, the circumflex 98 | .UL ^ 99 | signifies 100 | the beginning of a line. 101 | Thus 102 | .P1 103 | /^string/ 104 | .P2 105 | finds 106 | .UL string 107 | only if it is at the beginning of a line: 108 | it will find 109 | .P1 110 | string 111 | .P2 112 | but not 113 | .P1 114 | the string... 115 | .P2 116 | The dollar-sign 117 | .UL $ 118 | is just the opposite of the circumflex; 119 | it means the end of a line: 120 | .P1 121 | /string$/ 122 | .P2 123 | will only find an occurrence of 124 | .UL string 125 | that is at the end of some line. 126 | This implies, of course, 127 | that 128 | .P1 129 | /^string$/ 130 | .P2 131 | will find only a line that contains just 132 | .UL string , 133 | and 134 | .P1 135 | /^\*.$/ 136 | .P2 137 | finds a line containing exactly one character. 138 | .PP 139 | The character 140 | .UL . , 141 | as we mentioned above, 142 | matches anything; 143 | .P1 144 | /x\*.y/ 145 | .P2 146 | matches any of 147 | .P1 148 | x+y 149 | x-y 150 | x y 151 | x\*.y 152 | .P2 153 | This is useful in conjunction with 154 | .UL * , 155 | which is a repetition character; 156 | .UL a* 157 | is a shorthand for ``any number of 158 | .UL a 's,'' 159 | so 160 | .UL .* 161 | matches any number of anythings. 162 | This is used like this: 163 | .P1 164 | s/\*.*/stuff/ 165 | .P2 166 | which changes an entire line, 167 | or 168 | .P1 169 | s/\*.*,// 170 | .P2 171 | which deletes all characters in the line up to and 172 | including the last comma. 173 | (Since 174 | .UL .* 175 | finds the longest possible match, 176 | this goes up to the last comma.) 177 | .PP 178 | .UL [ 179 | is used with 180 | .UL ] 181 | to form ``character classes''; 182 | for example, 183 | .P1 184 | /[0123456789]/ 185 | .P2 186 | matches any single digit \- 187 | any one of the characters inside the braces 188 | will cause a match. 189 | This can be abbreviated to 190 | .UL [0\-9] . 191 | .PP 192 | Finally, the 193 | .UL & 194 | is another shorthand character \- 195 | it is used only on the right-hand part of a substitute command 196 | where it means ``whatever was matched on the left-hand side''. 197 | It is used to save typing. 198 | Suppose the current line contained 199 | .P1 200 | Now is the time 201 | .P2 202 | and you wanted to put parentheses around it. 203 | You could just retype the line, but 204 | this is tedious. 205 | Or you could say 206 | .P1 207 | s/^/(/ 208 | s/$/)/ 209 | .P2 210 | using your knowledge of 211 | .UL ^ 212 | and 213 | .UL $ . 214 | But the easiest way uses the 215 | .UL & : 216 | .P1 217 | s/\*.*/(&)/ 218 | .P2 219 | This says ``match the whole line, and replace it 220 | by itself surrounded by parentheses.'' 221 | The 222 | .UL & 223 | can be used several times in a line; 224 | consider 225 | using 226 | .P1 227 | s/\*.*/&? &!!/ 228 | .P2 229 | to produce 230 | .P1 231 | Now is the time? Now is the time!! 232 | .P2 233 | .PP 234 | You don't have to match the whole line, of course: 235 | if the buffer contains 236 | .P1 237 | the end of the world 238 | .P2 239 | you could type 240 | .P1 241 | /world/s//& is at hand/ 242 | .P2 243 | to produce 244 | .P1 245 | the end of the world is at hand 246 | .P2 247 | Observe this expression carefully, 248 | for it illustrates how to take advantage of 249 | .ul 250 | ed 251 | to save typing. 252 | The string 253 | .UL /world/ 254 | found the desired line; 255 | the shorthand 256 | .UL // 257 | found the same 258 | word in the line; 259 | and the 260 | .UL & 261 | saves you from typing it again. 262 | .PP 263 | The 264 | .UL & 265 | is a special character only within 266 | the replacement text of a substitute command, 267 | and has no special meaning elsewhere. 268 | You can turn off the special meaning of 269 | .UL & 270 | by preceding it with a 271 | .UL \e : 272 | .P1 273 | s/ampersand/\e&/ 274 | .P2 275 | will convert the word ``ampersand'' into the literal symbol 276 | .UL & 277 | in the current line. 278 | -------------------------------------------------------------------------------- /USD.doc/10.edadv/ae7: -------------------------------------------------------------------------------- 1 | .\" $OpenBSD: ae7,v 1.3 2004/04/06 08:19:20 jmc Exp $ 2 | .\" 3 | .\" Copyright (C) Caldera International Inc. 2001-2002. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code and documentation must retain the above 10 | .\" copyright notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed or owned by Caldera 17 | .\" International, Inc. 18 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 19 | .\" contributors may be used to endorse or promote products derived from 20 | .\" this software without specific prior written permission. 21 | .\" 22 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 23 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 24 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 27 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | .\" POSSIBILITY OF SUCH DAMAGE. 34 | .\" 35 | .\" @(#)ae7 8.1 (Berkeley) 6/8/93 36 | .\" 37 | .NH 38 | SUPPORTING TOOLS 39 | .PP 40 | There are several tools and techniques that go along with the 41 | editor, all of which are relatively easy once you 42 | know how 43 | .UL ed 44 | works, 45 | because they are all based on the editor. 46 | In this section we will give some fairly cursory examples 47 | of these tools, 48 | more to indicate their existence than to provide 49 | a complete tutorial. 50 | More information on each can be found in 51 | [3]. 52 | .SH 53 | Grep 54 | .PP 55 | Sometimes you want to find all occurrences of some word or pattern in 56 | a set of files, to edit them 57 | or perhaps just to verify their presence or absence. 58 | It may be possible to edit each file separately and look 59 | for the pattern of interest, but if there are many files 60 | this can get very tedious, 61 | and if the files are really big, 62 | it may be impossible because of limits in 63 | .UL ed . 64 | .PP 65 | The program 66 | .UL grep 67 | was invented to get around these limitations. 68 | The search patterns that we have described in the paper are often 69 | called `regular expressions', and 70 | `grep' stands for 71 | .P1 72 | g/re/p 73 | .P2 74 | That describes exactly what 75 | .UL grep 76 | does _ 77 | it prints every line in a set of files that contains a 78 | particular pattern. 79 | Thus 80 | .P1 81 | grep \(fmthing\(fm file1 file2 file3 ... 82 | .P2 83 | finds `thing' wherever it occurs in any of the files 84 | `file1', 85 | `file2', 86 | etc. 87 | .UL grep 88 | also indicates the file in which the line was found, 89 | so you can later edit it if you like. 90 | .PP 91 | The pattern represented by `thing' can be any 92 | pattern you can use in the editor, 93 | since 94 | .UL grep 95 | and 96 | .UL ed 97 | use exactly the same mechanism for 98 | pattern searching. 99 | It is wisest always to enclose the pattern in the 100 | single quotes \(fm...\(fm if it contains any non-alphabetic 101 | characters, since many such characters also mean something 102 | special to the 103 | .UX 104 | command interpreter 105 | (the `shell'). 106 | If you don't quote them, the command interpreter will 107 | try to interpret them before 108 | .UL grep 109 | gets a chance. 110 | .PP 111 | There is also a way to find lines that 112 | .ul 113 | don't 114 | contain a pattern: 115 | .P1 116 | grep -v \(fmthing\(fm file1 file2 ... 117 | .P2 118 | finds all lines that 119 | don't contains `thing'. 120 | The 121 | .UL \-v 122 | must occur in the position shown. 123 | Given 124 | .UL grep 125 | and 126 | .UL grep\ \-v , 127 | it is possible to do things like selecting all lines that 128 | contain some combination of patterns. 129 | For example, to get all lines that contain `x' but not `y': 130 | .P1 131 | grep x file... | grep -v y 132 | .P2 133 | (The notation | is a `pipe', 134 | which causes the output of the first command to be used as 135 | input to the second command; see [2].) 136 | .SH 137 | Editing Scripts 138 | .PP 139 | If a fairly complicated set of editing operations 140 | is to be done on a whole set of files, 141 | the easiest thing to do is to make up a `script', 142 | i.e., a file that contains the operations you want to perform, 143 | then apply this script to each file in turn. 144 | .PP 145 | For example, suppose you want to change every 146 | `Unix' to `UNIX' and every `Gcos' to `GCOS' in a large number of files. 147 | Then put into the file `script' the lines 148 | .P1 149 | g/Unix/s//UNIX/g 150 | g/Gcos/s//GCOS/g 151 | w 152 | q 153 | .P2 154 | Now you can say 155 | .P1 156 | ed file1