diff --git a/.gitignore b/.gitignore index 37ee9f928..c08be9d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ +target/ /src/*/gen_table -/target/ +/build/ /tmp/ /busybox/ *~ diff --git a/Cargo.toml b/Cargo.toml index 5313c1978..48ce1d7bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ all = [ ] [dependencies] +uucore = { path="src/uucore" } base64 = { optional=true, path="src/base64" } basename = { optional=true, path="src/basename" } cat = { optional=true, path="src/cat" } diff --git a/src/base64/Cargo.toml b/src/base64/Cargo.toml index 2d379acea..1de7788fb 100644 --- a/src/base64/Cargo.toml +++ b/src/base64/Cargo.toml @@ -11,6 +11,7 @@ path = "base64.rs" getopts = "*" libc = "*" rustc-serialize = "*" +uucore = { path="../uucore" } [[bin]] name="base64" diff --git a/src/base64/base64.rs b/src/base64/base64.rs index 0fa88de1a..9196b0399 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -13,6 +13,9 @@ extern crate rustc_serialize as serialize; extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use serialize::base64::{self, FromBase64, ToBase64}; use std::ascii::AsciiExt; @@ -21,10 +24,6 @@ use std::fs::File; use std::io::{BufReader, Read, stdin, stdout, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - enum Mode { Decode, Encode, diff --git a/src/basename/Cargo.toml b/src/basename/Cargo.toml index 82f68686c..c4538e925 100644 --- a/src/basename/Cargo.toml +++ b/src/basename/Cargo.toml @@ -10,6 +10,7 @@ path = "basename.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="basename" diff --git a/src/basename/basename.rs b/src/basename/basename.rs index 4fa9d4df9..6ca4cf002 100644 --- a/src/basename/basename.rs +++ b/src/basename/basename.rs @@ -12,14 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::io::Write; use std::path::{is_separator, PathBuf}; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "basename"; static VERSION: &'static str = "1.0.0"; diff --git a/src/cat/Cargo.toml b/src/cat/Cargo.toml index 1bcb50c16..44a3c5401 100644 --- a/src/cat/Cargo.toml +++ b/src/cat/Cargo.toml @@ -10,6 +10,7 @@ path = "cat.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="cat" diff --git a/src/cat/cat.rs b/src/cat/cat.rs index cfc65e668..829d46614 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -14,16 +14,15 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + +use libc::STDIN_FILENO; +use libc::{c_int, isatty}; use getopts::Options; use std::fs::File; use std::intrinsics::{copy_nonoverlapping}; use std::io::{stdout, stdin, stderr, Write, Read, Result}; -use libc::STDIN_FILENO; -use libc::{c_int, isatty}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; static NAME: &'static str = "cat"; static VERSION: &'static str = "1.0.0"; diff --git a/src/chmod/Cargo.toml b/src/chmod/Cargo.toml index d97b17592..fee66379a 100644 --- a/src/chmod/Cargo.toml +++ b/src/chmod/Cargo.toml @@ -14,6 +14,7 @@ aho-corasick = "*" memchr = "*" regex = "*" regex-syntax = "*" +uucore = { path="../uucore" } walker = "*" [[bin]] diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index 21ba9d7c5..9271d1bbe 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -19,23 +19,18 @@ extern crate regex; extern crate regex_syntax; extern crate walker; +#[macro_use] +extern crate uucore; + use getopts::Options; use regex::Regex; use std::ffi::CString; use std::io::{Error, Write}; use std::mem; use std::path::Path; +use uucore::fs::UUPathExt; use walker::Walker; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; - const NAME: &'static str = "chmod"; const VERSION: &'static str = "1.0.0"; diff --git a/src/chroot/Cargo.toml b/src/chroot/Cargo.toml index 2c6bfc660..ffbb535a9 100644 --- a/src/chroot/Cargo.toml +++ b/src/chroot/Cargo.toml @@ -10,6 +10,7 @@ path = "chroot.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="chroot" diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index 7575ca401..a69147e80 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -12,7 +12,9 @@ extern crate getopts; extern crate libc; -use c_types::{get_pw_from_args, get_group}; +#[macro_use] +extern crate uucore; + use getopts::Options; use libc::{setgid, setuid}; use std::ffi::CString; @@ -20,12 +22,8 @@ use std::io::{Error, Write}; use std::iter::FromIterator; use std::path::Path; use std::process::Command; - -#[path = "../common/util.rs"] #[macro_use] mod util; -#[path = "../common/c_types.rs"] mod c_types; -#[path = "../common/filesystem.rs"] mod filesystem; - -use filesystem::UUPathExt; +use uucore::c_types::{get_pw_from_args, get_group}; +use uucore::fs::UUPathExt; extern { fn chroot(path: *const libc::c_char) -> libc::c_int; diff --git a/src/cksum/Cargo.toml b/src/cksum/Cargo.toml index b6685f0fa..861340183 100644 --- a/src/cksum/Cargo.toml +++ b/src/cksum/Cargo.toml @@ -10,6 +10,7 @@ path = "cksum.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="cksum" diff --git a/src/cksum/cksum.rs b/src/cksum/cksum.rs index 8b0823c16..42548833e 100644 --- a/src/cksum/cksum.rs +++ b/src/cksum/cksum.rs @@ -11,6 +11,9 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::fs::File; use std::io::{self, stdin, Read, Write, BufReader}; @@ -19,10 +22,6 @@ use std::path::Path; use crc_table::CRC_TABLE; -#[path="../common/util.rs"] -#[macro_use] -mod util; - mod crc_table; static NAME: &'static str = "cksum"; diff --git a/src/cp/Cargo.toml b/src/cp/Cargo.toml index 32f7d0e8f..6717c6c79 100644 --- a/src/cp/Cargo.toml +++ b/src/cp/Cargo.toml @@ -10,6 +10,7 @@ path = "cp.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="cp" diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 18dd12093..04d0c8ea1 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -11,19 +11,14 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::fs; use std::io::{ErrorKind, Result, Write}; use std::path::Path; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::{canonicalize, CanonicalizeMode, UUPathExt}; +use uucore::fs::{canonicalize, CanonicalizeMode, UUPathExt}; #[derive(Clone, Eq, PartialEq)] pub enum Mode { diff --git a/src/cut/Cargo.toml b/src/cut/Cargo.toml index 3c28bf93c..acccbf657 100644 --- a/src/cut/Cargo.toml +++ b/src/cut/Cargo.toml @@ -10,6 +10,7 @@ path = "cut.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="cut" diff --git a/src/cut/cut.rs b/src/cut/cut.rs index c27849de5..a05679f08 100644 --- a/src/cut/cut.rs +++ b/src/cut/cut.rs @@ -12,22 +12,17 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{stdout, stdin, BufRead, BufReader, Read, Stdout, Write}; use std::path::Path; +use uucore::fs::UUPathExt; use ranges::Range; use searcher::Searcher; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; - mod buffer; mod ranges; mod searcher; diff --git a/src/du/Cargo.toml b/src/du/Cargo.toml index 2bbeba09e..5b26212e1 100644 --- a/src/du/Cargo.toml +++ b/src/du/Cargo.toml @@ -11,6 +11,7 @@ path = "du.rs" getopts = "*" libc = "*" time = "*" +uucore = { path="../uucore" } [[bin]] name="du" diff --git a/src/du/du.rs b/src/du/du.rs index b1cbb1ad7..cb60dcb0f 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -15,6 +15,9 @@ extern crate getopts; extern crate libc; extern crate time; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::{stderr, Write}; use std::os::unix::fs::MetadataExt; @@ -24,10 +27,6 @@ use time::Timespec; use std::sync::mpsc::channel; use std::thread; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "du"; static VERSION: &'static str = "1.0.0"; diff --git a/src/echo/Cargo.toml b/src/echo/Cargo.toml index deddcf2e4..7e8f4f427 100644 --- a/src/echo/Cargo.toml +++ b/src/echo/Cargo.toml @@ -10,6 +10,7 @@ path = "echo.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="echo" diff --git a/src/echo/echo.rs b/src/echo/echo.rs index 9102287d9..0e7508dfb 100644 --- a/src/echo/echo.rs +++ b/src/echo/echo.rs @@ -12,13 +12,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::io::Write; use std::str::from_utf8; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - #[allow(dead_code)] static NAME: &'static str = "echo"; static VERSION: &'static str = "1.0.0"; diff --git a/src/env/Cargo.toml b/src/env/Cargo.toml index 7edb50740..504088efc 100644 --- a/src/env/Cargo.toml +++ b/src/env/Cargo.toml @@ -10,6 +10,7 @@ path = "env.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="env" diff --git a/src/env/env.rs b/src/env/env.rs index b40c44942..eb5d8ebcb 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -13,14 +13,13 @@ #![allow(non_camel_case_types)] +#[macro_use] +extern crate uucore; + use std::env; use std::io::Write; use std::process::Command; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "env"; static VERSION: &'static str = "1.0.0"; diff --git a/src/expand/Cargo.toml b/src/expand/Cargo.toml index 1924ca905..0ad6f8e87 100644 --- a/src/expand/Cargo.toml +++ b/src/expand/Cargo.toml @@ -11,6 +11,7 @@ path = "expand.rs" getopts = "*" libc = "*" unicode-width = "*" +uucore = { path="../uucore" } [[bin]] name="expand" diff --git a/src/expand/expand.rs b/src/expand/expand.rs index a64313206..5312e631d 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -17,6 +17,9 @@ extern crate libc; extern crate rustc_unicode; extern crate unicode_width; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::iter::repeat; @@ -24,10 +27,6 @@ use std::str::from_utf8; use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "expand"; static VERSION: &'static str = "0.0.1"; diff --git a/src/expr/Cargo.toml b/src/expr/Cargo.toml index 31793d6b1..32567df84 100644 --- a/src/expr/Cargo.toml +++ b/src/expr/Cargo.toml @@ -11,6 +11,7 @@ path = "expr.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="expr" diff --git a/src/expr/expr.rs b/src/expr/expr.rs index 9a461b68b..9ed14f160 100644 --- a/src/expr/expr.rs +++ b/src/expr/expr.rs @@ -12,9 +12,9 @@ extern crate getopts; extern crate libc; -#[path="../common/util.rs"] #[macro_use] -mod util; +extern crate uucore; + mod tokens; mod syntax_tree; diff --git a/src/factor/Cargo.toml b/src/factor/Cargo.toml index 2cbb4e9d4..0498908fa 100644 --- a/src/factor/Cargo.toml +++ b/src/factor/Cargo.toml @@ -11,6 +11,7 @@ path = "factor.rs" getopts = "*" libc = "*" rand = "*" +uucore = { path="../uucore" } [[bin]] name="factor" diff --git a/src/factor/factor.rs b/src/factor/factor.rs index 92254370f..6399b4383 100644 --- a/src/factor/factor.rs +++ b/src/factor/factor.rs @@ -17,6 +17,9 @@ extern crate getopts; extern crate libc; extern crate rand; +#[macro_use] +extern crate uucore; + use numeric::*; use prime_table::P_INVS_U64; use rand::weak_rng; @@ -26,9 +29,6 @@ use std::io::{stdin, BufRead, BufReader, Write}; use std::num::Wrapping; use std::mem::swap; -#[path="../common/util.rs"] -#[macro_use] -mod util; mod numeric; mod prime_table; diff --git a/src/fmt/Cargo.toml b/src/fmt/Cargo.toml index 14d16f529..a70851434 100644 --- a/src/fmt/Cargo.toml +++ b/src/fmt/Cargo.toml @@ -11,6 +11,7 @@ path = "fmt.rs" getopts = "*" libc = "*" unicode-width = "*" +uucore = { path="../uucore" } [[bin]] name="fmt" diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index 1e0067e8f..06cb6205d 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -14,6 +14,9 @@ extern crate getopts; extern crate rustc_unicode; extern crate unicode_width; +#[macro_use] +extern crate uucore; + use std::cmp; use std::io::{Read, BufReader, BufWriter}; use std::fs::File; @@ -30,9 +33,6 @@ macro_rules! silent_unwrap( ) ); -#[path = "../common/util.rs"] -#[macro_use] -mod util; mod linebreak; mod parasplit; diff --git a/src/fold/Cargo.toml b/src/fold/Cargo.toml index 9712b86ef..5da2fed4d 100644 --- a/src/fold/Cargo.toml +++ b/src/fold/Cargo.toml @@ -10,6 +10,7 @@ path = "fold.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="fold" diff --git a/src/fold/fold.rs b/src/fold/fold.rs index 367e0360f..d75a317e4 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -12,14 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "fold"; static VERSION: &'static str = "1.0.0"; diff --git a/src/groups/Cargo.toml b/src/groups/Cargo.toml index 0f6a05413..684a250fc 100644 --- a/src/groups/Cargo.toml +++ b/src/groups/Cargo.toml @@ -10,6 +10,7 @@ path = "groups.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="groups" diff --git a/src/groups/groups.rs b/src/groups/groups.rs index 4883efd34..834922b84 100644 --- a/src/groups/groups.rs +++ b/src/groups/groups.rs @@ -9,13 +9,14 @@ * file that was distributed with this source code. * */ + extern crate getopts; -use c_types::{get_pw_from_args, group}; -use std::io::Write; +#[macro_use] +extern crate uucore; -#[path = "../common/util.rs"] #[macro_use] mod util; -#[path = "../common/c_types.rs"] mod c_types; +use std::io::Write; +use uucore::c_types::{get_pw_from_args, group}; static NAME: &'static str = "groups"; static VERSION: &'static str = "1.0.0"; diff --git a/src/hashsum/Cargo.toml b/src/hashsum/Cargo.toml index fa0547553..3e70dee34 100644 --- a/src/hashsum/Cargo.toml +++ b/src/hashsum/Cargo.toml @@ -13,6 +13,7 @@ libc = "*" regex = "*" regex-syntax = "*" rust-crypto = "*" +uucore = { path="../uucore" } [[bin]] name="hashsum" diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index 7afd0d40a..5fedb7e9b 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -16,6 +16,9 @@ extern crate getopts; extern crate regex_syntax; extern crate regex; +#[macro_use] +extern crate uucore; + use crypto::digest::Digest; use crypto::md5::Md5; use crypto::sha1::Sha1; @@ -26,10 +29,6 @@ use std::fs::File; use std::io::{self, BufRead, BufReader, Read, stdin, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "hashsum"; static VERSION: &'static str = "1.0.0"; diff --git a/src/head/Cargo.toml b/src/head/Cargo.toml index e5f012e16..930f8832d 100644 --- a/src/head/Cargo.toml +++ b/src/head/Cargo.toml @@ -10,6 +10,7 @@ path = "head.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="head" diff --git a/src/head/head.rs b/src/head/head.rs index cc61e6521..9d539687e 100644 --- a/src/head/head.rs +++ b/src/head/head.rs @@ -13,15 +13,14 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::fs::File; use std::path::Path; use std::str::from_utf8; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "head"; static VERSION: &'static str = "1.0.0"; diff --git a/src/hostid/Cargo.toml b/src/hostid/Cargo.toml index 796e96457..b2d0c746b 100644 --- a/src/hostid/Cargo.toml +++ b/src/hostid/Cargo.toml @@ -10,6 +10,7 @@ path = "hostid.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="hostid" diff --git a/src/hostid/hostid.rs b/src/hostid/hostid.rs index 30fe092ca..bab2c50a1 100644 --- a/src/hostid/hostid.rs +++ b/src/hostid/hostid.rs @@ -12,11 +12,10 @@ extern crate getopts; extern crate libc; -use libc::c_long; - -#[path = "../common/util.rs"] #[macro_use] -mod util; +extern crate uucore; + +use libc::c_long; static NAME: &'static str = "hostid"; static VERSION: &'static str = "0.0.1"; diff --git a/src/hostname/Cargo.toml b/src/hostname/Cargo.toml index 6f67767dc..45b06daf3 100644 --- a/src/hostname/Cargo.toml +++ b/src/hostname/Cargo.toml @@ -10,6 +10,7 @@ path = "hostname.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="hostname" diff --git a/src/hostname/hostname.rs b/src/hostname/hostname.rs index 6353f7c6c..1519bdbdc 100644 --- a/src/hostname/hostname.rs +++ b/src/hostname/hostname.rs @@ -16,16 +16,15 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + +use getopts::Options; use std::collections::hash_set::HashSet; use std::iter::repeat; use std::str; use std::io::Write; use std::net::ToSocketAddrs; -use getopts::Options; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; static NAME: &'static str = "hostname"; diff --git a/src/id/Cargo.toml b/src/id/Cargo.toml index c2803d60f..930f91f50 100644 --- a/src/id/Cargo.toml +++ b/src/id/Cargo.toml @@ -10,6 +10,7 @@ path = "id.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="id" diff --git a/src/id/id.rs b/src/id/id.rs index 5d5f74f79..f589d3345 100644 --- a/src/id/id.rs +++ b/src/id/id.rs @@ -17,11 +17,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use libc::{getgid, getuid, uid_t, getegid, geteuid, getlogin}; use std::ffi::CStr; use std::io::Write; use std::ptr::read; -use c_types::{ +use uucore::c_types::{ c_passwd, c_group, get_groups, @@ -31,9 +34,6 @@ use c_types::{ group }; -#[path = "../common/util.rs"] #[macro_use] mod util; -#[path = "../common/c_types.rs"] mod c_types; - #[cfg(not(target_os = "linux"))] mod audit { pub use std::mem::uninitialized; diff --git a/src/kill/Cargo.toml b/src/kill/Cargo.toml index cb0939dea..b90b8a3ad 100644 --- a/src/kill/Cargo.toml +++ b/src/kill/Cargo.toml @@ -10,6 +10,7 @@ path = "kill.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="kill" diff --git a/src/kill/kill.rs b/src/kill/kill.rs index 99aa40178..08626b850 100644 --- a/src/kill/kill.rs +++ b/src/kill/kill.rs @@ -12,19 +12,12 @@ extern crate getopts; extern crate libc; -use libc::{c_int, pid_t}; -use signals::ALL_SIGNALS; -use std::io::{Error, Write}; - -#[path = "../common/util.rs"] #[macro_use] -mod util; +extern crate uucore; -#[path = "../common/c_types.rs"] -mod c_types; - -#[path = "../common/signals.rs"] -mod signals; +use libc::{c_int, pid_t}; +use std::io::{Error, Write}; +use uucore::signals::ALL_SIGNALS; static NAME: &'static str = "kill"; static VERSION: &'static str = "0.0.1"; @@ -96,7 +89,7 @@ fn handle_obsolete(mut args: Vec) -> (Vec, Option) { let val = &slice[1..]; match val.parse() { Ok(num) => { - if signals::is_signal(num) { + if uucore::signals::is_signal(num) { args.remove(i); return (args, Some(val.to_string())); } @@ -174,7 +167,7 @@ Usage: fn kill(signalname: &str, pids: std::vec::Vec) -> i32 { let mut status = 0; - let optional_signal_value = signals::signal_by_name_or_value(signalname); + let optional_signal_value = uucore::signals::signal_by_name_or_value(signalname); let signal_value = match optional_signal_value { Some(x) => x, None => crash!(EXIT_ERR, "unknown signal name {}", signalname) diff --git a/src/link/Cargo.toml b/src/link/Cargo.toml index c762bd738..24fe96770 100644 --- a/src/link/Cargo.toml +++ b/src/link/Cargo.toml @@ -10,6 +10,7 @@ path = "link.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="link" diff --git a/src/link/link.rs b/src/link/link.rs index 3777b0444..37fde7d4a 100644 --- a/src/link/link.rs +++ b/src/link/link.rs @@ -11,14 +11,13 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::fs::hard_link; use std::io::Write; use std::path::Path; -#[path="../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "link"; static VERSION: &'static str = "1.0.0"; diff --git a/src/ln/Cargo.toml b/src/ln/Cargo.toml index f617aa8e0..e4973c1cc 100644 --- a/src/ln/Cargo.toml +++ b/src/ln/Cargo.toml @@ -10,6 +10,7 @@ path = "ln.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="ln" diff --git a/src/ln/ln.rs b/src/ln/ln.rs index 5c2a9c866..6e8e19518 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -11,20 +11,15 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::{BufRead, BufReader, Result, stdin, Write}; #[cfg(unix)] use std::os::unix::fs::symlink as symlink_file; #[cfg(windows)] use std::os::windows::fs::symlink_file; use std::path::{Path, PathBuf}; - -#[path="../common/util.rs"] -#[macro_use] -mod util; - -#[path="../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; static NAME: &'static str = "ln"; static VERSION: &'static str = "1.0.0"; diff --git a/src/logname/Cargo.toml b/src/logname/Cargo.toml index 2fc373c2e..824f99893 100644 --- a/src/logname/Cargo.toml +++ b/src/logname/Cargo.toml @@ -10,6 +10,7 @@ path = "logname.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="logname" diff --git a/src/logname/logname.rs b/src/logname/logname.rs index 39c1fc3c6..6e5dd0465 100644 --- a/src/logname/logname.rs +++ b/src/logname/logname.rs @@ -14,11 +14,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::ffi::CStr; use std::io::Write; -#[path = "../common/util.rs"] #[macro_use] mod util; - extern { // POSIX requires using getlogin (or equivalent code) pub fn getlogin() -> *const libc::c_char; diff --git a/src/mkdir/Cargo.toml b/src/mkdir/Cargo.toml index 1afcf60c6..99824019e 100644 --- a/src/mkdir/Cargo.toml +++ b/src/mkdir/Cargo.toml @@ -10,6 +10,7 @@ path = "mkdir.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="mkdir" diff --git a/src/mkdir/mkdir.rs b/src/mkdir/mkdir.rs index 7fce74011..dffcbc78a 100644 --- a/src/mkdir/mkdir.rs +++ b/src/mkdir/mkdir.rs @@ -12,19 +12,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::ffi::CString; use std::fs; use std::io::{Error, Write}; use std::path::{Path, PathBuf}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; static NAME: &'static str = "mkdir"; static VERSION: &'static str = "1.0.0"; diff --git a/src/mkfifo/Cargo.toml b/src/mkfifo/Cargo.toml index c733a2cb9..360e69c2b 100644 --- a/src/mkfifo/Cargo.toml +++ b/src/mkfifo/Cargo.toml @@ -10,6 +10,7 @@ path = "mkfifo.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="mkfifo" diff --git a/src/mkfifo/mkfifo.rs b/src/mkfifo/mkfifo.rs index ff8c11ed3..795b689be 100644 --- a/src/mkfifo/mkfifo.rs +++ b/src/mkfifo/mkfifo.rs @@ -12,14 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use libc::mkfifo; use std::ffi::CString; use std::io::{Error, Write}; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "mkfifo"; static VERSION: &'static str = "1.0.0"; diff --git a/src/mv/Cargo.toml b/src/mv/Cargo.toml index 5a3a1cf03..82dfa90e0 100644 --- a/src/mv/Cargo.toml +++ b/src/mv/Cargo.toml @@ -10,6 +10,7 @@ path = "mv.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [dev-dependencies] time = "*" diff --git a/src/mv/mv.rs b/src/mv/mv.rs index 2ce69b256..f84a0ae2b 100644 --- a/src/mv/mv.rs +++ b/src/mv/mv.rs @@ -13,19 +13,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::{BufRead, BufReader, Result, stdin, Write}; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; static NAME: &'static str = "mv"; static VERSION: &'static str = "0.0.1"; diff --git a/src/nice/Cargo.toml b/src/nice/Cargo.toml index 38bf0a322..9fa1c051c 100644 --- a/src/nice/Cargo.toml +++ b/src/nice/Cargo.toml @@ -10,6 +10,7 @@ path = "nice.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="nice" diff --git a/src/nice/nice.rs b/src/nice/nice.rs index 2b4e9285b..92d4d85f5 100644 --- a/src/nice/nice.rs +++ b/src/nice/nice.rs @@ -12,6 +12,9 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use libc::{c_char, c_int, execvp}; use std::ffi::CString; use std::io::{Error, Write}; @@ -22,10 +25,6 @@ const VERSION: &'static str = "1.0.0"; // XXX: PRIO_PROCESS is 0 on at least FreeBSD and Linux. Don't know about Mac OS X. const PRIO_PROCESS: c_int = 0; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - extern { fn getpriority(which: c_int, who: c_int) -> c_int; fn setpriority(which: c_int, who: c_int, prio: c_int) -> c_int; diff --git a/src/nl/Cargo.toml b/src/nl/Cargo.toml index 1c05d75ca..f5a700e5d 100644 --- a/src/nl/Cargo.toml +++ b/src/nl/Cargo.toml @@ -14,6 +14,7 @@ aho-corasick = "*" memchr = "*" regex = "*" regex-syntax = "*" +uucore = { path="../uucore" } [[bin]] name="nl" diff --git a/src/nl/nl.rs b/src/nl/nl.rs index 7d5a3a8e9..7b15bd3e6 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -16,14 +16,14 @@ extern crate memchr; extern crate regex_syntax; extern crate regex; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::iter::repeat; use std::path::Path; -#[path="../common/util.rs"] -#[macro_use] -mod util; mod helper; static NAME: &'static str = "nl"; diff --git a/src/nohup/Cargo.toml b/src/nohup/Cargo.toml index 70766b16b..e902d5d6c 100644 --- a/src/nohup/Cargo.toml +++ b/src/nohup/Cargo.toml @@ -10,6 +10,7 @@ path = "nohup.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="nohup" diff --git a/src/nohup/nohup.rs b/src/nohup/nohup.rs index fb7958faa..e0cdd4b98 100644 --- a/src/nohup/nohup.rs +++ b/src/nohup/nohup.rs @@ -12,6 +12,9 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use libc::{c_char, signal, dup2, execvp, isatty}; use libc::{SIG_IGN, SIGHUP}; use std::ffi::CString; @@ -21,9 +24,6 @@ use std::os::unix::prelude::*; use std::path::{Path, PathBuf}; use std::env; -#[path = "../common/util.rs"] #[macro_use] mod util; -#[path = "../common/c_types.rs"] mod c_types; - static NAME: &'static str = "nohup"; static VERSION: &'static str = "1.0.0"; diff --git a/src/nproc/Cargo.toml b/src/nproc/Cargo.toml index d0c1ea9be..3ad1c9e34 100644 --- a/src/nproc/Cargo.toml +++ b/src/nproc/Cargo.toml @@ -11,6 +11,7 @@ path = "nproc.rs" getopts = "*" libc = "*" num_cpus = "*" +uucore = { path="../uucore" } [[bin]] name="nproc" diff --git a/src/nproc/nproc.rs b/src/nproc/nproc.rs index 0e64c8500..f0b7c97fb 100644 --- a/src/nproc/nproc.rs +++ b/src/nproc/nproc.rs @@ -12,16 +12,15 @@ extern crate getopts; extern crate num_cpus; +#[macro_use] +extern crate uucore; + use std::io::Write; use std::env; static NAME : &'static str = "nproc"; static VERSION : &'static str = "0.0.0"; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/paste/Cargo.toml b/src/paste/Cargo.toml index 95f992752..0b22ba4ed 100644 --- a/src/paste/Cargo.toml +++ b/src/paste/Cargo.toml @@ -10,6 +10,7 @@ path = "paste.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="paste" diff --git a/src/paste/paste.rs b/src/paste/paste.rs index 8b6c15f3c..f170452af 100644 --- a/src/paste/paste.rs +++ b/src/paste/paste.rs @@ -12,15 +12,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::iter::repeat; use std::fs::File; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "paste"; static VERSION: &'static str = "1.0.0"; diff --git a/src/printenv/Cargo.toml b/src/printenv/Cargo.toml index a3ee2009e..fa378b465 100644 --- a/src/printenv/Cargo.toml +++ b/src/printenv/Cargo.toml @@ -10,6 +10,7 @@ path = "printenv.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="printenv" diff --git a/src/printenv/printenv.rs b/src/printenv/printenv.rs index 0995bea92..025294cff 100644 --- a/src/printenv/printenv.rs +++ b/src/printenv/printenv.rs @@ -14,13 +14,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::io::Write; use std::env; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "printenv"; static VERSION: &'static str = "1.0.0"; diff --git a/src/ptx/Cargo.toml b/src/ptx/Cargo.toml index 9d43268c6..708d2c944 100644 --- a/src/ptx/Cargo.toml +++ b/src/ptx/Cargo.toml @@ -14,6 +14,7 @@ aho-corasick = "*" memchr = "*" regex-syntax = "*" regex = "*" +uucore = { path="../uucore" } [[bin]] name="ptx" diff --git a/src/ptx/ptx.rs b/src/ptx/ptx.rs index d766e88ae..681ffa5ea 100644 --- a/src/ptx/ptx.rs +++ b/src/ptx/ptx.rs @@ -15,18 +15,16 @@ extern crate memchr; extern crate regex_syntax; extern crate regex; +#[macro_use] +extern crate uucore; + +use getopts::{Options, Matches}; +use regex::Regex; +use std::cmp; use std::collections::{HashMap, HashSet, BTreeSet}; use std::default::Default; use std::fs::File; -use getopts::{Options, Matches}; use std::io::{stdin, stdout, BufReader, BufWriter, BufRead, Read, Write}; -use regex::Regex; -use std::cmp; - - -#[path = "../common/util.rs"] -#[macro_use] -mod util; static NAME: &'static str = "ptx"; static VERSION: &'static str = "1.0.0"; diff --git a/src/pwd/Cargo.toml b/src/pwd/Cargo.toml index cdf4c7f48..e72800968 100644 --- a/src/pwd/Cargo.toml +++ b/src/pwd/Cargo.toml @@ -10,6 +10,7 @@ path = "pwd.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="pwd" diff --git a/src/pwd/pwd.rs b/src/pwd/pwd.rs index ac645626e..0f423ae2f 100644 --- a/src/pwd/pwd.rs +++ b/src/pwd/pwd.rs @@ -12,13 +12,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::io::Write; use std::env; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "pwd"; static VERSION: &'static str = "1.0.0"; diff --git a/src/readlink/Cargo.toml b/src/readlink/Cargo.toml index d46dd5954..e18e9ecfe 100644 --- a/src/readlink/Cargo.toml +++ b/src/readlink/Cargo.toml @@ -10,6 +10,7 @@ path = "readlink.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="readlink" diff --git a/src/readlink/readlink.rs b/src/readlink/readlink.rs index da65d5056..9249bd5fd 100644 --- a/src/readlink/readlink.rs +++ b/src/readlink/readlink.rs @@ -11,18 +11,13 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::Write; use std::path::PathBuf; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::{canonicalize, CanonicalizeMode}; +use uucore::fs::{canonicalize, CanonicalizeMode}; const NAME: &'static str = "readlink"; const VERSION: &'static str = "0.0.1"; diff --git a/src/realpath/Cargo.toml b/src/realpath/Cargo.toml index 329415b86..7cef34d27 100644 --- a/src/realpath/Cargo.toml +++ b/src/realpath/Cargo.toml @@ -10,6 +10,7 @@ path = "realpath.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="realpath" diff --git a/src/realpath/realpath.rs b/src/realpath/realpath.rs index 7a2c9d325..a0b6cda4f 100644 --- a/src/realpath/realpath.rs +++ b/src/realpath/realpath.rs @@ -12,18 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::{canonicalize, CanonicalizeMode}; +use uucore::fs::{canonicalize, CanonicalizeMode}; static NAME: &'static str = "realpath"; static VERSION: &'static str = "1.0.0"; diff --git a/src/relpath/Cargo.toml b/src/relpath/Cargo.toml index 11efcca2c..2b9627adb 100644 --- a/src/relpath/Cargo.toml +++ b/src/relpath/Cargo.toml @@ -10,6 +10,7 @@ path = "relpath.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="relpath" diff --git a/src/relpath/relpath.rs b/src/relpath/relpath.rs index c0c01185f..ab982c7f0 100644 --- a/src/relpath/relpath.rs +++ b/src/relpath/relpath.rs @@ -12,18 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::env; use std::io::Write; use std::path::{Path, PathBuf}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::{canonicalize, CanonicalizeMode}; +use uucore::fs::{canonicalize, CanonicalizeMode}; static NAME: &'static str = "relpath"; static VERSION: &'static str = "1.0.0"; diff --git a/src/rm/Cargo.toml b/src/rm/Cargo.toml index dc4128ec3..5879ee076 100644 --- a/src/rm/Cargo.toml +++ b/src/rm/Cargo.toml @@ -10,6 +10,7 @@ path = "rm.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="rm" diff --git a/src/rm/rm.rs b/src/rm/rm.rs index 34e1e1e42..c9d859dc5 100644 --- a/src/rm/rm.rs +++ b/src/rm/rm.rs @@ -12,20 +12,15 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::collections::VecDeque; use std::fs; use std::io::{stdin, stderr, BufRead, Write}; use std::ops::BitOr; use std::path::{Path, PathBuf}; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; #[derive(Eq, PartialEq, Clone, Copy)] enum InteractiveMode { diff --git a/src/rmdir/Cargo.toml b/src/rmdir/Cargo.toml index 667643385..97ce7f1cc 100644 --- a/src/rmdir/Cargo.toml +++ b/src/rmdir/Cargo.toml @@ -10,6 +10,7 @@ path = "rmdir.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="rmdir" diff --git a/src/rmdir/rmdir.rs b/src/rmdir/rmdir.rs index 68ddf76e3..dba5d0332 100644 --- a/src/rmdir/rmdir.rs +++ b/src/rmdir/rmdir.rs @@ -12,14 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs; use std::io::Write; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "rmdir"; static VERSION: &'static str = "1.0.0"; diff --git a/src/seq/Cargo.toml b/src/seq/Cargo.toml index dc3634507..5e8fc0629 100644 --- a/src/seq/Cargo.toml +++ b/src/seq/Cargo.toml @@ -10,6 +10,7 @@ path = "seq.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="seq" diff --git a/src/seq/seq.rs b/src/seq/seq.rs index e28714633..90de55d32 100644 --- a/src/seq/seq.rs +++ b/src/seq/seq.rs @@ -6,13 +6,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::cmp; use std::io::Write; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "seq"; static VERSION: &'static str = "1.0.0"; diff --git a/src/shuf/Cargo.toml b/src/shuf/Cargo.toml index 944d4ddd9..8b5d7e14e 100644 --- a/src/shuf/Cargo.toml +++ b/src/shuf/Cargo.toml @@ -11,6 +11,7 @@ path = "shuf.rs" getopts = "*" libc = "*" rand = "*" +uucore = { path="../uucore" } [[bin]] name="shuf" diff --git a/src/shuf/shuf.rs b/src/shuf/shuf.rs index 34ca1614e..87e5a8b0f 100644 --- a/src/shuf/shuf.rs +++ b/src/shuf/shuf.rs @@ -13,16 +13,15 @@ extern crate getopts; extern crate libc; extern crate rand; +#[macro_use] +extern crate uucore; + use rand::{Rng, ThreadRng}; use rand::read::ReadRng; use std::fs::File; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use std::usize::MAX as MAX_USIZE; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - enum Mode { Default, Echo, diff --git a/src/sleep/Cargo.toml b/src/sleep/Cargo.toml index 4a14913ce..8430e420a 100644 --- a/src/sleep/Cargo.toml +++ b/src/sleep/Cargo.toml @@ -10,6 +10,7 @@ path = "sleep.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="sleep" diff --git a/src/sleep/sleep.rs b/src/sleep/sleep.rs index 545ba6600..5052988a7 100644 --- a/src/sleep/sleep.rs +++ b/src/sleep/sleep.rs @@ -12,18 +12,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::io::Write; use std::thread::{self}; use std::time::Duration; use std::u32::MAX as U32_MAX; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/parse_time.rs"] -mod parse_time; - static NAME: &'static str = "sleep"; static VERSION: &'static str = "1.0.0"; @@ -68,7 +64,7 @@ specified by the sum of their values.", NAME, VERSION); fn sleep(args: Vec) { let sleep_time = args.iter().fold(0.0, |result, arg| - match parse_time::from_str(&arg[..]) { + match uucore::parse_time::from_str(&arg[..]) { Ok(m) => m + result, Err(f) => crash!(1, "{}", f), }); diff --git a/src/sort/Cargo.toml b/src/sort/Cargo.toml index c0c9290a9..a7ab52be4 100644 --- a/src/sort/Cargo.toml +++ b/src/sort/Cargo.toml @@ -10,6 +10,7 @@ path = "sort.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="sort" diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 67d72b8fe..89710a571 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -14,6 +14,9 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use libc::STDIN_FILENO; use libc::{c_int, isatty}; use std::cmp::Ordering; @@ -21,10 +24,6 @@ use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "sort"; static VERSION: &'static str = "0.0.1"; diff --git a/src/split/Cargo.toml b/src/split/Cargo.toml index 7c6e1b579..cda1dad48 100644 --- a/src/split/Cargo.toml +++ b/src/split/Cargo.toml @@ -10,6 +10,7 @@ path = "split.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="split" diff --git a/src/split/split.rs b/src/split/split.rs index dfd320789..de9b27817 100644 --- a/src/split/split.rs +++ b/src/split/split.rs @@ -12,15 +12,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::char; use std::fs::{File, OpenOptions}; use std::io::{BufRead, BufReader, BufWriter, Read, stdin, stdout, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "split"; static VERSION: &'static str = "1.0.0"; diff --git a/src/stdbuf/Cargo.toml b/src/stdbuf/Cargo.toml index c21aa55f5..4e2c22d9b 100644 --- a/src/stdbuf/Cargo.toml +++ b/src/stdbuf/Cargo.toml @@ -10,6 +10,7 @@ path = "stdbuf.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="stdbuf" diff --git a/src/stdbuf/libstdbuf.rs b/src/stdbuf/libstdbuf.rs index 6ff620a99..3ee5f22da 100644 --- a/src/stdbuf/libstdbuf.rs +++ b/src/stdbuf/libstdbuf.rs @@ -3,15 +3,14 @@ extern crate libc; +#[macro_use] +extern crate uucore; + use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF, setvbuf}; use std::env; use std::io::Write; use std::ptr; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - extern { static stdin: *mut FILE; static stdout: *mut FILE; diff --git a/src/stdbuf/stdbuf.rs b/src/stdbuf/stdbuf.rs index 300ffd83e..ff24c23eb 100644 --- a/src/stdbuf/stdbuf.rs +++ b/src/stdbuf/stdbuf.rs @@ -12,20 +12,15 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::{Matches, Options}; use std::io::{self, Write}; use std::os::unix::process::ExitStatusExt; use std::path::PathBuf; use std::process::Command; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::{canonicalize, CanonicalizeMode, UUPathExt}; +use uucore::fs::{canonicalize, CanonicalizeMode, UUPathExt}; static NAME: &'static str = "stdbuf"; static VERSION: &'static str = "1.0.0"; diff --git a/src/sum/Cargo.toml b/src/sum/Cargo.toml index f10bc5745..3f9bbc5af 100644 --- a/src/sum/Cargo.toml +++ b/src/sum/Cargo.toml @@ -10,6 +10,7 @@ path = "sum.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="sum" diff --git a/src/sum/sum.rs b/src/sum/sum.rs index 690ce1198..1febb2446 100644 --- a/src/sum/sum.rs +++ b/src/sum/sum.rs @@ -12,14 +12,13 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{Read, Result, stdin, Write}; use std::path::Path; -#[path="../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "sum"; static VERSION: &'static str = "1.0.0"; diff --git a/src/sync/Cargo.toml b/src/sync/Cargo.toml index 5e58cb359..9d2cacb46 100644 --- a/src/sync/Cargo.toml +++ b/src/sync/Cargo.toml @@ -10,6 +10,7 @@ path = "sync.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="sync" diff --git a/src/sync/sync.rs b/src/sync/sync.rs index a0dfccf69..a23e0c123 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -14,8 +14,8 @@ extern crate getopts; extern crate libc; -#[path = "../common/util.rs"] #[macro_use] mod util; -#[cfg(windows)] #[path = "../common/wide.rs"] mod wide; +#[macro_use] +extern crate uucore; static NAME: &'static str = "sync"; static VERSION: &'static str = "1.0.0"; @@ -42,7 +42,7 @@ mod platform { use std::fs::OpenOptions; use std::io::{Write}; use std::os::windows::prelude::*; - use wide::{FromWide, ToWide}; + use uucore::wide::{FromWide, ToWide}; unsafe fn flush_volume(name: &str) { let name_wide = name.to_wide_null(); diff --git a/src/tac/Cargo.toml b/src/tac/Cargo.toml index aa3b3d563..806fd552f 100644 --- a/src/tac/Cargo.toml +++ b/src/tac/Cargo.toml @@ -10,6 +10,7 @@ path = "tac.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="tac" diff --git a/src/tac/tac.rs b/src/tac/tac.rs index 49997fa57..3620d948b 100644 --- a/src/tac/tac.rs +++ b/src/tac/tac.rs @@ -12,13 +12,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{BufReader, Read, stdin, stdout, Stdout, Write}; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "tac"; static VERSION: &'static str = "1.0.0"; diff --git a/src/tail/Cargo.toml b/src/tail/Cargo.toml index bc3e0e2f6..4468d4d4c 100644 --- a/src/tail/Cargo.toml +++ b/src/tail/Cargo.toml @@ -10,6 +10,7 @@ path = "tail.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="tail" diff --git a/src/tail/tail.rs b/src/tail/tail.rs index 45d91ec33..790a162ac 100644 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -12,6 +12,9 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::collections::VecDeque; use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin, stdout, Write}; @@ -20,10 +23,6 @@ use std::str::from_utf8; use std::thread::sleep; use std::time::Duration; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "tail"; static VERSION: &'static str = "0.0.1"; diff --git a/src/tee/Cargo.toml b/src/tee/Cargo.toml index f30515dbe..f97ed1927 100644 --- a/src/tee/Cargo.toml +++ b/src/tee/Cargo.toml @@ -10,6 +10,7 @@ path = "tee.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="tee" diff --git a/src/tee/tee.rs b/src/tee/tee.rs index ba712670e..fd3cafa61 100644 --- a/src/tee/tee.rs +++ b/src/tee/tee.rs @@ -11,14 +11,13 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use std::fs::OpenOptions; use std::io::{copy, Error, ErrorKind, Read, Result, sink, stdin, stdout, Write}; use std::path::{Path, PathBuf}; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "tee"; static VERSION: &'static str = "1.0.0"; diff --git a/src/test/Cargo.toml b/src/test/Cargo.toml index 17bf8e03e..3a89cd976 100644 --- a/src/test/Cargo.toml +++ b/src/test/Cargo.toml @@ -10,6 +10,7 @@ path = "test.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="test" diff --git a/src/timeout/Cargo.toml b/src/timeout/Cargo.toml index 1dac40526..85a0c9061 100644 --- a/src/timeout/Cargo.toml +++ b/src/timeout/Cargo.toml @@ -11,6 +11,7 @@ path = "timeout.rs" getopts = "*" libc = "*" time = "*" +uucore = { path="../uucore" } [[bin]] name="timeout" diff --git a/src/timeout/timeout.rs b/src/timeout/timeout.rs index c6867076a..2572aa3b7 100644 --- a/src/timeout/timeout.rs +++ b/src/timeout/timeout.rs @@ -13,24 +13,14 @@ extern crate getopts; extern crate libc; extern crate time; +#[macro_use] +extern crate uucore; + use libc::pid_t; use std::io::{ErrorKind, Write}; use std::process::{Command, Stdio}; use std::os::unix::process::ExitStatusExt; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/parse_time.rs"] -mod parse_time; - -#[path = "../common/signals.rs"] -mod signals; - -#[path = "../common/process.rs"] -mod process; -use process::ChildExt; +use uucore::process::ChildExt; extern { pub fn setpgid(_: libc::pid_t, _: libc::pid_t) -> libc::c_int; @@ -74,7 +64,7 @@ Usage: let status = matches.opt_present("preserve-status"); let foreground = matches.opt_present("foreground"); let kill_after = match matches.opt_str("kill-after") { - Some(tstr) => match parse_time::from_str(&tstr) { + Some(tstr) => match uucore::parse_time::from_str(&tstr) { Ok(time) => time, Err(f) => { show_error!("{}", f); @@ -84,16 +74,16 @@ Usage: None => 0f64 }; let signal = match matches.opt_str("signal") { - Some(sigstr) => match signals::signal_by_name_or_value(&sigstr) { + Some(sigstr) => match uucore::signals::signal_by_name_or_value(&sigstr) { Some(sig) => sig, None => { show_error!("invalid signal '{}'", sigstr); return ERR_EXIT_STATUS; } }, - None => signals::signal_by_name_or_value("TERM").unwrap() + None => uucore::signals::signal_by_name_or_value("TERM").unwrap() }; - let duration = match parse_time::from_str(&matches.free[0]) { + let duration = match uucore::parse_time::from_str(&matches.free[0]) { Ok(time) => time, Err(f) => { show_error!("{}", f); @@ -144,7 +134,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: usize, kill_af // XXX: this may not be right return 124; } - return_if_err!(ERR_EXIT_STATUS, process.send_signal(signals::signal_by_name_or_value("KILL").unwrap())); + return_if_err!(ERR_EXIT_STATUS, process.send_signal(uucore::signals::signal_by_name_or_value("KILL").unwrap())); return_if_err!(ERR_EXIT_STATUS, process.wait()); 137 }, diff --git a/src/touch/Cargo.toml b/src/touch/Cargo.toml index bb9b40438..e9a6b5ea4 100644 --- a/src/touch/Cargo.toml +++ b/src/touch/Cargo.toml @@ -12,6 +12,7 @@ filetime = "*" getopts = "*" libc = "*" time = "*" +uucore = { path="../uucore" } [[bin]] name="touch" diff --git a/src/touch/touch.rs b/src/touch/touch.rs index efee232cc..f4f8e3d16 100644 --- a/src/touch/touch.rs +++ b/src/touch/touch.rs @@ -14,19 +14,14 @@ extern crate libc; extern crate time; extern crate filetime; +#[macro_use] +extern crate uucore; + use filetime::*; use std::fs::{self, File}; use std::io::{Error, Write}; use std::path::Path; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; static NAME: &'static str = "touch"; static VERSION: &'static str = "1.0.0"; diff --git a/src/tr/Cargo.toml b/src/tr/Cargo.toml index cbbed1673..78ba1210c 100644 --- a/src/tr/Cargo.toml +++ b/src/tr/Cargo.toml @@ -12,6 +12,7 @@ getopts = "*" libc = "*" bit-set = "*" vec_map = "*" +uucore = { path="../uucore" } [[bin]] name="tr" diff --git a/src/tr/tr.rs b/src/tr/tr.rs index 877788691..cdd30deef 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -1,5 +1,6 @@ #![crate_name = "tr"] #![feature(io)] + /* * This file is part of the uutils coreutils package. * @@ -15,6 +16,9 @@ extern crate bit_set; extern crate getopts; extern crate vec_map; +#[macro_use] +extern crate uucore; + use bit_set::BitSet; use getopts::Options; use std::io::{stdin, stdout, BufReader, Read, Write}; @@ -22,10 +26,6 @@ use vec_map::VecMap; use expand::ExpandSet; -#[path="../common/util.rs"] -#[macro_use] -mod util; - mod expand; static NAME: &'static str = "tr"; diff --git a/src/truncate/Cargo.toml b/src/truncate/Cargo.toml index d36728324..4491d9262 100644 --- a/src/truncate/Cargo.toml +++ b/src/truncate/Cargo.toml @@ -10,6 +10,7 @@ path = "truncate.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="truncate" diff --git a/src/truncate/truncate.rs b/src/truncate/truncate.rs index 8f0b79d84..361371f50 100644 --- a/src/truncate/truncate.rs +++ b/src/truncate/truncate.rs @@ -12,15 +12,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::ascii::AsciiExt; use std::fs::{File, metadata, OpenOptions}; use std::io::{Result, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - #[derive(Eq, PartialEq)] enum TruncateMode { Reference, diff --git a/src/tsort/Cargo.toml b/src/tsort/Cargo.toml index 12b45b748..d3d96f2d8 100644 --- a/src/tsort/Cargo.toml +++ b/src/tsort/Cargo.toml @@ -10,6 +10,7 @@ path = "tsort.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="tsort" diff --git a/src/tsort/tsort.rs b/src/tsort/tsort.rs index 0bca10b41..de2a6348d 100644 --- a/src/tsort/tsort.rs +++ b/src/tsort/tsort.rs @@ -13,15 +13,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io::{BufRead, BufReader, Read, stdin, Write}; use std::path::Path; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "tsort"; static VERSION: &'static str = "1.0.0"; diff --git a/src/tty/Cargo.toml b/src/tty/Cargo.toml index 699033899..6229406eb 100644 --- a/src/tty/Cargo.toml +++ b/src/tty/Cargo.toml @@ -10,6 +10,7 @@ path = "tty.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="tty" diff --git a/src/tty/tty.rs b/src/tty/tty.rs index 12cbd25d9..039f28b3f 100644 --- a/src/tty/tty.rs +++ b/src/tty/tty.rs @@ -14,13 +14,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use std::ffi::CStr; use std::io::Write; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - extern { fn ttyname(filedesc: libc::c_int) -> *const libc::c_char; fn isatty(filedesc: libc::c_int) -> libc::c_int; diff --git a/src/uname/Cargo.toml b/src/uname/Cargo.toml index c6d381cf7..15e95f07b 100644 --- a/src/uname/Cargo.toml +++ b/src/uname/Cargo.toml @@ -10,6 +10,7 @@ path = "uname.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="uname" diff --git a/src/uname/uname.rs b/src/uname/uname.rs index e8a7c075f..75a14f8c8 100644 --- a/src/uname/uname.rs +++ b/src/uname/uname.rs @@ -14,13 +14,13 @@ extern crate getopts; extern crate libc; -use c_types::utsname; +#[macro_use] +extern crate uucore; + use std::ffi::CStr; use std::io::Write; use std::mem::uninitialized; - -#[path = "../common/util.rs"] #[macro_use] mod util; -#[path = "../common/c_types.rs"] mod c_types; +use uucore::c_types::utsname; struct Uts { sysname: String, diff --git a/src/unexpand/Cargo.toml b/src/unexpand/Cargo.toml index 01612c5d5..9123271ab 100644 --- a/src/unexpand/Cargo.toml +++ b/src/unexpand/Cargo.toml @@ -11,6 +11,7 @@ path = "unexpand.rs" getopts = "*" libc = "*" unicode-width = "*" +uucore = { path="../uucore" } [[bin]] name="unexpand" diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 481aa84e7..a8af2635d 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -17,16 +17,15 @@ extern crate libc; extern crate rustc_unicode; extern crate unicode_width; +#[macro_use] +extern crate uucore; + use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write}; use std::str::from_utf8; use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "unexpand"; static VERSION: &'static str = "0.0.1"; diff --git a/src/uniq/Cargo.toml b/src/uniq/Cargo.toml index a1997a355..f5d9a56e7 100644 --- a/src/uniq/Cargo.toml +++ b/src/uniq/Cargo.toml @@ -10,6 +10,7 @@ path = "uniq.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="uniq" diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index c042a5948..273339ae3 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -12,6 +12,9 @@ extern crate getopts; +#[macro_use] +extern crate uucore; + use getopts::{Matches, Options}; use std::cmp::min; use std::fs::File; @@ -19,10 +22,6 @@ use std::io::{BufRead, BufReader, BufWriter, Read, stdin, stdout, Write}; use std::path::Path; use std::str::FromStr; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "uniq"; static VERSION: &'static str = "1.0.0"; diff --git a/src/unlink/Cargo.toml b/src/unlink/Cargo.toml index bb9b0ef94..cd23f3f3e 100644 --- a/src/unlink/Cargo.toml +++ b/src/unlink/Cargo.toml @@ -10,6 +10,7 @@ path = "unlink.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="unlink" diff --git a/src/unlink/unlink.rs b/src/unlink/unlink.rs index f05eb7537..186ef24cf 100644 --- a/src/unlink/unlink.rs +++ b/src/unlink/unlink.rs @@ -14,16 +14,15 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use libc::{S_IFMT, S_IFLNK, S_IFREG}; use libc::{lstat, unlink, c_char, stat}; use std::io::{Error, ErrorKind, Write}; use std::mem::uninitialized; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "unlink"; static VERSION: &'static str = "1.0.0"; diff --git a/src/uptime/Cargo.toml b/src/uptime/Cargo.toml index baf9f9d16..50cf4bd6d 100644 --- a/src/uptime/Cargo.toml +++ b/src/uptime/Cargo.toml @@ -11,6 +11,7 @@ path = "uptime.rs" getopts = "*" libc = "*" time = "*" +uucore = { path="../uucore" } [[bin]] name="uptime" diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index 63e1d47e1..24170fa1d 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -15,6 +15,9 @@ extern crate getopts; extern crate libc; extern crate time as rtime; +#[macro_use] +extern crate uucore; + use getopts::Options; use libc::{time_t, c_double, c_int, c_char}; use std::ffi::CString; @@ -22,13 +25,7 @@ use std::fs::File; use std::io::{Read, Write}; use std::mem::transmute; use std::ptr::null; -use utmpx::*; - -#[path = "../common/util.rs"] #[macro_use] mod util; - -#[path = "../common/c_types.rs"] mod c_types; - -#[path = "../common/utmpx.rs"] mod utmpx; +use uucore::utmpx::*; static NAME: &'static str = "uptime"; static VERSION: &'static str = "1.0.0"; diff --git a/src/users/Cargo.toml b/src/users/Cargo.toml index 2ffc7148d..059d773d5 100644 --- a/src/users/Cargo.toml +++ b/src/users/Cargo.toml @@ -10,6 +10,7 @@ path = "users.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="users" diff --git a/src/users/users.rs b/src/users/users.rs index 7832208aa..c33b503cb 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -17,18 +17,14 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::ffi::{CStr, CString}; use std::mem; use std::ptr; -use utmpx::*; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/utmpx.rs"] -mod utmpx; +use uucore::utmpx::*; extern { fn getutxent() -> *const c_utmp; diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml new file mode 100644 index 000000000..65c4d6a01 --- /dev/null +++ b/src/uucore/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "uucore" +version = "0.0.1" +authors = [] + +[dependencies] +libc = "*" +time = "*" + +[lib] +path = "lib.rs" diff --git a/src/common/c_types.rs b/src/uucore/c_types.rs similarity index 99% rename from src/common/c_types.rs rename to src/uucore/c_types.rs index 0f0dbdb46..49e01d582 100644 --- a/src/common/c_types.rs +++ b/src/uucore/c_types.rs @@ -145,7 +145,7 @@ pub fn get_group(groupname: &str) -> Option { let group = if groupname.chars().all(|c| c.is_digit(10)) { unsafe { getgrgid(groupname.parse().unwrap()) } } else { - unsafe { + unsafe { let cstr = CString::new(groupname).unwrap(); getgrnam(cstr.as_bytes_with_nul().as_ptr() as *const c_char) } diff --git a/src/common/filesystem.rs b/src/uucore/fs.rs similarity index 98% rename from src/common/filesystem.rs rename to src/uucore/fs.rs index e00aa34b8..e0372b357 100644 --- a/src/common/filesystem.rs +++ b/src/uucore/fs.rs @@ -43,7 +43,6 @@ impl UUPathExt for Path { } #[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[allow(dead_code)] pub enum CanonicalizeMode { None, Normal, @@ -51,7 +50,6 @@ pub enum CanonicalizeMode { Missing, } -#[allow(dead_code)] fn resolve>(original: P) -> Result { const MAX_LINKS_FOLLOWED: u32 = 255; let mut followed = 0; @@ -81,7 +79,6 @@ fn resolve>(original: P) -> Result { Ok(result) } -#[allow(dead_code)] pub fn canonicalize>(original: P, can_mode: CanonicalizeMode) -> Result { // Create an absolute path let original = original.as_ref(); diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs new file mode 100644 index 000000000..adbe7fe80 --- /dev/null +++ b/src/uucore/lib.rs @@ -0,0 +1,14 @@ +extern crate libc; +extern crate time; + +#[macro_use] +mod macros; + +pub mod c_types; +pub mod fs; +pub mod parse_time; +pub mod process; +#[cfg(unix)] pub mod signals; +#[cfg(unix)] pub mod utmpx; + +#[cfg(windows)] pub mod wide; diff --git a/src/common/util.rs b/src/uucore/macros.rs similarity index 95% rename from src/common/util.rs rename to src/uucore/macros.rs index d333def3e..89fa1c2a6 100644 --- a/src/common/util.rs +++ b/src/uucore/macros.rs @@ -7,9 +7,10 @@ * file that was distributed with this source code. */ +#[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); + pipe_write!(&mut ::std::io::stderr(), "{}: error: ", module_path!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); @@ -17,7 +18,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", ::NAME); + pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", module_path!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); @@ -25,7 +26,7 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_info( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: ", ::NAME); + pipe_write!(&mut ::std::io::stderr(), "{}: ", module_path!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); diff --git a/src/common/parse_time.rs b/src/uucore/parse_time.rs similarity index 100% rename from src/common/parse_time.rs rename to src/uucore/parse_time.rs diff --git a/src/common/process.rs b/src/uucore/process.rs similarity index 100% rename from src/common/process.rs rename to src/uucore/process.rs diff --git a/src/common/signals.rs b/src/uucore/signals.rs similarity index 99% rename from src/common/signals.rs rename to src/uucore/signals.rs index f48fefd2f..62db82f1b 100644 --- a/src/common/signals.rs +++ b/src/uucore/signals.rs @@ -7,8 +7,6 @@ * that was distributed with this source code. */ -#![allow(dead_code)] - pub static DEFAULT_SIGNAL:usize= 15; diff --git a/src/common/utmpx.rs b/src/uucore/utmpx.rs similarity index 98% rename from src/common/utmpx.rs rename to src/uucore/utmpx.rs index a210dfff4..58bedc91a 100644 --- a/src/common/utmpx.rs +++ b/src/uucore/utmpx.rs @@ -1,5 +1,4 @@ -#![allow(non_camel_case_types)] -#![allow(dead_code)] +#![allow(dead_code, non_camel_case_types)] extern crate libc; diff --git a/src/common/wide.rs b/src/uucore/wide.rs similarity index 100% rename from src/common/wide.rs rename to src/uucore/wide.rs diff --git a/src/wc/Cargo.toml b/src/wc/Cargo.toml index 235b46d11..cad95a824 100644 --- a/src/wc/Cargo.toml +++ b/src/wc/Cargo.toml @@ -10,6 +10,7 @@ path = "wc.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="wc" diff --git a/src/wc/wc.rs b/src/wc/wc.rs index 9160b1c60..684afc1f3 100644 --- a/src/wc/wc.rs +++ b/src/wc/wc.rs @@ -12,6 +12,9 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::{Matches, Options}; use std::ascii::AsciiExt; use std::fs::File; @@ -19,15 +22,7 @@ use std::io::{stdin, BufRead, BufReader, Read, Write}; use std::path::Path; use std::result::Result as StdResult; use std::str::from_utf8; - -#[path = "../common/util.rs"] -#[macro_use] -mod util; - -#[path = "../common/filesystem.rs"] -mod filesystem; - -use filesystem::UUPathExt; +use uucore::fs::UUPathExt; struct Settings { show_bytes: bool, diff --git a/src/whoami/Cargo.toml b/src/whoami/Cargo.toml index c5036711c..13598a92a 100644 --- a/src/whoami/Cargo.toml +++ b/src/whoami/Cargo.toml @@ -10,6 +10,7 @@ path = "whoami.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="whoami" diff --git a/src/whoami/platform/unix.rs b/src/whoami/platform/unix.rs index 009a7ef6b..f4db2e53e 100644 --- a/src/whoami/platform/unix.rs +++ b/src/whoami/platform/unix.rs @@ -9,9 +9,7 @@ use std::io::{Result, Error}; use ::libc; -use self::c_types::{c_passwd, getpwuid}; - -#[path = "../../common/c_types.rs"] mod c_types; +use uucore::c_types::{c_passwd, getpwuid}; extern { pub fn geteuid() -> libc::uid_t; diff --git a/src/whoami/platform/windows.rs b/src/whoami/platform/windows.rs index 28d36cbfc..0a8611952 100644 --- a/src/whoami/platform/windows.rs +++ b/src/whoami/platform/windows.rs @@ -10,15 +10,14 @@ extern crate winapi; extern crate advapi32; -use std::io::{Result, Error}; +#[macro_use] +extern crate uucore; -#[path = "../../common/wide.rs"] #[macro_use] mod wide; - -use std::mem; -use std::io::Write; use std::ffi::OsString; +use std::io::{Error, Result, Write}; +use std::mem; use std::os::windows::ffi::OsStringExt; -use self::wide::FromWide; +use uucore::wide::FromWide; pub unsafe fn getusername() -> Result { let mut buffer: [winapi::WCHAR; winapi::UNLEN as usize + 1] = mem::uninitialized(); diff --git a/src/whoami/whoami.rs b/src/whoami/whoami.rs index 14325b537..3e35b22c3 100644 --- a/src/whoami/whoami.rs +++ b/src/whoami/whoami.rs @@ -14,10 +14,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::io::Write; -#[path = "../common/util.rs"] #[macro_use] mod util; mod platform; static NAME: &'static str = "whoami"; diff --git a/src/yes/Cargo.toml b/src/yes/Cargo.toml index 36d86854d..6d113820f 100644 --- a/src/yes/Cargo.toml +++ b/src/yes/Cargo.toml @@ -10,6 +10,7 @@ path = "yes.rs" [dependencies] getopts = "*" libc = "*" +uucore = { path="../uucore" } [[bin]] name="yes" diff --git a/src/yes/yes.rs b/src/yes/yes.rs index bc492095a..fd24b6a4b 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -14,13 +14,12 @@ extern crate getopts; extern crate libc; +#[macro_use] +extern crate uucore; + use getopts::Options; use std::io::Write; -#[path = "../common/util.rs"] -#[macro_use] -mod util; - static NAME: &'static str = "yes"; static VERSION: &'static str = "1.0.0"; diff --git a/tests/hashsum.rs b/tests/hashsum.rs index b0bb2929b..d653e5422 100644 --- a/tests/hashsum.rs +++ b/tests/hashsum.rs @@ -1,10 +1,6 @@ #[macro_use] mod common; - - - - macro_rules! get_hash( ($str:expr) => ( $str.split(' ').collect::>()[0]