Anonymous user
User defined pipe and redirection operators: Difference between revisions
User defined pipe and redirection operators (view source)
Revision as of 21:50, 8 August 2014
, 9 years ago→{{header|Go}}: Use builtin io.TeeReader; don't special-case CloseWithError(io.EOF)
(→{{header|ALGOL 68}}: PROC and OP details) |
(→{{header|Go}}: Use builtin io.TeeReader; don't special-case CloseWithError(io.EOF)) |
||
Line 194:
import (
"bufio"
"fmt"
"io"
Line 205 ⟶ 204:
// fake file system
var fs = make(map[string]string)
type file struct{ name string }
func (f file) Write(p []byte) (int, error) {
}
// role of > operator
func toName(name string, src io.Reader) {
▲ fs[name] = string(b)
}
// role of < operator
func fromName(name string) io.Reader {
return
}
func tee(in io.Reader, name string) io.Reader {
switch readErr {▼
▲ return pr
}
Line 319 ⟶ 301:
io.WriteString(pw, "\n")
}
}
pw.CloseWithError(readErr)
Line 369 ⟶ 350:
}
writeLines(0, rn)
}()
return pr
Line 382 ⟶ 359:
go func() {
b, err := ioutil.ReadAll(in)
if len(b) > 0 {
if b[len(b)-1] == '\n' {
Line 398 ⟶ 371:
}
}
pw.
}()
return pr
|