mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #172 from ebfe/strbuf-getopts
Update for getopts changes
This commit is contained in:
commit
85d7fe9081
36 changed files with 158 additions and 152 deletions
|
@ -36,7 +36,7 @@ mod util;
|
||||||
static NAME: &'static str = "base64";
|
static NAME: &'static str = "base64";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = box os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
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"),
|
||||||
|
@ -67,7 +67,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
let ignore_garbage = matches.opt_present("ignore-garbage");
|
let ignore_garbage = matches.opt_present("ignore-garbage");
|
||||||
let line_wrap = match matches.opt_str("wrap") {
|
let line_wrap = match matches.opt_str("wrap") {
|
||||||
Some(s) => match from_str(s) {
|
Some(s) => match from_str(s.as_slice()) {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => {
|
None => {
|
||||||
error!("error: {:s}", "Argument to option 'wrap' improperly formatted.");
|
error!("error: {:s}", "Argument to option 'wrap' improperly formatted.");
|
||||||
|
@ -86,7 +86,7 @@ fn main() {
|
||||||
match mode {
|
match mode {
|
||||||
Decode => decode(input, ignore_garbage),
|
Decode => decode(input, ignore_garbage),
|
||||||
Encode => encode(input, line_wrap),
|
Encode => encode(input, line_wrap),
|
||||||
Help => help(progname, usage),
|
Help => help(progname.as_slice(), usage.as_slice()),
|
||||||
Version => version()
|
Version => version()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,16 +139,16 @@ fn encode(input: &mut Reader, line_wrap: uint) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => fail!(f.to_str())
|
Err(f) => fail!(f.to_str())
|
||||||
};
|
};
|
||||||
let mut encoded = to_encode.as_slice().to_base64(b64_conf);
|
let encoded = to_encode.as_slice().to_base64(b64_conf);
|
||||||
|
|
||||||
// To my knowledge, RFC 3548 does not specify which line endings to use. It
|
// To my knowledge, RFC 3548 does not specify which line endings to use. It
|
||||||
// seems that rust's base64 algorithm uses CRLF as prescribed by RFC 2045.
|
// seems that rust's base64 algorithm uses CRLF as prescribed by RFC 2045.
|
||||||
// However, since GNU base64 outputs only LF (presumably because that is
|
// However, since GNU base64 outputs only LF (presumably because that is
|
||||||
// the standard UNIX line ending), we strip CRs from the output to maintain
|
// the standard UNIX line ending), we strip CRs from the output to maintain
|
||||||
// compatibility.
|
// compatibility.
|
||||||
encoded = encoded.replace("\r", "");
|
let final = encoded.replace("\r", "");
|
||||||
|
|
||||||
println(encoded);
|
println(final);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(progname: &str, usage: &str) {
|
fn help(progname: &str, usage: &str) {
|
||||||
|
|
|
@ -24,8 +24,8 @@ static NAME: &'static str = "basename";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = strip_dir(args.get(0));
|
let program = strip_dir(os::args().get(0));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Argument parsing
|
// Argument parsing
|
||||||
|
@ -46,7 +46,7 @@ fn main() {
|
||||||
println!("Print NAME with any leading directory components removed.");
|
println!("Print NAME with any leading directory components removed.");
|
||||||
println!("If specified, also remove a trailing SUFFIX.");
|
println!("If specified, also remove a trailing SUFFIX.");
|
||||||
|
|
||||||
print(getopts::usage("", opts));
|
print(getopts::usage("", opts).as_slice());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
// too many arguments
|
// too many arguments
|
||||||
else if args.len() > 3 {
|
else if args.len() > 3 {
|
||||||
println(program + ": extra operand `" + args.get(3).clone() + "'");
|
println(program + ": extra operand `" + args.get(3).as_slice() + "'");
|
||||||
println("Try `" + program + " --help' for more information.");
|
println("Try `" + program + " --help' for more information.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,11 @@ fn main() {
|
||||||
|
|
||||||
let fullname = args.get(1).clone();
|
let fullname = args.get(1).clone();
|
||||||
|
|
||||||
let mut name = strip_dir(&fullname);
|
let mut name = strip_dir(&fullname.as_slice().to_owned());
|
||||||
|
|
||||||
if args.len() > 2 {
|
if args.len() > 2 {
|
||||||
let suffix = args.get(2).clone();
|
let suffix = args.get(2).clone();
|
||||||
name = strip_suffix(&name, &suffix);
|
name = strip_suffix(&name, &suffix.to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
println(name);
|
println(name);
|
||||||
|
|
16
cat/cat.rs
16
cat/cat.rs
|
@ -20,8 +20,8 @@ use std::io::stdio::{stdout_raw, stdin_raw};
|
||||||
use std::io::{BufferedWriter};
|
use std::io::{BufferedWriter};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).as_slice();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("A", "show-all", "equivalent to -vET"),
|
getopts::optflag("A", "show-all", "equivalent to -vET"),
|
||||||
getopts::optflag("b", "number-nonblank", "number nonempty output lines, overrides -n"),
|
getopts::optflag("b", "number-nonblank", "number nonempty output lines, overrides -n"),
|
||||||
|
@ -45,7 +45,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [OPTION]... [FILE]...", program);
|
println!(" {0:s} [OPTION]... [FILE]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Concatenate FILE(s), or standard input, to standard output.", opts));
|
print(getopts::usage("Concatenate FILE(s), or standard input, to standard output.", opts).as_slice());
|
||||||
println!("");
|
println!("");
|
||||||
println!("With no FILE, or when FILE is -, read standard input.");
|
println!("With no FILE, or when FILE is -, read standard input.");
|
||||||
return;
|
return;
|
||||||
|
@ -62,13 +62,13 @@ fn main() {
|
||||||
if matches.opt_present("number-nonblank") {
|
if matches.opt_present("number-nonblank") {
|
||||||
number_mode = NumberNonEmpty;
|
number_mode = NumberNonEmpty;
|
||||||
}
|
}
|
||||||
let show_nonprint = matches.opts_present(["show-nonprinting".to_owned(), "show-all".to_owned(), "t".to_owned(), "e".to_owned()]);
|
let show_nonprint = matches.opts_present(["show-nonprinting".to_strbuf(), "show-all".to_strbuf(), "t".to_strbuf(), "e".to_strbuf()]);
|
||||||
let show_ends = matches.opts_present(["show-ends".to_owned(), "show-all".to_owned(), "e".to_owned()]);
|
let show_ends = matches.opts_present(["show-ends".to_strbuf(), "show-all".to_strbuf(), "e".to_strbuf()]);
|
||||||
let show_tabs = matches.opts_present(["show-tabs".to_owned(), "show-all".to_owned(), "t".to_owned()]);
|
let show_tabs = matches.opts_present(["show-tabs".to_strbuf(), "show-all".to_strbuf(), "t".to_strbuf()]);
|
||||||
let squeeze_blank = matches.opt_present("squeeze-blank");
|
let squeeze_blank = matches.opt_present("squeeze-blank");
|
||||||
let mut files = matches.free;
|
let mut files = matches.free;
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
files = vec!("-".to_owned());
|
files = vec!("-".to_strbuf());
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
||||||
|
@ -96,7 +96,7 @@ fn is_newline_char(byte: u8) -> bool {
|
||||||
byte == LF
|
byte == LF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(files: Vec<~str>, number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
|
pub fn exec(files: Vec<StrBuf>, number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -78,12 +78,13 @@ fn open_file(name: &str) -> IoResult<Box<Reader>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
getopts::optflag("V", "version", "output version information and exit"),
|
getopts::optflag("V", "version", "output version information and exit"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let matches = match getopts::getopts(os::args().tail(), opts) {
|
let matches = match getopts::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => fail!("{}", err.to_err_msg()),
|
Err(err) => fail!("{}", err.to_err_msg()),
|
||||||
};
|
};
|
||||||
|
@ -94,7 +95,7 @@ pub fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {} [OPTIONS] [FILE]...", NAME);
|
println!(" {} [OPTIONS] [FILE]...", NAME);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Print CRC and size for each file.", opts.as_slice()));
|
print(getopts::usage("Print CRC and size for each file.", opts.as_slice()).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for fname in files.iter() {
|
for fname in files.iter() {
|
||||||
match cksum(*fname) {
|
match cksum(fname.as_slice()) {
|
||||||
Ok((crc, size)) => println!("{} {} {}", crc, size, fname),
|
Ok((crc, size)) => println!("{} {} {}", crc, size, fname),
|
||||||
Err(err) => show_error!(2, "'{}' {}", fname, err),
|
Err(err) => show_error!(2, "'{}' {}", fname, err),
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ fn open_file(name: &str) -> IoResult<Box<Buffer>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
|
getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"),
|
||||||
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
|
getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"),
|
||||||
|
@ -89,7 +90,7 @@ pub fn main() {
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let matches = match getopts::getopts(os::args().tail(), opts) {
|
let matches = match getopts::getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => fail!("{}", err.to_err_msg()),
|
Err(err) => fail!("{}", err.to_err_msg()),
|
||||||
};
|
};
|
||||||
|
@ -100,7 +101,7 @@ pub fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
|
println!(" {} [OPTIONS] FILE1 FILE2", NAME);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Compare sorted files line by line.", opts.as_slice()));
|
print(getopts::usage("Compare sorted files line by line.", opts.as_slice()).as_slice());
|
||||||
if matches.free.len() != 2 {
|
if matches.free.len() != 2 {
|
||||||
os::set_exit_status(1);
|
os::set_exit_status(1);
|
||||||
}
|
}
|
||||||
|
@ -108,8 +109,8 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let mut f1 = open_file(matches.free.get(0).clone()).unwrap();
|
let mut f1 = open_file(matches.free.get(0).as_slice()).unwrap();
|
||||||
let mut f2 = open_file(matches.free.get(1).clone()).unwrap();
|
let mut f2 = open_file(matches.free.get(1).as_slice()).unwrap();
|
||||||
|
|
||||||
comm(&mut f1, &mut f2, &matches)
|
comm(&mut f1, &mut f2, &matches)
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,9 @@ extern {
|
||||||
pub fn getgrgid(gid: uid_t) -> *c_group;
|
pub fn getgrgid(gid: uid_t) -> *c_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pw_from_args(free: &Vec<~str>) -> Option<c_passwd> {
|
pub fn get_pw_from_args(free: &Vec<StrBuf>) -> Option<c_passwd> {
|
||||||
if free.len() == 1 {
|
if free.len() == 1 {
|
||||||
let username = free.get(0).clone();
|
let username = free.get(0).as_slice();
|
||||||
|
|
||||||
// Passed user as id
|
// Passed user as id
|
||||||
if username.chars().all(|c| c.is_digit()) {
|
if username.chars().all(|c| c.is_digit()) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ use std::io::print;
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
|
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
|
||||||
|
@ -38,7 +38,7 @@ fn main() {
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Output each NAME with its last non-slash component and trailing slashes
|
print(getopts::usage("Output each NAME with its last non-slash component and trailing slashes
|
||||||
removed; if NAME contains no /'s, output '.' (meaning the current
|
removed; if NAME contains no /'s, output '.' (meaning the current
|
||||||
directory).", opts));
|
directory).", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("n", "", "do not output the trailing newline"),
|
getopts::optflag("n", "", "do not output the trailing newline"),
|
||||||
|
@ -92,7 +92,7 @@ fn main() {
|
||||||
println!(" {0:s} [SHORT-OPTION]... [STRING]...", program);
|
println!(" {0:s} [SHORT-OPTION]... [STRING]...", program);
|
||||||
println!(" {0:s} LONG-OPTION", program);
|
println!(" {0:s} LONG-OPTION", program);
|
||||||
println!("");
|
println!("");
|
||||||
println(getopts::usage("Echo the STRING(s) to standard output.", opts));
|
println(getopts::usage("Echo the STRING(s) to standard output.", opts).as_slice());
|
||||||
println("If -e is in effect, the following sequences are recognized:
|
println("If -e is in effect, the following sequences are recognized:
|
||||||
|
|
||||||
\\\\ backslash
|
\\\\ backslash
|
||||||
|
|
16
fold/fold.rs
16
fold/fold.rs
|
@ -27,11 +27,10 @@ static NAME: &'static str = "fold";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
|
||||||
|
|
||||||
|
let (args, obs_width) = handle_obsolete(os::args().as_slice().to_owned());
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let (args, obs_width) = handle_obsolete(args.as_slice().to_owned());
|
|
||||||
|
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optflag("b", "bytes", "count using bytes rather than columns (meaning control characters such as newline are not treated specially)"),
|
getopts::optflag("b", "bytes", "count using bytes rather than columns (meaning control characters such as newline are not treated specially)"),
|
||||||
|
@ -62,7 +61,10 @@ fn main() {
|
||||||
if matches.opt_present("w") {
|
if matches.opt_present("w") {
|
||||||
matches.opt_str("w")
|
matches.opt_str("w")
|
||||||
} else {
|
} else {
|
||||||
obs_width
|
match obs_width {
|
||||||
|
Some(v) => Some(v.to_strbuf()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let width = match poss_width {
|
let width = match poss_width {
|
||||||
Some(inp_width) => match uint::parse_bytes(inp_width.as_bytes(), 10) {
|
Some(inp_width) => match uint::parse_bytes(inp_width.as_bytes(), 10) {
|
||||||
|
@ -72,7 +74,7 @@ fn main() {
|
||||||
None => 80
|
None => 80
|
||||||
};
|
};
|
||||||
let files = if matches.free.is_empty() {
|
let files = if matches.free.is_empty() {
|
||||||
vec!("-".to_owned())
|
vec!("-".to_strbuf())
|
||||||
} else {
|
} else {
|
||||||
matches.free
|
matches.free
|
||||||
};
|
};
|
||||||
|
@ -93,9 +95,9 @@ fn handle_obsolete(args: ~[~str]) -> (~[~str], Option<~str>) {
|
||||||
(args.as_slice().to_owned(), None)
|
(args.as_slice().to_owned(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold(filenames: Vec<~str>, bytes: bool, spaces: bool, width: uint) {
|
fn fold(filenames: Vec<StrBuf>, bytes: bool, spaces: bool, width: uint) {
|
||||||
for filename in filenames.iter() {
|
for filename in filenames.iter() {
|
||||||
let filename: &str = *filename;
|
let filename: &str = filename.as_slice();
|
||||||
let buffer = BufferedReader::new(
|
let buffer = BufferedReader::new(
|
||||||
if filename == "-".to_owned() {
|
if filename == "-".to_owned() {
|
||||||
box io::stdio::stdin_raw() as Box<Reader>
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
|
|
|
@ -26,7 +26,7 @@ use c_types::{get_pw_from_args, group};
|
||||||
static NAME: &'static str = "groups";
|
static NAME: &'static str = "groups";
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let options = [
|
let options = [
|
||||||
optflag("h", "", "Help")
|
optflag("h", "", "Help")
|
||||||
];
|
];
|
||||||
|
|
11
head/head.rs
11
head/head.rs
|
@ -23,24 +23,23 @@ use getopts::{optopt, optflag, getopts, usage};
|
||||||
static PROGRAM: &'static str = "head";
|
static PROGRAM: &'static str = "head";
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let args = os::args();
|
|
||||||
|
|
||||||
let options = args.tail().to_owned();
|
|
||||||
let mut line_count = 10u;
|
let mut line_count = 10u;
|
||||||
|
|
||||||
// handle obsolete -number syntax
|
// handle obsolete -number syntax
|
||||||
let options = match obsolete(options) {
|
let options = match obsolete(os::args().tail().to_owned()) {
|
||||||
(args, Some(n)) => { line_count = n; args },
|
(args, Some(n)) => { line_count = n; args },
|
||||||
(args, None) => args
|
(args, None) => args
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let args: Vec<StrBuf> = options.iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let possible_options = [
|
let possible_options = [
|
||||||
optopt("n", "number", "Number of lines to print", "n"),
|
optopt("n", "number", "Number of lines to print", "n"),
|
||||||
optflag("h", "help", "help"),
|
optflag("h", "help", "help"),
|
||||||
optflag("V", "version", "version")
|
optflag("V", "version", "version")
|
||||||
];
|
];
|
||||||
|
|
||||||
let given_options = match getopts(options, possible_options) {
|
let given_options = match getopts(args.as_slice(), possible_options) {
|
||||||
Ok (m) => { m }
|
Ok (m) => { m }
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{:s}", usage(PROGRAM, possible_options));
|
println!("{:s}", usage(PROGRAM, possible_options));
|
||||||
|
@ -56,7 +55,7 @@ fn main () {
|
||||||
|
|
||||||
match given_options.opt_str("n") {
|
match given_options.opt_str("n") {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
match from_str(n) {
|
match from_str(n.as_slice()) {
|
||||||
Some(m) => { line_count = m }
|
Some(m) => { line_count = m }
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
optflag("", "help", "display this help and exit"),
|
optflag("", "help", "display this help and exit"),
|
||||||
|
@ -63,7 +63,7 @@ fn main() {
|
||||||
let matches = match getopts(args.tail(), opts) {
|
let matches = match getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage));
|
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -78,7 +78,7 @@ fn main() {
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
HostId => hostid(),
|
HostId => hostid(),
|
||||||
Help => help(NAME, usage),
|
Help => help(NAME, usage.as_slice()),
|
||||||
Version => version(),
|
Version => version(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).to_owned();
|
let program = args.get(0).to_owned();
|
||||||
|
|
||||||
let options = [
|
let options = [
|
||||||
|
@ -59,7 +59,7 @@ fn main () {
|
||||||
|
|
||||||
println!("{:s}", hostname);
|
println!("{:s}", hostname);
|
||||||
}
|
}
|
||||||
1 => { xsethostname( matches.free.last().unwrap() ) }
|
1 => { xsethostname( &matches.free.last().unwrap().as_slice().to_owned() ) }
|
||||||
_ => { help_menu(program, options); }
|
_ => { help_menu(program, options); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
2
id/id.rs
2
id/id.rs
|
@ -88,7 +88,7 @@ extern {
|
||||||
static NAME: &'static str = "id";
|
static NAME: &'static str = "id";
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let args_t = args.tail();
|
let args_t = args.tail();
|
||||||
|
|
||||||
let options = [
|
let options = [
|
||||||
|
|
18
kill/kill.rs
18
kill/kill.rs
|
@ -54,7 +54,7 @@ pub enum Mode {
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
optflag("h", "help", "display this help and exit"),
|
optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -70,7 +70,7 @@ fn main() {
|
||||||
let matches = match getopts(args.tail(), opts) {
|
let matches = match getopts(args.tail(), opts) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage));
|
show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice()));
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -89,10 +89,10 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
Kill => kill(matches.opt_str("signal").unwrap_or("9".to_owned()), matches.free),
|
Kill => kill(matches.opt_str("signal").unwrap_or("9".to_strbuf()).as_slice(), matches.free),
|
||||||
Table => table(),
|
Table => table(),
|
||||||
List => list(matches.opt_str("list")),
|
List => list(matches.opt_str("list")),
|
||||||
Help => help(NAME, usage),
|
Help => help(NAME, usage.as_slice()),
|
||||||
Version => version(),
|
Version => version(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,9 +149,9 @@ fn print_signals() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(arg: Option<~str>) {
|
fn list(arg: Option<StrBuf>) {
|
||||||
match arg {
|
match arg {
|
||||||
Some(x) => print_signal(x),
|
Some(x) => print_signal(x.to_owned()),
|
||||||
None => print_signals(),
|
None => print_signals(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -178,14 +178,14 @@ fn signal_by_name_or_value(signal_name_or_value:~str) -> Option<uint> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill(signalname: ~str, pids: std::vec::Vec<~str>) {
|
fn kill(signalname: &str, pids: std::vec::Vec<StrBuf>) {
|
||||||
let optional_signal_value = signal_by_name_or_value(signalname.clone());
|
let optional_signal_value = signal_by_name_or_value(signalname.to_owned());
|
||||||
let signal_value = match optional_signal_value {
|
let signal_value = match optional_signal_value {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => crash!(EXIT_ERR, "unknown signal name {}", signalname)
|
None => crash!(EXIT_ERR, "unknown signal name {}", signalname)
|
||||||
};
|
};
|
||||||
for pid in pids.iter() {
|
for pid in pids.iter() {
|
||||||
match from_str::<i32>(*pid) {
|
match from_str::<i32>(pid.as_slice()) {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let result = Process::kill(x, signal_value as int);
|
let result = Process::kill(x, signal_value as int);
|
||||||
match result {
|
match result {
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -66,7 +66,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {:s}", program);
|
println!(" {:s}", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("print user's login name", opts));
|
print(getopts::usage("print user's login name", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
|
|
@ -28,7 +28,7 @@ static NAME: &'static str = "md5sum";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ fn main() {
|
||||||
let strict = matches.opt_present("strict");
|
let strict = matches.opt_present("strict");
|
||||||
let warn = matches.opt_present("warn") && !status;
|
let warn = matches.opt_present("warn") && !status;
|
||||||
let files = if matches.free.is_empty() {
|
let files = if matches.free.is_empty() {
|
||||||
vec!("-".to_owned())
|
vec!("-".to_strbuf())
|
||||||
} else {
|
} else {
|
||||||
matches.free
|
matches.free
|
||||||
};
|
};
|
||||||
|
@ -76,13 +76,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn md5sum(files: Vec<~str>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) {
|
fn md5sum(files: Vec<StrBuf>, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) {
|
||||||
let mut md5 = crypto::md5::Md5::new();
|
let mut md5 = crypto::md5::Md5::new();
|
||||||
let bytes = md5.output_bits() / 4;
|
let bytes = md5.output_bits() / 4;
|
||||||
let mut bad_format = 0;
|
let mut bad_format = 0;
|
||||||
let mut failed = 0;
|
let mut failed = 0;
|
||||||
for filename in files.iter() {
|
for filename in files.iter() {
|
||||||
let filename: &str = *filename;
|
let filename: &str = filename.as_slice();
|
||||||
let mut file = BufferedReader::new(
|
let mut file = BufferedReader::new(
|
||||||
if filename == "-".to_owned() {
|
if filename == "-".to_owned() {
|
||||||
box stdin_raw() as Box<Reader>
|
box stdin_raw() as Box<Reader>
|
||||||
|
|
|
@ -29,7 +29,7 @@ static VERSION: &'static str = "1.0.0";
|
||||||
* Handles option parsing
|
* Handles option parsing
|
||||||
*/
|
*/
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
// Linux-specific options, not implemented
|
// Linux-specific options, not implemented
|
||||||
|
@ -63,10 +63,10 @@ fn main() {
|
||||||
|
|
||||||
// Translate a ~str in octal form to u32, default to 755
|
// Translate a ~str in octal form to u32, default to 755
|
||||||
// Not tested on Windows
|
// Not tested on Windows
|
||||||
let mode_match = matches.opts_str(&["mode".to_owned()]);
|
let mode_match = matches.opts_str(&["mode".to_strbuf()]);
|
||||||
let mode: FilePermission = if mode_match.is_some() {
|
let mode: FilePermission = if mode_match.is_some() {
|
||||||
let m = mode_match.unwrap();
|
let m = mode_match.unwrap();
|
||||||
let res: Option<u32> = strconv::from_str_common(m, 8, false, false, false,
|
let res: Option<u32> = strconv::from_str_common(m.as_slice(), 8, false, false, false,
|
||||||
strconv::ExpNone,
|
strconv::ExpNone,
|
||||||
false, false);
|
false, false);
|
||||||
if res.is_some() {
|
if res.is_some() {
|
||||||
|
@ -93,7 +93,7 @@ fn print_help(opts: &[getopts::OptGroup]) {
|
||||||
/**
|
/**
|
||||||
* Create the list of new directories
|
* Create the list of new directories
|
||||||
*/
|
*/
|
||||||
fn exec(dirs: Vec<~str>, mk_parents: bool, mode: FilePermission, verbose: bool) {
|
fn exec(dirs: Vec<StrBuf>, mk_parents: bool, mode: FilePermission, verbose: bool) {
|
||||||
let mut parent_dirs = Vec::new();
|
let mut parent_dirs = Vec::new();
|
||||||
if mk_parents {
|
if mk_parents {
|
||||||
for dir in dirs.iter() {
|
for dir in dirs.iter() {
|
||||||
|
@ -103,7 +103,7 @@ fn exec(dirs: Vec<~str>, mk_parents: bool, mode: FilePermission, verbose: bool)
|
||||||
match parent {
|
match parent {
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
if !Path::new(p).exists() {
|
if !Path::new(p).exists() {
|
||||||
parent_dirs.push(p.into_owned())
|
parent_dirs.push(p.to_strbuf())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => ()
|
None => ()
|
||||||
|
|
|
@ -24,7 +24,7 @@ static NAME: &'static str = "paste";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
|
@ -50,16 +50,16 @@ fn main() {
|
||||||
let serial = matches.opt_present("serial");
|
let serial = matches.opt_present("serial");
|
||||||
let delimiters = match matches.opt_str("delimiters") {
|
let delimiters = match matches.opt_str("delimiters") {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => "\t".to_owned()
|
None => "\t".to_strbuf()
|
||||||
};
|
};
|
||||||
paste(matches.free, serial, delimiters);
|
paste(matches.free, serial, delimiters.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) {
|
fn paste(filenames: Vec<StrBuf>, serial: bool, delimiters: &str) {
|
||||||
let mut files: Vec<io::BufferedReader<Box<Reader>>> = filenames.move_iter().map(|name|
|
let mut files: Vec<io::BufferedReader<Box<Reader>>> = filenames.move_iter().map(|name|
|
||||||
io::BufferedReader::new(
|
io::BufferedReader::new(
|
||||||
if name == "-".to_owned() {
|
if name.as_slice() == "-" {
|
||||||
box io::stdio::stdin_raw() as Box<Reader>
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
} else {
|
} else {
|
||||||
box crash_if_err!(1, io::File::open(&Path::new(name))) as Box<Reader>
|
box crash_if_err!(1, io::File::open(&Path::new(name))) as Box<Reader>
|
||||||
|
|
|
@ -25,7 +25,7 @@ mod util;
|
||||||
static NAME: &'static str = "printenv";
|
static NAME: &'static str = "printenv";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [VARIABLE]... [OPTION]...", program);
|
println!(" {0:s} [VARIABLE]... [OPTION]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts));
|
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
@ -59,7 +59,7 @@ fn main() {
|
||||||
exec(matches.free, separator);
|
exec(matches.free, separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(args: Vec<~str>, separator: &str) {
|
pub fn exec(args: Vec<StrBuf>, 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() {
|
||||||
|
@ -70,7 +70,7 @@ pub fn exec(args: Vec<~str>, separator: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for env_var in args.iter() {
|
for env_var in args.iter() {
|
||||||
match os::getenv(*env_var) {
|
match os::getenv(env_var.as_slice()) {
|
||||||
Some(var) => {
|
Some(var) => {
|
||||||
print(var);
|
print(var);
|
||||||
print(separator);
|
print(separator);
|
||||||
|
|
|
@ -24,7 +24,7 @@ static NAME: &'static str = "pwd";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("", "help", "display this help and exit"),
|
getopts::optflag("", "help", "display this help and exit"),
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [OPTION] NAME...", program);
|
println!(" {0:s} [OPTION] NAME...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Print the full filename of the current working directory.", opts));
|
print(getopts::usage("Print the full filename of the current working directory.", opts).as_slice());
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
return println!("pwd version: {}", VERSION);
|
return println!("pwd version: {}", VERSION);
|
||||||
} else {
|
} else {
|
||||||
|
|
27
rm/rm.rs
27
rm/rm.rs
|
@ -30,7 +30,7 @@ enum InteractiveMode {
|
||||||
static NAME: &'static str = "rm";
|
static NAME: &'static str = "rm";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
// TODO: make getopts support -R in addition to -r
|
// TODO: make getopts support -R in addition to -r
|
||||||
|
@ -60,7 +60,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [OPTION]... [FILE]...", program);
|
println!(" {0:s} [OPTION]... [FILE]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Remove (unlink) the FILE(s).", opts));
|
print(getopts::usage("Remove (unlink) the FILE(s).", opts).as_slice());
|
||||||
println!("");
|
println!("");
|
||||||
println!("By default, rm does not remove directories. Use the --recursive (-r)");
|
println!("By default, rm does not remove directories. Use the --recursive (-r)");
|
||||||
println!("option to remove each listed directory, too, along with all of its contents");
|
println!("option to remove each listed directory, too, along with all of its contents");
|
||||||
|
@ -120,37 +120,38 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement one-file-system
|
// TODO: implement one-file-system
|
||||||
fn remove(files: Vec<~str>, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) {
|
fn remove(files: Vec<StrBuf>, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) {
|
||||||
for filename in files.iter() {
|
for filename in files.iter() {
|
||||||
let file = Path::new(filename.to_owned());
|
let filename = filename.as_slice();
|
||||||
|
let file = Path::new(filename);
|
||||||
if file.exists() {
|
if file.exists() {
|
||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
if recursive && (*filename != "/".to_owned() || !preserve_root) {
|
if recursive && (filename != "/" || !preserve_root) {
|
||||||
let walk_dir = match fs::walk_dir(&file) {
|
let walk_dir = match fs::walk_dir(&file) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "{}", f.to_str());
|
crash!(1, "{}", f.to_str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
remove(walk_dir.map(|x| x.as_str().unwrap().to_owned()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
|
remove(walk_dir.map(|x| x.as_str().unwrap().to_strbuf()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
|
||||||
remove_dir(&file, *filename, interactive, verbose);
|
remove_dir(&file, filename, interactive, verbose);
|
||||||
} else if dir && (*filename != "/".to_owned() || !preserve_root) {
|
} else if dir && (filename != "/" || !preserve_root) {
|
||||||
remove_dir(&file, *filename, interactive, verbose);
|
remove_dir(&file, filename, interactive, verbose);
|
||||||
} else {
|
} else {
|
||||||
if recursive {
|
if recursive {
|
||||||
show_error!(1, "could not remove directory '{}'",
|
show_error!(1, "could not remove directory '{}'",
|
||||||
*filename);
|
filename);
|
||||||
} else {
|
} else {
|
||||||
show_error!(1,
|
show_error!(1,
|
||||||
"could not remove directory '{}' (did you mean to pass '-r'?)",
|
"could not remove directory '{}' (did you mean to pass '-r'?)",
|
||||||
*filename);
|
filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
remove_file(&file, *filename, interactive, verbose);
|
remove_file(&file, filename.as_slice(), interactive, verbose);
|
||||||
}
|
}
|
||||||
} else if !force {
|
} else if !force {
|
||||||
show_error!(1, "no such file or directory '{}'", *filename);
|
show_error!(1, "no such file or directory '{}'", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod util;
|
||||||
static NAME: &'static str = "rmdir";
|
static NAME: &'static str = "rmdir";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
|
@ -47,7 +47,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [OPTION]... DIRECTORY...", program);
|
println!(" {0:s} [OPTION]... DIRECTORY...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Remove the DIRECTORY(ies), if they are empty.", opts));
|
print(getopts::usage("Remove the DIRECTORY(ies), if they are empty.", opts).as_slice());
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("rmdir 1.0.0");
|
println!("rmdir 1.0.0");
|
||||||
} else if matches.free.is_empty() {
|
} else if matches.free.is_empty() {
|
||||||
|
@ -61,12 +61,12 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove(dirs: Vec<~str>, ignore: bool, parents: bool, verbose: bool) {
|
fn remove(dirs: Vec<StrBuf>, ignore: bool, parents: bool, verbose: bool) {
|
||||||
for dir in dirs.iter() {
|
for dir in dirs.iter() {
|
||||||
let path = Path::new(dir.to_owned());
|
let path = Path::new(dir.as_slice());
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
remove_dir(&path, dir, ignore, parents, verbose);
|
remove_dir(&path, dir.as_slice(), ignore, parents, verbose);
|
||||||
} else {
|
} else {
|
||||||
show_error!(1, "failed to remove '{}' (file)", *dir);
|
show_error!(1, "failed to remove '{}' (file)", *dir);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ fn remove(dirs: Vec<~str>, ignore: bool, parents: bool, verbose: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_dir(path: &Path, dir: &~str, ignore: bool, parents: bool, verbose: bool) {
|
fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) {
|
||||||
let mut walk_dir = match fs::walk_dir(path) {
|
let mut walk_dir = match fs::walk_dir(path) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
|
@ -88,12 +88,12 @@ fn remove_dir(path: &Path, dir: &~str, ignore: bool, parents: bool, verbose: boo
|
||||||
match fs::rmdir(path) {
|
match fs::rmdir(path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if verbose {
|
if verbose {
|
||||||
println!("Removed directory '{}'", *dir);
|
println!("Removed directory '{}'", dir);
|
||||||
}
|
}
|
||||||
if parents {
|
if parents {
|
||||||
let dirname = path.dirname_str().unwrap();
|
let dirname = path.dirname_str().unwrap();
|
||||||
if dirname != "." {
|
if dirname != "." {
|
||||||
remove_dir(&Path::new(dirname), &dirname.to_owned(), ignore, parents, verbose);
|
remove_dir(&Path::new(dirname), dirname, ignore, parents, verbose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ fn remove_dir(path: &Path, dir: &~str, ignore: bool, parents: bool, verbose: boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !ignore {
|
} else if !ignore {
|
||||||
show_error!(1, "Failed to remove directory '{}' (non-empty)", *dir);
|
show_error!(1, "Failed to remove directory '{}' (non-empty)", dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn escape_sequences(s: &str) -> ~str {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""),
|
||||||
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""),
|
||||||
|
@ -83,8 +83,8 @@ fn main() {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!(1, "{:s}", s); return; }
|
Err(s) => { show_error!(1, "{:s}", s); return; }
|
||||||
};
|
};
|
||||||
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_owned()));
|
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_strbuf()).as_slice());
|
||||||
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.clone()));
|
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_strbuf()).as_slice());
|
||||||
print_seq(first, step, last, separator, terminator, matches.opt_present("w"));
|
print_seq(first, step, last, separator, terminator, matches.opt_present("w"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ mod util;
|
||||||
static NAME: &'static str = "sleep";
|
static NAME: &'static str = "sleep";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
|
@ -51,7 +51,7 @@ fn main() {
|
||||||
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
|
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
|
||||||
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
|
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
|
||||||
point number. Given two or more arguments, pause for the amount of time
|
point number. Given two or more arguments, pause for the amount of time
|
||||||
specified by the sum of their values.", opts));
|
specified by the sum of their values.", opts).as_slice());
|
||||||
} else if matches.opt_present("version") {
|
} else if matches.opt_present("version") {
|
||||||
println!("sleep 1.0.0");
|
println!("sleep 1.0.0");
|
||||||
} else if matches.free.is_empty() {
|
} else if matches.free.is_empty() {
|
||||||
|
@ -62,9 +62,9 @@ specified by the sum of their values.", opts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sleep(args: Vec<~str>) {
|
fn sleep(args: Vec<StrBuf>) {
|
||||||
let sleep_time = args.iter().fold(0.0, |result, arg| {
|
let sleep_time = args.iter().fold(0.0, |result, arg| {
|
||||||
let (arg, suffix_time) = match match_suffix(arg) {
|
let (arg, suffix_time) = match match_suffix(arg.as_slice()) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
crash!(1, "{}", f)
|
crash!(1, "{}", f)
|
||||||
|
@ -86,19 +86,19 @@ fn sleep(args: Vec<~str>) {
|
||||||
timer::sleep((sleep_time * 1000.0) as u64);
|
timer::sleep((sleep_time * 1000.0) as u64);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn match_suffix(arg: &~str) -> Result<(~str, int), ~str> {
|
fn match_suffix(arg: &str) -> Result<(~str, int), ~str> {
|
||||||
let result = match (*arg).char_at_reverse(0) {
|
let result = match (arg).char_at_reverse(0) {
|
||||||
's' | 'S' => 1,
|
's' | 'S' => 1,
|
||||||
'm' | 'M' => 60,
|
'm' | 'M' => 60,
|
||||||
'h' | 'H' => 60 * 60,
|
'h' | 'H' => 60 * 60,
|
||||||
'd' | 'D' => 60 * 60 * 24,
|
'd' | 'D' => 60 * 60 * 24,
|
||||||
val => {
|
val => {
|
||||||
if !val.is_alphabetic() {
|
if !val.is_alphabetic() {
|
||||||
return Ok(((*arg).clone(), 1))
|
return Ok(((arg).to_owned(), 1))
|
||||||
} else {
|
} else {
|
||||||
return Err(format!("Invalid time interval '{}'", arg))
|
return Err(format!("Invalid time interval '{}'", arg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(((*arg).slice_to((*arg).len() - 1).to_owned(), result))
|
Ok(((arg).slice_to((arg).len() - 1).to_owned(), result))
|
||||||
}
|
}
|
||||||
|
|
12
tac/tac.rs
12
tac/tac.rs
|
@ -24,7 +24,7 @@ static NAME: &'static str = "tac";
|
||||||
static VERSION: &'static str = "1.0.0";
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
|
@ -58,21 +58,21 @@ fn main() {
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => "\n".to_owned()
|
None => "\n".to_strbuf()
|
||||||
};
|
};
|
||||||
let files = if matches.free.is_empty() {
|
let files = if matches.free.is_empty() {
|
||||||
vec!("-".to_owned())
|
vec!("-".to_strbuf())
|
||||||
} else {
|
} else {
|
||||||
matches.free
|
matches.free
|
||||||
};
|
};
|
||||||
tac(files, before, regex, separator);
|
tac(files, before, regex, separator.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tac(filenames: Vec<~str>, before: bool, _: bool, separator: ~str) {
|
fn tac(filenames: Vec<StrBuf>, 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.as_slice() == "-" {
|
||||||
box io::stdio::stdin_raw() as Box<Reader>
|
box io::stdio::stdin_raw() as Box<Reader>
|
||||||
} else {
|
} else {
|
||||||
box crash_if_err!(1, io::File::open(&Path::new(filename))) as Box<Reader>
|
box crash_if_err!(1, io::File::open(&Path::new(filename))) as Box<Reader>
|
||||||
|
|
10
tee/tee.rs
10
tee/tee.rs
|
@ -47,9 +47,11 @@ fn options(args: &[~str]) -> Result<Options, ()> {
|
||||||
optflag("V", "version", "output version information and exit"),
|
optflag("V", "version", "output version information and exit"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let args: Vec<StrBuf> = args.iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| {
|
getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| {
|
||||||
let version = format!("{} {}", NAME, VERSION);
|
let version = format!("{} {}", NAME, VERSION);
|
||||||
let program = args[0].clone();
|
let program = args.get(0).as_slice();
|
||||||
let arguments = "[OPTION]... [FILE]...";
|
let arguments = "[OPTION]... [FILE]...";
|
||||||
let brief = "Copy standard input to each FILE, and also to standard " +
|
let brief = "Copy standard input to each FILE, and also to standard " +
|
||||||
"output.";
|
"output.";
|
||||||
|
@ -57,18 +59,18 @@ fn options(args: &[~str]) -> Result<Options, ()> {
|
||||||
let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}",
|
let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}",
|
||||||
version, program, arguments, usage(brief, opts),
|
version, program, arguments, usage(brief, opts),
|
||||||
comment);
|
comment);
|
||||||
let names = m.free.clone().move_iter().collect::<Vec<~str>>().append_one("-".to_owned()).as_slice().to_owned();
|
let names = m.free.clone().move_iter().collect::<Vec<StrBuf>>().append_one("-".to_strbuf());
|
||||||
let to_print = if m.opt_present("help") { Some(help) }
|
let to_print = if m.opt_present("help") { Some(help) }
|
||||||
else if m.opt_present("version") { Some(version) }
|
else if m.opt_present("version") { Some(version) }
|
||||||
else { None };
|
else { None };
|
||||||
Ok(Options {
|
Ok(Options {
|
||||||
program: program,
|
program: program.into_owned(),
|
||||||
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: box 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.as_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(options: Options) -> Result<(), ()> {
|
fn exec(options: Options) -> Result<(), ()> {
|
||||||
|
|
|
@ -47,7 +47,7 @@ enum TruncateMode {
|
||||||
static NAME: &'static str = "truncate";
|
static NAME: &'static str = "truncate";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
|
@ -108,7 +108,7 @@ file based on its current size:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str>, filenames: Vec<~str>) {
|
fn truncate(no_create: bool, _: bool, reference: Option<StrBuf>, size: Option<StrBuf>, filenames: Vec<StrBuf>) {
|
||||||
let (refsize, mode) = match reference {
|
let (refsize, mode) = match reference {
|
||||||
Some(rfilename) => {
|
Some(rfilename) => {
|
||||||
let rfile = match File::open(&Path::new(rfilename.clone())) {
|
let rfile = match File::open(&Path::new(rfilename.clone())) {
|
||||||
|
@ -119,10 +119,10 @@ fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str
|
||||||
};
|
};
|
||||||
(get_file_size!(rfile, return), Reference)
|
(get_file_size!(rfile, return), Reference)
|
||||||
}
|
}
|
||||||
None => parse_size(size.unwrap())
|
None => parse_size(size.unwrap().as_slice())
|
||||||
};
|
};
|
||||||
for filename in filenames.iter() {
|
for filename in filenames.iter() {
|
||||||
let filename: &str = *filename;
|
let filename = filename.as_slice();
|
||||||
let path = Path::new(filename);
|
let path = Path::new(filename);
|
||||||
if path.exists() || !no_create {
|
if path.exists() || !no_create {
|
||||||
match File::open_mode(&path, Open, ReadWrite) {
|
match File::open_mode(&path, Open, ReadWrite) {
|
||||||
|
@ -152,7 +152,7 @@ fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_size(size: ~str) -> (u64, TruncateMode) {
|
fn parse_size(size: &str) -> (u64, TruncateMode) {
|
||||||
let mode = match size.char_at(0) {
|
let mode = match size.char_at(0) {
|
||||||
'+' => Extend,
|
'+' => Extend,
|
||||||
'-' => Reduce,
|
'-' => Reduce,
|
||||||
|
|
|
@ -35,7 +35,7 @@ extern {
|
||||||
static NAME: &'static str = "tty";
|
static NAME: &'static str = "tty";
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
|
|
||||||
let options = [
|
let options = [
|
||||||
optflag("s", "silent", "print nothing, only return an exit status")
|
optflag("s", "silent", "print nothing, only return an exit status")
|
||||||
|
@ -46,7 +46,7 @@ fn main () {
|
||||||
m.opt_present("s")
|
m.opt_present("s")
|
||||||
},
|
},
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
println(f.to_err_msg());
|
println(f.to_err_msg().as_slice());
|
||||||
usage();
|
usage();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ unsafe fn getuname() -> utsrust {
|
||||||
static NAME: &'static str = "uname";
|
static NAME: &'static str = "uname";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).as_slice();
|
let program = args.get(0).as_slice();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -74,13 +74,13 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {:s}", program);
|
println!(" {:s}", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("The uname utility writes symbols representing one or more system characteristics to the standard output.", opts));
|
print(getopts::usage("The uname utility writes symbols representing one or more system characteristics to the standard output.", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let uname = unsafe { getuname() };
|
let uname = unsafe { getuname() };
|
||||||
let mut output = StrBuf::new();
|
let mut output = StrBuf::new();
|
||||||
if matches.opt_present("sysname") || matches.opt_present("all")
|
if matches.opt_present("sysname") || matches.opt_present("all")
|
||||||
|| !matches.opts_present(["nodename".to_owned(), "release".to_owned(), "version".to_owned(), "machine".to_owned()]) {
|
|| !matches.opts_present(["nodename".to_strbuf(), "release".to_strbuf(), "version".to_strbuf(), "machine".to_strbuf()]) {
|
||||||
output.push_str(uname.sysname);
|
output.push_str(uname.sysname);
|
||||||
output.push_str(" ");
|
output.push_str(" ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ mod util;
|
||||||
static NAME: &'static str = "unlink";
|
static NAME: &'static str = "unlink";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -47,7 +47,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [FILE]... [OPTION]...", program);
|
println!(" {0:s} [FILE]... [OPTION]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Unlink the file at [FILE].", opts));
|
print(getopts::usage("Unlink the file at [FILE].", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("v", "version", "output version information and exit"),
|
getopts::optflag("v", "version", "output version information and exit"),
|
||||||
|
@ -68,7 +68,7 @@ fn main() {
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Print the current time, the length of time the system has been up,\n\
|
print(getopts::usage("Print the current time, the length of time the system has been up,\n\
|
||||||
the number of users on the system, and the average number of jobs\n\
|
the number of users on the system, and the average number of jobs\n\
|
||||||
in the run queue over the last 1, 5 and 15 minutes.", opts));
|
in the run queue over the last 1, 5 and 15 minutes.", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern {
|
||||||
static NAME: &'static str = "users";
|
static NAME: &'static str = "users";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).as_slice();
|
let program = args.get(0).as_slice();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -66,7 +66,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {:s} [OPTION]... [FILE]", program);
|
println!(" {:s} [OPTION]... [FILE]", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Output who is currently logged in according to FILE.", opts));
|
print(getopts::usage("Output who is currently logged in according to FILE.", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
wc/wc.rs
10
wc/wc.rs
|
@ -34,7 +34,7 @@ struct Result {
|
||||||
static NAME: &'static str = "wc";
|
static NAME: &'static str = "wc";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("c", "bytes", "print the byte counts"),
|
getopts::optflag("c", "bytes", "print the byte counts"),
|
||||||
|
@ -57,7 +57,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [OPTION]... [FILE]...", program);
|
println!(" {0:s} [OPTION]... [FILE]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Print newline, word and byte counts for each FILE", opts));
|
print(getopts::usage("Print newline, word and byte counts for each FILE", opts).as_slice());
|
||||||
println!("");
|
println!("");
|
||||||
println!("With no FILE, or when FILE is -, read standard input.");
|
println!("With no FILE, or when FILE is -, read standard input.");
|
||||||
return;
|
return;
|
||||||
|
@ -70,7 +70,7 @@ fn main() {
|
||||||
|
|
||||||
let mut files = matches.free.clone();
|
let mut files = matches.free.clone();
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
files = vec!("-".to_owned());
|
files = vec!("-".to_strbuf());
|
||||||
}
|
}
|
||||||
|
|
||||||
wc(files, &matches);
|
wc(files, &matches);
|
||||||
|
@ -87,7 +87,7 @@ fn is_word_seperator(byte: u8) -> bool {
|
||||||
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
|
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wc(files: Vec<~str>, matches: &Matches) {
|
pub fn wc(files: Vec<StrBuf>, matches: &Matches) {
|
||||||
let mut total_line_count: uint = 0;
|
let mut total_line_count: uint = 0;
|
||||||
let mut total_word_count: uint = 0;
|
let mut total_word_count: uint = 0;
|
||||||
let mut total_char_count: uint = 0;
|
let mut total_char_count: uint = 0;
|
||||||
|
@ -155,7 +155,7 @@ pub fn wc(files: Vec<~str>, matches: &Matches) {
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(Result {
|
results.push(Result {
|
||||||
filename: path.clone(),
|
filename: path.as_slice().to_owned(),
|
||||||
bytes: byte_count,
|
bytes: byte_count,
|
||||||
chars: char_count,
|
chars: char_count,
|
||||||
lines: line_count,
|
lines: line_count,
|
||||||
|
|
|
@ -42,7 +42,7 @@ unsafe fn getusername() -> ~str {
|
||||||
static NAME: &'static str = "whoami";
|
static NAME: &'static str = "whoami";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).as_slice();
|
let program = args.get(0).as_slice();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -58,7 +58,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {:s}", program);
|
println!(" {:s}", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("print effective userid", opts));
|
print(getopts::usage("print effective userid", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
|
|
@ -25,7 +25,7 @@ mod util;
|
||||||
static NAME: &'static str = "yes";
|
static NAME: &'static str = "yes";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = os::args();
|
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect();
|
||||||
let program = args.get(0).clone();
|
let program = args.get(0).clone();
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
|
@ -43,7 +43,7 @@ fn main() {
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
println!(" {0:s} [STRING]... [OPTION]...", program);
|
println!(" {0:s} [STRING]... [OPTION]...", program);
|
||||||
println!("");
|
println!("");
|
||||||
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts));
|
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts).as_slice());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
if matches.opt_present("version") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue