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:
commit
c92779c03b
9 changed files with 32 additions and 32 deletions
|
@ -37,7 +37,7 @@ mod util;
|
||||||
static NAME: &'static str = "base64";
|
static NAME: &'static str = "base64";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = ~os::args();
|
let args = box os::args();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
optflag("d", "decode", "decode data"),
|
optflag("d", "decode", "decode data"),
|
||||||
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
|
optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"),
|
||||||
|
@ -78,10 +78,10 @@ fn main() {
|
||||||
None => 76
|
None => 76
|
||||||
};
|
};
|
||||||
let mut input = if matches.free.is_empty() || matches.free.get(0).as_slice() == "-" {
|
let mut input = if matches.free.is_empty() || matches.free.get(0).as_slice() == "-" {
|
||||||
~stdin() as ~Reader
|
box stdin() as Box<Reader>
|
||||||
} else {
|
} else {
|
||||||
let path = Path::new(matches.free.get(0).clone());
|
let path = Path::new(matches.free.get(0).clone());
|
||||||
~File::open(&path) as ~Reader
|
box File::open(&path) as Box<Reader>
|
||||||
};
|
};
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
|
|
|
@ -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 {
|
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())) {
|
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())
|
Err(e) => fail!("cat: {0:s}: {1:s}", path, e.to_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
env/env.rs
vendored
2
env/env.rs
vendored
|
@ -56,7 +56,7 @@ fn main() {
|
||||||
let prog = args[0].as_slice();
|
let prog = args[0].as_slice();
|
||||||
|
|
||||||
// to handle arguments the same way than GNU env, we can't use getopts
|
// 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,
|
ignore_env: false,
|
||||||
null: false,
|
null: false,
|
||||||
unsets: vec!(),
|
unsets: vec!(),
|
||||||
|
|
|
@ -98,9 +98,9 @@ fn fold(filenames: Vec<~str>, bytes: bool, spaces: bool, width: uint) {
|
||||||
let filename: &str = *filename;
|
let filename: &str = *filename;
|
||||||
let buffer = BufferedReader::new(
|
let buffer = BufferedReader::new(
|
||||||
if filename == "-".to_owned() {
|
if filename == "-".to_owned() {
|
||||||
~io::stdio::stdin_raw() as ~Reader
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
} else {
|
} 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);
|
fold_file(buffer, bytes, spaces, width);
|
||||||
|
|
|
@ -85,9 +85,9 @@ fn md5sum(files: Vec<~str>, binary: bool, check: bool, tag: bool, status: bool,
|
||||||
let filename: &str = *filename;
|
let filename: &str = *filename;
|
||||||
let mut file = BufferedReader::new(
|
let mut file = BufferedReader::new(
|
||||||
if filename == "-".to_owned() {
|
if filename == "-".to_owned() {
|
||||||
~stdin_raw() as ~Reader
|
box stdin_raw() as Box<Reader>
|
||||||
} else {
|
} else {
|
||||||
~safe_unwrap!(File::open(&Path::new(filename))) as ~Reader
|
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if check {
|
if check {
|
||||||
|
|
|
@ -57,12 +57,12 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) {
|
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(
|
io::BufferedReader::new(
|
||||||
if name == "-".to_owned() {
|
if name == "-".to_owned() {
|
||||||
~io::stdio::stdin_raw() as ~Reader
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
} else {
|
} 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();
|
).collect();
|
||||||
|
|
|
@ -73,9 +73,9 @@ fn tac(filenames: Vec<~str>, before: bool, _: bool, separator: ~str) {
|
||||||
for filename in filenames.move_iter() {
|
for filename in filenames.move_iter() {
|
||||||
let mut file = io::BufferedReader::new(
|
let mut file = io::BufferedReader::new(
|
||||||
if filename == "-".to_owned() {
|
if filename == "-".to_owned() {
|
||||||
~io::stdio::stdin_raw() as ~Reader
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
} else {
|
} 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());
|
let mut data = crash_if_err!(1, file.read_to_str());
|
||||||
|
|
26
tee/tee.rs
26
tee/tee.rs
|
@ -36,7 +36,7 @@ struct Options {
|
||||||
append: bool,
|
append: bool,
|
||||||
ignore_interrupts: bool,
|
ignore_interrupts: bool,
|
||||||
print_and_exit: Option<~str>,
|
print_and_exit: Option<~str>,
|
||||||
files: ~Vec<Path>
|
files: Box<Vec<Path>>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn options(args: &[~str]) -> Result<Options, ()> {
|
fn options(args: &[~str]) -> Result<Options, ()> {
|
||||||
|
@ -66,7 +66,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
|
||||||
append: m.opt_present("append"),
|
append: m.opt_present("append"),
|
||||||
ignore_interrupts: m.opt_present("ignore-interrupts"),
|
ignore_interrupts: m.opt_present("ignore-interrupts"),
|
||||||
print_and_exit: to_print,
|
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))
|
}).map_err(|message| warn(message))
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ fn exec(options: Options) -> Result<(), ()> {
|
||||||
fn tee(options: Options) -> Result<(), ()> {
|
fn tee(options: Options) -> Result<(), ()> {
|
||||||
let writers = options.files.iter().map(|path| open(path, options.append)).collect();
|
let writers = options.files.iter().map(|path| open(path, options.append)).collect();
|
||||||
let output = &mut MultiWriter::new(writers);
|
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() {
|
if copy(input, output).is_err() || output.flush().is_err() {
|
||||||
Err(())
|
Err(())
|
||||||
} else {
|
} 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("-") {
|
let inner = if *path == Path::new("-") {
|
||||||
~stdout() as ~Writer
|
box stdout() as Box<Writer>
|
||||||
} else {
|
} else {
|
||||||
let mode = if append { Append } else { Truncate };
|
let mode = if append { Append } else { Truncate };
|
||||||
match File::open_mode(path, mode, Write) {
|
match File::open_mode(path, mode, Write) {
|
||||||
Ok(file) => ~file as ~Writer,
|
Ok(file) => box file as Box<Writer>,
|
||||||
Err(_) => ~NullWriter as ~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 {
|
struct NamedWriter {
|
||||||
inner: ~Writer,
|
inner: Box<Writer>,
|
||||||
path: ~Path
|
path: Box<Path>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writer for NamedWriter {
|
impl Writer for NamedWriter {
|
||||||
|
@ -112,7 +112,7 @@ impl Writer for NamedWriter {
|
||||||
with_path(self.path.clone(), || {
|
with_path(self.path.clone(), || {
|
||||||
let val = self.inner.write(buf);
|
let val = self.inner.write(buf);
|
||||||
if val.is_err() {
|
if val.is_err() {
|
||||||
self.inner = ~NullWriter as ~Writer;
|
self.inner = box NullWriter as Box<Writer>;
|
||||||
}
|
}
|
||||||
val
|
val
|
||||||
})
|
})
|
||||||
|
@ -122,7 +122,7 @@ impl Writer for NamedWriter {
|
||||||
with_path(self.path.clone(), || {
|
with_path(self.path.clone(), || {
|
||||||
let val = self.inner.flush();
|
let val = self.inner.flush();
|
||||||
if val.is_err() {
|
if val.is_err() {
|
||||||
self.inner = ~NullWriter as ~Writer;
|
self.inner = box NullWriter as Box<Writer>;
|
||||||
}
|
}
|
||||||
val
|
val
|
||||||
})
|
})
|
||||||
|
@ -130,7 +130,7 @@ impl Writer for NamedWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NamedReader {
|
struct NamedReader {
|
||||||
inner: ~Reader
|
inner: Box<Reader>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reader for NamedReader {
|
impl Reader for NamedReader {
|
||||||
|
|
6
wc/wc.rs
6
wc/wc.rs
|
@ -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 {
|
if "-" == path {
|
||||||
let reader = ~stdin() as ~Reader;
|
let reader = box stdin() as Box<Reader>;
|
||||||
return Some(BufferedReader::new(reader));
|
return Some(BufferedReader::new(reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
match File::open(&std::path::Path::new(path.as_slice())) {
|
match File::open(&std::path::Path::new(path.as_slice())) {
|
||||||
Ok(fd) => {
|
Ok(fd) => {
|
||||||
let reader = ~fd as ~Reader;
|
let reader = box fd as Box<Reader>;
|
||||||
return Some(BufferedReader::new(reader));
|
return Some(BufferedReader::new(reader));
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue