Remove pipe_* macros

This commit is contained in:
Alex Lyon
2017-12-10 20:57:39 -08:00
parent 6829ca3d10
commit 7aea948473
73 changed files with 150 additions and 311 deletions
+4 -4
View File
@@ -13,11 +13,11 @@ extern crate uucore;
use uucore::encoding::{Data, Format, wrap_print};
use std::fs::File;
use std::io::{BufReader, Read, stdin, Write};
use std::io::{BufReader, Read, stdin};
use std::path::Path;
static SYNTAX: &'static str = "[OPTION]... [FILE]";
static SUMMARY: &'static str = "Base32 encode or decode FILE, or standard input, to standard output.";
static SYNTAX: &'static str = "[OPTION]... [FILE]";
static SUMMARY: &'static str = "Base32 encode or decode FILE, or standard input, to standard output.";
static LONG_HELP: &'static str = "
With no FILE, or when FILE is -, read standard input.
@@ -39,7 +39,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)",
"COLS")
.parse(args);
let line_wrap = match matches.opt_str("wrap") {
Some(s) => {
match s.parse() {
+3 -3
View File
@@ -15,11 +15,11 @@ extern crate uucore;
use uucore::encoding::{Data, Format, wrap_print};
use std::fs::File;
use std::io::{BufReader, Read, stdin, Write};
use std::io::{BufReader, Read, stdin};
use std::path::Path;
static SYNTAX: &'static str = "[OPTION]... [FILE]";
static SUMMARY: &'static str = "Base64 encode or decode FILE, or standard input, to standard output.";
static SYNTAX: &'static str = "[OPTION]... [FILE]";
static SUMMARY: &'static str = "Base64 encode or decode FILE, or standard input, to standard output.";
static LONG_HELP: &'static str = "
With no FILE, or when FILE is -, read standard input.
+2 -3
View File
@@ -12,13 +12,12 @@
#[macro_use]
extern crate uucore;
use std::io::Write;
use std::path::{is_separator, PathBuf};
static NAME: &'static str = "basename";
static SYNTAX: &'static str = "NAME [SUFFIX]";
static SYNTAX: &'static str = "NAME [SUFFIX]";
static SUMMARY: &'static str = "Print NAME with any leading directory components removed
If specified, also remove a trailing SUFFIX";
If specified, also remove a trailing SUFFIX";
static LONG_HELP: &'static str = "";
pub fn uumain(args: Vec<String>) -> i32 {
-1
View File
@@ -17,7 +17,6 @@ use uucore::fs::resolve_relative_path;
extern crate walkdir;
use walkdir::WalkDir;
use std::io::prelude::*;
use std::io::Result as IOResult;
use std::io::Error as IOError;
-1
View File
@@ -17,7 +17,6 @@ extern crate walker;
extern crate uucore;
use std::fs;
use std::io::Write;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::Path;
use walker::Walker;
+1 -1
View File
@@ -23,7 +23,7 @@ use walkdir::WalkDir;
use std::fs::{self, Metadata};
use std::os::unix::fs::MetadataExt;
use std::io::{self, Write};
use std::io;
use std::io::Result as IOResult;
use std::path::Path;
+4 -4
View File
@@ -18,18 +18,18 @@ use uucore::libc::{self, setgid, setuid, chroot, setgroups};
use uucore::entries;
use std::ffi::CString;
use std::io::{Error, Write};
use std::io::Error;
use std::iter::FromIterator;
use std::path::Path;
use std::process::Command;
static NAME: &'static str = "chroot";
static SYNTAX: &'static str = "[OPTION]... NEWROOT [COMMAND [ARG]...]";
static SUMMARY: &'static str = "Run COMMAND with root directory set to NEWROOT.";
static SYNTAX: &'static str = "[OPTION]... NEWROOT [COMMAND [ARG]...]";
static SUMMARY: &'static str = "Run COMMAND with root directory set to NEWROOT.";
static LONG_HELP: &'static str = "
If COMMAND is not specified, it defaults to '$(SHELL) -i'.
If $(SHELL) is not set, /bin/sh is used.
";
";
pub fn uumain(args: Vec<String>) -> i32 {
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* This file is part of the uutils coreutils package.
*
* (c) Arcterus <arcterus@mail.com>
* (c) Alex Lyon <arcterus@mail.com>
* (c) Michael Gehring <mg@ebfe.org>
*
* For the full copyright and license information, please view the LICENSE
+4 -4
View File
@@ -14,16 +14,16 @@
extern crate uucore;
use std::fs::File;
use std::io::{self, stdin, Read, Write, BufReader};
use std::io::{self, stdin, Read, BufReader};
#[cfg(not(windows))]
use std::mem;
use std::path::Path;
include!(concat!(env!("OUT_DIR"), "/crc_table.rs"));
static SYNTAX: &'static str = "[OPTIONS] [FILE]...";
static SUMMARY: &'static str = "Print CRC and size for each file";
static LONG_HELP: &'static str = "";
static SYNTAX: &'static str = "[OPTIONS] [FILE]...";
static SUMMARY: &'static str = "Print CRC and size for each file";
static LONG_HELP: &'static str = "";
#[inline]
fn crc_update(crc: u32, input: u8) -> u32 {
+5 -5
View File
@@ -39,7 +39,7 @@ use clap::{Arg, App, ArgMatches};
use quick_error::ResultExt;
use std::collections::HashSet;
use std::fs;
use std::io::{BufReader, BufRead, stdin, Write};
use std::io::{BufReader, BufRead, stdin, stdout, Write};
use std::io;
use std::path::{Path, PathBuf, StripPrefixError};
use std::str::FromStr;
@@ -114,9 +114,9 @@ macro_rules! or_continue(
/// answered yes.
macro_rules! prompt_yes(
($($args:tt)+) => ({
pipe_write!(&mut ::std::io::stdout(), $($args)+);
pipe_write!(&mut ::std::io::stdout(), " [y/N]: ");
pipe_flush!();
print!($($args)+);
print!(" [y/N]: ");
crash_if_err!(1, stdout().flush());
let mut s = String::new();
match BufReader::new(stdin()).read_line(&mut s) {
Ok(_) => match s.char_indices().nth(0) {
@@ -573,7 +573,7 @@ impl Options {
attributes.push(Attribute::Xattr);
attributes.push(Attribute::Links);
break;
} else {
} else {
attributes.push(Attribute::from_str(attribute_str)?);
}
}
+1 -1
View File
@@ -136,7 +136,7 @@ impl<R: Read> self::Bytes::Select for ByteReader<R> {
};
match out {
Some(out) => pipe_crash_if_err!(1, out.write_all(&buffer[0..consume_val])),
Some(out) => crash_if_err!(1, out.write_all(&buffer[0..consume_val])),
None => (),
}
(res, consume_val)
+16 -16
View File
@@ -150,7 +150,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
loop {
match buf_read.select(low - cur_pos, None::<&mut Stdout>) {
NewlineFound => {
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
continue 'newline
}
Complete(len) => {
@@ -160,7 +160,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
Partial(len) => cur_pos += len,
EndOfFile => {
if orig_pos != cur_pos {
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
break 'newline
@@ -171,7 +171,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
match opts.out_delim {
Some(ref delim) => {
if print_delim {
pipe_crash_if_err!(1, out.write_all(delim.as_bytes()));
crash_if_err!(1, out.write_all(delim.as_bytes()));
}
print_delim = true;
}
@@ -189,7 +189,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
}
EndOfFile => {
if cur_pos != low || low == high {
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
break 'newline
@@ -199,7 +199,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
}
buf_read.consume_line();
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
0
@@ -230,9 +230,9 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &[Range], delim: &str, only_
if delim_search.peek().is_none() {
if ! only_delimited {
pipe_crash_if_err!(1, out.write_all(line));
crash_if_err!(1, out.write_all(line));
if line[line.len() - 1] != newline_char {
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
}
@@ -249,14 +249,14 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &[Range], delim: &str, only_
for _ in 0..high - low + 1 {
if print_delim {
pipe_crash_if_err!(1, out.write_all(out_delim.as_bytes()));
crash_if_err!(1, out.write_all(out_delim.as_bytes()));
}
match delim_search.next() {
Some((high_idx, next_low_idx)) => {
let segment = &line[low_idx..high_idx];
pipe_crash_if_err!(1, out.write_all(segment));
crash_if_err!(1, out.write_all(segment));
print_delim = true;
@@ -266,7 +266,7 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &[Range], delim: &str, only_
None => {
let segment = &line[low_idx..];
pipe_crash_if_err!(1, out.write_all(segment));
crash_if_err!(1, out.write_all(segment));
if line[line.len() - 1] == newline_char {
continue 'newline
@@ -277,7 +277,7 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &[Range], delim: &str, only_
}
}
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
0
@@ -318,9 +318,9 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32
if delim_search.peek().is_none() {
if ! opts.only_delimited {
pipe_crash_if_err!(1, out.write_all(line));
crash_if_err!(1, out.write_all(line));
if line[line.len() - 1] != newline_char {
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
}
@@ -345,7 +345,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32
Some((high_idx, next_low_idx)) => {
let segment = &line[low_idx..high_idx];
pipe_crash_if_err!(1, out.write_all(segment));
crash_if_err!(1, out.write_all(segment));
print_delim = true;
low_idx = next_low_idx;
@@ -354,7 +354,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32
None => {
let segment = &line[low_idx..line.len()];
pipe_crash_if_err!(1, out.write_all(segment));
crash_if_err!(1, out.write_all(segment));
if line[line.len() - 1] == newline_char {
continue 'newline
@@ -364,7 +364,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32
}
}
pipe_crash_if_err!(1, out.write_all(&[newline_char]));
crash_if_err!(1, out.write_all(&[newline_char]));
}
0
+3 -4
View File
@@ -13,19 +13,18 @@ extern crate glob;
#[macro_use]
extern crate uucore;
use std::fs::File;
use std::io::{BufRead, BufReader, Write};
use std::io::{BufRead, BufReader};
use std::borrow::Borrow;
use std::env;
static SYNTAX: &'static str = "[OPTION]... [FILE]";
static SUMMARY: &'static str = "Output commands to set the LS_COLORS environment variable.";
static SUMMARY: &'static str = "Output commands to set the LS_COLORS environment variable.";
static LONG_HELP: &'static str = "
If FILE is specified, read it to determine which colors to use for which
file types and extensions. Otherwise, a precompiled database is used.
For details on the format of these files, run 'dircolors --print-database'
";
";
mod colors;
use colors::INTERNAL_DB;
+5 -5
View File
@@ -12,12 +12,12 @@
#[macro_use]
extern crate uucore;
use std::io::Write;
use std::io::{Write, stdout};
use std::str::from_utf8;
#[allow(dead_code)]
static SYNTAX: &'static str = "[OPTIONS]... [STRING]...";
static SUMMARY: &'static str = "display a line of text";
static SYNTAX: &'static str = "[OPTIONS]... [STRING]...";
static SUMMARY: &'static str = "display a line of text";
static LONG_HELP: &'static str = r#"
Echo the STRING(s) to standard output.
If -e is in effect, the following sequences are recognized:
@@ -34,7 +34,7 @@ static LONG_HELP: &'static str = r#"
\\v vertical tab
\\0NNN byte with octal value NNN (1 to 3 digits)
\\xHH byte with hexadecimal value HH (1 to 2 digits)
"#;
"#;
#[derive(Clone)]
struct EchoOptions {
@@ -173,7 +173,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
if options.newline {
pipe_flush!();
return_if_err!(1, stdout().flush())
} else {
println!("")
}
+7 -7
View File
@@ -17,15 +17,15 @@
extern crate uucore;
use std::env;
use std::io::Write;
use std::io::{Write, stdout};
use std::process::Command;
static NAME: &'static str = "env";
static SYNTAX: &'static str = "[OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
static SUMMARY: &'static str = "Set each NAME to VALUE in the environment and run COMMAND";
static NAME: &'static str = "env";
static SYNTAX: &'static str = "[OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]";
static SUMMARY: &'static str = "Set each NAME to VALUE in the environment and run COMMAND";
static LONG_HELP: &'static str = "
A mere - implies -i. If no COMMAND, print the resulting environment
";
";
struct options {
ignore_env: bool,
@@ -48,7 +48,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
core_opts.optflag("i", "ignore-environment", "start with an empty environment")
.optflag("0", "null", "end each output line with a 0 byte rather than newline")
.optopt("u", "unset", "remove variable from the environment", "NAME");
let mut opts = Box::new(options {
ignore_env: false,
null: false,
@@ -189,7 +189,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
} else {
// no program provided
print_env(opts.null);
pipe_flush!();
return_if_err!(1, stdout().flush());
}
0
-2
View File
@@ -16,8 +16,6 @@ extern crate onig;
mod tokens;
mod syntax_tree;
use std::io::{Write};
static NAME: &'static str = "expr";
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
+1 -1
View File
@@ -21,7 +21,7 @@ extern crate uucore;
use numeric::*;
use rand::distributions::{Range, IndependentSample};
use std::cmp::{max, min};
use std::io::{stdin, BufRead, BufReader, Write};
use std::io::{stdin, BufRead, BufReader};
use std::num::Wrapping;
use std::mem::swap;
+6 -6
View File
@@ -3,7 +3,7 @@
/*
* This file is part of the uutils coreutils package.
*
* (c) Arcterus <arcterus@mail.com>
* (c) Alex Lyon <arcterus@mail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -13,13 +13,13 @@
extern crate uucore;
use std::fs::File;
use std::io::{BufRead, BufReader, Read, stdin, Write};
use std::io::{BufRead, BufReader, Read, stdin};
use std::path::Path;
static SYNTAX: &'static str = "[OPTION]... [FILE]...";
static SUMMARY: &'static str = "Writes each file (or standard input if no files are given)
to standard output whilst breaking long lines";
static LONG_HELP: &'static str = "";
static SYNTAX: &'static str = "[OPTION]... [FILE]...";
static SUMMARY: &'static str = "Writes each file (or standard input if no files are given)
to standard output whilst breaking long lines";
static LONG_HELP: &'static str = "";
pub fn uumain(args: Vec<String>) -> i32 {
let (args, obs_width) = handle_obsolete(&args[..]);
-1
View File
@@ -13,7 +13,6 @@
#[macro_use]
extern crate uucore;
use uucore::entries::{Passwd, Locate, get_groups, gid2grp};
use std::io::Write;
static SYNTAX: &'static str = "[user]";
static SUMMARY: &'static str = "display current group names";
+8 -8
View File
@@ -3,7 +3,7 @@
/*
* This file is part of the uutils coreutils package.
*
* (c) Arcterus <arcterus@mail.com>
* (c) Alex Lyon <arcterus@mail.com>
* (c) Vsevolod Velichko <torkvemada@sorokdva.net>
* (c) Gil Cottle <gcottle@redtown.org>
*
@@ -34,7 +34,7 @@ use sha2::{Sha224, Sha256, Sha384, Sha512};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
use std::ascii::AsciiExt;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Read, stdin, Write};
use std::io::{self, BufRead, BufReader, Read, stdin};
use std::path::Path;
static NAME: &'static str = "hashsum";
@@ -232,7 +232,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
fn version() {
pipe_println!("{} {}", NAME, VERSION);
println!("{} {}", NAME, VERSION);
}
fn usage(program: &str, binary_name: &str, opts: &getopts::Options) {
@@ -251,7 +251,7 @@ Usage:
Compute and check message digests.", NAME, VERSION, spec);
pipe_print!("{}", opts.usage(&msg));
print!("{}", opts.usage(&msg));
}
fn hashsum(algoname: &str, mut digest: Box<Digest>, files: Vec<String>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool, output_bits: usize) -> Result<(), i32> {
@@ -325,11 +325,11 @@ fn hashsum(algoname: &str, mut digest: Box<Digest>, files: Vec<String>, binary:
.to_ascii_lowercase();
if sum == real_sum {
if !quiet {
pipe_println!("{}: OK", ck_filename);
println!("{}: OK", ck_filename);
}
} else {
if !status {
pipe_println!("{}: FAILED", ck_filename);
println!("{}: FAILED", ck_filename);
}
failed += 1;
}
@@ -337,9 +337,9 @@ fn hashsum(algoname: &str, mut digest: Box<Digest>, files: Vec<String>, binary:
} else {
let sum = safe_unwrap!(digest_reader(&mut digest, &mut file, binary, output_bits));
if tag {
pipe_println!("{} ({}) = {}", algoname, filename, sum);
println!("{} ({}) = {}", algoname, filename, sum);
} else {
pipe_println!("{} {}{}", sum, binary_marker, filename);
println!("{} {}{}", sum, binary_marker, filename);
}
}
}

Some files were not shown because too many files have changed in this diff Show More