diff --git a/.gitmodules b/.gitmodules index bdf322bee..f6dae76e5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "deps/time"] path = deps/time url = https://github.com/rust-lang/time +[submodule "deps/regex"] + path = deps/regex + url = https://github.com/rust-lang/regex diff --git a/Makefile b/Makefile index bcba7f737..706f38efd 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ ENABLE_STRIP ?= n # Binaries RUSTC ?= rustc +CARGO ?= cargo RM := rm # Install directories @@ -177,7 +178,7 @@ define CRATE_BUILD -include $(BUILDDIR)/$(1).d $(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps - $(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --crate-type rlib --dep-info $(BUILDDIR)/$(1).d $$< --out-dir $(BUILDDIR) + $(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --crate-type rlib --dep-info $(BUILDDIR)/$(1).d $$< --out-dir $(BUILDDIR) endef # Aliases build rule @@ -199,7 +200,7 @@ test_$(1): $(TEMPDIR)/$(1)/$(1)_test $(BUILDDIR)/$(1) $(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<) $(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1) - $(call command,$(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --test -o $$@ $$<) + $(call command,$(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --test -o $$@ $$<) $(TEMPDIR)/$(1): | $(TEMPDIR) $(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@) @@ -222,15 +223,21 @@ $(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS # Dependencies $(BUILDDIR)/.rust-crypto: $(BUILDDIR)/.rust-time | $(BUILDDIR) - cd $(BASEDIR)/deps/rust-crypto && cargo build --release + cd $(BASEDIR)/deps/rust-crypto && $(CARGO) build --release cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib @touch $@ $(BUILDDIR)/.rust-time: - cd $(BASEDIR)/deps/time && cargo build --release + cd $(BASEDIR)/deps/time && $(CARGO) build --release cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib @touch $@ +$(BUILDDIR)/.rust-regex: + cd $(BASEDIR)/deps/regex/regex_macros && $(CARGO) build --release + cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/libregex_macros* $(BUILDDIR) + cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/deps/libregex*.rlib $(BUILDDIR)/libregex.rlib + @touch $@ + $(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR) $(RUSTC) $(RUSTCFLAGS) $< -o $@ @@ -240,7 +247,7 @@ $(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR) $(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table -deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-time $(SRCDIR)/cksum/crc_table.rs +deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-time $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs crates: echo $(EXES) diff --git a/deps/regex b/deps/regex new file mode 160000 index 000000000..094a68530 --- /dev/null +++ b/deps/regex @@ -0,0 +1 @@ +Subproject commit 094a68530a6550d5158988ec37afea75b95bbac9 diff --git a/src/base64/base64.rs b/src/base64/base64.rs index b8eed44d4..5af887749 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -15,6 +15,7 @@ extern crate libc; #[macro_use] extern crate log; use std::ascii::AsciiExt; +use std::error::Error; use std::io::{println, File, stdout}; use std::io::stdio::stdin_raw; @@ -33,7 +34,7 @@ mod util; static NAME: &'static str = "base64"; -pub fn uumain(args: Vec) -> int { +pub fn uumain(args: Vec) -> isize { let opts = [ optflag("d", "decode", "decode data"), optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"), @@ -46,8 +47,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), &opts) { Ok(m) => m, Err(e) => { - error!("error: {}", e); - panic!() + crash!(1, "error: {}", e); } }; @@ -67,8 +67,7 @@ pub fn uumain(args: Vec) -> int { Some(s) => match s.parse() { Some(s) => s, None => { - error!("error: {}", "Argument to option 'wrap' improperly formatted."); - panic!() + crash!(1, "error: {}", "Argument to option 'wrap' improperly formatted."); } }, None => 76 @@ -129,13 +128,12 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { } } Err(s) => { - error!("error: {}", s); - panic!() + crash!(1, "error: {} ({})", s.description(), s.detail().unwrap_or("".to_string())); } } } -fn encode(input: &mut Reader, line_wrap: uint) { +fn encode(input: &mut Reader, line_wrap: usize) { let b64_conf = base64::Config { char_set: base64::Standard, newline: base64::Newline::LF, diff --git a/src/cat/cat.rs b/src/cat/cat.rs index d90591513..7c15a1a2b 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -1,5 +1,5 @@ #![crate_name = "cat"] -#![feature(unsafe_destructor)] +#![feature(box_syntax, unsafe_destructor)] /* * This file is part of the uutils coreutils package. diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index 5c5125c3c..2f57e33b7 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -10,12 +10,14 @@ */ #![allow(unused_variables)] // only necessary while the TODOs still exist +#![feature(plugin)] extern crate getopts; extern crate libc; extern crate regex; -#[macro_use] extern crate regex_macros; +#[plugin] extern crate regex_macros; +use std::ffi::CString; use std::io::fs; use std::io::fs::PathExtensions; use std::io::IoError; @@ -30,7 +32,7 @@ mod util; const NAME: &'static str = "chmod"; const VERSION: &'static str = "1.0.0"; -pub fn uumain(args: Vec) -> int { +pub fn uumain(args: Vec) -> isize { let program = args[0].clone(); let opts = [ @@ -88,7 +90,7 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.", }); let cmode = if fmode.is_none() { - let mode = matches.free.remove(0).unwrap(); // there are at least two elements + let mode = matches.free.remove(0); match verify_mode(mode.as_slice()) { Ok(_) => Some(mode), Err(f) => { @@ -143,7 +145,7 @@ fn verify_mode(mode: &str) -> Result<(), String> { Ok(()) } -fn chmod(files: Vec, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option, cmode: Option<&String>) -> Result<(), int> { +fn chmod(files: Vec, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option, cmode: Option<&String>) -> Result<(), isize> { let mut r = Ok(()); for filename in files.iter() { @@ -179,8 +181,8 @@ fn chmod(files: Vec, changes: bool, quiet: bool, verbose: bool, preserve r } -fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option, cmode: Option<&String>) -> Result<(), int> { - let path = name.to_c_str(); +fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool, fmode: Option, cmode: Option<&String>) -> Result<(), isize> { + let path = CString::from_slice(name.as_bytes()); match fmode { Some(mode) => { if unsafe { libc::chmod(path.as_ptr(), mode) } == 0 { @@ -210,7 +212,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool if levels.len() == 0 { levels = "a"; } - let change_str = cap.at(3).to_string() + "+"; + let change_str = cap.at(3).unwrap().to_string() + "+"; let change = change_str.as_slice(); let mut action = change.char_at(0); let mut rwx = 0; diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index a4d74c04c..db7e4a2bb 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -14,7 +14,7 @@ extern crate libc; use getopts::{optflag, optopt, getopts, usage}; use c_types::{get_pw_from_args, get_group}; use libc::funcs::posix88::unistd::{execvp, setuid, setgid}; -use std::ffi::c_str_to_bytes; +use std::ffi::{c_str_to_bytes, CString}; use std::io::fs::PathExtensions; use std::iter::FromIterator; @@ -38,7 +38,7 @@ extern { static NAME: &'static str = "chroot"; static VERSION: &'static str = "1.0.0"; -pub fn uumain(args: Vec) -> int { +pub fn uumain(args: Vec) -> isize { let program = &args[0]; let options = [ @@ -93,10 +93,10 @@ pub fn uumain(args: Vec) -> int { set_context(&newroot, &opts); unsafe { - let executable = command[0].as_slice().to_c_str().into_inner(); - let mut command_parts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().into_inner()).collect(); + let executable = CString::from_slice(command[0].as_bytes()).as_slice_with_nul().as_ptr(); + let mut command_parts: Vec<*const i8> = command.iter().map(|x| CString::from_slice(x.as_bytes()).as_slice_with_nul().as_ptr()).collect(); command_parts.push(std::ptr::null()); - execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as int + execvp(executable as *const libc::c_char, command_parts.as_ptr() as *mut *const libc::c_char) as isize } } @@ -129,7 +129,7 @@ fn enter_chroot(root: &Path) { let root_str = root.display(); std::os::change_dir(root).unwrap(); let err = unsafe { - chroot(".".to_c_str().into_inner() as *const libc::c_char) + chroot(CString::from_slice(b".").as_slice_with_nul().as_ptr() as *const libc::c_char) }; if err != 0 { crash!(1, "cannot chroot to {}: {}", root_str, strerror(err).as_slice()) diff --git a/src/cksum/cksum.rs b/src/cksum/cksum.rs index 8c29652c9..c1a5a3e89 100644 --- a/src/cksum/cksum.rs +++ b/src/cksum/cksum.rs @@ -28,11 +28,11 @@ static VERSION: &'static str = "1.0.0"; #[inline] fn crc_update(crc: u32, input: u8) -> u32 { - (crc << 8) ^ CRC_TABLE[((crc >> 24) as uint ^ input as uint) & 0xFF] + (crc << 8) ^ CRC_TABLE[((crc >> 24) as usize ^ input as usize) & 0xFF] } #[inline] -fn crc_final(mut crc: u32, mut length: uint) -> u32 { +fn crc_final(mut crc: u32, mut length: usize) -> u32 { while length != 0 { crc = crc_update(crc, length as u8); length >>= 8; @@ -42,7 +42,7 @@ fn crc_final(mut crc: u32, mut length: uint) -> u32 { } #[inline] -fn cksum(fname: &str) -> IoResult<(u32, uint)> { +fn cksum(fname: &str) -> IoResult<(u32, usize)> { let mut crc = 0u32; let mut size = 0u; @@ -74,7 +74,7 @@ fn cksum(fname: &str) -> IoResult<(u32, uint)> { } } -pub fn uumain(args: Vec) -> int { +pub fn uumain(args: Vec) -> isize { let opts = [ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"), diff --git a/src/comm/comm.rs b/src/comm/comm.rs index 8f16cdc0f..16f04072b 100644 --- a/src/comm/comm.rs +++ b/src/comm/comm.rs @@ -20,7 +20,7 @@ use std::path::Path; static NAME : &'static str = "comm"; static VERSION : &'static str = "1.0.0"; -fn mkdelim(col: uint, opts: &getopts::Matches) -> String { +fn mkdelim(col: usize, opts: &getopts::Matches) -> String { let mut s = String::new(); let delim = match opts.opt_str("output-delimiter") { Some(d) => d.clone(), @@ -52,8 +52,8 @@ enum LineReader { impl LineReader { fn read_line(&mut self) -> IoResult { match self { - &LineReader::Stdin(ref mut r) => r.read_line(), - &LineReader::FileIn(ref mut r) => r.read_line(), + &mut LineReader::Stdin(ref mut r) => r.read_line(), + &mut LineReader::FileIn(ref mut r) => r.read_line(), } } } @@ -107,7 +107,7 @@ fn open_file(name: &str) -> IoResult { } } -pub fn uumain(args: Vec) -> int { +pub fn uumain(args: Vec) -> isize { let opts = [ getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"), getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"), diff --git a/src/common/c_types.rs b/src/common/c_types.rs index 0650a51d7..78fde5648 100644 --- a/src/common/c_types.rs +++ b/src/common/c_types.rs @@ -167,15 +167,15 @@ pub fn get_group(groupname: &str) -> Option { pub fn get_group_list(name: *const c_char, gid: gid_t) -> Vec { let mut ngroups: c_int = 32; - let mut groups: Vec = Vec::with_capacity(ngroups as uint); + let mut groups: Vec = Vec::with_capacity(ngroups as usize); if unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups) } == -1 { - groups.reserve(ngroups as uint); + groups.reserve(ngroups as usize); unsafe { get_group_list_internal(name, gid, groups.as_mut_ptr(), &mut ngroups); } } else { - groups.truncate(ngroups as uint); + groups.truncate(ngroups as usize); } - unsafe { groups.set_len(ngroups as uint); } + unsafe { groups.set_len(ngroups as usize); } groups } @@ -199,18 +199,18 @@ unsafe fn get_group_list_internal(name: *const c_char, gid: gid_t, groups: *mut } } -pub fn get_groups() -> Result, uint> { +pub fn get_groups() -> Result, usize> { let ngroups = unsafe { getgroups(0, null_mut()) }; if ngroups == -1 { return Err(os::errno()); } - let mut groups : Vec= repeat(0).take(ngroups as uint).collect(); + let mut groups : Vec= repeat(0).take(ngroups as usize).collect(); let ngroups = unsafe { getgroups(ngroups, groups.as_mut_ptr()) }; if ngroups == -1 { Err(os::errno()) } else { - groups.truncate(ngroups as uint); + groups.truncate(ngroups as usize); Ok(groups) } } diff --git a/src/common/util.rs b/src/common/util.rs index 2aaf848ba..7ee97b5f2 100644 --- a/src/common/util.rs +++ b/src/common/util.rs @@ -10,42 +10,42 @@ extern crate libc; macro_rules! show_error( - ($($args:expr),+) => ({ + ($($args:tt)+) => ({ pipe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); - pipe_writeln!(&mut ::std::io::stderr(), $($args),+); + pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); #[macro_export] macro_rules! show_warning( - ($($args:expr),+) => ({ + ($($args:tt)+) => ({ pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", ::NAME); - pipe_writeln!(&mut ::std::io::stderr(), $($args),+); + pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); #[macro_export] macro_rules! show_info( - ($($args:expr),+) => ({ + ($($args:tt)+) => ({ pipe_write!(&mut ::std::io::stderr(), "{}: ", ::NAME); - pipe_writeln!(&mut ::std::io::stderr(), $($args),+); + pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); #[macro_export] macro_rules! eprint( - ($($args:expr),+) => (pipe_write!(&mut ::std::io::stderr(), $($args),+)) + ($($args:tt)+) => (pipe_write!(&mut ::std::io::stderr(), $($args)+)) ); #[macro_export] macro_rules! eprintln( - ($($args:expr),+) => (pipe_writeln!(&mut ::std::io::stderr(), $($args),+)) + ($($args:tt)+) => (pipe_writeln!(&mut ::std::io::stderr(), $($args)+)) ); #[macro_export] macro_rules! crash( - ($exitcode:expr, $($args:expr),+) => ({ - show_error!($($args),+); + ($exitcode:expr, $($args:tt)+) => ({ + show_error!($($args)+); unsafe { ::util::libc::exit($exitcode as ::util::libc::c_int); } }) ); @@ -84,8 +84,8 @@ macro_rules! return_if_err( #[macro_export] macro_rules! pipe_print( - ($($args:expr),+) => ( - match write!(&mut ::std::io::stdout(), $($args),+) { + ($($args:tt)+) => ( + match write!(&mut ::std::io::stdout(), $($args)+) { Ok(_) => true, Err(f) => { if f.kind == ::std::io::BrokenPipe { @@ -100,8 +100,8 @@ macro_rules! pipe_print( #[macro_export] macro_rules! pipe_println( - ($($args:expr),+) => ( - match writeln!(&mut ::std::io::stdout(), $($args),+) { + ($($args:tt)+) => ( + match writeln!(&mut ::std::io::stdout(), $($args)+) { Ok(_) => true, Err(f) => { if f.kind == ::std::io::BrokenPipe { @@ -116,8 +116,8 @@ macro_rules! pipe_println( #[macro_export] macro_rules! pipe_write( - ($fd:expr, $($args:expr),+) => ( - match write!($fd, $($args),+) { + ($fd:expr, $($args:tt)+) => ( + match write!($fd, $($args)+) { Ok(_) => true, Err(f) => { if f.kind == ::std::io::BrokenPipe { @@ -132,8 +132,8 @@ macro_rules! pipe_write( #[macro_export] macro_rules! pipe_writeln( - ($fd:expr, $($args:expr),+) => ( - match writeln!($fd, $($args),+) { + ($fd:expr, $($args:tt)+) => ( + match writeln!($fd, $($args)+) { Ok(_) => true, Err(f) => { if f.kind == ::std::io::BrokenPipe { @@ -148,8 +148,8 @@ macro_rules! pipe_writeln( #[macro_export] macro_rules! safe_write( - ($fd:expr, $($args:expr),+) => ( - match write!($fd, $($args),+) { + ($fd:expr, $($args:tt)+) => ( + match write!($fd, $($args)+) { Ok(_) => {} Err(f) => panic!(f.to_string()) } @@ -158,8 +158,8 @@ macro_rules! safe_write( #[macro_export] macro_rules! safe_writeln( - ($fd:expr, $($args:expr),+) => ( - match writeln!($fd, $($args),+) { + ($fd:expr, $($args:tt)+) => ( + match writeln!($fd, $($args)+) { Ok(_) => {} Err(f) => panic!(f.to_string()) }