Merge branch 'master' of github.com:uutils/coreutils

Conflicts:
	Makefile
This commit is contained in:
KokaKiwi 2013-10-18 14:01:11 +02:00
commit f1ca63f280
4 changed files with 31 additions and 28 deletions

View file

@ -6,6 +6,7 @@ build:
sh -c 'rustc --out-dir build/ printenv/printenv.rs' sh -c 'rustc --out-dir build/ printenv/printenv.rs'
sh -c 'rustc --out-dir build/ true/true.rs' sh -c 'rustc --out-dir build/ true/true.rs'
sh -c 'rustc --out-dir build/ yes/yes.rs' sh -c 'rustc --out-dir build/ yes/yes.rs'
sh -c 'rustc --out-dir build/ cat/cat.rs'
sh -c 'rustc --out-dir build/ whoami/whoami.rs' sh -c 'rustc --out-dir build/ whoami/whoami.rs'
.PHONY: build .PHONY: build

View file

@ -15,7 +15,7 @@ extern mod extra;
use std::os; use std::os;
use std::io::{stdin, stderr, stdout, Writer, Reader}; use std::io::{stdin, stderr, stdout, Writer, Reader};
use extra::getopts::*; use extra::getopts::groups;
fn main() { fn main() {
let args = os::args(); let args = os::args();
@ -37,12 +37,12 @@ fn main() {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
stderr().write_line("Invalid options"); stderr().write_line("Invalid options");
stderr().write_line(fail_str(f)); stderr().write_line(f.to_err_msg());
os::set_exit_status(1); os::set_exit_status(1);
return return
} }
}; };
if opts_present(&matches, [~"h", ~"help"]) { if matches.opts_present([~"h", ~"help"]) {
println("cat 1.0.0"); println("cat 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -53,22 +53,22 @@ fn main() {
println("With no FILE, or when FILE is -, read standard input."); println("With no FILE, or when FILE is -, read standard input.");
return; return;
} }
if opts_present(&matches, [~"V", ~"version"]) { if matches.opts_present([~"V", ~"version"]) {
println("cat 1.0.0"); println("cat 1.0.0");
return; return;
} }
let mut number_mode = NumberNone; let mut number_mode = NumberNone;
if opts_present(&matches, [~"n", ~"number"]) { if matches.opts_present([~"n", ~"number"]) {
number_mode = NumberAll; number_mode = NumberAll;
} }
if opts_present(&matches, [~"b", ~"number-nonblank"]) { if matches.opts_present([~"b", ~"number-nonblank"]) {
number_mode = NumberNonEmpty; number_mode = NumberNonEmpty;
} }
let show_nonprint = opts_present(&matches, [~"v", ~"show-nonprinting", ~"A", ~"show-all", ~"t", ~"e"]); let show_nonprint = matches.opts_present([~"v", ~"show-nonprinting", ~"A", ~"show-all", ~"t", ~"e"]);
let show_ends = opts_present(&matches, [~"E", ~"show-ends", ~"A", ~"show-all", ~"e"]); let show_ends = matches.opts_present([~"E", ~"show-ends", ~"A", ~"show-all", ~"e"]);
let show_tabs = opts_present(&matches, [~"T", ~"show-tabs", ~"A", ~"show-all", ~"t"]); let show_tabs = matches.opts_present([~"T", ~"show-tabs", ~"A", ~"show-all", ~"t"]);
let squeeze_blank = opts_present(&matches, [~"s", ~"squeeze-blank"]); let squeeze_blank = matches.opts_present([~"s", ~"squeeze-blank"]);
let mut files = matches.free; let mut files = matches.free;
if files.is_empty() { if files.is_empty() {
files = ~[~"-"]; files = ~[~"-"];
@ -84,15 +84,17 @@ pub enum NumberingMode {
NumberAll, NumberAll,
} }
static TAB: u8 = bytes!("\t"); static TAB: u8 = '\t' as u8;
static CR: u8 = bytes!("\r"); static CR: u8 = '\r' as u8;
static LF: u8 = bytes!("\n"); static LF: u8 = '\n' as u8;
#[cfg(windows)]
fn is_newline_char(byte: u8) -> bool { fn is_newline_char(byte: u8) -> bool {
if cfg!("windows") { byte == LF || byte == CR
return byte == LF || byte == CR }
}
#[cfg(unix)]
fn is_newline_char(byte: u8) -> bool {
byte == LF byte == LF
} }
@ -103,7 +105,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end
for path in files.iter() { for path in files.iter() {
let reader = match open(path.to_owned()) { let reader = match open(path.to_owned()) {
Some(f) => f, Some(f) => f,
None => { loop } None => { continue }
}; };
let mut counter: uint = 1; let mut counter: uint = 1;
@ -156,7 +158,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end
for path in files.iter() { for path in files.iter() {
let reader = match open(path.to_owned()) { let reader = match open(path.to_owned()) {
Some(f) => f, Some(f) => f,
None => { loop } None => { continue }
}; };
loop { loop {

View file

@ -15,7 +15,7 @@ extern mod extra;
use std::os; use std::os;
use std::io::stderr; use std::io::stderr;
use extra::getopts::*; use extra::getopts::groups;
fn main() { fn main() {
let args = os::args(); let args = os::args();
@ -29,12 +29,12 @@ fn main() {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
stderr().write_line("Invalid options"); stderr().write_line("Invalid options");
stderr().write_line(fail_str(f)); stderr().write_line(f.to_err_msg());
os::set_exit_status(1); os::set_exit_status(1);
return return
} }
}; };
if opts_present(&matches, [~"h", ~"help"]) { if matches.opts_present([~"h", ~"help"]) {
println("printenv 1.0.0"); println("printenv 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -43,12 +43,12 @@ fn main() {
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;
} }
if opts_present(&matches, [~"V", ~"version"]) { if matches.opts_present([~"V", ~"version"]) {
println("printenv 1.0.0"); println("printenv 1.0.0");
return; return;
} }
let mut separator = "\n"; let mut separator = "\n";
if opts_present(&matches, [~"0", ~"null"]) { if matches.opts_present([~"0", ~"null"]) {
separator = "\x00"; separator = "\x00";
}; };
@ -58,7 +58,7 @@ fn main() {
pub fn exec(args: ~[~str], separator: &str) { 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.consume_iter() { for (env_var, value) in vars.move_iter() {
print(fmt!("%s=%s", env_var, value)); print(fmt!("%s=%s", env_var, value));
print(separator); print(separator);
} }

View file

@ -15,7 +15,7 @@ extern mod extra;
use std::os; use std::os;
use std::io::stderr; use std::io::stderr;
use extra::getopts::*; use extra::getopts::groups;
fn main() { fn main() {
let args = os::args(); let args = os::args();
@ -28,12 +28,12 @@ fn main() {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
stderr().write_line("Invalid options"); stderr().write_line("Invalid options");
stderr().write_line(fail_str(f)); stderr().write_line(f.to_err_msg());
os::set_exit_status(1); os::set_exit_status(1);
return return
} }
}; };
if opts_present(&matches, [~"h", ~"help"]) { if matches.opts_present([~"h", ~"help"]) {
println("yes 1.0.0"); println("yes 1.0.0");
println(""); println("");
println("Usage:"); println("Usage:");
@ -42,7 +42,7 @@ fn main() {
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;
} }
if opts_present(&matches, [~"V", ~"version"]) { if matches.opts_present([~"V", ~"version"]) {
println("yes 1.0.0"); println("yes 1.0.0");
return; return;
} }