Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ install:
pip3 install $SPHINX_VERSIONED
fi

before_script:
- rustup component add rustfmt

script:
# Check style
- cargo fmt --all -- --check
# Build
- cargo build $CARGO_ARGS --features "$FEATURES"
# Run tests
- if [ ! $REDOX ]; then cargo test $CARGO_ARGS --features "$FEATURES" --no-fail-fast; fi
- if [ -n "$TEST_INSTALL" ]; then mkdir installdir_test; DESTDIR=installdir_test make install; [ `ls installdir_test/usr/local/bin | wc -l` -gt 0 ]; fi

Expand Down
25 changes: 15 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn main() {
if val == "1" && key.starts_with(feature_prefix) {
let krate = key[feature_prefix.len()..].to_lowercase();
match krate.as_ref() {
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic" | "windows"
| "nightly" | "test_unimplemented" => continue,
"default" | "unix" | "redox" | "redox_generic" | "fuchsia" | "generic"
| "windows" | "nightly" | "test_unimplemented" => continue,
_ => {}
}
crates.push(krate.to_string());
Expand All @@ -35,7 +35,8 @@ pub fn main() {
fn util_map() -> UtilityMap {
let mut map: UtilityMap = HashMap::new();\n"
.as_bytes(),
).unwrap();
)
.unwrap();

for krate in crates {
cf.write_all(format!("extern crate uu_{krate};\n", krate = krate).as_bytes())
Expand All @@ -59,14 +60,18 @@ pub fn main() {
map.insert(\"shake128sum\", uu_hashsum::uumain);
map.insert(\"shake256sum\", uu_hashsum::uumain);\n"
.as_bytes(),
).unwrap();
)
.unwrap();
}
_ => mf.write_all(
format!(
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
krate = krate
).as_bytes(),
).unwrap(),
_ => mf
.write_all(
format!(
"map.insert(\"{krate}\", uu_{krate}::uumain);\n",
krate = krate
)
.as_bytes(),
)
.unwrap(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion mkmain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::io::Write;
use std::fs::File;
use std::io::Write;
use std::path::Path;

static TEMPLATE: &'static str = "\
Expand Down
3 changes: 1 addition & 2 deletions src/base32/base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use uucore::encoding::Format;
mod base_common;

static SYNTAX: &str = "[OPTION]... [FILE]";
static SUMMARY: &str =
"Base32 encode or decode FILE, or standard input, to standard output.";
static SUMMARY: &str = "Base32 encode or decode FILE, or standard input, to standard output.";
static LONG_HELP: &str = "
With no FILE, or when FILE is -, read standard input.

Expand Down
3 changes: 1 addition & 2 deletions src/base64/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use uucore::encoding::Format;
mod base_common;

static SYNTAX: &str = "[OPTION]... [FILE]";
static SUMMARY: &str =
"Base64 encode or decode FILE, or standard input, to standard output.";
static SUMMARY: &str = "Base64 encode or decode FILE, or standard input, to standard output.";
static LONG_HELP: &str = "
With no FILE, or when FILE is -, read standard input.

Expand Down
25 changes: 14 additions & 11 deletions src/base64/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ pub fn execute(
"COLS",
)
.parse(args);

let line_wrap = matches.opt_str("wrap").map(|s| {
match s.parse() {
Ok(n) => n,
Err(e) => {
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
}

let line_wrap = matches.opt_str("wrap").map(|s| match s.parse() {
Ok(n) => n,
Err(e) => {
crash!(1, "invalid wrap size: ‘{}’: {}", s, e);
}
});
let ignore_garbage = matches.opt_present("ignore-garbage");
Expand All @@ -55,7 +53,13 @@ pub fn execute(

if matches.free.is_empty() || &matches.free[0][..] == "-" {
let stdin_raw = stdin();
handle_input(&mut stdin_raw.lock(), format, line_wrap, ignore_garbage, decode);
handle_input(
&mut stdin_raw.lock(),
format,
line_wrap,
ignore_garbage,
decode,
);
} else {
let path = Path::new(matches.free[0].as_str());
let file_buf = safe_unwrap!(File::open(&path));
Expand All @@ -73,8 +77,7 @@ fn handle_input<R: Read>(
ignore_garbage: bool,
decode: bool,
) {
let mut data = Data::new(input, format)
.ignore_garbage(ignore_garbage);
let mut data = Data::new(input, format).ignore_garbage(ignore_garbage);
if let Some(wrap) = line_wrap {
data = data.line_wrap(wrap);
}
Expand All @@ -88,4 +91,4 @@ fn handle_input<R: Read>(
Err(_) => crash!(1, "invalid input"),
}
}
}
}
18 changes: 6 additions & 12 deletions src/basename/basename.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#![crate_name = "uu_basename"]

/*
* This file is part of the uutils coreutils package.
*
* (c) Jimmy Lu <jimmy.lu.2011@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// This file is part of the uutils coreutils package.
//
// (c) Jimmy Lu <jimmy.lu.2011@gmail.com>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#[macro_use]
extern crate uucore;
Expand All @@ -21,9 +19,7 @@ static SUMMARY: &str = "Print NAME with any leading directory components removed
static LONG_HELP: &str = "";

pub fn uumain(args: Vec<String>) -> i32 {
//
// Argument parsing
//
let matches = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP)
.optflag(
"a",
Expand Down Expand Up @@ -74,9 +70,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
"".to_owned()
};

//
// Main Program Processing
//

let paths = if multiple_paths {
&matches.free[..]
Expand Down
54 changes: 25 additions & 29 deletions src/cat/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
files.push("-".to_owned());
}

let can_write_fast = !(show_tabs || show_nonprint || show_ends || squeeze_blank
let can_write_fast = !(show_tabs
|| show_nonprint
|| show_ends
|| squeeze_blank
|| number_mode != NumberingMode::NumberNone);

let success = if can_write_fast {
Expand All @@ -190,7 +193,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
write_lines(files, &options).is_ok()
};

if success { 0 } else { 1 }
if success {
0
} else {
1
}
}

/// Classifies the `InputType` of file at `path` if possible
Expand All @@ -205,25 +212,13 @@ fn get_input_type(path: &str) -> CatResult<InputType> {

match metadata(path).context(path)?.file_type() {
#[cfg(unix)]
ft if ft.is_block_device() =>
{
Ok(InputType::BlockDevice)
}
ft if ft.is_block_device() => Ok(InputType::BlockDevice),
#[cfg(unix)]
ft if ft.is_char_device() =>
{
Ok(InputType::CharacterDevice)
}
ft if ft.is_char_device() => Ok(InputType::CharacterDevice),
#[cfg(unix)]
ft if ft.is_fifo() =>
{
Ok(InputType::Fifo)
}
ft if ft.is_fifo() => Ok(InputType::Fifo),
#[cfg(unix)]
ft if ft.is_socket() =>
{
Ok(InputType::Socket)
}
ft if ft.is_socket() => Ok(InputType::Socket),
ft if ft.is_dir() => Ok(InputType::Directory),
ft if ft.is_file() => Ok(InputType::File),
ft if ft.is_symlink() => Ok(InputType::SymLink),
Expand Down Expand Up @@ -282,12 +277,14 @@ fn write_fast(files: Vec<String>) -> CatResult<()> {

for file in files {
match open(&file[..]) {
Ok(mut handle) => while let Ok(n) = handle.reader.read(&mut in_buf) {
if n == 0 {
break;
Ok(mut handle) => {
while let Ok(n) = handle.reader.read(&mut in_buf) {
if n == 0 {
break;
}
writer.write_all(&in_buf[..n]).context(&file[..])?;
}
writer.write_all(&in_buf[..n]).context(&file[..])?;
},
}
Err(error) => {
writeln!(&mut stderr(), "{}", error)?;
error_count += 1;
Expand Down Expand Up @@ -404,7 +401,8 @@ fn write_file_lines(file: &str, options: &OutputOptions, state: &mut OutputState

// write***_to_end methods
// Write all symbols till end of line or end of buffer is reached
// Return the (number of written symbols + 1) or 0 if the end of buffer is reached
// Return the (number of written symbols + 1) or 0 if the end of buffer is
// reached
fn write_to_end<W: Write>(in_buf: &[u8], writer: &mut W) -> usize {
match in_buf.iter().position(|c| *c == b'\n') {
Some(p) => {
Expand All @@ -421,10 +419,7 @@ fn write_to_end<W: Write>(in_buf: &[u8], writer: &mut W) -> usize {
fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
let mut count = 0;
loop {
match in_buf
.iter()
.position(|c| *c == b'\n' || *c == b'\t')
{
match in_buf.iter().position(|c| *c == b'\n' || *c == b'\t') {
Some(p) => {
writer.write_all(&in_buf[..p]).unwrap();
if in_buf[p] == b'\n' {
Expand Down Expand Up @@ -458,7 +453,8 @@ fn write_nonprint_to_end<W: Write>(in_buf: &[u8], writer: &mut W, tab: &[u8]) ->
128...159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]),
160...254 => writer.write_all(&[b'M', b'-', byte - 128]),
_ => writer.write_all(&[b'M', b'-', b'^', 63]),
}.unwrap();
}
.unwrap();
count += 1;
}
if count != in_buf.len() {
Expand Down
8 changes: 4 additions & 4 deletions src/chgrp/chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

#[macro_use]
extern crate uucore;
use uucore::libc::{self, gid_t, lchown};
pub use uucore::entries;
use uucore::fs::resolve_relative_path;
use uucore::libc::{self, gid_t, lchown};

extern crate walkdir;
use walkdir::WalkDir;

use std::io::Result as IOResult;
use std::io::Error as IOError;
use std::io::Result as IOResult;

use std::fs;
use std::fs::Metadata;
Expand Down Expand Up @@ -183,12 +183,12 @@ struct Chgrper {
}

macro_rules! unwrap {
($m:expr, $e:ident, $err:block) => (
($m:expr, $e:ident, $err:block) => {
match $m {
Ok(meta) => meta,
Err($e) => $err,
}
)
};
}

impl Chgrper {
Expand Down
Loading