summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 50bba9340f6f3a94ce051bde3c6bb71cfed2ed53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![feature(test)]
#![feature(plugin,collections,str_char)] // For peg
#![plugin(peg_syntax_ext)]

extern crate test;
extern crate time;
extern crate getopts;
extern crate regex;

mod line;
mod filter;
mod config;

use std::io::{stdin,stdout,stderr,Write,BufRead};

pub use line::Line;
use config::Config;


fn main() {
    let mut c = Config::new();
    let filter = c.parse_args();

    let s = stdin();
    let o = stdout();
    let mut o = o.lock();
    for l in s.lock().lines().map(|x| x.unwrap()) {
        let mut line = match Line::new(l.as_ref()) {
            Ok(x) => x,
            Err(_) => {
                if !c.quiet {
                    writeln!(&mut stderr(), "Unrecognized line: {}", l).unwrap();
                }
                continue;
            }
        };

        if c.vhost2ident {
            line.vhost2ident();
        }

        if filter.apply(&line) {
            line.write(&mut o).unwrap();
            o.write_all("\n".as_bytes()).unwrap();
        }
    }
}