Merge pull request #451 from ebfe/fix-build-master

Fix build with rust master
This commit is contained in:
Heather 2014-11-20 07:48:10 +04:00
commit b58f597ba1
67 changed files with 388 additions and 389 deletions

View file

@ -44,7 +44,7 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("h", "help", "display this help text and exit"),
optflag("V", "version", "output version information and exit")
];
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => {
error!("error: {}", e);
@ -53,15 +53,15 @@ pub fn uumain(args: Vec<String>) -> int {
};
let progname = args[0].clone();
let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", opts);
let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", &opts);
let mode = if matches.opt_present("help") {
Help
Mode::Help
} else if matches.opt_present("version") {
Version
Mode::Version
} else if matches.opt_present("decode") {
Decode
Mode::Decode
} else {
Encode
Mode::Encode
};
let ignore_garbage = matches.opt_present("ignore-garbage");
let line_wrap = match matches.opt_str("wrap") {
@ -86,10 +86,10 @@ pub fn uumain(args: Vec<String>) -> int {
};
match mode {
Decode => decode(input, ignore_garbage),
Encode => encode(input, line_wrap),
Help => help(progname.as_slice(), usage.as_slice()),
Version => version()
Mode::Decode => decode(input, ignore_garbage),
Mode::Encode => encode(input, line_wrap),
Mode::Help => help(progname.as_slice(), usage.as_slice()),
Mode::Version => version()
}
0

View file

@ -32,7 +32,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -43,7 +43,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Print NAME with any leading directory components removed.");
println!("If specified, also remove a trailing SUFFIX.");
print(getopts::usage("", opts).as_slice());
print(getopts::usage("", &opts).as_slice());
return 0;
}

View file

@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => panic!("Invalid options\n{}", f)
};
@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print(getopts::usage("Concatenate FILE(s), or standard input, to \
standard output.", opts).as_slice());
standard output.", &opts).as_slice());
println!("");
println!("With no FILE, or when FILE is -, read standard input.");
return 0;
@ -57,18 +57,18 @@ pub fn uumain(args: Vec<String>) -> int {
return 0;
}
let mut number_mode = NumberNone;
let mut number_mode = NumberingMode::NumberNone;
if matches.opt_present("n") {
number_mode = NumberAll;
number_mode = NumberingMode::NumberAll;
}
if matches.opt_present("b") {
number_mode = NumberNonEmpty;
number_mode = NumberingMode::NumberNonEmpty;
}
let show_nonprint = matches.opts_present(["A".to_string(), "e".to_string(),
let show_nonprint = matches.opts_present(&["A".to_string(), "e".to_string(),
"t".to_string(), "v".to_string()]);
let show_ends = matches.opts_present(["E".to_string(), "A".to_string(),
let show_ends = matches.opts_present(&["E".to_string(), "A".to_string(),
"e".to_string()]);
let show_tabs = matches.opts_present(["A".to_string(), "T".to_string(),
let show_tabs = matches.opts_present(&["A".to_string(), "T".to_string(),
"t".to_string()]);
let squeeze_blank = matches.opt_present("s");
let mut files = matches.free;
@ -104,7 +104,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
let mut writer = UnsafeWriter::new(out_buf.as_mut_slice(), stdout_raw());
let mut at_line_start = true;
loop {
let n = match reader.read(in_buf) {
let n = match reader.read(&mut in_buf) {
Ok(n) if n != 0 => n,
_ => break,
};
@ -118,7 +118,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
};
if in_buf[pos] == '\n' as u8 {
if !at_line_start || !squeeze_blank {
if at_line_start && number == NumberAll {
if at_line_start && number == NumberingMode::NumberAll {
(write!(&mut writer, "{0:6u}\t", line_counter)).unwrap();
line_counter += 1;
}
@ -133,7 +133,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
at_line_start = true;
continue;
}
if at_line_start && number != NumberNone {
if at_line_start && number != NumberingMode::NumberNone {
(write!(&mut writer, "{0:6u}\t", line_counter)).unwrap();
line_counter += 1;
}
@ -180,7 +180,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
let mut writer = UnsafeWriter::new(out_buf.as_mut_slice(), stdout_raw());
let mut at_line_start = true;
loop {
let n = match reader.read(in_buf) {
let n = match reader.read(&mut in_buf) {
Ok(n) if n != 0 => n,
_ => break,
};
@ -191,7 +191,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
}
if byte == '\n' as u8 {
if !at_line_start || !squeeze_blank {
if at_line_start && number == NumberAll {
if at_line_start && number == NumberingMode::NumberAll {
(write!(&mut writer, "{0:6u}\t", line_counter)).unwrap();
line_counter += 1;
}
@ -206,7 +206,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
at_line_start = true;
continue;
}
if at_line_start && number != NumberNone {
if at_line_start && number != NumberingMode::NumberNone {
(write!(&mut writer, "{0:6u}\t", line_counter)).unwrap();
line_counter += 1;
at_line_start = false;
@ -228,8 +228,8 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
_ => byte,
};
match byte {
0 ... 31 => writer.write(['^' as u8, byte + 64]),
127 => writer.write(['^' as u8, byte - 64]),
0 ... 31 => writer.write(&['^' as u8, byte + 64]),
127 => writer.write(&['^' as u8, byte - 64]),
_ => writer.write_u8(byte),
}
} else {
@ -251,7 +251,7 @@ fn write_fast(files: Vec<String>) {
};
loop {
match reader.read(in_buf) {
match reader.read(&mut in_buf) {
Ok(n) if n != 0 => {
// This interface is completely broken.
writer.write(in_buf.slice_to(n)).unwrap();
@ -267,7 +267,7 @@ fn exec(files: Vec<String>, number: NumberingMode, show_nonprint: bool,
if show_nonprint || show_tabs {
write_bytes(files, number, squeeze_blank, show_ends, show_nonprint, show_tabs);
} else if number != NumberNone || squeeze_blank || show_ends {
} else if number != NumberingMode::NumberNone || squeeze_blank || show_ends {
write_lines(files, number, squeeze_blank, show_ends);
} else {
write_fast(files);

View file

@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit")
];
// TODO: sanitize input for - at beginning (e.g. chmod -x testfile). Solution is to add a to -x, making a-x
let mut matches = match getopts::getopts(args.tail(), opts) {
let mut matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "{}", f)
@ -66,7 +66,7 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
name = NAME, version = VERSION, program = program,
usage = getopts::usage("Change the mode of each FILE to MODE. \
With --reference, change the mode of \
each FILE to that of RFILE.", opts));
each FILE to that of RFILE.", &opts));
} else if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.free.is_empty() && matches.opt_present("reference") || matches.free.len() < 2 {

View file

@ -51,17 +51,17 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "Show program's version")
];
let opts = match getopts(args.tail(), options) {
let opts = match getopts(args.tail(), &options) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
help_menu(program.as_slice(), options);
help_menu(program.as_slice(), &options);
return 1
}
};
if opts.opt_present("V") { version(); return 0 }
if opts.opt_present("h") { help_menu(program.as_slice(), options); return 0 }
if opts.opt_present("h") { help_menu(program.as_slice(), &options); return 0 }
if opts.free.len() == 0 {
println!("Missing operand: NEWROOT");
@ -126,9 +126,7 @@ fn set_context(root: &Path, options: &getopts::Matches) {
fn enter_chroot(root: &Path) {
let root_str = root.display();
if !std::os::change_dir(root) {
crash!(1, "cannot chdir to {}", root_str)
};
std::os::change_dir(root).unwrap();
let err = unsafe {
chroot(".".to_c_str().unwrap() as *const libc::c_char)
};

View file

@ -61,7 +61,7 @@ fn cksum(fname: &str) -> IoResult<(u32, uint)> {
let mut bytes: [u8, ..1024 * 1024] = unsafe { mem::uninitialized() };
loop {
match rd.read(bytes) {
match rd.read(&mut bytes) {
Ok(num_bytes) => {
for &b in bytes.slice_to(num_bytes).iter() {
crc = crc_update(crc, b);
@ -80,7 +80,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};

View file

@ -52,8 +52,8 @@ enum LineReader {
impl LineReader {
fn read_line(&mut self) -> IoResult<String> {
match self {
&Stdin(ref mut r) => r.read_line(),
&FileIn(ref mut r) => r.read_line(),
&LineReader::Stdin(ref mut r) => r.read_line(),
&LineReader::FileIn(ref mut r) => r.read_line(),
}
}
}
@ -117,7 +117,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};

View file

@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("h", "help", "display this help and exit"),
optflag("", "version", "output version information and exit"),
];
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => {
error!("error: {}", e);
@ -45,19 +45,19 @@ pub fn uumain(args: Vec<String>) -> int {
};
let progname = &args[0];
let usage = usage("Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", opts);
let usage = usage("Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", &opts);
let mode = if matches.opt_present("version") {
Version
Mode::Version
} else if matches.opt_present("help") {
Help
Mode::Help
} else {
Copy
Mode::Copy
};
match mode {
Copy => copy(matches),
Help => help(progname.as_slice(), usage.as_slice()),
Version => version(),
Mode::Copy => copy(matches),
Mode::Help => help(progname.as_slice(), usage.as_slice()),
Mode::Version => version(),
}
0
@ -168,12 +168,12 @@ pub fn paths_refer_to_same_file(p1: &Path, p2: &Path) -> io::IoResult<bool> {
if p1_lstat.kind == io::TypeSymlink {
raw_p1 = fs::readlink(&raw_p1).unwrap();
}
raw_p1 = os::make_absolute(&raw_p1);
raw_p1 = os::make_absolute(&raw_p1).unwrap();
if p2_lstat.kind == io::TypeSymlink {
raw_p2 = fs::readlink(&raw_p2).unwrap();
}
raw_p2 = os::make_absolute(&raw_p2);
raw_p2 = os::make_absolute(&raw_p2).unwrap();
Ok(raw_p1 == raw_p2)
}

View file

@ -99,7 +99,7 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
}
let newline_idx = match self.end - self.start {
0 => return Bytes::EndOfFile,
0 => return Bytes::Selected::EndOfFile,
buf_used if bytes < buf_used => {
// because the output delimiter should only be placed between
// segments check if the byte after bytes is a newline
@ -114,7 +114,7 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
self.start += bytes;
return Bytes::Complete(segment);
return Bytes::Selected::Complete(segment);
}
}
}
@ -129,7 +129,7 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
self.start = 0;
self.end = 0;
return Bytes::Partial(segment);
return Bytes::Selected::Partial(segment);
}
}
}
@ -139,6 +139,6 @@ impl<R: Reader> Bytes::Select for BufReader<R> {
let segment = self.buffer.slice(self.start, new_start);
self.start = new_start;
Bytes::NewlineFound(segment)
Bytes::Selected::NewlineFound(segment)
}
}

View file

@ -55,7 +55,8 @@ fn list_to_ranges(list: &str, complement: bool) -> Result<Vec<Range>, String> {
fn cut_bytes<R: Reader>(reader: R,
ranges: &Vec<Range>,
opts: &Options) -> int {
use buffer::Bytes::{Select, NewlineFound, Complete, Partial, EndOfFile};
use buffer::Bytes::Select;
use buffer::Bytes::Selected::{NewlineFound, Complete, Partial, EndOfFile};
let mut buf_read = buffer::BufReader::new(reader);
let mut out = BufferedWriter::new(stdio::stdout_raw());
@ -126,7 +127,7 @@ fn cut_bytes<R: Reader>(reader: R,
}
buf_read.consume_line();
out.write([b'\n']).unwrap();
out.write(&[b'\n']).unwrap();
}
0
@ -261,7 +262,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
if ! only_delimited {
out.write(line.as_slice()).unwrap();
if line[line.len() - 1] != b'\n' {
out.write([b'\n']).unwrap();
out.write(&[b'\n']).unwrap();
}
}
@ -343,7 +344,7 @@ fn cut_fields<R: Reader>(reader: R,
if ! opts.only_delimited {
out.write(line.as_slice()).unwrap();
if line[line.len() - 1] != b'\n' {
out.write([b'\n']).unwrap();
out.write(&[b'\n']).unwrap();
}
}
@ -404,13 +405,13 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> int {
if stdin_read { continue }
exit_code |= match mode {
Bytes(ref ranges, ref opts) => {
Mode::Bytes(ref ranges, ref opts) => {
cut_bytes(stdio::stdin_raw(), ranges, opts)
}
Characters(ref ranges, ref opts) => {
Mode::Characters(ref ranges, ref opts) => {
cut_characters(stdio::stdin_raw(), ranges, opts)
}
Fields(ref ranges, ref opts) => {
Mode::Fields(ref ranges, ref opts) => {
cut_fields(stdio::stdin_raw(), ranges, opts)
}
};
@ -433,11 +434,11 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> int {
};
exit_code |= match mode {
Bytes(ref ranges, ref opts) => cut_bytes(file, ranges, opts),
Characters(ref ranges, ref opts) => {
Mode::Bytes(ref ranges, ref opts) => cut_bytes(file, ranges, opts),
Mode::Characters(ref ranges, ref opts) => {
cut_characters(file, ranges, opts)
}
Fields(ref ranges, ref opts) => cut_fields(file, ranges, opts)
Mode::Fields(ref ranges, ref opts) => cut_fields(file, ranges, opts)
};
}
}
@ -459,7 +460,7 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("", "version", "output version information and exit"),
];
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
show_error!("Invalid options\n{}", f)
@ -471,7 +472,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0} OPTION... [FILE]...", args[0]);
println!("");
print(usage("Print selected parts of lines from each FILE to standard output.", opts).as_slice());
print(usage("Print selected parts of lines from each FILE to standard output.", &opts).as_slice());
println!("");
println!("Use one, and only one of -b, -c or -f. Each LIST is made up of one");
println!("range, or many ranges separated by commas. Selected input is written");
@ -499,13 +500,13 @@ pub fn uumain(args: Vec<String>) -> int {
matches.opt_str("fields")) {
(Some(byte_ranges), None, None) => {
list_to_ranges(byte_ranges.as_slice(), complement).map(|ranges|
Bytes(ranges,
Mode::Bytes(ranges,
Options { out_delim: matches.opt_str("output-delimiter") })
)
}
(None, Some(char_ranges), None) => {
list_to_ranges(char_ranges.as_slice(), complement).map(|ranges|
Characters(ranges,
Mode::Characters(ranges,
Options { out_delim: matches.opt_str("output-delimiter") })
)
}
@ -520,7 +521,7 @@ pub fn uumain(args: Vec<String>) -> int {
if delim.as_slice().char_len() != 1 {
Err("the delimiter must be a single character".to_string())
} else {
Ok(Fields(ranges,
Ok(Mode::Fields(ranges,
FieldOptions {
delimiter: delim,
out_delimeter: out_delim,
@ -528,7 +529,7 @@ pub fn uumain(args: Vec<String>) -> int {
}))
}
}
None => Ok(Fields(ranges,
None => Ok(Mode::Fields(ranges,
FieldOptions {
delimiter: "\t".to_string(),
out_delimeter: out_delim,

View file

@ -23,7 +23,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => panic!("Invalid options\n{}", f)
};
@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> int {
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).as_slice());
directory).", &opts).as_slice());
return 0;
}

View file

@ -157,7 +157,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
show_error!("Invalid options\n{}", f);
@ -184,7 +184,7 @@ Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (pow
ers of 1000).",
program = program,
version = VERSION,
usage = getopts::usage("Summarize disk usage of each FILE, recursively for directories.", opts));
usage = getopts::usage("Summarize disk usage of each FILE, recursively for directories.", &opts));
return 0;
} else if matches.opt_present("version") {
println!("{} version: {}", program, VERSION);

View file

@ -142,7 +142,7 @@ fn print_help(program: &String) {
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).as_slice());
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

View file

@ -82,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -91,7 +91,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage: {:s} [OPTION]... [FILE]...", NAME);
io::print(getopts::usage(
"Convert tabs in each FILE to spaces, writing to standard output.\n\
With no FILE, or when FILE is -, read standard input.", opts).as_slice());
With no FILE, or when FILE is -, read standard input.", &opts).as_slice());
return 0;
}

View file

@ -69,7 +69,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("v", "version", "print the version and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -82,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> int {
\t{program} [OPTION]\n\
\n\
{usage}", program = program, version = VERSION, usage = getopts::usage("Print the prime factors of the given number(s). \
If none are specified, read from standard input.", opts));
If none are specified, read from standard input.", &opts));
return 1;
}
if matches.opt_present("version") {

View file

@ -9,11 +9,10 @@
use FmtOptions;
use parasplit::{Paragraph, ParaWords, WordInfo};
use std::num::{Float, SignedInt};
use std::num::{Float, Int, SignedInt};
use std::i64;
use std::cmp;
use std::mem;
use std::num;
struct BreakArgs<'a> {
opts : &'a FmtOptions,
@ -373,7 +372,7 @@ fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (
// we penalize lines that have very different ratios from previous lines
let bad_delta_r = (DR_MULT * (((ratio - prev_rat) / 2.0).powf(3f32)).abs()) as i64;
let demerits = num::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2);
let demerits = Int::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2);
(demerits, ratio)
}

View file

@ -40,16 +40,16 @@ impl Line {
// when we know that it's a FormatLine, as in the ParagraphStream iterator
fn get_formatline(self) -> FileLine {
match self {
FormatLine(fl) => fl,
NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine")
Line::FormatLine(fl) => fl,
Line::NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine")
}
}
// when we know that it's a NoFormatLine, as in the ParagraphStream iterator
fn get_noformatline(self) -> (String, bool) {
match self {
NoFormatLine(s, b) => (s, b),
FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine")
Line::NoFormatLine(s, b) => (s, b),
Line::FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine")
}
}
}
@ -154,34 +154,34 @@ impl<'a> Iterator<Line> for FileLines<'a> {
// Err(true) indicates that this was a linebreak,
// which is important to know when detecting mail headers
if n.as_slice().is_whitespace() {
return Some(NoFormatLine("\n".to_string(), true));
return Some(Line::NoFormatLine("\n".to_string(), true));
}
// if this line does not match the prefix,
// emit the line unprocessed and iterate again
let (pmatch, poffset) = self.match_prefix(n.as_slice());
if !pmatch {
return Some(NoFormatLine(n, false));
return Some(Line::NoFormatLine(n, false));
} else if n.as_slice().slice_from(poffset + self.opts.prefix.len()).is_whitespace() {
// if the line matches the prefix, but is blank after,
// don't allow lines to be combined through it (that is,
// treat it like a blank line, except that since it's
// not truly blank we will not allow mail headers on the
// following line)
return Some(NoFormatLine(n, false));
return Some(Line::NoFormatLine(n, false));
}
// skip if this line matches the anti_prefix
// (NOTE definition of match_anti_prefix is TRUE if we should process)
if !self.match_anti_prefix(n.as_slice()) {
return Some(NoFormatLine(n, false));
return Some(Line::NoFormatLine(n, false));
}
// figure out the indent, prefix, and prefixindent ending points
let prefix_end = poffset + self.opts.prefix.len();
let (indent_end, prefix_len, indent_len) = self.compute_indent(n.as_slice(), prefix_end);
Some(FormatLine(FileLine {
Some(Line::FormatLine(FileLine {
line : n,
indent_end : indent_end,
pfxind_end : poffset,
@ -259,8 +259,8 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
match self.lines.peek() {
None => return None,
Some(l) => match l {
&FormatLine(_) => false,
&NoFormatLine(_, _) => true
&Line::FormatLine(_) => false,
&Line::NoFormatLine(_, _) => true
}
};
@ -292,8 +292,8 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
None => break,
Some(l) => {
match l {
&FormatLine(ref x) => x,
&NoFormatLine(..) => break
&Line::FormatLine(ref x) => x,
&Line::NoFormatLine(..) => break
}
}
};

View file

@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {} [OPTION]... [FILE]...", program);
println!("");
print!("{}", getopts::usage("Writes each file (or standard input if no files are given) to standard output whilst breaking long lines", opts));
print!("{}", getopts::usage("Writes each file (or standard input if no files are given) to standard output whilst breaking long lines", &opts));
} else if matches.opt_present("V") {
println!("{} v{}", NAME, VERSION);
} else {

View file

@ -33,7 +33,7 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "display version information and exit")
];
let matches = match getopts(args.tail(), options) {
let matches = match getopts(args.tail(), &options) {
Ok(m) => { m },
Err(f) => {
show_error!("{}", f);
@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
print!("{} v{}\n\n\
Usage:\n \
{} [OPTION]... [USER]...\n\n\
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", options));
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", &options));
} else {
group(get_pw_from_args(&matches.free), true);
}

View file

@ -273,7 +273,7 @@ fn digest_reader(digest: &mut Box<Digest>, reader: &mut Reader, binary: bool) ->
let mut vec = Vec::with_capacity(524288);
let mut looking_for_newline = false;
loop {
match reader.read(buffer) {
match reader.read(&mut buffer) {
Ok(0) => {},
Ok(nread) => {
if windows && !binary {

View file

@ -46,16 +46,16 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "version")
];
let given_options = match getopts(args.as_slice(), possible_options) {
let given_options = match getopts(args.as_slice(), &possible_options) {
Ok (m) => { m }
Err(_) => {
println!("{:s}", usage(NAME, possible_options));
println!("{:s}", usage(NAME, &possible_options));
return 1;
}
};
if given_options.opt_present("h") {
println!("{:s}", usage(NAME, possible_options));
println!("{:s}", usage(NAME, &possible_options));
return 0;
}
if given_options.opt_present("V") { version(); return 0 }

View file

@ -54,10 +54,10 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("", "version", "output version information and exit"),
];
let usage = usage("[options]", opts);
let usage = usage("[options]", &opts);
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => {
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_slice()));
@ -66,17 +66,17 @@ pub fn uumain(args: Vec<String>) -> int {
};
let mode = if matches.opt_present("version") {
Version
Mode::Version
} else if matches.opt_present("help") {
Help
Mode::Help
} else {
HostId
Mode::HostId
};
match mode {
HostId => hostid(),
Help => help(NAME, usage.as_slice()),
Version => version(),
Mode::HostId => hostid(),
Mode::Help => help(NAME, usage.as_slice()),
Mode::Version => version(),
}
0

View file

@ -53,13 +53,13 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "Show program's version")
];
let matches = match getopts(args.tail(), options) {
let matches = match getopts(args.tail(), &options) {
Ok(m) => { m }
_ => { help_menu(program.as_slice(), options); return 0; }
_ => { help_menu(program.as_slice(), &options); return 0; }
};
if matches.opt_present("h") {
help_menu(program.as_slice(), options);
help_menu(program.as_slice(), &options);
return 0
}
if matches.opt_present("V") { version(); return 0 }
@ -110,7 +110,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
}
1 => xsethostname(matches.free.last().unwrap().as_slice()),
_ => help_menu(program.as_slice(), options)
_ => help_menu(program.as_slice(), &options)
};
0

View file

@ -100,16 +100,16 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("u", "", "Display the effective user ID as a number")
];
let matches = match getopts(args_t, options) {
let matches = match getopts(args_t, &options) {
Ok(m) => { m },
Err(_) => {
println!("{:s}", usage(NAME, options));
println!("{:s}", usage(NAME, &options));
return 1;
}
};
if matches.opt_present("h") {
println!("{:s}", usage(NAME, options));
println!("{:s}", usage(NAME, &options));
return 0;
}

View file

@ -61,11 +61,11 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("L", "table", "list all signal names in a nice table"),
];
let usage = usage("[options] <pid> [...]", opts);
let usage = usage("[options] <pid> [...]", &opts);
let (args, obs_signal) = handle_obsolete(args);
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => {
show_error!("{}\n{}", e, get_help_text(NAME, usage.as_slice()));
@ -74,23 +74,23 @@ pub fn uumain(args: Vec<String>) -> int {
};
let mode = if matches.opt_present("version") {
Version
Mode::Version
} else if matches.opt_present("help") {
Help
Mode::Help
} else if matches.opt_present("table") {
Table
Mode::Table
} else if matches.opt_present("list") {
List
Mode::List
} else {
Kill
Mode::Kill
};
match mode {
Kill => return kill(matches.opt_str("signal").unwrap_or(obs_signal.unwrap_or("9".to_string())).as_slice(), matches.free),
Table => table(),
List => list(matches.opt_str("list")),
Help => help(NAME, usage.as_slice()),
Version => version(),
Mode::Kill => return kill(matches.opt_str("signal").unwrap_or(obs_signal.unwrap_or("9".to_string())).as_slice(), matches.free),
Mode::Table => table(),
Mode::List => list(matches.opt_str("list")),
Mode::Help => help(NAME, usage.as_slice()),
Mode::Version => version(),
}
0

View file

@ -27,7 +27,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};

View file

@ -53,7 +53,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {:s}", program);
println!("");
print(getopts::usage("print user's login name", opts).as_slice());
print(getopts::usage("print user's login name", &opts).as_slice());
return 0;
}
if matches.opt_present("version") {

View file

@ -41,7 +41,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "display this version")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "Invalid options\n{}", f);
@ -49,7 +49,7 @@ pub fn uumain(args: Vec<String>) -> int {
};
if args.len() == 1 || matches.opt_present("help") {
print_help(opts);
print_help(&opts);
return 0;
}
if matches.opt_present("version") {

View file

@ -30,7 +30,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => panic!("{}", err),
};

View file

@ -79,14 +79,14 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "output version information and exit"),
];
let matches = match getopts(args.tail(), opts) {
let matches = match getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
show_error!("Invalid options\n{}", f);
return 1;
}
};
let usage = usage("Move SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", opts);
let usage = usage("Move SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", &opts);
/* This does not exactly match the GNU implementation:
* The GNU mv defaults to Force, but if more than one of the
@ -94,23 +94,23 @@ pub fn uumain(args: Vec<String>) -> int {
* To default to no-clobber in that situation seems safer:
*/
let overwrite_mode = if matches.opt_present("no-clobber") {
NoClobber
OverwriteMode::NoClobber
} else if matches.opt_present("interactive") {
Interactive
OverwriteMode::Interactive
} else {
Force
OverwriteMode::Force
};
let backup_mode = if matches.opt_present("b") {
SimpleBackup
BackupMode::SimpleBackup
} else if matches.opt_present("backup") {
match matches.opt_str("backup") {
None => SimpleBackup,
None => BackupMode::SimpleBackup,
Some(mode) => match mode.as_slice() {
"simple" | "never" => SimpleBackup,
"numbered" | "t" => NumberedBackup,
"existing" | "nil" => ExistingBackup,
"none" | "off" => NoBackup,
"simple" | "never" => BackupMode::SimpleBackup,
"numbered" | "t" => BackupMode::NumberedBackup,
"existing" | "nil" => BackupMode::ExistingBackup,
"none" | "off" => BackupMode::NoBackup,
x => {
show_error!("invalid argument {} for backup type\n\
Try 'mv --help' for more information.", x);
@ -119,10 +119,10 @@ pub fn uumain(args: Vec<String>) -> int {
}
}
} else {
NoBackup
BackupMode::NoBackup
};
if overwrite_mode == NoClobber && backup_mode != NoBackup {
if overwrite_mode == OverwriteMode::NoClobber && backup_mode != BackupMode::NoBackup {
show_error!("options --backup and --no-clobber are mutually exclusive\n\
Try 'mv --help' for more information.");
return 1;
@ -276,21 +276,21 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
if to.exists() {
match b.overwrite {
NoClobber => return Ok(()),
Interactive => {
OverwriteMode::NoClobber => return Ok(()),
OverwriteMode::Interactive => {
print!("{}: overwrite {}? ", NAME, to.display());
if !read_yes() {
return Ok(());
}
},
Force => {}
OverwriteMode::Force => {}
};
backup_path = match b.backup {
NoBackup => None,
SimpleBackup => Some(simple_backup_path(to, &b.suffix)),
NumberedBackup => Some(numbered_backup_path(to)),
ExistingBackup => Some(existing_backup_path(to, &b.suffix))
BackupMode::NoBackup => None,
BackupMode::SimpleBackup => Some(simple_backup_path(to, &b.suffix)),
BackupMode::NumberedBackup => Some(numbered_backup_path(to)),
BackupMode::ExistingBackup => Some(existing_backup_path(to, &b.suffix))
};
if let Some(ref p) = backup_path {
try!(fs::rename(to, p));
@ -318,7 +318,7 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
fn read_yes() -> bool {
match BufferedReader::new(stdin_raw()).read_line() {
Ok(s) => match s.as_slice().slice_shift_char() {
(Some(x), _) => x == 'y' || x == 'Y',
Some((x, _)) => x == 'y' || x == 'Y',
_ => false
},
_ => false

View file

@ -4,12 +4,12 @@ extern crate regex;
// parse_style parses a style string into a NumberingStyle.
fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> {
match chars {
['a'] => { Ok(::NumberForAll) },
['t'] => { Ok(::NumberForNonEmpty) },
['n'] => { Ok(::NumberForNone) },
['a'] => { Ok(::NumberingStyle::NumberForAll) },
['t'] => { Ok(::NumberingStyle::NumberForNonEmpty) },
['n'] => { Ok(::NumberingStyle::NumberForNone) },
['p', rest..] => {
match regex::Regex::new(String::from_chars(rest).as_slice()) {
Ok(re) => Ok(::NumberForRegularExpression(re)),
Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)),
Err(_) => Err(String::from_str("Illegal regular expression")),
}
}
@ -32,9 +32,9 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
match opts.opt_str("n") {
None => {},
Some(val) => match val.as_slice() {
"ln" => { settings.number_format = ::Left; },
"rn" => { settings.number_format = ::Right; },
"rz" => { settings.number_format = ::RightZero; },
"ln" => { settings.number_format = ::NumberFormat::Left; },
"rn" => { settings.number_format = ::NumberFormat::Right; },
"rz" => { settings.number_format = ::NumberFormat::RightZero; },
_ => { errs.push(String::from_str("Illegal value for -n")); },
}
}

View file

@ -19,6 +19,7 @@ extern crate getopts;
use std::io::{stdin};
use std::io::BufferedReader;
use std::io::fs::File;
use std::num::Int;
use std::path::Path;
use getopts::{optopt, optflag, getopts, usage, OptGroup};
@ -93,30 +94,30 @@ pub fn uumain(args: Vec<String>) -> int {
// A mutable settings object, initialized with the defaults.
let mut settings = Settings {
header_numbering: NumberForNone,
body_numbering: NumberForAll,
footer_numbering: NumberForNone,
header_numbering: NumberingStyle::NumberForNone,
body_numbering: NumberingStyle::NumberForAll,
footer_numbering: NumberingStyle::NumberForNone,
section_delimiter: ['\\', ':'],
starting_line_number: 1,
line_increment: 1,
join_blank_lines: 1,
number_width: 6,
number_format: Right,
number_format: NumberFormat::Right,
renumber: true,
number_separator: String::from_str("\t"),
};
let given_options = match getopts(args.tail(), possible_options) {
let given_options = match getopts(args.tail(), &possible_options) {
Ok (m) => { m }
Err(f) => {
show_error!("{}", f);
print_usage(possible_options);
print_usage(&possible_options);
return 1
}
};
if given_options.opt_present("help") {
print_usage(possible_options);
print_usage(&possible_options);
return 0;
}
if given_options.opt_present("version") { version(); return 0; }
@ -164,15 +165,15 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
let line_no_width_initial = line_no_width;
// Stores the smallest integer with one more digit than line_no, so that
// when line_no >= line_no_threshold, we need to use one more digit.
let mut line_no_threshold = std::num::pow(10u64, line_no_width);
let mut line_no_threshold = Int::pow(10u64, line_no_width);
let mut empty_line_count: u64 = 0;
let fill_char = match settings.number_format {
RightZero => '0',
NumberFormat::RightZero => '0',
_ => ' '
};
// Initially, we use the body's line counting settings
let mut regex_filter = match settings.body_numbering {
NumberForRegularExpression(ref re) => re,
NumberingStyle::NumberForRegularExpression(ref re) => re,
_ => REGEX_DUMMY,
};
let mut line_filter = pass_regex;
@ -226,7 +227,7 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
if settings.renumber {
line_no = settings.starting_line_number;
line_no_width = line_no_width_initial;
line_no_threshold = std::num::pow(10u64, line_no_width);
line_no_threshold = Int::pow(10u64, line_no_width);
}
&settings.header_numbering
},
@ -239,16 +240,16 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
&settings.body_numbering
}
} {
NumberForAll => {
NumberingStyle::NumberForAll => {
line_filter = pass_all;
},
NumberForNonEmpty => {
NumberingStyle::NumberForNonEmpty => {
line_filter = pass_nonempty;
},
NumberForNone => {
NumberingStyle::NumberForNone => {
line_filter = pass_none;
}
NumberForRegularExpression(ref re) => {
NumberingStyle::NumberForRegularExpression(ref re) => {
line_filter = pass_regex;
regex_filter = re;
}
@ -285,7 +286,7 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
}
let fill = String::from_char(w, fill_char);
match settings.number_format {
Left => {
NumberFormat::Left => {
println!("{1}{0}{2}{3}", fill, line_no, settings.number_separator, line)
},
_ => {

View file

@ -79,17 +79,17 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "Show version and exit"),
];
let opts = match getopts(args.tail(), options) {
let opts = match getopts(args.tail(), &options) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
show_usage(program.as_slice(), options);
show_usage(program.as_slice(), &options);
return 1
}
};
if opts.opt_present("V") { version(); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), options); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), &options); return 0 }
if opts.free.len() == 0 {
show_error!("Missing operand: COMMAND");

View file

@ -29,7 +29,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => {
show_error!("{}", err);
@ -48,7 +48,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {} [OPTIONS] NAME...", NAME);
println!("");
print!("{}", getopts::usage("Print the number of cores available to the current process.", opts));
print!("{}", getopts::usage("Print the number of cores available to the current process.", &opts));
return 0;
}

View file

@ -31,7 +31,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -41,7 +41,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print!("{}", getopts::usage("Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.", opts));
print!("{}", getopts::usage("Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output.", &opts));
} else if matches.opt_present("version") {
println!("{} {}", NAME, VERSION);
} else {

View file

@ -31,7 +31,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "Invalid options\n{}", f)
@ -43,7 +43,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [VARIABLE]... [OPTION]...", program);
println!("");
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts).as_slice());
print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", &opts).as_slice());
return 0;
}
if matches.opt_present("version") {

View file

@ -29,7 +29,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "Invalid options\n{}", f)
@ -42,14 +42,14 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION] NAME...", program);
println!("");
print(getopts::usage("Print the full filename of the current working directory.", opts).as_slice());
print(getopts::usage("Print the full filename of the current working directory.", &opts).as_slice());
} else if matches.opt_present("version") {
println!("pwd version: {}", VERSION);
return 0;
} else {
let cwd = std::os::getcwd();
println!("{}", cwd.display());
println!("{}", cwd.unwrap().display());
return 0;
}

View file

@ -30,17 +30,17 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("q", "quiet", "Do not print warnings for invalid paths"),
];
let opts = match getopts(args.tail(), options) {
let opts = match getopts(args.tail(), &options) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
show_usage(program.as_slice(), options);
show_usage(program.as_slice(), &options);
return 1
}
};
if opts.opt_present("V") { version(); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), options); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), &options); return 0 }
if opts.free.len() == 0 {
show_error!("Missing operand: FILENAME, at least one is required");
@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) -> int {
fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
let p = Path::new(path);
let abs = std::os::make_absolute(&p);
let abs = std::os::make_absolute(&p).unwrap();
if strip {
if zero {

View file

@ -28,17 +28,17 @@ pub fn uumain(args: Vec<String>) -> int {
optopt("d", "", "If any of FROM and TO is not subpath of DIR, output absolute path instead of relative", "DIR"),
];
let opts = match getopts(args.tail(), options) {
let opts = match getopts(args.tail(), &options) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
show_usage(program.as_slice(), options);
show_usage(program.as_slice(), &options);
return 1
}
};
if opts.opt_present("V") { version(); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), options); return 0 }
if opts.opt_present("h") { show_usage(program.as_slice(), &options); return 0 }
if opts.free.len() == 0 {
show_error!("Missing operand: TO");
@ -50,14 +50,14 @@ pub fn uumain(args: Vec<String>) -> int {
let from = if opts.free.len() > 1 {
Path::new(opts.free[1].as_slice())
} else {
std::os::getcwd()
std::os::getcwd().unwrap()
};
let absto = std::os::make_absolute(&to);
let absfrom = std::os::make_absolute(&from);
let absto = std::os::make_absolute(&to).unwrap();
let absfrom = std::os::make_absolute(&from).unwrap();
if opts.opt_present("d") {
let base = Path::new(opts.opt_str("d").unwrap());
let absbase = std::os::make_absolute(&base);
let absbase = std::os::make_absolute(&base).unwrap();
if !absbase.is_ancestor_of(&absto) || !absbase.is_ancestor_of(&absfrom) {
println!("{}", absto.display());
return 0

View file

@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "{}", f)
@ -59,7 +59,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print(getopts::usage("Remove (unlink) the FILE(s).", opts).as_slice());
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");
@ -83,27 +83,27 @@ pub fn uumain(args: Vec<String>) -> int {
let force = matches.opt_present("force");
let interactive =
if matches.opt_present("i") {
InteractiveAlways
InteractiveMode::InteractiveAlways
} else if matches.opt_present("I") {
InteractiveOnce
InteractiveMode::InteractiveOnce
} else if matches.opt_present("interactive") {
match matches.opt_str("interactive").unwrap().as_slice() {
"none" => InteractiveNone,
"once" => InteractiveOnce,
"always" => InteractiveAlways,
"none" => InteractiveMode::InteractiveNone,
"once" => InteractiveMode::InteractiveOnce,
"always" => InteractiveMode::InteractiveAlways,
val => {
crash!(1, "Invalid argument to interactive ({})", val)
}
}
} else {
InteractiveNone
InteractiveMode::InteractiveNone
};
let one_fs = matches.opt_present("one-file-system");
let preserve_root = !matches.opt_present("no-preserve-root");
let recursive = matches.opt_present("recursive");
let dir = matches.opt_present("dir");
let verbose = matches.opt_present("verbose");
if interactive == InteractiveOnce && (recursive || matches.free.len() > 3) {
if interactive == InteractiveMode::InteractiveOnce && (recursive || matches.free.len() > 3) {
let msg =
if recursive {
"Remove all arguments recursively? "
@ -169,7 +169,7 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> {
let response =
if interactive == InteractiveAlways {
if interactive == InteractiveMode::InteractiveAlways {
prompt_file(path, name)
} else {
true
@ -189,7 +189,7 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo
fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> {
let response =
if interactive == InteractiveAlways {
if interactive == InteractiveMode::InteractiveAlways {
prompt_file(path, name)
} else {
true

View file

@ -32,7 +32,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "print this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
@ -46,7 +46,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... DIRECTORY...", program);
println!("");
print(getopts::usage("Remove the DIRECTORY(ies), if they are empty.", opts).as_slice());
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() {

View file

@ -136,7 +136,7 @@ fn print_help(program: &String) {
];
println!("seq 1.0.0\n");
println!("Usage:\n {} [-w] [-s string] [-t string] [first [step]] last\n", *program);
println!("{:s}", getopts::usage("Print sequences of numbers", opts));
println!("{:s}", getopts::usage("Print sequences of numbers", &opts));
}
fn print_version() {

View file

@ -48,7 +48,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let mut matches = match getopts::getopts(args.tail(), opts) {
let mut matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "{}", f)
@ -64,7 +64,7 @@ Usage:
{usage}
With no FILE, or when FILE is -, read standard input.",
name = NAME, version = VERSION, prog = program,
usage = getopts::usage("Write a random permutation of the input lines to standard output.", opts));
usage = getopts::usage("Write a random permutation of the input lines to standard output.", &opts));
} else if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else {
@ -76,7 +76,7 @@ With no FILE, or when FILE is -, read standard input.",
return 1;
}
match parse_range(range) {
Ok(m) => InputRange(m),
Ok(m) => Mode::InputRange(m),
Err((msg, code)) => {
show_error!("{}", msg);
return code;
@ -85,12 +85,12 @@ With no FILE, or when FILE is -, read standard input.",
}
None => {
if echo {
Echo
Mode::Echo
} else {
if matches.free.len() == 0 {
matches.free.push("-".to_string());
}
Default
Mode::Default
}
}
};
@ -122,9 +122,9 @@ With no FILE, or when FILE is -, read standard input.",
fn shuf(input: Vec<String>, mode: Mode, repeat: bool, zero: bool, count: uint, output: Option<String>, random: Option<String>) -> IoResult<()> {
match mode {
Echo => shuf_lines(input, repeat, zero, count, output, random),
InputRange(range) => shuf_lines(range.map(|num| num.to_string()).collect(), repeat, zero, count, output, random),
Default => {
Mode::Echo => shuf_lines(input, repeat, zero, count, output, random),
Mode::InputRange(range) => shuf_lines(range.map(|num| num.to_string()).collect(), repeat, zero, count, output, random),
Mode::Default => {
let lines: Vec<String> = input.into_iter().flat_map(|filename| {
let slice = filename.as_slice();
let mut file_buf;
@ -159,8 +159,8 @@ enum WrappedRng {
impl WrappedRng {
fn next_u32(&mut self) -> u32 {
match self {
&RngFile(ref mut r) => r.next_u32(),
&RngDefault(ref mut r) => r.next_u32(),
&WrappedRng::RngFile(ref mut r) => r.next_u32(),
&WrappedRng::RngDefault(ref mut r) => r.next_u32(),
}
}
}
@ -171,8 +171,8 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
None => box io::stdout() as Box<Writer>
};
let mut rng = match random {
Some(name) => RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))),
None => RngDefault(rand::task_rng()),
Some(name) => WrappedRng::RngFile(rand::reader::ReaderRng::new(try!(io::File::open(&Path::new(name))))),
None => WrappedRng::RngDefault(rand::task_rng()),
};
let mut len = lines.len();
let max = if repeat { count } else { cmp::min(count, len) };

View file

@ -33,7 +33,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
show_error!("{}", f);
@ -53,7 +53,7 @@ pub fn uumain(args: Vec<String>) -> int {
'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).as_slice());
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() {

View file

@ -35,7 +35,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -43,7 +43,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage: {0:s} [OPTION]... [FILE]...", program);
println!("Write the sorted concatenation of all FILE(s) to standard output.");
println!("");
print(getopts::usage("Mandatory arguments for long options are mandatory for short options too.", opts).as_slice());
print(getopts::usage("Mandatory arguments for long options are mandatory for short options too.", &opts).as_slice());
println!("");
println!("With no FILE, or when FILE is -, read standard input.");
return 0;

View file

@ -15,7 +15,7 @@ extern crate getopts;
extern crate libc;
use std::io;
use std::num;
use std::num::Int;
use std::char;
#[path = "../common/util.rs"]
@ -36,7 +36,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [INPUT [PREFIX]]", NAME);
println!("");
io::print(getopts::usage("Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is -, read standard input." , opts).as_slice());
io::print(getopts::usage("Output fixed-size pieces of INPUT to PREFIXaa, PREFIX ab, ...; default size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is -, read standard input." , &opts).as_slice());
return 0;
}
@ -193,7 +193,7 @@ fn str_prefix(i: uint, width: uint) -> String {
let mut w = width;
while w > 0 {
w -= 1;
let div = num::pow(26 as uint, w);
let div = Int::pow(26 as uint, w);
let r = n / div;
n -= r * div;
c.push(char::from_u32((r as u32) + 97).unwrap());
@ -208,7 +208,7 @@ fn num_prefix(i: uint, width: uint) -> String {
let mut w = width;
while w > 0 {
w -= 1;
let div = num::pow(10 as uint, w);
let div = Int::pow(10 as uint, w);
let r = n / div;
n -= r * div;
c.push(char::from_digit(r, 10).unwrap());

View file

@ -27,7 +27,7 @@ fn bsd_sum(mut reader: Box<Reader>) -> (uint, u16) {
let mut blocks_read = 0;
let mut checksum: u16 = 0;
loop {
match reader.read(buf) {
match reader.read(&mut buf) {
Ok(n) if n != 0 => {
blocks_read += 1;
for &byte in buf.slice_to(n).iter() {
@ -48,7 +48,7 @@ fn sysv_sum(mut reader: Box<Reader>) -> (uint, u16) {
let mut ret = 0;
loop {
match reader.read(buf) {
match reader.read(&mut buf) {
Ok(n) if n != 0 => {
blocks_read += 1;
for &byte in buf.slice_to(n).iter() {
@ -84,7 +84,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("v", "version", "print the version and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -95,7 +95,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print(getopts::usage("checksum and count the blocks in a file", opts).as_slice());
print(getopts::usage("checksum and count the blocks in a file", &opts).as_slice());
println!("");
println!("With no FILE, or when FILE is -, read standard input.");
return 0;

View file

@ -148,13 +148,13 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "output version information and exit")
];
let matches = match getopts(args.tail(), options) {
let matches = match getopts(args.tail(), &options) {
Ok(m) => { m }
_ => { help(program.as_slice(), options); return 1 }
_ => { help(program.as_slice(), &options); return 1 }
};
if matches.opt_present("h") {
help(program.as_slice(), options);
help(program.as_slice(), &options);
return 0
}

View file

@ -32,7 +32,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -42,7 +42,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print!("{}", getopts::usage("Write each file to standard output, last line first.", opts));
print!("{}", getopts::usage("Write each file to standard output, last line first.", &opts));
} else if matches.opt_present("version") {
println!("tac {}", VERSION);
} else {

View file

@ -54,16 +54,16 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("V", "version", "version"),
];
let given_options = match getopts(args.as_slice(), possible_options) {
let given_options = match getopts(args.as_slice(), &possible_options) {
Ok (m) => { m }
Err(_) => {
println!("{:s}", usage(NAME, possible_options));
println!("{:s}", usage(NAME, &possible_options));
return 1;
}
};
if given_options.opt_present("h") {
println!("{:s}", usage(NAME, possible_options));
println!("{:s}", usage(NAME, &possible_options));
return 0;
}
if given_options.opt_present("V") { version(); return 0 }

View file

@ -50,14 +50,14 @@ fn options(args: &[String]) -> Result<Options, ()> {
let args: Vec<String> = args.iter().map(|x| x.to_string()).collect();
getopts(args.tail(), opts).map_err(|e| format!("{}", e)).and_then(|m| {
getopts(args.tail(), &opts).map_err(|e| format!("{}", e)).and_then(|m| {
let version = format!("{} {}", NAME, VERSION);
let program = args[0].as_slice();
let arguments = "[OPTION]... [FILE]...";
let brief = "Copy standard input to each FILE, and also to standard output.";
let comment = "If a FILE is -, copy again to standard output.";
let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}",
version, program, arguments, usage(brief, opts),
version, program, arguments, usage(brief, &opts),
comment);
let mut names = m.free.clone().into_iter().collect::<Vec<String>>();
names.push("-".to_string());

View file

@ -53,23 +53,23 @@ fn one(args: &[&[u8]]) -> bool {
fn two(args: &[&[u8]], error: &mut bool) -> bool {
match args[0] {
b"!" => !one(args.slice_from(1)),
b"-b" => path(args[1], BlockSpecial),
b"-c" => path(args[1], CharacterSpecial),
b"-d" => path(args[1], Directory),
b"-e" => path(args[1], Exists),
b"-f" => path(args[1], Regular),
b"-g" => path(args[1], GroupIDFlag),
b"-h" => path(args[1], SymLink),
b"-L" => path(args[1], SymLink),
b"-b" => path(args[1], PathCondition::BlockSpecial),
b"-c" => path(args[1], PathCondition::CharacterSpecial),
b"-d" => path(args[1], PathCondition::Directory),
b"-e" => path(args[1], PathCondition::Exists),
b"-f" => path(args[1], PathCondition::Regular),
b"-g" => path(args[1], PathCondition::GroupIDFlag),
b"-h" => path(args[1], PathCondition::SymLink),
b"-L" => path(args[1], PathCondition::SymLink),
b"-n" => one(args.slice_from(1)),
b"-p" => path(args[1], FIFO),
b"-r" => path(args[1], Readable),
b"-S" => path(args[1], Socket),
b"-s" => path(args[1], NonEmpty),
b"-p" => path(args[1], PathCondition::FIFO),
b"-r" => path(args[1], PathCondition::Readable),
b"-S" => path(args[1], PathCondition::Socket),
b"-s" => path(args[1], PathCondition::NonEmpty),
b"-t" => isatty(args[1]),
b"-u" => path(args[1], UserIDFlag),
b"-w" => path(args[1], Writable),
b"-x" => path(args[1], Executable),
b"-u" => path(args[1], PathCondition::UserIDFlag),
b"-w" => path(args[1], PathCondition::Writable),
b"-x" => path(args[1], PathCondition::Executable),
b"-z" => !one(args.slice_from(1)),
_ => {
*error = true;
@ -82,12 +82,12 @@ fn three(args: &[&[u8]], error: &mut bool) -> bool {
match args[1] {
b"=" => args[0] == args[2],
b"!=" => args[0] != args[2],
b"-eq" => integers(args[0], args[2], Equal),
b"-ne" => integers(args[0], args[2], Unequal),
b"-gt" => integers(args[0], args[2], Greater),
b"-ge" => integers(args[0], args[2], GreaterEqual),
b"-lt" => integers(args[0], args[2], Less),
b"-le" => integers(args[0], args[2], LessEqual),
b"-eq" => integers(args[0], args[2], IntegerCondition::Equal),
b"-ne" => integers(args[0], args[2], IntegerCondition::Unequal),
b"-gt" => integers(args[0], args[2], IntegerCondition::Greater),
b"-ge" => integers(args[0], args[2], IntegerCondition::GreaterEqual),
b"-lt" => integers(args[0], args[2], IntegerCondition::Less),
b"-le" => integers(args[0], args[2], IntegerCondition::LessEqual),
_ => match args[0] {
b"!" => !two(args.slice_from(1), error),
_ => {
@ -129,12 +129,12 @@ fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool {
_ => return false,
};
match cond {
Equal => a == b,
Unequal => a != b,
Greater => a > b,
GreaterEqual => a >= b,
Less => a < b,
LessEqual => a <= b,
IntegerCondition::Equal => a == b,
IntegerCondition::Unequal => a != b,
IntegerCondition::Greater => a > b,
IntegerCondition::GreaterEqual => a >= b,
IntegerCondition::Less => a < b,
IntegerCondition::LessEqual => a <= b,
}
}
@ -207,7 +207,7 @@ fn parse_expr(mut args: &[&[u8]], error: &mut bool) -> bool {
let lhs = dispatch(&mut args, error);
if args.len() > 0 {
parse_expr_helper(&hashmap, &mut args, lhs, Unknown, error)
parse_expr_helper(&hashmap, &mut args, lhs, Precedence::Unknown, error)
} else {
lhs
}
@ -238,14 +238,14 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
rhs = parse_expr_helper(hashmap, args, rhs, subprec, error);
}
lhs = match prec {
UnOp | BUnOp => {
Precedence::UnOp | Precedence::BUnOp => {
*error = true;
false
}
And => lhs && rhs,
Or => lhs || rhs,
BinOp => three(&[if lhs { b" " } else { b"" }, op, if rhs { b" " } else { b"" }], error),
Paren => unimplemented!(), // TODO: implement parentheses
Precedence::And => lhs && rhs,
Precedence::Or => lhs || rhs,
Precedence::BinOp => three(&[if lhs { b" " } else { b"" }, op, if rhs { b" " } else { b"" }], error),
Precedence::Paren => unimplemented!(), // TODO: implement parentheses
_ => unreachable!()
};
if args.len() > 0 {
@ -262,41 +262,41 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
fn setup_hashmap<'a>() -> HashMap<&'a [u8], Precedence> {
let mut hashmap = HashMap::<&'a [u8], Precedence>::new();
hashmap.insert(b"-b", UnOp);
hashmap.insert(b"-c", UnOp);
hashmap.insert(b"-d", UnOp);
hashmap.insert(b"-e", UnOp);
hashmap.insert(b"-f", UnOp);
hashmap.insert(b"-g", UnOp);
hashmap.insert(b"-h", UnOp);
hashmap.insert(b"-L", UnOp);
hashmap.insert(b"-n", UnOp);
hashmap.insert(b"-p", UnOp);
hashmap.insert(b"-r", UnOp);
hashmap.insert(b"-S", UnOp);
hashmap.insert(b"-s", UnOp);
hashmap.insert(b"-t", UnOp);
hashmap.insert(b"-u", UnOp);
hashmap.insert(b"-w", UnOp);
hashmap.insert(b"-x", UnOp);
hashmap.insert(b"-z", UnOp);
hashmap.insert(b"-b", Precedence::UnOp);
hashmap.insert(b"-c", Precedence::UnOp);
hashmap.insert(b"-d", Precedence::UnOp);
hashmap.insert(b"-e", Precedence::UnOp);
hashmap.insert(b"-f", Precedence::UnOp);
hashmap.insert(b"-g", Precedence::UnOp);
hashmap.insert(b"-h", Precedence::UnOp);
hashmap.insert(b"-L", Precedence::UnOp);
hashmap.insert(b"-n", Precedence::UnOp);
hashmap.insert(b"-p", Precedence::UnOp);
hashmap.insert(b"-r", Precedence::UnOp);
hashmap.insert(b"-S", Precedence::UnOp);
hashmap.insert(b"-s", Precedence::UnOp);
hashmap.insert(b"-t", Precedence::UnOp);
hashmap.insert(b"-u", Precedence::UnOp);
hashmap.insert(b"-w", Precedence::UnOp);
hashmap.insert(b"-x", Precedence::UnOp);
hashmap.insert(b"-z", Precedence::UnOp);
hashmap.insert(b"=", BinOp);
hashmap.insert(b"!=", BinOp);
hashmap.insert(b"-eq", BinOp);
hashmap.insert(b"-ne", BinOp);
hashmap.insert(b"-gt", BinOp);
hashmap.insert(b"-ge", BinOp);
hashmap.insert(b"-lt", BinOp);
hashmap.insert(b"-le", BinOp);
hashmap.insert(b"=", Precedence::BinOp);
hashmap.insert(b"!=", Precedence::BinOp);
hashmap.insert(b"-eq", Precedence::BinOp);
hashmap.insert(b"-ne", Precedence::BinOp);
hashmap.insert(b"-gt", Precedence::BinOp);
hashmap.insert(b"-ge", Precedence::BinOp);
hashmap.insert(b"-lt", Precedence::BinOp);
hashmap.insert(b"-le", Precedence::BinOp);
hashmap.insert(b"!", BUnOp);
hashmap.insert(b"!", Precedence::BUnOp);
hashmap.insert(b"-a", And);
hashmap.insert(b"-o", Or);
hashmap.insert(b"-a", Precedence::And);
hashmap.insert(b"-o", Precedence::Or);
hashmap.insert(b"(", Paren);
hashmap.insert(b")", Paren);
hashmap.insert(b"(", Precedence::Paren);
hashmap.insert(b")", Precedence::Paren);
hashmap
}
@ -346,7 +346,7 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
let path = unsafe { path.to_c_str_unchecked() };
let mut stat = unsafe { std::mem::zeroed() };
if cond == SymLink {
if cond == PathCondition::SymLink {
if unsafe { lstat(path.as_ptr(), &mut stat) } == 0 {
if stat.st_mode & S_IFMT == S_IFLNK {
return true;
@ -359,20 +359,20 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
}
let file_type = stat.st_mode & S_IFMT;
match cond {
BlockSpecial => file_type == S_IFBLK,
CharacterSpecial => file_type == S_IFCHR,
Directory => file_type == S_IFDIR,
Exists => true,
Regular => file_type == S_IFREG,
GroupIDFlag => stat.st_mode & S_ISGID != 0,
SymLink => true,
FIFO => file_type == S_IFIFO,
Readable => perm(stat, Read),
Socket => file_type == S_IFSOCK,
NonEmpty => stat.st_size > 0,
UserIDFlag => stat.st_mode & S_ISUID != 0,
Writable => perm(stat, Write),
Executable => perm(stat, Execute),
PathCondition::BlockSpecial => file_type == S_IFBLK,
PathCondition::CharacterSpecial => file_type == S_IFCHR,
PathCondition::Directory => file_type == S_IFDIR,
PathCondition::Exists => true,
PathCondition::Regular => file_type == S_IFREG,
PathCondition::GroupIDFlag => stat.st_mode & S_ISGID != 0,
PathCondition::SymLink => true,
PathCondition::FIFO => file_type == S_IFIFO,
PathCondition::Readable => perm(stat, Permission::Read),
PathCondition::Socket => file_type == S_IFSOCK,
PathCondition::NonEmpty => stat.st_size > 0,
PathCondition::UserIDFlag => stat.st_mode & S_ISUID != 0,
PathCondition::Writable => perm(stat, Permission::Write),
PathCondition::Executable => perm(stat, Permission::Execute),
}
}

View file

@ -46,7 +46,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(ERR_EXIT_STATUS, "{}", f)
@ -58,7 +58,7 @@ pub fn uumain(args: Vec<String>) -> int {
Usage:
{} [OPTION] DURATION COMMAND [ARG]...
{}", NAME, VERSION, program, getopts::usage("Start COMMAND, and kill it if still running after DURATION.", opts));
{}", NAME, VERSION, program, getopts::usage("Start COMMAND, and kill it if still running after DURATION.", &opts));
} else if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.free.len() < 2 {

View file

@ -39,7 +39,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => panic!("Invalid options\n{}", e)
};
@ -55,16 +55,16 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage: {:s} [OPTION]... FILE...", NAME);
println!("");
println!("{:s}", getopts::usage("Update the access and modification times of \
each FILE to the current time.", opts));
each FILE to the current time.", &opts));
if matches.free.is_empty() {
return 1;
}
return 0;
}
if matches.opt_present("date") && matches.opts_present(["reference".to_string(), "t".to_string()]) ||
matches.opt_present("reference") && matches.opts_present(["date".to_string(), "t".to_string()]) ||
matches.opt_present("t") && matches.opts_present(["date".to_string(), "reference".to_string()]) {
if matches.opt_present("date") && matches.opts_present(&["reference".to_string(), "t".to_string()]) ||
matches.opt_present("reference") && matches.opts_present(&["date".to_string(), "t".to_string()]) ||
matches.opt_present("t") && matches.opts_present(&["date".to_string(), "reference".to_string()]) {
panic!("Invalid options: cannot specify reference time from more than one source");
}
@ -73,7 +73,7 @@ pub fn uumain(args: Vec<String>) -> int {
let path = Path::new(matches.opt_str("reference").unwrap().to_string());
let stat = stat(&path, !matches.opt_present("no-dereference"));
(stat.accessed, stat.modified)
} else if matches.opts_present(["date".to_string(), "t".to_string()]) {
} else if matches.opts_present(&["date".to_string(), "t".to_string()]) {
let timestamp = if matches.opt_present("date") {
parse_date(matches.opt_str("date").unwrap().as_slice())
} else {
@ -91,7 +91,7 @@ pub fn uumain(args: Vec<String>) -> int {
if !path.exists() {
// no-dereference included here for compatibility
if matches.opts_present(["no-create".to_string(), "no-dereference".to_string()]) {
if matches.opts_present(&["no-create".to_string(), "no-dereference".to_string()]) {
continue;
}
@ -101,14 +101,14 @@ pub fn uumain(args: Vec<String>) -> int {
};
// Minor optimization: if no reference time was specified, we're done.
if !matches.opts_present(["date".to_string(), "reference".to_string(), "t".to_string()]) {
if !matches.opts_present(&["date".to_string(), "reference".to_string(), "t".to_string()]) {
continue;
}
}
// If changing "only" atime or mtime, grab the existing value of the other.
// Note that "-a" and "-m" may be passed together; this is not an xor.
if matches.opts_present(["a".to_string(), "m".to_string(), "time".to_string()]) {
if matches.opts_present(&["a".to_string(), "m".to_string(), "time".to_string()]) {
let stat = stat(&path, !matches.opt_present("no-dereference"));
let time = matches.opt_strs("time");

View file

@ -154,7 +154,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(err) => {
show_error!("{}", err);
@ -163,7 +163,7 @@ pub fn uumain(args: Vec<String>) -> int {
};
if matches.opt_present("help") {
usage(opts);
usage(&opts);
return 0;
}
@ -173,12 +173,12 @@ pub fn uumain(args: Vec<String>) -> int {
}
if matches.free.len() == 0 {
usage(opts);
usage(&opts);
return 1;
}
let dflag = matches.opt_present("d");
let cflag = matches.opts_present(["c".to_string(), "C".to_string()]);
let cflag = matches.opts_present(&["c".to_string(), "C".to_string()]);
let sets = matches.free;
if cflag && !dflag {

View file

@ -44,7 +44,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "{}", f)
@ -57,7 +57,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... FILE...", program);
println!("");
print!("{}", getopts::usage("Shrink or extend the size of each file to the specified size.", opts));
print!("{}", getopts::usage("Shrink or extend the size of each file to the specified size.", &opts));
print!("
SIZE is an integer with an optional prefix and optional unit.
The available units (K, M, G, T, P, E, Z, and Y) use the following format:
@ -109,7 +109,7 @@ fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<St
}
};
match fs::stat(rfile.path()) {
Ok(stat) => (stat.size, Reference),
Ok(stat) => (stat.size, TruncateMode::Reference),
Err(f) => {
show_error!("{}", f.to_string());
return Err(1);
@ -132,13 +132,13 @@ fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<St
}
};
let tsize = match mode {
Reference => refsize,
Extend => fsize + refsize,
Reduce => fsize - refsize,
AtMost => if fsize > refsize { refsize } else { fsize },
AtLeast => if fsize < refsize { refsize } else { fsize },
RoundDown => fsize - fsize % refsize,
RoundUp => fsize + fsize % refsize
TruncateMode::Reference => refsize,
TruncateMode::Extend => fsize + refsize,
TruncateMode::Reduce => fsize - refsize,
TruncateMode::AtMost => if fsize > refsize { refsize } else { fsize },
TruncateMode::AtLeast => if fsize < refsize { refsize } else { fsize },
TruncateMode::RoundDown => fsize - fsize % refsize,
TruncateMode::RoundUp => fsize + fsize % refsize
};
match file.truncate(tsize as i64) {
Ok(_) => {}
@ -160,17 +160,17 @@ fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<St
fn parse_size(size: &str) -> (u64, TruncateMode) {
let mode = match size.char_at(0) {
'+' => Extend,
'-' => Reduce,
'<' => AtMost,
'>' => AtLeast,
'/' => RoundDown,
'*' => RoundUp,
_ => Reference /* assume that the size is just a number */
'+' => TruncateMode::Extend,
'-' => TruncateMode::Reduce,
'<' => TruncateMode::AtMost,
'>' => TruncateMode::AtLeast,
'/' => TruncateMode::RoundDown,
'*' => TruncateMode::RoundUp,
_ => TruncateMode::Reference /* assume that the size is just a number */
};
let bytes = {
let mut slice =
if mode == Reference {
if mode == TruncateMode::Reference {
let size: &str = size;
size
} else {

View file

@ -30,7 +30,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -41,7 +41,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {} [OPTIONS] FILE", NAME);
println!("");
io::print(getopts::usage("Topological sort the strings in FILE. Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline). If FILE is not passed in, stdin is used instead.", opts).as_slice());
io::print(getopts::usage("Topological sort the strings in FILE. Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline). If FILE is not passed in, stdin is used instead.", &opts).as_slice());
return 0;
}

View file

@ -39,7 +39,7 @@ pub fn uumain(args: Vec<String>) -> int {
optflag("s", "silent", "print nothing, only return an exit status")
];
let silent = match getopts(args.tail(), options) {
let silent = match getopts(args.tail(), &options) {
Ok(m) => {
m.opt_present("s")
},

View file

@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("s", "sysname", "print the operating system name."),
getopts::optflag("v", "version", "print the operating system version."),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f),
};
@ -74,13 +74,13 @@ pub fn uumain(args: Vec<String>) -> int {
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).as_slice());
print(getopts::usage("The uname utility writes symbols representing one or more system characteristics to the standard output.", &opts).as_slice());
return 0;
}
let uname = unsafe { getuname() };
let mut output = String::new();
if matches.opt_present("sysname") || matches.opt_present("all")
|| !matches.opts_present(["nodename".to_string(), "release".to_string(), "version".to_string(), "machine".to_string()]) {
|| !matches.opts_present(&["nodename".to_string(), "release".to_string(), "version".to_string(), "machine".to_string()]) {
output.push_str(uname.sysname.as_slice());
output.push_str(" ");
}

View file

@ -84,7 +84,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -93,7 +93,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage: {:s} [OPTION]... [FILE]...", NAME);
io::print(getopts::usage(
"Convert blanks in each FILE to tabs, writing to standard output.\n\
With no FILE, or when FILE is -, read standard input.", opts).as_slice());
With no FILE, or when FILE is -, read standard input.", &opts).as_slice());
return 0;
}

View file

@ -138,7 +138,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit")
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f)
};
@ -150,7 +150,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print!("{}", getopts::usage("Filter adjacent matching lines from INPUT (or standard input),\n\
writing to OUTPUT (or standard output).", opts));
writing to OUTPUT (or standard output).", &opts));
println!("");
println!("Note: '{0}' does not detect repeated lines unless they are adjacent.\n\
You may want to sort the input first, or use 'sort -u' without '{0}'.\n", program);

View file

@ -32,7 +32,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "invalid options\n{}", f)
@ -45,7 +45,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [FILE]... [OPTION]...", program);
println!("");
print(getopts::usage("Unlink the file at [FILE].", opts).as_slice());
print(getopts::usage("Unlink the file at [FILE].", &opts).as_slice());
return 0;
}

View file

@ -58,7 +58,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("v", "version", "output version information and exit"),
getopts::optflag("h", "help", "display this help and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "Invalid options\n{}", f)
};
@ -72,7 +72,7 @@ pub fn uumain(args: Vec<String>) -> int {
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).as_slice());
in the run queue over the last 1, 5 and 15 minutes.", &opts).as_slice());
return 0;
}

View file

@ -59,7 +59,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => panic!("{}", f),
};
@ -70,7 +70,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {:s} [OPTION]... [FILE]", program);
println!("");
print(getopts::usage("Output who is currently logged in according to FILE.", opts).as_slice());
print(getopts::usage("Output who is currently logged in according to FILE.", &opts).as_slice());
return 0;
}

View file

@ -47,7 +47,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "Invalid options\n{}", f)
@ -58,7 +58,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [OPTION]... [FILE]...", program);
println!("");
print(getopts::usage("Print newline, word and byte counts for each FILE", opts).as_slice());
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 0;

View file

@ -72,7 +72,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => crash!(1, "{}", f),
};
@ -82,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {:s}", program);
println!("");
print(getopts::usage("print effective userid", opts).as_slice());
print(getopts::usage("print effective userid", &opts).as_slice());
return 0;
}
if matches.opt_present("version") {

View file

@ -29,7 +29,7 @@ pub fn uumain(args: Vec<String>) -> int {
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
];
let matches = match getopts::getopts(args.tail(), opts) {
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(f) => {
crash!(1, "invalid options\n{}", f)
@ -41,7 +41,7 @@ pub fn uumain(args: Vec<String>) -> int {
println!("Usage:");
println!(" {0:s} [STRING]... [OPTION]...", program);
println!("");
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts).as_slice());
print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", &opts).as_slice());
return 0;
}
if matches.opt_present("version") {