1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Fix master by using Vec and adjusting

This commit is contained in:
Alan Andrade 2014-03-22 01:18:52 -07:00
parent 2e29f4cc79
commit 10d7a0cc9c
18 changed files with 38 additions and 38 deletions

View file

@ -76,10 +76,10 @@ fn main() {
},
None => 76
};
let mut input = if matches.free.is_empty() || matches.free[0] == ~"-" {
let mut input = if matches.free.is_empty() || matches.free.get(0).as_slice() == "-" {
~stdin() as ~Reader
} else {
let path = Path::new(matches.free[0]);
let path = Path::new(matches.free.get(0).clone());
~File::open(&path) as ~Reader
};

View file

@ -17,7 +17,7 @@ extern crate getopts;
use std::os;
use std::io::{print, File};
use std::io::stdio::{stdout_raw, stdin_raw};
use std::io::{BufferedReader, BufferedWriter};
use std::io::{BufferedWriter};
fn main() {
let args = os::args();
@ -68,7 +68,7 @@ fn main() {
let squeeze_blank = matches.opt_present("squeeze-blank");
let mut files = matches.free;
if files.is_empty() {
files = ~[~"-"];
files = vec!(~"-");
}
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
@ -96,7 +96,7 @@ fn is_newline_char(byte: u8) -> bool {
byte == LF
}
pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
pub fn exec(files: Vec<~str>, number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) {
if NumberNone != number || show_nonprint || show_ends || show_tabs || squeeze_blank {
let mut counter: uint = 1;

View file

@ -10,7 +10,7 @@ use std::libc::{
getgroups
};
use std::vec;
use std::vec::Vec;
use std::ptr::read;
use std::str::raw::from_c_str;
@ -54,9 +54,9 @@ extern {
pub fn getgrgid(gid: uid_t) -> *c_group;
}
pub fn get_pw_from_args(free: &~[~str]) -> Option<c_passwd> {
pub fn get_pw_from_args(free: &Vec<~str>) -> Option<c_passwd> {
if free.len() == 1 {
let username = free[0].clone();
let username = free.get(0).clone();
// Passed user as id
if username.chars().all(|c| c.is_digit()) {
@ -88,7 +88,7 @@ pub fn get_pw_from_args(free: &~[~str]) -> Option<c_passwd> {
static NGROUPS: i32 = 20;
pub fn group(possible_pw: Option<c_passwd>, nflag: bool) {
let mut groups = vec::with_capacity(NGROUPS as uint);
let mut groups = Vec::with_capacity(NGROUPS as uint);
let mut ngroups;
if possible_pw.is_some() {

View file

@ -213,7 +213,7 @@ ers of 1000).",
separate_dirs: matches.opt_present("S"),
};
let strs = if matches.free.is_empty() {~[~"./"]} else {matches.free.clone()};
let strs = if matches.free.is_empty() {vec!(~"./")} else {matches.free.clone()};
let options_arc = Arc::new(options);

View file

@ -14,7 +14,7 @@
extern crate getopts;
use std::{os,libc,vec,str};
use std::{os,libc,str};
use getopts::{optflag, getopts, usage};
extern {
@ -78,7 +78,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
fn xgethostname() -> ~str {
let namelen = 256u;
let mut name = vec::from_elem(namelen, 0u8);
let mut name = Vec::from_elem(namelen, 0u8);
let err = unsafe {
gethostname (name.as_mut_ptr() as *libc::c_char,

View file

@ -17,7 +17,7 @@
#[feature(macro_rules)];
extern crate getopts;
use std::{libc, os, vec};
use std::{libc, os};
use std::ptr::read;
use std::libc::{
c_char,
@ -318,7 +318,7 @@ fn id_print(possible_pw: Option<c_passwd>,
}
let mut ngroups;
let mut groups = vec::with_capacity(NGROUPS as uint);
let mut groups = Vec::with_capacity(NGROUPS as uint);
if use_ggl && possible_pw.is_some() {
ngroups = NGROUPS;

View file

@ -28,7 +28,7 @@ static VERSION: &'static str = "1.0.0";
*/
fn main() {
let args = os::args();
let opts = ~[
// Linux-specific options, not implemented
// getopts::optflag("Z", "context", "set SELinux secutiry context" +
@ -91,8 +91,8 @@ fn print_help(opts: &[getopts::OptGroup]) {
/**
* Create the list of new directories
*/
fn exec(dirs: ~[~str], mk_parents: bool, mode: u32, verbose: bool) {
let mut parent_dirs: ~[~str] = ~[];
fn exec(dirs: Vec<~str>, mk_parents: bool, mode: u32, verbose: bool) {
let mut parent_dirs = Vec::new();
if mk_parents {
for dir in dirs.iter() {
let path = Path::new((*dir).clone());

View file

@ -55,7 +55,7 @@ fn main() {
}
}
fn paste(filenames: ~[~str], serial: bool, delimiters: ~str) {
fn paste(filenames: Vec<~str>, serial: bool, delimiters: ~str) {
let mut files: ~[io::BufferedReader<io::File>] = filenames.move_iter().map(|name|
io::BufferedReader::new(crash_if_err!(1, io::File::open(&Path::new(name))))
).collect();
@ -79,18 +79,18 @@ fn paste(filenames: ~[~str], serial: bool, delimiters: ~str) {
println!("{}", output);
}
} else {
let mut eof = std::vec::from_elem(files.len(), false);
let mut eof = Vec::from_elem(files.len(), false);
loop {
let mut output = ~"";
let mut eof_count = 0;
for (i, file) in files.mut_iter().enumerate() {
if eof[i] {
if *eof.get(i) {
eof_count += 1;
} else {
match file.read_line() {
Ok(line) => output = output + line.slice_to(line.len() - 1),
Err(f) => if f.kind == io::EndOfFile {
eof[i] = true;
*eof.get_mut(i) = true;
eof_count += 1;
} else {
crash!(1, "{}", f.to_str());

View file

@ -58,7 +58,7 @@ fn main() {
exec(matches.free, separator);
}
pub fn exec(args: ~[~str], separator: &str) {
pub fn exec(args: Vec<~str>, separator: &str) {
if args.is_empty() {
let vars = os::env();
for (env_var, value) in vars.move_iter() {

View file

@ -119,7 +119,7 @@ fn main() {
}
// TODO: implement one-file-system
fn remove(files: &[~str], force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) {
fn remove(files: Vec<~str>, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) {
for filename in files.iter() {
let file = Path::new(filename.to_owned());
if file.exists() {
@ -131,7 +131,7 @@ fn remove(files: &[~str], force: bool, interactive: InteractiveMode, one_fs: boo
crash!(1, "{}", f.to_str());
}
};
remove(walk_dir.map(|x| x.as_str().unwrap().to_owned()).to_owned_vec(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
remove(walk_dir.map(|x| x.as_str().unwrap().to_owned()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
remove_dir(&file, *filename, interactive, verbose);
} else if dir && (*filename != ~"/" || !preserve_root) {
remove_dir(&file, *filename, interactive, verbose);

View file

@ -60,7 +60,7 @@ fn main() {
}
}
fn remove(dirs: &[~str], ignore: bool, parents: bool, verbose: bool) {
fn remove(dirs: Vec<~str>, ignore: bool, parents: bool, verbose: bool) {
for dir in dirs.iter() {
let path = Path::new(dir.to_owned());
if path.exists() {

View file

@ -63,7 +63,7 @@ fn main() {
return;
}
let first = if matches.free.len() > 1 {
match parse_float(matches.free[0]) {
match parse_float(matches.free.get(0).as_slice()) {
Ok(n) => n,
Err(s) => { show_error!(1, "{:s}", s); return; }
}
@ -71,14 +71,14 @@ fn main() {
1.0
};
let step = if matches.free.len() > 2 {
match parse_float(matches.free[1]) {
match parse_float(matches.free.get(1).as_slice()) {
Ok(n) => n,
Err(s) => { show_error!(1, "{:s}", s); return; }
}
} else {
1.0
};
let last = match parse_float(matches.free[matches.free.len()-1]) {
let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) {
Ok(n) => n,
Err(s) => { show_error!(1, "{:s}", s); return; }
};

View file

@ -62,7 +62,7 @@ specified by the sum of their values.", opts));
}
}
fn sleep(args: &[~str]) {
fn sleep(args: Vec<~str>) {
let sleep_time = args.iter().fold(0.0, |result, arg| {
let suffix_time = match match_suffix(unsafe { cast::transmute(arg) }) {
Ok(m) => m,

View file

@ -63,7 +63,7 @@ fn main() {
}
}
fn tac(filenames: ~[~str], before: bool, _: bool, separator: ~str) {
fn tac(filenames: Vec<~str>, before: bool, _: bool, separator: ~str) {
for filename in filenames.move_iter() {
let mut file = io::BufferedReader::new(
crash_if_err!(1, io::File::open(&Path::new(filename))));

View file

@ -36,7 +36,7 @@ struct Options {
append: bool,
ignore_interrupts: bool,
print_and_exit: Option<~str>,
files: ~[Path]
files: ~Vec<Path>
}
fn options(args: &[~str]) -> Result<Options, ()> {
@ -57,7 +57,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}",
version, program, arguments, usage(brief, opts),
comment);
let names = m.free + ~[~"-"];
let names = std::vec::append_one(m.free.clone(), ~"-");
let to_print = if m.opt_present("help") { Some(help) }
else if m.opt_present("version") { Some(version) }
else { None };
@ -66,7 +66,7 @@ fn options(args: &[~str]) -> Result<Options, ()> {
append: m.opt_present("append"),
ignore_interrupts: m.opt_present("ignore-interrupts"),
print_and_exit: to_print,
files: names.map(|name| Path::new(name.clone()))
files: ~names.iter().map(|name| Path::new(name.clone())).collect()
})
}).map_err(|message| warn(message))
}
@ -79,7 +79,7 @@ fn exec(options: Options) -> Result<(), ()> {
}
fn tee(options: Options) -> Result<(), ()> {
let writers = options.files.map(|path| open(path, options.append));
let writers = options.files.iter().map(|path| open(path, options.append)).collect();
let output = &mut MultiWriter::new(writers);
let input = &mut NamedReader { inner: ~stdin() as ~Reader };
if copy(input, output).is_err() || output.flush().is_err() {

View file

@ -107,7 +107,7 @@ file based on its current size:
}
}
fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str>, filenames: ~[~str]) {
fn truncate(no_create: bool, _: bool, reference: Option<~str>, size: Option<~str>, filenames: Vec<~str>) {
let (refsize, mode) = match reference {
Some(rfilename) => {
let rfile = match File::open(&Path::new(rfilename.clone())) {

View file

@ -77,7 +77,7 @@ fn main() {
let mut filename = DEFAULT_FILE;
if matches.free.len() > 0 {
filename = matches.free[0].as_slice();
filename = matches.free.get(0).as_slice();
}
exec(filename);

View file

@ -69,7 +69,7 @@ fn main() {
let mut files = matches.free.clone();
if files.is_empty() {
files = ~[~"-"];
files = vec!(~"-");
}
wc(files, &matches);
@ -86,7 +86,7 @@ fn is_word_seperator(byte: u8) -> bool {
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
}
pub fn wc(files: ~[~str], matches: &Matches) {
pub fn wc(files: Vec<~str>, matches: &Matches) {
let mut total_line_count: uint = 0;
let mut total_word_count: uint = 0;
let mut total_char_count: uint = 0;