1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

Merge pull request #360 from Arcterus/makefile-fixes

Force programs to rebuild when a dependency changes
This commit is contained in:
Heather 2014-07-20 06:16:33 +04:00
commit dc0611e52b
57 changed files with 164 additions and 158 deletions

View file

@ -1,5 +1,12 @@
include common.mk
# Binaries
RUSTC ?= rustc
RM := rm
# Flags
RUSTCFLAGS := --opt-level=3
RMFLAGS :=
# Install directories
PREFIX ?= /usr/local
BINDIR ?= /bin
@ -87,8 +94,7 @@ BUILD ?= $(PROGS)
EXES := \
$(sort $(filter $(BUILD),$(filter-out $(DONT_BUILD),$(PROGS))))
CRATES := \
$(sort $(EXES))
CRATE_RLIBS :=
INSTALL ?= $(EXES)
@ -109,25 +115,33 @@ TEST ?= $(TEST_PROGS)
TESTS := \
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
# Setup for building crates
define BUILD_SETUP
X := $(shell $(RUSTC) --print-file-name --crate-type rlib $(1)/$(1).rs)
$(1)_RLIB := $$(X)
CRATE_RLIBS += $$(X)
endef
$(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate))))
# Utils stuff
EXES_PATHS := $(addprefix build/,$(EXES))
RLIB_PATHS := $(addprefix build/,$(CRATE_RLIBS))
command = sh -c '$(1)'
# Main exe build rule
define EXE_BUILD
build/gen/$(1).rs: build/mkmain
build/mkmain $(1) build/gen/$(1).rs
build/$(1): build/gen/$(1).rs build/$(1).timestamp | build deps
build/$(1): build/gen/$(1).rs build/$($(1)_RLIB) | build deps
$(RUSTC) $(RUSTCFLAGS) -L build/ -o build/$(1) build/gen/$(1).rs
endef
define CRATE_BUILD
-include build/$(1).d
build/$(1).timestamp: $(1)/$(1).rs | build deps
build/$($(1)_RLIB): $(1)/$(1).rs | build deps
$(RUSTC) $(RUSTCFLAGS) -L build/ --crate-type rlib --dep-info build/$(1).d $(1)/$(1).rs --out-dir build
@touch build/$(1).timestamp
endef
# Aliases build rule
@ -155,16 +169,22 @@ endef
# Main rules
all: $(EXES_PATHS) build/uutils
# Creating necessary rules for each targets
$(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate))))
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
-include build/uutils.d
build/uutils: uutils/uutils.rs build/mkuutils $(addprefix build/, $(addsuffix .timestamp, $(CRATES)))
build/uutils: uutils/uutils.rs build/mkuutils $(RLIB_PATHS)
build/mkuutils build/gen/uutils.rs $(BUILD)
$(RUSTC) $(RUSTCFLAGS) -L build/ --dep-info $@.d build/gen/uutils.rs -o $@
# Dependencies
LIBCRYPTO := $(shell $(RUSTC) --print-file-name --crate-type rlib deps/rust-crypto/src/rust-crypto/lib.rs)
-include build/rust-crypto.d
build/$(LIBCRYPTO): | build
build/.rust-crypto: | build
$(RUSTC) $(RUSTCFLAGS) --crate-type rlib --dep-info build/rust-crypto.d deps/rust-crypto/src/rust-crypto/lib.rs --out-dir build/
@touch $@
build/mkmain: mkmain.rs | build
$(RUSTC) $(RUSTCFLAGS) -L build mkmain.rs -o $@
@ -175,7 +195,7 @@ build/mkuutils: mkuutils.rs | build
cksum/crc_table.rs: cksum/gen_table.rs
cd cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
deps: build/$(LIBCRYPTO) cksum/crc_table.rs
deps: build/.rust-crypto cksum/crc_table.rs
crates:
echo $(EXES)
@ -193,12 +213,6 @@ build:
tmp:
mkdir tmp
# Creating necessary rules for each targets
$(foreach crate,$(CRATES),$(eval $(call CRATE_BUILD,$(crate))))
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
install: $(addprefix build/,$(INSTALLEES))
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)
for prog in $(INSTALLEES); do \

View file

@ -52,7 +52,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
};
let progname = args.get(0).clone();
let progname = args[0].clone();
let usage = usage("Base64 encode or decode FILE, or standard input, to standard output.", opts);
let mode = if matches.opt_present("help") {
Help
@ -76,11 +76,11 @@ pub fn uumain(args: Vec<String>) -> int {
};
let mut stdin_buf;
let mut file_buf;
let input = if matches.free.is_empty() || matches.free.get(0).as_slice() == "-" {
let input = if matches.free.is_empty() || matches.free[0].as_slice() == "-" {
stdin_buf = stdin_raw();
&mut stdin_buf as &mut Reader
} else {
let path = Path::new(matches.free.get(0).as_slice());
let path = Path::new(matches.free[0].as_slice());
file_buf = File::open(&path);
&mut file_buf as &mut Reader
};

View file

@ -23,7 +23,7 @@ static NAME: &'static str = "basename";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = strip_dir(args.get(0).as_slice());
let program = strip_dir(args[0].as_slice());
//
// Argument parsing
@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
// too many arguments
else if args.len() > 3 {
println!("{}: extra operand '{}'", program, args.get(3));
println!("{}: extra operand '{}'", program, args[3]);
println!("Try '{} --help' for more information.", program);
return 1;
}
@ -71,12 +71,12 @@ pub fn uumain(args: Vec<String>) -> int {
// Main Program Processing
//
let fullname = args.get(1);
let fullname = &args[1];
let mut name = strip_dir(fullname.as_slice());
if args.len() > 2 {
let suffix = args.get(2).clone();
let suffix = args[2].clone();
name = strip_suffix(name.as_slice(), suffix.as_slice());
}

View file

@ -20,7 +20,7 @@ use std::io::{IoResult};
use std::ptr::{copy_nonoverlapping_memory};
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("A", "show-all", "equivalent to -vET"),
getopts::optflag("b", "number-nonblank",

View file

@ -37,7 +37,7 @@ static NAME: &'static str = "chroot";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optopt("u", "user", "User (ID or name) to switch before running the program", "USER"),
@ -72,7 +72,7 @@ pub fn uumain(args: Vec<String>) -> int {
let defaultOption: &'static str = "-i";
let userShell = std::os::getenv("SHELL");
let newroot = Path::new(opts.free.get(0).as_slice());
let newroot = Path::new(opts.free[0].as_slice());
if !newroot.is_dir() {
crash!(1, "cannot change root directory to `{}`: no such directory", newroot.display());
}
@ -91,7 +91,7 @@ pub fn uumain(args: Vec<String>) -> int {
set_context(&newroot, &opts);
unsafe {
let executable = command.get(0).as_slice().to_c_str().unwrap();
let executable = command[0].as_slice().to_c_str().unwrap();
let mut commandParts: Vec<*const i8> = command.iter().map(|x| x.to_c_str().unwrap()).collect();
commandParts.push(std::ptr::null());
execvp(executable as *const libc::c_char, commandParts.as_ptr() as *mut *const libc::c_char) as int
@ -113,8 +113,8 @@ fn set_context(root: &Path, options: &getopts::Matches) {
}
None => Vec::new()
};
let user = if userspec.is_empty() { userStr.as_slice() } else { userspec.get(0).as_slice() };
let group = if userspec.is_empty() { groupStr.as_slice() } else { userspec.get(1).as_slice() };
let user = if userspec.is_empty() { userStr.as_slice() } else { userspec[0].as_slice() };
let group = if userspec.is_empty() { groupStr.as_slice() } else { userspec[1].as_slice() };
enter_chroot(root);

View file

@ -62,19 +62,19 @@ fn comm(a: &mut Box<Buffer>, b: &mut Box<Buffer>, opts: &getopts::Matches) {
match ord {
Less => {
if !opts.opt_present("1") {
print!("{}{}", delim.get(1), ra.map(ensure_nl).unwrap());
print!("{}{}", delim[1], ra.map(ensure_nl).unwrap());
}
ra = a.read_line();
}
Greater => {
if !opts.opt_present("2") {
print!("{}{}", delim.get(2), rb.map(ensure_nl).unwrap());
print!("{}{}", delim[2], rb.map(ensure_nl).unwrap());
}
rb = b.read_line();
}
Equal => {
if !opts.opt_present("3") {
print!("{}{}", delim.get(3), ra.map(ensure_nl).unwrap());
print!("{}{}", delim[3], ra.map(ensure_nl).unwrap());
}
ra = a.read_line();
rb = b.read_line();
@ -127,8 +127,8 @@ pub fn uumain(args: Vec<String>) -> int {
}
let mut f1 = open_file(matches.free.get(0).as_slice()).unwrap();
let mut f2 = open_file(matches.free.get(1).as_slice()).unwrap();
let mut f1 = open_file(matches.free[0].as_slice()).unwrap();
let mut f2 = open_file(matches.free[1].as_slice()).unwrap();
comm(&mut f1, &mut f2, &matches);

View file

@ -1,7 +0,0 @@
# Binaries
RUSTC ?= rustc
RM := rm
# Flags
RUSTCFLAGS := --opt-level=3
RMFLAGS :=

View file

@ -98,7 +98,7 @@ extern {
pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
if free.len() == 1 {
let username = free.get(0).as_slice();
let username = free[0].as_slice();
// Passed user as id
if username.chars().all(|c| c.is_digit()) {

View file

@ -44,7 +44,7 @@ pub fn uumain(args: Vec<String>) -> int {
},
};
let progname = args.get(0);
let progname = &args[0];
let usage = usage("Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.", opts);
let mode = if matches.opt_present("version") {
Version
@ -90,13 +90,13 @@ fn copy(matches: getopts::Matches) {
fail!()
} else {
// Only the last argument:
Path::new(matches.free.get(matches.free.len() - 1).as_slice())
Path::new(matches.free[matches.free.len() - 1].as_slice())
};
assert!(sources.len() >= 1);
if sources.len() == 1 {
let source = sources.get(0);
let source = &sources[0];
let same_file = match paths_refer_to_same_file(source, &dest) {
Ok(b) => b,
Err(e) => if e.kind == io::FileNotFound {

View file

@ -259,7 +259,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
if delim_search.peek().is_none() {
if ! only_delimited {
out.write(line.as_slice()).unwrap();
if *line.get(line.len() - 1) != b'\n' {
if line[line.len() - 1] != b'\n' {
out.write([b'\n']).unwrap();
}
}
@ -296,7 +296,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
out.write(segment).unwrap();
if *line.get(line.len() - 1) == b'\n' {
if line[line.len() - 1] == b'\n' {
continue 'newline
}
break
@ -341,7 +341,7 @@ fn cut_fields<R: Reader>(reader: R,
if delim_search.peek().is_none() {
if ! opts.only_delimited {
out.write(line.as_slice()).unwrap();
if *line.get(line.len() - 1) != b'\n' {
if line[line.len() - 1] != b'\n' {
out.write([b'\n']).unwrap();
}
}
@ -378,7 +378,7 @@ fn cut_fields<R: Reader>(reader: R,
out.write(segment).unwrap();
if *line.get(line.len() - 1) == b'\n' {
if line[line.len() - 1] == b'\n' {
continue 'newline
}
break
@ -468,7 +468,7 @@ pub fn uumain(args: Vec<String>) -> int {
if matches.opt_present("help") {
println!("Usage:");
println!(" {0} OPTION... [FILE]...", args.get(0));
println!(" {0} OPTION... [FILE]...", args[0]);
println!("");
print(usage("Print selected parts of lines from each FILE to standard output.", opts).as_slice());
println!("");
@ -548,7 +548,7 @@ pub fn uumain(args: Vec<String>) -> int {
Err(err_msg) => {
show_error!("{}\n\
Try '{} --help' for more information",
err_msg, args.get(0));
err_msg, args[0]);
1
}
}

View file

@ -66,9 +66,9 @@ impl Range {
for i in range(0, ranges.len()) {
let j = i + 1;
while j < ranges.len() && ranges.get(j).low <= ranges.get(i).high {
while j < ranges.len() && ranges[j].low <= ranges[i].high {
let j_high = ranges.remove(j).unwrap().high;
ranges.get_mut(i).high = max(ranges.get(i).high, j_high);
ranges.get_mut(i).high = max(ranges[i].high, j_high);
}
}
@ -81,8 +81,8 @@ pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
let mut complements = Vec::with_capacity(ranges.len() + 1);
if ranges.len() > 0 && ranges.get(0).low > 1 {
complements.push(Range { low: 1, high: ranges.get(0).low - 1 });
if ranges.len() > 0 && ranges[0].low > 1 {
complements.push(Range { low: 1, high: ranges[0].low - 1 });
}
let mut ranges_iter = ranges.iter().peekable();

View file

@ -16,7 +16,7 @@ use std::io::print;
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("z", "zero", "separate output with NUL rather than newline"),
getopts::optflag("", "help", "display this help and exit"),

View file

@ -89,7 +89,7 @@ fn du(path: &Path, mut my_stat: Stat,
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
// In task
getopts::optflag("a", "all", " write counts for all files, not just directories"),
@ -245,7 +245,7 @@ ers of 1000).",
}
}
let number = std::uint::parse_bytes(numbers.as_slice(), 10).unwrap();
let multiple = match std::str::from_chars(letters.as_slice()).as_slice() {
let multiple = match String::from_chars(letters.as_slice()).as_slice() {
"K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024,
"T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024,
"E" => 1024 * 1024 * 1024 * 1024 * 1024 * 1024,

View file

@ -80,7 +80,7 @@ fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) {
fn parse_options(args: Vec<String>, options: &mut EchoOptions) -> Option<Vec<String>> {
let mut echo_args = vec!();
let program = args.get(0).clone();
let program = args[0].clone();
'argloop: for arg in args.move_iter().skip(1) {
match arg.as_slice() {
"--help" | "-h" => {

4
env/env.rs vendored
View file

@ -52,7 +52,7 @@ fn print_env(null: bool) {
}
pub fn uumain(args: Vec<String>) -> int {
let prog = args.get(0).as_slice();
let prog = args[0].as_slice();
// to handle arguments the same way than GNU env, we can't use getopts
let mut opts = box options {
@ -191,7 +191,7 @@ pub fn uumain(args: Vec<String>) -> int {
if opts.program.len() >= 1 {
use std::io::process::{Command, InheritFd};
let prog = opts.program.get(0).clone();
let prog = opts.program[0].clone();
let args = opts.program.slice_from(1);
match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() {
Ok(exit) =>

View file

@ -64,7 +64,7 @@ fn print_factors_str(num_str: &str) {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("h", "help", "show this help message"),
getopts::optflag("v", "version", "print the version and exit"),

View file

@ -83,11 +83,11 @@ pub fn uumain(args: Vec<String>) -> int {
let matches = match getopts::getopts(args.tail(), opts.as_slice()) {
Ok(m) => m,
Err(f) => crash!(1, "{}\nTry `{} --help' for more information.", f, args.get(0))
Err(f) => crash!(1, "{}\nTry `{} --help' for more information.", f, args[0])
};
if matches.opt_present("h") {
print_usage(args.get(0).as_slice(), opts.as_slice(), "");
print_usage(args[0].as_slice(), opts.as_slice(), "");
}
if matches.opt_present("V") || matches.opt_present("h") {

View file

@ -289,7 +289,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
if next_active_breaks.is_empty() {
// every potential linebreak is too long! choose the linebreak with the least demerits, ld_idx
let new_break = restart_active_breaks(args, linebreaks.get(ld_idx), ld_idx, w, slen, minlength);
let new_break = restart_active_breaks(args, &linebreaks[ld_idx], ld_idx, w, slen, minlength);
next_active_breaks.push(linebreaks.len());
linebreaks.push(new_break);
least_demerits = 0;
@ -312,7 +312,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
fn build_best_path<'a>(paths: &Vec<LineBreak<'a>>, active: &Vec<uint>) -> Vec<(&'a WordInfo<'a>, bool)> {
let mut breakwords = vec!();
// of the active paths, we select the one with the fewest demerits
let mut best_idx = match active.iter().min_by(|&&a| paths.get(a).demerits) {
let mut best_idx = match active.iter().min_by(|&&a| paths[a].demerits) {
None => crash!(1, "Failed to find a k-p linebreak solution. This should never happen."),
Some(&s) => s
};
@ -320,7 +320,7 @@ fn build_best_path<'a>(paths: &Vec<LineBreak<'a>>, active: &Vec<uint>) -> Vec<(&
// now, chase the pointers back through the break list, recording
// the words at which we should break
loop {
let next_best = paths.get(best_idx);
let next_best = paths[best_idx];
match next_best.linebreak {
None => return breakwords,
Some(prev) => {

View file

@ -425,10 +425,10 @@ impl<'a> ParaWords<'a> {
self.words.extend(
if self.opts.crown || self.opts.tagged {
// crown and tagged mode has the "init" in the first line, so slice from there
WordSplit::new(self.opts, self.para.lines.get(0).as_slice().slice_from(self.para.init_end))
WordSplit::new(self.opts, self.para.lines[0].as_slice().slice_from(self.para.init_end))
} else {
// otherwise we slice from the indent
WordSplit::new(self.opts, self.para.lines.get(0).as_slice().slice_from(self.para.indent_end))
WordSplit::new(self.opts, self.para.lines[0].as_slice().slice_from(self.para.indent_end))
});
if self.para.lines.len() > 1 {

View file

@ -28,7 +28,7 @@ static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let (args, obs_width) = handle_obsolete(args.as_slice());
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("b", "bytes", "count using bytes rather than columns (meaning control characters such as newline are not treated specially)"),
@ -86,7 +86,7 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
let mut args = Vec::<String>::from_slice(args);
let mut i = 0;
while i < args.len() {
if args.get(i).as_slice().char_at(0) == '-' && args.get(i).len() > 1 && args.get(i).as_slice().char_at(1).is_digit() {
if args[i].as_slice().char_at(0) == '-' && args[i].len() > 1 && args[i].as_slice().char_at(1).is_digit() {
return (args.clone(),
Some(args.remove(i).unwrap().as_slice().slice_from(1).to_string()));
}

View file

@ -26,7 +26,7 @@ static NAME: &'static str = "groups";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let options = [
optflag("h", "help", "display this help menu and exit"),

View file

@ -90,7 +90,7 @@ fn detect_algo(program: &str, matches: &getopts::Matches) -> (&str, Box<Digest>)
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let binary = Path::new(program.as_slice());
let binary_name = binary.filename_str().unwrap();
@ -313,4 +313,3 @@ fn digest_reader(digest: &mut Box<Digest>, reader: &mut Reader, binary: bool) ->
Ok(digest.result_str())
}

View file

@ -104,7 +104,7 @@ fn obsolete (options: &[String]) -> (Vec<String>, Option<uint>) {
let b = options.len();
while a < b {
let current = options.get(a).clone();
let current = options[a].clone();
let current = current.as_bytes();
if current.len() > 1 && current[0] == '-' as u8 {

View file

@ -33,7 +33,7 @@ extern {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optflag("f", "full", "Default option to show full name"),

View file

@ -103,7 +103,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
let mut i = 0;
while i < args.len() {
// this is safe because slice is valid when it is referenced
let slice: &str = unsafe { std::mem::transmute(args.get(i).as_slice()) };
let slice: &str = unsafe { std::mem::transmute(args[i].as_slice()) };
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit() {
let val = slice.slice_from(1);
match from_str(val) {

View file

@ -50,8 +50,8 @@ pub fn uumain(args: Vec<String>) -> int {
return 0;
}
let old = Path::new(matches.free.get(0).as_slice());
let new = Path::new(matches.free.get(1).as_slice());
let old = Path::new(matches.free[0].as_slice());
let new = Path::new(matches.free[1].as_slice());
match link(&old, &new) {
Ok(_) => 0,

View file

@ -43,7 +43,7 @@ fn version() {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
//
// Argument parsing

View file

@ -3,7 +3,7 @@ use std::os;
use std::path::Path;
use std::str::replace;
static TEMPLATE : &'static str = r"
static TEMPLATE: &'static str = "\
extern crate @UTIL_CRATE@;
use std::os;
@ -22,14 +22,14 @@ fn main() {
return;
}
let crat = match args.get(1).as_slice() {
let crat = match args[1].as_slice() {
"test" => "uutest",
"true" => "uutrue",
"false" => "uufalse",
"sync" => "uusync",
s => s.clone(),
};
let outfile = args.get(2).as_slice();
let outfile = args[2].as_slice();
let main = std::str::replace(TEMPLATE, "@UTIL_CRATE@", crat);
let mut out = File::open_mode(&Path::new(outfile), Truncate, ReadWrite);

View file

@ -15,12 +15,18 @@ fn main() {
let mut hashsum = false;
for prog in args.slice_from(2).iter() {
match prog.as_slice() {
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
"hashsum" | "md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
if !hashsum {
crates.push_str("extern crate hashsum;\n");
util_map.push_str("map.insert(\"hashsum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"md5sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha1sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha224sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha256sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha384sum\", hashsum::uumain);\n");
util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n");
hashsum = true;
}
util_map.push_str(format!("map.insert(\"{}\", hashsum::uumain);\n", prog).as_slice());
}
"test" => {
crates.push_str("extern crate uutest;\n");
@ -38,7 +44,7 @@ fn main() {
}
}
}
let outfile = args.get(1).as_slice();
let outfile = args[1].as_slice();
// XXX: this all just assumes that the IO works correctly
let mut out = File::open_mode(&Path::new(outfile), Truncate, Write).unwrap();

View file

@ -1,8 +1,6 @@
extern crate getopts;
extern crate regex;
use std::str;
// parse_style parses a style string into a NumberingStyle.
fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> {
match chars {
@ -10,7 +8,7 @@ fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> {
['t'] => { Ok(::NumberForNonEmpty) },
['n'] => { Ok(::NumberForNone) },
['p', ..rest] => {
match regex::Regex::new(str::from_chars(rest).as_slice()) {
match regex::Regex::new(String::from_chars(rest).as_slice()) {
Ok(re) => Ok(::NumberForRegularExpression(re)),
Err(_) => Err(String::from_str("Illegal regular expression")),
}

View file

@ -50,7 +50,7 @@ fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null(
fn rewind_stdout<T: std::rt::rtio::RtioFileStream>(_: &mut T) {}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optflag("h", "help", "Show help and exit"),
@ -82,7 +82,7 @@ pub fn uumain(args: Vec<String>) -> int {
unsafe {
// we ignore the memory leak here because it doesn't matter anymore
let executable = opts.free.get(0).as_slice().to_c_str().unwrap();
let executable = opts.free[0].as_slice().to_c_str().unwrap();
let mut args: Vec<*const i8> = opts.free.iter().map(|x| x.to_c_str().unwrap()).collect();
args.push(std::ptr::null());
execvp(executable as *const libc::c_char, args.as_ptr() as *mut *const libc::c_char) as int

View file

@ -23,7 +23,7 @@ static NAME: &'static str = "paste";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("s", "serial", "paste one file at a time instead of in parallel"),
@ -75,7 +75,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
match file.read_line() {
Ok(line) => {
output.push_str(line.as_slice().trim_right());
output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice());
output.push_str(delimiters[delim_count % delimiters.len()].as_slice());
}
Err(f) => if f.kind == io::EndOfFile {
break
@ -93,7 +93,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
let mut output = "".to_string();
let mut eof_count = 0;
for (i, file) in files.mut_iter().enumerate() {
if *eof.get(i) {
if eof[i] {
eof_count += 1;
} else {
match file.read_line() {
@ -106,7 +106,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
}
}
}
output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice());
output.push_str(delimiters[delim_count % delimiters.len()].as_slice());
delim_count += 1;
}
if files.len() == eof_count {

View file

@ -25,7 +25,7 @@ mod util;
static NAME: &'static str = "printenv";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"),
getopts::optflag("h", "help", "display this help and exit"),

View file

@ -23,7 +23,7 @@ static NAME: &'static str = "pwd";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("", "help", "display this help and exit"),
getopts::optflag("", "version", "output version information and exit"),

View file

@ -21,7 +21,7 @@ static NAME: &'static str = "realpath";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optflag("h", "help", "Show help and exit"),
optflag("V", "version", "Show version and exit"),

View file

@ -21,7 +21,7 @@ static NAME: &'static str = "relpath";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optflag("h", "help", "Show help and exit"),
optflag("V", "version", "Show version and exit"),
@ -46,9 +46,9 @@ pub fn uumain(args: Vec<String>) -> int {
return 1
}
let to = Path::new(opts.free.get(0).as_slice());
let to = Path::new(opts.free[0].as_slice());
let from = if opts.free.len() > 1 {
Path::new(opts.free.get(1).as_slice())
Path::new(opts.free[1].as_slice())
} else {
std::os::getcwd()
};

View file

@ -29,7 +29,7 @@ enum InteractiveMode {
static NAME: &'static str = "rm";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
// TODO: make getopts support -R in addition to -r
let opts = [
@ -235,4 +235,3 @@ fn read_prompt() -> bool {
Err(_) => true
}
}

View file

@ -22,7 +22,7 @@ mod util;
static NAME: &'static str = "rmdir";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("", "ignore-fail-on-non-empty", "ignore each failure that is solely because a directory is non-empty"),
@ -96,7 +96,7 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool
};
let mut r = Ok(());
if walk_dir.next() == None {
match fs::rmdir(path) {
Ok(_) => {
@ -122,4 +122,3 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool
r
}

View file

@ -51,7 +51,7 @@ fn escape_sequences(s: &str) -> String {
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, int> {
let mut seq_args = vec!();
let program = args.get(0).clone();
let program = args[0].clone();
let mut iter = args.move_iter().skip(1);
loop {
match iter.next() {
@ -159,7 +159,7 @@ fn print_version() {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let mut options = SeqOptions {
separator: "\n".to_string(),
terminator: None,
@ -176,7 +176,7 @@ pub fn uumain(args: Vec<String>) -> int {
let mut largest_dec = 0;
let mut padding = 0;
let first = if free.len() > 1 {
let slice = free.get(0).as_slice();
let slice = free[0].as_slice();
let len = slice.len();
let dec = slice.find('.').unwrap_or(len);
largest_dec = len - dec;
@ -189,12 +189,12 @@ pub fn uumain(args: Vec<String>) -> int {
1.0
};
let step = if free.len() > 2 {
let slice = free.get(1).as_slice();
let slice = free[1].as_slice();
let len = slice.len();
let dec = slice.find('.').unwrap_or(len);
largest_dec = cmp::max(largest_dec, len - dec);
padding = cmp::max(padding, dec);
match parse_float(free.get(1).as_slice()) {
match parse_float(free[1].as_slice()) {
Ok(n) => n,
Err(s) => { show_error!("{:s}", s); return 1; }
}
@ -202,7 +202,7 @@ pub fn uumain(args: Vec<String>) -> int {
1.0
};
let last = {
let slice = free.get(free.len() - 1).as_slice();
let slice = free[free.len() - 1].as_slice();
padding = cmp::max(padding, slice.find('.').unwrap_or(slice.len()));
match parse_float(slice) {
Ok(n) => n,

View file

@ -35,7 +35,7 @@ static NAME: &'static str = "shuf";
static VERSION: &'static str = "0.0.1";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("e", "echo", "treat each ARG as an input line"),
@ -164,7 +164,7 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
let max = if repeat { count } else { cmp::min(count, len) };
for _ in range(0, max) {
let idx = rng.next_u32() as uint % len;
try!(write!(output, "{}{}", lines.get(idx), if zero { '\0' } else { '\n' }));
try!(write!(output, "{}{}", lines[idx], if zero { '\0' } else { '\n' }));
if !repeat {
lines.remove(idx);
len -= 1;
@ -178,15 +178,14 @@ fn parse_range(input_range: String) -> Result<RangeInclusive<uint>, (String, int
if split.len() != 2 {
Err(("invalid range format".to_string(), 1))
} else {
let begin = match from_str::<uint>(*split.get(0)) {
let begin = match from_str::<uint>(split[0]) {
Some(m) => m,
None => return Err((format!("{} is not a valid number", split.get(0)), 1))
None => return Err((format!("{} is not a valid number", split[0]), 1))
};
let end = match from_str::<uint>(*split.get(1)) {
let end = match from_str::<uint>(split[1]) {
Some(m) => m,
None => return Err((format!("{} is not a valid number", split.get(1)), 1))
None => return Err((format!("{} is not a valid number", split[1]), 1))
};
Ok(range_inclusive(begin, end))
}
}

View file

@ -24,7 +24,7 @@ mod util;
static NAME: &'static str = "sleep";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),

View file

@ -76,7 +76,7 @@ fn open(name: &str) -> IoResult<Box<Reader>> {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("r", "", "use the BSD compatible algorithm (default)"),
getopts::optflag("s", "sysv", "use System V compatible algorithm"),

View file

@ -137,7 +137,7 @@ mod platform {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0);
let program = &args[0];
let options = [
optflag("h", "help", "display this help and exit"),

View file

@ -23,7 +23,7 @@ static NAME: &'static str = "tac";
static VERSION: &'static str = "1.0.0";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("b", "before", "attach the separator before instead of after"),

View file

@ -109,7 +109,7 @@ pub fn uumain(args: Vec<String>) -> int {
tail(&mut buffer, line_count, follow, sleep_sec);
}
}
0
}
@ -123,7 +123,7 @@ fn obsolete (options: &[String]) -> (Vec<String>, Option<uint>) {
let b = options.len();
while a < b {
let current = options.get(a).clone();
let current = options[a].clone();
let current = current.as_bytes();
if current.len() > 1 && current[0] == '-' as u8 {

View file

@ -31,6 +31,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
}
#[allow(dead_code)]
struct Options {
program: String,
append: bool,
@ -51,7 +52,7 @@ fn options(args: &[String]) -> Result<Options, ()> {
getopts(args.tail(), opts).map_err(|e| format!("{}", e)).and_then(|m| {
let version = format!("{} {}", NAME, VERSION);
let program = args.get(0).as_slice();
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.";
@ -110,7 +111,7 @@ struct NamedWriter {
impl Writer for NamedWriter {
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
with_path(self.path.clone(), || {
with_path(&*self.path.clone(), || {
let val = self.inner.write(buf);
if val.is_err() {
self.inner = box NullWriter as Box<Writer>;
@ -120,7 +121,7 @@ impl Writer for NamedWriter {
}
fn flush(&mut self) -> IoResult<()> {
with_path(self.path.clone(), || {
with_path(&*self.path.clone(), || {
let val = self.inner.flush();
if val.is_err() {
self.inner = box NullWriter as Box<Writer>;

View file

@ -187,11 +187,11 @@ pub fn uumain(args: Vec<String>) -> int {
}
if dflag {
let set1 = expand_set(sets.get(0).as_slice());
let set1 = expand_set(sets[0].as_slice());
delete(set1, cflag);
} else {
let set1 = expand_set(sets.get(0).as_slice());
let set2 = expand_set(sets.get(1).as_slice());
let set1 = expand_set(sets[0].as_slice());
let set2 = expand_set(sets[1].as_slice());
tr(set1.as_slice(), set2.as_slice());
}

View file

@ -34,7 +34,7 @@ enum TruncateMode {
static NAME: &'static str = "truncate";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("c", "no-create", "do not create files that do not exist"),
@ -220,4 +220,3 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
}
(number, mode)
}

View file

@ -30,7 +30,7 @@ struct utsrust {
nodename: String,
release: String,
version: String,
machine: String
machine: String
}
extern {
@ -51,7 +51,7 @@ unsafe fn getuname() -> utsrust {
static NAME: &'static str = "uname";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("a", "all", "Behave as though all of the options -mnrsv were specified."),

View file

@ -43,7 +43,7 @@ impl Uniq {
for io_line in reader.lines() {
let line = crash_if_err!(1, io_line);
if !lines.is_empty() && self.cmp_key(lines.get(0)) != self.cmp_key(&line) {
if !lines.is_empty() && self.cmp_key(&lines[0]) != self.cmp_key(&line) {
let print_delimiter = delimiters == "prepend" || (delimiters == "separate" && first_line_printed);
first_line_printed |= self.print_lines(writer, &lines, print_delimiter);
lines.truncate(0);
@ -83,7 +83,7 @@ impl Uniq {
let mut count = if self.all_repeated { 1 } else { lines.len() };
if lines.len() == 1 && !self.repeats_only
|| lines.len() > 1 && !self.uniques_only {
self.print_line(writer, lines.get(0), count, print_delimiter);
self.print_line(writer, &lines[0], count, print_delimiter);
first_line_printed = true;
count += 1;
}
@ -119,7 +119,7 @@ fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<
}
pub fn uumain(args: Vec<String>) -> int {
let program_path = Path::new(args.get(0).clone());
let program_path = Path::new(args[0].clone());
let program = program_path.filename_str().unwrap_or(NAME);
let opts = [
@ -159,10 +159,10 @@ pub fn uumain(args: Vec<String>) -> int {
} else {
let (in_file_name, out_file_name) = match matches.free.len() {
0 => ("-".into_string(), "-".into_string()),
1 => (matches.free.get(0).clone(), "-".into_string()),
2 => (matches.free.get(0).clone(), matches.free.get(1).clone()),
1 => (matches.free[0].clone(), "-".into_string()),
2 => (matches.free[0].clone(), matches.free[1].clone()),
_ => {
crash!(1, "Extra operand: {}", matches.free.get(2));
crash!(1, "Extra operand: {}", matches.free[2]);
}
};
let uniq = Uniq {

View file

@ -26,7 +26,7 @@ mod util;
static NAME: &'static str = "unlink";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
@ -57,10 +57,10 @@ pub fn uumain(args: Vec<String>) -> int {
if matches.free.len() == 0 {
crash!(1, "missing operand\nTry '{0:s} --help' for more information.", program);
} else if matches.free.len() > 1 {
crash!(1, "extra operand: '{1}'\nTry '{0:s} --help' for more information.", program, matches.free.get(1));
crash!(1, "extra operand: '{1}'\nTry '{0:s} --help' for more information.", program, matches.free[1]);
}
let path = Path::new(matches.free.get(0).clone());
let path = Path::new(matches.free[0].clone());
let result = path.lstat().and_then(|info| {
match info.kind {

View file

@ -47,7 +47,7 @@ extern {
}
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("v", "version", "output version information and exit"),
getopts::optflag("h", "help", "display this help and exit"),
@ -180,7 +180,7 @@ fn print_uptime(upsecs: i64) {
let updays = upsecs / 86400;
let uphours = (upsecs - (updays * 86400)) / 3600;
let upmins = (upsecs - (updays * 86400) - (uphours * 3600)) / 60;
if updays == 1 {
if updays == 1 {
print!("up {:1d} day, {:2d}:{:02d}, ", updays, uphours, upmins);
}
else if updays > 1 {

View file

@ -47,7 +47,7 @@ extern {
static NAME: &'static str = "users";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),
@ -75,7 +75,7 @@ pub fn uumain(args: Vec<String>) -> int {
let mut filename = DEFAULT_FILE;
if matches.free.len() > 0 {
filename = matches.free.get(0).as_slice();
filename = matches.free[0].as_slice();
}
exec(filename);

View file

@ -29,14 +29,13 @@ fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> int>) {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");
println!(" {} [util [arguments...]", NAME);
println!(" {} [util [arguments...]]\n", NAME);
println!("Currently defined functions:");
let mut utils: Vec<&str> = cmap.keys().map(|&s| s).collect();
utils.sort();
for util in utils.iter() {
println!("\t{}", util);
}
println!("");
}
fn main() {
@ -44,7 +43,7 @@ fn main() {
let mut args = os::args();
// try binary name as util name.
let binary = Path::new(args.get(0).as_slice());
let binary = Path::new(args[0].as_slice());
let binary_as_util = binary.filename_str().unwrap();
match umap.find_equiv(&binary_as_util) {
@ -69,7 +68,7 @@ fn main() {
// try first arg as util name.
if args.len() >= 2 {
args.shift();
let util = args.get(0).as_slice();
let util = args[0].as_slice();
match umap.find_equiv(&util) {
Some(&uumain) => {
@ -77,10 +76,10 @@ fn main() {
return
}
None => {
if args.get(0).as_slice() == "--help" {
if args[0].as_slice() == "--help" {
// see if they want help on a specific util
if args.len() >= 2 {
let util = args.get(1).as_slice();
let util = args[1].as_slice();
match umap.find_equiv(&util) {
Some(&uumain) => {
os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()]));

View file

@ -35,7 +35,7 @@ struct Result {
static NAME: &'static str = "wc";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("c", "bytes", "print the byte counts"),
getopts::optflag("m", "chars", "print the character counts"),

View file

@ -67,7 +67,7 @@ mod platform {
static NAME: &'static str = "whoami";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).as_slice();
let program = args[0].as_slice();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),

View file

@ -24,7 +24,7 @@ mod util;
static NAME: &'static str = "yes";
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let program = args[0].clone();
let opts = [
getopts::optflag("h", "help", "display this help and exit"),
getopts::optflag("V", "version", "output version information and exit"),