diff --git a/base64/base64.rs b/base64/base64.rs index 14dc03e1a..55ee21b50 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -17,7 +17,6 @@ extern crate getopts; extern crate libc; #[phase(syntax, link)] extern crate log; -use std::char; use std::io::{println, File, stdin, stdout}; use std::os; use std::str; @@ -55,7 +54,7 @@ fn main() { } }; - let progname = args[0].clone(); + let progname = args.get(0).clone(); let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", opts); let mode = if matches.opt_present("help") { Help @@ -101,13 +100,9 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { to_decode = str::replace(to_decode, "\n", ""); if ignore_garbage { - let standard_chars: ~[char] = - bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ", - "abcdefghijklmnopqrstuvwxyz", - "0123456789+/").iter().map(|b| char::from_u32(*b as u32).unwrap()).collect(); - + let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; to_decode = to_decode - .trim_chars(|c| !standard_chars.contains(&c)) + .trim_chars(|c| !standard_chars.contains_char(c)) .to_owned(); } @@ -115,7 +110,7 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { Ok(bytes) => { let mut out = stdout(); - match out.write(bytes) { + match out.write(bytes.as_slice()) { Ok(_) => {} Err(f) => { crash!(1, "{}", f.to_str()); } } diff --git a/basename/basename.rs b/basename/basename.rs index 99587bd1b..b82dc037d 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -25,7 +25,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = strip_dir(&args[ 0 ].clone()); + let program = strip_dir(args.get(0)); // // Argument parsing @@ -64,7 +64,7 @@ fn main() { } // too many arguments else if args.len() > 3 { - println(program + ": extra operand `" + args[ 3 ] + "'"); + println(program + ": extra operand `" + args.get(3).clone() + "'"); println("Try `" + program + " --help' for more information."); return; } @@ -73,12 +73,12 @@ fn main() { // Main Program Processing // - let fullname = args[ 1 ].clone(); + let fullname = args.get(1).clone(); let mut name = strip_dir(&fullname); if args.len() > 2 { - let suffix = args[ 2 ].clone(); + let suffix = args.get(2).clone(); name = strip_suffix(&name, &suffix); } diff --git a/cat/cat.rs b/cat/cat.rs index 81260e774..758929fb9 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -21,7 +21,7 @@ use std::io::{BufferedWriter}; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("A", "show-all", "equivalent to -vET"), getopts::optflag("b", "number-nonblank", "number nonempty output lines, overrides -n"), diff --git a/dirname/dirname.rs b/dirname/dirname.rs index c1f6439b0..f3bbdc2b8 100644 --- a/dirname/dirname.rs +++ b/dirname/dirname.rs @@ -18,7 +18,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("z", "zero", "separate output with NUL rather than newline"), getopts::optflag("", "help", "display this help and exit"), diff --git a/du/du.rs b/du/du.rs index a586b00c8..18c74f938 100644 --- a/du/du.rs +++ b/du/du.rs @@ -88,7 +88,7 @@ fn du(path: &Path, mut my_stat: FileStat, fn main() { let args = os::args(); - let program = args[0].as_slice(); + let program = args.get(0).as_slice(); let opts = ~[ // In task getopts::optflag("a", "all", " write counts for all files, not just directories"), diff --git a/echo/echo.rs b/echo/echo.rs index d91c76bc6..d93ff303a 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -71,7 +71,7 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) { fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("n", "", "do not output the trailing newline"), getopts::optflag("e", "", "enable interpretation of backslash escapes"), diff --git a/env/env.rs b/env/env.rs index 6df1150d8..15f0c1e98 100644 --- a/env/env.rs +++ b/env/env.rs @@ -53,7 +53,7 @@ fn print_env(null: bool) { fn main() { let args = std::os::args(); - let prog = args[0].as_slice(); + let prog = args.get(0).as_slice(); // to handle arguments the same way than GNU env, we can't use getopts let mut opts = box options { @@ -191,7 +191,10 @@ fn main() { } if opts.program.len() >= 1 { - match std::io::process::Process::status(opts.program.get(0).as_slice(), opts.program.slice_from(1)) { + use std::io::process::{Command, InheritFd}; + let prog = opts.program.get(0).clone(); + let args = opts.program.slice_from(1); + match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() { Ok(exit) => std::os::set_exit_status(match exit { std::io::process::ExitStatus(s) => s, diff --git a/fold/fold.rs b/fold/fold.rs index cfeddb150..187f3754e 100644 --- a/fold/fold.rs +++ b/fold/fold.rs @@ -29,9 +29,9 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); - let (args, obs_width) = handle_obsolete(args); + let (args, obs_width) = handle_obsolete(args.as_slice().to_owned()); let opts = [ getopts::optflag("b", "bytes", "count using bytes rather than columns (meaning control characters such as newline are not treated specially)"), diff --git a/hostname/hostname.rs b/hostname/hostname.rs index 27d3ef240..60e975d6b 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -25,7 +25,7 @@ extern { fn main () { let args = os::args(); - let program = args[0].to_owned(); + let program = args.get(0).to_owned(); let options = [ optflag("f", "full", "Default option to show full name"), @@ -96,7 +96,7 @@ fn xgethostname() -> ~str { } fn xsethostname(name: &~str) { - let vec_name: ~[libc::c_char] = name.bytes().map(|c| c as i8).collect(); + let vec_name: Vec = name.bytes().map(|c| c as i8).collect(); let err = unsafe { sethostname (vec_name.as_ptr(), vec_name.len() as i32) diff --git a/logname/logname.rs b/logname/logname.rs index de489f483..243a8d790 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -45,7 +45,7 @@ fn version() { fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); // // Argument parsing diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index 687c8116f..438886750 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -30,7 +30,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = [ getopts::optflag("b", "binary", "read in binary mode"), diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 4ae6b79c0..264a64ccb 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -70,12 +70,12 @@ fn main() { strconv::ExpNone, false, false); if res.is_some() { - unsafe { std::cast::transmute(res.unwrap()) } + unsafe { std::mem::transmute(res.unwrap()) } } else { crash!(1, "no mode given"); } } else { - unsafe { std::cast::transmute(0o755 as u32) } + unsafe { std::mem::transmute(0o755 as u32) } }; let dirs = matches.free; diff --git a/paste/paste.rs b/paste/paste.rs index 921e7df3f..2f72013f0 100644 --- a/paste/paste.rs +++ b/paste/paste.rs @@ -25,7 +25,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("s", "serial", "paste one file at a time instead of in parallel"), @@ -57,7 +57,7 @@ fn main() { } fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) { - let mut files: ~[io::BufferedReader>] = filenames.move_iter().map(|name| + let mut files: Vec>> = filenames.move_iter().map(|name| io::BufferedReader::new( if name == "-".to_owned() { box io::stdio::stdin_raw() as Box @@ -66,14 +66,14 @@ fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) { } ) ).collect(); - let delimiters: ~[~str] = delimiters.chars().map(|x| x.to_str()).collect(); + let delimiters: Vec<~str> = delimiters.chars().map(|x| x.to_str()).collect(); let mut delim_count = 0; if serial { for file in files.mut_iter() { let mut output = "".to_owned(); loop { output = output + match file.read_line() { - Ok(line) => line.trim_right() + delimiters[delim_count % delimiters.len()], + Ok(line) => line.trim_right() + delimiters.get(delim_count % delimiters.len()).clone(), Err(f) => if f.kind == io::EndOfFile { break } else { @@ -103,7 +103,7 @@ fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) { } } } - output = output + delimiters[delim_count % delimiters.len()]; + output = output + delimiters.get(delim_count % delimiters.len()).clone(); delim_count += 1; } if files.len() == eof_count { diff --git a/printenv/printenv.rs b/printenv/printenv.rs index 0c87df0f3..b5c87d73b 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -26,7 +26,7 @@ static NAME: &'static str = "printenv"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"), getopts::optflag("h", "help", "display this help and exit"), diff --git a/pwd/pwd.rs b/pwd/pwd.rs index 4661ebf30..4ca5cc016 100644 --- a/pwd/pwd.rs +++ b/pwd/pwd.rs @@ -25,7 +25,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("", "help", "display this help and exit"), getopts::optflag("", "version", "output version information and exit"), diff --git a/rm/rm.rs b/rm/rm.rs index 3ffc19b09..3ce712abb 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -31,7 +31,7 @@ static NAME: &'static str = "rm"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); // TODO: make getopts support -R in addition to -r let opts = ~[ diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index be9efebe1..b4dfc3a36 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -24,7 +24,7 @@ static NAME: &'static str = "rmdir"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("", "ignore-fail-on-non-empty", "ignore each failure that is solely because a directory is non-empty"), diff --git a/sleep/sleep.rs b/sleep/sleep.rs index 01c5bed90..cdf5c7ddb 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -25,7 +25,7 @@ static NAME: &'static str = "sleep"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), diff --git a/tac/tac.rs b/tac/tac.rs index cd06a678d..22e1abe96 100644 --- a/tac/tac.rs +++ b/tac/tac.rs @@ -25,7 +25,7 @@ static VERSION: &'static str = "1.0.0"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("b", "before", "attach the separator before instead of after"), @@ -86,7 +86,7 @@ fn tac(filenames: Vec<~str>, before: bool, _: bool, separator: ~str) { buf.truncate(len - 1); data = buf.into_owned(); } - let split_vec: ~[&str] = data.split_str(separator).collect(); + let split_vec: Vec<&str> = data.split_str(separator).collect(); let rev: ~str = split_vec.iter().rev().fold("".to_owned(), |a, &b| a + if before { separator + b diff --git a/tee/tee.rs b/tee/tee.rs index 36459aceb..a2339e72b 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -25,7 +25,7 @@ static NAME: &'static str = "tee"; static VERSION: &'static str = "1.0.0"; fn main() { - match options(args()).and_then(exec) { + match options(args().as_slice()).and_then(exec) { Ok(_) => set_exit_status(0), Err(_) => set_exit_status(1) } @@ -149,5 +149,5 @@ fn with_path(path: &Path, cb: || -> IoResult) -> IoResult { } fn warn(message: &str) { - error!("{}: {}", args()[0], message); + error!("{}: {}", args().get(0), message); } diff --git a/truncate/truncate.rs b/truncate/truncate.rs index 04ad57c44..74c88dbb7 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -48,7 +48,7 @@ static NAME: &'static str = "truncate"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("c", "no-create", "do not create files that do not exist"), diff --git a/uname/uname.rs b/uname/uname.rs index aaefedc1e..8546da39f 100644 --- a/uname/uname.rs +++ b/uname/uname.rs @@ -53,7 +53,7 @@ static NAME: &'static str = "uname"; fn main() { let args = os::args(); - let program = args[0].as_slice(); + let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("a", "all", "Behave as though all of the options -mnrsv were specified."), diff --git a/uptime/uptime.rs b/uptime/uptime.rs index cb5e328de..89ff30857 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -18,7 +18,7 @@ extern crate getopts; extern crate libc; use std::os; -use std::cast::transmute; +use std::mem::transmute; use std::io::{print, File}; use std::ptr::null; use std::from_str::from_str; @@ -49,7 +49,7 @@ extern { fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("v", "version", "output version information and exit"), getopts::optflag("h", "help", "display this help and exit"), diff --git a/users/users.rs b/users/users.rs index d9319794a..8494b244a 100644 --- a/users/users.rs +++ b/users/users.rs @@ -20,7 +20,7 @@ extern crate getopts; extern crate libc; use std::io::print; -use std::cast; +use std::mem; use std::os; use std::ptr; use std::str; @@ -49,7 +49,7 @@ static NAME: &'static str = "users"; fn main() { let args = os::args(); - let program = args[0].as_slice(); + let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"), @@ -103,7 +103,7 @@ fn exec(filename: &str) { } if (*line).ut_type == USER_PROCESS { - let user = str::raw::from_c_str(cast::transmute(&(*line).ut_user)); + let user = str::raw::from_c_str(mem::transmute(&(*line).ut_user)); users.push(user); } } diff --git a/wc/wc.rs b/wc/wc.rs index fc6ee9ac1..cf77a5a82 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -35,7 +35,7 @@ static NAME: &'static str = "wc"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("c", "bytes", "print the byte counts"), getopts::optflag("m", "chars", "print the character counts"), diff --git a/whoami/whoami.rs b/whoami/whoami.rs index 9b7ad244e..d407a0800 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -43,7 +43,7 @@ static NAME: &'static str = "whoami"; fn main() { let args = os::args(); - let program = args[0].as_slice(); + let program = args.get(0).as_slice(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"), diff --git a/yes/yes.rs b/yes/yes.rs index 47bde021a..c8c2b7365 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -26,7 +26,7 @@ static NAME: &'static str = "yes"; fn main() { let args = os::args(); - let program = args[0].clone(); + let program = args.get(0).clone(); let opts = ~[ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"),