fn cat<F: Read>(&self, file: &mut F, line_count: &mut usize, stdout: &mut StdoutLock, stderr: &mut Stderr) {
        let mut character_count = 0;
        let mut last_line_was_blank = false;
        let mut buf: [u8; 8*8192] = [0; 8*8192]; // 64K seems to be the sweet spot for a buffer on my machine.
        let mut out_buf: Vec<u8> = Vec::with_capacity(24*8192); // Worst case 2 chars out per char
        loop {
            let n_read = file.read(&mut buf).try(stderr);
            if n_read == 0 { // We've reached the end of the input
                break;
            }

            for &byte in buf[0..n_read].iter() {
                if character_count == 0 && (self.number || (self.number_nonblank && byte != b'\n')) {
                    out_buf.write(b"     ").try(stderr);
                    out_buf.write(line_count.to_string().as_bytes()).try(stderr);
                    out_buf.write(b"  ").try(stderr);
                    *line_count += 1;
                }
                match byte {
                    0...8 | 11...31 => if self.show_nonprinting {
                        push_caret(&mut out_buf, stderr, byte+64);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    9 => {
                        if self.show_tabs {
                            push_caret(&mut out_buf, stderr, b'I');
                        } else {
                            out_buf.write(&[byte]).try(stderr);
                        }
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    }
                    10 => {
                        if character_count == 0 {
                            if self.squeeze_blank && last_line_was_blank {
                                continue
                            } else if !last_line_was_blank {
                                last_line_was_blank = true;
                            }
                        } else {
                            last_line_was_blank = false;
                            character_count = 0;
                        }
                        if self.show_ends {
                            out_buf.write(b"$\n").try(stderr);
                        } else {
                            out_buf.write(b"\n").try(stderr);
                        }
                    },
                    32...126 => {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    127 => if self.show_nonprinting {
                        push_caret(&mut out_buf, stderr, b'?');
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    128...159 => if self.show_nonprinting {
                        out_buf.write(b"M-^").try(stderr);
                        out_buf.write(&[byte-64]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    } else {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    _ => if self.show_nonprinting {
                        out_buf.write(b"M-").try(stderr);
                        out_buf.write(&[byte-128]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    } else {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                }
            }
            stdout.write_all(&out_buf).try(stderr);
            out_buf.clear();
        }
    }
/// Cats either a file or stdin based on the flag arguments given to the program.
Cats either a file or stdin based on the flag arguments given to the program.
Cats either a file or stdin based on the flag arguments given to the program .
fn cat<F: Read>(&self, file: &mut F, line_count: &mut usize, stdout: &mut StdoutLock, stderr: &mut Stderr) {
        let mut character_count = 0;
        let mut last_line_was_blank = false;
        let mut buf: [u8; 8*8192] = [0; 8*8192]; // 64K seems to be the sweet spot for a buffer on my machine.
        let mut out_buf: Vec<u8> = Vec::with_capacity(24*8192); // Worst case 2 chars out per char
        loop {
            let n_read = file.read(&mut buf).try(stderr);
            if n_read == 0 { // We've reached the end of the input
                break;
            }
            for &byte in buf[0..n_read].iter() {
                if character_count == 0 && (self.number || (self.number_nonblank && byte != b'\n')) {
                    out_buf.write(b"     ").try(stderr);
                    out_buf.write(line_count.to_string().as_bytes()).try(stderr);
                    out_buf.write(b"  ").try(stderr);
                    *line_count += 1;
                }
                match byte {
                    0...8 | 11...31 => if self.show_nonprinting {
                        push_caret(&mut out_buf, stderr, byte+64);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    9 => {
                        if self.show_tabs {
                            push_caret(&mut out_buf, stderr, b'I');
                        } else {
                            out_buf.write(&[byte]).try(stderr);
                        }
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    }
                    10 => {
                        if character_count == 0 {
                            if self.squeeze_blank && last_line_was_blank {
                                continue
                            } else if !last_line_was_blank {
                                last_line_was_blank = true;
                            }
                        } else {
                            last_line_was_blank = false;
                            character_count = 0;
                        }
                        if self.show_ends {
                            out_buf.write(b"$\n").try(stderr);
                        } else {
                            out_buf.write(b"\n").try(stderr);
                        }
                    },
                    32...126 => {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    127 => if self.show_nonprinting {
                        push_caret(&mut out_buf, stderr, b'?');
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    128...159 => if self.show_nonprinting {
                        out_buf.write(b"M-^").try(stderr);
                        out_buf.write(&[byte-64]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    } else {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                    _ => if self.show_nonprinting {
                        out_buf.write(b"M-").try(stderr);
                        out_buf.write(&[byte-128]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    } else {
                        out_buf.write(&[byte]).try(stderr);
                        count_character(&mut character_count, &self.number, &self.number_nonblank);
                    },
                }
            }
            stdout.write_all(&out_buf).try(stderr);
            out_buf.clear();
        }
    }
fn cat < F : Read > ( & self , file : & mut F , line_count : & mut usize , stdout : & mut StdoutLock , stderr : & mut Stderr ) { let mut character_count = 0 ; let mut last_line_was_blank = false ; let mut buf : [ u8 ; 8 * 8192 ] = [ 0 ; 8 * 8192 ] ; // 64K seems to be the sweet spot for a buffer on my machine. let mut out_buf : Vec < u8 > = Vec :: with_capacity ( 24 * 8192 ) ; // Worst case 2 chars out per char loop { let n_read = file . read ( & mut buf ) . try ( stderr ) ; if n_read == 0 { // We've reached the end of the input break ; } for & byte in buf [ 0 .. n_read ] . iter ( ) { if character_count == 0 && ( self . number || ( self . number_nonblank && byte != b'\n' ) ) { out_buf . write ( b" " ) . try ( stderr ) ; out_buf . write ( line_count . to_string ( ) . as_bytes ( ) ) . try ( stderr ) ; out_buf . write ( b" " ) . try ( stderr ) ; * line_count += 1 ; } match byte { 0 ... 8 | 11 ... 31 => if self . show_nonprinting { push_caret ( & mut out_buf , stderr , byte + 64 ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } , 9 => { if self . show_tabs { push_caret ( & mut out_buf , stderr , b'I' ) ; } else { out_buf . write ( & [ byte ] ) . try ( stderr ) ; } count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } 10 => { if character_count == 0 { if self . squeeze_blank && last_line_was_blank { continue } else if ! last_line_was_blank { last_line_was_blank = true ; } } else { last_line_was_blank = false ; character_count = 0 ; } if self . show_ends { out_buf . write ( b" \n " ) . try ( stderr ) ; } else { out_buf . write ( b" \n " ) . try ( stderr ) ; } } , 32 ... 126 => { out_buf . write ( & [ byte ] ) . try ( stderr ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } , 127 => if self . show_nonprinting { push_caret ( & mut out_buf , stderr , b'?' ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } , 128 ... 159 => if self . show_nonprinting { out_buf . write ( b" " ) . try ( stderr ) ; out_buf . write ( & [ byte - 64 ] ) . try ( stderr ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } else { out_buf . write ( & [ byte ] ) . try ( stderr ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } , _ => if self . show_nonprinting { out_buf . write ( b" " ) . try ( stderr ) ; out_buf . write ( & [ byte - 128 ] ) . try ( stderr ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } else { out_buf . write ( & [ byte ] ) . try ( stderr ) ; count_character ( & mut character_count , & self . number , & self . number_nonblank ) ; } , } } stdout . write_all ( & out_buf ) . try ( stderr ) ; out_buf . clear ( ) ; } }
Cats either a file or stdin based on the flag arguments given to the program.
Cats either a file or stdin based on the flag arguments given to the program .
&self
file
&mut F
line_count
&mut usize
stdout
&mut StdoutLock
stderr
&mut Stderr