rsc | b2cfc4e | 2003-09-30 17:47:41 +0000 | [diff] [blame] | 1 | #include <fmt.h> |
| 2 | #include "bio.h" |
| 3 | |
| 4 | Biobuf bout; |
| 5 | |
| 6 | void |
| 7 | bcat(Biobuf *b, char *name) |
| 8 | { |
| 9 | char buf[1000]; |
| 10 | int n; |
| 11 | |
| 12 | while((n = Bread(b, buf, sizeof buf)) > 0){ |
| 13 | if(Bwrite(&bout, buf, n) < 0) |
| 14 | fprint(2, "writing during %s: %r\n", name); |
| 15 | } |
| 16 | if(n < 0) |
| 17 | fprint(2, "reading %s: %r\n", name); |
| 18 | } |
| 19 | |
| 20 | int |
| 21 | main(int argc, char **argv) |
| 22 | { |
| 23 | int i; |
| 24 | Biobuf b, *bp; |
rsc | 669250d | 2003-12-03 22:50:48 +0000 | [diff] [blame] | 25 | Fmt fmt; |
rsc | b2cfc4e | 2003-09-30 17:47:41 +0000 | [diff] [blame] | 26 | |
| 27 | Binit(&bout, 1, O_WRONLY); |
rsc | 669250d | 2003-12-03 22:50:48 +0000 | [diff] [blame] | 28 | Bfmtinit(&fmt, &bout); |
| 29 | fmtprint(&fmt, "hello, world\n"); |
| 30 | Bfmtflush(&fmt); |
rsc | b2cfc4e | 2003-09-30 17:47:41 +0000 | [diff] [blame] | 31 | |
| 32 | if(argc == 1){ |
| 33 | Binit(&b, 0, O_RDONLY); |
| 34 | bcat(&b, "<stdin>"); |
| 35 | }else{ |
| 36 | for(i=1; i<argc; i++){ |
| 37 | if((bp = Bopen(argv[i], O_RDONLY)) == 0){ |
| 38 | fprint(2, "Bopen %s: %r\n", argv[i]); |
| 39 | continue; |
| 40 | } |
| 41 | bcat(bp, argv[i]); |
| 42 | Bterm(bp); |
| 43 | } |
| 44 | } |
| 45 | exit(0); |
| 46 | } |