From 3e4c1023c492089aedeb47a6877dff3cd92718e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81o=20Testard?= Date: Fri, 18 Oct 2013 13:40:36 +0200 Subject: [PATCH] Fix compilation for Rust master branch (0.9-pre) --- Makefile | 1 + cat/cat.rs | 38 ++++++++++++++++++++------------------ printenv/printenv.rs | 12 ++++++------ yes/yes.rs | 8 ++++---- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index d43b21f12..2c8d213f2 100644 --- a/Makefile +++ b/Makefile @@ -6,5 +6,6 @@ build: sh -c 'rustc --out-dir build/ printenv/printenv.rs' sh -c 'rustc --out-dir build/ true/true.rs' sh -c 'rustc --out-dir build/ yes/yes.rs' + sh -c 'rustc --out-dir build/ cat/cat.rs' .PHONY: build diff --git a/cat/cat.rs b/cat/cat.rs index 4ad997868..68e5c8859 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -15,7 +15,7 @@ extern mod extra; use std::os; use std::io::{stdin, stderr, stdout, Writer, Reader}; -use extra::getopts::*; +use extra::getopts::groups; fn main() { let args = os::args(); @@ -37,12 +37,12 @@ fn main() { Ok(m) => m, Err(f) => { stderr().write_line("Invalid options"); - stderr().write_line(fail_str(f)); + stderr().write_line(f.to_err_msg()); os::set_exit_status(1); return } }; - if opts_present(&matches, [~"h", ~"help"]) { + if matches.opts_present([~"h", ~"help"]) { println("cat 1.0.0"); println(""); println("Usage:"); @@ -53,22 +53,22 @@ fn main() { println("With no FILE, or when FILE is -, read standard input."); return; } - if opts_present(&matches, [~"V", ~"version"]) { + if matches.opts_present([~"V", ~"version"]) { println("cat 1.0.0"); return; } let mut number_mode = NumberNone; - if opts_present(&matches, [~"n", ~"number"]) { + if matches.opts_present([~"n", ~"number"]) { number_mode = NumberAll; } - if opts_present(&matches, [~"b", ~"number-nonblank"]) { + if matches.opts_present([~"b", ~"number-nonblank"]) { number_mode = NumberNonEmpty; } - let show_nonprint = opts_present(&matches, [~"v", ~"show-nonprinting", ~"A", ~"show-all", ~"t", ~"e"]); - let show_ends = opts_present(&matches, [~"E", ~"show-ends", ~"A", ~"show-all", ~"e"]); - let show_tabs = opts_present(&matches, [~"T", ~"show-tabs", ~"A", ~"show-all", ~"t"]); - let squeeze_blank = opts_present(&matches, [~"s", ~"squeeze-blank"]); + let show_nonprint = matches.opts_present([~"v", ~"show-nonprinting", ~"A", ~"show-all", ~"t", ~"e"]); + let show_ends = matches.opts_present([~"E", ~"show-ends", ~"A", ~"show-all", ~"e"]); + let show_tabs = matches.opts_present([~"T", ~"show-tabs", ~"A", ~"show-all", ~"t"]); + let squeeze_blank = matches.opts_present([~"s", ~"squeeze-blank"]); let mut files = matches.free; if files.is_empty() { files = ~[~"-"]; @@ -84,15 +84,17 @@ pub enum NumberingMode { NumberAll, } -static TAB: u8 = bytes!("\t"); -static CR: u8 = bytes!("\r"); -static LF: u8 = bytes!("\n"); +static TAB: u8 = '\t' as u8; +static CR: u8 = '\r' as u8; +static LF: u8 = '\n' as u8; +#[cfg(windows)] fn is_newline_char(byte: u8) -> bool { - if cfg!("windows") { - return byte == LF || byte == CR - } + byte == LF || byte == CR +} +#[cfg(unix)] +fn is_newline_char(byte: u8) -> bool { byte == LF } @@ -103,7 +105,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end for path in files.iter() { let reader = match open(path.to_owned()) { Some(f) => f, - None => { loop } + None => { continue } }; let mut counter: uint = 1; @@ -156,7 +158,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end for path in files.iter() { let reader = match open(path.to_owned()) { Some(f) => f, - None => { loop } + None => { continue } }; loop { diff --git a/printenv/printenv.rs b/printenv/printenv.rs index 81d5bd1f9..33a4a4a95 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -15,7 +15,7 @@ extern mod extra; use std::os; use std::io::stderr; -use extra::getopts::*; +use extra::getopts::groups; fn main() { let args = os::args(); @@ -29,12 +29,12 @@ fn main() { Ok(m) => m, Err(f) => { stderr().write_line("Invalid options"); - stderr().write_line(fail_str(f)); + stderr().write_line(f.to_err_msg()); os::set_exit_status(1); return } }; - if opts_present(&matches, [~"h", ~"help"]) { + if matches.opts_present([~"h", ~"help"]) { println("printenv 1.0.0"); println(""); println("Usage:"); @@ -43,12 +43,12 @@ fn main() { print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts)); return; } - if opts_present(&matches, [~"V", ~"version"]) { + if matches.opts_present([~"V", ~"version"]) { println("printenv 1.0.0"); return; } let mut separator = "\n"; - if opts_present(&matches, [~"0", ~"null"]) { + if matches.opts_present([~"0", ~"null"]) { separator = "\x00"; }; @@ -58,7 +58,7 @@ fn main() { pub fn exec(args: ~[~str], separator: &str) { if args.is_empty() { let vars = os::env(); - for (env_var, value) in vars.consume_iter() { + for (env_var, value) in vars.move_iter() { print(fmt!("%s=%s", env_var, value)); print(separator); } diff --git a/yes/yes.rs b/yes/yes.rs index d19ea8910..a60eb29e8 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -15,7 +15,7 @@ extern mod extra; use std::os; use std::io::stderr; -use extra::getopts::*; +use extra::getopts::groups; fn main() { let args = os::args(); @@ -28,12 +28,12 @@ fn main() { Ok(m) => m, Err(f) => { stderr().write_line("Invalid options"); - stderr().write_line(fail_str(f)); + stderr().write_line(f.to_err_msg()); os::set_exit_status(1); return } }; - if opts_present(&matches, [~"h", ~"help"]) { + if matches.opts_present([~"h", ~"help"]) { println("yes 1.0.0"); println(""); println("Usage:"); @@ -42,7 +42,7 @@ fn main() { print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts)); return; } - if opts_present(&matches, [~"V", ~"version"]) { + if matches.opts_present([~"V", ~"version"]) { println("yes 1.0.0"); return; }