From 577e4baef929c87520f36821c65e99ca375b2836 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Sat, 17 May 2014 12:32:14 +0200 Subject: [PATCH] Update for getopts changes --- base64/base64.rs | 12 ++++++------ basename/basename.rs | 12 ++++++------ cat/cat.rs | 16 ++++++++-------- cksum/cksum.rs | 7 ++++--- comm/comm.rs | 9 +++++---- common/c_types.rs | 4 ++-- dirname/dirname.rs | 4 ++-- echo/echo.rs | 4 ++-- fold/fold.rs | 16 +++++++++------- groups/groups.rs | 2 +- head/head.rs | 11 +++++------ hostid/hostid.rs | 6 +++--- hostname/hostname.rs | 4 ++-- id/id.rs | 2 +- kill/kill.rs | 18 +++++++++--------- logname/logname.rs | 4 ++-- md5sum/md5sum.rs | 8 ++++---- mkdir/mkdir.rs | 10 +++++----- paste/paste.rs | 10 +++++----- printenv/printenv.rs | 8 ++++---- pwd/pwd.rs | 4 ++-- rm/rm.rs | 27 ++++++++++++++------------- rmdir/rmdir.rs | 18 +++++++++--------- seq/seq.rs | 6 +++--- sleep/sleep.rs | 16 ++++++++-------- tac/tac.rs | 12 ++++++------ tee/tee.rs | 10 ++++++---- truncate/truncate.rs | 10 +++++----- tty/tty.rs | 4 ++-- uname/uname.rs | 6 +++--- unlink/unlink.rs | 4 ++-- uptime/uptime.rs | 4 ++-- users/users.rs | 4 ++-- wc/wc.rs | 10 +++++----- whoami/whoami.rs | 4 ++-- yes/yes.rs | 4 ++-- 36 files changed, 158 insertions(+), 152 deletions(-) diff --git a/base64/base64.rs b/base64/base64.rs index 55ee21b50..b1898e4d8 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -36,7 +36,7 @@ mod util; static NAME: &'static str = "base64"; fn main() { - let args = box os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = ~[ optflag("d", "decode", "decode data"), 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 line_wrap = match matches.opt_str("wrap") { - Some(s) => match from_str(s) { + Some(s) => match from_str(s.as_slice()) { Some(s) => s, None => { error!("error: {:s}", "Argument to option 'wrap' improperly formatted."); @@ -86,7 +86,7 @@ fn main() { match mode { Decode => decode(input, ignore_garbage), Encode => encode(input, line_wrap), - Help => help(progname, usage), + Help => help(progname.as_slice(), usage.as_slice()), Version => version() } } @@ -139,16 +139,16 @@ fn encode(input: &mut Reader, line_wrap: uint) { Ok(m) => m, 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 // seems that rust's base64 algorithm uses CRLF as prescribed by RFC 2045. // However, since GNU base64 outputs only LF (presumably because that is // the standard UNIX line ending), we strip CRs from the output to maintain // compatibility. - encoded = encoded.replace("\r", ""); + let final = encoded.replace("\r", ""); - println(encoded); + println(final); } fn help(progname: &str, usage: &str) { diff --git a/basename/basename.rs b/basename/basename.rs index b82dc037d..58a5a3a15 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -24,8 +24,8 @@ static NAME: &'static str = "basename"; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); - let program = strip_dir(args.get(0)); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); + let program = strip_dir(os::args().get(0)); // // Argument parsing @@ -46,7 +46,7 @@ fn main() { println!("Print NAME with any leading directory components removed."); println!("If specified, also remove a trailing SUFFIX."); - print(getopts::usage("", opts)); + print(getopts::usage("", opts).as_slice()); return; } @@ -64,7 +64,7 @@ fn main() { } // too many arguments 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."); return; } @@ -75,11 +75,11 @@ fn main() { 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 { let suffix = args.get(2).clone(); - name = strip_suffix(&name, &suffix); + name = strip_suffix(&name, &suffix.to_owned()); } println(name); diff --git a/cat/cat.rs b/cat/cat.rs index 758929fb9..2ae2d4c36 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -20,8 +20,8 @@ use std::io::stdio::{stdout_raw, stdin_raw}; use std::io::{BufferedWriter}; fn main() { - let args = os::args(); - let program = args.get(0).clone(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); + let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("A", "show-all", "equivalent to -vET"), getopts::optflag("b", "number-nonblank", "number nonempty output lines, overrides -n"), @@ -45,7 +45,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [OPTION]... [FILE]...", program); 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!("With no FILE, or when FILE is -, read standard input."); return; @@ -62,13 +62,13 @@ fn main() { if matches.opt_present("number-nonblank") { 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_ends = matches.opts_present(["show-ends".to_owned(), "show-all".to_owned(), "e".to_owned()]); - let show_tabs = matches.opts_present(["show-tabs".to_owned(), "show-all".to_owned(), "t".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_strbuf(), "show-all".to_strbuf(), "e".to_strbuf()]); + 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 mut files = matches.free; if files.is_empty() { - files = vec!("-".to_owned()); + files = vec!("-".to_strbuf()); } 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 } -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, 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 { let mut counter: uint = 1; diff --git a/cksum/cksum.rs b/cksum/cksum.rs index 56be7d88f..259d0eaee 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -78,12 +78,13 @@ fn open_file(name: &str) -> IoResult> { } pub fn main() { + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = [ getopts::optflag("h", "help", "display this help 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, Err(err) => fail!("{}", err.to_err_msg()), }; @@ -94,7 +95,7 @@ pub fn main() { println!("Usage:"); println!(" {} [OPTIONS] [FILE]...", NAME); 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; } @@ -114,7 +115,7 @@ pub fn main() { } for fname in files.iter() { - match cksum(*fname) { + match cksum(fname.as_slice()) { Ok((crc, size)) => println!("{} {} {}", crc, size, fname), Err(err) => show_error!(2, "'{}' {}", fname, err), } diff --git a/comm/comm.rs b/comm/comm.rs index 3d6223677..8e4bfcdab 100644 --- a/comm/comm.rs +++ b/comm/comm.rs @@ -82,6 +82,7 @@ fn open_file(name: &str) -> IoResult> { } pub fn main() { + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = [ getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"), 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"), ]; - let matches = match getopts::getopts(os::args().tail(), opts) { + let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(err) => fail!("{}", err.to_err_msg()), }; @@ -100,7 +101,7 @@ pub fn main() { println!("Usage:"); println!(" {} [OPTIONS] FILE1 FILE2", NAME); 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 { 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 f2 = open_file(matches.free.get(1).clone()).unwrap(); + let mut f1 = open_file(matches.free.get(0).as_slice()).unwrap(); + let mut f2 = open_file(matches.free.get(1).as_slice()).unwrap(); comm(&mut f1, &mut f2, &matches) } diff --git a/common/c_types.rs b/common/c_types.rs index 3a30e6c1e..d96999ba9 100644 --- a/common/c_types.rs +++ b/common/c_types.rs @@ -73,9 +73,9 @@ extern { pub fn getgrgid(gid: uid_t) -> *c_group; } -pub fn get_pw_from_args(free: &Vec<~str>) -> Option { +pub fn get_pw_from_args(free: &Vec) -> Option { if free.len() == 1 { - let username = free.get(0).clone(); + let username = free.get(0).as_slice(); // Passed user as id if username.chars().all(|c| c.is_digit()) { diff --git a/dirname/dirname.rs b/dirname/dirname.rs index f3bbdc2b8..0afdde371 100644 --- a/dirname/dirname.rs +++ b/dirname/dirname.rs @@ -17,7 +17,7 @@ use std::io::print; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("z", "zero", "separate output with NUL rather than newline"), @@ -38,7 +38,7 @@ fn main() { println!(""); 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 -directory).", opts)); +directory).", opts).as_slice()); return; } diff --git a/echo/echo.rs b/echo/echo.rs index d93ff303a..6486fbf36 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -70,7 +70,7 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) { } fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ 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} LONG-OPTION", program); 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: \\\\ backslash diff --git a/fold/fold.rs b/fold/fold.rs index 187f3754e..9f40063ea 100644 --- a/fold/fold.rs +++ b/fold/fold.rs @@ -27,11 +27,10 @@ static NAME: &'static str = "fold"; static VERSION: &'static str = "1.0.0"; 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 (args, obs_width) = handle_obsolete(args.as_slice().to_owned()); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = [ 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") { matches.opt_str("w") } else { - obs_width + match obs_width { + Some(v) => Some(v.to_strbuf()), + None => None, + } }; let width = match poss_width { Some(inp_width) => match uint::parse_bytes(inp_width.as_bytes(), 10) { @@ -72,7 +74,7 @@ fn main() { None => 80 }; let files = if matches.free.is_empty() { - vec!("-".to_owned()) + vec!("-".to_strbuf()) } else { matches.free }; @@ -93,9 +95,9 @@ fn handle_obsolete(args: ~[~str]) -> (~[~str], Option<~str>) { (args.as_slice().to_owned(), None) } -fn fold(filenames: Vec<~str>, bytes: bool, spaces: bool, width: uint) { +fn fold(filenames: Vec, bytes: bool, spaces: bool, width: uint) { for filename in filenames.iter() { - let filename: &str = *filename; + let filename: &str = filename.as_slice(); let buffer = BufferedReader::new( if filename == "-".to_owned() { box io::stdio::stdin_raw() as Box diff --git a/groups/groups.rs b/groups/groups.rs index d46ac19d1..d267cf252 100644 --- a/groups/groups.rs +++ b/groups/groups.rs @@ -26,7 +26,7 @@ use c_types::{get_pw_from_args, group}; static NAME: &'static str = "groups"; fn main () { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let options = [ optflag("h", "", "Help") ]; diff --git a/head/head.rs b/head/head.rs index f54d109a3..27fd08911 100644 --- a/head/head.rs +++ b/head/head.rs @@ -23,24 +23,23 @@ use getopts::{optopt, optflag, getopts, usage}; static PROGRAM: &'static str = "head"; fn main () { - let args = os::args(); - - let options = args.tail().to_owned(); let mut line_count = 10u; // 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, None) => args }; + let args: Vec = options.iter().map(|x| x.to_strbuf()).collect(); + let possible_options = [ optopt("n", "number", "Number of lines to print", "n"), optflag("h", "help", "help"), 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 } Err(_) => { println!("{:s}", usage(PROGRAM, possible_options)); @@ -56,7 +55,7 @@ fn main () { match given_options.opt_str("n") { Some(n) => { - match from_str(n) { + match from_str(n.as_slice()) { Some(m) => { line_count = m } None => {} } diff --git a/hostid/hostid.rs b/hostid/hostid.rs index 19f891b7d..f616ef622 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -50,7 +50,7 @@ extern { } fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = ~[ optflag("", "help", "display this help and exit"), @@ -63,7 +63,7 @@ fn main() { let matches = match getopts(args.tail(), opts) { Ok(m) => m, 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 }, }; @@ -78,7 +78,7 @@ fn main() { match mode { HostId => hostid(), - Help => help(NAME, usage), + Help => help(NAME, usage.as_slice()), Version => version(), } } diff --git a/hostname/hostname.rs b/hostname/hostname.rs index 60e975d6b..3292e4a2b 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -24,7 +24,7 @@ extern { } fn main () { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).to_owned(); let options = [ @@ -59,7 +59,7 @@ fn main () { println!("{:s}", hostname); } - 1 => { xsethostname( matches.free.last().unwrap() ) } + 1 => { xsethostname( &matches.free.last().unwrap().as_slice().to_owned() ) } _ => { help_menu(program, options); } }; } diff --git a/id/id.rs b/id/id.rs index a19815c79..b9e79b790 100644 --- a/id/id.rs +++ b/id/id.rs @@ -88,7 +88,7 @@ extern { static NAME: &'static str = "id"; fn main () { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let args_t = args.tail(); let options = [ diff --git a/kill/kill.rs b/kill/kill.rs index 189f29985..076f61edc 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -54,7 +54,7 @@ pub enum Mode { fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = ~[ optflag("h", "help", "display this help and exit"), @@ -70,7 +70,7 @@ fn main() { let matches = match getopts(args.tail(), opts) { Ok(m) => m, 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 }, }; @@ -89,10 +89,10 @@ fn main() { }; 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(), List => list(matches.opt_str("list")), - Help => help(NAME, usage), + Help => help(NAME, usage.as_slice()), Version => version(), } } @@ -149,9 +149,9 @@ fn print_signals() { } } -fn list(arg: Option<~str>) { +fn list(arg: Option) { match arg { - Some(x) => print_signal(x), + Some(x) => print_signal(x.to_owned()), None => print_signals(), }; } @@ -178,14 +178,14 @@ fn signal_by_name_or_value(signal_name_or_value:~str) -> Option { return None; } -fn kill(signalname: ~str, pids: std::vec::Vec<~str>) { - let optional_signal_value = signal_by_name_or_value(signalname.clone()); +fn kill(signalname: &str, pids: std::vec::Vec) { + let optional_signal_value = signal_by_name_or_value(signalname.to_owned()); let signal_value = match optional_signal_value { Some(x) => x, None => crash!(EXIT_ERR, "unknown signal name {}", signalname) }; for pid in pids.iter() { - match from_str::(*pid) { + match from_str::(pid.as_slice()) { Some(x) => { let result = Process::kill(x, signal_value as int); match result { diff --git a/logname/logname.rs b/logname/logname.rs index 243a8d790..8bbf7a908 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -44,7 +44,7 @@ fn version() { } fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); // @@ -66,7 +66,7 @@ fn main() { println!("Usage:"); println!(" {:s}", program); println!(""); - print(getopts::usage("print user's login name", opts)); + print(getopts::usage("print user's login name", opts).as_slice()); return; } if matches.opt_present("version") { diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index 438886750..fce9218da 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -28,7 +28,7 @@ static NAME: &'static str = "md5sum"; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); @@ -68,7 +68,7 @@ fn main() { let strict = matches.opt_present("strict"); let warn = matches.opt_present("warn") && !status; let files = if matches.free.is_empty() { - vec!("-".to_owned()) + vec!("-".to_strbuf()) } else { 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, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) { let mut md5 = crypto::md5::Md5::new(); let bytes = md5.output_bits() / 4; let mut bad_format = 0; let mut failed = 0; for filename in files.iter() { - let filename: &str = *filename; + let filename: &str = filename.as_slice(); let mut file = BufferedReader::new( if filename == "-".to_owned() { box stdin_raw() as Box diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 264a64ccb..81d12f4b4 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -29,7 +29,7 @@ static VERSION: &'static str = "1.0.0"; * Handles option parsing */ fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = ~[ // Linux-specific options, not implemented @@ -63,10 +63,10 @@ fn main() { // Translate a ~str in octal form to u32, default to 755 // 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 m = mode_match.unwrap(); - let res: Option = strconv::from_str_common(m, 8, false, false, false, + let res: Option = strconv::from_str_common(m.as_slice(), 8, false, false, false, strconv::ExpNone, false, false); if res.is_some() { @@ -93,7 +93,7 @@ fn print_help(opts: &[getopts::OptGroup]) { /** * Create the list of new directories */ -fn exec(dirs: Vec<~str>, mk_parents: bool, mode: FilePermission, verbose: bool) { +fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool) { let mut parent_dirs = Vec::new(); if mk_parents { for dir in dirs.iter() { @@ -103,7 +103,7 @@ fn exec(dirs: Vec<~str>, mk_parents: bool, mode: FilePermission, verbose: bool) match parent { Some(p) => { if !Path::new(p).exists() { - parent_dirs.push(p.into_owned()) + parent_dirs.push(p.to_strbuf()) } }, None => () diff --git a/paste/paste.rs b/paste/paste.rs index 2f72013f0..e20aea39f 100644 --- a/paste/paste.rs +++ b/paste/paste.rs @@ -24,7 +24,7 @@ static NAME: &'static str = "paste"; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ @@ -50,16 +50,16 @@ fn main() { let serial = matches.opt_present("serial"); let delimiters = match matches.opt_str("delimiters") { 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, serial: bool, delimiters: &str) { let mut files: Vec>> = filenames.move_iter().map(|name| io::BufferedReader::new( - if name == "-".to_owned() { + if name.as_slice() == "-" { box io::stdio::stdin_raw() as Box } else { box crash_if_err!(1, io::File::open(&Path::new(name))) as Box diff --git a/printenv/printenv.rs b/printenv/printenv.rs index b5c87d73b..92a4770ae 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -25,7 +25,7 @@ mod util; static NAME: &'static str = "printenv"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"), @@ -44,7 +44,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [VARIABLE]... [OPTION]...", program); 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; } if matches.opt_present("version") { @@ -59,7 +59,7 @@ fn main() { exec(matches.free, separator); } -pub fn exec(args: Vec<~str>, separator: &str) { +pub fn exec(args: Vec, separator: &str) { if args.is_empty() { let vars = os::env(); 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() { - match os::getenv(*env_var) { + match os::getenv(env_var.as_slice()) { Some(var) => { print(var); print(separator); diff --git a/pwd/pwd.rs b/pwd/pwd.rs index 4ca5cc016..c8182828b 100644 --- a/pwd/pwd.rs +++ b/pwd/pwd.rs @@ -24,7 +24,7 @@ static NAME: &'static str = "pwd"; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("", "help", "display this help and exit"), @@ -44,7 +44,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [OPTION] NAME...", program); 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") { return println!("pwd version: {}", VERSION); } else { diff --git a/rm/rm.rs b/rm/rm.rs index 3ce712abb..1d7286efa 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -30,7 +30,7 @@ enum InteractiveMode { static NAME: &'static str = "rm"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); // TODO: make getopts support -R in addition to -r @@ -60,7 +60,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [OPTION]... [FILE]...", program); println!(""); - print(getopts::usage("Remove (unlink) the FILE(s).", opts)); + print(getopts::usage("Remove (unlink) the FILE(s).", opts).as_slice()); println!(""); 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"); @@ -120,37 +120,38 @@ fn main() { } // 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, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) { 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.is_dir() { - if recursive && (*filename != "/".to_owned() || !preserve_root) { + if recursive && (filename != "/" || !preserve_root) { let walk_dir = match fs::walk_dir(&file) { Ok(m) => m, Err(f) => { 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_dir(&file, *filename, interactive, verbose); - } else if dir && (*filename != "/".to_owned() || !preserve_root) { - remove_dir(&file, *filename, interactive, 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); + } else if dir && (filename != "/" || !preserve_root) { + remove_dir(&file, filename, interactive, verbose); } else { if recursive { show_error!(1, "could not remove directory '{}'", - *filename); + filename); } else { show_error!(1, "could not remove directory '{}' (did you mean to pass '-r'?)", - *filename); + filename); } } } else { - remove_file(&file, *filename, interactive, verbose); + remove_file(&file, filename.as_slice(), interactive, verbose); } } else if !force { - show_error!(1, "no such file or directory '{}'", *filename); + show_error!(1, "no such file or directory '{}'", filename); } } } diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index b4dfc3a36..0fdccaebb 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -23,7 +23,7 @@ mod util; static NAME: &'static str = "rmdir"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ @@ -47,7 +47,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [OPTION]... DIRECTORY...", program); 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") { println!("rmdir 1.0.0"); } 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, ignore: bool, parents: bool, verbose: bool) { for dir in dirs.iter() { - let path = Path::new(dir.to_owned()); + let path = Path::new(dir.as_slice()); if path.exists() { if path.is_dir() { - remove_dir(&path, dir, ignore, parents, verbose); + remove_dir(&path, dir.as_slice(), ignore, parents, verbose); } else { 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) { Ok(m) => m, Err(f) => { @@ -88,12 +88,12 @@ fn remove_dir(path: &Path, dir: &~str, ignore: bool, parents: bool, verbose: boo match fs::rmdir(path) { Ok(_) => { if verbose { - println!("Removed directory '{}'", *dir); + println!("Removed directory '{}'", dir); } if parents { let dirname = path.dirname_str().unwrap(); 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 { - show_error!(1, "Failed to remove directory '{}' (non-empty)", *dir); + show_error!(1, "Failed to remove directory '{}' (non-empty)", dir); } } diff --git a/seq/seq.rs b/seq/seq.rs index c079c4e0b..cf7918bea 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -34,7 +34,7 @@ fn escape_sequences(s: &str) -> ~str { } fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let opts = ~[ getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""), getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""), @@ -83,8 +83,8 @@ fn main() { Ok(n) => n, Err(s) => { show_error!(1, "{:s}", s); return; } }; - let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_owned())); - let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.clone())); + 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.to_strbuf()).as_slice()); print_seq(first, step, last, separator, terminator, matches.opt_present("w")); } diff --git a/sleep/sleep.rs b/sleep/sleep.rs index cdf5c7ddb..27e26c80a 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -24,7 +24,7 @@ mod util; static NAME: &'static str = "sleep"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ @@ -51,7 +51,7 @@ fn main() { '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 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") { println!("sleep 1.0.0"); } 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) { 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, Err(f) => { crash!(1, "{}", f) @@ -86,19 +86,19 @@ fn sleep(args: Vec<~str>) { timer::sleep((sleep_time * 1000.0) as u64); } -fn match_suffix(arg: &~str) -> Result<(~str, int), ~str> { - let result = match (*arg).char_at_reverse(0) { +fn match_suffix(arg: &str) -> Result<(~str, int), ~str> { + let result = match (arg).char_at_reverse(0) { 's' | 'S' => 1, 'm' | 'M' => 60, 'h' | 'H' => 60 * 60, 'd' | 'D' => 60 * 60 * 24, val => { if !val.is_alphabetic() { - return Ok(((*arg).clone(), 1)) + return Ok(((arg).to_owned(), 1)) } else { 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)) } diff --git a/tac/tac.rs b/tac/tac.rs index 22e1abe96..2e6dacc76 100644 --- a/tac/tac.rs +++ b/tac/tac.rs @@ -24,7 +24,7 @@ static NAME: &'static str = "tac"; static VERSION: &'static str = "1.0.0"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ @@ -58,21 +58,21 @@ fn main() { m } } - None => "\n".to_owned() + None => "\n".to_strbuf() }; let files = if matches.free.is_empty() { - vec!("-".to_owned()) + vec!("-".to_strbuf()) } else { 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, before: bool, _: bool, separator: &str) { for filename in filenames.move_iter() { let mut file = io::BufferedReader::new( - if filename == "-".to_owned() { + if filename.as_slice() == "-" { box io::stdio::stdin_raw() as Box } else { box crash_if_err!(1, io::File::open(&Path::new(filename))) as Box diff --git a/tee/tee.rs b/tee/tee.rs index a2339e72b..731fbe26b 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -47,9 +47,11 @@ fn options(args: &[~str]) -> Result { optflag("V", "version", "output version information and exit"), ]; + let args: Vec = args.iter().map(|x| x.to_strbuf()).collect(); + getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| { let version = format!("{} {}", NAME, VERSION); - let program = args[0].clone(); + let program = args.get(0).as_slice(); let arguments = "[OPTION]... [FILE]..."; let brief = "Copy standard input to each FILE, and also to standard " + "output."; @@ -57,18 +59,18 @@ fn options(args: &[~str]) -> Result { let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}", version, program, arguments, usage(brief, opts), comment); - let names = m.free.clone().move_iter().collect::>().append_one("-".to_owned()).as_slice().to_owned(); + let names = m.free.clone().move_iter().collect::>().append_one("-".to_strbuf()); let to_print = if m.opt_present("help") { Some(help) } else if m.opt_present("version") { Some(version) } else { None }; Ok(Options { - program: program, + program: program.into_owned(), append: m.opt_present("append"), ignore_interrupts: m.opt_present("ignore-interrupts"), print_and_exit: to_print, 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<(), ()> { diff --git a/truncate/truncate.rs b/truncate/truncate.rs index 74c88dbb7..039af2fb8 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -47,7 +47,7 @@ enum TruncateMode { static NAME: &'static str = "truncate"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); 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, size: Option, filenames: Vec) { let (refsize, mode) = match reference { Some(rfilename) => { 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) } - None => parse_size(size.unwrap()) + None => parse_size(size.unwrap().as_slice()) }; for filename in filenames.iter() { - let filename: &str = *filename; + let filename = filename.as_slice(); let path = Path::new(filename); if path.exists() || !no_create { 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) { '+' => Extend, '-' => Reduce, diff --git a/tty/tty.rs b/tty/tty.rs index f781b4fba..cd482fae1 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -35,7 +35,7 @@ extern { static NAME: &'static str = "tty"; fn main () { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let options = [ optflag("s", "silent", "print nothing, only return an exit status") @@ -46,7 +46,7 @@ fn main () { m.opt_present("s") }, Err(f) => { - println(f.to_err_msg()); + println(f.to_err_msg().as_slice()); usage(); return } diff --git a/uname/uname.rs b/uname/uname.rs index 8546da39f..2b2fce57c 100644 --- a/uname/uname.rs +++ b/uname/uname.rs @@ -52,7 +52,7 @@ unsafe fn getuname() -> utsrust { static NAME: &'static str = "uname"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), @@ -74,13 +74,13 @@ fn main() { println!("Usage:"); println!(" {:s}", program); 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; } let uname = unsafe { getuname() }; let mut output = StrBuf::new(); 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(" "); } diff --git a/unlink/unlink.rs b/unlink/unlink.rs index e681e070e..d0375f096 100644 --- a/unlink/unlink.rs +++ b/unlink/unlink.rs @@ -27,7 +27,7 @@ mod util; static NAME: &'static str = "unlink"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), @@ -47,7 +47,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [FILE]... [OPTION]...", program); println!(""); - print(getopts::usage("Unlink the file at [FILE].", opts)); + print(getopts::usage("Unlink the file at [FILE].", opts).as_slice()); return; } diff --git a/uptime/uptime.rs b/uptime/uptime.rs index 89ff30857..21e5c4dbb 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -48,7 +48,7 @@ extern { } fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("v", "version", "output version information and exit"), @@ -68,7 +68,7 @@ fn main() { println!(""); 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\ - 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; } diff --git a/users/users.rs b/users/users.rs index 8494b244a..ab5a4b730 100644 --- a/users/users.rs +++ b/users/users.rs @@ -48,7 +48,7 @@ extern { static NAME: &'static str = "users"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), @@ -66,7 +66,7 @@ fn main() { println!("Usage:"); println!(" {:s} [OPTION]... [FILE]", program); 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; } diff --git a/wc/wc.rs b/wc/wc.rs index cf77a5a82..ec3fb5598 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -34,7 +34,7 @@ struct Result { static NAME: &'static str = "wc"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("c", "bytes", "print the byte counts"), @@ -57,7 +57,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [OPTION]... [FILE]...", program); 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!("With no FILE, or when FILE is -, read standard input."); return; @@ -70,7 +70,7 @@ fn main() { let mut files = matches.free.clone(); if files.is_empty() { - files = vec!("-".to_owned()); + files = vec!("-".to_strbuf()); } wc(files, &matches); @@ -87,7 +87,7 @@ fn is_word_seperator(byte: u8) -> bool { byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF } -pub fn wc(files: Vec<~str>, matches: &Matches) { +pub fn wc(files: Vec, matches: &Matches) { let mut total_line_count: uint = 0; let mut total_word_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 { - filename: path.clone(), + filename: path.as_slice().to_owned(), bytes: byte_count, chars: char_count, lines: line_count, diff --git a/whoami/whoami.rs b/whoami/whoami.rs index d407a0800..20794e78d 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -42,7 +42,7 @@ unsafe fn getusername() -> ~str { static NAME: &'static str = "whoami"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), @@ -58,7 +58,7 @@ fn main() { println!("Usage:"); println!(" {:s}", program); println!(""); - print(getopts::usage("print effective userid", opts)); + print(getopts::usage("print effective userid", opts).as_slice()); return; } if matches.opt_present("version") { diff --git a/yes/yes.rs b/yes/yes.rs index c8c2b7365..e88aec95a 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -25,7 +25,7 @@ mod util; static NAME: &'static str = "yes"; fn main() { - let args = os::args(); + let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); let program = args.get(0).clone(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), @@ -43,7 +43,7 @@ fn main() { println!("Usage:"); println!(" {0:s} [STRING]... [OPTION]...", program); 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; } if matches.opt_present("version") {