mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3145 from TheBorrowCheckers/cat-cleanup
cat: minor cleanups
This commit is contained in:
commit
cb54e76151
1 changed files with 12 additions and 13 deletions
|
@ -325,15 +325,15 @@ fn cat_path(
|
||||||
state: &mut OutputState,
|
state: &mut OutputState,
|
||||||
out_info: Option<&FileInformation>,
|
out_info: Option<&FileInformation>,
|
||||||
) -> CatResult<()> {
|
) -> CatResult<()> {
|
||||||
if path == "-" {
|
|
||||||
let stdin = io::stdin();
|
|
||||||
let mut handle = InputHandle {
|
|
||||||
reader: stdin,
|
|
||||||
is_interactive: atty::is(atty::Stream::Stdin),
|
|
||||||
};
|
|
||||||
return cat_handle(&mut handle, options, state);
|
|
||||||
}
|
|
||||||
match get_input_type(path)? {
|
match get_input_type(path)? {
|
||||||
|
InputType::StdIn => {
|
||||||
|
let stdin = io::stdin();
|
||||||
|
let mut handle = InputHandle {
|
||||||
|
reader: stdin,
|
||||||
|
is_interactive: atty::is(atty::Stream::Stdin),
|
||||||
|
};
|
||||||
|
cat_handle(&mut handle, options, state)
|
||||||
|
}
|
||||||
InputType::Directory => Err(CatError::IsDirectory),
|
InputType::Directory => Err(CatError::IsDirectory),
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
InputType::Socket => {
|
InputType::Socket => {
|
||||||
|
@ -560,13 +560,12 @@ fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
|
||||||
{
|
{
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
writer.write_all(&in_buf[..p]).unwrap();
|
writer.write_all(&in_buf[..p]).unwrap();
|
||||||
if in_buf[p] == b'\n' {
|
if in_buf[p] == b'\t' {
|
||||||
return count + p;
|
|
||||||
} else if in_buf[p] == b'\t' {
|
|
||||||
writer.write_all(b"^I").unwrap();
|
writer.write_all(b"^I").unwrap();
|
||||||
in_buf = &in_buf[p + 1..];
|
in_buf = &in_buf[p + 1..];
|
||||||
count += p + 1;
|
count += p + 1;
|
||||||
} else {
|
} else {
|
||||||
|
// b'\n' or b'\r'
|
||||||
return count + p;
|
return count + p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -589,10 +588,10 @@ fn write_nonprint_to_end<W: Write>(in_buf: &[u8], writer: &mut W, tab: &[u8]) ->
|
||||||
9 => writer.write_all(tab),
|
9 => writer.write_all(tab),
|
||||||
0..=8 | 10..=31 => writer.write_all(&[b'^', byte + 64]),
|
0..=8 | 10..=31 => writer.write_all(&[b'^', byte + 64]),
|
||||||
32..=126 => writer.write_all(&[byte]),
|
32..=126 => writer.write_all(&[byte]),
|
||||||
127 => writer.write_all(&[b'^', byte - 64]),
|
127 => writer.write_all(&[b'^', b'?']),
|
||||||
128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
|
128..=159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
|
||||||
160..=254 => writer.write_all(&[b'M', b'-', byte - 128]),
|
160..=254 => writer.write_all(&[b'M', b'-', byte - 128]),
|
||||||
_ => writer.write_all(&[b'M', b'-', b'^', 63]),
|
_ => writer.write_all(&[b'M', b'-', b'^', b'?']),
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue