env, expand, fmt: fix build

This commit is contained in:
Arcterus 2015-01-09 17:20:40 -08:00 committed by Michael Gehring
parent 8e430d6952
commit e142b4f23e
5 changed files with 28 additions and 15 deletions

1
src/env/env.rs vendored
View file

@ -12,6 +12,7 @@
/* last synced with: env (GNU coreutils) 8.13 */
#![allow(non_camel_case_types)]
#![feature(box_syntax)]
struct options {
ignore_env: bool,

View file

@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/
#![feature(box_syntax)]
extern crate getopts;
extern crate libc;

View file

@ -8,8 +8,11 @@
* file that was distributed with this source code.
*/
#![feature(box_syntax)]
extern crate core;
extern crate getopts;
extern crate unicode;
use std::cmp;
use std::io::{BufferedReader, BufferedWriter, File, IoResult};

View file

@ -94,7 +94,7 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer
// break_simple implements a "greedy" breaking algorithm: print words until
// maxlength would be exceeded, then print a linebreak and indent and continue.
fn break_simple<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs<'a>) {
fn break_simple<'a, T: Iterator<Item=&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs<'a>) {
iter.fold((args.init_len, false), |l, winfo| accum_words_simple(args, l, winfo));
silent_unwrap!(args.ostream.write_char('\n'));
}
@ -120,7 +120,7 @@ fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (usize, boo
// Knuth, D.E., and Plass, M.F. "Breaking Paragraphs into Lines." in Software,
// Practice and Experience. Vol. 11, No. 11, November 1981.
// http://onlinelibrary.wiley.com/doi/10.1002/spe.4380111102/pdf
fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, args: &mut BreakArgs<'a>) {
fn break_knuth_plass<'a, T: Clone + Iterator<Item=&'a WordInfo<'a>>>(mut iter: T, args: &mut BreakArgs<'a>) {
// run the algorithm to get the breakpoints
let breakpoints = find_kp_breakpoints(iter.clone(), args);
@ -183,7 +183,7 @@ struct LineBreak<'a> {
fresh : bool
}
fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> {
fn find_kp_breakpoints<'a, T: Iterator<Item=&'a WordInfo<'a>>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> {
let mut iter = iter.peekable();
// set up the initial null linebreak
let mut linebreaks = vec!(LineBreak {
@ -199,7 +199,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
let active_breaks = &mut vec!(0);
let next_active_breaks = &mut vec!();
let stretch = (args.opts.width - args.opts.goal) as int;
let stretch = (args.opts.width - args.opts.goal) as isize;
let minlength = args.opts.goal - stretch as usize;
let mut new_linebreaks = vec!();
let mut is_sentence_start = false;
@ -256,7 +256,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
// there is no penalty for the final line's length
(0, 0.0)
} else {
compute_demerits((args.opts.goal - tlen) as int, stretch, w.word_nchars as int, active.prev_rat)
compute_demerits((args.opts.goal - tlen) as isize, stretch, w.word_nchars as isize, active.prev_rat)
};
// do not even consider adding a line that has too many demerits
@ -344,7 +344,7 @@ const DR_MULT: f32 = 600.0;
const DL_MULT: f32 = 300.0;
#[inline(always)]
fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (i64, f32) {
fn compute_demerits(delta_len: isize, stretch: isize, wlen: isize, prev_rat: f32) -> (i64, f32) {
// how much stretch are we using?
let ratio =
if delta_len == 0 {
@ -386,8 +386,8 @@ fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_i
} else {
// choose the lesser evil: breaking too early, or breaking too late
let wlen = w.word_nchars + args.compute_width(w, active.length, active.fresh);
let underlen: int = (min - active.length) as int;
let overlen: int = ((wlen + slen + active.length) - args.opts.width) as int;
let underlen = (min - active.length) as isize;
let overlen = ((wlen + slen + active.length) - args.opts.width) as isize;
if overlen > underlen {
// break early, put this word on the next line
(true, args.indent_len + w.word_nchars)

View file

@ -11,6 +11,7 @@ use core::iter::Peekable;
use std::io::Lines;
use std::slice::Iter;
use std::str::CharRange;
use unicode::str::UnicodeStr;
use FileOrStdReader;
use FmtOptions;
@ -78,7 +79,7 @@ impl<'a> FileLines<'a> {
// returns true if this line should be formatted
fn match_prefix(&self, line: &str) -> (bool, usize) {
if !self.opts.use_prefix { return (true, 0u); }
if !self.opts.use_prefix { return (true, 0); }
FileLines::match_prefix_generic(self.opts.prefix.as_slice(), line, self.opts.xprefix)
}
@ -100,7 +101,7 @@ impl<'a> FileLines<'a> {
if !exact {
// we do it this way rather than byte indexing to support unicode whitespace chars
let mut i = 0u;
let mut i = 0;
while (i < line.len()) && line.char_at(i).is_whitespace() {
i = match line.char_range_at(i) { CharRange { ch: _ , next: nxi } => nxi };
if line.slice_from(i).starts_with(pfx) {
@ -138,7 +139,9 @@ impl<'a> FileLines<'a> {
}
}
impl<'a> Iterator<Line> for FileLines<'a> {
impl<'a> Iterator for FileLines<'a> {
type Item = Line;
fn next(&mut self) -> Option<Line> {
let n =
match self.lines.next() {
@ -252,7 +255,9 @@ impl<'a> ParagraphStream<'a> {
}
}
impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
impl<'a> Iterator for ParagraphStream<'a> {
type Item = Result<Paragraph, String>;
fn next(&mut self) -> Option<Result<Paragraph, String>> {
// return a NoFormatLine in an Err; it should immediately be output
let noformat =
@ -410,7 +415,7 @@ impl<'a> ParaWords<'a> {
// no extra spacing for mail headers; always exactly 1 space
// safe to trim_left on every line of a mail header, since the
// first line is guaranteed not to have any spaces
self.words.extend(self.para.lines.iter().flat_map(|x| x.as_slice().words()).map(|x| WordInfo {
self.words.extend(self.para.lines.iter().flat_map(|x| StrExt::words(x.as_slice())).map(|x| WordInfo {
word : x,
word_start : 0,
word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped)
@ -480,7 +485,7 @@ impl<'a> WordSplit<'a> {
impl<'a> WordSplit<'a> {
fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> {
// wordsplits *must* start at a non-whitespace character
let trim_string = string.trim_left();
let trim_string = StrExt::trim_left(string);
WordSplit { opts: opts, string: trim_string, length: string.len(), position: 0, prev_punct: false }
}
@ -504,7 +509,9 @@ pub struct WordInfo<'a> {
}
// returns (&str, is_start_of_sentence)
impl<'a> Iterator<WordInfo<'a>> for WordSplit<'a> {
impl<'a> Iterator for WordSplit<'a> {
type Item = WordInfo<'a>;
fn next(&mut self) -> Option<WordInfo<'a>> {
if self.position >= self.length {
return None