1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #164 from ebfe/box-syntax

Update to box/Box<T> syntax.
This commit is contained in:
Arcterus 2014-05-08 18:56:35 -07:00
commit c92779c03b
9 changed files with 32 additions and 32 deletions

View file

@ -37,7 +37,7 @@ mod util;
static NAME: &'static str = "base64";
fn main() {
let args = ~os::args();
let args = box os::args();
let opts = ~[
optflag("d", "decode", "decode data"),
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
@ -78,10 +78,10 @@ fn main() {
None => 76
};
let mut input = if matches.free.is_empty() || matches.free.get(0).as_slice() == "-" {
~stdin() as ~Reader
box stdin() as Box<Reader>
} else {
let path = Path::new(matches.free.get(0).clone());
~File::open(&path) as ~Reader
box File::open(&path) as Box<Reader>
};
match mode {

View file

@ -175,13 +175,13 @@ pub fn exec(files: Vec<~str>, number: NumberingMode, show_nonprint: bool, show_e
}
}
fn open(path: ~str) -> Option<~Reader> {
fn open(path: ~str) -> Option<Box<Reader>> {
if "-" == path {
return Some(~stdin_raw() as ~Reader);
return Some(box stdin_raw() as Box<Reader>);
}
match File::open(&std::path::Path::new(path.as_slice())) {
Ok(fd) => return Some(~fd as ~Reader),
Ok(fd) => return Some(box fd as Box<Reader>),
Err(e) => fail!("cat: {0:s}: {1:s}", path, e.to_str())
}
}

2
env/env.rs vendored
View file

@ -56,7 +56,7 @@ fn main() {
let prog = args[0].as_slice();
// to handle arguments the same way than GNU env, we can't use getopts
let mut opts = ~options {
let mut opts = box options {
ignore_env: false,
null: false,
unsets: vec!(),

View file

@ -98,9 +98,9 @@ fn fold(filenames: Vec<~str>, bytes: bool, spaces: bool, width: uint) {
let filename: &str = *filename;
let buffer = BufferedReader::new(
if filename == "-".to_owned() {
~io::stdio::stdin_raw() as ~Reader
box io::stdio::stdin_raw() as Box<Reader>
} else {
~safe_unwrap!(File::open(&Path::new(filename))) as ~Reader
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
}
);
fold_file(buffer, bytes, spaces, width);

View file

@ -85,9 +85,9 @@ fn md5sum(files: Vec<~str>, binary: bool, check: bool, tag: bool, status: bool,
let filename: &str = *filename;
let mut file = BufferedReader::new(
if filename == "-".to_owned() {
~stdin_raw() as ~Reader
box stdin_raw() as Box<Reader>
} else {
~safe_unwrap!(File::open(&Path::new(filename))) as ~Reader
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
}
);
if check {

View file

@ -57,12 +57,12 @@ fn main() {
}
fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) {
let mut files: ~[io::BufferedReader<~Reader>] = filenames.move_iter().map(|name|
let mut files: ~[io::BufferedReader<Box<Reader>>] = filenames.move_iter().map(|name|
io::BufferedReader::new(
if name == "-".to_owned() {
~io::stdio::stdin_raw() as ~Reader
box io::stdio::stdin_raw() as Box<Reader>
} else {
~crash_if_err!(1, io::File::open(&Path::new(name))) as ~Reader
box crash_if_err!(1, io::File::open(&Path::new(name))) as Box<Reader>
}
)
).collect();

View file

@ -73,9 +73,9 @@ fn tac(filenames: Vec<~str>, before: bool, _: bool, separator: ~str) {
for filename in filenames.move_iter() {
let mut file = io::BufferedReader::new(
if filename == "-".to_owned() {
~io::stdio::stdin_raw() as ~Reader
box io::stdio::stdin_raw() as Box<Reader>
} else {
~crash_if_err!(1, io::File::open(&Path::new(filename))) as ~Reader
box crash_if_err!(1, io::File::open(&Path::new(filename))) as Box<Reader>
}
);
let mut data = crash_if_err!(1, file.read_to_str());

View file

@ -36,7 +36,7 @@ struct Options {
append: bool,
ignore_interrupts: bool,
print_and_exit: Option<~str>,
files: ~Vec<Path>
files: Box<Vec<Path>>
}
fn options(args: &[~str]) -> Result<Options, ()> {
@ -66,7 +66,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
append: m.opt_present("append"),
ignore_interrupts: m.opt_present("ignore-interrupts"),
print_and_exit: to_print,
files: ~names.iter().map(|name| Path::new(name.clone())).collect()
files: box names.iter().map(|name| Path::new(name.clone())).collect()
})
}).map_err(|message| warn(message))
}
@ -81,7 +81,7 @@ fn exec(options: Options) -> Result<(), ()> {
fn tee(options: Options) -> Result<(), ()> {
let writers = options.files.iter().map(|path| open(path, options.append)).collect();
let output = &mut MultiWriter::new(writers);
let input = &mut NamedReader { inner: ~stdin() as ~Reader };
let input = &mut NamedReader { inner: box stdin() as Box<Reader> };
if copy(input, output).is_err() || output.flush().is_err() {
Err(())
} else {
@ -89,22 +89,22 @@ fn tee(options: Options) -> Result<(), ()> {
}
}
fn open(path: &Path, append: bool) -> ~Writer {
fn open(path: &Path, append: bool) -> Box<Writer> {
let inner = if *path == Path::new("-") {
~stdout() as ~Writer
box stdout() as Box<Writer>
} else {
let mode = if append { Append } else { Truncate };
match File::open_mode(path, mode, Write) {
Ok(file) => ~file as ~Writer,
Err(_) => ~NullWriter as ~Writer
Ok(file) => box file as Box<Writer>,
Err(_) => box NullWriter as Box<Writer>
}
};
~NamedWriter { inner: inner, path: ~path.clone() } as ~Writer
box NamedWriter { inner: inner, path: box path.clone() } as Box<Writer>
}
struct NamedWriter {
inner: ~Writer,
path: ~Path
inner: Box<Writer>,
path: Box<Path>
}
impl Writer for NamedWriter {
@ -112,7 +112,7 @@ impl Writer for NamedWriter {
with_path(self.path.clone(), || {
let val = self.inner.write(buf);
if val.is_err() {
self.inner = ~NullWriter as ~Writer;
self.inner = box NullWriter as Box<Writer>;
}
val
})
@ -122,7 +122,7 @@ impl Writer for NamedWriter {
with_path(self.path.clone(), || {
let val = self.inner.flush();
if val.is_err() {
self.inner = ~NullWriter as ~Writer;
self.inner = box NullWriter as Box<Writer>;
}
val
})
@ -130,7 +130,7 @@ impl Writer for NamedWriter {
}
struct NamedReader {
inner: ~Reader
inner: Box<Reader>
}
impl Reader for NamedReader {

View file

@ -222,15 +222,15 @@ fn print_stats(filename: &~str, line_count: uint, word_count: uint, char_count:
}
}
fn open(path: ~str) -> Option<BufferedReader<~Reader>> {
fn open(path: ~str) -> Option<BufferedReader<Box<Reader>>> {
if "-" == path {
let reader = ~stdin() as ~Reader;
let reader = box stdin() as Box<Reader>;
return Some(BufferedReader::new(reader));
}
match File::open(&std::path::Path::new(path.as_slice())) {
Ok(fd) => {
let reader = ~fd as ~Reader;
let reader = box fd as Box<Reader>;
return Some(BufferedReader::new(reader));
},
Err(e) => {