1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Adapt to removal of ~str from libstd.

This commit is contained in:
Michael Gehring 2014-05-23 14:28:40 +02:00
parent db9d8c046a
commit 0ce3f0f4e1
28 changed files with 159 additions and 157 deletions

View file

@ -97,16 +97,16 @@ fn decode(input: &mut Reader, ignore_garbage: bool) {
Err(f) => fail!(f.to_str()) Err(f) => fail!(f.to_str())
}; };
to_decode = str::replace(to_decode, "\n", ""); to_decode = str::replace(to_decode.as_slice(), "\n", "");
if ignore_garbage { if ignore_garbage {
let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
to_decode = to_decode to_decode = to_decode.as_slice()
.trim_chars(|c| !standard_chars.contains_char(c)) .trim_chars(|c| !standard_chars.contains_char(c))
.to_owned(); .into_owned()
} }
match to_decode.from_base64() { match to_decode.as_slice().from_base64() {
Ok(bytes) => { Ok(bytes) => {
let mut out = stdout(); let mut out = stdout();
@ -148,7 +148,7 @@ fn encode(input: &mut Reader, line_wrap: uint) {
// compatibility. // compatibility.
let final = encoded.replace("\r", ""); let final = encoded.replace("\r", "");
println(final); println(final.as_slice());
} }
fn help(progname: &str, usage: &str) { fn help(progname: &str, usage: &str) {

View file

@ -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: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect(); let args = os::args();
let program = strip_dir(os::args().get(0)); let program = strip_dir(args.get(0).as_slice());
// //
// Argument parsing // Argument parsing
@ -52,20 +52,20 @@ fn main() {
} }
if matches.opt_present("version") { if matches.opt_present("version") {
println(program + " " + VERSION); println!("{} {}", program, VERSION);
return; return;
} }
// too few arguments // too few arguments
if args.len() < 2 { if args.len() < 2 {
println(program + ": missing operand"); println!("{}: {}", program, "missing operand");
println("Try `" + program + " --help' for more information."); println!("Try '{} --help' for more information.", program);
return; return;
} }
// too many arguments // too many arguments
else if args.len() > 3 { else if args.len() > 3 {
println(program + ": extra operand `" + args.get(3).as_slice() + "'"); println!("{}: extra operand '{}'", program, args.get(3));
println("Try `" + program + " --help' for more information."); println!("Try '{} --help' for more information.", program);
return; return;
} }
@ -73,19 +73,19 @@ fn main() {
// Main Program Processing // Main Program Processing
// //
let fullname = args.get(1).clone(); let fullname = args.get(1);
let mut name = strip_dir(&fullname.as_slice().to_owned()); let mut name = strip_dir(fullname.as_slice());
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.to_owned()); name = strip_suffix(name.as_slice(), suffix.as_slice());
} }
println(name); println(name.as_slice());
} }
fn strip_dir(fullname: &~str) -> ~str { fn strip_dir(fullname: &str) -> StrBuf {
let mut name = StrBuf::new(); let mut name = StrBuf::new();
for c in fullname.chars().rev() { for c in fullname.chars().rev() {
@ -98,14 +98,14 @@ fn strip_dir(fullname: &~str) -> ~str {
return name.as_slice().chars().rev().collect(); return name.as_slice().chars().rev().collect();
} }
fn strip_suffix(name: &~str, suffix: &~str) -> ~str { fn strip_suffix(name: &str, suffix: &str) -> StrBuf {
if name == suffix { if name == suffix {
return name.clone(); return name.into_strbuf();
} }
if name.ends_with(*suffix) { if name.ends_with(suffix) {
return name.slice_to(name.len() - suffix.len()).into_owned(); return name.slice_to(name.len() - suffix.len()).into_strbuf();
} }
return name.clone(); return name.into_strbuf();
} }

View file

@ -103,7 +103,7 @@ pub fn exec(files: Vec<StrBuf>, number: NumberingMode, show_nonprint: bool, show
let is_numbering = number == NumberAll || number == NumberNonEmpty; let is_numbering = number == NumberAll || number == NumberNonEmpty;
for path in files.iter() { for path in files.iter() {
let mut reader = match open(path.to_owned()) { let mut reader = match open(path.as_slice()) {
Some(f) => f, Some(f) => f,
None => { continue } None => { continue }
}; };
@ -158,7 +158,7 @@ pub fn exec(files: Vec<StrBuf>, number: NumberingMode, show_nonprint: bool, show
let mut buf = ~[0, .. 1024 * 64]; let mut buf = ~[0, .. 1024 * 64];
// passthru mode // passthru mode
for path in files.iter() { for path in files.iter() {
let mut reader = match open(path.to_owned()) { let mut reader = match open(path.as_slice()) {
Some(f) => f, Some(f) => f,
None => { continue } None => { continue }
}; };
@ -175,7 +175,7 @@ pub fn exec(files: Vec<StrBuf>, number: NumberingMode, show_nonprint: bool, show
} }
} }
fn open(path: ~str) -> Option<Box<Reader>> { fn open(path: &str) -> Option<Box<Reader>> {
if "-" == path { if "-" == path {
return Some(box stdin_raw() as Box<Reader>); return Some(box stdin_raw() as Box<Reader>);
} }

View file

@ -32,7 +32,7 @@ static VERSION: &'static str = "1.0.0";
struct Options { struct Options {
all: bool, all: bool,
program_name: ~str, program_name: StrBuf,
max_depth: Option<uint>, max_depth: Option<uint>,
total: bool, total: bool,
separate_dirs: bool, separate_dirs: bool,
@ -268,7 +268,7 @@ ers of 1000).",
None => 1024 None => 1024
}; };
let convert_size = |size: u64| -> ~str { let convert_size = |size: u64| -> StrBuf {
if matches.opt_present("human-readable") || matches.opt_present("si") { if matches.opt_present("human-readable") || matches.opt_present("si") {
if size > MB { if size > MB {
format!("{:.1f}M", (size as f64) / (MB as f64)) format!("{:.1f}M", (size as f64) / (MB as f64))

View file

@ -118,7 +118,7 @@ fn main() {
let string = matches.free.connect(" "); let string = matches.free.connect(" ");
if matches.opt_present("e") { if matches.opt_present("e") {
let mut prev_was_slash = false; let mut prev_was_slash = false;
let mut iter = string.chars().enumerate(); let mut iter = string.as_slice().chars().enumerate();
loop { loop {
match iter.next() { match iter.next() {
Some((index, c)) => { Some((index, c)) => {
@ -142,7 +142,7 @@ fn main() {
't' => print_char('\t'), 't' => print_char('\t'),
'v' => print_char('\x0B'), 'v' => print_char('\x0B'),
'x' => { 'x' => {
let (c, num_char_used) = convert_str(string, index + 1, 16u); let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 16u);
if num_char_used == 0 { if num_char_used == 0 {
print_char('\\'); print_char('\\');
print_char('x'); print_char('x');
@ -154,7 +154,7 @@ fn main() {
} }
}, },
'0' => { '0' => {
let (c, num_char_used) = convert_str(string, index + 1, 8u); let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 8u);
if num_char_used == 0 { if num_char_used == 0 {
print_char('\\'); print_char('\\');
print_char('0'); print_char('0');
@ -176,7 +176,7 @@ fn main() {
} }
} }
} else { } else {
print(string); print(string.as_slice());
} }
} }

16
env/env.rs vendored
View file

@ -16,9 +16,9 @@
struct options { struct options {
ignore_env: bool, ignore_env: bool,
null: bool, null: bool,
unsets: Vec<~str>, unsets: Vec<StrBuf>,
sets: Vec<(~str, ~str)>, sets: Vec<(StrBuf, StrBuf)>,
program: Vec<~str> program: Vec<StrBuf>
} }
fn usage(prog: &str) { fn usage(prog: &str) {
@ -77,7 +77,7 @@ fn main() {
if wait_cmd { if wait_cmd {
// we still accept NAME=VAL here but not other options // we still accept NAME=VAL here but not other options
let mut sp = opt.splitn('=', 1); let mut sp = opt.as_slice().splitn('=', 1);
let name = sp.next(); let name = sp.next();
let value = sp.next(); let value = sp.next();
@ -91,7 +91,7 @@ fn main() {
break; break;
} }
} }
} else if opt.starts_with("--") { } else if opt.as_slice().starts_with("--") {
match opt.as_slice() { match opt.as_slice() {
"--help" => { usage(prog); return } "--help" => { usage(prog); return }
"--version" => { version(); return } "--version" => { version(); return }
@ -113,7 +113,7 @@ fn main() {
return return
} }
} }
} else if opt.starts_with("-") { } else if opt.as_slice().starts_with("-") {
if opt.len() == 0 { if opt.len() == 0 {
// implies -i and stop parsing opts // implies -i and stop parsing opts
wait_cmd = true; wait_cmd = true;
@ -121,7 +121,7 @@ fn main() {
continue; continue;
} }
let mut chars = opt.chars(); let mut chars = opt.as_slice().chars();
chars.next(); chars.next();
for c in chars { for c in chars {
@ -148,7 +148,7 @@ fn main() {
} }
} else { } else {
// is it a NAME=VALUE like opt ? // is it a NAME=VALUE like opt ?
let mut sp = opt.splitn('=', 1); let mut sp = opt.as_slice().splitn('=', 1);
let name = sp.next(); let name = sp.next();
let value = sp.next(); let value = sp.next();

View file

@ -82,24 +82,24 @@ fn main() {
} }
} }
fn handle_obsolete(args: ~[~str]) -> (~[~str], Option<~str>) { fn handle_obsolete(args: &[StrBuf]) -> (Vec<StrBuf>, Option<StrBuf>) {
let mut args: Vec<~str> = args.move_iter().collect(); let mut args = Vec::<StrBuf>::from_slice(args);
let mut i = 0; let mut i = 0;
while i < args.len() { while i < args.len() {
if args.get(i).char_at(0) == '-' && args.get(i).len() > 1 && args.get(i).char_at(1).is_digit() { if args.get(i).as_slice().char_at(0) == '-' && args.get(i).len() > 1 && args.get(i).as_slice().char_at(1).is_digit() {
return (args.as_slice().to_owned(), return (args.clone(),
Some(args.remove(i).unwrap().slice_from(1).to_owned())); Some(args.remove(i).unwrap().as_slice().slice_from(1).to_owned()));
} }
i += 1; i += 1;
} }
(args.as_slice().to_owned(), None) (args, None)
} }
fn fold(filenames: Vec<StrBuf>, 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.as_slice(); let filename: &str = filename.as_slice();
let buffer = BufferedReader::new( let buffer = BufferedReader::new(
if filename == "-".to_owned() { if filename == "-" {
box io::stdio::stdin_raw() as Box<Reader> box io::stdio::stdin_raw() as Box<Reader>
} else { } else {
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader> box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
@ -117,7 +117,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
println!(""); println!("");
continue; continue;
} }
let line = line.slice_to(line.len() - 1); let line = line.as_slice().slice_to(line.len() - 1);
if bytes { if bytes {
let mut i = 0; let mut i = 0;
while i < line.len() { while i < line.len() {
@ -173,7 +173,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
match slice.rfind(|ch: char| ch.is_whitespace()) { match slice.rfind(|ch: char| ch.is_whitespace()) {
Some(m) => { Some(m) => {
let routput = slice.slice_from(m + 1).to_owned(); let routput = slice.slice_from(m + 1).to_owned();
let ncount = routput.chars().fold(0, |out, ch: char| out + if ch == '\t' { 8 } else { 1 }); let ncount = routput.as_slice().chars().fold(0, |out, ch: char| out + if ch == '\t' { 8 } else { 1 });
(slice.slice_to(m + 1), routput, ncount) (slice.slice_to(m + 1), routput, ncount)
}, },
None => (slice, "".to_owned(), 0) None => (slice, "".to_owned(), 0)

View file

@ -26,7 +26,7 @@ fn main () {
let mut line_count = 10u; let mut line_count = 10u;
// handle obsolete -number syntax // handle obsolete -number syntax
let options = match obsolete(os::args().tail().to_owned()) { let options = match obsolete(os::args().tail()) {
(args, Some(n)) => { line_count = n; args }, (args, Some(n)) => { line_count = n; args },
(args, None) => args (args, None) => args
}; };
@ -96,14 +96,14 @@ fn main () {
// //
// In case is found, the options vector will get rid of that object so that // In case is found, the options vector will get rid of that object so that
// getopts works correctly. // getopts works correctly.
fn obsolete (options: ~[~str]) -> (~[~str], Option<uint>) { fn obsolete (options: &[StrBuf]) -> (Vec<StrBuf>, Option<uint>) {
let mut options: Vec<~str> = options.move_iter().collect(); let mut options: Vec<StrBuf> = Vec::from_slice(options);
let mut a = 0; let mut a = 0;
let b = options.len(); let b = options.len();
let mut current;
while a < b { while a < b {
current = options.get(a).clone(); let current = options.get(a).clone();
let current = current.as_slice();
if current.len() > 1 && current[0] == '-' as u8 { if current.len() > 1 && current[0] == '-' as u8 {
let len = current.len(); let len = current.len();
@ -115,7 +115,7 @@ fn obsolete (options: ~[~str]) -> (~[~str], Option<uint>) {
if pos == len - 1 { if pos == len - 1 {
options.remove(a); options.remove(a);
let number : Option<uint> = from_str(current.slice(1,len)); let number : Option<uint> = from_str(current.slice(1,len));
return (options.as_slice().to_owned(), Some(number.unwrap())); return (options, Some(number.unwrap()));
} }
} }
} }
@ -123,7 +123,7 @@ fn obsolete (options: ~[~str]) -> (~[~str], Option<uint>) {
a += 1; a += 1;
}; };
(options.as_slice().to_owned(), None) (options, None)
} }
fn head<T: Reader> (reader: &mut BufferedReader<T>, line_count:uint) { fn head<T: Reader> (reader: &mut BufferedReader<T>, line_count:uint) {

View file

@ -52,7 +52,7 @@ extern {
fn main() { fn main() {
let args: Vec<StrBuf> = os::args().iter().map(|x| x.to_strbuf()).collect(); 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"),
optflag("", "version", "output version information and exit"), optflag("", "version", "output version information and exit"),
]; ];
@ -87,9 +87,8 @@ fn version() {
println!("{} {}", NAME, VERSION); println!("{} {}", NAME, VERSION);
} }
fn get_help_text(progname: &str, usage: &str) -> ~str { fn get_help_text(progname: &str, usage: &str) -> StrBuf {
let msg = format!("Usage: \n {0} {1}", progname, usage); format!("Usage: \n {0} {1}", progname, usage)
msg
} }
fn help(progname: &str, usage: &str) { fn help(progname: &str, usage: &str) {

View file

@ -36,31 +36,31 @@ fn main () {
let matches = match getopts(args.tail(), options) { let matches = match getopts(args.tail(), options) {
Ok(m) => { m } Ok(m) => { m }
_ => { help_menu(program, options); return; } _ => { help_menu(program.as_slice(), options); return; }
}; };
if matches.opt_present("h") { if matches.opt_present("h") {
help_menu(program, options); help_menu(program.as_slice(), options);
return return
} }
if matches.opt_present("V") { version(); return } if matches.opt_present("V") { version(); return }
match matches.free.len() { match matches.free.len() {
0 => { 0 => {
let hostname: ~str = xgethostname(); let hostname = xgethostname();
if matches.opt_present("s") { if matches.opt_present("s") {
let pos = hostname.find_str("."); let pos = hostname.as_slice().find_str(".");
if pos.is_some() { if pos.is_some() {
println!("{:s}", hostname.slice_to(pos.unwrap())); println!("{:s}", hostname.as_slice().slice_to(pos.unwrap()));
return; return;
} }
} }
println!("{:s}", hostname); println!("{:s}", hostname.as_slice());
} }
1 => { xsethostname( &matches.free.last().unwrap().as_slice().to_owned() ) } 1 => { xsethostname( matches.free.last().unwrap().as_slice() ) }
_ => { help_menu(program, options); } _ => { help_menu(program.as_slice(), options); }
}; };
} }
@ -77,7 +77,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
print!("{:s}", usage("Print or set the system's host name.", options)); print!("{:s}", usage("Print or set the system's host name.", options));
} }
fn xgethostname() -> ~str { fn xgethostname() -> StrBuf {
let namelen = 256u; let namelen = 256u;
let mut name = Vec::from_elem(namelen, 0u8); let mut name = Vec::from_elem(namelen, 0u8);
@ -95,7 +95,7 @@ fn xgethostname() -> ~str {
str::from_utf8(name.slice_to(last_char)).unwrap().to_owned() str::from_utf8(name.slice_to(last_char)).unwrap().to_owned()
} }
fn xsethostname(name: &~str) { fn xsethostname(name: &str) {
let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as i8).collect(); let vec_name: Vec<libc::c_char> = name.bytes().map(|c| c as i8).collect();
let err = unsafe { let err = unsafe {
@ -103,6 +103,6 @@ fn xsethostname(name: &~str) {
}; };
if err != 0 { if err != 0 {
println!("Cannot set hostname to {:s}", *name); println!("Cannot set hostname to {:s}", name);
} }
} }

View file

@ -121,12 +121,12 @@ fn table() {
} }
} }
fn print_signal(signal_name_or_value: ~str) { fn print_signal(signal_name_or_value: &str) {
for signal in ALL_SIGNALS.iter() { for signal in ALL_SIGNALS.iter() {
if signal.name == signal_name_or_value || ("SIG" + signal.name) == signal_name_or_value { if signal.name == signal_name_or_value || (format!("SIG{}", signal.name).as_slice()) == signal_name_or_value {
println!("{}", signal.value) println!("{}", signal.value)
exit!(EXIT_OK) exit!(EXIT_OK)
} else if signal_name_or_value == signal.value.to_str() { } else if signal_name_or_value == signal.value.to_str().as_slice() {
println!("{}", signal.name); println!("{}", signal.name);
exit!(EXIT_OK) exit!(EXIT_OK)
} }
@ -151,27 +151,26 @@ fn print_signals() {
fn list(arg: Option<StrBuf>) { fn list(arg: Option<StrBuf>) {
match arg { match arg {
Some(x) => print_signal(x.to_owned()), Some(x) => print_signal(x.as_slice()),
None => print_signals(), None => print_signals(),
}; };
} }
fn get_help_text(progname: &str, usage: &str) -> ~str { fn get_help_text(progname: &str, usage: &str) -> StrBuf {
let msg = format!("Usage: \n {0} {1}", progname, usage); format!("Usage: \n {0} {1}", progname, usage)
msg
} }
fn help(progname: &str, usage: &str) { fn help(progname: &str, usage: &str) {
println!("{}", get_help_text(progname, usage)); println!("{}", get_help_text(progname, usage));
} }
fn signal_by_name_or_value(signal_name_or_value:~str) -> Option<uint> { fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
if signal_name_or_value == "0".to_owned() { if signal_name_or_value == "0" {
return Some(0); return Some(0);
} }
for signal in ALL_SIGNALS.iter() { for signal in ALL_SIGNALS.iter() {
let long_name = "SIG" + signal.name; let long_name = format!("SIG{}", signal.name);
if signal.name == signal_name_or_value || (signal_name_or_value == signal.value.to_str()) || (long_name == signal_name_or_value) { if signal.name == signal_name_or_value || (signal_name_or_value == signal.value.to_str().as_slice()) || (long_name.as_slice() == signal_name_or_value) {
return Some(signal.value); return Some(signal.value);
} }
} }
@ -179,7 +178,7 @@ fn signal_by_name_or_value(signal_name_or_value:~str) -> Option<uint> {
} }
fn kill(signalname: &str, pids: std::vec::Vec<StrBuf>) { fn kill(signalname: &str, pids: std::vec::Vec<StrBuf>) {
let optional_signal_value = signal_by_name_or_value(signalname.to_owned()); let optional_signal_value = signal_by_name_or_value(signalname);
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)

View file

@ -18,7 +18,7 @@
extern crate getopts; extern crate getopts;
extern crate libc; extern crate libc;
use std::io::{print, println}; use std::io::print;
use std::os; use std::os;
use std::str; use std::str;
use libc::c_char; use libc::c_char;
@ -30,7 +30,7 @@ extern {
pub fn getlogin() -> *libc::c_char; pub fn getlogin() -> *libc::c_char;
} }
unsafe fn get_userlogin() -> ~str { unsafe fn get_userlogin() -> StrBuf {
let login: *libc::c_char = getlogin(); let login: *libc::c_char = getlogin();
str::raw::from_c_str(login) str::raw::from_c_str(login)
@ -40,7 +40,7 @@ static NAME: &'static str = "logname";
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
fn version() { fn version() {
println(NAME + " " + VERSION); println!("{} {}", NAME, VERSION);
} }
fn main() { fn main() {

View file

@ -84,7 +84,7 @@ fn md5sum(files: Vec<StrBuf>, binary: bool, check: bool, tag: bool, status: bool
for filename in files.iter() { for filename in files.iter() {
let filename: &str = filename.as_slice(); let filename: &str = filename.as_slice();
let mut file = BufferedReader::new( let mut file = BufferedReader::new(
if filename == "-".to_owned() { if filename == "-" {
box stdin_raw() as Box<Reader> box stdin_raw() as Box<Reader>
} else { } else {
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader> box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
@ -95,9 +95,9 @@ fn md5sum(files: Vec<StrBuf>, binary: bool, check: bool, tag: bool, status: bool
//let mut buffer = BufferedReader::new(file); //let mut buffer = BufferedReader::new(file);
for (i, line) in buffer.lines().enumerate() { for (i, line) in buffer.lines().enumerate() {
let line = safe_unwrap!(line); let line = safe_unwrap!(line);
let (ck_filename, sum) = match from_gnu(line, bytes) { let (ck_filename, sum) = match from_gnu(line.as_slice(), bytes) {
Some(m) => m, Some(m) => m,
None => match from_bsd(line, bytes) { None => match from_bsd(line.as_slice(), bytes) {
Some(m) => m, Some(m) => m,
None => { None => {
bad_format += 1; bad_format += 1;
@ -112,7 +112,7 @@ fn md5sum(files: Vec<StrBuf>, binary: bool, check: bool, tag: bool, status: bool
} }
}; };
let real_sum = calc_sum(&mut md5, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary); let real_sum = calc_sum(&mut md5, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary);
if sum == real_sum { if sum == real_sum.as_slice() {
if !quiet { if !quiet {
println!("{}: OK", ck_filename); println!("{}: OK", ck_filename);
} }
@ -145,15 +145,15 @@ fn md5sum(files: Vec<StrBuf>, binary: bool, check: bool, tag: bool, status: bool
} }
} }
fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> ~str { fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> StrBuf {
let data = let data =
if binary { if binary {
(safe_unwrap!(file.read_to_end())).as_slice().to_owned() (safe_unwrap!(file.read_to_end()))
} else { } else {
(safe_unwrap!(file.read_to_str())).into_bytes() (safe_unwrap!(file.read_to_str())).into_bytes()
}; };
md5.reset(); md5.reset();
md5.input(data); md5.input(data.as_slice());
md5.result_str() md5.result_str()
} }

View file

@ -89,8 +89,7 @@ fn print_help(opts: &[getopts::OptGroup]) {
println!("mkdir v{} - make a new directory with the given path", VERSION); println!("mkdir v{} - make a new directory with the given path", VERSION);
println!(""); println!("");
println!("Usage:"); println!("Usage:");
print!("{}", getopts::usage("Create the given DIRECTORY(ies)" + print!("{}", getopts::usage("Create the given DIRECTORY(ies) if they do not exist", opts));
" if they do not exist", opts));
} }
/** /**

View file

@ -66,23 +66,26 @@ fn paste(filenames: Vec<StrBuf>, serial: bool, delimiters: &str) {
} }
) )
).collect(); ).collect();
let delimiters: Vec<~str> = delimiters.chars().map(|x| x.to_str()).collect(); let delimiters: Vec<StrBuf> = delimiters.chars().map(|x| x.to_str()).collect();
let mut delim_count = 0; let mut delim_count = 0;
if serial { if serial {
for file in files.mut_iter() { for file in files.mut_iter() {
let mut output = "".to_owned(); let mut output = StrBuf::new();
loop { loop {
output = output + match file.read_line() { match file.read_line() {
Ok(line) => line.trim_right() + delimiters.get(delim_count % delimiters.len()).clone(), Ok(line) => {
output.push_str(line.as_slice().trim_right());
output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice());
}
Err(f) => if f.kind == io::EndOfFile { Err(f) => if f.kind == io::EndOfFile {
break break
} else { } else {
crash!(1, "{}", f.to_str()) crash!(1, "{}", f.to_str())
} }
}; }
delim_count += 1; delim_count += 1;
} }
println!("{}", output.slice_to(output.len() - 1)); println!("{}", output.as_slice().slice_to(output.len() - 1));
} }
} else { } else {
let mut eof = Vec::from_elem(files.len(), false); let mut eof = Vec::from_elem(files.len(), false);
@ -94,7 +97,7 @@ fn paste(filenames: Vec<StrBuf>, serial: bool, delimiters: &str) {
eof_count += 1; eof_count += 1;
} else { } else {
match file.read_line() { match file.read_line() {
Ok(line) => output = output + line.slice_to(line.len() - 1), Ok(line) => output.push_str(line.as_slice().slice_to(line.len() - 1)),
Err(f) => if f.kind == io::EndOfFile { Err(f) => if f.kind == io::EndOfFile {
*eof.get_mut(i) = true; *eof.get_mut(i) = true;
eof_count += 1; eof_count += 1;
@ -103,13 +106,13 @@ fn paste(filenames: Vec<StrBuf>, serial: bool, delimiters: &str) {
} }
} }
} }
output = output + delimiters.get(delim_count % delimiters.len()).clone(); output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice());
delim_count += 1; delim_count += 1;
} }
if files.len() == eof_count { if files.len() == eof_count {
break; break;
} }
println!("{}", output.slice_to(output.len() - 1)); println!("{}", output.as_slice().slice_to(output.len() - 1));
delim_count = 0; delim_count = 0;
} }
} }

View file

@ -72,7 +72,7 @@ pub fn exec(args: Vec<StrBuf>, separator: &str) {
for env_var in args.iter() { for env_var in args.iter() {
match os::getenv(env_var.as_slice()) { match os::getenv(env_var.as_slice()) {
Some(var) => { Some(var) => {
print(var); print(var.as_slice());
print(separator); print(separator);
} }
_ => () _ => ()

View file

@ -192,9 +192,9 @@ fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: b
fn prompt_file(path: &Path, name: &str) -> bool { fn prompt_file(path: &Path, name: &str) -> bool {
if path.is_dir() { if path.is_dir() {
prompt(format!("Remove directory '{}'? ", name)) prompt(format!("Remove directory '{}'? ", name).as_slice())
} else { } else {
prompt(format!("Remove file '{}'? ", name)) prompt(format!("Remove file '{}'? ", name).as_slice())
} }
} }
@ -207,7 +207,7 @@ fn read_prompt() -> bool {
stdio::flush(); stdio::flush();
match BufferedReader::new(stdin()).read_line() { match BufferedReader::new(stdin()).read_line() {
Ok(line) => { Ok(line) => {
match line.char_at(0) { match line.as_slice().char_at(0) {
'y' | 'Y' => true, 'y' | 'Y' => true,
'n' | 'N' => false, 'n' | 'N' => false,
_ => { _ => {

View file

@ -21,14 +21,14 @@ fn print_usage(opts: ~[getopts::OptGroup]) {
println!("{:s}", getopts::usage("Print sequences of numbers", opts)); println!("{:s}", getopts::usage("Print sequences of numbers", opts));
} }
fn parse_float(s: &str) -> Result<f32, ~str>{ fn parse_float(s: &str) -> Result<f32, StrBuf>{
match from_str(s) { match from_str(s) {
Some(n) => Ok(n), Some(n) => Ok(n),
None => Err(format!("seq: invalid floating point argument: {:s}", s)) None => Err(format!("seq: invalid floating point argument: {:s}", s))
} }
} }
fn escape_sequences(s: &str) -> ~str { fn escape_sequences(s: &str) -> StrBuf {
s.replace("\\n", "\n"). s.replace("\\n", "\n").
replace("\\t", "\t") replace("\\t", "\t")
} }
@ -96,7 +96,7 @@ fn done_printing(next: f32, step: f32, last: f32) -> bool {
} }
} }
fn print_seq(first: f32, step: f32, last: f32, separator: ~str, terminator: ~str, pad: bool) { fn print_seq(first: f32, step: f32, last: f32, separator: StrBuf, terminator: StrBuf, pad: bool) {
let mut i = first; let mut i = first;
let maxlen = first.max(last).to_str().len(); let maxlen = first.max(last).to_str().len();
while !done_printing(i, step, last) { while !done_printing(i, step, last) {

View file

@ -67,17 +67,17 @@ fn sleep(args: Vec<StrBuf>) {
let (arg, suffix_time) = match match_suffix(arg.as_slice()) { 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.to_strbuf())
} }
}; };
let num = let num =
if suffix_time == 0 { if suffix_time == 0 {
0.0 0.0
} else { } else {
match num::from_str_radix::<f64>((arg), 10) { match num::from_str_radix::<f64>((arg.as_slice()), 10) {
Some(m) => m, Some(m) => m,
None => { None => {
crash!(1, "Invalid time interval '{}'", arg) crash!(1, "Invalid time interval '{}'", arg.to_strbuf())
} }
} }
}; };
@ -86,7 +86,7 @@ fn sleep(args: Vec<StrBuf>) {
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<(StrBuf, int), StrBuf> {
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,
@ -94,7 +94,7 @@ fn match_suffix(arg: &str) -> Result<(~str, int), ~str> {
'd' | 'D' => 60 * 60 * 24, 'd' | 'D' => 60 * 60 * 24,
val => { val => {
if !val.is_alphabetic() { if !val.is_alphabetic() {
return Ok(((arg).to_owned(), 1)) return Ok((arg.to_strbuf(), 1))
} else { } else {
return Err(format!("Invalid time interval '{}'", arg)) return Err(format!("Invalid time interval '{}'", arg))
} }

View file

@ -79,21 +79,24 @@ fn tac(filenames: Vec<StrBuf>, before: bool, _: bool, separator: &str) {
} }
); );
let mut data = crash_if_err!(1, file.read_to_str()); let mut data = crash_if_err!(1, file.read_to_str());
if data.ends_with("\n") { if data.as_slice().ends_with("\n") {
// removes blank line that is inserted otherwise // removes blank line that is inserted otherwise
let mut buf = data.into_strbuf(); let mut buf = data.into_strbuf();
let len = buf.len(); let len = buf.len();
buf.truncate(len - 1); buf.truncate(len - 1);
data = buf.into_owned(); data = buf.into_owned();
} }
let split_vec: Vec<&str> = data.split_str(separator).collect(); let split_vec: Vec<&str> = data.as_slice().split_str(separator).collect();
let rev: ~str = split_vec.iter().rev().fold("".to_owned(), |a, &b| let rev: StrBuf = split_vec.iter().rev().fold(StrBuf::new(), |mut a, &b| {
a + if before { if before {
separator + b a.push_str(separator);
a.push_str(b);
} else { } else {
b + separator a.push_str(b);
a.push_str(separator);
} }
); a
});
print!("{}", rev); print!("{}", rev);
} }
} }

View file

@ -32,14 +32,14 @@ fn main() {
} }
struct Options { struct Options {
program: ~str, program: StrBuf,
append: bool, append: bool,
ignore_interrupts: bool, ignore_interrupts: bool,
print_and_exit: Option<~str>, print_and_exit: Option<StrBuf>,
files: Box<Vec<Path>> files: Box<Vec<Path>>
} }
fn options(args: &[~str]) -> Result<Options, ()> { fn options(args: &[StrBuf]) -> Result<Options, ()> {
let opts = ~[ let opts = ~[
optflag("a", "append", "append to the given FILEs, do not overwrite"), optflag("a", "append", "append to the given FILEs, do not overwrite"),
optflag("i", "ignore-interrupts", "ignore interrupt signals"), optflag("i", "ignore-interrupts", "ignore interrupt signals"),
@ -53,8 +53,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
let version = format!("{} {}", NAME, VERSION); let version = format!("{} {}", NAME, VERSION);
let program = args.get(0).as_slice(); 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.";
let comment = "If a FILE is -, copy again to standard output."; let comment = "If a FILE is -, copy again to standard output.";
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),
@ -64,7 +63,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
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.into_owned(), program: program.to_strbuf(),
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,
@ -75,7 +74,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
fn exec(options: Options) -> Result<(), ()> { fn exec(options: Options) -> Result<(), ()> {
match options.print_and_exit { match options.print_and_exit {
Some(text) => Ok(println(text)), Some(text) => Ok(println(text.as_slice())),
None => tee(options) None => tee(options)
} }
} }
@ -145,7 +144,7 @@ impl Reader for NamedReader {
fn with_path<T>(path: &Path, cb: || -> IoResult<T>) -> IoResult<T> { fn with_path<T>(path: &Path, cb: || -> IoResult<T>) -> IoResult<T> {
match cb() { match cb() {
Err(f) => { warn(format!("{}: {}", path.display(), f.to_str())); Err(f) } Err(f) => { warn(format!("{}: {}", path.display(), f.to_str()).as_slice()); Err(f) }
okay => okay okay => okay
} }
} }

View file

@ -178,7 +178,7 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
} }
slice slice
}.to_owned().into_bytes(); }.to_owned().into_bytes();
let mut number = match u64::parse_bytes(bytes, 10) { let mut number = match u64::parse_bytes(bytes.as_slice(), 10) {
Some(num) => num, Some(num) => num,
None => { None => {
crash!(1, "'{}' is not a valid number.", size) crash!(1, "'{}' is not a valid number.", size)

View file

@ -55,8 +55,8 @@ fn main () {
let tty = unsafe { str::raw::from_c_str(ttyname(libc::STDIN_FILENO)) }; let tty = unsafe { str::raw::from_c_str(ttyname(libc::STDIN_FILENO)) };
if !silent { if !silent {
if !tty.is_whitespace() { if !tty.as_slice().is_whitespace() {
println(tty); println(tty.as_slice());
} else { } else {
println!("not a tty"); println!("not a tty");
} }

View file

@ -27,11 +27,11 @@ use c_types::utsname;
#[path = "../common/c_types.rs"] mod c_types; #[path = "../common/c_types.rs"] mod c_types;
struct utsrust { struct utsrust {
sysname: ~str, sysname: StrBuf,
nodename: ~str, nodename: StrBuf,
release: ~str, release: StrBuf,
version: ~str, version: StrBuf,
machine: ~str machine: StrBuf
} }
extern { extern {
@ -81,24 +81,24 @@ fn main() {
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_strbuf(), "release".to_strbuf(), "version".to_strbuf(), "machine".to_strbuf()]) { || !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.as_slice());
output.push_str(" "); output.push_str(" ");
} }
if matches.opt_present("nodename") || matches.opt_present("all") { if matches.opt_present("nodename") || matches.opt_present("all") {
output.push_str(uname.nodename); output.push_str(uname.nodename.as_slice());
output.push_str(" "); output.push_str(" ");
} }
if matches.opt_present("release") || matches.opt_present("all") { if matches.opt_present("release") || matches.opt_present("all") {
output.push_str(uname.release); output.push_str(uname.release.as_slice());
output.push_str(" "); output.push_str(" ");
} }
if matches.opt_present("version") || matches.opt_present("all") { if matches.opt_present("version") || matches.opt_present("all") {
output.push_str(uname.version); output.push_str(uname.version.as_slice());
output.push_str(" "); output.push_str(" ");
} }
if matches.opt_present("machine") || matches.opt_present("all") { if matches.opt_present("machine") || matches.opt_present("all") {
output.push_str(uname.machine); output.push_str(uname.machine.as_slice());
output.push_str(" "); output.push_str(" ");
} }
println!("{}", output.as_slice().trim_left()) println!("{}", output.as_slice().trim_left())

View file

@ -167,8 +167,8 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
} }
}; };
match uptime_text.words().next() { match uptime_text.as_slice().words().next() {
Some(s) => match from_str(s.replace(".","")) { Some(s) => match from_str(s.replace(".","").as_slice()) {
Some(n) => n, Some(n) => n,
None => -1 None => -1
}, },

View file

@ -23,7 +23,7 @@ use getopts::Matches;
mod util; mod util;
struct Result { struct Result {
filename: ~str, filename: StrBuf,
bytes: uint, bytes: uint,
chars: uint, chars: uint,
lines: uint, lines: uint,
@ -155,7 +155,7 @@ pub fn wc(files: Vec<StrBuf>, matches: &Matches) {
} }
results.push(Result { results.push(Result {
filename: path.as_slice().to_owned(), filename: path.to_strbuf(),
bytes: byte_count, bytes: byte_count,
chars: char_count, chars: char_count,
lines: line_count, lines: line_count,
@ -177,15 +177,15 @@ pub fn wc(files: Vec<StrBuf>, matches: &Matches) {
} }
for result in results.iter() { for result in results.iter() {
print_stats(&result.filename, result.lines, result.words, result.chars, result.bytes, result.max_line_length, matches, max_str_len); print_stats(result.filename.as_slice(), result.lines, result.words, result.chars, result.bytes, result.max_line_length, matches, max_str_len);
} }
if files.len() > 1 { if files.len() > 1 {
print_stats(&"total".to_owned(), total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len); print_stats("total", total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len);
} }
} }
fn print_stats(filename: &~str, line_count: uint, word_count: uint, char_count: uint, fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint,
byte_count: uint, longest_line_length: uint, matches: &Matches, max_str_len: uint) { byte_count: uint, longest_line_length: uint, matches: &Matches, max_str_len: uint) {
if matches.opt_present("lines") { if matches.opt_present("lines") {
print!("{:1$}", line_count, max_str_len); print!("{:1$}", line_count, max_str_len);
@ -214,16 +214,16 @@ fn print_stats(filename: &~str, line_count: uint, word_count: uint, char_count:
print!("{:1$}", byte_count, max_str_len + 1); print!("{:1$}", byte_count, max_str_len + 1);
} }
if *filename != "-".to_owned() { if filename != "-" {
println!(" {}", *filename); println!(" {}", filename.as_slice());
} }
else { else {
println!(""); println!("");
} }
} }
fn open(path: ~str) -> Option<BufferedReader<Box<Reader>>> { fn open(path: StrBuf) -> Option<BufferedReader<Box<Reader>>> {
if "-" == path { if "-" == path.as_slice() {
let reader = box stdin() as Box<Reader>; let reader = box stdin() as Box<Reader>;
return Some(BufferedReader::new(reader)); return Some(BufferedReader::new(reader));
} }

View file

@ -30,7 +30,7 @@ extern {
pub fn geteuid() -> libc::c_int; pub fn geteuid() -> libc::c_int;
} }
unsafe fn getusername() -> ~str { unsafe fn getusername() -> StrBuf {
let passwd: *c_passwd = getpwuid(geteuid()); let passwd: *c_passwd = getpwuid(geteuid());
let pw_name: *libc::c_char = (*passwd).pw_name; let pw_name: *libc::c_char = (*passwd).pw_name;

View file

@ -55,10 +55,10 @@ fn main() {
string = matches.free.connect(" "); string = matches.free.connect(" ");
} }
exec(string); exec(string.as_slice());
} }
pub fn exec(string: ~str) { pub fn exec(string: &str) {
loop { loop {
println(string); println(string);
} }