mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Update fold to nightly build.
This commit is contained in:
parent
b4c106b004
commit
dd19bc27c1
1 changed files with 19 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
#![crate_name = "fold"]
|
||||
#![feature(collections, core, old_io, old_path, rustc_private, unicode)]
|
||||
#![feature(collections, rustc_private)]
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
|
@ -13,9 +13,9 @@
|
|||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
||||
use std::old_io as io;
|
||||
use std::old_io::fs::File;
|
||||
use std::old_io::BufferedReader;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
||||
use std::path::Path;
|
||||
|
||||
#[path = "../common/util.rs"]
|
||||
#[macro_use]
|
||||
|
@ -25,7 +25,7 @@ static NAME: &'static str = "fold";
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let (args, obs_width) = handle_obsolete(args.as_slice());
|
||||
let (args, obs_width) = handle_obsolete(&args[..]);
|
||||
let program = args[0].clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
getopts::optflag("V", "version", "output version information and exit")
|
||||
];
|
||||
|
||||
let matches = match getopts::getopts(args.tail(), &opts) {
|
||||
let matches = match getopts::getopts(&args[1..], &opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "{}", f)
|
||||
};
|
||||
|
@ -82,8 +82,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
|
||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
let slice = arg.as_slice();
|
||||
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
|
||||
let slice = &arg;
|
||||
if slice.chars().next().unwrap() == '-' && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) {
|
||||
return (args[..i].to_vec() + &args[i + 1..],
|
||||
Some(slice[1..].to_string()));
|
||||
}
|
||||
|
@ -94,16 +94,16 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
|||
#[inline]
|
||||
fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: usize) {
|
||||
for filename in filenames.iter() {
|
||||
let filename: &str = filename.as_slice();
|
||||
let filename: &str = &filename;
|
||||
let mut stdin_buf;
|
||||
let mut file_buf;
|
||||
let buffer = BufferedReader::new(
|
||||
let buffer = BufReader::new(
|
||||
if filename == "-" {
|
||||
stdin_buf = io::stdio::stdin_raw();
|
||||
&mut stdin_buf as &mut Reader
|
||||
stdin_buf = stdin();
|
||||
&mut stdin_buf as &mut Read
|
||||
} else {
|
||||
file_buf = safe_unwrap!(File::open(&Path::new(filename)));
|
||||
&mut file_buf as &mut Reader
|
||||
file_buf = safe_unwrap!(File::open(Path::new(filename)));
|
||||
&mut file_buf as &mut Read
|
||||
}
|
||||
);
|
||||
fold_file(buffer, bytes, spaces, width);
|
||||
|
@ -111,11 +111,9 @@ fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: usize) {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool, width: usize) {
|
||||
let mut file = file;
|
||||
for line in file.lines() {
|
||||
let line_string = safe_unwrap!(line);
|
||||
let mut line = line_string.as_slice();
|
||||
fn fold_file<T: Read>(mut file: BufReader<T>, bytes: bool, spaces: bool, width: usize) {
|
||||
let mut line = String::new();
|
||||
while safe_unwrap!(file.read_line(&mut line)) > 0 {
|
||||
if bytes {
|
||||
let len = line.len();
|
||||
let mut i = 0;
|
||||
|
@ -143,15 +141,15 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
|||
println!("");
|
||||
continue;
|
||||
}
|
||||
line = &line[..line.len() - 1];
|
||||
len -= 1;
|
||||
line.truncate(len);
|
||||
}
|
||||
let mut output = String::new();
|
||||
let mut count = 0;
|
||||
for (i, ch) in line.chars().enumerate() {
|
||||
if count >= width {
|
||||
let (val, ncount) = {
|
||||
let slice = output.as_slice();
|
||||
let slice = &output[..];
|
||||
let (out, val, ncount) =
|
||||
if spaces && i + 1 < len {
|
||||
match rfind_whitespace(slice) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue