mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Update main utils for language changes.
This commit is contained in:
parent
a501bade88
commit
c4fab4cf67
4 changed files with 64 additions and 57 deletions
49
cat/cat.rs
49
cat/cat.rs
|
@ -15,7 +15,7 @@
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::io::{stdin, stderr, stdout, Writer, Reader};
|
use std::rt::io::{stdin, stderr, stdout, File, result};
|
||||||
use extra::getopts::groups;
|
use extra::getopts::groups;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -37,8 +37,8 @@ fn main() {
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
stderr().write_line("Invalid options");
|
writeln!(&mut stderr() as &mut Writer,
|
||||||
stderr().write_line(f.to_err_msg());
|
"Invalid options\n{}", f.to_err_msg());
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ fn main() {
|
||||||
println("cat 1.0.0");
|
println("cat 1.0.0");
|
||||||
println("");
|
println("");
|
||||||
println("Usage:");
|
println("Usage:");
|
||||||
println(format!(" {0:s} [OPTION]... [FILE]...", program));
|
println!(" {0:s} [OPTION]... [FILE]...", program);
|
||||||
println("");
|
println("");
|
||||||
print(groups::usage("Concatenate FILE(s), or standard input, to standard output.", opts));
|
print(groups::usage("Concatenate FILE(s), or standard input, to standard output.", opts));
|
||||||
println("");
|
println("");
|
||||||
|
@ -100,24 +100,28 @@ fn is_newline_char(byte: u8) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
|
pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
|
||||||
let writer = stdout();
|
let mut writer = stdout();
|
||||||
|
|
||||||
if NumberNone != number || show_nonprint || show_ends || show_tabs || squeeze_blank {
|
if NumberNone != number || show_nonprint || show_ends || show_tabs || squeeze_blank {
|
||||||
let mut counter: uint = 1;
|
let mut counter: uint = 1;
|
||||||
let is_numbering = number == NumberAll || number == NumberNonEmpty;
|
let is_numbering = number == NumberAll || number == NumberNonEmpty;
|
||||||
|
|
||||||
for path in files.iter() {
|
for path in files.iter() {
|
||||||
let reader = match open(path.to_owned()) {
|
let mut reader = match open(path.to_owned()) {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => { continue }
|
None => { continue }
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut at_line_start = true;
|
let mut at_line_start = true;
|
||||||
|
let mut buf = [0, .. 2];
|
||||||
loop {
|
loop {
|
||||||
let buf = reader.read_bytes(2);
|
// reading from a TTY seems to raise a condition on
|
||||||
for byte in buf.iter() {
|
// EOF, rather than return Some(0) like a file.
|
||||||
|
match result(|| reader.read(buf)) {
|
||||||
|
Ok(Some(n)) if n != 0 => {
|
||||||
|
for byte in buf.slice_to(n).iter() {
|
||||||
if at_line_start && (number == NumberAll || (number == NumberNonEmpty && !is_newline_char(*byte))) {
|
if at_line_start && (number == NumberAll || (number == NumberNonEmpty && !is_newline_char(*byte))) {
|
||||||
writer.write_str(format!("{0:6u}\t", counter));
|
write!(&mut writer as &mut Writer, "{0:6u}\t", counter);
|
||||||
counter += 1;
|
counter += 1;
|
||||||
at_line_start = false;
|
at_line_start = false;
|
||||||
}
|
}
|
||||||
|
@ -145,9 +149,8 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end
|
||||||
writer.write([*byte]);
|
writer.write([*byte]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if reader.eof() {
|
_ => break
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,31 +158,35 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut buf = [0, .. 100000];
|
||||||
// passthru mode
|
// passthru mode
|
||||||
for path in files.iter() {
|
for path in files.iter() {
|
||||||
let reader = match open(path.to_owned()) {
|
let mut reader = match open(path.to_owned()) {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => { continue }
|
None => { continue }
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
writer.write(reader.read_bytes(100000));
|
// reading from a TTY seems to raise a condition on EOF,
|
||||||
if reader.eof() {
|
// rather than return Some(0) like a file.
|
||||||
break;
|
match result(|| reader.read(buf)) {
|
||||||
|
Ok(Some(n)) if n != 0 => writer.write(buf.slice_to(n)),
|
||||||
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(path: ~str) -> Option<@Reader> {
|
fn open(path: ~str) -> Option<~Reader> {
|
||||||
if "-" == path {
|
if "-" == path {
|
||||||
return Some(stdin());
|
return Some(~stdin() as ~Reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
match std::io::file_reader(&std::path::Path::new(path.as_slice())) {
|
match result(|| File::open(&std::path::Path::new(path.as_slice()))) {
|
||||||
Ok(fd) => return Some(fd),
|
Ok(fd) => return Some(~fd as ~Reader),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
stderr().write_line(format!("cat: {0:s}: {1:s}", path, e));
|
writeln!(&mut stderr() as &mut Writer,
|
||||||
|
"cat: {0:s}: {1:s}", path, e.to_str());
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::io::stderr;
|
use std::rt::io::stderr;
|
||||||
use extra::getopts::groups;
|
use extra::getopts::groups;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -28,8 +28,8 @@ fn main() {
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
stderr().write_line("Invalid options");
|
writeln!(&mut stderr() as &mut Writer,
|
||||||
stderr().write_line(f.to_err_msg());
|
"Invalid options\n{}", f.to_err_msg());
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ fn main() {
|
||||||
println("printenv 1.0.0");
|
println("printenv 1.0.0");
|
||||||
println("");
|
println("");
|
||||||
println("Usage:");
|
println("Usage:");
|
||||||
println(format!(" {0:s} [VARIABLE]... [OPTION]...", program));
|
println!(" {0:s} [VARIABLE]... [OPTION]...", program);
|
||||||
println("");
|
println("");
|
||||||
print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts));
|
print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts));
|
||||||
return;
|
return;
|
||||||
|
@ -59,7 +59,7 @@ pub fn exec(args: ~[~str], separator: &str) {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
let vars = os::env();
|
let vars = os::env();
|
||||||
for (env_var, value) in vars.move_iter() {
|
for (env_var, value) in vars.move_iter() {
|
||||||
print(format!("{0:s}={1:s}", env_var, value));
|
print!("{0:s}={1:s}", env_var, value);
|
||||||
print(separator);
|
print(separator);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn main() {
|
||||||
];
|
];
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => fail2!(f.to_err_msg()),
|
Err(f) => fail!(f.to_err_msg()),
|
||||||
};
|
};
|
||||||
if matches.opt_present("help") {
|
if matches.opt_present("help") {
|
||||||
println("whoami 1.0.0");
|
println("whoami 1.0.0");
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::io::stderr;
|
use std::rt::io::stderr;
|
||||||
use extra::getopts::groups;
|
use extra::getopts::groups;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -27,8 +27,8 @@ fn main() {
|
||||||
let matches = match groups::getopts(args.tail(), opts) {
|
let matches = match groups::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
stderr().write_line("Invalid options");
|
writeln!(&mut stderr() as &mut Writer,
|
||||||
stderr().write_line(f.to_err_msg());
|
"Invalid options\n{}", f.to_err_msg());
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ fn main() {
|
||||||
println("yes 1.0.0");
|
println("yes 1.0.0");
|
||||||
println("");
|
println("");
|
||||||
println("Usage:");
|
println("Usage:");
|
||||||
println(format!(" {0:s} [STRING]... [OPTION]...", program));
|
println!(" {0:s} [STRING]... [OPTION]...", program);
|
||||||
println("");
|
println("");
|
||||||
print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts));
|
print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts));
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue