1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge pull request #392 from Arcterus/fix-build

Update for latest Rust and remove warnings
This commit is contained in:
Heather 2014-09-18 02:13:36 +04:00
commit 2db41553a6
20 changed files with 52 additions and 43 deletions

View file

@ -15,6 +15,7 @@ extern crate libc;
use getopts::{optflag, optopt, getopts, usage};
use c_types::{get_pw_from_args, get_group};
use libc::funcs::posix88::unistd::{execvp, setuid, setgid};
use std::io::fs::PathExtensions;
#[path = "../common/util.rs"] mod util;
#[path = "../common/c_types.rs"] mod c_types;

View file

@ -15,6 +15,7 @@ extern crate getopts;
extern crate libc;
use std::io::{stdio, File, BufferedWriter, BufferedReader, print};
use std::io::fs::PathExtensions;
use getopts::{optopt, optflag, getopts, usage};
use ranges::Range;

View file

@ -23,15 +23,15 @@ impl std::from_str::FromStr for Range {
match (parts.next(), parts.next()) {
(Some(nm), None) => {
from_str::<uint>(nm).filtered(|nm| *nm > 0)
from_str::<uint>(nm).and_then(|nm| if nm > 0 { Some(nm) } else { None })
.map(|nm| Range { low: nm, high: nm })
}
(Some(n), Some(m)) if m.len() == 0 => {
from_str::<uint>(n).filtered(|low| *low > 0)
from_str::<uint>(n).and_then(|low| if low > 0 { Some(low) } else { None })
.map(|low| Range { low: low, high: MAX })
}
(Some(n), Some(m)) if n.len() == 0 => {
from_str::<uint>(m).filtered(|high| *high >= 1)
from_str::<uint>(m).and_then(|high| if high >= 1 { Some(high) } else { None })
.map(|high| Range { low: 1, high: high })
}
(Some(n), Some(m)) => {

View file

@ -200,9 +200,9 @@ pub fn uumain(args: Vec<String>) -> int {
}
Ok(f) => f
};
let mut pStream = ParagraphStream::new(&fmt_opts, &mut fp);
for paraResult in pStream {
match paraResult {
let mut p_stream = ParagraphStream::new(&fmt_opts, &mut fp);
for para_result in p_stream {
match para_result {
Err(s) => silent_unwrap!(ostream.write(s.as_bytes())),
Ok(para) => break_lines(&para, &fmt_opts, &mut ostream)
}

View file

@ -40,16 +40,16 @@ impl<'a> BreakArgs<'a> {
pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer+'static>) {
// indent
let pIndent = para.indent_str.as_slice();
let pIndentLen = para.indent_len;
let p_indent = para.indent_str.as_slice();
let p_indent_len = para.indent_len;
// words
let pWords = ParaWords::new(opts, para);
let mut pWords_words = pWords.words();
let p_words = ParaWords::new(opts, para);
let mut p_words_words = p_words.words();
// the first word will *always* appear on the first line
// make sure of this here
let (w, w_len) = match pWords_words.next() {
let (w, w_len) = match p_words_words.next() {
Some(winfo) => (winfo.word, winfo.word_nchars),
None => {
silent_unwrap!(ostream.write_char('\n'));
@ -57,15 +57,15 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer
}
};
// print the init, if it exists, and get its length
let pInitLen = w_len +
let p_init_len = w_len +
if opts.crown || opts.tagged {
// handle "init" portion
silent_unwrap!(ostream.write(para.init_str.as_bytes()));
para.init_len
} else if !para.mail_header {
// for non-(crown, tagged) that's the same as a normal indent
silent_unwrap!(ostream.write(pIndent.as_bytes()));
pIndentLen
silent_unwrap!(ostream.write(p_indent.as_bytes()));
p_indent_len
} else {
// except that mail headers get no indent at all
0
@ -78,17 +78,17 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer
let mut break_args = BreakArgs {
opts : opts,
init_len : pInitLen,
indent_str : pIndent,
indent_len : pIndentLen,
init_len : p_init_len,
indent_str : p_indent,
indent_len : p_indent_len,
uniform : uniform,
ostream : ostream
};
if opts.quick || para.mail_header {
break_simple(pWords_words, &mut break_args);
break_simple(p_words_words, &mut break_args);
} else {
break_knuth_plass(pWords_words, &mut break_args);
break_knuth_plass(p_words_words, &mut break_args);
}
}
@ -139,7 +139,9 @@ fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, arg
// We find identical breakpoints here by comparing addresses of the references.
// This is OK because the backing vector is not mutating once we are linebreaking.
if winfo as *const _ == next_break as *const _ {
let winfo_ptr = winfo as *const _;
let next_break_ptr = next_break as *const _;
if winfo_ptr == next_break_ptr {
// OK, we found the matching word
if break_before {
write_newline(args.indent_str, args.ostream);
@ -368,9 +370,9 @@ fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (
};
// we penalize lines that have very different ratios from previous lines
let bad_deltaR = (DR_MULT * num::abs(num::pow((ratio - prev_rat) / 2.0, 3))) as i64;
let bad_delta_r = (DR_MULT * num::abs(num::pow((ratio - prev_rat) / 2.0, 3))) as i64;
let demerits = num::pow(1 + bad_linelen + bad_wordlen + bad_deltaR, 2);
let demerits = num::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2);
(demerits, ratio)
}

View file

@ -230,20 +230,20 @@ impl<'a> ParagraphStream<'a> {
if line.indent_end > 0 {
false
} else {
let lSlice = line.line.as_slice();
if lSlice.starts_with("From ") {
let l_slice = line.line.as_slice();
if l_slice.starts_with("From ") {
true
} else {
let colonPosn =
match lSlice.find(':') {
let colon_posn =
match l_slice.find(':') {
Some(n) => n,
None => return false
};
// header field must be nonzero length
if colonPosn == 0 { return false; }
if colon_posn == 0 { return false; }
return lSlice.slice_to(colonPosn).chars().all(|x| match x as uint {
return l_slice.slice_to(colon_posn).chars().all(|x| match x as uint {
y if y < 33 || y > 126 => false,
_ => true
});
@ -280,7 +280,7 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
let mut indent_len = 0;
let mut prefix_len = 0;
let mut pfxind_end = 0;
let mut pLines = Vec::new();
let mut p_lines = Vec::new();
let mut in_mail = false;
let mut second_done = false; // for when we use crown or tagged mode
@ -298,7 +298,7 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
}
};
if pLines.len() == 0 {
if p_lines.len() == 0 {
// first time through the loop, get things set up
// detect mail header
if self.opts.mail && self.next_mail && ParagraphStream::is_mail_header(fl) {
@ -366,7 +366,7 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
}
}
pLines.push(self.lines.next().unwrap().get_formatline().line);
p_lines.push(self.lines.next().unwrap().get_formatline().line);
// when we're in split-only mode, we never join lines, so stop here
if self.opts.split_only {
@ -380,7 +380,7 @@ impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
self.next_mail = in_mail;
Some(Ok(Paragraph {
lines : pLines,
lines : p_lines,
init_str : init_str,
init_len : init_len,
init_end : init_end,

View file

@ -14,7 +14,7 @@
extern crate getopts;
extern crate libc;
use std::io::fs;
use std::io::fs::{mod, PathExtensions};
use std::io::FilePermission;
use std::num::strconv;

View file

@ -43,7 +43,7 @@ fn rewind_stdout<T: std::rt::rtio::RtioFileStream>(s: &mut T) {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() }
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int { std::ptr::null() }
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]

View file

@ -15,6 +15,7 @@ extern crate getopts;
extern crate libc;
use std::io::{print, stdin, stdio, fs, BufferedReader};
use std::io::fs::PathExtensions;
#[path = "../common/util.rs"]
mod util;

View file

@ -15,6 +15,7 @@ extern crate getopts;
extern crate libc;
use std::io::{print, fs};
use std::io::fs::PathExtensions;
#[path = "../common/util.rs"]
mod util;

View file

@ -170,7 +170,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
fn version() {
println!("sync (uutils) 1.0.0");
println!("{} (uutils) {}", NAME, VERSION);
println!("The MIT License");
println!("");
println!("Author -- Alexander Fomin.");

View file

@ -14,6 +14,7 @@ extern crate getopts;
extern crate time;
use std::io::File;
use std::io::fs::PathExtensions;
#[path = "../common/util.rs"]
mod util;

View file

@ -15,6 +15,7 @@ extern crate getopts;
extern crate libc;
use std::io::{File, Open, ReadWrite, fs};
use std::io::fs::PathExtensions;
use std::u64;
#[path = "../common/util.rs"]

View file

@ -17,7 +17,7 @@ extern crate getopts;
extern crate libc;
use std::io;
use std::io::fs;
use std::io::fs::{mod, PathExtensions};
use std::io::print;
#[path = "../common/util.rs"]

View file

@ -16,6 +16,7 @@ extern crate libc;
use std::str::from_utf8;
use std::io::{print, File, BufferedReader};
use std::io::fs::PathExtensions;
use std::io::stdio::stdin_raw;
use std::result::Result as StdResult;
use getopts::Matches;

View file

@ -24,7 +24,7 @@ fn test_output_multi_files_print_all_chars() {
fn test_stdin_squeeze() {
let mut process= Command::new(PROGNAME).arg("-A").spawn().unwrap();
process.stdin.take_unwrap().write(b"\x00\x01\x02").unwrap();
process.stdin.take().unwrap().write(b"\x00\x01\x02").unwrap();
let po = process.wait_with_output().unwrap();
let out = str::from_utf8(po.output.as_slice()).unwrap();
@ -35,7 +35,7 @@ fn test_stdin_squeeze() {
fn test_stdin_number_non_blank() {
let mut process = Command::new(PROGNAME).arg("-b").arg("-").spawn().unwrap();
process.stdin.take_unwrap().write(b"\na\nb\n\n\nc").unwrap();
process.stdin.take().unwrap().write(b"\na\nb\n\n\nc").unwrap();
let po = process.wait_with_output().unwrap();
let out = str::from_utf8(po.output.as_slice()).unwrap();

View file

@ -1,5 +1,5 @@
use std::io::process::Command;
use std::io::fs::rmdir;
use std::io::fs::{rmdir, PathExtensions};
static exe: &'static str = "./mkdir";
static test_dir1: &'static str = "mkdir_test1";

View file

@ -6,7 +6,7 @@ static PROGNAME: &'static str = "./nl";
#[test]
fn test_stdin_nonewline() {
let mut process = Command::new(PROGNAME).spawn().unwrap();
process.stdin.take_unwrap().write(b"No Newline").unwrap();
process.stdin.take().unwrap().write(b"No Newline").unwrap();
let po = process.wait_with_output().unwrap();
let out = str::from_utf8(po.output.as_slice()).unwrap();
@ -17,7 +17,7 @@ fn test_stdin_newline() {
let mut process = Command::new(PROGNAME).arg("-s").arg("-")
.arg("-w").arg("1").spawn().unwrap();
process.stdin.take_unwrap().write(b"Line One\nLine Two\n").unwrap();
process.stdin.take().unwrap().write(b"Line One\nLine Two\n").unwrap();
let po = process.wait_with_output().unwrap();
let out = str::from_utf8(po.output.as_slice()).unwrap();

View file

@ -5,7 +5,7 @@ static PROGNAME: &'static str = "./tr";
fn run(input: &str, args: &[&'static str]) -> Vec<u8> {
let mut process = Command::new(PROGNAME).args(args).spawn().unwrap();
process.stdin.take_unwrap().write_str(input).unwrap();
process.stdin.take().unwrap().write_str(input).unwrap();
let po = match process.wait_with_output() {
Ok(p) => p,

View file

@ -5,7 +5,7 @@ static PROGNAME: &'static str = "./unexpand";
fn run(input: &str, args: &[&'static str]) -> Vec<u8> {
let mut process = Command::new(PROGNAME).args(args).spawn().unwrap();
process.stdin.take_unwrap().write_str(input).unwrap();
process.stdin.take().unwrap().write_str(input).unwrap();
let po = match process.wait_with_output() {
Ok(p) => p,